-
Notifications
You must be signed in to change notification settings - Fork 8
Description
If we have a type that includes another datatype and so on, we still have a write command for each type even so at compile time we would know the entire 'chain'
an example would be:
struct S1 {
v: Vec<u8>
}
struct S2 {
s1: S1
}
struct S3 {
s2: S2
}
serializing S3
would write {"s2":
then {"s1":
then {"v":
then [
and only then the data.
A human observer will notice that we could reduce this to a single call of {"s2":{"s1":{"v":[
.
At the same time we can notice that we do the same on the 'tail' where we will write ]
then }
then }
then }
.
A human observer, again, will notice that we could reduce this to a single call of ]}}}
.
The same logic can be applied to combining <key>:{
and },
for keys that are neither first nor last to reduce write calls further.
An initial though is to split the encoding out into 3 sections:
- static start
- body
- static end
where 1 and 3 take the form of fn static_*() -> &'static u8
so the proc macro can call them on underlying structs to inline those parts of a sub type.