Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bin-protocol

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bin-protocol - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

2

package.json

@@ -9,3 +9,3 @@ {

},
"version": "1.0.2",
"version": "1.0.3",
"main": "./lib/index.js",

@@ -12,0 +12,0 @@ "keywords": ["buffer"],

@@ -42,2 +42,4 @@ # bin-protocol

Built-in metods:
```javascript

@@ -57,2 +59,4 @@ var protocol = require('bin-protocol');

Define custom 'char' and 'array' methods:
```javascript

@@ -115,4 +119,32 @@ var protocol = require('bin-protocol');

See tests for more.
Define reader and writer methods together, this one writes (or reads) raw buffer preceeded by its length as 32 bit integer.
```javascript
protocol.define('bytes', {
read: function() {
this.Int32BE('length');
if(this.context.length <= 0){
return null;
}
this.raw('value', this.context.length);
return this.context.value;
},
write: function(value) {
if (value === undefined || value === null) {
this.Int32BE(-1);
} else {
if(Buffer.isBuffer(value) || typeof value === 'string'){
this
.Int32BE(value.length)
.raw(value);
} else {
throw new Error('Kafka bytes value should be a Buffer or String');
}
}
}
});
```
See [Kafka protocol](https://github.com/oleksiyk/kafka/tree/master/lib/protocol) for more examples.
# License (MIT)

@@ -119,0 +151,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc