refactor: make encode fixed method to take a [32]byte, and change Encode to take a byte array that just copies and calls EncodeFixed

This commit is contained in:
Derrick Hammer 2023-05-09 12:48:48 -04:00
parent b21a425e24
commit 6ceefc11cf
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 8 additions and 1 deletions

View File

@ -14,7 +14,14 @@ type CID struct {
Size uint64
}
func Encode(hash [32]byte, size uint64) (string, error) {
func Encode(hash []byte, size uint64) (string, error) {
var hashBytes [32]byte
copy(hashBytes[:], hash)
return EncodeFixed(hashBytes, size)
}
func EncodeFixed(hash [32]byte, size uint64) (string, error) {
sizeBytes := make([]byte, 8)
binary.LittleEndian.PutUint64(sizeBytes, size)