@@ -318,6 +318,26 @@ func TestPacket_ToData(t *testing.T) {
318318 B : []byte {0x7E , 0x0A , 0x41 , 0x00 , 0x02 , 0x00 , 0x00 , 0x0F , 0x0A , 0x0D , 0x31 , 0x36 , 0x36 , 0x30 , 0x33 , 0x36 , 0x30 , 0x39 , 0x31 , 0x35 , 0x35 , 0x35 , 0x36 },
319319 },
320320 },
321+ {
322+ name : "to data2" ,
323+ fields : fields {
324+ HeaderByte : []byte {},
325+ Data : []byte {0x0A , 0x0D , 0x31 , 0x36 , 0x36 , 0x30 , 0x33 , 0x36 , 0x30 , 0x39 , 0x31 , 0x35 , 0x35 , 0x35 , 0x36 },
326+ },
327+ want : & bytebuffer.ByteBuffer {
328+ B : []byte {0x0A , 0x0D , 0x31 , 0x36 , 0x36 , 0x30 , 0x33 , 0x36 , 0x30 , 0x39 , 0x31 , 0x35 , 0x35 , 0x35 , 0x36 },
329+ },
330+ },
331+ {
332+ name : "to data2" ,
333+ fields : fields {
334+ HeaderByte : []byte {0x20 },
335+ Data : []byte {0x0A , 0x0D , 0x31 , 0x36 , 0x36 , 0x30 , 0x33 , 0x36 , 0x30 , 0x39 , 0x31 , 0x35 , 0x35 , 0x35 , 0x36 },
336+ },
337+ want : & bytebuffer.ByteBuffer {
338+ B : []byte {0x0A , 0x0D , 0x31 , 0x36 , 0x36 , 0x30 , 0x33 , 0x36 , 0x30 , 0x39 , 0x31 , 0x35 , 0x35 , 0x35 , 0x36 },
339+ },
340+ },
321341 }
322342 for _ , tt := range tests {
323343 t .Run (tt .name , func (t * testing.T ) {
@@ -329,6 +349,9 @@ func TestPacket_ToData(t *testing.T) {
329349 if got := p .ToData (); ! reflect .DeepEqual (got , tt .want ) {
330350 t .Errorf ("Packet.ToData() = %v, want %v" , got , tt .want )
331351 }
352+ if ! reflect .DeepEqual (p .ToData ().B , p .ToByte ()) {
353+ t .Errorf ("Packet.ToData() = %v, want %v" , p .ToByte (), p .ToData ().B )
354+ }
332355 })
333356 }
334357}
0 commit comments