func ReadMessage(r io.Reader, msg proto.Message) (uint64, error) {
	var header [msgHeaderSize]byte
	_, err := io.ReadFull(r, header[:])
	if err != nil {
		return 0, errors.Trace(err)
	}

	if magic := binary.BigEndian.Uint16(header[0:2]); magic != msgMagic {
		return 0, errors.Errorf("mismatch header magic %x != %x", magic, msgMagic)
	}

	// skip version now.

	msgLen := binary.BigEndian.Uint32(header[4:8])
	msgID := binary.BigEndian.Uint64(header[8:])

	body := make([]byte, msgLen)
	_, err = io.ReadFull(r, body)
	if err != nil {
		return 0, errors.Trace(err)
	}

	err = proto.Unmarshal(body, msg)
	if err != nil {
		return 0, errors.Trace(err)
	}

	return msgID, nil
}
// ReadMessage reads a protocol buffer message from reader.
ReadMessage reads a protocol buffer message from reader.
// ReadMessage reads a protocol buffer message from reader .
func ReadMessage(r io.Reader, msg proto.Message) (uint64, error) {
	var header [msgHeaderSize]byte
	_, err := io.ReadFull(r, header[:])
	if err != nil {
		return 0, errors.Trace(err)
	}
	if magic := binary.BigEndian.Uint16(header[0:2]); magic != msgMagic {
		return 0, errors.Errorf("mismatch header magic %x != %x", magic, msgMagic)
	}
	msgLen := binary.BigEndian.Uint32(header[4:8])
	msgID := binary.BigEndian.Uint64(header[8:])
	body := make([]byte, msgLen)
	_, err = io.ReadFull(r, body)
	if err != nil {
		return 0, errors.Trace(err)
	}
	err = proto.Unmarshal(body, msg)
	if err != nil {
		return 0, errors.Trace(err)
	}
	return msgID, nil
}
func ReadMessage ( r io . Reader , msg proto . Message ) ( uint64 , error ) { var header [ msgHeaderSize ] byte _ , err := io . ReadFull ( r , header [ : ] ) if err != nil { return 0 , errors . Trace ( err ) } if magic := binary . BigEndian . Uint16 ( header [ 0 : 2 ] ) ; magic != msgMagic { return 0 , errors . Errorf ( " " , magic , msgMagic ) } msgLen := binary . BigEndian . Uint32 ( header [ 4 : 8 ] ) msgID := binary . BigEndian . Uint64 ( header [ 8 : ] ) body := make ( [ ] byte , msgLen ) _ , err = io . ReadFull ( r , body ) if err != nil { return 0 , errors . Trace ( err ) } err = proto . Unmarshal ( body , msg ) if err != nil { return 0 , errors . Trace ( err ) } return msgID , nil }
ReadMessage reads a protocol buffer message from reader.
ReadMessage reads a protocol buffer message from reader .
// skip version now.