Skip to content

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

Merged
merged 11 commits into from
May 20, 2021

Conversation

kenkoooo
Copy link
Contributor

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.

@pooooodles
Copy link

Tracked in https://jira.mongodb.org/browse/RUST-687

@pooooodles pooooodles added the tracked-in-jira Ticket filed in Mongo's Jira system label Mar 1, 2021
Copy link
Contributor

@patrickfreed patrickfreed left a 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.

@pooooodles
Copy link

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!

@kenkoooo
Copy link
Contributor Author

@agolin95 Thank you for your confirmation. Let me try to implement as @patrickfreed suggested.

@kenkoooo kenkoooo force-pushed the feature/deserialize_uuid_old branch from 0948b5f to 94dbb48 Compare April 25, 2021 12:23
@kenkoooo kenkoooo force-pushed the feature/deserialize_uuid_old branch from 94dbb48 to 27c1ee2 Compare April 25, 2021 12:24
@kenkoooo
Copy link
Contributor Author

Hi, sorry for the very slow work. I update my PR as @patrickfreed suggested. Could you take a look into it? Thanks!

@patrickfreed patrickfreed changed the title Support deserializing binary of UuidOld RUST-687 Support deserializing binary of UuidOld May 11, 2021
Copy link
Contributor

@patrickfreed patrickfreed left a 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_ after uuid? We're versioning these helpers in order to support multiple semver-breaking versions of uuid as they come out. See #255 for more info (you can leave the exising uuid_as_binary one alone, that'll be updated in that PR)
  • Can we add top level re-exports of the serialize and deserialize 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!

@kenkoooo
Copy link
Contributor Author

@patrickfreed Thanks for your review! I updated it.

@patrickfreed
Copy link
Contributor

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.

Copy link
Contributor

@isabelatkinson isabelatkinson left a 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!

@kenkoooo
Copy link
Contributor Author

@isabelatkinson @patrickfreed Thanks! I reformat by cargo +nightly fmt.

Copy link
Contributor

@patrickfreed patrickfreed left a 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 !

@patrickfreed patrickfreed merged commit 87f8056 into mongodb:master May 20, 2021
@kenkoooo kenkoooo deleted the feature/deserialize_uuid_old branch May 20, 2021 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tracked-in-jira Ticket filed in Mongo's Jira system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants