(action MetaAction, hash string, data []byte)
| 15 | ) |
| 16 | |
| 17 | func 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 | |
| 33 | func DecodeMetaBlock(blockBytes []byte) (action MetaAction, hash string, data []byte, err error) { |
| 34 | var dataOffset = 4 /** Len **/ + HashLen + 1 /** Action **/ |
no outgoing calls