Guys there is something else:
Now that my serialization works fine, I still have an issue..
I have a Serialization trait that I implemented for many types.
It runs at runtime, give me the proper types for every fields and I am able to serialize the data accordingly in the final buffer. Runs fine.
The difficulty is when reading the archive after the serialization.
Let's take this struct:
struct A{
field0: String,
field1: u32
}
My ideal logic would be to generate at compile time
// offset in the current received slice
// Block returns an &str.
struct StringBlock{
offset: usize,
len : usize
}
impl StringBlock{
...
}
struct ArchivedA{
field0: StringBlock,
field1: u32
}
But it's not possible because I refuse to create the logic based on field names ( what about aliases (which will often not be mine) and other funky things: I leave that to the compiler, this is insane).
So, I can't pre generate this schema at compile time; I am not talking about writing by hand for a specific struct.
I want to be able to generalize and later use syn and quote for this.
Creating an Archive trait enables to go from original trait to my custom structs. One at a time.
I think I don't get how it can work.
How can I access my field like
let my_a: &ArchivedA = ...
println!("{} {}", my_a.field0, my_a. field1);
field0 in ArchivedA may not occupy as much space as field0 in A so I would have to calculate at runtime the position in the buffer. Doesn't look practical.
So I am stuck at this point.
Again, I do this as an exercise to increase my understanding of the language. Reading through serde and rkyv source code doesn't help, the code is very long and kind of difficult to follow for me right now. Didn't find a really simple rust implementation for beginners.
Thanks a lot for any help you can give me!