Motivation
-
The goal of this product is to provide a set of utilities that enable frictionless transitioning between a
byte stream, ex:&[u8], and an arbitrarystruct. In other words, the project provides a set oftraitsandimpl's that can be used to manuallyserializean arbitrarystructinto abyte streamas well as todeserializea givenbyte streaminto it originalstruct. -
In addition to be able to custom serialize an arbitrary
struct, you can leverage an included#[derive(..)]proc_macroand a number usefullmacro attributesto create automatically generated serialize and deserializetraitimplementation that covers most of typical usecases.
Benefit case
-
If you work with network streams which deliver data in
byte streamformat and a well defined sequence you can use this product to quickly and efficently map yourbyte streaminto astructof your choice and focus on the business logic instead of parsing and mapping. -
if you have two or more systems which need to communicate with each other, either over a network socket or a shared memory, but at a very
low latency/cpu cost, this product is a good choice for you.
Structure
- The project contains two cargo artifacts
-
byteserde- Cargo.toml-
contains ByteSerializeStack, ByteSerializeHeap & ByteDeserialize
<T>traitsand helperstruct's that make it easy to manually create custombyte streamserailizer and deserializer -
ByteSerializerStack
<CAP>- provides ultra fast speed by serializing into a pre allocatedbyte array[u8; CAP]onstack, hence the name, it is very fast but at the cost of you needing to specify the size of the LARGESTstructyou will attempt to serialize. If you reach the boundary of this preallocated byte array, your serialization will fail. This utility provides a reset features, which moves the internal counter to the begining, and allows you to recycle the buffer for multiple purpoces. -
ByteSerializerHeap - provides a fast enough for most speed by serializing into a
byte vectorVec<u8>, hence the name. This utility trades some performance in return for not having to worry about knowing the LARGESTstructsize in advance. -
ByteDeserializer - takes a
byte stream&[u8]irrespctive of heap vs stack allocation and turns it into astruct
-
-
byteserde_derive- byteserde/Cargo.toml- contains procedural macro that generaters implementation of these traits on regular & tuple rust structure.
- NOTE: that Union, Enum, and Unit structure are not not currently supported
-
Examples & Overview
- Please reffer to this document for a number of helpfull examples and feature review.
Want to contribute?
- Here are a few useful hints to get you started developers corner