Binary is a high-performance binary serialization library for Go, specifically designed for TinyGo compatibility and resource-constrained environments.
- TinyGo Compatible: Optimized for embedded systems and WebAssembly.
- Extreme Performance: Minimal allocations and efficient encoding.
- Simple API: Just
EncodeandDecode. - Zero Dependencies: Core logic is lightweight and self-contained.
go get github.com/tinywasm/binarypackage main
import (
"fmt"
"github.com/tinywasm/binary"
)
type User struct {
Name string
Age int
}
func main() {
user := &User{Name: "Alice", Age: 30}
// Encode
var data []byte
binary.Encode(user, &data)
// Decode
var decoded User
binary.Decode(data, &decoded)
fmt.Printf("Decoded: %+v\n", decoded)
}Encode(input, output any) error: Encodes into*[]byteorio.Writer.Decode(input, output any) error: Decodes from[]byteorio.Reader.SetLog(fn func(...any)): Sets internal logger for debugging.
This project is an adaptation of Kelindar/binary focused on TinyGo.