Skip to content

Commit 0a072d2

Browse files
committed
Generating protobufs in the repo
1 parent 8b946cc commit 0a072d2

File tree

4 files changed

+6899
-1
lines changed

4 files changed

+6899
-1
lines changed

build.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ use walkdir::WalkDir;
33
fn main() -> std::io::Result<()> {
44
let protobufs_dir = "src/protobufs/";
55
println!("cargo:rerun-if-changed={}", protobufs_dir);
6+
let out_dir = "src/generated-protobufs/";
7+
68

79
// Allows protobuf compilation without installing the `protoc` binary
810
match protoc_bin_vendored::protoc_bin_path() {
@@ -58,6 +60,8 @@ fn main() -> std::io::Result<()> {
5860
config.type_attribute(".", "#[allow(clippy::doc_lazy_continuation)]");
5961
}
6062

63+
config.out_dir(out_dir);
64+
6165
config.compile_protos(&protos, &[protobufs_dir]).unwrap();
6266

6367
Ok(())

src/generated-protobufs/_.rs

Lines changed: 290 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,290 @@
1+
/// This is the inner options message, which basically defines options for
2+
/// a field. When it is used in message or file scope, it applies to all
3+
/// fields.
4+
#[derive(serde::Serialize, serde::Deserialize)]
5+
#[serde(rename_all = "camelCase")]
6+
#[allow(clippy::doc_lazy_continuation)]
7+
#[allow(clippy::derive_partial_eq_without_eq)]
8+
#[derive(Clone, PartialEq, ::prost::Message)]
9+
pub struct NanoPbOptions {
10+
/// Allocated size for 'bytes' and 'string' fields.
11+
/// For string fields, this should include the space for null terminator.
12+
#[prost(int32, optional, tag = "1")]
13+
pub max_size: ::core::option::Option<i32>,
14+
/// Maximum length for 'string' fields. Setting this is equivalent
15+
/// to setting max_size to a value of length+1.
16+
#[prost(int32, optional, tag = "14")]
17+
pub max_length: ::core::option::Option<i32>,
18+
/// Allocated number of entries in arrays ('repeated' fields)
19+
#[prost(int32, optional, tag = "2")]
20+
pub max_count: ::core::option::Option<i32>,
21+
/// Size of integer fields. Can save some memory if you don't need
22+
/// full 32 bits for the value.
23+
#[prost(enumeration = "IntSize", optional, tag = "7", default = "IsDefault")]
24+
pub int_size: ::core::option::Option<i32>,
25+
/// Force type of field (callback or static allocation)
26+
#[prost(enumeration = "FieldType", optional, tag = "3", default = "FtDefault")]
27+
pub r#type: ::core::option::Option<i32>,
28+
/// Use long names for enums, i.e. EnumName_EnumValue.
29+
#[prost(bool, optional, tag = "4", default = "true")]
30+
pub long_names: ::core::option::Option<bool>,
31+
/// Add 'packed' attribute to generated structs.
32+
/// Note: this cannot be used on CPUs that break on unaligned
33+
/// accesses to variables.
34+
#[prost(bool, optional, tag = "5", default = "false")]
35+
pub packed_struct: ::core::option::Option<bool>,
36+
/// Add 'packed' attribute to generated enums.
37+
#[prost(bool, optional, tag = "10", default = "false")]
38+
pub packed_enum: ::core::option::Option<bool>,
39+
/// Skip this message
40+
#[prost(bool, optional, tag = "6", default = "false")]
41+
pub skip_message: ::core::option::Option<bool>,
42+
/// Generate oneof fields as normal optional fields instead of union.
43+
#[prost(bool, optional, tag = "8", default = "false")]
44+
pub no_unions: ::core::option::Option<bool>,
45+
/// integer type tag for a message
46+
#[prost(uint32, optional, tag = "9")]
47+
pub msgid: ::core::option::Option<u32>,
48+
/// decode oneof as anonymous union
49+
#[prost(bool, optional, tag = "11", default = "false")]
50+
pub anonymous_oneof: ::core::option::Option<bool>,
51+
/// Proto3 singular field does not generate a "has_" flag
52+
#[prost(bool, optional, tag = "12", default = "false")]
53+
pub proto3: ::core::option::Option<bool>,
54+
/// Force proto3 messages to have no "has_" flag.
55+
/// This was default behavior until nanopb-0.4.0.
56+
#[prost(bool, optional, tag = "21", default = "false")]
57+
pub proto3_singular_msgs: ::core::option::Option<bool>,
58+
/// Generate an enum->string mapping function (can take up lots of space).
59+
#[prost(bool, optional, tag = "13", default = "false")]
60+
pub enum_to_string: ::core::option::Option<bool>,
61+
/// Generate bytes arrays with fixed length
62+
#[prost(bool, optional, tag = "15", default = "false")]
63+
pub fixed_length: ::core::option::Option<bool>,
64+
/// Generate repeated field with fixed count
65+
#[prost(bool, optional, tag = "16", default = "false")]
66+
pub fixed_count: ::core::option::Option<bool>,
67+
/// Generate message-level callback that is called before decoding submessages.
68+
/// This can be used to set callback fields for submsgs inside oneofs.
69+
#[prost(bool, optional, tag = "22", default = "false")]
70+
pub submsg_callback: ::core::option::Option<bool>,
71+
/// Shorten or remove package names from type names.
72+
/// This option applies only on the file level.
73+
#[prost(enumeration = "TypenameMangling", optional, tag = "17", default = "MNone")]
74+
pub mangle_names: ::core::option::Option<i32>,
75+
/// Data type for storage associated with callback fields.
76+
#[prost(string, optional, tag = "18", default = "pb_callback_t")]
77+
pub callback_datatype: ::core::option::Option<::prost::alloc::string::String>,
78+
/// Callback function used for encoding and decoding.
79+
/// Prior to nanopb-0.4.0, the callback was specified in per-field pb_callback_t
80+
/// structure. This is still supported, but does not work inside e.g. oneof or pointer
81+
/// fields. Instead, a new method allows specifying a per-message callback that
82+
/// will be called for all callback fields in a message type.
83+
#[prost(string, optional, tag = "19", default = "pb_default_field_callback")]
84+
pub callback_function: ::core::option::Option<::prost::alloc::string::String>,
85+
/// Select the size of field descriptors. This option has to be defined
86+
/// for the whole message, not per-field. Usually automatic selection is
87+
/// ok, but if it results in compilation errors you can increase the field
88+
/// size here.
89+
#[prost(enumeration = "DescriptorSize", optional, tag = "20", default = "DsAuto")]
90+
pub descriptorsize: ::core::option::Option<i32>,
91+
/// Set default value for has_ fields.
92+
#[prost(bool, optional, tag = "23", default = "false")]
93+
pub default_has: ::core::option::Option<bool>,
94+
/// Extra files to include in generated `.pb.h`
95+
#[prost(string, repeated, tag = "24")]
96+
pub include: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
97+
/// Automatic includes to exclude from generated `.pb.h`
98+
/// Same as nanopb_generator.py command line flag -x.
99+
#[prost(string, repeated, tag = "26")]
100+
pub exclude: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
101+
/// Package name that applies only for nanopb.
102+
#[prost(string, optional, tag = "25")]
103+
pub package: ::core::option::Option<::prost::alloc::string::String>,
104+
/// Override type of the field in generated C code. Only to be used with related field types
105+
#[prost(
106+
enumeration = "::prost_types::field_descriptor_proto::Type",
107+
optional,
108+
tag = "27"
109+
)]
110+
pub type_override: ::core::option::Option<i32>,
111+
/// Due to historical reasons, nanopb orders fields in structs by their tag number
112+
/// instead of the order in .proto. Set this to false to keep the .proto order.
113+
/// The default value will probably change to false in nanopb-0.5.0.
114+
#[prost(bool, optional, tag = "28", default = "true")]
115+
pub sort_by_tag: ::core::option::Option<bool>,
116+
/// Set the FT_DEFAULT field conversion strategy.
117+
/// A field that can become a static member of a c struct (e.g. int, bool, etc)
118+
/// will be a a static field.
119+
/// Fields with dynamic length are converted to either a pointer or a callback.
120+
#[prost(enumeration = "FieldType", optional, tag = "29", default = "FtCallback")]
121+
pub fallback_type: ::core::option::Option<i32>,
122+
}
123+
#[derive(serde::Serialize, serde::Deserialize)]
124+
#[serde(rename_all = "camelCase")]
125+
#[allow(clippy::doc_lazy_continuation)]
126+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
127+
#[repr(i32)]
128+
pub enum FieldType {
129+
/// Automatically decide field type, generate static field if possible.
130+
FtDefault = 0,
131+
/// Always generate a callback field.
132+
FtCallback = 1,
133+
/// Always generate a dynamically allocated field.
134+
FtPointer = 4,
135+
/// Generate a static field or raise an exception if not possible.
136+
FtStatic = 2,
137+
/// Ignore the field completely.
138+
FtIgnore = 3,
139+
/// Legacy option, use the separate 'fixed_length' option instead
140+
FtInline = 5,
141+
}
142+
impl FieldType {
143+
/// String value of the enum field names used in the ProtoBuf definition.
144+
///
145+
/// The values are not transformed in any way and thus are considered stable
146+
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
147+
pub fn as_str_name(&self) -> &'static str {
148+
match self {
149+
FieldType::FtDefault => "FT_DEFAULT",
150+
FieldType::FtCallback => "FT_CALLBACK",
151+
FieldType::FtPointer => "FT_POINTER",
152+
FieldType::FtStatic => "FT_STATIC",
153+
FieldType::FtIgnore => "FT_IGNORE",
154+
FieldType::FtInline => "FT_INLINE",
155+
}
156+
}
157+
/// Creates an enum from field names used in the ProtoBuf definition.
158+
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
159+
match value {
160+
"FT_DEFAULT" => Some(Self::FtDefault),
161+
"FT_CALLBACK" => Some(Self::FtCallback),
162+
"FT_POINTER" => Some(Self::FtPointer),
163+
"FT_STATIC" => Some(Self::FtStatic),
164+
"FT_IGNORE" => Some(Self::FtIgnore),
165+
"FT_INLINE" => Some(Self::FtInline),
166+
_ => None,
167+
}
168+
}
169+
}
170+
#[derive(serde::Serialize, serde::Deserialize)]
171+
#[serde(rename_all = "camelCase")]
172+
#[allow(clippy::doc_lazy_continuation)]
173+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
174+
#[repr(i32)]
175+
pub enum IntSize {
176+
/// Default, 32/64bit based on type in .proto
177+
IsDefault = 0,
178+
Is8 = 8,
179+
Is16 = 16,
180+
Is32 = 32,
181+
Is64 = 64,
182+
}
183+
impl IntSize {
184+
/// String value of the enum field names used in the ProtoBuf definition.
185+
///
186+
/// The values are not transformed in any way and thus are considered stable
187+
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
188+
pub fn as_str_name(&self) -> &'static str {
189+
match self {
190+
IntSize::IsDefault => "IS_DEFAULT",
191+
IntSize::Is8 => "IS_8",
192+
IntSize::Is16 => "IS_16",
193+
IntSize::Is32 => "IS_32",
194+
IntSize::Is64 => "IS_64",
195+
}
196+
}
197+
/// Creates an enum from field names used in the ProtoBuf definition.
198+
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
199+
match value {
200+
"IS_DEFAULT" => Some(Self::IsDefault),
201+
"IS_8" => Some(Self::Is8),
202+
"IS_16" => Some(Self::Is16),
203+
"IS_32" => Some(Self::Is32),
204+
"IS_64" => Some(Self::Is64),
205+
_ => None,
206+
}
207+
}
208+
}
209+
#[derive(serde::Serialize, serde::Deserialize)]
210+
#[serde(rename_all = "camelCase")]
211+
#[allow(clippy::doc_lazy_continuation)]
212+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
213+
#[repr(i32)]
214+
pub enum TypenameMangling {
215+
/// Default, no typename mangling
216+
MNone = 0,
217+
/// Strip current package name
218+
MStripPackage = 1,
219+
/// Only use last path component
220+
MFlatten = 2,
221+
/// Replace the package name by the initials
222+
MPackageInitials = 3,
223+
}
224+
impl TypenameMangling {
225+
/// String value of the enum field names used in the ProtoBuf definition.
226+
///
227+
/// The values are not transformed in any way and thus are considered stable
228+
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
229+
pub fn as_str_name(&self) -> &'static str {
230+
match self {
231+
TypenameMangling::MNone => "M_NONE",
232+
TypenameMangling::MStripPackage => "M_STRIP_PACKAGE",
233+
TypenameMangling::MFlatten => "M_FLATTEN",
234+
TypenameMangling::MPackageInitials => "M_PACKAGE_INITIALS",
235+
}
236+
}
237+
/// Creates an enum from field names used in the ProtoBuf definition.
238+
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
239+
match value {
240+
"M_NONE" => Some(Self::MNone),
241+
"M_STRIP_PACKAGE" => Some(Self::MStripPackage),
242+
"M_FLATTEN" => Some(Self::MFlatten),
243+
"M_PACKAGE_INITIALS" => Some(Self::MPackageInitials),
244+
_ => None,
245+
}
246+
}
247+
}
248+
#[derive(serde::Serialize, serde::Deserialize)]
249+
#[serde(rename_all = "camelCase")]
250+
#[allow(clippy::doc_lazy_continuation)]
251+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
252+
#[repr(i32)]
253+
pub enum DescriptorSize {
254+
/// Select minimal size based on field type
255+
DsAuto = 0,
256+
/// 1 word; up to 15 byte fields, no arrays
257+
Ds1 = 1,
258+
/// 2 words; up to 4095 byte fields, 4095 entry arrays
259+
Ds2 = 2,
260+
/// 4 words; up to 2^32-1 byte fields, 2^16-1 entry arrays
261+
Ds4 = 4,
262+
/// 8 words; up to 2^32-1 entry arrays
263+
Ds8 = 8,
264+
}
265+
impl DescriptorSize {
266+
/// String value of the enum field names used in the ProtoBuf definition.
267+
///
268+
/// The values are not transformed in any way and thus are considered stable
269+
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
270+
pub fn as_str_name(&self) -> &'static str {
271+
match self {
272+
DescriptorSize::DsAuto => "DS_AUTO",
273+
DescriptorSize::Ds1 => "DS_1",
274+
DescriptorSize::Ds2 => "DS_2",
275+
DescriptorSize::Ds4 => "DS_4",
276+
DescriptorSize::Ds8 => "DS_8",
277+
}
278+
}
279+
/// Creates an enum from field names used in the ProtoBuf definition.
280+
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
281+
match value {
282+
"DS_AUTO" => Some(Self::DsAuto),
283+
"DS_1" => Some(Self::Ds1),
284+
"DS_2" => Some(Self::Ds2),
285+
"DS_4" => Some(Self::Ds4),
286+
"DS_8" => Some(Self::Ds8),
287+
_ => None,
288+
}
289+
}
290+
}

0 commit comments

Comments
 (0)