From 1334ea3e45aaf9d2620223215763443647aae5a7 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Sat, 21 Feb 2026 10:05:19 +0800 Subject: objectid: Add RawBytes --- objectid/objectid.go | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'objectid/objectid.go') 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 -- cgit v1.3.1-10-gc9f91