Repository navigation
Releases: davidesantangelo/cton
Releases · davidesantangelo/cton
Release list
v1.0.0
Summary
- Introduce schema DSL + validation API for LLM-safe outputs.
- Add streaming IO helpers and CTON-B binary envelope.
- Refresh README for LLM-first usage and CLI upgrades.
Performance
- Faster decoder scalar scans and reusable encoder buffer.
CLI
- New flags: --schema, --stream, --to-binary, --from-binary.
Tests
- Added schema, streaming, binary, and CLI coverage.
v0.4.0
Added
-
Comment Support: CTON now supports single-line comments using
#syntax. Comments are ignored during parsing, allowing for annotated data files.- Decoder skips comments (from
#to end of line) during parsing - Encoder can emit comments via new
comments:option:Cton.dump(data, comments: { "key" => "description" })
- Decoder skips comments (from
-
Validation API: New methods to validate CTON syntax without full parsing:
Cton.valid?(string)returnstrueorfalseCton.validate(string)returns aValidationResultobject with detailed error informationValidationResultincludesvalid?,errors, andto_smethodsValidationErrorincludesmessage,line,column, andsource_excerpt
-
Token Statistics API: Analyze and compare CTON vs JSON token efficiency:
Cton.stats(data)returns aStatsobject with comprehensive metricsCton.stats_hash(data)returns stats as a HashStatsincludesjson_chars,cton_chars,savings_percent,estimated_json_tokens,estimated_cton_tokensStats.compare(data)compares multiple format variants (CTON, CTON inline, CTON pretty, JSON, JSON pretty)
-
Custom Type Registry: Register custom serializers for domain objects:
Cton.register_type(klass, as: :object) { |value| ... }registers a type handlerCton.unregister_type(klass)removes a handlerCton.clear_type_registry!clears all handlers- Supports
:object,:array, and:scalarmodes
-
Enhanced CLI: New command-line options:
--stats/-s: Show token savings statistics comparing JSON vs CTON--validate: Validate CTON syntax without conversion--minify/-m: Output CTON without separators (fully inline)- Improved error messages with line/column information and colored output
-
Enhanced Error Reporting:
ParseErrornow includes structured location information:lineandcolumnattributes for precise error locationsource_excerptshowing context around the errorsuggestionsarray for helpful hintsto_hmethod for programmatic error handling
v0.3.0
Added
- Performance tunables:
Cton.dumpnow acceptsdecimal_mode: :fast | :precise, allowing callers to trade float-format determinism for lower allocation pressure. Specs cover both modes. - Benchmark harness: New
bench/encode_decode_bench.rbscript (wired into the README/Development docs) exercises encode/decode hot paths and prints comparative JSON vs CTON timings. On Ruby 3.1.4/macOS the fast encoder completes 1,000 iterations in ~0.63s and the new inline decoder stress test wraps 400 concatenated documents in ~4.14s. - Regression tests: Added specs for streaming documents without separators plus validation around the new decimal mode toggle.
Changed
- Encoder: Memoizes table schemas per array instance, adds a fast-path for homogeneous scalar lists, and reduces float/BigDecimal copying by favoring Ruby's native float formatting before falling back to
BigDecimal. Unsupporteddecimal_modevalues now raise immediately. - Decoder: Replaces high-allocation
StringScannertokenization with raw string slicing, improves key-boundary detection for inline payloads, and keeps symbolization logic untouched. Boundary heuristics now prefer alphabetic key starts to avoid splitting numeric payloads. - Documentation: README now calls out the tuning flags, inline caveats, and benchmark instructions; Development workflow highlights how to rerun the perf suite.
Fixed
- Inline parsing: Eliminated the runaway allocations and incorrect key splits when processing long documents with
separator: "". - Float normalization: Restored canonical
9.2-style output in fast mode while keeping the new perf optimizations.
v0.2.0
Added
- CLI Tool: New
bin/ctonexecutable for converting between JSON and CTON from the command line. Supports auto-detection, pretty printing, and file I/O. - Streaming IO:
Cton.dumpnow accepts anIOobject as the second argument (or viaio:keyword), allowing direct writing to files or sockets without intermediate string allocation. - Pretty Printing: Added
pretty: trueoption toCton.dumpto format output with indentation and newlines for better readability. - Extended Types: Native support for
Time,Date(ISO8601),Set(as Array), andOpenStruct(as Object). - Enhanced Error Reporting:
ParseErrornow includes line and column numbers to help locate syntax errors in large documents.
Changed
- Ruby 3 Compatibility: Improved argument handling in
Cton.dumpto robustly support Ruby 3 keyword arguments when passing hashes.
v0.1.1
Changed
- Performance: Refactored
Encoderto useStringIOandDecoderto useStringScannerfor significantly improved performance and memory usage. - Architecture: Split
Ctonmodule into dedicatedCton::EncoderandCton::Decoderclasses for better maintainability.
Fixed
- Parsing: Fixed an issue where unterminated strings were not correctly detected.
- Whitespace: Improved whitespace handling in the decoder, specifically fixing issues with whitespace between keys and structure markers.
Added
- Type Safety: Added comprehensive RBS signatures (
sig/cton.rbs) for better IDE support and static analysis. - Tests: Expanded test coverage for validation, complex tables, mixed arrays, unicode values, and error cases.
v0.1.0
Added
- Initial Release: First public version of the
ctongem. - CTON Encoder:
Cton.dump(aliased asCton.generate) to convert a RubyHashinto a CTON string.- Encodes objects, arrays, strings, numbers, booleans, and
nil. - Automatic table detection for arrays of uniform hashes, creating a highly compact representation:
key[N]{h1,h2}=v1,v2;.... - Smart string quoting: only quotes strings containing special characters, whitespace, or those that could be misinterpreted as numbers, booleans, or null.
- Number normalization: canonicalizes floats and
BigDecimalto a clean, exponent-free format.NaNandInfinityare converted tonullfor safety. - Configurable separator (
\nby default) between top-level key-value pairs.
- Encodes objects, arrays, strings, numbers, booleans, and
- CTON Decoder:
Cton.load(aliased asCton.parse) to parse a CTON string back into a Ruby object.- Handles all CTON structures: objects
(), arrays[], and compact tables[]{}. - Supports an optional
symbolize_names: trueargument to convert all hash keys to symbols. - Robust parsing of scalars, including quoted and unquoted strings.
- Handles all CTON structures: objects
- Error Handling:
Cton::EncodeErrorfor unsupported Ruby types during encoding andCton::ParseErrorfor malformed CTON input. - Documentation:
README.mdwith a format overview, usage examples, and rationale. - Testing: Comprehensive RSpec suite ensuring round-trip integrity and correct handling of edge cases.