sint32_test_pairs.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * @fileoverview Test data for int32 encoding and decoding.
  3. */
  4. goog.module('protobuf.binary.sint32TestPairs');
  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 getSint32Pairs() {
  14. const sint32Pairs = [
  15. {
  16. name: 'zero',
  17. intValue: 0,
  18. bufferDecoder: createBufferDecoder(0x00),
  19. },
  20. {
  21. name: 'one ',
  22. intValue: 1,
  23. bufferDecoder: createBufferDecoder(0x02),
  24. },
  25. {
  26. name: 'minus one',
  27. intValue: -1,
  28. bufferDecoder: createBufferDecoder(0x01),
  29. },
  30. {
  31. name: 'two',
  32. intValue: 2,
  33. bufferDecoder: createBufferDecoder(0x04),
  34. },
  35. {
  36. name: 'minus two',
  37. intValue: -2,
  38. bufferDecoder: createBufferDecoder(0x03),
  39. },
  40. {
  41. name: 'int 2^31 - 1',
  42. intValue: Math.pow(2, 31) - 1,
  43. bufferDecoder: createBufferDecoder(0xFE, 0xFF, 0xFF, 0xFF, 0x0F),
  44. },
  45. {
  46. name: '-2^31',
  47. intValue: -Math.pow(2, 31),
  48. bufferDecoder: createBufferDecoder(0xFF, 0xFF, 0xFF, 0xFF, 0x0F),
  49. },
  50. ];
  51. return [...sint32Pairs];
  52. }
  53. exports = {getSint32Pairs};