options.proto 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /* Test nanopb option parsing.
  2. * options.expected lists the patterns that are searched for in the output.
  3. */
  4. syntax = "proto2";
  5. import "nanopb.proto";
  6. // File level options
  7. option (nanopb_fileopt).max_size = 20;
  8. message Message1
  9. {
  10. required string filesize = 1;
  11. }
  12. // Message level options
  13. message Message2
  14. {
  15. option (nanopb_msgopt).max_size = 30;
  16. required string msgsize = 1;
  17. }
  18. // Field level options
  19. message Message3
  20. {
  21. option (nanopb_msgopt).msgid = 103;
  22. required string fieldsize = 1 [(nanopb).max_size = 40];
  23. required string fieldlen = 2 [(nanopb).max_length = 40];
  24. }
  25. // Forced callback field
  26. message Message4
  27. {
  28. option (nanopb_msgopt).msgid = 104;
  29. required int32 int32_callback = 1 [(nanopb).type = FT_CALLBACK];
  30. }
  31. // Short enum names
  32. enum Enum1
  33. {
  34. option (nanopb_enumopt).long_names = false;
  35. EnumValue1 = 1;
  36. EnumValue2 = 2;
  37. }
  38. message EnumTest
  39. {
  40. required Enum1 field = 1 [default = EnumValue2];
  41. }
  42. // Short enum names inside message
  43. message Message5
  44. {
  45. option (nanopb_msgopt).msgid = 105;
  46. enum Enum2
  47. {
  48. option (nanopb_enumopt).long_names = false;
  49. EnumValue1 = 1;
  50. }
  51. required Enum2 field = 1 [default = EnumValue1];
  52. }
  53. // Packed structure
  54. message my_packed_struct
  55. {
  56. option (nanopb_msgopt).packed_struct = true;
  57. optional int32 myfield = 1;
  58. }
  59. // Message with ignored field
  60. message Message6
  61. {
  62. required int32 field1 = 1;
  63. optional int32 skipped_field = 2 [(nanopb).type = FT_IGNORE];
  64. }
  65. // Message that is skipped
  66. message SkippedMessage
  67. {
  68. option (nanopb_msgopt).skip_message = true;
  69. required int32 foo = 1;
  70. }
  71. // Message with oneof field
  72. message OneofMessage
  73. {
  74. oneof foo {
  75. int32 bar = 1;
  76. }
  77. }
  78. // Proto3-style optional field in proto2 file
  79. message Proto3Field
  80. {
  81. optional int32 proto3field = 1 [(nanopb).proto3 = true];
  82. }
  83. // Wide descriptors
  84. message WideMessage
  85. {
  86. option (nanopb_msgopt).descriptorsize = DS_4;
  87. required int32 foo = 1;
  88. }
  89. // Wide descriptor option in a single field
  90. message WideMessage2
  91. {
  92. required int32 foo = 1 [(nanopb).descriptorsize = DS_8];
  93. required int32 foo2 = 2 [(nanopb).descriptorsize = DS_4];
  94. required int32 foo3 = 3;
  95. }
  96. // Default value for has_ field
  97. message HasFieldMessage
  98. {
  99. optional int32 present = 1 [(nanopb).default_has = true];
  100. optional int32 missing = 2 [(nanopb).default_has = false];
  101. optional int32 normal = 3;
  102. }
  103. // Overridden type in generated C code
  104. message TypeOverrideMessage
  105. {
  106. required Enum1 normal = 1;
  107. required Enum1 overridden = 2 [(nanopb).type_override = TYPE_UINT32];
  108. }