default:
err = errors.New("unknown message type")
}
- data = buf.Bytes()
+ data = make([]byte, 4+buf.Len())
+ binary.BigEndian.PutUint32(data, uint32(buf.Len()))
+ if buf.Len() != copy(data[4:], buf.Bytes()) {
+ panic("bad copy")
+ }
return
}
return
}
-func encodeMessage(type_ MessageType, data interface{}) []byte {
- w := &bytes.Buffer{}
- w.WriteByte(byte(type_))
- err := binary.Write(w, binary.BigEndian, data)
- if err != nil {
- panic(err)
- }
- return w.Bytes()
-}
-
type Bytes []byte
func (b Bytes) MarshalBinary() ([]byte, error) {