roaring-rs icon indicating copy to clipboard operation
roaring-rs copied to clipboard

Serde support?

Open rw opened this issue 4 years ago • 5 comments

It would be useful to have built-in serde support for storing and retrieving bitmaps from this library. Could the existing serialization functions be used to implement this efficiently?

rw avatar Jun 19 '20 23:06 rw

The existing serialisation functions are good for reading/writing to byte buffers/files etc. I'm not sure exactly what serde support entails however but assuming it's about either writing to files or transmitting across the network then yes, the existing functions are good + efficient.

josephglanville avatar Jun 20 '20 10:06 josephglanville

@josephglanville It would be very convenient for this library to impl serde::Serialize and serde::Deserialize, so that users could use serde derive automagically. :-]

rw avatar Jun 20 '20 21:06 rw

This should be relatively trivial to implement, though unfortunately because of serde's design it will require serializing the entire bitmap into a Vec<u8> before writing to the serializer.

Nemo157 avatar Jun 20 '20 21:06 Nemo157

Has anyone tried this approach? https://riptutorial.com/rust/example/20152/implement-serialize-and-deserialize-for-a-type-in-a-different-crate

ingberam avatar Nov 23 '21 20:11 ingberam

One consideration is human readable formats.

It's not immediately obvious how to do serde from a binary format into a human readable one. For example, default behavior of serde_json is to encode it as a json array of numbers: serde-rs/json#360. Users would likely need to use something like serde_with or a newtype regardless if we provided a Serializeimpl.

saik0 avatar Jan 10 '22 03:01 saik0