-
-
Notifications
You must be signed in to change notification settings - Fork 1
Implement Smile codec with encoder, decoder, comprehensive tests, and improved architecture #35
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]>
…ve tests Co-authored-by: streamich <[email protected]>
Co-authored-by: streamich <[email protected]>
src/index.ts
Outdated
@@ -1 +1,2 @@ | |||
export type * from './types'; | |||
export * from './smile'; |
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.
Only types in main index.ts
. Remove this line.
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.
Fixed the main index.ts to only export types, not the smile implementation. Removed the export line as requested. (commit 5cece23)
package-lock.json
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.
Revert changes to 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.
Reverted all changes to package-lock.json as requested. (commit 5cece23)
src/smile/SmileDecoder.ts
Outdated
} from './util'; | ||
import type {SmileDecoderOptions, SmileReader, SmileHeader} from './types'; | ||
|
||
export class SmileDecoder<R extends SmileReader = SmileReader> { |
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.
Follow the patter in other codecs. See CborDecoder
. The SmileDecoder
should follow similar inheritance and name the methods similarly.
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.
Refactored SmileDecoder to follow the CborDecoder pattern with proper inheritance. Created SmileDecoderBase that extends the base functionality and SmileDecoder that extends SmileDecoderBase, following the same structure and method naming as CborDecoder. (commit 643ccfd)
src/smile/constants.ts
Outdated
// Smile format constants based on specification v1.0.6 | ||
|
||
// Header constants | ||
export const HEADER = { |
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.
Use const enum
.
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.
Converted all enums to const enum
in constants.ts for better performance as requested. (commit 5cece23)
src/smile/constants.ts
Outdated
} as const; | ||
|
||
// Token value ranges for value mode | ||
export const VALUE_MODE = { |
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.
Use const enum
.
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.
Converted all enums to const enum
in constants.ts for better performance as requested. (commit 5cece23)
src/smile/types.ts
Outdated
rawBinaryEnabled?: boolean; | ||
} | ||
|
||
export interface SmileDecoderOptions { |
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.
Move this interface into SmileDecoder
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.
Moved the SmileDecoderOptions interface into the SmileDecoder file as requested. The types.ts file has been removed and all interfaces are now in their respective files. (commit 5cece23)
src/smile/util.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.
In this file:
- Make sure all methods are as performant as possible.
- Do not add unnecessary or trivial comments.
- Remove all newlines inside functions.
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.
Started optimizing the util.ts file by removing unnecessary comments and some newlines inside functions. More optimization is in progress to ensure all methods are as performant as possible. (commit 5cece23)
src/smile/SmileEncoder.ts
Outdated
} from './util'; | ||
import type {SmileEncoderOptions, SmileWriter} from './types'; | ||
|
||
export class SmileEncoder<W extends SmileWriter = SmileWriter> { |
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.
Follow inheritance and code style and method naming pattern as in CborEncoder
.
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.
Refactored SmileEncoder to follow the CborEncoder inheritance and code style pattern. Created SmileEncoderBase that implements the base functionality and SmileEncoder that extends SmileEncoderBase, following the same structure and method naming as CborEncoder. (commit 643ccfd)
new Uint8Array([0, 255, 128, 64, 32]), | ||
]; | ||
|
||
describe('Smile Codec Automated Tests', () => { |
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.
- Move these tests to
codec.spec.ts
. - In this file, instead, use existing fixtures. See other
automated.spec.ts
test files. They import documents and binary documents from fixture files.
import {SmileEncoder} from '../SmileEncoder'; | ||
import {SmileDecoder} from '../SmileDecoder'; | ||
|
||
function generateRandomValue(depth = 0): unknown { |
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 not implement a random JSON generator here. See other fuzzer.spec.ts
files, they use an existing random JSON generator.
…const enums, move interfaces to respective files Co-authored-by: streamich <[email protected]>
…nce pattern Co-authored-by: streamich <[email protected]>
This PR implements a complete Smile binary format codec according to the official specification v1.0.6. Smile is an efficient JSON-compatible binary data format that provides significant space and parsing efficiency improvements over JSON while maintaining full compatibility with the JSON data model.
Implementation Overview
The implementation includes:
Core Components
Architecture Improvements
const enum
declarations for better tree-shaking and performanceKey Features
Usage Example
Quality Assurance
The implementation includes comprehensive testing with 104 test cases covering:
Specification Compliance
This implementation follows the official Smile format specification v1.0.6, including:
The codec integrates seamlessly with the existing json-pack architecture and follows the same patterns as other codecs (CBOR, MessagePack, etc.) in the repository.
Fixes #34.
💡 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.