xref: /aosp_15_r20/external/nanopb-c/generator/proto/nanopb.proto (revision c8d645cafcee3f91213d30caa0fe303887010b9b)
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}
35
36// This is the inner options message, which basically defines options for
37// a field. When it is used in message or file scope, it applies to all
38// fields.
39message NanoPBOptions {
40  // Allocated size for 'bytes' and 'string' fields.
41  // For string fields, this should include the space for null terminator.
42  optional int32 max_size = 1;
43
44  // Maximum length for 'string' fields. Setting this is equivalent
45  // to setting max_size to a value of length+1.
46  optional int32 max_length = 14;
47
48  // Allocated number of entries in arrays ('repeated' fields)
49  optional int32 max_count = 2;
50
51  // Size of integer fields. Can save some memory if you don't need
52  // full 32 bits for the value.
53  optional IntSize int_size = 7 [default = IS_DEFAULT];
54
55  // Force type of field (callback or static allocation)
56  optional FieldType type = 3 [default = FT_DEFAULT];
57
58  // Use long names for enums, i.e. EnumName_EnumValue.
59  optional bool long_names = 4 [default = true];
60
61  // Add 'packed' attribute to generated structs.
62  // Note: this cannot be used on CPUs that break on unaligned
63  // accesses to variables.
64  optional bool packed_struct = 5 [default = false];
65
66  // Add 'packed' attribute to generated enums.
67  optional bool packed_enum = 10 [default = false];
68
69  // Skip this message
70  optional bool skip_message = 6 [default = false];
71
72  // Generate oneof fields as normal optional fields instead of union.
73  optional bool no_unions = 8 [default = false];
74
75  // integer type tag for a message
76  optional uint32 msgid = 9;
77
78  // decode oneof as anonymous union
79  optional bool anonymous_oneof = 11 [default = false];
80
81  // Proto3 singular field does not generate a "has_" flag
82  optional bool proto3 = 12 [default = false];
83
84  // Generate an enum->string mapping function (can take up lots of space).
85  optional bool enum_to_string = 13 [default = false];
86
87  // Generate bytes arrays with fixed length
88  optional bool fixed_length = 15 [default = false];
89
90  // Generate repeated field with fixed count
91  optional bool fixed_count = 16 [default = false];
92
93  // Mangle long names
94  optional TypenameMangling mangle_names = 17 [default = M_NONE];
95}
96
97// Extensions to protoc 'Descriptor' type in order to define options
98// inside a .proto file.
99//
100// Protocol Buffers extension number registry
101// --------------------------------
102// Project:  Nanopb
103// Contact:  Petteri Aimonen <[email protected]>
104// Web site: http://kapsi.fi/~jpa/nanopb
105// Extensions: 1010 (all types)
106// --------------------------------
107
108extend google.protobuf.FileOptions {
109    optional NanoPBOptions nanopb_fileopt = 1010;
110}
111
112extend google.protobuf.MessageOptions {
113    optional NanoPBOptions nanopb_msgopt = 1010;
114}
115
116extend google.protobuf.EnumOptions {
117    optional NanoPBOptions nanopb_enumopt = 1010;
118}
119
120extend google.protobuf.FieldOptions {
121    optional NanoPBOptions nanopb = 1010;
122}
123
124
125