Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions uuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,13 @@ func (uuid UUID) String() string {
return string(buf[:])
}

// Bytes returns the bytes form of uuid, xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.
func (uuid UUID) Bytes() []byte {
var buf [36]byte
encodeHex(buf[:], uuid)
return buf[:]
}

// URN returns the RFC 2141 URN form of uuid,
// urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx, or "" if uuid is invalid.
func (uuid UUID) URN() string {
Expand Down
3 changes: 3 additions & 0 deletions uuid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@ func TestCoding(t *testing.T) {
if v := data.String(); v != text {
t.Errorf("%x: encoded to %s, expected %s", data, v, text)
}
if bs := data.Bytes(); string(bs) != text {
t.Errorf("%x: encoded to %s, expected %s", data, string(bs), text)
}
if v := data.URN(); v != urn {
t.Errorf("%x: urn is %s, expected %s", data, v, urn)
}
Expand Down