{"_id":"compact-encoding@3.6.0","bugs":{"url":"https://github.com/holepunchto/compact-encoding/issues"},"dist":{"shasum":"7f61ac1fd48f47e73f2762850de8a76968c9da0d","tarball":"http://registry-npm.ywwl.com/compact-encoding/download/compact-encoding-3.6.0.tgz","fileCount":11,"integrity":"sha512-+VVXplmZBKLpmuU0SersD3p2bD9ZzdlP4E7NrZLL1sJ/YiferaRm2aJKVs/HvxHCWtCu644RBUoAJp8Vic3+kg==","signatures":[{"sig":"MEQCIFZfqYcADTLQTgkqSOc3e1rBjAKotOqb03rTsAFIe+YJAiAsySyVONJQH90KigkOB8YBrqQNWzk4yLFqrl5OIbd7pg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQC2S4WKWd4vu+FxGWjjafTYoIWbUCHjSW4POACyW1E4jAIgW7uV3uwtDD4M3HVgQuNr4MqJ0xOLc4ePk3GEsXKwADw="}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/compact-encoding@3.6.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":75489,"size":16350,"noattachment":false,"key":"/compact-encoding/-/compact-encoding-3.6.0.tgz"},"name":"compact-encoding","types":"./index.d.ts","author":{"url":"@mafintosh","name":"Mathias Buus"},"exports":{".":{"types":"./index.d.ts","default":"./index.js"},"./raw":{"types":"./raw.d.ts","default":"./raw.js"},"./endian":{"types":"./endian.d.ts","default":"./endian.js"},"./lexint":{"types":"./lexint.d.ts","default":"./lexint.js"},"./package":"./package.json"},"gitHead":"1e8833d49ea068391bbcaae39cf2428f05dd495b","license":"Apache-2.0","scripts":{"lint":"prettier --check . && lunte","test":"npm run test:bare && npm run test:node","format":"prettier --write . && lunte --fix","test:bare":"brittle-bare --coverage test.js","test:node":"brittle-node --coverage test.js"},"version":"3.6.0","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"44d1a455-c25d-4327-b46f-a5f957453909"}},"homepage":"https://github.com/holepunchto/compact-encoding#readme","repository":{"url":"git+https://github.com/holepunchto/compact-encoding.git","type":"git"},"_npmVersion":"11.20.0","description":"A series of compact encoding schemes for building small and fast parsers and serializers","directories":{},"maintainers":[{"name":"mafintosh","email":"mathiasbuus@gmail.com"}],"_nodeVersion":"26.13.0","dependencies":{"b4a":"^1.3.0"},"_hasShrinkwrap":false,"devDependencies":{"lunte":"^1.8.6","brittle":"^4.0.0","prettier":"^3.6.2","prettier-config-holepunch":"^2.0.0"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/compact-encoding_3.6.0_1793976682557_0.5810362341853678"},"readme":"# compact-encoding\n\nA series of compact encoding schemes for building small and fast parsers and serializers\n\n```\nnpm install compact-encoding\n```\n\n## Usage\n\n```js\nconst cenc = require('compact-encoding')\n\nconst state = cenc.state()\n\n// use preencode to figure out how big a buffer is needed\ncenc.uint.preencode(state, 42)\ncenc.string.preencode(state, 'hi')\n\nconsole.log(state) // { start: 0, end: 4, buffer: null }\n\nstate.buffer = Buffer.allocUnsafe(state.end)\n\n// then use encode to actually encode it to the buffer\ncenc.uint.encode(state, 42)\ncenc.string.encode(state, 'hi')\n\n// to decode it simply use decode instead\n\nstate.start = 0\ncenc.uint.decode(state) // 42\ncenc.string.decode(state) // 'hi'\n```\n\n## Encoder API\n\n#### `state`\n\nShould be an object that looks like this `{ start, end, buffer }`.\n\nYou can also get a blank state object using `cenc.state()`.\n\n- `start` is the byte offset to start encoding/decoding at.\n- `end` is the byte offset indicating the end of the buffer.\n- `buffer` should be either a Node.js Buffer or Uint8Array.\n\n#### `enc.preencode(state, val)`\n\nDoes a fast preencode dry-run that only sets state.end.\nUse this to figure out how big of a buffer you need.\n\n`preencode` is not guaranteed to reject an invalid `val`. `encode` is where a value is checked.\n\n#### `enc.encode(state, val)`\n\nEncodes `val` into `state.buffer` at position `state.start`.\nUpdates `state.start` to point after the encoded value when done.\n\n#### `val = enc.decode(state)`\n\nDecodes a value from `state.buffer` as position `state.start`.\nUpdates `state.start` to point after the decoded value when done in the buffer.\n\n## Helpers\n\nIf you are just encoding to a buffer or decoding from one you can use the `encode` and `decode` helpers\nto reduce your boilerplate\n\n```js\nconst buf = cenc.encode(cenc.bool, true)\nconst bool = cenc.decode(cenc.bool, buf)\n```\n\n## Bundled encodings\n\nThe following encodings are bundled as they are primitives that can be used\nto build others on top. Feel free to PR more that are missing.\n\n- `cenc.raw` - Pass through encodes a buffer, i.e. a basic copy.\n- `cenc.uint` - Encodes a uint using the smallest fixed size encoding with a prefix to signal which one. Useful for uints that can be a wide range of values.\n- `cenc.uint8` - Encodes a fixed size uint8.\n- `cenc.uint16` - Encodes a fixed size uint16. Useful for things like ports.\n- `cenc.uint24` - Encodes a fixed size uint24. Useful for message framing.\n- `cenc.uint32` - Encodes a fixed size uint32. Useful for very large message framing.\n- `cenc.uint40` - Encodes a fixed size uint40.\n- `cenc.uint48` - Encodes a fixed size uint48.\n- `cenc.uint56` - Encodes a fixed size uint56.\n- `cenc.uint64` - Encodes a fixed size uint64.\n- `cenc.int` - Encodes an int using `cenc.uint` with ZigZag encoding.\n- `cenc.int8` - Encodes a fixed size int8 using `cenc.uint8` with ZigZag encoding.\n- `cenc.int16` - Encodes a fixed size int16 using `cenc.uint16` with ZigZag encoding.\n- `cenc.int24` - Encodes a fixed size int24 using `cenc.uint24` with ZigZag encoding.\n- `cenc.int32` - Encodes a fixed size int32 using `cenc.uint32` with ZigZag encoding.\n- `cenc.int40` - Encodes a fixed size int40 using `cenc.uint40` with ZigZag encoding.\n- `cenc.int48` - Encodes a fixed size int48 using `cenc.uint48` with ZigZag encoding.\n- `cenc.int56` - Encodes a fixed size int56 using `cenc.uint56` with ZigZag encoding.\n- `cenc.int64` - Encodes a fixed size int64 using `cenc.uint64` with ZigZag encoding.\n- `cenc.biguint64` - Encodes a fixed size biguint64.\n- `cenc.bigint64` - Encodes a fixed size bigint64 using `cenc.biguint64` with ZigZag encoding.\n- `cenc.biguint` - Encodes a biguint with its word count uint prefixed.\n- `cenc.bigint` - Encodes a bigint using `cenc.biguint` with ZigZag encoding.\n- `cenc.float32` - Encodes a fixed size float32.\n- `cenc.float64` - Encodes a fixed size float64.\n- `cenc.buffer` - Encodes a buffer with its length uint prefixed.\n- `cenc.optionalBuffer` - Like `cenc.buffer`, but also accepts `null`. An empty buffer and `null` both encode as length 0, which decodes as `null`.\n- `cenc.raw.buffer` - Encodes a buffer without a length prefixed.\n- `cenc.arraybuffer` - Encodes an arraybuffer with its length uint prefixed.\n- `cenc.raw.arraybuffer` - Encodes an arraybuffer without a length prefixed.\n- `cenc.uint8array` - Encodes a uint8array with its element length uint prefixed.\n- `cenc.raw.uint8array` - Encodes a uint8array without a length prefixed.\n- `cenc.uint16array` - Encodes a uint16array with its element length uint prefixed.\n- `cenc.raw.uint16array` - Encodes a uint16array without a length prefixed.\n- `cenc.uint32array` - Encodes a uint32array with its element length uint prefixed.\n- `cenc.raw.uint32array` - Encodes a uint32array without a length prefixed.\n- `cenc.int8array` - Encodes a int8array with its element length uint prefixed.\n- `cenc.raw.int8array` - Encodes a int8array without a length prefixed.\n- `cenc.int16array` - Encodes a int16array with its element length uint prefixed.\n- `cenc.raw.int16array` - Encodes a int16array without a length prefixed.\n- `cenc.int32array` - Encodes a int32array with its element length uint prefixed.\n- `cenc.raw.int32array` - Encodes a int32array without a length prefixed.\n- `cenc.biguint64array` - Encodes a biguint64array with its element length uint prefixed.\n- `cenc.raw.biguint64array` - Encodes a biguint64array without a length prefixed.\n- `cenc.bigint64array` - Encodes a bigint64array with its element length uint prefixed.\n- `cenc.raw.bigint64array` - Encodes a bigint64array without a length prefixed.\n- `cenc.float32array` - Encodes a float32array with its element length uint prefixed.\n- `cenc.raw.float32array` - Encodes a float32array without a length prefixed.\n- `cenc.float64array` - Encodes a float64array with its element length uint prefixed.\n- `cenc.raw.float64array` - Encodes a float64array without a length prefixed.\n- `cenc.bitarray` - Encodes an array of bits or booleans with its length uint prefixed. Decoding returns array of booleans.\n- `cenc.bool` - Encodes a boolean as 1 or 0.\n- `cenc.string`, `cenc.utf8` - Encodes a utf-8 string, similar to buffer.\n- `cenc.raw.string`, `cenc.raw.utf8` - Encodes a utf-8 string without a length prefixed.\n- `cenc.string.fixed(n)`, `cenc.utf8.fixed(n)` - Encodes a fixed sized utf-8 string.\n- `cenc.ascii` - Encodes an ascii string.\n- `cenc.raw.ascii` - Encodes an ascii string without a length prefixed.\n- `cenc.ascii.fixed(n)` - Encodes a fixed size ascii string.\n- `cenc.hex` - Encodes a hex string.\n- `cenc.raw.hex` - Encodes a hex string without a length prefixed.\n- `cenc.hex.fixed(n)` - Encodes a fixed size hex string.\n- `cenc.base64` - Encodes a base64 string.\n- `cenc.raw.base64` - Encodes a base64 string without a length prefixed.\n- `cenc.base64.fixed(n)` - Encodes a fixed size base64 string.\n- `cenc.utf16le`, `cenc.ucs2` - Encodes a utf16le string.\n- `cenc.raw.utf16le`, `cenc.raw.ucs2` - Encodes a utf16le string without a length prefixed.\n- `cenc.utf16le.fixed(n)`, `cenc.ucs2.fixed(n)` - Encodes a fixed size utf16le string.\n- `cenc.fixed8` - Encodes a fixed 8 byte buffer.\n- `cenc.fixed16` - Encodes a fixed 16 byte buffer.\n- `cenc.fixed24` - Encodes a fixed 24 byte buffer.\n- `cenc.fixed32` - Encodes a fixed 32 byte buffer.\n- `cenc.fixed64` - Encodes a fixed 64 byte buffer.\n- `cenc.fixed(n)` - Makes a fixed sized encoder.\n- `cenc.date(d)` - Encodes a date object.\n- `cenc.array(enc)` - Makes an array encoder from another encoder. Arrays are uint prefixed with their length.\n- `cenc.raw.array(enc)` - Makes an array encoder from another encoder, without a length prefixed.\n- `cenc.record(keyEnc, valueEnc)` - Makes a record encoder from a key and a value encoder. Keys are always strings, so `keyEnc` has to be a string encoding. Records are uint prefixed with their number of pairs. The order the pairs are written in is undefined, so two encoders may order the same record differently.\n- `cenc.stringRecord` - Encodes a record of strings to strings.\n- `cenc.orderedRecord(keyEnc, valueEnc)` - Same as `cenc.record`, but the keys are sorted before being written, so a record encodes to the same bytes whatever order its keys were set in. Keys sort by their own utf-8 bytes rather than by what `keyEnc` writes, which is the comparison every language can reproduce. Keys that encode to the same bytes, two different unpaired surrogates say, keep the order they were set in.\n- `cenc.orderedStringRecord` - Encodes a record of strings to strings, with the keys sorted.\n- `cenc.json` - Encodes a JSON value as utf-8.\n- `cenc.raw.json` - Encodes a JSON value as utf-8 without a length prefixed.\n- `cenc.ndjson` - Encodes a JSON value as newline delimited utf-8.\n- `cenc.raw.ndjson` - Encodes a JSON value as newline delimited utf-8 without a length prefixed.\n- `cenc.any` - Encodes any JSON representable value into a self described buffer. Like JSON + buffer, but using compact types. Useful for schemaless codecs.\n- `cenc.port` - Encodes a port number for network addresses.\n- `cenc.ipv4` - Encodes an IPv4 network address.\n- `cenc.ipv4Address` Encodes an IPv4 network address and a port number.\n- `cenc.ipv6` - Encodes an IPv6 network address.\n- `cenc.ipv6Address` Encodes an IPv6 network address and a port number.\n- `cenc.ip` - Encodes a dual IPv4/6 network address.\n- `cenc.ipAddress` Encodes a dual IPv4/6 network address and a port number.\n- `cenc.from(enc)` - Makes a compact encoder from a [codec](https://github.com/mafintosh/codecs) or [abstract-encoding](https://github.com/mafintosh/abstract-encoding).\n- `cenc.none` - Helper for when you want to just express nothing\n\n## License\n\nApache 2.0\n","publish_time":1793976682658,"_cnpm_publish_time":1793976682658,"dist-tags":{"latest":"3.7.1"}}