network/frame/payload_frame_test.go

21 lines
602 B
Go
Raw Normal View History

2022-10-11 17:36:09 +08:00
package frame
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestPayloadFrameEncode(t *testing.T) {
f := NewPayloadFrame(0x13).SetCarriage([]byte("hpds"))
2022-10-12 10:16:59 +08:00
assert.Equal(t, []byte{0x80 | byte(TagOfPayloadFrame), 0x06, 0x13, 0x04, 0x68, 0x70, 0x64, 0x73}, f.Encode())
2022-10-11 17:36:09 +08:00
}
func TestPayloadFrameDecode(t *testing.T) {
2022-10-12 10:16:59 +08:00
buf := []byte{0x80 | byte(TagOfPayloadFrame), 0x06, 0x13, 0x04, 0x68, 0x70, 0x64, 0x73}
2022-10-11 17:36:09 +08:00
payload, err := DecodeToPayloadFrame(buf)
assert.NoError(t, err)
assert.EqualValues(t, 0x13, payload.Tag)
2022-10-12 10:16:59 +08:00
assert.Equal(t, []byte{0x68, 0x70, 0x64, 0x73}, payload.Carriage)
2022-10-11 17:36:09 +08:00
}