Example #1
0
func TestSerialize(t *testing.T) {
	var msg example_msgs.AllFieldTypes

	msg.H.Seq = 0x89ABCDEF
	msg.H.Stamp = ros.NewTime(0x89ABCDEF, 0x01234567)
	msg.H.FrameID = "frame_id"
	msg.B = 0x01
	msg.I8 = 0x01
	msg.I16 = 0x0123
	msg.I32 = 0x01234567
	msg.I64 = 0x0123456789ABCDEF
	msg.U8 = 0x01
	msg.U16 = 0x0123
	msg.U32 = 0x01234567
	msg.U64 = 0x0123456789ABCDEF
	msg.F32 = 3.141592653589793238462643383
	msg.F64 = 3.1415926535897932384626433832795028842
	msg.T = ros.NewTime(0x89ABCDEF, 0x01234567)
	msg.D = ros.NewDuration(0x89ABCDEF, 0x01234567)
	msg.S = "Hello, world!"
	msg.C = std_msgs.ColorRGBA{R: 1.0, G: 0.5, B: 0.25, A: 0.125}

	msg.DynAry = append(msg.DynAry, 0x01234567)
	msg.DynAry = append(msg.DynAry, 0x89ABCDEF)
	msg.FixAry[0] = 0x01234567
	msg.FixAry[1] = 0x89ABCDEF

	var buf bytes.Buffer
	err := msg.Serialize(&buf)
	if err != nil {
		t.Error(err)
	}

	result := buf.Bytes()
	expected := getTestData()
	CheckBytes(t, expected, result)
}