@@ -2,7 +2,6 @@ package y3
2
2
3
3
import (
4
4
"bytes"
5
- "log"
6
5
"testing"
7
6
8
7
"github.com/yomorun/y3-codec-golang/pkg/spec"
@@ -105,30 +104,37 @@ func TestStreamDecode4(t *testing.T) {
105
104
}
106
105
107
106
func 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 }
109
108
110
109
// as reader
111
110
r := bytes .NewReader (data )
112
111
// create steam decoder
113
112
pr := NewStreamDecoder (r )
114
113
115
- times := 0
114
+ times := 1
116
115
117
116
// handler
118
117
pr .OnPacket (func (p * spec.Packet ) {
119
- log .Printf ("==>OnPacket: %v" , p )
120
- if times == 0 {
118
+ if times == 1 {
121
119
compareBytes (t , p .GetTagBuffer (), []byte {0x01 }, "T" )
122
120
compareBytes (t , p .GetLengthBuffer (), []byte {0x01 }, "L" )
123
121
compareBytes (t , p .GetValueBuffer (), []byte {0x01 }, "V" )
124
122
}
125
- if times == 1 {
123
+ if times == 2 {
126
124
compareBytes (t , p .GetTagBuffer (), []byte {0x02 }, "T" )
127
125
compareBytes (t , p .GetLengthBuffer (), []byte {0x02 }, "L" )
128
126
compareBytes (t , p .GetValueBuffer (), []byte {0x01 , 0x02 }, "V" )
129
127
}
130
- if times == 2 {
128
+ if times == 3 {
131
129
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" )
132
138
compareBytes (t , p .GetLengthBuffer (), []byte {0x03 }, "L" )
133
139
compareBytes (t , p .GetValueBuffer (), []byte {0x01 , 0x02 , 0x03 }, "V" )
134
140
}
0 commit comments