Bingo
Binary serialization framework for Nim
Install / Use
/learn @planetis-m/BingoREADME
bingo — Binary serialization framework for Nim
About
This package provides the binTo, loadBin procs which deserialize the specified
type from a Stream. The storeBin procs are used to write the binary
representation of a location into a Stream. Low level initFromBin and storeBin
procs can be overloaded, in order to support arbitary container types, i.e.
marshal_smartptrs.nim.
Usage
import std/streams, bingo
type
Foo = ref object
value: int
next: Foo
let d = Foo(value: 1, next: Foo(value: 2, next: nil))
let s = newStringStream()
# Make a roundtrip
s.storeBin(d) # writes binary from a location
s.setPosition(0)
let a = s.binTo(Foo) # reads binary and transform to a type
# Alternatively load directly into a location
s.setPosition(0)
var b: Foo
s.loadBin(b)
Features
- Serializing and deserializing directly into
Streams. For common usage it is done automatically. Generally speaking intervation is needed when working withptrtypes. - Supports
options,setsandtablesby default. - Overloading serialization procs.
Limitations
-
Limited support of object variants. The discriminant field is expected first. Also there can be no fields before and after the case section.
-
Borrowing proc
initFromBin[T](dst: var T; s: Stream)for distinct types isn't currently working. Blocked by a Nim bug. Use overloads for now. Or you can easily override this behaviour by copying these lines in your project:from typetraits import distinctBase proc storeBin[T: distinct](s: Stream; x: T) = storeToBin(s, x.distinctBase) proc initFromBin[T: distinct](dst: var T; s: Stream) = initFromBin(dst.distinctBase, p) -
Custom pragmas are not supported. Unless
hasCustomPragmaimproves, this feature won't be added. You can currently substitute skipped fields by creating empty overloads.
Related Skills
node-connect
349.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.5kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
349.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
349.2kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
