Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add automatic json serialization and deserialization #143

Open
Shahab96 opened this issue Apr 1, 2024 · 4 comments · May be fixed by #142
Open

Add automatic json serialization and deserialization #143

Shahab96 opened this issue Apr 1, 2024 · 4 comments · May be fixed by #142

Comments

@Shahab96
Copy link
Contributor

Shahab96 commented Apr 1, 2024

No description provided.

@Shahab96 Shahab96 linked a pull request Apr 1, 2024 that will close this issue
@aisk
Copy link
Owner

aisk commented Apr 1, 2024

The original idea to automatically load and dump JSON/msgpack values is from the Python memcache client. The pymemcache can set a normal Python object with its set method, serialize it with Python's pickle library, and use a bit flag stored in the memcache flag to indicate it. When getting a key with such a value, pymemcache will check the flag and use pickle to deserialize the value.

I haven't dug too much to see if Rust can implement this too, but I guess maybe we can try to see if we can let Serialize / Deserialize implement FromMemcacheValue / ToMemcacheValue to achieve the goal.

And If we can implment this, I think we can just implment one serialization protocol like JSON, and add a hook to let user change the default behavior to change the serialization protocol and compress format.

@Shahab96
Copy link
Contributor Author

Shahab96 commented Apr 1, 2024

Looking through the code, this should be possible to implement. There is a catch though, right now we don't actually set flags for anything anywhere so we would need to add that first. This would unfortunately need changes to the arguments passed into set in ProtocolTrait to allow the caller to pass flags in. The drawback there is that once we allow that there wouldn't be a way to tell whether a flag was set by us or by the user, and honestly us setting a flag doesn't seem like good behavior as we could possibly be overwriting user data.

An alternative is to allow the user to select a serialization type for the connection, and simply have everything serialized to the selected type, however this would mean the consumer wouldn't be able to use different ser/de types for different keys.

What are your thoughts on this?

@Shahab96
Copy link
Contributor Author

Shahab96 commented Apr 1, 2024

I do think we should adjust the arguments for set either way, as currently consumers of this library have no way to set flags on their data unless I am mistaken in my understanding of the code

@aisk
Copy link
Owner

aisk commented Apr 6, 2024

Sorry late for the reply. Already commented on the new issue. I think it's fine to add a mechanism to let users specify the flags.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants