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

Requesting some clarification on a sentence in README #19

Closed
shawnps opened this issue Sep 13, 2017 · 2 comments
Closed

Requesting some clarification on a sentence in README #19

shawnps opened this issue Sep 13, 2017 · 2 comments

Comments

@shawnps
Copy link
Contributor

shawnps commented Sep 13, 2017

Hi, could someone confirm if my understanding of this sentence is correct?

"One loss due to this change is the ability to represent an invalid UUID (vs a NIL UUID)."

This is saying that it's not possible to represent an invalid UUID with the google/uuid library because it is a strict 16-byte array rather than a byte slice? When/why would I want to be able to represent invalid UUIDs, for testing?

Thank you!

@pborman
Copy link
Collaborator

pborman commented Sep 13, 2017

Yes, that is the correct understanding.

The original uuid package (github.com/pborman/uuid) was based on slices has the following function:

func Parse(s string) UUID

This package had to change this to:

func Parse(s string) (UUID, error)

If you have a type that contains an optional UUID nothing special needs to be added for a byte slice representation:

type S struct {
        ID uuid.UUID
}

if s.ID != nil {
        fmt.Printf("ID is %v\n", s.ID)
}

With an array it becomes be one of

type S1 struct {
        ID     uuid.UUID
        HaveID bool
}
type S2 struct {
        ID *uuid.UUID
}

if s1.HaveID {
        fmt.Printf("ID is %v\n", s1.ID)
}
if s2.ID != nil {
        fmt.Printf("ID is %v\n", *s2.ID)
}

This is the only reason that there is both a github/pborman/uuid package and a github/google/uuid package (the pborman version is the original, the google version addresses the desire of making UUIDs comparable objects by switch from a slice to an array. It changes the code from:

if uuid.Compare(uuid1, uuid2) {

to

if uuid1 == uuid2 {

and also allows UUIDs to be used as keys in a map.

@shawnps
Copy link
Contributor Author

shawnps commented Sep 13, 2017

@pborman I see, thank you for the clarification! I'll close this issue out.

@shawnps shawnps closed this as completed Sep 13, 2017
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

No branches or pull requests

2 participants