Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
protocol-buffers
Advanced tools
Encode/decode protocol buffers in node with stream support
npm install protocol-buffers
You should pass raw a .proto
file as a buffer (or you can specify the schema as json).
Per default the first message is used as the main one. Add an optional second argument to set it
to a specific message
Assuming the following test.proto
file exists
message Test {
required float num = 1;
required string payload = 2;
}
var protobuf = require('protocol-buffers');
var schema = protobuf(fs.readFileSync('test.proto'));
var buf = schema.encode({
num: 42,
payload: 'hello world'
});
console.log(buf); // should print a buffer
var obj = schema.decode(buf);
console.log(obj); // should print an object similar to above
You can also stream the encoding/decodings
var encoder = schema.createEncodeStream();
encoder.write({
num: 42,
payload: 'hello world'
});
encoder.write({
num: 43,
payload: 'hello another world'
});
...
encoder.on('data', function(buf) {
// buf is a buffer with the encoded object
});
And similarly if you wanted to decode
var decoder = schema.createDecodeStream();
decoder.write(buf);
decoder.on('data', function(obj) {
// obj is an unpacked object
});
Note that each buffer passed to decoder.write
should contain a full protobuf object so make sure
you do some sort of delimiting/length-prefixing first
In addition to passing in a raw proto file you can also specify the schema as JSON
var schema = protobuf([{
name: 'num',
type: 'float'
}, {
name: 'payload',
type: 'bytes'
}, {
name: 'some_nested_thing',
type: 'object',
fields: [{
name: 'another_prop',
type: 'string'
}]
}]);
MIT
FAQs
Protocol Buffers for Node.js
The npm package protocol-buffers receives a total of 19,219 weekly downloads. As such, protocol-buffers popularity was classified as popular.
We found that protocol-buffers demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.