2022-10-11 17:36:09 +08:00
|
|
|
package frame
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestPayloadFrameEncode(t *testing.T) {
|
2023-04-05 16:15:59 +08:00
|
|
|
f := &PayloadFrame{
|
|
|
|
Tag(0x13),
|
|
|
|
[]byte("yomo"),
|
|
|
|
}
|
|
|
|
f.SetCarriage([]byte("yomo"))
|
|
|
|
assert.Equal(t, []byte{0x80 | byte(TagOfPayloadFrame), 0x9, 0x1, 0x1, 0x13, 0x2, 0x04, 0x79, 0x6F, 0x6D, 0x6F}, f.Encode())
|
2022-10-11 17:36:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestPayloadFrameDecode(t *testing.T) {
|
2023-04-05 16:15:59 +08:00
|
|
|
buf := []byte{0x80 | byte(TagOfPayloadFrame), 0x9, 0x1, 0x1, 0x13, 0x2, 0x04, 0x79, 0x6F, 0x6D, 0x6F}
|
|
|
|
payload := new(PayloadFrame)
|
|
|
|
err := DecodeToPayloadFrame(buf, payload)
|
2022-10-11 17:36:09 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.EqualValues(t, 0x13, payload.Tag)
|
2023-04-05 16:15:59 +08:00
|
|
|
assert.Equal(t, []byte{0x79, 0x6F, 0x6D, 0x6F}, payload.Carriage)
|
2022-10-11 17:36:09 +08:00
|
|
|
}
|