aboutsummaryrefslogtreecommitdiff
path: root/objectid/objectid.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-02-21 10:05:19 +0800
committerGravatar Runxi Yu2026-02-21 11:00:52 +0800
commit1334ea3e45aaf9d2620223215763443647aae5a7 (patch)
treeefe900b59f7f70ddc13d830ea027db7e7bd44ad6 /objectid/objectid.go
parenttestgit: Add git repack (diff)
signatureNo signature
objectid: Add RawBytes
Diffstat (limited to 'objectid/objectid.go')
-rw-r--r--objectid/objectid.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/objectid/objectid.go b/objectid/objectid.go
index 4058bc20..a2fa28c4 100644
--- a/objectid/objectid.go
+++ b/objectid/objectid.go
@@ -159,6 +159,17 @@ func (id ObjectID) Bytes() []byte {
return append([]byte(nil), id.data[:size]...)
}
+// RawBytes returns a direct byte slice view of the object ID bytes.
+//
+// The returned slice aliases the object ID's internal storage. Callers MUST
+// treat it as read-only and MUST NOT modify its contents.
+//
+// Use Bytes when an independent copy is required.
+func (id *ObjectID) RawBytes() []byte {
+ size := id.Size()
+ return id.data[:size:size]
+}
+
// ParseHex parses an object ID from hex for the specified algorithm.
func ParseHex(algo Algorithm, s string) (ObjectID, error) {
var id ObjectID