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 8syntax = "proto2"; 9import "google/protobuf/descriptor.proto"; 10 11option java_package = "fi.kapsi.koti.jpa.nanopb"; 12 13enum FieldType { 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 20} 21 22enum IntSize { 23 IS_DEFAULT = 0; // Default, 32/64bit based on type in .proto 24 IS_8 = 8; 25 IS_16 = 16; 26 IS_32 = 32; 27 IS_64 = 64; 28} 29 30enum 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 35} 36 37enum DescriptorSize { 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 43} 44 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 47// fields. 48message 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; 52 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; 56 57 // Allocated number of entries in arrays ('repeated' fields) 58 optional int32 max_count = 2; 59 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]; 63 64 // Force type of field (callback or static allocation) 65 optional FieldType type = 3 [default = FT_DEFAULT]; 66 67 // Use long names for enums, i.e. EnumName_EnumValue. 68 optional bool long_names = 4 [default = true]; 69 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]; 74 75 // Add 'packed' attribute to generated enums. 76 optional bool packed_enum = 10 [default = false]; 77 78 // Skip this message 79 optional bool skip_message = 6 [default = false]; 80 81 // Generate oneof fields as normal optional fields instead of union. 82 optional bool no_unions = 8 [default = false]; 83 84 // integer type tag for a message 85 optional uint32 msgid = 9; 86 87 // decode oneof as anonymous union 88 optional bool anonymous_oneof = 11 [default = false]; 89 90 // Proto3 singular field does not generate a "has_" flag 91 optional bool proto3 = 12 [default = false]; 92 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]; 96 97 // Generate an enum->string mapping function (can take up lots of space). 98 optional bool enum_to_string = 13 [default = false]; 99 100 // Generate bytes arrays with fixed length 101 optional bool fixed_length = 15 [default = false]; 102 103 // Generate repeated field with fixed count 104 optional bool fixed_count = 16 [default = false]; 105 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]; 109 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]; 113 114 // Data type for storage associated with callback fields. 115 optional string callback_datatype = 18 [default = "pb_callback_t"]; 116 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"]; 123 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 127 // size here. 128 optional DescriptorSize descriptorsize = 20 [default = DS_AUTO]; 129 130 // Set default value for has_ fields. 131 optional bool default_has = 23 [default = false]; 132 133 // Extra files to include in generated `.pb.h` 134 repeated string include = 24; 135 136 // Automatic includes to exlude from generated `.pb.h` 137 // Same as nanopb_generator.py command line flag -x. 138 repeated string exclude = 26; 139 140 // Package name that applies only for nanopb. 141 optional string package = 25; 142 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; 145 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]; 150} 151 152// Extensions to protoc 'Descriptor' type in order to define options 153// inside a .proto file. 154// 155// Protocol Buffers extension number registry 156// -------------------------------- 157// Project: Nanopb 158// Contact: Petteri Aimonen <jpa@kapsi.fi> 159// Web site: http://kapsi.fi/~jpa/nanopb 160// Extensions: 1010 (all types) 161// -------------------------------- 162 163extend google.protobuf.FileOptions { 164 optional NanoPBOptions nanopb_fileopt = 1010; 165} 166 167extend google.protobuf.MessageOptions { 168 optional NanoPBOptions nanopb_msgopt = 1010; 169} 170 171extend google.protobuf.EnumOptions { 172 optional NanoPBOptions nanopb_enumopt = 1010; 173} 174 175extend google.protobuf.FieldOptions { 176 optional NanoPBOptions nanopb = 1010; 177} 178 179 180