• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * @fileoverview Test data for int64 encoding and decoding.
3 */
4goog.module('protobuf.binary.int64TestPairs');
5
6const BufferDecoder = goog.require('protobuf.binary.BufferDecoder');
7const Int64 = goog.require('protobuf.Int64');
8const {createBufferDecoder} = goog.require('protobuf.binary.bufferDecoderHelper');
9
10/**
11 * An array of Pairs of float values and their bit representation.
12 * This is used to test encoding and decoding from/to the protobuf wire format.
13 * @return {!Array<{name: string, longValue: !Int64, bufferDecoder:
14 *     !BufferDecoder, error: ?boolean, skip_writer: ?boolean}>}
15 */
16function getInt64Pairs() {
17  const int64Pairs = [
18    {
19      name: 'zero',
20      longValue: Int64.fromInt(0),
21      bufferDecoder: createBufferDecoder(0x00),
22    },
23    {
24      name: 'one ',
25      longValue: Int64.fromInt(1),
26      bufferDecoder: createBufferDecoder(0x01),
27    },
28    {
29      name: 'minus one',
30      longValue: Int64.fromInt(-1),
31      bufferDecoder: createBufferDecoder(
32          0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01),
33    },
34    {
35      name: 'max signed int 2^63 - 1',
36      longValue: Int64.fromBits(0xFFFFFFFF, 0x7FFFFFFF),
37      bufferDecoder: createBufferDecoder(
38          0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F),
39
40    },
41    {
42      name: 'value min signed int -2^63 (64 bit)',
43      longValue: Int64.fromBits(0xFFFFFFFF, 0xFFFFFFFF),
44      bufferDecoder: createBufferDecoder(
45          0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01),
46    },
47    {
48      name: 'errors out for 11 bytes',
49      longValue: Int64.fromInt(-1),
50      bufferDecoder: createBufferDecoder(
51          0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF),
52      error: true,
53      skip_writer: true,
54    },
55  ];
56  return [...int64Pairs];
57}
58
59exports = {getInt64Pairs};
60