Comparing version 0.0.1 to 0.0.2
@@ -16,2 +16,3 @@ /*! | ||
const HashWriter = require('./hashwriter'); | ||
const Struct = require('./struct'); | ||
@@ -25,2 +26,3 @@ exports.encoding = encoding; | ||
exports.HashWriter = HashWriter; | ||
exports.Struct = Struct; | ||
@@ -27,0 +29,0 @@ exports.read = function read(data, zeroCopy) { |
@@ -92,3 +92,3 @@ /*! | ||
this.offset += off; | ||
return off; | ||
return this; | ||
} | ||
@@ -158,2 +158,3 @@ | ||
this.stack.length = 0; | ||
return this; | ||
} | ||
@@ -160,0 +161,0 @@ |
{ | ||
"name": "bufio", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Buffer and serialization utilities for javascript", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -21,2 +21,45 @@ # bufio | ||
## Struct Usage | ||
``` js | ||
const bio = require('bufio'); | ||
class MyStruct extends bio.Struct { | ||
constructor() { | ||
super(); | ||
this.str = 'hello'; | ||
this.value = 0; | ||
} | ||
write(bw) { | ||
bw.writeVarString(this.str, 'ascii'); | ||
bw.writeU64(this.value); | ||
return this; | ||
} | ||
read(br) { | ||
this.str = br.readVarString('ascii'); | ||
this.value = br.readU64(); | ||
return this; | ||
} | ||
} | ||
const obj = new MyStruct(); | ||
console.log('Buffer:'); | ||
console.log(obj.encode()); | ||
console.log('Decoded:'); | ||
console.log(MyStruct.decode(obj.encode())); | ||
console.log('Hex:'); | ||
console.log(obj.toHex()); | ||
console.log('Decoded:'); | ||
console.log(MyStruct.fromHex(obj.toHex())); | ||
console.log('Base64:'); | ||
console.log(obj.toBase64()); | ||
``` | ||
## Contribution and License Agreement | ||
@@ -23,0 +66,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
74278
16
3138
75