Go to file
Ludovic Chenut 38a73a70fd
Remove a typo
2023-10-16 17:15:22 +02:00
binary_serialization Remove a typo 2023-10-16 17:15:22 +02:00
tests first commit 2022-08-29 17:09:26 +02:00
LICENSE-APACHEv2 first commit 2022-08-29 17:09:26 +02:00
LICENSE-MIT first commit 2022-08-29 17:09:26 +02:00
README.md first commit 2022-08-29 17:09:26 +02:00
binary_serialization.nim first commit 2022-08-29 17:09:26 +02:00
binary_serialization.nimble first commit 2022-08-29 17:09:26 +02:00
nim.cfg first commit 2022-08-29 17:09:26 +02:00

README.md

nim-binary-serialization

Binary packed serialization compatible with the nim-serialization framework.

Usage

type
  Example = object
    first: uint8
    second: uint16

let ex = Example(first: 5.uint8, second: 12.uint16)
assert Binary.encode(ex) == @[5.uint8, 0, 12]

type
  SeqHolder = object
    # bin_value is used during encoding instead of the actual value
    seqLength {.bin_value: it.vals.len.}: uint8
    # bin_len is the length of the sequence in element, used during decoding
    vals {.bin_len: it.seqLength.}: seq[Example]

assert Binary.encode(SeqHolder(vals: @[ex, ex])) == @[2.uint8, 5, 0, 12, 5, 0, 12]

type
  ByteSharing = object
    a {.bin_bitsize: 3.}: uint8
    b {.bin_bitsize: 5.}: uint8

assert Binary.encode(ByteSharing(a: 2.uint8, b: 4.uint8)) == @[68.uint8]

You can find real examples in the tests (including IP frames, Yamux header, more to come)

License

Licensed and distributed under either of

or

at your option. These files may not be copied, modified, or distributed except according to those terms.