• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * @fileoverview Test data for int32 encoding and decoding.
3 */
4goog.module('protobuf.binary.uint32TestPairs');
5
6const BufferDecoder = goog.require('protobuf.binary.BufferDecoder');
7const {createBufferDecoder} = goog.require('protobuf.binary.bufferDecoderHelper');
8
9/**
10 * An array of Pairs of float values and their bit representation.
11 * This is used to test encoding and decoding from/to the protobuf wire format.
12 * @return {!Array<{name: string, intValue:number, bufferDecoder:
13 *     !BufferDecoder, error: (boolean|undefined),
14 *    skip_reader: (boolean|undefined), skip_writer: (boolean|undefined)}>}
15 */
16function getUint32Pairs() {
17  const uint32Pairs = [
18    {
19      name: 'zero',
20      intValue: 0,
21      bufferDecoder: createBufferDecoder(0x00),
22    },
23    {
24      name: 'one ',
25      intValue: 1,
26      bufferDecoder: createBufferDecoder(0x01),
27    },
28    {
29      name: 'max signed int 2^31 - 1',
30      intValue: Math.pow(2, 31) - 1,
31      bufferDecoder: createBufferDecoder(0xFF, 0xFF, 0xFF, 0xFF, 0x07),
32    },
33    {
34      name: 'max unsigned int 2^32 - 1',
35      intValue: Math.pow(2, 32) - 1,
36      bufferDecoder: createBufferDecoder(0xFF, 0xFF, 0xFF, 0xFF, 0x0F),
37    },
38    {
39      name: 'negative one',
40      intValue: -1,
41      bufferDecoder: createBufferDecoder(0xFF, 0xFF, 0xFF, 0xFF, 0x0F),
42      skip_reader: true,
43    },
44    {
45      name: 'truncates more than 32 bits',
46      intValue: Math.pow(2, 32) - 1,
47      bufferDecoder: createBufferDecoder(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01),
48      skip_writer: true,
49    },
50    {
51      name: 'truncates more than 32 bits (bit 33 set)',
52      intValue: Math.pow(2, 28) - 1,
53      bufferDecoder: createBufferDecoder(0xFF, 0xFF, 0xFF, 0xFF, 0x10),
54      skip_writer: true,
55    },
56    {
57      name: 'errors out for 11 bytes',
58      intValue: Math.pow(2, 32) - 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 [...uint32Pairs];
66}
67
68exports = {getUint32Pairs};
69