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
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());";
+}
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_;
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() << ");";
}
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| ";
}
}
-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 << "}";
}
void ParentDef::GenRustWriteToFields(std::ostream& s) const {
auto fields = fields_.GetFieldsWithoutTypes({
BodyField::kFieldType,
- CountField::kFieldType,
PaddingField::kFieldType,
ReservedField::kFieldType,
FixedScalarField::kFieldType,
int size = 0;
auto fields = fields_.GetFieldsWithoutTypes({
BodyField::kFieldType,
- CountField::kFieldType,
});
for (int i = 0; i < fields.size(); i++) {
size += fields[i]->GetSize().bits();
s << "})}\n";
// write_to function
- s << "fn write_to(&self, buffer: &mut BytesMut) {";
+ s << "fn write_to(&self, buffer: &mut [u8]) {";
GenRustWriteToFields(s);
s << "}\n";
Some(acl) = consume(&raw_hal.acl_rx) => {
acl_up_tx.send(acl.clone()).await.unwrap();
logger.log(Type::Acl, Direction::Up, acl.to_bytes()).await;
- }
+ },
+ else => break,
}
}
});