diff --git a/uuid.go b/uuid.go index dc75cee..19f2e07 100644 --- a/uuid.go +++ b/uuid.go @@ -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 { diff --git a/uuid_test.go b/uuid_test.go index 906ecbe..c06fc52 100644 --- a/uuid_test.go +++ b/uuid_test.go @@ -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) }