MCPcopy Create free account
hub / github.com/CrowdStrike/csproto / TestEncodeInt64

Function TestEncodeInt64

encoder_test.go:182–227  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

180}
181
182func TestEncodeInt64(t *testing.T) {
183 cases := []struct {
184 name string
185 fieldNum int
186 v int64
187 expected []byte
188 }{
189 {
190 name: "zero",
191 fieldNum: 1,
192 v: 0,
193 expected: []byte{0x8, 0x0},
194 },
195 {
196 name: "max int",
197 fieldNum: 2,
198 v: math.MaxInt64,
199 expected: []byte{0x10, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F},
200 },
201 {
202 name: "min int",
203 fieldNum: 2,
204 v: math.MinInt64,
205 expected: []byte{0x10, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x1},
206 },
207 {
208 name: "regular value",
209 fieldNum: 3,
210 v: 421138,
211 expected: []byte{0x18, 0x92, 0xDA, 0x19},
212 },
213 {
214 name: "negative value",
215 fieldNum: 3,
216 v: -421138,
217 expected: []byte{0x18, 0xee, 0xa5, 0xe6, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1},
218 },
219 }
220 for _, tc := range cases {
221 t.Run(tc.name, func(t *testing.T) {
222 dest := make([]byte, len(tc.expected))
223 csproto.NewEncoder(dest).EncodeInt64(tc.fieldNum, tc.v)
224 assert.Equal(t, tc.expected, dest)
225 })
226 }
227}
228
229func TestEncodePackedInt64(t *testing.T) {
230 dest := make([]byte, 15)

Callers

nothing calls this directly

Calls 2

NewEncoderFunction · 0.92
EncodeInt64Method · 0.80

Tested by

no test coverage detected