Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

planetis-m/bingo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

25 Commits

Repository files navigation

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 with ptr types.
  • Supports options, sets and tables by 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 hasCustomPragma improves, this feature won't be added. You can currently substitute skipped fields by creating empty overloads.

AltStyle によって変換されたページ (->オリジナル) /