All Projects → megagrump → moonblob

megagrump / moonblob

Licence: MIT license
Binary serialization for moonscript + LuaJIT

Programming Languages

MoonScript
45 projects
shell
77523 projects

Projects that are alternatives of or similar to moonblob

wasmbin
A self-generating WebAssembly parser & serializer in Rust.
Stars: ✭ 40 (+81.82%)
Mutual labels:  serialization
FWK
💎 3D game framework in C, with Luajit bindings now.
Stars: ✭ 423 (+1822.73%)
Mutual labels:  luajit
GenericProtocol
⚡️ A fast TCP event based buffered server/client protocol for transferring data over the (inter)net in .NET 🌐
Stars: ✭ 38 (+72.73%)
Mutual labels:  serialization
flextool
C++ compile-time programming (serialization, reflection, code modification, enum to string, better enum, enum to json, extend or parse language, etc.)
Stars: ✭ 32 (+45.45%)
Mutual labels:  serialization
ngx-localstorage
An Angular wrapper for localstorage/sessionstorage access.
Stars: ✭ 27 (+22.73%)
Mutual labels:  serialization
c-plus-plus-serializer
A minimal C++11 header only serializer. Can serialize basic types, strings, containers, maps and custom classes. No suppprt yet for pointer types.
Stars: ✭ 36 (+63.64%)
Mutual labels:  serialization
JAson
Creation a JSON object with data of different types and run serialization and deserialization of JSON data.
Stars: ✭ 38 (+72.73%)
Mutual labels:  serialization
lua-twitter
A Lua twitter library that works with OpenResty or LuaSocket
Stars: ✭ 29 (+31.82%)
Mutual labels:  moonscript
borsh-rs
Rust implementation of Binary Object Representation Serializer for Hashing
Stars: ✭ 149 (+577.27%)
Mutual labels:  serialization
NBT
A java implementation of the NBT protocol, including a way to implement custom tags.
Stars: ✭ 128 (+481.82%)
Mutual labels:  serialization
blobs
random blob generation and animation
Stars: ✭ 115 (+422.73%)
Mutual labels:  blob
lcurses
Lua bindings for Curses
Stars: ✭ 60 (+172.73%)
Mutual labels:  luajit
cattrs
Complex custom class converters for attrs.
Stars: ✭ 565 (+2468.18%)
Mutual labels:  serialization
serde
🚝 (unmaintained) A framework for defining, serializing, deserializing, and validating data structures
Stars: ✭ 49 (+122.73%)
Mutual labels:  serialization
avrow
Avrow is a pure Rust implementation of the avro specification https://avro.apache.org/docs/current/spec.html with Serde support.
Stars: ✭ 27 (+22.73%)
Mutual labels:  serialization
bytecodec
A tiny Rust framework for implementing encoders/decoders of byte-oriented protocols
Stars: ✭ 21 (-4.55%)
Mutual labels:  serialization
fdat.cljc
Function serialization between Clojure processes and dialects
Stars: ✭ 49 (+122.73%)
Mutual labels:  serialization
parco
🏇🏻 generalist, fast and tiny binary parser and compiler generator, powered by Go 1.18+ Generics
Stars: ✭ 57 (+159.09%)
Mutual labels:  serialization
elm-protobuf
protobuf plugin for elm
Stars: ✭ 93 (+322.73%)
Mutual labels:  serialization
aspect
Aspect is a compiling template engine for Lua and LuaJIT
Stars: ✭ 17 (-22.73%)
Mutual labels:  luajit

moonblob - binary serialization library

moonblob is a compact LuaJIT library written in moonscript that performs serialization into an efficient binary format. It can be used to parse arbitrary binary data, or to serialize data for efficient storage or transmission.

How to use

Writing data

BlobWriter = require('BlobWriter')

blob = BlobWriter()

-- Store raw binary data
blob
	:u8(23)
	:number(123.45)
	:f32(23.0)
	:string('string')
	...

-- Store Lua types
blob
	:write({ key: 'value', tbl: { 1, 2, 3 } }) -- no cycles allowed!
	:write(23)
	:write(true)
	:write('string')

-- Write data to file
file = io.open('filename.ext', 'wb')
file:write(blob:tostring())
file:close()

Reading data

BlobReader = require('BlobReader')

-- Load data from file
file = io.open('filename.ext', 'rb')
blob = BlobReader(file:read('*all'))
file:close()

-- Parse raw binary data
u8 = blob:u8()
s16 = blob:s16()
str = blob:cstring()
float = blob:f32()
...

-- Read Lua types
tbl = blob:table()
bool = blob:bool() -- 8 bits, 0 == false
num = blob:number()
str = blob:string()

Documentation

API reference

Reading and writing Lua types

BlobReader:read and BlobWriter:write can be used to store Lua values along with their type. BlobReader:read can only read data that was previously written by BlobWriter:write.

These data types are supported by BlobReader:read and BlobWriter:write:

  • number (64 bit)
  • string (up to 2^32-1 bytes)
  • boolean
  • table
  • cdata

Type and length information will be added as metadata by the write function. Metadata overhead is 1 byte per value written for type information, and between 1 and 5 bytes per string written for length information. Tables can contain number, string, boolean, 'cdata', and table as key and value types. An error is being thrown if other types or cyclic nested tables are encountered.

Low level I/O

A low level interface is provided for handling arbitrary binary data.

number       -- Lua number (64 bit floating point)
bool         -- boolean value (8 bits; 0 == false)
string       -- Lua string
table        -- Lua table
s8  / u8     -- signed/unsigned 8 bit integer value
s16 / u16    -- signed/unsigned 16 bit integer value
s32 / u32    -- signed/unsigned 32 bit integer value
s64 / u64    -- signed/unsigned 64 bit integer value
vs32 / vu32  -- length-encoded signed/unsigned 32 bit value
f32 / f64    -- 32/64 bit floating point value
raw          -- raw binary data (length must be specified)
cstring      -- zero-terminated string
array        -- sequential table of typed values
cdata        -- LuaJIT cdata

To describe the raw data format in a more concise manner, use BlobWriter:pack and BlobReader:unpack. These functions work similar to string.unpack and string.pack in Lua 5.3, although some details are different (fixed instead of native data sizes; more supported data types; some features are not implemented). See API reference for details.

Compatibility

The library was developed on and for x86 and x64 machines - other architectures are currently untested.

Since moonblob uses the ffi library and C data types, it is not compatible with vanilla Lua and can only be used with LuaJIT.

License

Copyright 2017-2021 megagrump

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].