Skip to content
Merged
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
5 changes: 5 additions & 0 deletions ulid.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ func MustParseStrict(ulid string) ULID {
return id
}

// Bytes returns bytes slice representation of ULID.
func (u ULID) Bytes() []byte {
return u[:]
}

// String returns a lexicographically sortable string encoded ULID
// (26 characters, non-standard base 32) e.g. 01AN4Z07BY79KA1307SR9X4MV3
// Format: tttttttttteeeeeeeeeeeeeeee where t is time and e is entropy
Expand Down
11 changes: 11 additions & 0 deletions ulid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,17 @@ func TestMonotonicSafe(t *testing.T) {
}
}

func TestULID_Bytes(t *testing.T) {
tt := time.Unix(1000000, 0)
entropy := ulid.Monotonic(rand.New(rand.NewSource(tt.UnixNano())), 0)
id := ulid.MustNew(ulid.Timestamp(tt), entropy)
bid := id.Bytes()
bid[len(bid)-1]++
if bytes.Equal(id.Bytes(), bid) {
t.Error("Bytes() returned a reference to ulid underlying array!")
}
}

type safeMonotonicReader struct {
mtx sync.Mutex
ulid.MonotonicReader
Expand Down