• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/* Test handling of enums with different value ranges.
2 * Depending on compiler and the packed_enum setting, the datatypes
3 * for enums can be either signed or unsigned. In past this has caused
4 * a bit of a problem for the encoder/decoder (issue #164).
5 */
6
7syntax = "proto2";
8
9import 'nanopb.proto';
10
11option (nanopb_fileopt).long_names = false;
12
13enum UnpackedUint8 {
14    option (nanopb_enumopt).packed_enum = false;
15    UU8_MIN = 0;
16    UU8_MAX = 255;
17}
18
19enum PackedUint8 {
20    option (nanopb_enumopt).packed_enum = true;
21    PU8_MIN = 0;
22    PU8_MAX = 255;
23}
24
25enum UnpackedInt8 {
26    option (nanopb_enumopt).packed_enum = false;
27    UI8_MIN = -128;
28    UI8_MAX = 127;
29}
30
31enum PackedInt8 {
32    option (nanopb_enumopt).packed_enum = true;
33    PI8_MIN = -128;
34    PI8_MAX = 127;
35}
36
37enum UnpackedUint16 {
38    option (nanopb_enumopt).packed_enum = false;
39    UU16_MIN = 0;
40    UU16_MAX = 65535;
41}
42
43enum PackedUint16 {
44    option (nanopb_enumopt).packed_enum = true;
45    PU16_MIN = 0;
46    PU16_MAX = 65535;
47}
48
49enum UnpackedInt16 {
50    option (nanopb_enumopt).packed_enum = false;
51    UI16_MIN = -32768;
52    UI16_MAX = 32767;
53}
54
55enum PackedInt16 {
56    option (nanopb_enumopt).packed_enum = true;
57    PI16_MIN = -32768;
58    PI16_MAX = 32767;
59}
60
61/* Protobuf supports enums up to 32 bits.
62 * The 32 bit case is covered by HugeEnum in the alltypes test.
63 */
64
65message PackedEnums {
66    required PackedUint8  u8_min  = 1;
67    required PackedUint8  u8_max  = 2;
68    required PackedInt8   i8_min  = 3;
69    required PackedInt8   i8_max  = 4;
70    required PackedUint16 u16_min = 5;
71    required PackedUint16 u16_max = 6;
72    required PackedInt16  i16_min = 7;
73    required PackedInt16  i16_max = 8;
74}
75
76message UnpackedEnums {
77    required UnpackedUint8  u8_min  = 1;
78    required UnpackedUint8  u8_max  = 2;
79    required UnpackedInt8   i8_min  = 3;
80    required UnpackedInt8   i8_max  = 4;
81    required UnpackedUint16 u16_min = 5;
82    required UnpackedUint16 u16_max = 6;
83    required UnpackedInt16  i16_min = 7;
84    required UnpackedInt16  i16_max = 8;
85}
86
87