Skip to content

Getting Started

Pick your language below for a quick first round-trip.

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(())
}

See the full Rust guide.

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)
}

See the full Go guide.

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

See the full Python guide.

Other Languages

LanguageGuide
SwiftSwift guide
C#C# guide
DartDart guide
JS / TSJS / TS guide
PHPPHP guide
CC guide
C++C++ guide
Java / KotlinJava / Kotlin guide
ZigZig guide

Language Support Matrix

LanguageMinimum versionMain modelBinary decode requirement
RustRust 1.85+serde derive / target typetarget type T
GoGo 1.24+reflection + struct tagsoutput pointer
PythonPython 3.8+Python dict/list + compiled extensionschema string
Java / KotlinJava 21+reflection + Class<T> / Kotlin helpertarget class
SwiftSwift tools 5.9+AsunValue value modelbuilt into binary payload
C#.NET 8+IAsunSchema + factoryfield names + types + factory
DartDart 3.0+AsunSchema + factoryfield names + types + factory
JS / TSES2020-capable runtimeplain objects + runtime inferenceschema string
PHPPHP 8.4+arrays via native extensionschema argument
CC11explicit schema descriptorschema descriptor
C++C++17metadata macros on target typetarget type T
ZigZig 0.15.2+comptime target typetarget type T + allocator

Use the language guide pages for the exact install steps, minimal examples, and current implementation limits for each runtime.

Tooling

  • Read the spec for the canonical format definition.
  • Use the VS Code extension for syntax highlighting and preview.
  • Use the compatibility and benchmark pages when comparing implementations.

Released under the MIT License.