Skip to content

Commit

Permalink
Add .get_properties_mut() helper method to some frames
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed Aug 23, 2021
1 parent 4556ad1 commit ccafaf1
Show file tree
Hide file tree
Showing 5 changed files with 313 additions and 264 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changes

## [codec-0.7.2] - 2021-08-23

* Add `.get_properties_mut()` helper method to some frames

## [codec-0.7.1] - 2021-08-22

* Auto-generate mut methods for type fields
Expand Down
2 changes: 1 addition & 1 deletion codec/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ntex-amqp-codec"
version = "0.7.1"
version = "0.7.2"
description = "AMQP 1.0 Protocol Codec"
authors = ["Nikolay Kim <[email protected]>", "Max Gortman <[email protected]>", "Mike Yagley <[email protected]>"]
license = "MIT/Apache-2.0"
Expand Down
10 changes: 10 additions & 0 deletions codec/codegen/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,16 @@ impl {{list.name}} {
{{/if}}
{{/each}}

{{#if list.props}}
#[inline]
pub fn get_properties_mut(&mut self) -> &mut Fields {
if self.{{list.inner}}properties.is_none() {
self.{{list.inner}}properties = Some(Fields::default());
}
self.{{list.inner}}properties.as_mut().unwrap()
}
{{/if}}

{{#if list.transfer}}
#[inline]
pub fn body(&self) -> Option<&TransferBody> {
Expand Down
7 changes: 7 additions & 0 deletions codec/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ pub struct Described {
fields: Vec<Field>,
transfer: bool,
boxed: bool,
props: bool,
inner: String,
}

Expand Down Expand Up @@ -335,6 +336,10 @@ impl Described {
.map(|item| item == "frame")
.unwrap_or(false),
};
let props = match d.name.as_str() {
"open" | "begin" | "attach" | "flow" => true,
_ => false,
};
Described {
name: camel_case(&d.name),
ty: String::new(),
Expand All @@ -351,6 +356,7 @@ impl Described {
.to_string(),
transfer,
boxed,
props,
}
}
fn alias(d: _Described) -> Described {
Expand All @@ -362,6 +368,7 @@ impl Described {
fields: d.field.into_iter().map(|f| Field::from(f)).collect(),
transfer: false,
boxed: false,
props: false,
inner: "".to_string(),
}
}
Expand Down
Loading

0 comments on commit ccafaf1

Please sign in to comment.