Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add derive serde attributes to the generated message and service struct #137

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions rosrust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ license = "MIT"
name = "rosrust"
readme = "../README.md"
repository = "https://github.com/adnanademovic/rosrust"
version = "0.9.4"
version = "0.9.5"

[dependencies]
byteorder = "1.3.2"
Expand All @@ -15,7 +15,7 @@ error-chain = "0.12.1"
lazy_static = "1.4.0"
log = "0.4.8"
nix = "0.15.0"
rosrust_codegen = "0.9.2"
rosrust_codegen = 0.9.3
ZhangHanDong marked this conversation as resolved.
Show resolved Hide resolved
serde = "1.0.102"
serde_derive = "1.0.102"
xml-rpc = "0.0.12"
Expand All @@ -29,6 +29,9 @@ regex = "1.3.1"
criterion = "0.3.0"
env_logger = "0.7.1"

[features]
derive-serde = ["rosrust_codegen/derive-serde"]

[[bench]]
name = "benchmarks"
harness = false
Expand Down
10 changes: 9 additions & 1 deletion rosrust_codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ license = "MIT"
name = "rosrust_codegen"
readme = "README.md"
repository = "https://github.com/adnanademovic/rosrust"
version = "0.9.2"
version = "0.9.3"

[features]
derive-serde = ["serde"]

[dependencies]
error-chain = "0.12.1"
Expand All @@ -19,5 +22,10 @@ digest = "0.8.1"
md-5 = "0.8.0"
hex = "0.4.0"

[dependencies.serde]
serde = "1.0"



[lib]
proc-macro = true
3 changes: 3 additions & 0 deletions rosrust_codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

extern crate proc_macro;

#[cfg(feature="derive-serde")]
use serde;

mod error;
mod genmsg;
mod helpers;
Expand Down
9 changes: 9 additions & 0 deletions rosrust_codegen/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,16 @@ impl Msg {
.iter()
.map(|v| v.const_token_stream(crate_prefix))
.collect::<Vec<_>>();

let serde_derives = if cfg!(feature = "derive-serde") {
quote! { #[derive(::serde::Serialize, ::serde::Deserialize)] }
} else {
quote! {}
};

quote! {
#[allow(dead_code, non_camel_case_types, non_snake_case)]
#serde_derives
#[derive(Clone)]
pub struct #name {
#(#fields)*
Expand Down Expand Up @@ -387,6 +395,7 @@ fn match_lines(data: &str) -> Result<Vec<FieldInfo>> {
.chain_err(|| "Failed to parse line in data string")
}

#[cfg_attr(feature = "derive-serde", derive(::serde::Serialize, ::serde::Deserialize))]
#[derive(Debug, PartialEq)]
struct FieldLine {
field_type: String,
Expand Down
7 changes: 7 additions & 0 deletions rosrust_codegen/src/output_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,15 @@ impl Service {
let req_ident = Ident::new(&format!("{}Req", name), Span::call_site());
let res_ident = Ident::new(&format!("{}Res", name), Span::call_site());

let serde_derives = if cfg!(feature = "derive-serde") {
quote! { #[derive(::serde::Serialize, ::serde::Deserialize)] }
} else {
quote! {}
};

quote! {
#[allow(dead_code,non_camel_case_types,non_snake_case)]
#serde_derives
#[derive(Clone, Debug, Default, PartialEq)]
pub struct #name_ident;

Expand Down
2 changes: 1 addition & 1 deletion rosrust_msg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ version = "0.1.0"
build = "build.rs"

[dependencies]
rosrust = "0.9.4"
rosrust = "0.9.5"