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

Commit 50e4c1a9 authored by Zach Johnson's avatar Zach Johnson Committed by Gerrit Code Review
Browse files

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

parents 794c2f38 08329553
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