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

Commit 48c2f68e authored by Zach Johnson's avatar Zach Johnson Committed by Gerrit Code Review
Browse files

Merge "rusty-gd: Fix offsets for scalar fields."

parents 03186560 42ecc03d
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -156,13 +156,16 @@ int ScalarField::GetRustBitOffset(

void ScalarField::GenRustGetter(std::ostream& s, Size start_offset, Size end_offset) const {
  Size size = GetSize();

  int num_leading_bits = GetRustBitOffset(s, start_offset, end_offset, GetSize());

  s << "let " << GetName() << " = ";
  if (num_leading_bits == 0) {
    s << GetRustDataType() << "::from_le_bytes(bytes[" << start_offset.bytes() << "..";
  s << start_offset.bytes() + GetSize().bytes() << "].try_into().unwrap());";

  if (num_leading_bits != 0) {
    s << start_offset.bytes() + size.bytes() << "].try_into().unwrap());";
  } else {
    s << GetRustDataType() << "::from_le_bytes(bytes[" << start_offset.bytes() - 1 << "..";
    s << start_offset.bytes() + size.bytes() - 1 << "].try_into().unwrap());";
    s << "let " << GetName() << " = " << GetName() << " >> " << num_leading_bits << ";";
  }