| Crates.io | rubbo-jsonb |
| lib.rs | rubbo-jsonb |
| version | 0.1.0 |
| created_at | 2026-01-23 09:41:46.232616+00 |
| updated_at | 2026-01-23 09:41:46.232616+00 |
| description | Rust implementation of Apache Dubbo 3. High-performance RPC framework with Triple protocol. |
| homepage | https://github.com/huiyang233/rubbo |
| repository | https://github.com/huiyang233/rubbo |
| max_upload_size | |
| id | 2063949 |
| size | 69,488 |
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.
serde ecosystem.fastjson2 serialization.| 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 |
| 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 |
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);
}
rubbo-jsonb 是 Fastjson2 JSONB 二进制协议的 Rust 实现。它旨在兼容 Dubbo 3 Triple 协议中使用的 fastjson2 序列化方式。
serde 生态系统。fastjson2 序列化所需的二进制格式。| 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 |
完整支持序列化和反序列化 |
| 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);
}