Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a630ba0f authored by Myles Watson's avatar Myles Watson
Browse files

PDL: Use Size for StructField sizes

Structs can have dynamic sizes, which need to be passed in.

Bug: 138260498
Test: bluetooth_packet_parser_test
Change-Id: I621252699b597e728ff1566b95babd98cf00e8d4
parent b95e2472
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@

const std::string StructField::kFieldType = "StructField";

StructField::StructField(std::string name, std::string type_name, int size, ParseLocation loc)
StructField::StructField(std::string name, std::string type_name, Size size, ParseLocation loc)
    : PacketField(name, loc), type_name_(type_name), size_(size) {}

const std::string& StructField::GetFieldType() const {
@@ -30,6 +30,11 @@ Size StructField::GetSize() const {
  return size_;
}

Size StructField::GetBuilderSize() const {
  std::string ret = "(" + GetName() + "_.size() * 8)";
  return ret;
}

std::string StructField::GetDataType() const {
  return type_name_;
}
+3 −1
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@

class StructField : public PacketField {
 public:
  StructField(std::string name, std::string type_name, int size, ParseLocation loc);
  StructField(std::string name, std::string type_name, Size size, ParseLocation loc);

  static const std::string kFieldType;

@@ -29,6 +29,8 @@ class StructField : public PacketField {

  virtual Size GetSize() const override;

  virtual Size GetBuilderSize() const override;

  virtual std::string GetDataType() const override;

  virtual void GenExtractor(std::ostream& s, int num_leading_bits, bool for_struct) const override;
+1 −1
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ PacketField* StructDef::GetNewField(const std::string& name, ParseLocation loc)
  if (fields_.HasBody()) {
    return new VariableLengthStructField(name, name_, loc);
  } else {
    return new StructField(name, name_, total_size_.bits(), loc);
    return new StructField(name, name_, total_size_, loc);
  }
}