diff options
| author | 2026-02-21 10:05:19 +0800 | |
|---|---|---|
| committer | 2026-02-21 11:00:52 +0800 | |
| commit | 1334ea3e45aaf9d2620223215763443647aae5a7 (patch) | |
| tree | efe900b59f7f70ddc13d830ea027db7e7bd44ad6 /objectid/objectid.go | |
| parent | testgit: Add git repack (diff) | |
| signature | No signature | |
objectid: Add RawBytes
Diffstat (limited to 'objectid/objectid.go')
| -rw-r--r-- | objectid/objectid.go | 11 |
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 |
