From 94bfb1fa147f80e6ec39009d41fc2f853925e0a5 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Sun, 16 Nov 2025 00:00:00 +0000 Subject: hash: Generic hash-algorithm API --- obj_blob.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'obj_blob.go') diff --git a/obj_blob.go b/obj_blob.go index 9edad0a9..1f74464e 100644 --- a/obj_blob.go +++ b/obj_blob.go @@ -1,27 +1,26 @@ package furgit // Blob represents the contents of a Git blob. -type Blob struct { - Hash Hash - +type Blob[T HashType] struct { + Hash Hash[T] Data []byte } // ObjType allows Blob to satisfy the Object interface. -func (*Blob) ObjType() ObjType { +func (*Blob[T]) ObjType() ObjType { return ObjBlob } -func parseBlob(id Hash, body []byte) (*Blob, error) { +func parseBlob[T HashType](id Hash[T], body []byte) (*Blob[T], error) { data := append([]byte(nil), body...) - return &Blob{ + return &Blob[T]{ Hash: id, Data: data, }, nil } // Serialize renders the full "blob size\\0body" representation. -func (b *Blob) Serialize(hashSize int) ([]byte, error) { +func (b *Blob[T]) Serialize() ([]byte, error) { header, err := headerForType(ObjBlob, b.Data) if err != nil { return nil, err -- cgit v1.3.1-10-gc9f91