21 lines
602 B
Go
21 lines
602 B
Go
package frame
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestPayloadFrameEncode(t *testing.T) {
|
|
f := NewPayloadFrame(0x13).SetCarriage([]byte("hpds"))
|
|
assert.Equal(t, []byte{0x80 | byte(TagOfPayloadFrame), 0x06, 0x13, 0x04, 0x68, 0x70, 0x64, 0x73}, f.Encode())
|
|
}
|
|
|
|
func TestPayloadFrameDecode(t *testing.T) {
|
|
buf := []byte{0x80 | byte(TagOfPayloadFrame), 0x06, 0x13, 0x04, 0x68, 0x70, 0x64, 0x73}
|
|
payload, err := DecodeToPayloadFrame(buf)
|
|
assert.NoError(t, err)
|
|
assert.EqualValues(t, 0x13, payload.Tag)
|
|
assert.Equal(t, []byte{0x68, 0x70, 0x64, 0x73}, payload.Carriage)
|
|
}
|