-
-
Notifications
You must be signed in to change notification settings - Fork 1
Implement FlexBuffers codec for binary JSON serialization #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Co-authored-by: streamich <[email protected]>
…ollections work Co-authored-by: streamich <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
src/flexbuffers/constants.ts
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make all enums const enum
in this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do no use TextDecoder
, use existing string decoding implementations from this library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove StreamingBinaryJsonEncoder
.
export class FlexBuffersEncoder implements BinaryJsonEncoder, StreamingBinaryJsonEncoder { | |
export class FlexBuffersEncoder implements BinaryJsonEncoder { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed StreamingBinaryJsonEncoder from imports and implements clause. Commit 8db9f29.
…er, replace TextDecoder, add byte value tests Co-authored-by: streamich <[email protected]>
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.