(t *testing.T)
| 159 | } |
| 160 | |
| 161 | func TestInputStreamSequential(t *testing.T) { |
| 162 | f := New(WithXlang(false), WithCompatible(false)) |
| 163 | // Register type in compatible mode to test Meta Sharing across sequential reads |
| 164 | f.config.Compatible = true |
| 165 | f.RegisterStruct(&StreamTestStruct{}, 100) |
| 166 | |
| 167 | msg1 := &StreamTestStruct{ID: 1, Name: "Msg 1", Data: []byte{1, 1}} |
| 168 | msg2 := &StreamTestStruct{ID: 2, Name: "Msg 2", Data: []byte{2, 2}} |
| 169 | msg3 := &StreamTestStruct{ID: 3, Name: "Msg 3", Data: []byte{3, 3}} |
| 170 | |
| 171 | var buf bytes.Buffer |
| 172 | |
| 173 | // Serialize sequentially into one stream |
| 174 | data1, _ := f.Serialize(msg1) |
| 175 | buf.Write(data1) |
| 176 | data2, _ := f.Serialize(msg2) |
| 177 | buf.Write(data2) |
| 178 | data3, _ := f.Serialize(msg3) |
| 179 | buf.Write(data3) |
| 180 | |
| 181 | fDec := New(WithXlang(false), WithCompatible(false)) |
| 182 | fDec.config.Compatible = true |
| 183 | fDec.RegisterStruct(&StreamTestStruct{}, 100) |
| 184 | |
| 185 | // Create a InputStream |
| 186 | sr := NewInputStream(&buf) |
| 187 | |
| 188 | // Deserialize sequentially |
| 189 | var out1, out2, out3 StreamTestStruct |
| 190 | |
| 191 | err := fDec.DeserializeFromStream(sr, &out1) |
| 192 | if err != nil { |
| 193 | t.Fatalf("Deserialize 1 failed: %v", err) |
| 194 | } |
| 195 | if out1.ID != msg1.ID || out1.Name != msg1.Name || !bytes.Equal(out1.Data, msg1.Data) { |
| 196 | t.Errorf("Msg 1 mismatch. Got: %+v, Want: %+v", out1, msg1) |
| 197 | } |
| 198 | |
| 199 | err = fDec.DeserializeFromStream(sr, &out2) |
| 200 | if err != nil { |
| 201 | t.Fatalf("Deserialize 2 failed: %v", err) |
| 202 | } |
| 203 | if out2.ID != msg2.ID || out2.Name != msg2.Name || !bytes.Equal(out2.Data, msg2.Data) { |
| 204 | t.Errorf("Msg 2 mismatch. Got: %+v, Want: %+v", out2, msg2) |
| 205 | } |
| 206 | |
| 207 | err = fDec.DeserializeFromStream(sr, &out3) |
| 208 | if err != nil { |
| 209 | t.Fatalf("Deserialize 3 failed: %v", err) |
| 210 | } |
| 211 | if out3.ID != msg3.ID || out3.Name != msg3.Name || !bytes.Equal(out3.Data, msg3.Data) { |
| 212 | t.Errorf("Msg 3 mismatch. Got: %+v, Want: %+v", out3, msg3) |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | func TestInputStreamShrink(t *testing.T) { |
| 217 | // Create a large payload that easily escapes the bufferSize (4096) |
nothing calls this directly
no test coverage detected