func Decode(r io.Reader) (Message, error) {
	var (
		size uint32
		mt   MessageType
		err  error
	)
	if size, mt, err = DecodeHdr(r); err != nil {
		return nil, err
	}

	// This LimitedReader is not a necessity, but used as an error checker.
	limiter := &io.LimitedReader{R: r, N: int64(size) - HeaderSize}

	m, err := MessageTypeToMessage(mt)
	if err != nil {
		return nil, err
	}
	if err = m.Decode(limiter); err != nil {
		return nil, err
	}
	return m, nil
}
// Decode decodes an entire message, including header, and returns the message.
// It may return an error if reading from the Reader fails, or if a message
// tries to consume more data than the size of the header indicated, making the
// message invalid.
Decode decodes an entire message, including header, and returns the message.
It may return an error if reading from the Reader fails, or if a message
tries to consume more data than the size of the header indicated, making the
message invalid.
// Decode decodes an entire message including header and returns the message . // It may return an error if reading from the Reader fails or if a message // tries to consume more data than the size of the header indicated making the // message invalid .
func Decode(r io.Reader) (Message, error) {
	var (
		size uint32
		mt   MessageType
		err  error
	)
	if size, mt, err = DecodeHdr(r); err != nil {
		return nil, err
	}
	limiter := &io.LimitedReader{R: r, N: int64(size) - HeaderSize}
	m, err := MessageTypeToMessage(mt)
	if err != nil {
		return nil, err
	}
	if err = m.Decode(limiter); err != nil {
		return nil, err
	}
	return m, nil
}
func Decode ( r io . Reader ) ( Message , error ) { var ( size uint32 mt MessageType err error ) if size , mt , err = DecodeHdr ( r ) ; err != nil { return nil , err } limiter := & io . LimitedReader { R : r , N : int64 ( size ) - HeaderSize } m , err := MessageTypeToMessage ( mt ) if err != nil { return nil , err } if err = m . Decode ( limiter ) ; err != nil { return nil , err } return m , nil }
Decode decodes an entire message, including header, and returns the message.
Decode decodes an entire message including header and returns the message .
// This LimitedReader is not a necessity, but used as an error checker.