sfixed32_test_pairs.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /**
  2. * @fileoverview Test data for sfixed32 encoding and decoding.
  3. */
  4. goog.module('protobuf.binary.sfixed32TestPairs');
  5. const BufferDecoder = goog.require('protobuf.binary.BufferDecoder');
  6. const {createBufferDecoder} = goog.require('protobuf.binary.bufferDecoderHelper');
  7. /**
  8. * An array of Pairs of int 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}>}
  12. */
  13. function getSfixed32Pairs() {
  14. const sfixed32Pairs = [
  15. {
  16. name: 'zero',
  17. intValue: 0,
  18. bufferDecoder: createBufferDecoder(0x00, 0x00, 0x00, 0x00),
  19. },
  20. {
  21. name: 'one',
  22. intValue: 1,
  23. bufferDecoder: createBufferDecoder(0x01, 0x00, 0x00, 0x00)
  24. },
  25. {
  26. name: 'minus one',
  27. intValue: -1,
  28. bufferDecoder: createBufferDecoder(0xFF, 0xFF, 0xFF, 0xFF),
  29. },
  30. {
  31. name: 'max int 2^31 -1',
  32. intValue: Math.pow(2, 31) - 1,
  33. bufferDecoder: createBufferDecoder(0xFF, 0xFF, 0xFF, 0x7F)
  34. },
  35. {
  36. name: 'min int -2^31',
  37. intValue: -Math.pow(2, 31),
  38. bufferDecoder: createBufferDecoder(0x00, 0x00, 0x00, 0x80)
  39. },
  40. ];
  41. return [...sfixed32Pairs];
  42. }
  43. exports = {getSfixed32Pairs};