int32_test_pairs.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /**
  2. * @fileoverview Test data for int32 encoding and decoding.
  3. */
  4. goog.module('protobuf.binary.int32TestPairs');
  5. const BufferDecoder = goog.require('protobuf.binary.BufferDecoder');
  6. const {createBufferDecoder} = goog.require('protobuf.binary.bufferDecoderHelper');
  7. /**
  8. * An array of Pairs of float values and their bit representation.
  9. * This is used to test encoding and decoding from/to the protobuf wire format.
  10. * @return {!Array<{name: string, intValue:number, bufferDecoder:
  11. * !BufferDecoder, error: ?boolean, skip_writer: ?boolean}>}
  12. */
  13. function getInt32Pairs() {
  14. const int32Pairs = [
  15. {
  16. name: 'zero',
  17. intValue: 0,
  18. bufferDecoder: createBufferDecoder(0x00),
  19. },
  20. {
  21. name: 'one ',
  22. intValue: 1,
  23. bufferDecoder: createBufferDecoder(0x01),
  24. },
  25. {
  26. name: 'minus one',
  27. intValue: -1,
  28. bufferDecoder: createBufferDecoder(0xFF, 0xFF, 0xFF, 0xFF, 0x0F),
  29. // The writer will encode this with 64 bits, see below
  30. skip_writer: true,
  31. },
  32. {
  33. name: 'minus one (64bits)',
  34. intValue: -1,
  35. bufferDecoder: createBufferDecoder(
  36. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01),
  37. },
  38. {
  39. name: 'max signed int 2^31 - 1',
  40. intValue: Math.pow(2, 31) - 1,
  41. bufferDecoder: createBufferDecoder(0xFF, 0xFF, 0xFF, 0xFF, 0x07),
  42. },
  43. {
  44. name: 'min signed int -2^31',
  45. intValue: -Math.pow(2, 31),
  46. bufferDecoder: createBufferDecoder(0x80, 0x80, 0x80, 0x80, 0x08),
  47. // The writer will encode this with 64 bits, see below
  48. skip_writer: true,
  49. },
  50. {
  51. name: 'value min signed int -2^31 (64 bit)',
  52. intValue: -Math.pow(2, 31),
  53. bufferDecoder: createBufferDecoder(
  54. 0x80, 0x80, 0x80, 0x80, 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0x01),
  55. },
  56. {
  57. name: 'errors out for 11 bytes',
  58. intValue: -1,
  59. bufferDecoder: createBufferDecoder(
  60. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF),
  61. error: true,
  62. skip_writer: true,
  63. },
  64. ];
  65. return [...int32Pairs];
  66. }
  67. exports = {getInt32Pairs};