mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-24 09:30:36 +00:00
f000b76879
* [FIX] Formatting and code-style - gofmt - import resort - prealloc slices - simplify code * fix vet
41 lines
818 B
Go
41 lines
818 B
Go
package core
|
|
|
|
import (
|
|
"encoding/binary"
|
|
"fmt"
|
|
"io"
|
|
)
|
|
|
|
// Header holds the head info of a block.
|
|
type Header struct {
|
|
// Base of the block.
|
|
BlockBase
|
|
// Padding that is fixed to 0
|
|
_ uint8
|
|
}
|
|
|
|
// DecodeBinary impelements the Payload interface.
|
|
func (h *Header) DecodeBinary(r io.Reader) error {
|
|
if err := h.BlockBase.DecodeBinary(r); err != nil {
|
|
return err
|
|
}
|
|
|
|
var padding uint8
|
|
if err := binary.Read(r, binary.LittleEndian, &padding); err != nil {
|
|
return err
|
|
}
|
|
|
|
if padding != 0 {
|
|
return fmt.Errorf("format error: padding must equal 0 got %d", padding)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// EncodeBinary impelements the Payload interface.
|
|
func (h *Header) EncodeBinary(w io.Writer) error {
|
|
if err := h.BlockBase.EncodeBinary(w); err != nil {
|
|
return err
|
|
}
|
|
return binary.Write(w, binary.LittleEndian, uint8(0))
|
|
}
|