git/odb/pack: introduce *Chain type

This commit is contained in:
Taylor Blau 2017-09-05 16:59:59 -04:00
parent 9ea23ca017
commit c7f13cdab2
2 changed files with 33 additions and 0 deletions

21
git/odb/pack/chain.go Normal file

@ -0,0 +1,21 @@
package pack
// Chain represents an element in the delta-base chain corresponding to a packed
// object.
type Chain interface {
// Unpack unpacks the data encoded in the delta-base chain up to and
// including the receiving Chain implementation by applying the
// delta-base chain successively to itself.
//
// If there was an error in the delta-base resolution, i.e., the chain
// is malformed, has a bad instruction, or there was an mmap-related
// read error, this function is expected to return that error.
//
// In the event that a non-nil error is returned, it is assumed that the
// unpacked data this function returns is malformed, or otherwise
// corrupt.
Unpack() ([]byte, error)
// Type returns the type of the receiving chain element.
Type() PackedObjectType
}

@ -0,0 +1,12 @@
package pack
type ChainSimple struct {
X []byte
Err error
}
func (c *ChainSimple) Unpack() ([]byte, error) {
return c.X, c.Err
}
func (c *ChainSimple) Type() PackedObjectType { return TypeNone }