diff options
| author | 2026-02-20 22:22:56 +0800 | |
|---|---|---|
| committer | 2026-02-20 22:27:13 +0800 | |
| commit | 98e5a64ce72e81dcede7dbebc74e22576a1f5ab8 (patch) | |
| tree | 0354081e3949292c202f8b481b584436da3f7452 /object/tree_serialize.go | |
| parent | objectheader: Add loose-object header parsing and emitting code (diff) | |
| signature | No signature | |
object: Use objectheader
Diffstat (limited to 'object/tree_serialize.go')
| -rw-r--r-- | object/tree_serialize.go | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/object/tree_serialize.go b/object/tree_serialize.go index 79b1c79a..2ef0ebbb 100644 --- a/object/tree_serialize.go +++ b/object/tree_serialize.go @@ -3,10 +3,12 @@ package object import ( "strconv" + "codeberg.org/lindenii/furgit/internal/objectheader" "codeberg.org/lindenii/furgit/objecttype" ) -func (tree *Tree) serialize() []byte { +// SerializeWithoutHeader renders the raw tree body bytes. +func (tree *Tree) SerializeWithoutHeader() ([]byte, error) { var bodyLen int for _, entry := range tree.Entries { mode := strconv.FormatUint(uint64(entry.Mode), 8) @@ -27,16 +29,19 @@ func (tree *Tree) serialize() []byte { pos += copy(body[pos:], id) } - return body + return body, nil } -// Serialize renders the raw object (header + body). -func (tree *Tree) Serialize() ([]byte, error) { - body := tree.serialize() - header, err := headerForType(objecttype.TypeTree, body) +// SerializeWithHeader renders the raw object (header + body). +func (tree *Tree) SerializeWithHeader() ([]byte, error) { + body, err := tree.SerializeWithoutHeader() if err != nil { return nil, err } + header, ok := objectheader.Encode(objecttype.TypeTree, int64(len(body))) + if !ok { + return nil, ErrInvalidObject + } raw := make([]byte, len(header)+len(body)) copy(raw, header) copy(raw[len(header):], body) |
