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

Commit 69d56395 authored by Qasim Javed's avatar Qasim Javed
Browse files

rusty-gd: Update new constructor and add parse constructor.

Bug: 171749953
Tag: #gd-refactor
Test: gd/cert/run --rhost SimpleHalTest
Change-Id: I7fe4a9eef6ca37a2a4428bd7439398fc46744db0
parent 832a3bae
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -468,6 +468,12 @@ rust_library {
    srcs: ["rust/packets/lib.rs", ":BluetoothGeneratedPackets_rust"],
    edition: "2018",
    host_supported: true,
    proc_macros: ["libnum_derive"],
    rustlibs: [
        "libbytes",
        "libnum_traits",
        "libthiserror",
    ],
}

// Generates binary schema data to be bundled and source file generated
+1 −0
Original line number Diff line number Diff line
@@ -61,6 +61,7 @@ void EnumGen::GenLogging(std::ostream& stream) {
}

void EnumGen::GenRustDef(std::ostream& stream) {
  stream << "#[derive(FromPrimitive, ToPrimitive)]\n";
  stream << "pub enum " << e_.name_ << " {";
  for (const auto& pair : e_.constants_) {
    stream << util::ConstantCaseToCamelCase(pair.second) << " = 0x" << std::hex << pair.first << std::dec << ",";
+6 −0
Original line number Diff line number Diff line
@@ -199,3 +199,9 @@ void ArrayField::GenStringRepresentation(std::ostream& s, std::string accessor)
std::string ArrayField::GetRustDataType() const {
  return "[" + element_field_->GetRustDataType() + "; " + std::to_string(array_size_) + "]";
}

void ArrayField::GenRustGetter(std::ostream& s, Size start_offset, Size) const {
  s << "let " << GetName() << " = ";
  s << "bytes[" << start_offset.bytes() << "..";
  s << start_offset.bytes() + GetSize().bytes() << "].try_into().unwrap();";
}
+2 −0
Original line number Diff line number Diff line
@@ -66,6 +66,8 @@ class ArrayField : public PacketField {

  virtual std::string GetRustDataType() const override;

  void GenRustGetter(std::ostream& s, Size start_offset, Size end_offset) const override;

  const std::string name_;

  const PacketField* element_field_{nullptr};
+3 −0
Original line number Diff line number Diff line
@@ -79,3 +79,6 @@ void BodyField::GenStringRepresentation(std::ostream& s, std::string accessor) c
std::string BodyField::GetRustDataType() const {
  return GetDataType();
}

void BodyField::GenRustGetter(std::ostream&, Size, Size) const {
}
Loading