zakarumych / alkahest

Fantastic serialization library
Other
157 stars 9 forks source link

0.1.5 to 0.3.0 migration help #9

Open djkoloski opened 1 year ago

djkoloski commented 1 year ago

I'm trying to update my serialization benchmarks for alkahest from 0.1.5 to 0.3.0 but am struggling to figure out what the correct API migration path is:

Thanks for all your hard work!

zakarumych commented 1 year ago

The API has been changed significantly. And I hope it was simplified. At least that was one of the goals.

So 'deserialize' creates new value from raw bytes and 'deserialize_in_place' populates existing value. This works similar to serde's methods of 'Deserialize' trait.

Alkahest no longer generates types to serialize and read data, instead user may implement 'Serialize' and 'Deserialize' traits or derive them.

'Lazy' type is closest to zero-copy deserialization in Alkahest now. It is deserializable from formula in its type parameter, but deserialization is no-op as it just copies reference to bytes slice and size. User may later deserialize from Lazy into any type that is deserializable from formula in type parameter. If formula is a slice, there's additional option to iterate over serialized values deserializing them one by one.

To get 'Lazy' value, just derive 'Deserialize' for a type, using 'Lazy' for the field that you want to deserialize lazily. Make sure to use field type in formula type as type parameter to 'Lazy'.