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

Commit fdc69bfc authored by Qasim Javed's avatar Qasim Javed Committed by Zach Johnson
Browse files

rusty-gd: Write correct size and compute it once

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

Change-Id: Id2e54a7e7d98d49f0dc908e878fee8b0f58f0def
parent d4d9f061
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -1103,7 +1103,6 @@ packet SetupSynchronousConnectionStatus : CommandStatus (command_op_code = SETUP

packet AcceptSynchronousConnection : ScoConnectionCommand (op_code = ACCEPT_SYNCHRONOUS_CONNECTION) {
  bd_addr : Address,
  _reserved_ : 4,
  transmit_bandwidth : 32,
  receive_bandwidth : 32,
  max_latency : 16, // 0-3 reserved, 0xFFFF = don't care
+6 −5
Original line number Diff line number Diff line
@@ -873,9 +873,12 @@ void PacketDef::GenRustStructSizeField(std::ostream& s) const {
      CountField::kFieldType,
  });
  for (int i = 0; i < fields.size(); i++) {
    size += fields[i]->GetSize().bytes();
    size += fields[i]->GetSize().bits();
  }
  s << size;
  if (size % 8 != 0) {
    ERROR() << "Packet size is not a multiple of 8!\n";
  }
  s << size / 8;
}

void PacketDef::GenRustStructImpls(std::ostream& s) const {
@@ -996,9 +999,6 @@ void PacketDef::GenRustStructImpls(std::ostream& s) const {

  // write_to function
  s << "fn write_to(&self, buffer: &mut BytesMut) {";
  if (fields.size() > 0) {
    s << " buffer.resize(buffer.len() + self.get_total_size(), 0);";
  }

  fields = fields_.GetFieldsWithoutTypes({
      BodyField::kFieldType,
@@ -1069,6 +1069,7 @@ void PacketDef::GenRustAccessStructImpls(std::ostream& s) const {

  s << "fn to_bytes(self) -> Bytes {";
  s << " let mut buffer = BytesMut::new();";
  s << " buffer.resize(self." << root_accessor << ".get_total_size(), 0);";
  s << " self." << root_accessor << ".write_to(&mut buffer);";
  s << " buffer.freeze()";
  s << "}\n";