ReStruct is a simple and light weight binary object serialisation / de-serialisation library for C#
The main objective is to provide an easy way to define data structures and serialise them with no overheads. This is a naive approach when compared to modern serialisation techniques and libaries such as protobuf but often times such an approach is desirable when working with legacy systems where the protocol can't be redefined.
- Supports Big Endian and Little Endian formats
- Supports Unsigned integers, boolean, arrays and classes
using ReStruct.Serializer;
[ReStruct(Endianness.Big)]
public class ControlInfo
{
public UInt32 Target;
[ReStructArray(4)]
public byte[] Vectors;
}
[ReStruct(Endianness.Big)]
public class Header
{
public UInt32 CommandId;
public ControlInfo ControlInfo;
}
var mesage = new Header
{
CommandId = 1,
ControlInfo = new ControlInfo
{
Target = 200,
Vectors = new byte[4] {0xaa, 0x55, 0xFF, 0x01}
}
};
new BinarySerializer().Serialize(stream, message);
var header = new BinarySerializer().Deserialize<Header>(stream);
ReStruct is licensed under MIT LICENSE