Skip to content

快速开始

下面按语言给出一轮最短上手示例。

Rust

toml
[dependencies]
asun = "1.0"
serde = { version = "1", features = ["derive"] }
rust
use asun::{decode, encode_typed, Result};
use serde::{Deserialize, Serialize};

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

fn main() -> Result<()> {
    let users = vec![
        User { id: 1, name: "Alice".into(), active: true },
        User { id: 2, name: "Bob".into(), active: false },
    ];

    let text = encode_typed(&users)?;
    let restored: Vec<User> = decode(&text)?;
    assert_eq!(users, restored);
    Ok(())
}

查看完整 Rust 指南

Go

bash
go get github.com/asunLab/asun-go
go
package main

import (
    "fmt"
    asun "github.com/asunLab/asun-go"
)

type User struct {
    ID     int64  `asun:"id"`
    Name   string `asun:"name"`
    Active bool   `asun:"active"`
}

func main() {
    users := []User{
        {ID: 1, Name: "Alice", Active: true},
        {ID: 2, Name: "Bob", Active: false},
    }

    text, _ := asun.EncodeTyped(users)
    var out []User
    _ = asun.Decode(text, &out)
    fmt.Println(out)
}

查看完整 Go 指南

Python

bash
pip install asun
python
import asun

users = [
    {"id": 1, "name": "Alice", "active": True},
    {"id": 2, "name": "Bob", "active": False},
]

text = asun.encodeTyped(users)
restored = asun.decode(text)

assert restored == users

查看完整 Python 指南

其他语言

语言指南
SwiftSwift 指南
C#C# 指南
DartDart 指南
JS / TSJS / TS 指南
PHPPHP 指南
CC 指南
C++C++ 指南
Java / KotlinJava / Kotlin 指南
ZigZig 指南

语言支持矩阵

语言最低版本主要模型二进制解码需要什么
RustRust 1.85+serde derive / 目标类型目标类型 T
GoGo 1.24+反射 + struct tag输出指针
PythonPython 3.8+Python dict/list + 编译扩展schema 字符串
Java / KotlinJava 21+反射 + Class<T> / Kotlin helper目标类
SwiftSwift tools 5.9+AsunValue 值模型内建在 binary payload 中
C#.NET 8+IAsunSchema + factory字段名 + 类型 + factory
DartDart 3.0+AsunSchema + factory字段名 + 类型 + factory
JS / TS支持 ES2020 的运行时普通对象 + 运行时推断schema 字符串
PHPPHP 8.4+原生扩展上的数组模型schema 参数
CC11显式 schema 描述符schema 描述符
C++C++17目标类型上的元数据宏目标类型 T
ZigZig 0.15.2+comptime 目标类型目标类型 T + allocator

如果你需要看某个语言的安装方式、最小示例、准确 API 名称和当前实现边界,请继续进入对应语言页。

工具

  • 规范以 ASUN 格式规范 为准。
  • VS Code 插件可提供语法高亮与预览。
  • 兼容性与 benchmark 页面适合做实现对比。

基于 MIT 许可证发布。