From 0f459825a36dbd510a0a5975cba5af073fa42cbd Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Sat, 21 Feb 2026 00:05:23 +0800 Subject: objectdb: Add ObjectDB interface --- objectdb/objectdb.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 objectdb/objectdb.go (limited to 'objectdb') diff --git a/objectdb/objectdb.go b/objectdb/objectdb.go new file mode 100644 index 00000000..3e45893a --- /dev/null +++ b/objectdb/objectdb.go @@ -0,0 +1,26 @@ +// Package objectdb provides storage interfaces for Git objects. +package objectdb + +import ( + "errors" + + "codeberg.org/lindenii/furgit/objectid" + "codeberg.org/lindenii/furgit/objecttype" +) + +// ErrObjectNotFound indicates that an object does not exist in a backend. +// TODO: This might need to be an interface or otherwise be able to encapsulate multiple concrete backends' +var ErrObjectNotFound = errors.New("objectdb: object not found") + +// ObjectDB reads Git objects by object ID. +type ObjectDB interface { + // ReadBytesFull reads a full serialized object as "type size\\x00content". + // If hashed with the same algorithm it MUST match the object ID. + ReadBytesFull(id objectid.ObjectID) ([]byte, error) + // ReadBytesContent reads an object's type and content bytes. + ReadBytesContent(id objectid.ObjectID) (objecttype.Type, []byte, error) + // ReadHeader reads an object's type and declared content length. + ReadHeader(id objectid.ObjectID) (objecttype.Type, int64, error) + // Close releases resources associated with the backend. + Close() error +} -- cgit v1.3.1-10-gc9f91