Beispiel #1
0
func (h *StreamReader) ReadMessage() (proto.Message, error) {
	// The returned buffer is only valid until the next call to ReadLine.
	// ReadLine either returns a non-nil line or it returns an error, never both.
	line, isPrefix, err := h.bufrd.ReadLine()
	if (err == nil || err == bufio.ErrBufferFull) && isPrefix {
		err = ErrMsgTooBig
	}
	if err == nil {
		err = checkSeparator(h.bufrd)
	}
	if err != nil {
		return "", err
	}

	message := make([]byte, len(line))
	copy(message, line)
	return proto.Message(message), nil
}
Beispiel #2
0
func TestReadMessage_AtomicRead(t *testing.T) {
	data := "o|123456"
	h := streamReader([]Chunk{{Data(data + "\n"), nil}})
	testReadMessage(h, proto.Message(data), nil, t)
}