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

Function TestEncodeSInt32

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

Source from the content-addressed store, hash-verified

357}
358
359func TestEncodeSInt32(t *testing.T) {
360 cases := []struct {
361 name string
362 fieldNum int
363 v int32
364 expected []byte
365 }{
366 {
367 name: "zero",
368 fieldNum: 1,
369 v: 0,
370 expected: []byte{0x8, 0x0},
371 },
372 {
373 name: "max uint",
374 fieldNum: 2,
375 v: math.MaxInt32,
376 expected: []byte{0x10, 0xFE, 0xFF, 0xFF, 0xFF, 0x0F},
377 },
378 {
379 name: "regular value",
380 fieldNum: 3,
381 v: 42,
382 expected: []byte{0x18, 0x54},
383 },
384 {
385 name: "negative value",
386 fieldNum: 4,
387 v: -42,
388 expected: []byte{0x20, 0x53},
389 },
390 {
391 name: "min uint",
392 fieldNum: 5,
393 v: math.MinInt32,
394 expected: []byte{0x28, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F},
395 },
396 }
397 for _, tc := range cases {
398 t.Run(tc.name, func(t *testing.T) {
399 dest := make([]byte, len(tc.expected))
400 csproto.NewEncoder(dest).EncodeSInt32(tc.fieldNum, tc.v)
401 assert.Equal(t, tc.expected, dest)
402 })
403 }
404}
405
406func TestEncodePackedSInt32(t *testing.T) {
407 dest := make([]byte, 10)

Callers

nothing calls this directly

Calls 2

NewEncoderFunction · 0.92
EncodeSInt32Method · 0.80

Tested by

no test coverage detected