micro-packed
Advanced tools
Comparing version 0.4.0 to 0.5.0
13
index.ts
@@ -179,2 +179,3 @@ import { base64, bytes as baseBytes, hex as baseHex, str as baseStr, utf8 } from '@scure/base'; | ||
} | ||
return; | ||
} | ||
@@ -674,2 +675,3 @@ finish() { | ||
else if (def) inner.decodeStream(r); | ||
return; | ||
}, | ||
@@ -696,2 +698,3 @@ }); | ||
else if (def !== undefined) inner.decodeStream(r); | ||
return; | ||
}, | ||
@@ -705,3 +708,3 @@ }); | ||
size: inner.size, | ||
encodeStream: (w: Writer, value: undefined) => inner.encodeStream(w, constant), | ||
encodeStream: (w: Writer, _: undefined) => inner.encodeStream(w, constant), | ||
decodeStream: (r: Reader): undefined => { | ||
@@ -727,6 +730,6 @@ const value = inner.decodeStream(r); | ||
return wrap({ | ||
encodeStream: (w: Writer, value: T) => { | ||
encodeStream: (_: Writer, value: T) => { | ||
if (value !== c) throw new Error(`constant: invalid value ${value} (exp: ${c})`); | ||
}, | ||
decodeStream: (r: Reader): T => c, | ||
decodeStream: (_: Reader): T => c, | ||
}); | ||
@@ -738,3 +741,4 @@ } | ||
for (let f of fields) { | ||
if (!f.size) return; | ||
if (f.size === undefined) return; | ||
if (!Number.isSafeInteger(f.size)) throw new Error(`sizeof: wrong element size=${size}`); | ||
size += f.size; | ||
@@ -1107,2 +1111,3 @@ } | ||
const log = (name: string, rw: Reader | Writer, value: any) => { | ||
// @ts-ignore | ||
console.log(`DEBUG/${name}(${rw.fieldPath.join('/')}):`, { type: typeof value, value }); | ||
@@ -1109,0 +1114,0 @@ return value; |
{ | ||
"name": "micro-packed", | ||
"version": "0.4.0", | ||
"description": "Less painful binary encoding / decoding", | ||
"version": "0.5.0", | ||
"description": "Define complex binary structures using composable primitives.", | ||
"files": [ | ||
"index.js", | ||
"index.d.ts", | ||
"index.d.ts.map", | ||
"index.ts" | ||
"lib/index.js", | ||
"lib/debugger.js", | ||
"lib/esm/index.js", | ||
"lib/esm/debugger.js", | ||
"lib/index.d.ts", | ||
"lib/debugger.d.ts", | ||
"lib/index.d.ts.map", | ||
"lib/debugger.d.ts.map", | ||
"index.ts", | ||
"debugger.ts", | ||
"lib/esm/package.json" | ||
], | ||
"type": "module", | ||
"main": "index.js", | ||
"module": "index.js", | ||
"types": "index.d.ts", | ||
"main": "lib/index.js", | ||
"module": "lib/esm/index.js", | ||
"types": "lib/index.d.ts", | ||
"exports": { | ||
".": { | ||
"types": "./lib/index.d.ts", | ||
"import": "./lib/esm/index.js", | ||
"default": "./lib/index.js" | ||
}, | ||
"./debugger": { | ||
"types": "./lib/debugger.d.ts", | ||
"import": "./lib/esm/debugger.js", | ||
"default": "./lib/debugger.js" | ||
} | ||
}, | ||
"dependencies": { | ||
"@scure/base": "~1.1.5" | ||
}, | ||
"scripts": { | ||
"build": "tsc", | ||
"lint": "prettier --check index.ts", | ||
"format": "prettier --write index.ts", | ||
"test": "node test/index.js" | ||
"build": "tsc && tsc -p tsconfig.esm.json", | ||
"lint": "prettier --check index.ts debugger.ts", | ||
"format": "prettier --write index.ts debugger.ts", | ||
"test": "node test/index.js && node test/debugger.test.js" | ||
}, | ||
@@ -28,5 +49,2 @@ "author": "Paul Miller (https://paulmillr.com)", | ||
}, | ||
"dependencies": { | ||
"@scure/base": "~1.1.3" | ||
}, | ||
"devDependencies": { | ||
@@ -46,8 +64,3 @@ "micro-should": "0.4.0", | ||
], | ||
"funding": [ | ||
{ | ||
"type": "individual", | ||
"url": "https://paulmillr.com/funding/" | ||
} | ||
] | ||
"funding": "https://paulmillr.com/funding/" | ||
} |
@@ -5,6 +5,5 @@ # micro-packed | ||
Allows declarative definition for complex structures (like in C/Rust) via composable primitives, | ||
which enables encoding these structures into bytes and parsing back. | ||
Define complex binary structures using composable primitives. | ||
Comes with an separate [debugger package](./debugger/). | ||
Comes with a friendly debugger. | ||
@@ -34,5 +33,18 @@ ## Usage | ||
field8: P.array(null, P.U64BE), | ||
}) | ||
}); | ||
``` | ||
## Debugger | ||
```ts | ||
import * as PD from 'micro-packed/debugger'; | ||
PD.decode(<coder>, data); | ||
PD.diff(<coder>, actual, expected); | ||
``` | ||
![Decode](./test/screens/decode.png) | ||
![Diff](./test/screens/diff.png) | ||
## Utils | ||
@@ -39,0 +51,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
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
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
171156
14
4153
290
1
No
Updated@scure/base@~1.1.5