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

Function TestEncodeSInt64

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

Source from the content-addressed store, hash-verified

426}
427
428func TestEncodeSInt64(t *testing.T) {
429 cases := []struct {
430 name string
431 fieldNum int
432 v int64
433 expected []byte
434 }{
435 {
436 name: "zero",
437 fieldNum: 1,
438 v: 0,
439 expected: []byte{0x8, 0x0},
440 },
441 {
442 name: "max uint",
443 fieldNum: 2,
444 v: math.MaxInt64,
445 expected: []byte{0x10, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01},
446 },
447 {
448 name: "regular value",
449 fieldNum: 3,
450 v: 421138,
451 expected: []byte{0x18, 0xA4, 0xB4, 0x33},
452 },
453 {
454 name: "negative value",
455 fieldNum: 4,
456 v: -421138,
457 expected: []byte{0x20, 0xA3, 0xB4, 0x33},
458 },
459 {
460 name: "min uint",
461 fieldNum: 4,
462 v: math.MinInt64,
463 expected: []byte{0x20, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01},
464 },
465 }
466 for _, tc := range cases {
467 t.Run(tc.name, func(t *testing.T) {
468 dest := make([]byte, len(tc.expected))
469 csproto.NewEncoder(dest).EncodeSInt64(tc.fieldNum, tc.v)
470 assert.Equal(t, tc.expected, dest)
471 })
472 }
473}
474
475func TestEncodePackedSInt64(t *testing.T) {
476 dest := make([]byte, 19)

Callers

nothing calls this directly

Calls 2

NewEncoderFunction · 0.92
EncodeSInt64Method · 0.80

Tested by

no test coverage detected