File tree 2 files changed +16
-0
lines changed
2 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -234,6 +234,11 @@ func MustParseStrict(ulid string) ULID {
234
234
return id
235
235
}
236
236
237
+ // Bytes returns bytes slice representation of ULID.
238
+ func (u ULID ) Bytes () []byte {
239
+ return u [:]
240
+ }
241
+
237
242
// String returns a lexicographically sortable string encoded ULID
238
243
// (26 characters, non-standard base 32) e.g. 01AN4Z07BY79KA1307SR9X4MV3
239
244
// Format: tttttttttteeeeeeeeeeeeeeee where t is time and e is entropy
Original file line number Diff line number Diff line change @@ -619,6 +619,17 @@ func TestMonotonicSafe(t *testing.T) {
619
619
}
620
620
}
621
621
622
+ func TestULID_Bytes (t * testing.T ) {
623
+ tt := time .Unix (1000000 , 0 )
624
+ entropy := ulid .Monotonic (rand .New (rand .NewSource (tt .UnixNano ())), 0 )
625
+ id := ulid .MustNew (ulid .Timestamp (tt ), entropy )
626
+ bid := id .Bytes ()
627
+ bid [len (bid )- 1 ]++
628
+ if bytes .Equal (id .Bytes (), bid ) {
629
+ t .Error ("Bytes() returned a reference to ulid underlying array!" )
630
+ }
631
+ }
632
+
622
633
type safeMonotonicReader struct {
623
634
mtx sync.Mutex
624
635
ulid.MonotonicReader
You can’t perform that action at this time.
0 commit comments