Implement Smile codec with encoder, decoder, comprehensive tests, and improved architecture#35
Implement Smile codec with encoder, decoder, comprehensive tests, and improved architecture#35
Conversation
Co-authored-by: streamich <9773803+streamich@users.noreply.github.com>
…ve tests Co-authored-by: streamich <9773803+streamich@users.noreply.github.com>
Co-authored-by: streamich <9773803+streamich@users.noreply.github.com>
src/index.ts
Outdated
| @@ -1 +1,2 @@ | |||
| export type * from './types'; | |||
| export * from './smile'; | |||
There was a problem hiding this comment.
Only types in main index.ts. Remove this line.
There was a problem hiding this comment.
Fixed the main index.ts to only export types, not the smile implementation. Removed the export line as requested. (commit 5cece23)
There was a problem hiding this comment.
Revert changes to this file.
There was a problem hiding this comment.
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.
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.
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.
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.
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.
Move this interface into SmileDecoder file.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
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.
Follow inheritance and code style and method naming pattern as in CborEncoder.
There was a problem hiding this comment.
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.
- Move these tests to
codec.spec.ts. - In this file, instead, use existing fixtures. See other
automated.spec.tstest 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.
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 <9773803+streamich@users.noreply.github.com>
…nce pattern Co-authored-by: streamich <9773803+streamich@users.noreply.github.com>
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 enumdeclarations 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.