Implement FlexBuffers codec for binary JSON serialization#37
Implement FlexBuffers codec for binary JSON serialization#37
Conversation
Co-authored-by: streamich <9773803+streamich@users.noreply.github.com>
…ollections work Co-authored-by: streamich <9773803+streamich@users.noreply.github.com>
streamich
left a comment
There was a problem hiding this comment.
In FlexBufferEncoder.spec.ts add some tests which DO NOT do a full round-trip, but they convert to Uint8Array and that is matched against known value.
There was a problem hiding this comment.
Make all enums const enum in this file.
There was a problem hiding this comment.
Changed FlexBufferType and BitWidth enums to const enum for better performance and tree-shaking. Commit 8db9f29.
| // Skip size (we already read it) | ||
| reader.x++; | ||
|
|
||
| return new TextDecoder().decode(stringData); |
There was a problem hiding this comment.
Do no use TextDecoder, use existing string decoding implementations from this library.
There was a problem hiding this comment.
Replaced TextDecoder with reader.utf8(size) to use the library's existing string decoding implementation. Commit 8db9f29.
| bitWidthToByteSize, | ||
| } from './constants'; | ||
|
|
||
| export class FlexBuffersEncoder implements BinaryJsonEncoder, StreamingBinaryJsonEncoder { |
There was a problem hiding this comment.
Remove StreamingBinaryJsonEncoder.
| export class FlexBuffersEncoder implements BinaryJsonEncoder, StreamingBinaryJsonEncoder { | |
| export class FlexBuffersEncoder implements BinaryJsonEncoder { |
There was a problem hiding this comment.
Removed StreamingBinaryJsonEncoder from imports and implements clause. Commit 8db9f29.
…er, replace TextDecoder, add byte value tests Co-authored-by: streamich <9773803+streamich@users.noreply.github.com>
Added comprehensive non-roundtrip tests that verify encoding to specific Uint8Array byte values. Tests cover scalars (null, booleans, integers, floats) and strings with their exact expected byte sequences. Commit 8db9f29. |
This PR implements a FlexBuffers codec in the
src/flexbuffers/directory, following the same pattern as the existing UBJSON codec. FlexBuffers is Google's schema-less binary format from the FlatBuffers project that provides efficient serialization for JSON-like data.Implementation
The codec includes:
Supported Data Types
✅ Fully working:
❌ Not implemented:
Technical Details
The implementation follows the FlexBuffers specification:
[value][type][bit_width]Example Usage
Test Results
This provides a solid foundation for FlexBuffers support in json-pack, handling the most common serialization use cases with excellent space efficiency.
Fixes #36.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.