Can there be a decode_without_loss() function in the Rust Candid crate?

Can there be a decode_without_loss() function in the candid rust crate that throws an error if the decoded structure would lose data in the de-serialization? A decode function that does not support the backwards compatibility features of candid?

The use case is for serialization during upgrades, I want to make sure users of a library in the post_upgrade hook don’t accidentally de-serialize their data onto a struct that would lose data.

@chenyan thoughts?

Candid is designed for describing interface, and is not a great fit for stable memory upgrade. The opt rule you mentioned is one problem. The other problem is that it doesn’t support sharing. It’s possible that a graph structure can take exponential space in stable memory. Have you considered other serialization format?

Thanks, I have considered some but there are many. Do you know of a good serialization format that supports sharing and cannot lose data on the de-serialization?

I don’t have first hand experience, but I’ve heard people using protobuf, MessagePack, and RON. They are probably also more cycle efficient than Candid.

1 Like

That helps to narrow it down. MessagePack looks cool.