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

Commit 35ba87d7 authored by Zach Johnson's avatar Zach Johnson Committed by Automerger Merge Worker
Browse files

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

Original change: https://android-review.googlesource.com/c/platform/system/bt/+/1526341

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I5e8a9f2e2d60bfffc359997c59cb52b49d4c0596
parents 81775c9e 48c2f68e
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 << ";";
  }