amethyst / hibitset

Hierarchical bit set container
Other
117 stars 32 forks source link

Serialize/Deserialize to/from Vec<u8> #57

Open cisaacson opened 4 years ago

cisaacson commented 4 years ago

Is there a way to serialize hibitset to bytes? I could implement Serde and use bincode, but wanted to know if there is an existing way to do this.

I tested adding optional serde to the source code and it works fine, if you like I can fork and submit a pull request.

WaDelma commented 4 years ago

I don't think there is a way to currently serialize hibitset.

cisaacson commented 4 years ago

The optional serde patch I tried works fine, let me know if you would like a pull request.

To use it looks like this, super easy to use:

let serde_len = bincode::serialized_size(&set1).unwrap();
        let set1_buf = bincode::serialize(&set1).unwrap();

        let result_set1: BitSet = bincode::deserialize(&set1_buf).unwrap();
WaDelma commented 4 years ago

I wouldn't resist adding such feature, so if you want to create PR it would be appreciated.

We most likely want to have it under a feature flag so we wont incur unnecessary dependencies users of the library.

cisaacson commented 4 years ago

Exactly how I implemented it (as an optional feature) :) I will submit a PR when I have fully tested it.

cisaacson commented 4 years ago

The PR has been submitted, let me know if you need anything else.