MCPcopy Create free account
hub / github.com/apache/fory / TestStreamDeserialization

Function TestStreamDeserialization

go/fory/stream_test.go:32–58  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

30}
31
32func TestStreamDeserialization(t *testing.T) {
33 f := New(WithXlang(false), WithCompatible(false))
34 f.RegisterStruct(&StreamTestStruct{}, 100)
35
36 original := &StreamTestStruct{
37 ID: 42,
38 Name: "Stream Test",
39 Data: []byte{1, 2, 3, 4, 5},
40 }
41
42 data, err := f.Serialize(original)
43 if err != nil {
44 t.Fatalf("Serialize failed: %v", err)
45 }
46
47 // 1. Test normal reader
48 reader := bytes.NewReader(data)
49 var decoded StreamTestStruct
50 err = f.DeserializeFromReader(reader, &decoded)
51 if err != nil {
52 t.Fatalf("DeserializeFromReader failed: %v", err)
53 }
54
55 if decoded.ID != original.ID || decoded.Name != original.Name || !bytes.Equal(decoded.Data, original.Data) {
56 t.Errorf("Decoded value mismatch. Got: %+v, Want: %+v", decoded, original)
57 }
58}
59
60// slowReader returns data byte by byte to test fill() logic and compaction
61type slowReader struct {

Callers

nothing calls this directly

Calls 7

WithXlangFunction · 0.85
WithCompatibleFunction · 0.85
NewFunction · 0.70
RegisterStructMethod · 0.45
SerializeMethod · 0.45
DeserializeFromReaderMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected