Imported Upstream version 2.4.2
[scm/test.git] / git / odb / object.go
1 package odb
2
3 import "io"
4
5 // Object is an interface satisfied by any concrete type that represents a loose
6 // Git object.
7 type Object interface {
8         // Encode takes an io.Writer, "to", and encodes an uncompressed
9         // Git-compatible representation of itself to that stream.
10         //
11         // It must return "n", the number of uncompressed bytes written to that
12         // stream, along with "err", any error that was encountered during the
13         // write.
14         //
15         // Any error that was encountered should be treated as "fatal-local",
16         // meaning that a particular invocation of Encode() cannot progress, and
17         // an accurate number "n" of bytes written up that point should be
18         // returned.
19         Encode(to io.Writer) (n int, err error)
20
21         // Decode takes an io.Reader, "from" as well as a size "size" (the
22         // number of uncompressed bytes on the stream that represent the object
23         // trying to be decoded) and decodes the encoded object onto itself,
24         // as a mutative transaction.
25         //
26         // It returns the number of uncompressed bytes "n" that an invoication
27         // of this function has advanced the io.Reader, "from", as well as any
28         // error that was encountered along the way.
29         //
30         // If an(y) error was encountered, it should be returned immediately,
31         // along with the number of bytes read up to that point.
32         Decode(from io.Reader, size int64) (n int, err error)
33
34         // Type returns the ObjectType constant that represents an instance of
35         // the implementing type.
36         Type() ObjectType
37 }