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

Commit 66020b74 authored by Myles Watson's avatar Myles Watson
Browse files

PDL Pybind: Add _reparsed struct

Bug: 149936691
Test: ./cert/run_cert_facade_only.sh
Change-Id: Ifd35c891d196ae98904718fbb37f8d9b3c2eb96f
parent 84003835
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -539,17 +539,17 @@ void PacketDef::GenBuilderCreatePybind11(std::ostream& s) const {
      // Serialize each struct
      s << "auto " << param->GetName() + "_bytes = std::make_shared<std::vector<uint8_t>>();";
      s << param->GetName() + "_bytes->reserve(" << param->GetName() << "[i]->size());";
      s << "auto " << param->GetName() + "_reparsed = std::make_unique<" << struct_type << ">();";
      s << "BitInserter " << param->GetName() + "_bi(*" << param->GetName() << "_bytes);";
      s << param->GetName() << "[i]->Serialize(" << param->GetName() << "_bi);";
      // Parse it again
      s << "auto " << param->GetName() << "_view = PacketView<kLittleEndian>(" << param->GetName() << "_bytes);";
      s << "auto result = Parse" << struct_type << "(" << param->GetName() + "_view.begin());";
      s << param->GetElementField()->GetDataType() << " " << param->GetName() << "_reparsed = ";
      s << "Parse" << struct_type << "(" << param->GetName() + "_view.begin());";
      // Push it into a new container
      if (param->GetFieldType() == VectorField::kFieldType) {
        s << move_only_param_name << ".push_back(std::move(" << param->GetName() + "_reparsed));";
      } else if (param->GetFieldType() == ArrayField::kFieldType) {
        s << move_only_param_name << "[i] = " << param->GetName() << "_reparsed;";
        s << move_only_param_name << "[i] = std::move(" << param->GetName() << "_reparsed);";
      } else {
        ERROR() << param << " is not supported by Pybind11";
      }