bin-protocol
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -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 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
68427
173