OSDN Git Service

PDL Pybind: Add _reparsed struct
authorMyles Watson <mylesgw@google.com>
Fri, 21 Feb 2020 23:03:14 +0000 (15:03 -0800)
committerMyles Watson <mylesgw@google.com>
Mon, 24 Feb 2020 22:35:27 +0000 (14:35 -0800)
Bug: 149936691
Test: ./cert/run_cert_facade_only.sh
Change-Id: Ifd35c891d196ae98904718fbb37f8d9b3c2eb96f

gd/packet/parser/packet_def.cc

index c2e8ac0..c37b63b 100644 (file)
@@ -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";
       }