MCPcopy
hub / github.com/segmentio/kafka-go / TestVarInts

Function TestVarInts

protocol/protocol_test.go:153–282  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

151}
152
153func TestVarInts(t *testing.T) {
154 type tc struct {
155 input int64
156 expVarInt []byte
157 expUVarInt []byte
158 }
159
160 tcs := []tc{
161 {
162 input: 12,
163 expVarInt: []byte{24},
164 expUVarInt: []byte{12},
165 },
166 {
167 input: 63,
168 expVarInt: []byte{126},
169 expUVarInt: []byte{63},
170 },
171 {
172 input: -64,
173 expVarInt: []byte{127},
174 expUVarInt: []byte{192, 255, 255, 255, 255, 255, 255, 255, 255, 1},
175 },
176 {
177 input: 64,
178 expVarInt: []byte{128, 1},
179 expUVarInt: []byte{64},
180 },
181 {
182 input: 127,
183 expVarInt: []byte{254, 1},
184 expUVarInt: []byte{127},
185 },
186 {
187 input: 128,
188 expVarInt: []byte{128, 2},
189 expUVarInt: []byte{128, 1},
190 },
191 {
192 input: 129,
193 expVarInt: []byte{130, 2},
194 expUVarInt: []byte{129, 1},
195 },
196 {
197 input: 12345,
198 expVarInt: []byte{242, 192, 1},
199 expUVarInt: []byte{185, 96},
200 },
201 {
202 input: 123456789101112,
203 expVarInt: []byte{240, 232, 249, 224, 144, 146, 56},
204 expUVarInt: []byte{184, 244, 188, 176, 136, 137, 28},
205 },
206 }
207
208 for _, tc := range tcs {
209 b := &bytes.Buffer{}
210 e := &encoder{writer: b}

Callers

nothing calls this directly

Calls 8

writeVarIntMethod · 0.95
readVarIntMethod · 0.95
writeUnsignedVarIntMethod · 0.95
readUnsignedVarIntMethod · 0.95
sizeOfVarIntFunction · 0.85
sizeOfUnsignedVarIntFunction · 0.85
BytesMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected