diff options
| author | 2026-02-21 12:27:55 +0800 | |
|---|---|---|
| committer | 2026-02-21 12:27:55 +0800 | |
| commit | 680d30bd77c4793fe5c1eaa05ad5217a2faee7c0 (patch) | |
| tree | 94f41a7ad5c9f82cce15639c969a42194b486dfa /refstore/reftable/parse_helpers.go | |
| parent | testgit: Add RepoOptions and NewRepo for ref format and bare. (diff) | |
| signature | No signature | |
refstore/reftable: Add basic implementation
Diffstat (limited to 'refstore/reftable/parse_helpers.go')
| -rw-r--r-- | refstore/reftable/parse_helpers.go | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/refstore/reftable/parse_helpers.go b/refstore/reftable/parse_helpers.go new file mode 100644 index 00000000..b5da555e --- /dev/null +++ b/refstore/reftable/parse_helpers.go @@ -0,0 +1,36 @@ +package reftable + +import "fmt" + +// readUint24 reads a 24-bit big-endian unsigned integer. +func readUint24(b []byte) uint32 { + return uint32(b[0])<<16 | uint32(b[1])<<8 | uint32(b[2]) +} + +// alignUp rounds pos up to the next multiple of blockSize. +func alignUp(pos, blockSize int) int { + rem := pos % blockSize + if rem == 0 { + return pos + } + return pos + (blockSize - rem) +} + +// readVarint decodes one reftable/ofs-delta style varint. +func readVarint(buf []byte, off, end int) (uint64, int, error) { + if off >= end { + return 0, 0, fmt.Errorf("unexpected EOF") + } + b := buf[off] + val := uint64(b & 0x7f) + off++ + for b&0x80 != 0 { + if off >= end { + return 0, 0, fmt.Errorf("unexpected EOF") + } + b = buf[off] + off++ + val = ((val + 1) << 7) | uint64(b&0x7f) + } + return val, off, nil +} |
