All Projects → svperbeast → struct

svperbeast / struct

Licence: MIT License
pack and unpack binary data.

Programming Languages

C++
36643 projects - #6 most used programming language
c
50402 projects - #5 most used programming language
CMake
9771 projects

Projects that are alternatives of or similar to struct

EndianBinaryIO
A C# library that can read and write primitives, enums, arrays, and strings to streams and byte arrays with specified endianness, string encoding, and boolean sizes.
Stars: ✭ 20 (-52.38%)
Mutual labels:  serialization, endianness, endian
Bytes
Swift Library for working with sequences of Bytes (aka [UInt8])
Stars: ✭ 35 (-16.67%)
Mutual labels:  serialization, bytes
Deku
Declarative binary reading and writing: bit-level, symmetric, serialization/deserialization
Stars: ✭ 136 (+223.81%)
Mutual labels:  serialization, bytes
biguint-format
Node.js module to format big uint numbers from a byte array or a Buffer
Stars: ✭ 16 (-61.9%)
Mutual labels:  bytes, endian
bytes
Work with bytes and implement network protocols
Stars: ✭ 77 (+83.33%)
Mutual labels:  serialization, bytes
bytes-java
Bytes is a utility library that makes it easy to create, parse, transform, validate and convert byte arrays in Java. It supports endianness as well as immutability and mutability, so the caller may decide to favor performance.
Stars: ✭ 120 (+185.71%)
Mutual labels:  bytes, endianness
AvroConvert
Apache Avro serializer for .NET
Stars: ✭ 44 (+4.76%)
Mutual labels:  serialization
json-serialization-benchmarking
Miscellaneous benchmarks for JSON serialization on JVM/Android
Stars: ✭ 48 (+14.29%)
Mutual labels:  serialization
HumanBytes
A library to convert byte sizes to a human readable form
Stars: ✭ 28 (-33.33%)
Mutual labels:  bytes
sbp
Structured Bindings Pack - serialize C++ structs into MessagePack binary form
Stars: ✭ 16 (-61.9%)
Mutual labels:  serialization
reflective-rapidjson
Code generator for serializing/deserializing C++ objects to/from JSON using Clang and RapidJSON
Stars: ✭ 26 (-38.1%)
Mutual labels:  serialization
magic-bytes
A library for detecting file types.
Stars: ✭ 20 (-52.38%)
Mutual labels:  bytes
moonwlker
Jackson JSON without annotation.
Stars: ✭ 14 (-66.67%)
Mutual labels:  serialization
binary
package binary is a lightweight and high-performance serialization library to encode/decode between go data and []byte.
Stars: ✭ 20 (-52.38%)
Mutual labels:  serialization
simplify
simplify 包含了一系列自我驱动学习的子项目。
Stars: ✭ 67 (+59.52%)
Mutual labels:  serialization
laravel5-jsonapi-dingo
Laravel5 JSONAPI and Dingo together to build APIs fast
Stars: ✭ 29 (-30.95%)
Mutual labels:  serialization
sqb
Extensible, multi-dialect SQL query builder and Database connection framework for NodeJS
Stars: ✭ 14 (-66.67%)
Mutual labels:  serialization
nimpb
Protocol Buffers for Nim
Stars: ✭ 29 (-30.95%)
Mutual labels:  serialization
amq-protocol
AMQP 0.9.1 protocol serialization and deserialization implementation for Ruby (2.0+)
Stars: ✭ 47 (+11.9%)
Mutual labels:  serialization
flask-arrested
Flask-Arrested: A Framework For Rapidly Building REST APIs with Flask.
Stars: ✭ 40 (-4.76%)
Mutual labels:  serialization

Introduction

struct is a binary data formatting library inspired by 'The Practice of Programming (Brian W. Kernighan, Rob Pike)' and Python struct module.

Format

struct uses following format characters (note that struct does not fully support the Python struct module's format):

Table 1. Byte order

Character Byte order
= native
< little-endian
> big-endian
! network (= big-endian)

Table 2. Format characters

Format C/C++ Type Standard size
b char 1
B unsigned char 1
h short 2
H unsigned short 2
i int 4
I unsigned int 4
l long 4
L unsigned long 4
q long long 8
Q unsigned long long 8
f float 4
d double 8
s char[]
p char[]
x pad bytes

Pack

#include "struct.h"
...
char buf1[BUFSIZ] = {'\0',};
char buf2[BUFSIZ] = {'\0',};
char str[BUFSIZ] = {'\0',};
char fmt[BUFSIZ] = {'\0',};
int val = 42;

struct_pack(buf1, "i", val);

strcpy(str, "test");
snprintf(fmt, sizeof(fmt), "%ds", strlen(str));

struct_pack(buf2, fmt, str);

Unpack

...
int rval;
char rstr[32] = {'\0',};

struct_unpack(buf1, "i", &rval);

struct_unpack(buf2, fmt, rstr);

Install

mkdir build
cd build
cmake ..
make
make install

headers: build/release/include/struct/. library: build/release/lib/.

Test

cmake -DSTRUCT_BUILD_TEST=ON ..
make
make test

or run struct_test.

valgrind memory check:

ctest -T memcheck

References

The Practice of Programming (9.1 Formatting Data)

Python struct

License

Code released under the MIT license.

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].