feat(mavlink): adopt the kaptan-native dialect
This commit is contained in:
1 parent
1c90870634
commit
5f91465e66
87 files changed
+7733
-6850
No files matched your search
@@ -31,6 +31,7 @@ fn expand_scalars(
|
||||
let mut descriptors = Vec::new();
|
||||
let mut reads = Vec::new();
|
||||
let mut writes = Vec::new();
|
||||
let mut snapshot_widths = Vec::new();
|
||||
for field in &fields {
|
||||
let FieldMetadata {
|
||||
descriptor,
|
||||
@@ -42,6 +43,7 @@ fn expand_scalars(
|
||||
let ty = &field.ty;
|
||||
let field_ident = &field.ident;
|
||||
let (kind, read, decode, out_of_domain_rule) = if !field.enum_backed {
|
||||
snapshot_widths.push(quote! { <#ty as #crate_path::ConfigScalar>::KIND.width() });
|
||||
(
|
||||
quote! { <#ty as #crate_path::ConfigScalar>::KIND },
|
||||
quote! { #crate_path::ConfigScalar::into_config_value(self.#field_ident) },
|
||||
@@ -49,16 +51,13 @@ fn expand_scalars(
|
||||
quote! { #crate_path::ValidationRule::AboveMaximum },
|
||||
)
|
||||
} else {
|
||||
snapshot_widths.push(quote! { 1usize });
|
||||
(
|
||||
quote! { #crate_path::ValueKind::U32 },
|
||||
quote! {
|
||||
#crate_path::ConfigValue::U32(u32::from(self.#field_ident.wire_value()))
|
||||
},
|
||||
quote! { #crate_path::ValueKind::U8 },
|
||||
quote! { #crate_path::ConfigValue::U8(self.#field_ident.wire_value()) },
|
||||
quote! {
|
||||
match value {
|
||||
#crate_path::ConfigValue::U32(value) => u8::try_from(value)
|
||||
.ok()
|
||||
.and_then(<#ty>::try_from_wire)
|
||||
#crate_path::ConfigValue::U8(value) => <#ty>::try_from_wire(value)
|
||||
.ok_or(#crate_path::ScalarValueError::OutOfDomain),
|
||||
value => Err(#crate_path::ScalarValueError::WrongKind(value.kind())),
|
||||
}
|
||||
@@ -122,6 +121,7 @@ fn expand_scalars(
|
||||
|
||||
impl #impl_generics #crate_path::Config for #ident #type_generics #where_clause {
|
||||
const FIELD_COUNT: usize = Self::DESCRIPTORS.len();
|
||||
const SNAPSHOT_VALUE_BYTES: usize = 0 #(+ #snapshot_widths)*;
|
||||
const SCHEMA_ID: [u8; 16] =
|
||||
#crate_path::validation::__schema_id(Self::DESCRIPTORS);
|
||||
|
||||
@@ -168,6 +168,7 @@ fn expand_children(
|
||||
let mut reads = Vec::new();
|
||||
let mut writes = Vec::new();
|
||||
let mut counts = Vec::new();
|
||||
let mut snapshot_widths = Vec::new();
|
||||
let mut schema_ids = Vec::new();
|
||||
let mut descriptor_lookups = Vec::new();
|
||||
for field in &fields {
|
||||
@@ -194,6 +195,7 @@ fn expand_children(
|
||||
}
|
||||
});
|
||||
counts.push(quote! { <#ty as #crate_path::Config>::FIELD_COUNT });
|
||||
snapshot_widths.push(quote! { <#ty as #crate_path::Config>::SNAPSHOT_VALUE_BYTES });
|
||||
schema_ids.push(quote! { <#ty as #crate_path::Config>::SCHEMA_ID });
|
||||
descriptor_lookups.push(quote! {
|
||||
if index < <#ty as #crate_path::Config>::FIELD_COUNT {
|
||||
@@ -207,6 +209,7 @@ fn expand_children(
|
||||
Ok(quote! {
|
||||
impl #impl_generics #crate_path::Config for #ident #type_generics #where_clause {
|
||||
const FIELD_COUNT: usize = 0 #(+ #counts)*;
|
||||
const SNAPSHOT_VALUE_BYTES: usize = 0 #(+ #snapshot_widths)*;
|
||||
const SCHEMA_ID: [u8; 16] =
|
||||
#crate_path::validation::__combine_schema_ids(&[#(#schema_ids),*]);
|
||||
|
||||
@@ -282,7 +285,7 @@ fn expand_field(crate_path: &syn::Path, field: &crate::parse::FieldModel) -> Res
|
||||
)
|
||||
} else {
|
||||
(
|
||||
quote! { #crate_path::ValueKind::U32 },
|
||||
quote! { #crate_path::ValueKind::U8 },
|
||||
quote! { <#ty>::CONFIG_ENUM_OPTIONS },
|
||||
)
|
||||
};
|
||||
@@ -328,7 +331,9 @@ fn config_value_constructor_tokens(crate_path: &syn::Path, ty: &syn::Type) -> Re
|
||||
let value = match segment.ident.to_string().as_str() {
|
||||
"bool" => quote! { #crate_path::ConfigValue::Bool },
|
||||
"i32" => quote! { #crate_path::ConfigValue::I32 },
|
||||
"u8" | "u16" | "u32" => quote! { #crate_path::ConfigValue::U32 },
|
||||
"u8" => quote! { #crate_path::ConfigValue::U8 },
|
||||
"u16" => quote! { #crate_path::ConfigValue::U16 },
|
||||
"u32" => quote! { #crate_path::ConfigValue::U32 },
|
||||
"u64" => quote! { #crate_path::ConfigValue::U64 },
|
||||
"f32" => quote! { #crate_path::ConfigValue::F32 },
|
||||
"f64" => quote! { #crate_path::ConfigValue::F64 },
|
||||
|
||||
Reference in new issue
Block a user