aboutsummaryrefslogtreecommitdiff
path: root/object/blob_serialize.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-02-20 22:22:56 +0800
committerGravatar Runxi Yu2026-02-20 22:27:13 +0800
commit98e5a64ce72e81dcede7dbebc74e22576a1f5ab8 (patch)
tree0354081e3949292c202f8b481b584436da3f7452 /object/blob_serialize.go
parentobjectheader: Add loose-object header parsing and emitting code (diff)
signatureNo signature
object: Use objectheader
Diffstat (limited to 'object/blob_serialize.go')
-rw-r--r--object/blob_serialize.go24
1 files changed, 18 insertions, 6 deletions
diff --git a/object/blob_serialize.go b/object/blob_serialize.go
index b06242a0..d14ae56c 100644
--- a/object/blob_serialize.go
+++ b/object/blob_serialize.go
@@ -1,15 +1,27 @@
package object
-import "codeberg.org/lindenii/furgit/objecttype"
+import (
+ "codeberg.org/lindenii/furgit/internal/objectheader"
+ "codeberg.org/lindenii/furgit/objecttype"
+)
-// Serialize renders the raw object (header + body).
-func (blob *Blob) Serialize() ([]byte, error) {
- header, err := headerForType(objecttype.TypeBlob, blob.Data)
+// SerializeWithoutHeader renders the raw blob body bytes.
+func (blob *Blob) SerializeWithoutHeader() ([]byte, error) {
+ return append([]byte(nil), blob.Data...), nil
+}
+
+// SerializeWithHeader renders the raw object (header + body).
+func (blob *Blob) SerializeWithHeader() ([]byte, error) {
+ body, err := blob.SerializeWithoutHeader()
if err != nil {
return nil, err
}
- raw := make([]byte, len(header)+len(blob.Data))
+ header, ok := objectheader.Encode(objecttype.TypeBlob, int64(len(body)))
+ if !ok {
+ return nil, ErrInvalidObject
+ }
+ raw := make([]byte, len(header)+len(body))
copy(raw, header)
- copy(raw[len(header):], blob.Data)
+ copy(raw[len(header):], body)
return raw, nil
}