1// This file contains definitions of custom options used to control the
2// code generator in nanopb protocol buffers library.
4// Most commonly used options are max_count and max_size, which allow
5// the generator to allocate static arrays for repeated and string fields.
7// There are three ways to use these options:
8// 1. Use a separate <protofile>.options file
9// 2. Use command line switches to nanopb_generator.py
10// 3. Use [(nanopb).option = value] in your <protofile>.proto file
12// For detailed documentation, refer to "Generator options" in docs/reference.md
15import "google/protobuf/descriptor.proto";
17option java_package = "fi.kapsi.koti.jpa.nanopb";
20 FT_DEFAULT = 0; // Automatically decide field type, generate static field if possible.
21 FT_CALLBACK = 1; // Always generate a callback field.
22 FT_POINTER = 4; // Always generate a dynamically allocated field.
23 FT_STATIC = 2; // Generate a static field or raise an exception if not possible.
24 FT_IGNORE = 3; // Ignore the field completely.
25 FT_INLINE = 5; // Legacy option, use the separate 'fixed_length' option instead
29 IS_DEFAULT = 0; // Default, 32/64bit based on type in .proto
36enum TypenameMangling {
37 M_NONE = 0; // Default, no typename mangling
38 M_STRIP_PACKAGE = 1; // Strip current package name
39 M_FLATTEN = 2; // Only use last path component
40 M_PACKAGE_INITIALS = 3; // Replace the package name by the initials
44 DS_AUTO = 0; // Select minimal size based on field type
45 DS_1 = 1; // 1 word; up to 15 byte fields, no arrays
46 DS_2 = 2; // 2 words; up to 4095 byte fields, 4095 entry arrays
47 DS_4 = 4; // 4 words; up to 2^32-1 byte fields, 2^16-1 entry arrays
48 DS_8 = 8; // 8 words; up to 2^32-1 entry arrays
51// This is the inner options message, which basically defines options for
52// a field. When it is used in message or file scope, it applies to all
54message NanoPBOptions {
55 // Allocated size for 'bytes' and 'string' fields.
56 // For string fields, this should include the space for null terminator.
57 optional int32 max_size = 1;
59 // Maximum length for 'string' fields. Setting this is equivalent
60 // to setting max_size to a value of length+1.
61 optional int32 max_length = 14;
63 // Allocated number of entries in arrays ('repeated' fields)
64 optional int32 max_count = 2;
66 // Size of integer fields. Can save some memory if you don't need
67 // full 32 bits for the value.
68 optional IntSize int_size = 7 [default = IS_DEFAULT];
70 // Size for enum fields. Supported by C++11 and C23 standards.
71 optional IntSize enum_intsize = 34 [default = IS_DEFAULT];
73 // Force type of field (callback or static allocation)
74 optional FieldType type = 3 [default = FT_DEFAULT];
76 // Use long names for enums, i.e. EnumName_EnumValue.
77 optional bool long_names = 4 [default = true];
79 // Add 'packed' attribute to generated structs.
80 // Note: this cannot be used on CPUs that break on unaligned
81 // accesses to variables.
82 optional bool packed_struct = 5 [default = false];
84 // Add 'packed' attribute to generated enums.
85 optional bool packed_enum = 10 [default = false];
88 optional bool skip_message = 6 [default = false];
90 // Generate oneof fields as normal optional fields instead of union.
91 optional bool no_unions = 8 [default = false];
93 // integer type tag for a message
94 optional uint32 msgid = 9;
96 // decode oneof as anonymous union
97 optional bool anonymous_oneof = 11 [default = false];
99 // Proto3 singular field does not generate a "has_" flag
100 optional bool proto3 = 12 [default = false];
102 // Force proto3 messages to have no "has_" flag.
103 // This was default behavior until nanopb-0.4.0.
104 optional bool proto3_singular_msgs = 21 [default = false];
106 // Generate an enum->string mapping function (can take up lots of space).
107 optional bool enum_to_string = 13 [default = false];
109 // Generate validation methods for enums
110 optional bool enum_validate = 32 [default = false];
112 // Generate bytes arrays with fixed length
113 optional bool fixed_length = 15 [default = false];
115 // Generate repeated field with fixed count
116 optional bool fixed_count = 16 [default = false];
118 // Generate message-level callback that is called before decoding submessages.
119 // This can be used to set callback fields for submsgs inside oneofs.
120 optional bool submsg_callback = 22 [default = false];
122 // Shorten or remove package names from type names.
123 // This option applies only on the file level.
124 optional TypenameMangling mangle_names = 17 [default = M_NONE];
126 // Data type for storage associated with callback fields.
127 optional string callback_datatype = 18 [default = "pb_callback_t"];
129 // Callback function used for encoding and decoding.
130 // Prior to nanopb-0.4.0, the callback was specified in per-field pb_callback_t
131 // structure. This is still supported, but does not work inside e.g. oneof or pointer
132 // fields. Instead, a new method allows specifying a per-message callback that
133 // will be called for all callback fields in a message type.
134 optional string callback_function = 19 [default = "pb_default_field_callback"];
136 // Select the size of field descriptors. This option has to be defined
137 // for the whole message, not per-field. Usually automatic selection is
138 // ok, but if it results in compilation errors you can increase the field
140 optional DescriptorSize descriptorsize = 20 [default = DS_AUTO];
142 // Set default value for has_ fields.
143 optional bool default_has = 23 [default = false];
145 // Extra files to include in generated `.pb.h`
146 repeated string include = 24;
148 // Automatic includes to exclude from generated `.pb.h`
149 // Same as nanopb_generator.py command line flag -x.
150 repeated string exclude = 26;
152 // Package name that applies only for nanopb.
153 optional string package = 25;
155 // Override type of the field in generated C code. Only to be used with related field types
156 optional google.protobuf.FieldDescriptorProto.Type type_override = 27;
158 // Override of the label of the field (see FieldDescriptorProto.Label). Can be used to create
159 // fields which nanopb considers required in proto3, or whether nanopb treats the field as
160 // optional/required/repeated.
161 optional google.protobuf.FieldDescriptorProto.Label label_override = 31;
163 // Due to historical reasons, nanopb orders fields in structs by their tag number
164 // instead of the order in .proto. Set this to false to keep the .proto order.
165 // The default value will probably change to false in nanopb-0.5.0.
166 optional bool sort_by_tag = 28 [default = true];
168 // Set the FT_DEFAULT field conversion strategy.
169 // A field that can become a static member of a c struct (e.g. int, bool, etc)
170 // will be a a static field.
171 // Fields with dynamic length are converted to either a pointer or a callback.
172 optional FieldType fallback_type = 29 [default = FT_CALLBACK];
174 // Override initializer used in generated MyMessage_init_zero and MyMessage_init_default macros
175 // By default decided automatically based on field default value and datatype.
176 optional string initializer = 30;
178 // Discard unused types that are automatically generated by protoc if they are not actually
179 // needed. Currently this applies to map< > types when the field is ignored by options.
180 optional bool discard_unused_automatic_types = 33 [default = true];
182 // Discard messages and fields marked with [deprecated = true] in the proto file.
183 optional bool discard_deprecated = 35 [default = false];
186// Extensions to protoc 'Descriptor' type in order to define options
187// inside a .proto file.
189// Protocol Buffers extension number registry
190// --------------------------------
192// Contact: Petteri Aimonen <jpa@kapsi.fi>
193// Web site: http://kapsi.fi/~jpa/nanopb
194// Extensions: 1010 (all types)
195// --------------------------------
197extend google.protobuf.FileOptions {
198 optional NanoPBOptions nanopb_fileopt = 1010;
201extend google.protobuf.MessageOptions {
202 optional NanoPBOptions nanopb_msgopt = 1010;
205extend google.protobuf.EnumOptions {
206 optional NanoPBOptions nanopb_enumopt = 1010;
209extend google.protobuf.FieldOptions {
210 optional NanoPBOptions nanopb = 1010;