blob: 1ca0c6dfc84d13d783bfdaee569f1e6721792cc1 (
about) (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
package id
import (
"bytes"
"encoding/hex"
)
// Algorithm returns the object ID's hash algorithm.
func (id ObjectID) Algorithm() Algorithm {
return id.algo
}
// Bytes returns a copy of the object ID bytes.
func (id ObjectID) Bytes() []byte {
size := id.Algorithm().Size()
return append([]byte(nil), id.data[:size]...)
}
// RawBytes returns a direct byte slice view of the object ID bytes.
//
// Prefer [ObjectID.Bytes] except for when it is a performance bottleneck.
//
// Labels: Mut-No.
func (id *ObjectID) RawBytes() []byte {
size := id.Algorithm().Size()
return id.data[:size:size]
}
// Compare lexicographically compares two object IDs
// by their canonical byte representation.
func (id ObjectID) Compare(other ObjectID) int {
return bytes.Compare(id.RawBytes(), other.RawBytes())
}
// String returns the canonical hex representation.
func (id ObjectID) String() string {
size := id.Algorithm().Size()
return hex.EncodeToString(id.data[:size])
}
|