Exemplo n.º 1
0
func assertRoundTrip(t *testing.T, expected message, actual message) {
	w := typed.NewWriteBufferWithSize(1024)
	require.Nil(t, expected.write(w), fmt.Sprintf("error writing message %v", expected.messageType()))

	var b bytes.Buffer
	w.FlushTo(&b)

	r := typed.NewReadBufferWithSize(1024)
	_, err := r.FillFrom(bytes.NewReader(b.Bytes()), len(b.Bytes()))
	require.Nil(t, err)
	require.Nil(t, actual.read(r), fmt.Sprintf("error reading message %v", expected.messageType()))

	assert.Equal(t, expected, actual, fmt.Sprintf("pre- and post-marshal %v do not match", expected.messageType()))
}
Exemplo n.º 2
0
func TestFraming(t *testing.T) {
	fh := FrameHeader{
		size:        uint16(0xFF34),
		messageType: messageTypeCallReq,
		ID:          0xDEADBEEF,
	}

	wbuf := typed.NewWriteBufferWithSize(1024)
	require.Nil(t, fh.write(wbuf))

	var b bytes.Buffer
	if _, err := wbuf.FlushTo(&b); err != nil {
		require.Nil(t, err)
	}

	rbuf := typed.NewReadBuffer(b.Bytes())

	var fh2 FrameHeader
	require.Nil(t, fh2.read(rbuf))

	assert.Equal(t, fh, fh2)
}