fraillt/bitsery

User-defined `deserialize` function?

DUOLabs333 opened this issue · 4 comments

Can we just define a custom deserialize function the same way we do for serialize?

I believe the serialize function acts as both the deserialization and serialization function. I wonder what your use case is?

Well, for example, I sometimes want a struct to be deserialized differently than how it's serialized (eg, I get some new information back that I need to specially handle).

Bitsery uses so called extensions to achieve this.
The idea is that you usually describe (declare) how particular struct will be serialized and deserialized, but extensions allow to customize how actual serialization and deserialization is implemented for particular type.
You can try to look in tutorials, or directly into bunch of extensions implementation.

Thanks.