
Research
Security News
Lazarus Strikes npm Again with New Wave of Malicious Packages
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
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 50,237 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.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.
Security News
Opengrep continues building momentum with the alpha release of its Playground tool, demonstrating the project's rapid evolution just two months after its initial launch.