Add proto3 option to handle singular fields
[apps/agl-service-can-low-level.git] / generator / proto / nanopb.proto
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
8 syntax = "proto2";
9 import "google/protobuf/descriptor.proto";
10
11 option java_package = "fi.kapsi.koti.jpa.nanopb";
12
13 enum 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; // Always generate an inline array of fixed size.
20 }
21
22 enum 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
30 // This is the inner options message, which basically defines options for
31 // a field. When it is used in message or file scope, it applies to all
32 // fields.
33 message NanoPBOptions {
34   // Allocated size for 'bytes' and 'string' fields.
35   optional int32 max_size = 1;
36   
37   // Allocated number of entries in arrays ('repeated' fields)
38   optional int32 max_count = 2;
39   
40   // Size of integer fields. Can save some memory if you don't need
41   // full 32 bits for the value.
42   optional IntSize int_size = 7 [default = IS_DEFAULT];
43
44   // Force type of field (callback or static allocation)
45   optional FieldType type = 3 [default = FT_DEFAULT];
46   
47   // Use long names for enums, i.e. EnumName_EnumValue.
48   optional bool long_names = 4 [default = true];
49   
50   // Add 'packed' attribute to generated structs.
51   // Note: this cannot be used on CPUs that break on unaligned
52   // accesses to variables.
53   optional bool packed_struct = 5 [default = false];
54   
55   // Add 'packed' attribute to generated enums.
56   optional bool packed_enum = 10 [default = false];
57   
58   // Skip this message
59   optional bool skip_message = 6 [default = false];
60
61   // Generate oneof fields as normal optional fields instead of union.
62   optional bool no_unions = 8 [default = false];
63
64   // integer type tag for a message
65   optional uint32 msgid = 9;
66
67   // decode oneof as anonymous union
68   optional bool anonymous_oneof = 11 [default = false];
69
70   // Proto3 singular field does not generate a "has_" flag
71   optional bool proto3 = 12 [default = false];
72 }
73
74 // Extensions to protoc 'Descriptor' type in order to define options
75 // inside a .proto file.
76 //
77 // Protocol Buffers extension number registry
78 // --------------------------------
79 // Project:  Nanopb
80 // Contact:  Petteri Aimonen <jpa@kapsi.fi>
81 // Web site: http://kapsi.fi/~jpa/nanopb
82 // Extensions: 1010 (all types)
83 // --------------------------------
84
85 extend google.protobuf.FileOptions {
86     optional NanoPBOptions nanopb_fileopt = 1010;
87 }
88
89 extend google.protobuf.MessageOptions {
90     optional NanoPBOptions nanopb_msgopt = 1010;
91 }
92
93 extend google.protobuf.EnumOptions {
94     optional NanoPBOptions nanopb_enumopt = 1010;
95 }
96
97 extend google.protobuf.FieldOptions {
98     optional NanoPBOptions nanopb = 1010;
99 }
100
101