compact-encoding
Advanced tools
+38
-0
@@ -108,2 +108,24 @@ const b4a = require('b4a') | ||
| const uint32be = (exports.uint32be = { | ||
| preencode(state, n) { | ||
| state.end += 4 | ||
| }, | ||
| encode(state, n) { | ||
| validateUint(n) | ||
| state.buffer[state.start++] = n >>> 24 | ||
| state.buffer[state.start++] = n >>> 16 | ||
| state.buffer[state.start++] = n >>> 8 | ||
| state.buffer[state.start++] = n | ||
| }, | ||
| decode(state) { | ||
| if (state.end - state.start < 4) throw new Error('Out of bounds') | ||
| return ( | ||
| state.buffer[state.start++] * 0x1000000 + | ||
| state.buffer[state.start++] * 0x10000 + | ||
| state.buffer[state.start++] * 0x100 + | ||
| state.buffer[state.start++] | ||
| ) | ||
| } | ||
| }) | ||
| const uint40 = (exports.uint40 = { | ||
@@ -173,2 +195,18 @@ preencode(state, n) { | ||
| exports.uint64be = { | ||
| preencode(state, n) { | ||
| state.end += 8 | ||
| }, | ||
| encode(state, n) { | ||
| validateUint(n) | ||
| const r = Math.floor(n / 0x100000000) | ||
| uint32be.encode(state, r) | ||
| uint32be.encode(state, n) | ||
| }, | ||
| decode(state) { | ||
| if (state.end - state.start < 8) throw new Error('Out of bounds') | ||
| return 0x100000000 * uint32be.decode(state) + uint32be.decode(state) | ||
| } | ||
| } | ||
| const int = (exports.int = zigZagInt(uint)) | ||
@@ -175,0 +213,0 @@ exports.int8 = zigZagInt(uint8) |
+1
-1
| { | ||
| "name": "compact-encoding", | ||
| "version": "3.0.1", | ||
| "version": "3.1.0", | ||
| "description": "A series of compact encoding schemes for building small and fast parsers and serializers", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
53226
1.85%1240
2.99%