MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / EncodeMetaBlock

Function EncodeMetaBlock

internal/utils/bfs/meta_block.go:17–31  ·  view source on GitHub ↗
(action MetaAction, hash string, data []byte)

Source from the content-addressed store, hash-verified

15)
16
17func EncodeMetaBlock(action MetaAction, hash string, data []byte) ([]byte, error) {
18 var hl = len(hash)
19 if hl != HashLen {
20 return nil, errors.New("invalid hash length")
21 }
22
23 var l = 1 /** Action **/ + hl /** Hash **/ + len(data)
24
25 var b = make([]byte, 4 /** Len **/ +l)
26 binary.BigEndian.PutUint32(b, uint32(l))
27 b[4] = action
28 copy(b[5:], hash)
29 copy(b[5+hl:], data)
30 return b, nil
31}
32
33func DecodeMetaBlock(blockBytes []byte) (action MetaAction, hash string, data []byte, err error) {
34 var dataOffset = 4 /** Len **/ + HashLen + 1 /** Action **/

Callers 3

TestMetaBlockFunction · 0.92
EncodeMethod · 0.85
RemoveFileMethod · 0.85

Calls

no outgoing calls

Tested by 1

TestMetaBlockFunction · 0.74