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) }
func TestSerializeHeader(t *testing.T) { var msg std_msgs.Header msg.Seq = 0x89ABCDEF msg.Stamp = ros.NewTime(0x89ABCDEF, 0x01234567) msg.FrameID = "frame_id" var buf bytes.Buffer err := msg.Serialize(&buf) if err != nil { t.Error(err) } result := buf.Bytes() expected := []byte{ // Header.Seq 0xEF, 0xCD, 0xAB, 0x89, // Header.Stamp 0xEF, 0xCD, 0xAB, 0x89, 0x67, 0x45, 0x23, 0x01, // Header.FrameId 0x08, 0x00, 0x00, 0x00, 0x66, 0x72, 0x61, 0x6D, 0x65, 0x5F, 0x69, 0x64, } CheckBytes(t, expected, result) }