Skip to content

Commit

Permalink
Allow derived structs in packets in new rust generator
Browse files Browse the repository at this point in the history
The legacy rust generator did not support derived structs because of
lack of common interface for parsing packets.
All packets under the new generator implement Packet::decode which
make it trivial to support.
  • Loading branch information
hchataing committed May 16, 2024
1 parent d1a2dc0 commit fe1935b
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 12 deletions.
9 changes: 1 addition & 8 deletions pdl-compiler/src/backends/rust/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,10 +524,6 @@ impl<'a> FieldParser<'a> {
assert_eq!(self.shift, 0, "Typedef field does not start on an octet boundary");

let decl = self.scope.typedef[type_id];
if let ast::DeclDesc::Struct { parent_id: Some(_), .. } = &decl.desc {
panic!("Derived struct used in typedef field");
}

let span = self.span;
let id = id.to_ident();
let type_id = type_id.to_ident();
Expand Down Expand Up @@ -555,11 +551,8 @@ impl<'a> FieldParser<'a> {
}
}
ast::DeclDesc::Struct { .. } => {
let width = syn::Index::from(width / 8);
quote! {
let (head, tail) = #span.split_at(#width);
#span = tail;
let #id = #type_id::decode_full(head)?;
let (#id, mut #span) = #type_id::decode(#span)?;
}
}
_ => unreachable!(),
Expand Down
4 changes: 0 additions & 4 deletions pdl-compiler/src/backends/rust/serializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,6 @@ impl Encoder {
assert_eq!(self.bit_shift, 0, "Typedef field does not start on an octet boundary");

let decl = scope.typedef[type_id];
if let ast::DeclDesc::Struct { parent_id: Some(_), .. } = &decl.desc {
panic!("Derived struct used in typedef field");
}

let id = id.to_ident();
let buf = &self.buf;

Expand Down

0 comments on commit fe1935b

Please sign in to comment.