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

Commit 08329553 authored by Qasim Javed's avatar Qasim Javed
Browse files

rusty-gd: Changes to make the HCI inquiry test pass

These include:

Writing count fields
Correct parsing of vectors
Using the correct offset when parsing struct fields

P.S. Also fixes the tokio panic caused by missing handling of the else
branch in the snoop HAL.

Bug: 171749953
Tag: #gd-refactor
Test: gd/cert/run --rhost DirectHciTest:test_inquiry_from_dut

Change-Id: I4bb884369d9d811c906e271c29460a3eb134a727
parent 7b09be8c
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -57,3 +57,9 @@ void CountField::GenValidator(std::ostream&) const {
std::string CountField::GetSizedFieldName() const {
  return sized_field_name_;
}

void CountField::GenRustWriter(std::ostream& s, Size start_offset, Size) const {
  s << "buffer[" << start_offset.bytes() << "..";
  s << start_offset.bytes() + GetSize().bytes() << "].copy_from_slice(&";
  s << "(self." << GetSizedFieldName() << ".len() as u8).to_le_bytes());";
}
+2 −0
Original line number Diff line number Diff line
@@ -44,6 +44,8 @@ class CountField : public ScalarField {

  virtual std::string GetSizedFieldName() const;

  void GenRustWriter(std::ostream& s, Size start_offset, Size end_offset) const override;

 private:
  int size_;
  std::string sized_field_name_;
+4 −2
Original line number Diff line number Diff line
@@ -98,6 +98,8 @@ void StructField::GenRustGetter(std::ostream& s, Size start_offset, Size) const
  s << start_offset.bytes() + GetSize().bytes() << "]).unwrap();";
}

void StructField::GenRustWriter(std::ostream& s, Size, Size) const {
  s << "self." << GetName() << ".write_to(buffer);";
void StructField::GenRustWriter(std::ostream& s, Size start_offset, Size) const {
  s << "let " << GetName() << " = &mut buffer[" << start_offset.bytes();
  s << ".." << start_offset.bytes() + GetSize().bytes() << "];";
  s << "self." << GetName() << ".write_to(" << GetName() << ");";
}
+13 −4
Original line number Diff line number Diff line
@@ -285,8 +285,8 @@ void VectorField::GenRustGetter(std::ostream& s, Size start_offset, Size) const
	  s << "bytes[" << start_offset.bytes() << "..].to_vec().chunks_exact(";
	} else {
          s << "bytes[" << start_offset.bytes() << "..(";
          s << start_offset.bytes() << " + " << size_field_->GetName();
          s << " as usize)].to_vec().chunks_exact(";
          s << start_offset.bytes() << " + (" << size_field_->GetName() << " as usize * ";
          s << GetElementField()->GetSize().bytes() << "))].to_vec().chunks_exact(";
	}

        s << element_size << ").into_iter().map(|i| ";
@@ -302,6 +302,15 @@ void VectorField::GenRustGetter(std::ostream& s, Size start_offset, Size) const
  }
}

void VectorField::GenRustWriter(std::ostream& s, Size, Size) const {
  s << "unimplemented!();";
void VectorField::GenRustWriter(std::ostream& s, Size start_offset, Size) const {
  s << "for (i, e) in self." << GetName() << ".iter().enumerate() {";
  if (GetElementField()->GetFieldType() == ScalarField::kFieldType) {
    s << "buffer[" << start_offset.bytes() << "+i..";
    s << start_offset.bytes() << "+i+" << GetElementField()->GetSize().bytes() << "]";
    s << ".copy_from_slice(&e.to_le_bytes())";
  } else {
    s << "self." << GetName() << "[i].write_to(&mut buffer[" << start_offset.bytes() << "+i..";
    s << start_offset.bytes() << "+i+" << GetElementField()->GetSize().bytes() << "]);";
  }
  s << "}";
}
+0 −2
Original line number Diff line number Diff line
@@ -573,7 +573,6 @@ bool ParentDef::HasChildEnums() const {
void ParentDef::GenRustWriteToFields(std::ostream& s) const {
  auto fields = fields_.GetFieldsWithoutTypes({
      BodyField::kFieldType,
      CountField::kFieldType,
      PaddingField::kFieldType,
      ReservedField::kFieldType,
      FixedScalarField::kFieldType,
@@ -634,7 +633,6 @@ void ParentDef::GenSizeRetVal(std::ostream& s) const {
  int size = 0;
  auto fields = fields_.GetFieldsWithoutTypes({
      BodyField::kFieldType,
      CountField::kFieldType,
  });
  for (int i = 0; i < fields.size(); i++) {
    size += fields[i]->GetSize().bits();
Loading