Crates.io | gs11n |
lib.rs | gs11n |
version | 0.3.1 |
source | src |
created_at | 2022-01-08 18:14:07.977061 |
updated_at | 2023-03-05 05:53:49.962981 |
description | Utililties need for GS11N |
homepage | |
repository | https://github.com/psionic12/gs11n |
max_upload_size | |
id | 510369 |
size | 87,447 |
GS11N is a Serialization crate which focus on Game development. By adding attributes, your rust codes will looks like scripts in Unity or UE
The minimum Rust version required to use GS11N is 1.57.0
#[derive(GS11N, Default)]
struct Orc {
#[serialized(0)]
health: usize,
#[serialized(1)]
mana: usize,
}
then serialize and deserialize it:
let encoder = Encoder::from(&orc);
let buffer = encoder.encode();
let decoder = Decoder::from_data(buffer);
let orc: Orc = decoder.decode().unwrap();
Notice that you struct type must implement trait Default
for now, this restriction may be relaxed in the future.
GS11N use some ideas from Protobuf, which are:
Other features are:
dyn
type, but need to give the type an type ID (check tests for a example)dyn
types can be compiled into a dynamic library, and load it later, this can be useful when debugging
or code updating (for example a hot fix or a DLC).#[derive(PartialEq, Debug, GS11N, Default)]
#[compact]
struct Color {
r: u8,
g: u8,
b: u8,
};
notice that is you choose to do this, the encoded date will not compatible if fields are added or removed
if you do not want to generate serialization or deserialization code:
#[derive(PartialEq, Debug, GS11N, Default)]
#[no_deserialization]
struct Foo {
str: &'static str,
}
Features in progressing: