ESDE (SE-rialize and DE-serialize library)
The idea is to easily store non-recursive data structures to files and read them back. "Easy" in that context means that the format is understandable by humans and can therefore, in theory, produced from other languages/frameworks as well.
This crate is focused on storing data in binary form, but can be adapted to store it in other formats.
It also provides derive macros (Deserialize
and Serialize
) to derive the corresponding traits for structs and enums.
note on cross-platform:
There are no particular guarantees.
Most importantly, lengths of slices/vectors are stored as [usize
]s, the length of which can vary from platform to platform.
Item
s
Items are the units in which data is serialized.
This can be anything.
I guess in most cases, the data structure is serialized into binary data to store it in a file, then a [u8
] will be used.
deserialization
You have an object that provides Item
s, implementing the [Sender
] trait.
This trait is automatically implemented for any [std::io::Read
], "sending" [u8
]s.
Objects that can be deserialized from a stream of given Item
s implement the [Deserialize<Item>
] trait.
Implementations for some primitive types are provided, most others should be derivable with the corresponding and intuitively named derive macro.
If an object is deserialized, its type must be known. In other words: One must know the type before the type can be parsed. No information what type is stored is provided by the library.
serialization
You have an object than accepts Item
s, implementing the [Receiver
] trait.
This trait is automatically implemented for any [std::io::Write
], receiving [u8
]s;
Any type that implements the [Serialize<Item>
] trait can be serialized with any [Receiver<Type = Item>
].
Some implementations of primitve types are provided.
example
;
planned future features
- attribute for ignoring fields when (de)serializing, they must implement [
Default
] - handle generic types