-
Notifications
You must be signed in to change notification settings - Fork 144
RUST-687 Support deserializing binary of UuidOld #239
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
RUST-687 Support deserializing binary of UuidOld #239
Conversation
Tracked in https://jira.mongodb.org/browse/RUST-687 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @kenkoooo! Thank you or the PR, and thank you @jcdyer for bringing up the UUID spec! I think this implementation looks great so far, but I think we'll want to go for a slightly different API to be consistent with how we currently handle regular subtype 4 UUIDs.
By that I mean, instead of separate types for each of the different UUIDs, can we change this to introduce separate serde_helper
modules for each? This matches the current UUID subtype 4 API.
e.g.
#[derive(Serialize, Deserialize)]
struct MyUuids {
// This is the existing UUID helper
#[serde(with = "serde_helpers::uuid_as_binary")]
regular: Uuid,
// Below would be the new ones for each legacy type
#[serde(with = "serde_helpers::uuid_as_java_legacy_binary")]
java_legacy: Uuid,
#[serde(with = "serde_helpers::uuid_as_python_legacy_binary")]
python_legacy: Uuid,
#[serde(with = "serde_helpers::uuid_as_c_sharp_legacy_binary")]
c_sharp_legacy: Uuid,
}
Check out serde_helpers.rs
for an example implementation for the subtype 4 version.
For datetimes, we originally did go the route of introducing a new type (bson::DateTime
) which wraps the regular chrono::DateTime
and has special Serialize
and Deserialize
implementations, but users tended to find it confusing / hard to use / hard to discover. As a result, we opted to take the serde_helper
approach for Uuid
instead as it is a bit more explicit / configurable, so I think we should continue to use that pattern for these legacy variants too.
Hey @kenkoooo just wanted to drop a comment to make sure you saw Patrick's feedback, are these changes you would like to make or would you prefer we push up changes to this branch ourselves? Thanks for all the hard work! |
@agolin95 Thank you for your confirmation. Let me try to implement as @patrickfreed suggested. |
0948b5f
to
94dbb48
Compare
94dbb48
to
27c1ee2
Compare
Hi, sorry for the very slow work. I update my PR as @patrickfreed suggested. Could you take a look into it? Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes look great! I only have a few minor comments:
- Can we update the module names to include
_0_8_
afteruuid
? We're versioning these helpers in order to support multiple semver-breaking versions ofuuid
as they come out. See #255 for more info (you can leave the exisinguuid_as_binary
one alone, that'll be updated in that PR) - Can we add top level re-exports of the
serialize
anddeserialize
functions similar to what we have for the other ones? Check the top of the file for the pattern there. - There are a few clippy failures, it looks like there are a few unneeded clones of uuid's in
src/tests/serde.rs
. Don't worry about the decimal128 ones--those are pre-existing.
Thanks again for your contribution!
…on-rust into feature/deserialize_uuid_old
@patrickfreed Thanks for your review! I updated it. |
Looks like rustfmt needs to be run, but other than that it looks good to me! (note: we use the nightly version of rustfmt). tagging in @isabelatkinson for review as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM once the formatting errors are fixed, thanks for your contribution!
@isabelatkinson @patrickfreed Thanks! I reformat by |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thank you for your contribution @kenkoooo !
Since I have a lot of existing binary data of subtype=0x03, which is a subtype of old UUID, I added support to deserialize such binary data to UUID.