BeBytes
BeBytes is a Rust library that provides the BeBytes trait and the BeBytes derive macro for serialization and deserialization of network structs. It allows you to convert your Rust structs into byte representations (serialization) and vice versa (deserialization) using big endian order.
Usage
Add this to your Cargo.toml:
[]
= "0.1"
Then, import the BeBytes trait and use it as a trait bound in your method signatures:
use BeBytes;
You can also use the BeBytes derive macro to automatically generate serialization and deserialization methods for your structs:
use BeBytes;
The BeBytes derive macro will generate the following methods for your struct:
try_from_be_bytes(&[u8]) -> Result<(Self, usize), Box<dyn std::error::Error>>: A method to convert a byte slice into an instance of your struct. It returns a Result containing the deserialized struct and the number of consumed bytes.to_be_bytes(&self) -> Vec<u8>: A method to convert the struct into a byte representation. It returns aVec<u8>containing the serialized bytes.field_size(&self) -> usize: A method to calculate the size (in bytes) of the struct.
Contribute
I'm doing this for fun, but all help is appreciated. Thanks
License
This project is licensed under the MIT License