bison-types
Advanced tools
Comparing version 3.0.1 to 3.0.2
{ | ||
"name": "bison-types", | ||
"version": "3.0.1", | ||
"version": "3.0.2", | ||
"description": "Convert between json and binary", | ||
@@ -28,3 +28,3 @@ "main": "target/index.js", | ||
"big.js": "~3.1.3", | ||
"clever-buffer": "^2.0.3", | ||
"clever-buffer": "^2.0.5", | ||
"lodash": "^4.13.1" | ||
@@ -31,0 +31,0 @@ }, |
@@ -85,2 +85,3 @@ # bison-types | ||
* `utf-8` - utf-8 encoded string | ||
* `latin1` - latin1 encoded string | ||
* `bool` - boolean (stored as 8 bit integer) | ||
@@ -188,2 +189,30 @@ * `skip` - will skip specified bytes | ||
### Reading a string with latin1 encoding | ||
```coffee | ||
bison = require 'bison-types' | ||
buf = new Buffer [0x48, 0xC9, 0x4C, 0x4C, 0x4F] | ||
types = bison.preCompile | ||
my-type: [ | ||
a: 'latin1(5)' | ||
] | ||
options = {bigEndian: false} | ||
reader = new bison.Reader buf, types, options | ||
myType = reader.read('my-type') # myType = { a: 'HELLO' } | ||
``` | ||
### Reading a multi-byte string | ||
```coffee | ||
bison = require 'bison-types' | ||
buf = new Buffer [0x48, 0xC3, 0x89, 0x4C, 0x4C, 0x4F] | ||
types = bison.preCompile | ||
my-type: [ | ||
a: 'utf-8(6)' | ||
] | ||
options = {bigEndian: false} | ||
reader = new bison.Reader buf, types, options | ||
myType = reader.read('my-type') # myType = { a: 'HÉLLO' } | ||
``` | ||
### Complex types | ||
@@ -286,2 +315,17 @@ The power of bison-types is evident as you define more complex types | ||
### Writing a string with latin1 encoding | ||
```coffee | ||
bison = require 'bison-types' | ||
buf = new Buffer 5 | ||
types = bison.preCompile | ||
my-type: [ | ||
a: 'latin1' | ||
] | ||
options = {bigEndian: false} | ||
writer = new bison.Writer buf, types, options | ||
writer.write 'my-type', { a: 'HÉLLO' } | ||
# buf will equal [0x48, 0xC9, 0x4C, 0x4C, 0x4F] | ||
``` | ||
### Only writing a certain length of string | ||
@@ -302,2 +346,17 @@ ```coffee | ||
### Writing a multi-byte string | ||
```coffee | ||
bison = require 'bison-types' | ||
buf = new Buffer 6 | ||
types = bison.preCompile | ||
my-type: [ | ||
a: 'utf-8' | ||
] | ||
options = {bigEndian: false} | ||
writer = new bison.Writer buf, types, options | ||
writer.write 'my-type', { a: 'HÉLLO' } | ||
# buf will equal [0x48, 0xC3, 0x89, 0x4C, 0x4C, 0x4F] | ||
``` | ||
### Complex types | ||
@@ -304,0 +363,0 @@ The power of bison-types is evident as you define more complex types |
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.10.0 | ||
// Generated by CoffeeScript 1.11.1 | ||
(function() { | ||
@@ -3,0 +3,0 @@ var _, util; |
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.10.0 | ||
// Generated by CoffeeScript 1.11.1 | ||
(function() { | ||
@@ -3,0 +3,0 @@ exports.Reader = require("./reader"); |
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.10.0 | ||
// Generated by CoffeeScript 1.11.1 | ||
(function() { | ||
@@ -3,0 +3,0 @@ var _, commonTypes, getTypeDefinition, typeHelper; |
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.10.0 | ||
// Generated by CoffeeScript 1.11.1 | ||
(function() { | ||
@@ -3,0 +3,0 @@ var CleverBufferReader, Reader, _, preCompile, typeHelper, |
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.10.0 | ||
// Generated by CoffeeScript 1.11.1 | ||
(function() { | ||
@@ -3,0 +3,0 @@ var exp; |
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.10.0 | ||
// Generated by CoffeeScript 1.11.1 | ||
(function() { | ||
@@ -68,2 +68,15 @@ module.exports = { | ||
}, | ||
'latin1': { | ||
_read: function(length) { | ||
return this.buffer.getString({ | ||
length: length, | ||
encoding: 'binary' | ||
}); | ||
}, | ||
_write: function(val) { | ||
return this.buffer.writeString(val, { | ||
encoding: 'binary' | ||
}); | ||
} | ||
}, | ||
'utf-8': { | ||
@@ -70,0 +83,0 @@ _read: function(length) { |
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.10.0 | ||
// Generated by CoffeeScript 1.11.1 | ||
(function() { | ||
@@ -3,0 +3,0 @@ var CleverBufferWriter, Writer, _, preCompile, typeHelper, |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
25377
389
458
0
Updatedclever-buffer@^2.0.5