diff --git a/generator/sbpg/targets/resources/rust/sbp_cargo.toml b/generator/sbpg/targets/resources/rust/sbp_cargo.toml index 770f97de62..0d9ded174b 100644 --- a/generator/sbpg/targets/resources/rust/sbp_cargo.toml +++ b/generator/sbpg/targets/resources/rust/sbp_cargo.toml @@ -20,7 +20,7 @@ readme = "../../README.md" [features] default = [] async = ["futures", "dencode/async"] -json = ["serde", "serde_json", "base64"] +json = ["serde", "serde_json", "serde-big-array", "base64"] link = ["slotmap"] [lib] @@ -48,6 +48,10 @@ optional = true version = "1.0" optional = true +[dependencies.serde-big-array] +version = "0.4.1" +optional = true + [dependencies.base64] version = "0.13" optional = true diff --git a/generator/sbpg/targets/resources/rust/sbp_messages_mod.rs b/generator/sbpg/targets/resources/rust/sbp_messages_mod.rs index d5e1d6bb6d..8b14ccced0 100644 --- a/generator/sbpg/targets/resources/rust/sbp_messages_mod.rs +++ b/generator/sbpg/targets/resources/rust/sbp_messages_mod.rs @@ -37,6 +37,9 @@ mod lib { pub use bytes::{Buf, BufMut}; + #[cfg(feature = "serde")] + pub use serde_big_array::BigArray; + macro_rules! get_bit_range { ($bitrange:expr, $source_ty:ty, $target_ty:ty, $msb:expr, $lsb:expr) => {{ let source_bit_len = std::mem::size_of::<$source_ty>() * 8; diff --git a/generator/sbpg/targets/resources/rust/sbp_messages_template.rs b/generator/sbpg/targets/resources/rust/sbp_messages_template.rs index d2fa4ff644..c1295b533d 100644 --- a/generator/sbpg/targets/resources/rust/sbp_messages_template.rs +++ b/generator/sbpg/targets/resources/rust/sbp_messages_template.rs @@ -53,7 +53,12 @@ pub struct (((m.msg_name))) { ((*- if f.desc *)) /// (((f.desc | commentify(indent=2) ))) ((*- endif *)) + ((*- if f.type_id == "array" and "size" in f.options and f.options["size"].value >= 32 *)) + #[cfg_attr(feature = "serde", serde(with="BigArray", rename(serialize = "(((f.identifier)))")))] + ((*- else *)) #[cfg_attr(feature = "serde", serde(rename(serialize = "(((f.identifier)))")))] + ((*- endif *)) + pub (((f.field_name))): (((f.type))), ((*- endfor *)) } diff --git a/rust/sbp/Cargo.toml b/rust/sbp/Cargo.toml index 3d9584c5b4..649f595f87 100644 --- a/rust/sbp/Cargo.toml +++ b/rust/sbp/Cargo.toml @@ -20,7 +20,7 @@ readme = "../../README.md" [features] default = [] async = ["futures", "dencode/async"] -json = ["serde", "serde_json", "base64"] +json = ["serde", "serde_json", "serde-big-array", "base64"] link = ["slotmap"] [lib] @@ -48,6 +48,10 @@ optional = true version = "1.0" optional = true +[dependencies.serde-big-array] +version = "0.4.1" +optional = true + [dependencies.base64] version = "0.13" optional = true diff --git a/rust/sbp/src/messages/mod.rs b/rust/sbp/src/messages/mod.rs index 3462ccb0a6..67e5786271 100644 --- a/rust/sbp/src/messages/mod.rs +++ b/rust/sbp/src/messages/mod.rs @@ -270,6 +270,9 @@ mod lib { pub use bytes::{Buf, BufMut}; + #[cfg(feature = "serde")] + pub use serde_big_array::BigArray; + macro_rules! get_bit_range { ($bitrange:expr, $source_ty:ty, $target_ty:ty, $msb:expr, $lsb:expr) => {{ let source_bit_len = std::mem::size_of::<$source_ty>() * 8;