@@ -2,7 +2,6 @@ package y3
22
33import (
44 "bytes"
5- "log"
65 "testing"
76
87 "github.com/yomorun/y3-codec-golang/pkg/spec"
@@ -105,30 +104,37 @@ func TestStreamDecode4(t *testing.T) {
105104}
106105
107106func TestStreamDecode5 (t * testing.T ) {
108- data := []byte {0x01 , 0x01 , 0x01 , 0x02 , 0x02 , 0x01 , 0x02 , 0x03 , 0x03 , 0x01 , 0x02 , 0x03 }
107+ data := []byte {0x01 , 0x01 , 0x01 , 0x02 , 0x02 , 0x01 , 0x02 , 0x03 , 0x00 , 0x04 , 0x03 , 0x01 , 0x02 , 0x03 }
109108
110109 // as reader
111110 r := bytes .NewReader (data )
112111 // create steam decoder
113112 pr := NewStreamDecoder (r )
114113
115- times := 0
114+ times := 1
116115
117116 // handler
118117 pr .OnPacket (func (p * spec.Packet ) {
119- log .Printf ("==>OnPacket: %v" , p )
120- if times == 0 {
118+ if times == 1 {
121119 compareBytes (t , p .GetTagBuffer (), []byte {0x01 }, "T" )
122120 compareBytes (t , p .GetLengthBuffer (), []byte {0x01 }, "L" )
123121 compareBytes (t , p .GetValueBuffer (), []byte {0x01 }, "V" )
124122 }
125- if times == 1 {
123+ if times == 2 {
126124 compareBytes (t , p .GetTagBuffer (), []byte {0x02 }, "T" )
127125 compareBytes (t , p .GetLengthBuffer (), []byte {0x02 }, "L" )
128126 compareBytes (t , p .GetValueBuffer (), []byte {0x01 , 0x02 }, "V" )
129127 }
130- if times == 2 {
128+ if times == 3 {
131129 compareBytes (t , p .GetTagBuffer (), []byte {0x03 }, "T" )
130+ compareBytes (t , p .GetLengthBuffer (), []byte {0x00 }, "L" )
131+ compareBytes (t , p .GetValueBuffer (), []byte {}, "V" )
132+ if p .Length != 0 {
133+ t .Errorf ("Packet:Tag=[% X] Length should be 0, actual=%d" , p .GetTagBuffer (), p .Length )
134+ }
135+ }
136+ if times == 4 {
137+ compareBytes (t , p .GetTagBuffer (), []byte {0x04 }, "T" )
132138 compareBytes (t , p .GetLengthBuffer (), []byte {0x03 }, "L" )
133139 compareBytes (t , p .GetValueBuffer (), []byte {0x01 , 0x02 , 0x03 }, "V" )
134140 }
0 commit comments