func (h *Header) Encode([] byte, error){
data:=make([]byte, 8)
data[0]=header.MajorVersion
data[1]=header.MinorVersion
binary.BigEndian.PutUint16(data[2:4], h.Length)
binary.BigEndian.PutUint32(data[4:8], h.ID)
return data, nil
}
func (h *Header) Decode(data [] byte) error{
if len(data)<8{
return fmt.Errorf(“can’t decode header: got %v bytes; need 8”, len(data))
}
h.MajorVersion = data[0]
h.MinorVersion = data[1]
h.Length = binary.BigEndian.Uint16(data[2:4])
h.ID = binary.BigEndian.Uint32(data[4:8])
return nil
}