nanopb.proto 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. // Custom options for defining:
  2. // - Maximum size of string/bytes
  3. // - Maximum number of elements in array
  4. //
  5. // These are used by nanopb to generate statically allocable structures
  6. // for memory-limited environments.
  7. syntax = "proto2";
  8. import "google/protobuf/descriptor.proto";
  9. option java_package = "fi.kapsi.koti.jpa.nanopb";
  10. enum FieldType {
  11. FT_DEFAULT = 0; // Automatically decide field type, generate static field if possible.
  12. FT_CALLBACK = 1; // Always generate a callback field.
  13. FT_POINTER = 4; // Always generate a dynamically allocated field.
  14. FT_STATIC = 2; // Generate a static field or raise an exception if not possible.
  15. FT_IGNORE = 3; // Ignore the field completely.
  16. FT_INLINE = 5; // Legacy option, use the separate 'fixed_length' option instead
  17. }
  18. enum IntSize {
  19. IS_DEFAULT = 0; // Default, 32/64bit based on type in .proto
  20. IS_8 = 8;
  21. IS_16 = 16;
  22. IS_32 = 32;
  23. IS_64 = 64;
  24. }
  25. enum TypenameMangling {
  26. M_NONE = 0; // Default, no typename mangling
  27. M_STRIP_PACKAGE = 1; // Strip current package name
  28. M_FLATTEN = 2; // Only use last path component
  29. M_PACKAGE_INITIALS = 3; // Replace the package name by the initials
  30. }
  31. enum DescriptorSize {
  32. DS_AUTO = 0; // Select minimal size based on field type
  33. DS_1 = 1; // 1 word; up to 15 byte fields, no arrays
  34. DS_2 = 2; // 2 words; up to 4095 byte fields, 4095 entry arrays
  35. DS_4 = 4; // 4 words; up to 2^32-1 byte fields, 2^16-1 entry arrays
  36. DS_8 = 8; // 8 words; up to 2^32-1 entry arrays
  37. }
  38. // This is the inner options message, which basically defines options for
  39. // a field. When it is used in message or file scope, it applies to all
  40. // fields.
  41. message NanoPBOptions {
  42. // Allocated size for 'bytes' and 'string' fields.
  43. // For string fields, this should include the space for null terminator.
  44. optional int32 max_size = 1;
  45. // Maximum length for 'string' fields. Setting this is equivalent
  46. // to setting max_size to a value of length+1.
  47. optional int32 max_length = 14;
  48. // Allocated number of entries in arrays ('repeated' fields)
  49. optional int32 max_count = 2;
  50. // Size of integer fields. Can save some memory if you don't need
  51. // full 32 bits for the value.
  52. optional IntSize int_size = 7 [default = IS_DEFAULT];
  53. // Force type of field (callback or static allocation)
  54. optional FieldType type = 3 [default = FT_DEFAULT];
  55. // Use long names for enums, i.e. EnumName_EnumValue.
  56. optional bool long_names = 4 [default = true];
  57. // Add 'packed' attribute to generated structs.
  58. // Note: this cannot be used on CPUs that break on unaligned
  59. // accesses to variables.
  60. optional bool packed_struct = 5 [default = false];
  61. // Add 'packed' attribute to generated enums.
  62. optional bool packed_enum = 10 [default = false];
  63. // Skip this message
  64. optional bool skip_message = 6 [default = false];
  65. // Generate oneof fields as normal optional fields instead of union.
  66. optional bool no_unions = 8 [default = false];
  67. // integer type tag for a message
  68. optional uint32 msgid = 9;
  69. // decode oneof as anonymous union
  70. optional bool anonymous_oneof = 11 [default = false];
  71. // Proto3 singular field does not generate a "has_" flag
  72. optional bool proto3 = 12 [default = false];
  73. // Force proto3 messages to have no "has_" flag.
  74. // This was default behavior until nanopb-0.4.0.
  75. optional bool proto3_singular_msgs = 21 [default = false];
  76. // Generate an enum->string mapping function (can take up lots of space).
  77. optional bool enum_to_string = 13 [default = false];
  78. // Generate bytes arrays with fixed length
  79. optional bool fixed_length = 15 [default = false];
  80. // Generate repeated field with fixed count
  81. optional bool fixed_count = 16 [default = false];
  82. // Generate message-level callback that is called before decoding submessages.
  83. // This can be used to set callback fields for submsgs inside oneofs.
  84. optional bool submsg_callback = 22 [default = false];
  85. // Shorten or remove package names from type names.
  86. // This option applies only on the file level.
  87. optional TypenameMangling mangle_names = 17 [default = M_NONE];
  88. // Data type for storage associated with callback fields.
  89. optional string callback_datatype = 18 [default = "pb_callback_t"];
  90. // Callback function used for encoding and decoding.
  91. // Prior to nanopb-0.4.0, the callback was specified in per-field pb_callback_t
  92. // structure. This is still supported, but does not work inside e.g. oneof or pointer
  93. // fields. Instead, a new method allows specifying a per-message callback that
  94. // will be called for all callback fields in a message type.
  95. optional string callback_function = 19 [default = "pb_default_field_callback"];
  96. // Select the size of field descriptors. This option has to be defined
  97. // for the whole message, not per-field. Usually automatic selection is
  98. // ok, but if it results in compilation errors you can increase the field
  99. // size here.
  100. optional DescriptorSize descriptorsize = 20 [default = DS_AUTO];
  101. // Set default value for has_ fields.
  102. optional bool default_has = 23 [default = false];
  103. // Extra files to include in generated `.pb.h`
  104. repeated string include = 24;
  105. // Automatic includes to exclude from generated `.pb.h`
  106. // Same as nanopb_generator.py command line flag -x.
  107. repeated string exclude = 26;
  108. // Package name that applies only for nanopb.
  109. optional string package = 25;
  110. // Override type of the field in generated C code. Only to be used with related field types
  111. optional google.protobuf.FieldDescriptorProto.Type type_override = 27;
  112. // Due to historical reasons, nanopb orders fields in structs by their tag number
  113. // instead of the order in .proto. Set this to false to keep the .proto order.
  114. // The default value will probably change to false in nanopb-0.5.0.
  115. optional bool sort_by_tag = 28 [default = true];
  116. }
  117. // Extensions to protoc 'Descriptor' type in order to define options
  118. // inside a .proto file.
  119. //
  120. // Protocol Buffers extension number registry
  121. // --------------------------------
  122. // Project: Nanopb
  123. // Contact: Petteri Aimonen <jpa@kapsi.fi>
  124. // Web site: http://kapsi.fi/~jpa/nanopb
  125. // Extensions: 1010 (all types)
  126. // --------------------------------
  127. extend google.protobuf.FileOptions {
  128. optional NanoPBOptions nanopb_fileopt = 1010;
  129. }
  130. extend google.protobuf.MessageOptions {
  131. optional NanoPBOptions nanopb_msgopt = 1010;
  132. }
  133. extend google.protobuf.EnumOptions {
  134. optional NanoPBOptions nanopb_enumopt = 1010;
  135. }
  136. extend google.protobuf.FieldOptions {
  137. optional NanoPBOptions nanopb = 1010;
  138. }