MCPcopy Create free account
hub / github.com/ByteStorage/FlyDB / decodeHashField

Function decodeHashField

structure/hash.go:1459–1495  ·  view source on GitHub ↗

decodeHashField decodes the HashField from a byte buffer.

(data []byte)

Source from the content-addressed store, hash-verified

1457
1458// decodeHashField decodes the HashField from a byte buffer.
1459func decodeHashField(data []byte) (*HashField, error) {
1460 hf := &HashField{}
1461
1462 // Create a buffer to hold the data
1463 buf := bytes.NewBuffer(data)
1464
1465 var keyLen int32
1466 if err := binary.Read(buf, binary.BigEndian, &keyLen); err != nil {
1467 return nil, err
1468 }
1469
1470 hf.key = make([]byte, keyLen)
1471 if _, err := buf.Read(hf.key); err != nil {
1472 return nil, err
1473 }
1474
1475 var fieldLen int32
1476 if err := binary.Read(buf, binary.BigEndian, &fieldLen); err != nil {
1477 return nil, err
1478 }
1479
1480 hf.field = make([]byte, fieldLen)
1481 if _, err := buf.Read(hf.field); err != nil {
1482 return nil, err
1483 }
1484
1485 if err := binary.Read(buf, binary.BigEndian, &hf.version); err != nil {
1486 return nil, err
1487 }
1488
1489 return &HashField{
1490 key: hf.key,
1491 field: hf.field,
1492 version: hf.version,
1493 }, nil
1494
1495}
1496
1497// EncodeHashMeta encodes a HashMetadata and returns the byte array and length.
1498// +-------------+------------+------------+------------+---------+----------+----------+---------+---------+

Callers 1

GetFieldsMethod · 0.85

Calls 1

ReadMethod · 0.65

Tested by

no test coverage detected