{"_id":"bun-ffi-structs","_rev":"9-5af623b3ff2b42ce0aff8097f6f8fb46","name":"bun-ffi-structs","dist-tags":{"latest":"0.3.1"},"versions":{"0.1.0":{"name":"bun-ffi-structs","version":"0.1.0","license":"MIT","_id":"bun-ffi-structs@0.1.0","maintainers":[{"name":"kommander","email":"rootkid815@gmail.com"}],"dist":{"shasum":"1a9c61d58cce60669ea84ccbee5032c0cab6b12d","tarball":"https://registry.npmjs.org/bun-ffi-structs/-/bun-ffi-structs-0.1.0.tgz","fileCount":8,"integrity":"sha512-NoRfJ81pgLIHCzw624/2GS2FuxcU0G4SRJww/4PXvheNVUPSIUjkOC6v1/8rk66tJVCb9oR0D6rDNKK0qT5O2Q==","signatures":[{"sig":"MEUCIHGTo/EJTdqfHHjgMCMw1QQgHoxeANEG66Fex8YhK0d1AiEArXCEQirMZysbEBYprksencdoV50nxjXNr2JIWb/TNY0=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":34032},"main":"index.js","type":"module","types":"index.d.ts","module":"index.js","shasum":"1a9c61d58cce60669ea84ccbee5032c0cab6b12d","scripts":{"test":"bun test","bench":"bun run bench/structs.bench.ts","build":"./scripts/build.sh","prettier:check":"bun prettier --check .","prettier:write":"bun prettier --write ."},"_npmUser":{"name":"kommander","email":"rootkid815@gmail.com"},"prettier":{"semi":false,"printWidth":120},"_integrity":"sha512-NoRfJ81pgLIHCzw624/2GS2FuxcU0G4SRJww/4PXvheNVUPSIUjkOC6v1/8rk66tJVCb9oR0D6rDNKK0qT5O2Q==","repository":{"url":"https://github.com/sst/bun-ffi-structs.git","type":"git"},"_npmVersion":"10.8.3","directories":{},"_nodeVersion":"24.3.0","_hasShrinkwrap":false,"devDependencies":{"prettier":"3.6.2","tinybench":"^5.0.1","@types/bun":"latest"},"peerDependencies":{"typescript":"^5"},"_npmOperationalInternal":{"tmp":"tmp/bun-ffi-structs_0.1.0_1761073072981_0.6959228776489845","host":"s3://npm-registry-packages-npm-production"}},"0.1.1":{"name":"bun-ffi-structs","version":"0.1.1","license":"MIT","_id":"bun-ffi-structs@0.1.1","maintainers":[{"name":"kommander","email":"rootkid815@gmail.com"}],"dist":{"shasum":"4f888640f59439e43e5feb3400b502a083e87802","tarball":"https://registry.npmjs.org/bun-ffi-structs/-/bun-ffi-structs-0.1.1.tgz","fileCount":8,"integrity":"sha512-Um8Kc4RCjxDQ9nFMrit4VaPHfbBW8xbeXH2csLXIEP/45CaeVoUec9X6i19khBxODsDNNZ1VC9EGYhjYa4Ptag==","signatures":[{"sig":"MEUCIFilMNtKLN7XPGZecVQ4TUswjxR6ecmvZ/FYXXFwwChzAiEA3Gts71/9+TJBBNXP0aiUQZl94q4zf44/+FNioB/PA10=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":34700},"main":"index.js","type":"module","types":"index.d.ts","module":"index.js","shasum":"4f888640f59439e43e5feb3400b502a083e87802","scripts":{"test":"bun test","bench":"bun run bench/structs.bench.ts","build":"./scripts/build.sh","prettier:check":"bun prettier --check .","prettier:write":"bun prettier --write ."},"_npmUser":{"name":"kommander","email":"rootkid815@gmail.com"},"prettier":{"semi":false,"printWidth":120},"_integrity":"sha512-Um8Kc4RCjxDQ9nFMrit4VaPHfbBW8xbeXH2csLXIEP/45CaeVoUec9X6i19khBxODsDNNZ1VC9EGYhjYa4Ptag==","repository":{"url":"https://github.com/sst/bun-ffi-structs.git","type":"git"},"_npmVersion":"10.8.3","directories":{},"_nodeVersion":"24.3.0","_hasShrinkwrap":false,"devDependencies":{"prettier":"3.6.2","tinybench":"^5.0.1","@types/bun":"latest"},"peerDependencies":{"typescript":"^5"},"_npmOperationalInternal":{"tmp":"tmp/bun-ffi-structs_0.1.1_1762864870460_0.26324757803313337","host":"s3://npm-registry-packages-npm-production"}},"0.1.2":{"name":"bun-ffi-structs","version":"0.1.2","license":"MIT","_id":"bun-ffi-structs@0.1.2","maintainers":[{"name":"kommander","email":"rootkid815@gmail.com"}],"dist":{"shasum":"afedf28e9df08eab628032896511d4987eb269ec","tarball":"https://registry.npmjs.org/bun-ffi-structs/-/bun-ffi-structs-0.1.2.tgz","fileCount":8,"integrity":"sha512-Lh1oQAYHDcnesJauieA4UNkWGXY9hYck7OA5IaRwE3Bp6K2F2pJSNYqq+hIy7P3uOvo3km3oxS8304g5gDMl/w==","signatures":[{"sig":"MEUCIQC2d6GLOh+Y4XUpnDVClz9lX/cKZ8/54cUHnyDkgfo0wwIgSFdvqTbFhcUy1AfZe/0dS0sNu3LS6TI/DAxAoMKCLQU=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":35221},"main":"index.js","type":"module","types":"index.d.ts","module":"index.js","shasum":"afedf28e9df08eab628032896511d4987eb269ec","scripts":{"test":"bun test","bench":"bun run bench/structs.bench.ts","build":"./scripts/build.sh","prettier:check":"bun prettier --check .","prettier:write":"bun prettier --write ."},"_npmUser":{"name":"kommander","email":"rootkid815@gmail.com"},"prettier":{"semi":false,"printWidth":120},"_integrity":"sha512-Lh1oQAYHDcnesJauieA4UNkWGXY9hYck7OA5IaRwE3Bp6K2F2pJSNYqq+hIy7P3uOvo3km3oxS8304g5gDMl/w==","repository":{"url":"https://github.com/sst/bun-ffi-structs.git","type":"git"},"_npmVersion":"10.8.3","directories":{},"_nodeVersion":"24.3.0","_hasShrinkwrap":false,"devDependencies":{"prettier":"3.6.2","tinybench":"^5.0.1","@types/bun":"latest"},"peerDependencies":{"typescript":"^5"},"_npmOperationalInternal":{"tmp":"tmp/bun-ffi-structs_0.1.2_1762871118423_0.43826058826350267","host":"s3://npm-registry-packages-npm-production"}},"0.2.1":{"name":"bun-ffi-structs","version":"0.2.1","license":"MIT","_id":"bun-ffi-structs@0.2.1","maintainers":[{"name":"kommander","email":"rootkid815@gmail.com"}],"dist":{"shasum":"235319b32f1553f6ea202210ae267c2a63695832","tarball":"https://registry.npmjs.org/bun-ffi-structs/-/bun-ffi-structs-0.2.1.tgz","fileCount":9,"integrity":"sha512-O+EpRGOPHZ1GxFEv92mjVa8qitK7x9PnoG6cowNWMHLPCA6TjIye+jaQJd5dcdj4sSyIdght6axxOgwQ5zIoNw==","signatures":[{"sig":"MEUCIHVRCmfdGQTDw+w1lKsFVbfyQklBz9R92W9BwTcNEhv4AiEA+MqMHHEu8mbQ8kdlr4PysvbplbQ6VMciliAnN8FERWM=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":39138},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","shasum":"235319b32f1553f6ea202210ae267c2a63695832","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"scripts":{"test":"bun test","bench":"bun run bench/structs.bench.ts","build":"./scripts/build.sh","prettier:check":"bun prettier --check .","prettier:write":"bun prettier --write ."},"_npmUser":{"name":"kommander","email":"rootkid815@gmail.com"},"prettier":{"semi":false,"printWidth":120},"_integrity":"sha512-O+EpRGOPHZ1GxFEv92mjVa8qitK7x9PnoG6cowNWMHLPCA6TjIye+jaQJd5dcdj4sSyIdght6axxOgwQ5zIoNw==","repository":{"url":"https://github.com/sst/bun-ffi-structs.git","type":"git"},"_npmVersion":"10.8.3","directories":{},"_nodeVersion":"24.3.0","_hasShrinkwrap":false,"devDependencies":{"prettier":"3.6.2","tinybench":"^5.0.1","@types/bun":"latest"},"peerDependencies":{"typescript":"^5"},"_npmOperationalInternal":{"tmp":"tmp/bun-ffi-structs_0.2.1_1777406122650_0.887643554879139","host":"s3://npm-registry-packages-npm-production"}},"0.2.2":{"name":"bun-ffi-structs","version":"0.2.2","license":"MIT","_id":"bun-ffi-structs@0.2.2","maintainers":[{"name":"kommander","email":"rootkid815@gmail.com"}],"dist":{"shasum":"a9e735133d0227f0b61a484fc1f833091a618c2c","tarball":"https://registry.npmjs.org/bun-ffi-structs/-/bun-ffi-structs-0.2.2.tgz","fileCount":9,"integrity":"sha512-N/ZWtyN0piZlrXQT7TO0V+q952orYqkfhXRXM1Hcbb+R3QSiBH4vLnib187Mrs1H7pWIYECAmPeapGYDOMCl+w==","signatures":[{"sig":"MEYCIQD+yvWwYC+cBtMiRKbCb5x/P+O5gxTbOD2W0+Bs29ZB6gIhAOA7QPb2f7txWfCBUWeMDZt6pVTCyZPElmygQI30J7oE","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":39389},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","shasum":"a9e735133d0227f0b61a484fc1f833091a618c2c","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"scripts":{"test":"bun test","bench":"bun run bench/structs.bench.ts","build":"./scripts/build.sh","prettier:check":"bun prettier --check .","prettier:write":"bun prettier --write ."},"_npmUser":{"name":"kommander","email":"rootkid815@gmail.com"},"prettier":{"semi":false,"printWidth":120},"_integrity":"sha512-N/ZWtyN0piZlrXQT7TO0V+q952orYqkfhXRXM1Hcbb+R3QSiBH4vLnib187Mrs1H7pWIYECAmPeapGYDOMCl+w==","repository":{"url":"https://github.com/sst/bun-ffi-structs.git","type":"git"},"_npmVersion":"10.8.3","directories":{},"_nodeVersion":"24.3.0","_hasShrinkwrap":false,"devDependencies":{"prettier":"3.6.2","tinybench":"^5.0.1","@types/bun":"latest"},"peerDependencies":{"typescript":"^5"},"_npmOperationalInternal":{"tmp":"tmp/bun-ffi-structs_0.2.2_1777537515576_0.7951545126055173","host":"s3://npm-registry-packages-npm-production"}},"0.2.3":{"name":"bun-ffi-structs","version":"0.2.3","license":"MIT","_id":"bun-ffi-structs@0.2.3","maintainers":[{"name":"kommander","email":"rootkid815@gmail.com"}],"dist":{"shasum":"f5cbf0f0d03f0e77dd6e8beb9137a581a6a6bdca","tarball":"https://registry.npmjs.org/bun-ffi-structs/-/bun-ffi-structs-0.2.3.tgz","fileCount":9,"integrity":"sha512-pgJiXP+hEgFo9qG51J6ItfY4ocs3vniwNzJ9WhoakB3QB2GdzQxX2EXssentPYlB2hOfJrTjO6iIQkWYzUodpg==","signatures":[{"sig":"MEUCIQDUgGuSRJ6pztK4yY9M83UWnv3UjJ17qNtgONFAZcoEnwIgfVyYYbNGFapaC1Lasxir94st3/lEEVF/vBnK/B8xSos=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":39633},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","shasum":"f5cbf0f0d03f0e77dd6e8beb9137a581a6a6bdca","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"scripts":{"test":"bun test","bench":"bun run bench/structs.bench.ts","build":"./scripts/build.sh","prettier:check":"bun prettier --check .","prettier:write":"bun prettier --write ."},"_npmUser":{"name":"kommander","email":"rootkid815@gmail.com"},"prettier":{"semi":false,"printWidth":120},"_integrity":"sha512-pgJiXP+hEgFo9qG51J6ItfY4ocs3vniwNzJ9WhoakB3QB2GdzQxX2EXssentPYlB2hOfJrTjO6iIQkWYzUodpg==","repository":{"url":"https://github.com/sst/bun-ffi-structs.git","type":"git"},"_npmVersion":"10.8.3","directories":{},"_nodeVersion":"24.3.0","_hasShrinkwrap":false,"devDependencies":{"prettier":"3.6.2","tinybench":"^5.0.1","@types/bun":"latest"},"peerDependencies":{"typescript":"^5"},"_npmOperationalInternal":{"tmp":"tmp/bun-ffi-structs_0.2.3_1778534918869_0.6655894131072089","host":"s3://npm-registry-packages-npm-production"}},"0.2.4":{"name":"bun-ffi-structs","version":"0.2.4","license":"MIT","_id":"bun-ffi-structs@0.2.4","maintainers":[{"name":"kommander","email":"rootkid815@gmail.com"}],"dist":{"shasum":"e23e4120d9ebe47efb70b8ce459c834e7c7d7cb0","tarball":"https://registry.npmjs.org/bun-ffi-structs/-/bun-ffi-structs-0.2.4.tgz","fileCount":9,"integrity":"sha512-AJzsqoVFs1KBbJbWHIYrVZLDC3NhTqqh25awRXqzoLzmBAKr5oqk6+CwuYHAekKx+VBCYVohBoKuRq40dV+TYg==","signatures":[{"sig":"MEYCIQDXwhT76iO3YlIQO9+Gcg5V8tbGOYDFwew1GQPxEulflQIhAPgrr5i0Y9bogtwTCySxHBuZPqYgmsPLPjntAKuf7N5M","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":40164},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","shasum":"e23e4120d9ebe47efb70b8ce459c834e7c7d7cb0","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"scripts":{"test":"bun test","bench":"bun run bench/structs.bench.ts","build":"./scripts/build.sh","prettier:check":"bun prettier --check .","prettier:write":"bun prettier --write ."},"_npmUser":{"name":"kommander","email":"rootkid815@gmail.com"},"prettier":{"semi":false,"printWidth":120},"_integrity":"sha512-AJzsqoVFs1KBbJbWHIYrVZLDC3NhTqqh25awRXqzoLzmBAKr5oqk6+CwuYHAekKx+VBCYVohBoKuRq40dV+TYg==","repository":{"url":"https://github.com/sst/bun-ffi-structs.git","type":"git"},"_npmVersion":"10.8.3","directories":{},"_nodeVersion":"24.3.0","_hasShrinkwrap":false,"devDependencies":{"prettier":"3.6.2","tinybench":"^5.0.1","@types/bun":"latest"},"peerDependencies":{"typescript":"^5"},"_npmOperationalInternal":{"tmp":"tmp/bun-ffi-structs_0.2.4_1782982887635_0.747497890543553","host":"s3://npm-registry-packages-npm-production"}},"0.3.0":{"name":"bun-ffi-structs","version":"0.3.0","license":"MIT","_id":"bun-ffi-structs@0.3.0","maintainers":[{"name":"kommander","email":"rootkid815@gmail.com"}],"dist":{"shasum":"85f050ffb4b11b1410ec578c7f9123f4960fb151","tarball":"https://registry.npmjs.org/bun-ffi-structs/-/bun-ffi-structs-0.3.0.tgz","fileCount":9,"integrity":"sha512-wyUMPvIXCEkymeRApw42wu/nHJxv8p3eaFy96MBWfF7wSpGTKeKFAQ9f58y8WnLGQ7eZYR3fLu71/H5qBC3+FQ==","signatures":[{"sig":"MEUCIFndVe/GTvtZIb70p+6gH8/+6R8LjdKnSa59aoWHnIkoAiEA3eXvKWh8GIUJvjjw8TzKbmW7i66T2S2SsGjuISO/dVw=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":56075},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","shasum":"85f050ffb4b11b1410ec578c7f9123f4960fb151","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"scripts":{"test":"bun test","bench":"bun run bench/structs.bench.ts","build":"./scripts/build.sh","bench:full":"bun run bench/structs.bench.ts --profile full","bench:quick":"bun run bench/structs.bench.ts --profile quick","bench:strict":"bun run bench/structs.bench.ts --profile full --strict-rme","prettier:check":"bun prettier --check .","prettier:write":"bun prettier --write ."},"_npmUser":{"name":"kommander","email":"rootkid815@gmail.com"},"prettier":{"semi":false,"printWidth":120},"_integrity":"sha512-wyUMPvIXCEkymeRApw42wu/nHJxv8p3eaFy96MBWfF7wSpGTKeKFAQ9f58y8WnLGQ7eZYR3fLu71/H5qBC3+FQ==","repository":{"url":"https://github.com/sst/bun-ffi-structs.git","type":"git"},"_npmVersion":"10.8.3","directories":{},"_nodeVersion":"24.3.0","_hasShrinkwrap":false,"devDependencies":{"prettier":"3.6.2","tinybench":"6.0.2","@types/bun":"latest"},"peerDependencies":{"typescript":"^5"},"_npmOperationalInternal":{"tmp":"tmp/bun-ffi-structs_0.3.0_1784668150866_0.7071800488243074","host":"s3://npm-registry-packages-npm-production"}},"0.3.1":{"name":"bun-ffi-structs","description":"Type-safe C-style struct packing and unpacking for Bun and Node.js FFI","version":"0.3.1","module":"./dist/index.js","main":"./dist/index.js","types":"./dist/index.d.ts","license":"MIT","type":"module","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"repository":{"type":"git","url":"https://github.com/anomalyco/bun-ffi-structs.git"},"homepage":"https://github.com/anomalyco/bun-ffi-structs#readme","bugs":"https://github.com/anomalyco/bun-ffi-structs/issues","scripts":{"test":"bun test","bench":"bun run bench/structs.bench.ts","bench:quick":"bun run bench/structs.bench.ts --profile quick","bench:full":"bun run bench/structs.bench.ts --profile full","bench:strict":"bun run bench/structs.bench.ts --profile full --strict-rme","prettier:check":"bun prettier --check .","prettier:write":"bun prettier --write .","build":"./scripts/build.sh"},"devDependencies":{"@types/bun":"latest","prettier":"3.6.2","tinybench":"6.0.2"},"peerDependencies":{"typescript":"^5"},"prettier":{"semi":false,"printWidth":120},"_id":"bun-ffi-structs@0.3.1","_integrity":"sha512-3gM7PpVWLyrwxWjcilSiGuhWanhZivvo6l0u573NziPH6f/gwk6McbaYgn7oJWov6pKGRTDbrg94W5DcJsKTtQ==","_nodeVersion":"24.3.0","_npmVersion":"10.8.3","shasum":"8af2f351a51310a8673dbe60c30dbad11d78a6ec","dist":{"integrity":"sha512-3gM7PpVWLyrwxWjcilSiGuhWanhZivvo6l0u573NziPH6f/gwk6McbaYgn7oJWov6pKGRTDbrg94W5DcJsKTtQ==","shasum":"8af2f351a51310a8673dbe60c30dbad11d78a6ec","tarball":"https://registry.npmjs.org/bun-ffi-structs/-/bun-ffi-structs-0.3.1.tgz","fileCount":9,"unpackedSize":66791,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQC0aU7ictteQOSiB5BKv2knjSgFWz1A9WgO3CnFhlO1UQIgX3hcVAP0IW9MiLFhD18WwBUmYiYrnumAnKRk0kjV76M="}]},"_npmUser":{"name":"kommander","email":"rootkid815@gmail.com"},"directories":{},"maintainers":[{"name":"kommander","email":"rootkid815@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/bun-ffi-structs_0.3.1_1784733966458_0.0349287329094532"},"_hasShrinkwrap":false}},"time":{"created":"2025-10-21T18:57:52.865Z","modified":"2026-07-22T15:26:06.783Z","0.1.0":"2025-10-21T18:57:53.160Z","0.1.1":"2025-11-11T12:41:10.698Z","0.1.2":"2025-11-11T14:25:18.612Z","0.2.1":"2026-04-28T19:55:22.812Z","0.2.2":"2026-04-30T08:25:15.722Z","0.2.3":"2026-05-11T21:28:39.005Z","0.2.4":"2026-07-02T09:01:27.796Z","0.3.0":"2026-07-21T21:09:11.014Z","0.3.1":"2026-07-22T15:26:06.626Z"},"license":"MIT","repository":{"type":"git","url":"https://github.com/anomalyco/bun-ffi-structs.git"},"maintainers":[{"name":"kommander","email":"rootkid815@gmail.com"}],"readme":"# bun-ffi-structs\n\nTypeScript struct-packing library for Bun and Node.js `node:ffi` workflows. Define and pack/unpack C-style structs with memory layout control for FFI calls.\n\n## Features\n\n- **Type-safe struct definitions** with primitives (u8, u16, u32, u64, i16, i32, i64, f32, f64, bool_u8, bool_u32, pointer)\n- **Enums** with custom base types and bidirectional mapping\n- **Nested structs** (inline or as pointers)\n- **Arrays** of primitives, enums, structs, and object pointers\n- **Fixed little-endian layout** with size-based alignment tested on x64 and arm64\n- **Field options**: optional, defaults, validation, transforms (packTransform, unpackTransform)\n- **Conditional fields** for platform-specific layouts\n- **mapValue/reduceValue** transformations for input/output type conversions\n- **Object pointers** for referencing external objects with `.ptr` property\n- **Allocation utilities** with pre-allocated sub-buffers for arrays\n- **C strings** (null-terminated) and raw string pointers\n- **Reusable decoding** into caller-owned objects and `DataView` storage\n- **Reusable primitive lists** with `packListInto`\n\n## Installation\n\n```bash\nbun install bun-ffi-structs\n```\n\nPure primitive layouts work on Node.js without FFI flags. Pointer-backed operations require Node.js 26.1 or newer with\n`--experimental-ffi`; when using Node's Permission Model, also pass `--permission --allow-ffi`.\n\nFor local development, run `bun run build`, then use `scripts/link-dev.sh <target-project-root>` to symlink this package into\nanother project's `node_modules`.\n\n## Usage\n\nSee [examples/README.md](examples/README.md) for runnable examples demonstrating various features.\n\n```typescript\nimport { defineStruct, defineEnum, allocStruct, objectPtr } from \"bun-ffi-structs\"\n\nconst ColorEnum = defineEnum({ RED: 0, GREEN: 1, BLUE: 2 })\n\nconst PositionStruct = defineStruct([\n  [\"x\", \"f32\"],\n  [\"y\", \"f32\"],\n  [\"z\", \"f32\"],\n])\n\nconst ObjectStruct = defineStruct([\n  [\"id\", \"u32\"],\n  [\"position\", PositionStruct],\n  [\"color\", ColorEnum],\n  [\"count\", \"u32\", { lengthOf: \"items\" }],\n  [\"items\", [\"u32\"]],\n])\n\nconst buffer: ArrayBuffer = ObjectStruct.pack({\n  id: 42,\n  position: { x: 1.0, y: 2.0, z: 3.0 },\n  color: \"BLUE\",\n  items: [10, 20, 30],\n})\n\nconst unpacked = ObjectStruct.unpack(buffer)\n// -> resolves to type {\n//   id: number\n//   position: { x: number, y: number, z: number }\n//   color: \"RED\" | \"GREEN\" | \"BLUE\"\n//   items: Iterable<number>\n//   count?: number | null | undefined\n// }\n```\n\n### Reusable Storage\n\nDefinitions without a top-level `reduceValue` expose\n`unpackInto(view, target, offset = 0)`. The offset is relative to the supplied `DataView`, the complete struct must fit before any\ntarget mutation occurs, and the same target is returned. Struct defaults are reapplied before decoding, `mapValue` is not called,\nand unrelated target properties remain unless overwritten by a struct default. Nested values, strings, and arrays can still allocate.\n\n```typescript\nconst CursorStruct = defineStruct([\n  [\"row\", \"u32\"],\n  [\"col\", \"u32\"],\n])\n\nconst packed = CursorStruct.pack({ row: 4, col: 8 })\nconst cursor = {}\nCursorStruct.unpackInto(new DataView(packed), cursor)\n```\n\nOption-free definitions containing only required, non-pointer primitive fields expose\n`packListInto(objects, view, offset, options?)`:\n\n```typescript\nconst buffer = new ArrayBuffer(CursorStruct.size * 2)\nCursorStruct.packListInto(\n  [\n    { row: 1, col: 2 },\n    { row: 3, col: 4 },\n  ],\n  new DataView(buffer),\n  0,\n)\n```\n\n`packListInto` deliberately excludes enums, pointers, strings, arrays, defaults, transforms, validation, mapping, reducers, and\nnested structs. Those definitions require stronger dirty-buffer or pointer-owner semantics than reusable primitive storage.\n\nHot required-primitive `pack`, `packInto`, `packList`, `packListInto`, `unpack`, and `unpackInto` paths are generated after a measured\nwarmup threshold. Primitive `unpackList` definitions with `reduceValue` receive equivalent specialization while preserving the reducer\ncallback. Environments that disable string code generation automatically continue on the generic implementations.\n","readmeFilename":"README.md","description":"Type-safe C-style struct packing and unpacking for Bun and Node.js FFI","homepage":"https://github.com/anomalyco/bun-ffi-structs#readme","bugs":"https://github.com/anomalyco/bun-ffi-structs/issues"}