MCPcopy
hub / github.com/openacid/slim / TestSlimTrie_MarshalUnmarshal

Function TestSlimTrie_MarshalUnmarshal

trie/slimtrie_marshal_test.go:84–151  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

82}
83
84func TestSlimTrie_MarshalUnmarshal(t *testing.T) {
85
86 ta := require.New(t)
87
88 keys := []string{
89 "abc",
90 "abcd",
91 "abd",
92 "abde",
93 "bc",
94 "bcd",
95 "bcde",
96 "cde",
97 }
98 values := []int{0, 1, 2, 3, 4, 5, 6, 7}
99
100 st1, err := NewSlimTrie(encode.Int{}, keys, values)
101 ta.NoError(err)
102
103 // marshal
104
105 marshalSize := proto.Size(st1)
106
107 buf, err := st1.Marshal()
108 ta.NoError(err)
109 ta.Equal(len(buf), marshalSize)
110
111 // marshal twice
112
113 buf1, err := proto.Marshal(st1)
114 ta.NoError(err)
115 ta.Equal(buf, buf1)
116
117 // check version
118 r := bytes.NewBuffer(buf)
119 n, h, err := pbcmpl.ReadHeader(r)
120 ta.NoError(err)
121 ta.Equal(int64(32), n)
122 ta.Equal(slimtrieVersion, h.GetVersion())
123
124 // unmarshal
125
126 st2, _ := NewSlimTrie(encode.Int{}, nil, nil)
127 err = proto.Unmarshal(buf, st2)
128 ta.NoError(err)
129 slimtrieEqual(st1, st2, t)
130
131 // proto.Unmarshal twice
132
133 err = proto.Unmarshal(buf, st2)
134 ta.NoError(err)
135 slimtrieEqual(st1, st2, t)
136
137 // Reset()
138
139 st2.Reset()
140 empty := &SlimTrie{
141 encoder: encode.Int{},

Callers

nothing calls this directly

Calls 7

MarshalMethod · 0.95
ResetMethod · 0.95
StringMethod · 0.95
NewSlimTrieFunction · 0.85
slimtrieEqualFunction · 0.85
UnmarshalMethod · 0.80
GetVersionMethod · 0.45

Tested by

no test coverage detected