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

feat: add uuid bytes #140

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

Conversation

rfyiamcool
Copy link

summary

add Bytes() for uuid object.

@rfyiamcool rfyiamcool requested a review from a team as a code owner November 24, 2023 03:21
Copy link

google-cla bot commented Nov 24, 2023

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

uuid.go Outdated
@@ -194,6 +194,14 @@ func (uuid UUID) String() string {
return string(buf[:])
}

// Bytes returns the bytes form of uuid, xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
// , or "" if uuid is invalid.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function cannot fail so there should just be a period at the end of line 197.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, It's ok ? 😁

uuid_test.go Outdated
@@ -224,6 +224,33 @@ func TestNew(t *testing.T) {
}
}

func TestBytes(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is not actually required. Instead, TestCoding should be modified to include a test of Bytes().

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done 😁

Signed-off-by: rfyiamcool <rfyiamcool@163.com>
Signed-off-by: rfyiamcool <rfyiamcool@163.com>
@it512
Copy link
Contributor

it512 commented Dec 9, 2023

func (uuid UUID) StringBytes() []byte {
 	var buf [36]byte
 	encodeHex(buf[:], uuid)
 	return buf[:]
 }

func (uuid UUID) Bytes() []byte{
 	return uuid[:] 
}

这样实现是不是更好?
Is it better to implement it this way?
@rfyiamcool @bormanp

@bormanp
Copy link
Collaborator

bormanp commented Dec 11, 2023

@it512 To get the bytes representation of a uuid you just have to say uuid[:] as you suggest, there is no reason for a function call. I believe the rationale behind Bytes() is to prevent the conversion from []byte -> string -> []byte. Do you have an alternate suggestion for the functions name? HexBytes?

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.

None yet

3 participants