rubbo-jsonb

Crates.iorubbo-jsonb
lib.rsrubbo-jsonb
version0.1.0
created_at2026-01-23 09:41:46.232616+00
updated_at2026-01-23 09:41:46.232616+00
descriptionRust implementation of Apache Dubbo 3. High-performance RPC framework with Triple protocol.
homepagehttps://github.com/huiyang233/rubbo
repositoryhttps://github.com/huiyang233/rubbo
max_upload_size
id2063949
size69,488
杨辉 (huiyang233)

documentation

https://docs.rs/rubbo

README

Rubbo JSONB

English | 中文

English

rubbo-jsonb is a Rust implementation of the Fastjson2 JSONB binary protocol. It is designed to be compatible with Dubbo 3's Triple protocol when using the fastjson2 serialization.

Features

  • Serde Compatibility: Fully integrates with Rust's serde ecosystem.
  • Dubbo 3 Ready: Implements the binary format required by Dubbo 3's fastjson2 serialization.

Type Support Matrix

Supported Types

Rust Type Fastjson2 JSONB Type Notes
bool BC_TRUE / BC_FALSE
i8, i16, i32 BC_INT32 family Optimized compact encoding supported (-16..47, etc.)
i64 BC_INT64 family Optimized compact encoding supported
u8 .. u64 BC_INT32 / BC_INT64 Mapped to signed integers
String, &str BC_STR_ASCII / BC_STR_UTF8 ASCII optimization supported
Vec<T>, &[T] BC_ARRAY Fixed-length arrays supported
Tuple BC_ARRAY Mapped to arrays
Map, HashMap BC_OBJECT
Struct BC_OBJECT Serialized as field-value pairs
Option<T> BC_NULL or Value None maps to BC_NULL
() (Unit) BC_NULL
f32, f64 BC_FLOAT, BC_DOUBLE Full support
Vec<u8> (Bytes) BC_BINARY Full support

Currently Unsupported / Partial Support

Rust Type Status Notes
Enum Basic Standard Serde enum handling; Complex variant types not fully tested
References No Circular reference detection and BC_REFERENCE (0x93) not supported
AutoType No Writing class names (BC_TYPED_ANY - 0x92) is not supported

Usage

Add to your Cargo.toml:

[dependencies]
rubbo-jsonb = { path = "../rubbo-jsonb" }

Use with Serde:

use rubbo_jsonb::{to_vec, from_slice};
use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize, PartialEq, Debug)]
struct User {
    id: i32,
    name: String,
}

fn main() {
    let user = User { id: 1, name: "Rubbo".to_string() };
    
    // Serialize
    let bytes = to_vec(&user).unwrap();
    
    // Deserialize
    let decoded: User = from_slice(&bytes).unwrap();
    
    assert_eq!(user, decoded);
}

中文 (Chinese)

rubbo-jsonbFastjson2 JSONB 二进制协议的 Rust 实现。它旨在兼容 Dubbo 3 Triple 协议中使用的 fastjson2 序列化方式。

特性

  • 兼容 Serde:完全集成 Rust 的 serde 生态系统。
  • Dubbo 3 就绪:实现了 Dubbo 3 fastjson2 序列化所需的二进制格式。

类型支持列表

已支持类型 (Supported Types)

Rust 类型 Fastjson2 JSONB 类型 说明
bool BC_TRUE / BC_FALSE 布尔值
i8, i16, i32 BC_INT32 系列 支持紧凑编码优化(如 -16..47 等范围)
i64 BC_INT64 系列 支持紧凑编码优化
u8 .. u64 BC_INT32 / BC_INT64 映射为有符号整数
String, &str BC_STR_ASCII / BC_STR_UTF8 支持 ASCII 编码优化
Vec<T>, &[T] BC_ARRAY 支持定长数组
Tuple (元组) BC_ARRAY 映射为数组
Map, HashMap BC_OBJECT 映射为对象
Struct (结构体) BC_OBJECT 序列化为字段-值对
Option<T> BC_NULL 或 值 None 映射为 BC_NULL
() (Unit) BC_NULL 空值
f32, f64 BC_FLOAT, BC_DOUBLE 完整支持序列化和反序列化
Vec<u8> (Bytes) BC_BINARY 完整支持序列化和反序列化

暂未支持 / 部分支持 (Unsupported / Partial Support)

Rust 类型 状态 说明
Enum (枚举) 基础支持 支持标准 Serde 枚举处理;复杂变体类型未充分测试
References (引用) 不支持 不支持循环引用检测和 BC_REFERENCE (0x93)
AutoType (类型全名) 不支持 不支持写入 Java 类名 (BC_TYPED_ANY - 0x92)

使用方法

Cargo.toml 中添加:

[dependencies]
rubbo-jsonb = { path = "../rubbo-jsonb" }

配合 Serde 使用:

use rubbo_jsonb::{to_vec, from_slice};
use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize, PartialEq, Debug)]
struct User {
    id: i32,
    name: String,
}

fn main() {
    let user = User { id: 1, name: "Rubbo".to_string() };
    
    // 序列化
    let bytes = to_vec(&user).unwrap();
    
    // 反序列化
    let decoded: User = from_slice(&bytes).unwrap();
    
    assert_eq!(user, decoded);
}
Commit count: 6

cargo fmt