cookie_store icon indicating copy to clipboard operation
cookie_store copied to clipboard

Add serialization deserialization

Open dcampbell24 opened this issue 1 year ago • 4 comments

This is the general idea. I can make load generic like I did with save. With a struct that implements Serialize and Deserialize it is easy to add other implementations besides JSON. I am partial to RON, and you mentioned a curl cookie format. Let me know what you think and what I have to change to get this included, along with what tests you expect.

I didn't reuse more code than I did, because the old code was line oriented, but this Serializes and Deserializes the whole blob at once.

I am creating a pull request, but I expect some work to be done before a merge happens.

dcampbell24 avatar Jul 28 '24 04:07 dcampbell24

I made load generic.

dcampbell24 avatar Jul 28 '24 21:07 dcampbell24

Sorry about making so many commits, but this is ready for review.

dcampbell24 avatar Aug 02 '24 03:08 dcampbell24

Thanks for the work here; I haven't had a chance to do a proper review, so just touching this to let you know I've seen it and hope to have a chance to look it over soon.

pfernie avatar Aug 23 '24 15:08 pfernie

Okay thanks. no rush.

dcampbell24 avatar Aug 31 '24 04:08 dcampbell24

I had some time to review this. I did a bit of a refactor; I introduced mod serde::{json,ron} and moved the relevant implementations there. I also feature gated the functionality, to avoid unnecessary dependencies. The serde_Json feature is currently enabled by default to avoid surprises, but a release will have to be a major ("0."-style, so 0.22.0) version bump anyway, so it might be better to take the opportunity and not enable it by default and avoid pulling in serde when not wanted.

I also dropped the intermediate CookieStoreSerialized struct, and just serialize/deserialize through a Vec<>, to avoid the extra level of nesting. IDK if that still suits your purpose; the only reason I'd see not to take this approach is if we anticipated adding more fields to the CookieStore that we'd want to serialize (I currently don't have any such plans).

Finally, as commented before, I don't want to fully remove the existing CookieStore::save_json and co. The new approach is IMO better, but if there are users out there (such as myself...) with "old" style cookie stores serialized, the new methods won't work with them since they are not actually valid JSON. I've introduced documentation around it to highlight the difference b/w the old methods and the new serde::Json module, as well as marking them deprecated to discourage their use.

LMK if this is still in line with the functionality you were intending.

pfernie avatar Oct 08 '24 20:10 pfernie

Yeah, it's good! Thanks for your work.

dcampbell24 avatar Oct 09 '24 00:10 dcampbell24