npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

boeuf

v0.0.2

Published

Protocol buffers as node streams

Downloads

7

Readme

Boeuf

Master branch build status Published version ISC Licensed

Boeuf is a node stream wrapper for protocol buffers. Under the hood it uses the mapbox pbf library for parsing and compiling, so can be used with either .proto schemas or with custom read/write functions.

Usage

const boeuf = require('boeuf');

let ws = boeuf.writable('./path/to/schema.proto');
let rs = boeuf.readable('./path/to/schema.proto');

ws.pipe(process.stdout);
ws.write({foo: 1, bar: 2});

rs.on('data', message => {
  // message is a parsed message as a js object
})
process.stdin.pipe(rs);

valid arguments for boeuf#readable and boeuf#writable are:

  1. a string path to a protocol buffers schema file (in which case the message name matching the name of the file given is used);
  2. as above but with a second argument specifying which message to use;
  3. a custom read or write function.
boeuf.readable('./Message.proto'); // 1.
boeuf.readable('./definitions.proto', 'Handshake'); // 2.
bouef.writable(myCustomWriteFn); // 3.

Custom read/write functions

Message framing is handled by the library, so a custom read/write function need only deal with reading and writing fields. Example read and write functions are given here but more information can be found under the mapbox/pbf library.

// o = object to write as message, pbf = instance of mapbox/pbf.
function myCustomWriteFunction(o, pbf) {
  if (o.name) pbf.writeStringField(1, o.name);
  if (o.flag) pbf.writeBooleanField(2, o.flag);
  if (o.size) pbf.writeFloatField(3, o.size);
}

// tag = the protocol buffer tag, o and pbf as above,
function myCustomReadFunction(tag, o, pbf) {
  if (tag === 1) o.name = pbf.readString();
  if (tag === 2) o.flag = pbf.readBoolean();
  if (tag === 3) o.size = pbf.readFloat();
}

Multiplexing

const multiplex = require('multiplex');
const boeuf = require('./src/boeuf');

// set up multiplexer...
let multiplexer = multiplex();
let fooWritable = boeuf.writable('./Foo.proto');
let barWritable = boeuf.writable('./Bar.proto');
fooWritable.pipe(multiplexer.createStream('1'));
barWritable.pipe(multiplexer.createStream('2'));

//...somewhere else set up demultiplexer
let demultiplexer = multiplex();
let fooReadable = boeuf.readable('./Foo.proto');
let barReadable = boeuf.readable('./Bar.proto');
demultiplexer.receiveStream('1').pipe(fooReadable);
demultiplexer.receiveStream('2').pipe(barReadable);

//connect the two
multiplexer.pipe(demultiplexer);

// write something
fooWritable.write({foo: 'hello world'});
barWritable.write({bar: 'hello world'});

Multiplexing can be used to send/receive different message formats over a single transport, or internally for making sure the correct message arrives at the correct parser.

Install

npm install boeuf