Motivation
-
The motivation for this product is two fold:
-
To be the
fastestbyte stream serializer/deserializer on the market for latency sensetive usecases. -
To be able to define rust
structthat represent application data models while at the same time not having to write code and instead usingderiveannotations and attributes auto-generate code to put these models on the wire forneworexistinglatencysensitive network protocols. Hence any and all auto generated serialization code should be as fast as one can possibly write by hand.
-
-
Benchmark results below show a performance summary of serializing & deserializing identical
samplestruct with only numeric fields using different frameworkds available:byteserde-~15nsread/writebincode-~15nsread /~100nswrite - this is likely result of the of the write producing a heap allocated vectorrmp-serde-~215nsread/writeserde_json-~600nsread/write - understandably slow due to strings usage- refer to this document for full benchmark details.
Benefit case
- If you work with network protocols that deliver data in
byte streamformat you can use this product to efficently map yourbyte streaminto astructof your choice at zero performance cost and focus on the business logic instead of parsing and mapping. - Please note that unlike
bincode, which comes with its own wire specification for languageprimitives, which you can then use to enchode amessage/actionand send it across the wire, this product is designed to take an existingmessage/actionspecificaiton and map it to a a ruststruct.- See example specifications which are posssible to map to a rust struct using this product but not
bincode:- Ouch5
- SoupBinTCP
- etc..
- See example specifications which are posssible to map to a rust struct using this product but not
The project contains three craits
byteserde_derive@crates.io - byteserde_derive/Cargo.toml
- contains derive macros that generates byteserde@crates.io traits
-
#[derive(ByteSerializeStack)]- generates ByteSerializeStack trait -
#[derive(ByteSerializeHeap)]- generates ByteSerializeHeap trait -
#[derive(ByteDeserialize)]- generates ByteDeserialize<T>trait -
#[derive(ByteSerializedSizeOf)]- generates ByteSerializedSizeOf trait - this trait provides anassociatedmethodbyte_size()which gives you astructmemory size in bytes without alignment. However it does not support types which heap allocate, ex: Vectors, Strings, or their derivations. -
#[derive(ByteSerializedLenOf)]- generates ByteSerializedLenOf trait - this trait provides aninstancemethodbyte_len(&self)which gives you memory size in bytes without alignment of specific instance. It exists specifically to deal with types thatByteSerializedSizeOf traitdoes not support
-
- For more examples follow here
- NOTE: that Union and Unit structure are not supported, but it might change in the future.
byteserde@crates.io - byteserde/Cargo.toml
- Highlights
-
ByteSerializerStack
<CAP>- provides ultra fast serializer 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 multiple times.- works for
structs that implement ByteSerializeStack trait
- works for
-
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.- works for
structs that implement ByteSerializeHeap trait
- works for
-
ByteDeserializer - takes a
byte stream&[u8]irrespctive of heap vs stack allocation and turns it into astruct- works for
structs that implement ByteDeserialize<T>trait
- works for
-
byteserde_types@crates.io - byteserde_types/Cargo.toml
- contains optional ascii string related types and macros, which are typically usefull when dealing with fixed length strings while parsing a
byte stream, follow example section for more details.
Examples & Overview
- Please refer to this document for a number of comprehensive examples and features overview.