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

Added support for marshaling/unmarshaling of MongoDB's BSON UUID binary format #92

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

inliquid
Copy link

@inliquid inliquid commented Jan 2, 2019

Added support for marshaling/unmarshaling of MongoDB's BSON UUID binary format.

…marshaling in MongoDB's BSON binary UUID format with Legacy UUID as default kind (0x03).

- Introduced SetBSONKind function to make user able to set different BSON kind.
@coveralls
Copy link

coveralls commented Jan 2, 2019

Coverage Status

Coverage decreased (-7.03%) to 90.49% when pulling 186ab35 on inliquid:master into b2ce238 on satori:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-7.03%) to 90.49% when pulling d437470 on inliquid:master into b2ce238 on satori:master.

@inliquid inliquid changed the title master Added support for marshaling/unmarshaling of MongoDB's BSON UUID binary format Jan 3, 2019
@saniales
Copy link

saniales commented Jan 20, 2019

I would disagree regarding this pr since there are different libraries for handling BSON format (eg mongo-go-driver and mgo) so it's better to have this implementation outside the package scope
Will update later with my solution on stack overflow
The method you are implementing is specific to mgo

EDIT:

You can find a solution to this problem on the following stackoverflow link
https://stackoverflow.com/questions/50889485/how-should-i-handle-uuid-fields-using-mgo/54094766#54094766

@inliquid
Copy link
Author

inliquid commented Feb 5, 2019

@saniales the above stackoverflow link covers different and quite too much particular case (it's close but not the same, also please pay attention that proposed solution covers both Mongo's Legacy UUID and new UUID binary kinds). And yes of course it's possible to embed UUID into your own struct and write Marshaler/Unmarshaler for that struct. However, if you try to do so you'll find that code becomes more complex, less clear, and overall it seems strange when support for JSON comes out of the box, but for BSON you have to reinvent the wheel. In my project I did this trick with embedded struct initially, but later moved to forked version of UUID implementation. From the other hand, I understand concerns for external dependencies.

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 this pull request may close these issues.

3 participants