Skip to content

Minimalistic structured data binary serialization library.

License

Notifications You must be signed in to change notification settings

misanthrop/binary-wheel

Repository files navigation

binary-wheel

Minimalistic structured data binary serialization library.

Quick example

bw = require 'binary-wheel'

Emotion = bw.enum ['Smile', 'Sad', 'Evil']

Message = bw.struct
  nickname: bw.string
  message: bw.string
  emotion: bw.optional Emotion

# pack binary data
buffer = Message.pack
  nickname: 'John'
  message: 'Hi!'
  emotion: 'Smile'

# unpack to JS object
message = Message.unpack buffer

Supported types

Name(s) Size in bits
bool 1
int8, uint8 8
int16, uint16 16
int32, uint32 32
float32 32
scaled 8 or 16 or 32
enum 1 .. 32
varint 2 + (8 or 16 or 32)
optional T 1 + (0 or sizeof T)
string sizeof varint + length*8
list T sizeof varint + length*sizeof T
struct sum sizeof members

Generate C++17

bw-gen-cpp types.coffee

About

Minimalistic structured data binary serialization library.

Resources

License

Stars

Watchers

Forks

Packages

No packages published