jsbt-rust

Crates.iojsbt-rust
lib.rsjsbt-rust
version0.1.1
created_at2025-12-13 08:40:22.45887+00
updated_at2025-12-13 08:48:12.937628+00
descriptionA Rust implementation of the JSBT binary serialization format for interoperability with JavaScript
homepage
repositoryhttps://github.com/mrorigo/jsbt-rust
max_upload_size
id1982730
size154,869
Mattias (mrorigo)

documentation

README

jsbt-rust

A Rust implementation of the JSBT (JavaScript Binary Transfer) serialization format for interoperability with JavaScript.

Description

jsbt-rust allows you to serialize and deserialize data in the JSBT format, ensuring byte-for-byte compatibility with the JavaScript/TypeScript implementation. This is ideal for high-performance data exchange between Rust backend services and JavaScript frontends or Node.js processes.

Features

  • Byte-for-byte Compatibility: Matches the JSBT specification perfectly, including little-endian byte order, bit flags, and custom encoding for Symbols and Floats.
  • Full Type Support: Handles primitives (null, undefined, bool, integer, float, string) and complex types (BigInt, Array, Object, Set, Map, Date, Symbol, TypedArray).
  • Reference Handling: Supports "Link" and "Copy" modes for efficient object graph serialization.
  • Async Support: Optional async decoding via the full_async feature.
  • Serde Integration: Uses serde for Rust type serialization.

Usage

Add this to your Cargo.toml:

[dependencies]
jsbt-rust = "0.1.0"

Basic Example

use jsbt_rust::{JSBTValue, EncodeOptions, DecodeOptions, encoder::encode_value, decoder::decode_value_sync, reader::ByteReader};
use std::io::Cursor;

fn main() {
    let value = JSBTValue::String("Hello, World!".to_string());
    
    // Encode
    let mut encode_ops = EncodeOptions::default();
    let mut buffer = Vec::new();
    encode_value(&value, &mut encode_ops, &mut buffer).unwrap();
    
    // Decode
    let cursor = Cursor::new(buffer);
    let mut reader = ByteReader::new(cursor);
    let mut decode_ops = DecodeOptions::default();
    let decoded_value = decode_value_sync(&mut reader, &mut decode_ops).unwrap();
    
    assert_eq!(value, decoded_value);
}

Feature Flags

  • full_async: Enables asynchronous decoding functions using tokio and async-base.

Attribution

This library is a Rust port of the original TypeScript implementation ts-jsbt by Alexander Cheprasov (@cheprasov).

License

MIT

Commit count: 0

cargo fmt