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