compact-encoding
Advanced tools
Comparing version 2.12.0 to 2.13.0
27
index.js
@@ -381,2 +381,29 @@ const b4a = require('b4a') | ||
exports.frame = function frame (enc) { | ||
const dummy = exports.state() | ||
return { | ||
preencode (state, m) { | ||
const end = state.end | ||
enc.preencode(state, m) | ||
uint.preencode(state, state.end - end) | ||
}, | ||
encode (state, m) { | ||
dummy.end = 0 | ||
enc.preencode(dummy, m) | ||
uint.encode(state, dummy.end) | ||
enc.encode(state, m) | ||
}, | ||
decode (state) { | ||
const end = state.end | ||
const len = uint.decode(state) | ||
state.end = state.start + len | ||
const m = enc.decode(state) | ||
state.start = state.end | ||
state.end = end | ||
return m | ||
} | ||
} | ||
} | ||
exports.json = { | ||
@@ -383,0 +410,0 @@ preencode (state, v) { |
{ | ||
"name": "compact-encoding", | ||
"version": "2.12.0", | ||
"version": "2.13.0", | ||
"description": "A series of compact encoding schemes for building small and fast parsers and serializers", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -674,1 +674,9 @@ const enc = require('./') | ||
}) | ||
test('framed', function (t) { | ||
const e = enc.frame(enc.uint) | ||
t.alike(enc.encode(e, 42), b4a.from([0x01, 0x2a])) | ||
t.alike(enc.decode(e, b4a.from([0x01, 0x2a])), 42) | ||
t.alike(enc.encode(e, 4200), b4a.from([0x03, 0xfd, 0x68, 0x10])) | ||
t.alike(enc.decode(e, b4a.from([0x03, 0xfd, 0x68, 0x10])), 4200) | ||
}) |
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
62245
1336