Loading tools/pdl/src/backends/rust.rs +18 −0 Original line number Diff line number Diff line Loading @@ -474,6 +474,21 @@ fn generate_packet_decl( } } }); let specialize = has_children_or_payload.then(|| { quote! { pub fn specialize(&self) -> #id_child { match &self.#id_lower.child { #( #id_data_child::#child(_) => #id_child::#child(#child::new(self.#top_level_id_lower.clone()).unwrap()), )* #id_data_child::Payload(payload) => #id_child::Payload(payload.clone()), #id_data_child::None => #id_child::None, } } } }); let builder_payload_field = has_children_or_payload.then(|| { quote! { pub payload: Option<Bytes> Loading Loading @@ -566,6 +581,9 @@ fn generate_packet_decl( let data = #top_level_data::parse(&mut bytes)?; Ok(Self::new(Arc::new(data)).unwrap()) } #specialize fn new(#top_level_id_lower: Arc<#top_level_data>) -> std::result::Result<Self, &'static str> { #( Loading tools/pdl/tests/generated/packet_decl_child_packets_big_endian.rs +8 −0 Original line number Diff line number Diff line Loading @@ -248,6 +248,14 @@ impl Foo { let data = FooData::parse(&mut bytes)?; Ok(Self::new(Arc::new(data)).unwrap()) } pub fn specialize(&self) -> FooChild { match &self.foo.child { FooDataChild::Bar(_) => FooChild::Bar(Bar::new(self.foo.clone()).unwrap()), FooDataChild::Baz(_) => FooChild::Baz(Baz::new(self.foo.clone()).unwrap()), FooDataChild::Payload(payload) => FooChild::Payload(payload.clone()), FooDataChild::None => FooChild::None, } } fn new(foo: Arc<FooData>) -> std::result::Result<Self, &'static str> { Ok(Self { foo }) } Loading tools/pdl/tests/generated/packet_decl_child_packets_little_endian.rs +8 −0 Original line number Diff line number Diff line Loading @@ -248,6 +248,14 @@ impl Foo { let data = FooData::parse(&mut bytes)?; Ok(Self::new(Arc::new(data)).unwrap()) } pub fn specialize(&self) -> FooChild { match &self.foo.child { FooDataChild::Bar(_) => FooChild::Bar(Bar::new(self.foo.clone()).unwrap()), FooDataChild::Baz(_) => FooChild::Baz(Baz::new(self.foo.clone()).unwrap()), FooDataChild::Payload(payload) => FooChild::Payload(payload.clone()), FooDataChild::None => FooChild::None, } } fn new(foo: Arc<FooData>) -> std::result::Result<Self, &'static str> { Ok(Self { foo }) } Loading tools/pdl/tests/generated/packet_decl_grand_children_big_endian.rs +35 −0 Original line number Diff line number Diff line Loading @@ -247,6 +247,15 @@ impl Parent { let data = ParentData::parse(&mut bytes)?; Ok(Self::new(Arc::new(data)).unwrap()) } pub fn specialize(&self) -> ParentChild { match &self.parent.child { ParentDataChild::Child(_) => { ParentChild::Child(Child::new(self.parent.clone()).unwrap()) } ParentDataChild::Payload(payload) => ParentChild::Payload(payload.clone()), ParentDataChild::None => ParentChild::None, } } fn new(parent: Arc<ParentData>) -> std::result::Result<Self, &'static str> { Ok(Self { parent }) } Loading Loading @@ -419,6 +428,15 @@ impl Child { let data = ParentData::parse(&mut bytes)?; Ok(Self::new(Arc::new(data)).unwrap()) } pub fn specialize(&self) -> ChildChild { match &self.child.child { ChildDataChild::GrandChild(_) => { ChildChild::GrandChild(GrandChild::new(self.parent.clone()).unwrap()) } ChildDataChild::Payload(payload) => ChildChild::Payload(payload.clone()), ChildDataChild::None => ChildChild::None, } } fn new(parent: Arc<ParentData>) -> std::result::Result<Self, &'static str> { let child = match &parent.child { ParentDataChild::Child(value) => value.clone(), Loading Loading @@ -604,6 +622,15 @@ impl GrandChild { let data = ParentData::parse(&mut bytes)?; Ok(Self::new(Arc::new(data)).unwrap()) } pub fn specialize(&self) -> GrandChildChild { match &self.grandchild.child { GrandChildDataChild::GrandGrandChild(_) => { GrandChildChild::GrandGrandChild(GrandGrandChild::new(self.parent.clone()).unwrap()) } GrandChildDataChild::Payload(payload) => GrandChildChild::Payload(payload.clone()), GrandChildDataChild::None => GrandChildChild::None, } } fn new(parent: Arc<ParentData>) -> std::result::Result<Self, &'static str> { let child = match &parent.child { ParentDataChild::Child(value) => value.clone(), Loading Loading @@ -793,6 +820,14 @@ impl GrandGrandChild { let data = ParentData::parse(&mut bytes)?; Ok(Self::new(Arc::new(data)).unwrap()) } pub fn specialize(&self) -> GrandGrandChildChild { match &self.grandgrandchild.child { GrandGrandChildDataChild::Payload(payload) => { GrandGrandChildChild::Payload(payload.clone()) } GrandGrandChildDataChild::None => GrandGrandChildChild::None, } } fn new(parent: Arc<ParentData>) -> std::result::Result<Self, &'static str> { let child = match &parent.child { ParentDataChild::Child(value) => value.clone(), Loading tools/pdl/tests/generated/packet_decl_grand_children_little_endian.rs +35 −0 Original line number Diff line number Diff line Loading @@ -247,6 +247,15 @@ impl Parent { let data = ParentData::parse(&mut bytes)?; Ok(Self::new(Arc::new(data)).unwrap()) } pub fn specialize(&self) -> ParentChild { match &self.parent.child { ParentDataChild::Child(_) => { ParentChild::Child(Child::new(self.parent.clone()).unwrap()) } ParentDataChild::Payload(payload) => ParentChild::Payload(payload.clone()), ParentDataChild::None => ParentChild::None, } } fn new(parent: Arc<ParentData>) -> std::result::Result<Self, &'static str> { Ok(Self { parent }) } Loading Loading @@ -419,6 +428,15 @@ impl Child { let data = ParentData::parse(&mut bytes)?; Ok(Self::new(Arc::new(data)).unwrap()) } pub fn specialize(&self) -> ChildChild { match &self.child.child { ChildDataChild::GrandChild(_) => { ChildChild::GrandChild(GrandChild::new(self.parent.clone()).unwrap()) } ChildDataChild::Payload(payload) => ChildChild::Payload(payload.clone()), ChildDataChild::None => ChildChild::None, } } fn new(parent: Arc<ParentData>) -> std::result::Result<Self, &'static str> { let child = match &parent.child { ParentDataChild::Child(value) => value.clone(), Loading Loading @@ -604,6 +622,15 @@ impl GrandChild { let data = ParentData::parse(&mut bytes)?; Ok(Self::new(Arc::new(data)).unwrap()) } pub fn specialize(&self) -> GrandChildChild { match &self.grandchild.child { GrandChildDataChild::GrandGrandChild(_) => { GrandChildChild::GrandGrandChild(GrandGrandChild::new(self.parent.clone()).unwrap()) } GrandChildDataChild::Payload(payload) => GrandChildChild::Payload(payload.clone()), GrandChildDataChild::None => GrandChildChild::None, } } fn new(parent: Arc<ParentData>) -> std::result::Result<Self, &'static str> { let child = match &parent.child { ParentDataChild::Child(value) => value.clone(), Loading Loading @@ -793,6 +820,14 @@ impl GrandGrandChild { let data = ParentData::parse(&mut bytes)?; Ok(Self::new(Arc::new(data)).unwrap()) } pub fn specialize(&self) -> GrandGrandChildChild { match &self.grandgrandchild.child { GrandGrandChildDataChild::Payload(payload) => { GrandGrandChildChild::Payload(payload.clone()) } GrandGrandChildDataChild::None => GrandGrandChildChild::None, } } fn new(parent: Arc<ParentData>) -> std::result::Result<Self, &'static str> { let child = match &parent.child { ParentDataChild::Child(value) => value.clone(), Loading Loading
tools/pdl/src/backends/rust.rs +18 −0 Original line number Diff line number Diff line Loading @@ -474,6 +474,21 @@ fn generate_packet_decl( } } }); let specialize = has_children_or_payload.then(|| { quote! { pub fn specialize(&self) -> #id_child { match &self.#id_lower.child { #( #id_data_child::#child(_) => #id_child::#child(#child::new(self.#top_level_id_lower.clone()).unwrap()), )* #id_data_child::Payload(payload) => #id_child::Payload(payload.clone()), #id_data_child::None => #id_child::None, } } } }); let builder_payload_field = has_children_or_payload.then(|| { quote! { pub payload: Option<Bytes> Loading Loading @@ -566,6 +581,9 @@ fn generate_packet_decl( let data = #top_level_data::parse(&mut bytes)?; Ok(Self::new(Arc::new(data)).unwrap()) } #specialize fn new(#top_level_id_lower: Arc<#top_level_data>) -> std::result::Result<Self, &'static str> { #( Loading
tools/pdl/tests/generated/packet_decl_child_packets_big_endian.rs +8 −0 Original line number Diff line number Diff line Loading @@ -248,6 +248,14 @@ impl Foo { let data = FooData::parse(&mut bytes)?; Ok(Self::new(Arc::new(data)).unwrap()) } pub fn specialize(&self) -> FooChild { match &self.foo.child { FooDataChild::Bar(_) => FooChild::Bar(Bar::new(self.foo.clone()).unwrap()), FooDataChild::Baz(_) => FooChild::Baz(Baz::new(self.foo.clone()).unwrap()), FooDataChild::Payload(payload) => FooChild::Payload(payload.clone()), FooDataChild::None => FooChild::None, } } fn new(foo: Arc<FooData>) -> std::result::Result<Self, &'static str> { Ok(Self { foo }) } Loading
tools/pdl/tests/generated/packet_decl_child_packets_little_endian.rs +8 −0 Original line number Diff line number Diff line Loading @@ -248,6 +248,14 @@ impl Foo { let data = FooData::parse(&mut bytes)?; Ok(Self::new(Arc::new(data)).unwrap()) } pub fn specialize(&self) -> FooChild { match &self.foo.child { FooDataChild::Bar(_) => FooChild::Bar(Bar::new(self.foo.clone()).unwrap()), FooDataChild::Baz(_) => FooChild::Baz(Baz::new(self.foo.clone()).unwrap()), FooDataChild::Payload(payload) => FooChild::Payload(payload.clone()), FooDataChild::None => FooChild::None, } } fn new(foo: Arc<FooData>) -> std::result::Result<Self, &'static str> { Ok(Self { foo }) } Loading
tools/pdl/tests/generated/packet_decl_grand_children_big_endian.rs +35 −0 Original line number Diff line number Diff line Loading @@ -247,6 +247,15 @@ impl Parent { let data = ParentData::parse(&mut bytes)?; Ok(Self::new(Arc::new(data)).unwrap()) } pub fn specialize(&self) -> ParentChild { match &self.parent.child { ParentDataChild::Child(_) => { ParentChild::Child(Child::new(self.parent.clone()).unwrap()) } ParentDataChild::Payload(payload) => ParentChild::Payload(payload.clone()), ParentDataChild::None => ParentChild::None, } } fn new(parent: Arc<ParentData>) -> std::result::Result<Self, &'static str> { Ok(Self { parent }) } Loading Loading @@ -419,6 +428,15 @@ impl Child { let data = ParentData::parse(&mut bytes)?; Ok(Self::new(Arc::new(data)).unwrap()) } pub fn specialize(&self) -> ChildChild { match &self.child.child { ChildDataChild::GrandChild(_) => { ChildChild::GrandChild(GrandChild::new(self.parent.clone()).unwrap()) } ChildDataChild::Payload(payload) => ChildChild::Payload(payload.clone()), ChildDataChild::None => ChildChild::None, } } fn new(parent: Arc<ParentData>) -> std::result::Result<Self, &'static str> { let child = match &parent.child { ParentDataChild::Child(value) => value.clone(), Loading Loading @@ -604,6 +622,15 @@ impl GrandChild { let data = ParentData::parse(&mut bytes)?; Ok(Self::new(Arc::new(data)).unwrap()) } pub fn specialize(&self) -> GrandChildChild { match &self.grandchild.child { GrandChildDataChild::GrandGrandChild(_) => { GrandChildChild::GrandGrandChild(GrandGrandChild::new(self.parent.clone()).unwrap()) } GrandChildDataChild::Payload(payload) => GrandChildChild::Payload(payload.clone()), GrandChildDataChild::None => GrandChildChild::None, } } fn new(parent: Arc<ParentData>) -> std::result::Result<Self, &'static str> { let child = match &parent.child { ParentDataChild::Child(value) => value.clone(), Loading Loading @@ -793,6 +820,14 @@ impl GrandGrandChild { let data = ParentData::parse(&mut bytes)?; Ok(Self::new(Arc::new(data)).unwrap()) } pub fn specialize(&self) -> GrandGrandChildChild { match &self.grandgrandchild.child { GrandGrandChildDataChild::Payload(payload) => { GrandGrandChildChild::Payload(payload.clone()) } GrandGrandChildDataChild::None => GrandGrandChildChild::None, } } fn new(parent: Arc<ParentData>) -> std::result::Result<Self, &'static str> { let child = match &parent.child { ParentDataChild::Child(value) => value.clone(), Loading
tools/pdl/tests/generated/packet_decl_grand_children_little_endian.rs +35 −0 Original line number Diff line number Diff line Loading @@ -247,6 +247,15 @@ impl Parent { let data = ParentData::parse(&mut bytes)?; Ok(Self::new(Arc::new(data)).unwrap()) } pub fn specialize(&self) -> ParentChild { match &self.parent.child { ParentDataChild::Child(_) => { ParentChild::Child(Child::new(self.parent.clone()).unwrap()) } ParentDataChild::Payload(payload) => ParentChild::Payload(payload.clone()), ParentDataChild::None => ParentChild::None, } } fn new(parent: Arc<ParentData>) -> std::result::Result<Self, &'static str> { Ok(Self { parent }) } Loading Loading @@ -419,6 +428,15 @@ impl Child { let data = ParentData::parse(&mut bytes)?; Ok(Self::new(Arc::new(data)).unwrap()) } pub fn specialize(&self) -> ChildChild { match &self.child.child { ChildDataChild::GrandChild(_) => { ChildChild::GrandChild(GrandChild::new(self.parent.clone()).unwrap()) } ChildDataChild::Payload(payload) => ChildChild::Payload(payload.clone()), ChildDataChild::None => ChildChild::None, } } fn new(parent: Arc<ParentData>) -> std::result::Result<Self, &'static str> { let child = match &parent.child { ParentDataChild::Child(value) => value.clone(), Loading Loading @@ -604,6 +622,15 @@ impl GrandChild { let data = ParentData::parse(&mut bytes)?; Ok(Self::new(Arc::new(data)).unwrap()) } pub fn specialize(&self) -> GrandChildChild { match &self.grandchild.child { GrandChildDataChild::GrandGrandChild(_) => { GrandChildChild::GrandGrandChild(GrandGrandChild::new(self.parent.clone()).unwrap()) } GrandChildDataChild::Payload(payload) => GrandChildChild::Payload(payload.clone()), GrandChildDataChild::None => GrandChildChild::None, } } fn new(parent: Arc<ParentData>) -> std::result::Result<Self, &'static str> { let child = match &parent.child { ParentDataChild::Child(value) => value.clone(), Loading Loading @@ -793,6 +820,14 @@ impl GrandGrandChild { let data = ParentData::parse(&mut bytes)?; Ok(Self::new(Arc::new(data)).unwrap()) } pub fn specialize(&self) -> GrandGrandChildChild { match &self.grandgrandchild.child { GrandGrandChildDataChild::Payload(payload) => { GrandGrandChildChild::Payload(payload.clone()) } GrandGrandChildDataChild::None => GrandGrandChildChild::None, } } fn new(parent: Arc<ParentData>) -> std::result::Result<Self, &'static str> { let child = match &parent.child { ParentDataChild::Child(value) => value.clone(), Loading