Explorar o código

Updated PHP generator to output raw binary strings instead of requiring hex2bin() at runtime.

Joshua Haberman %!s(int64=5) %!d(string=hai) anos
pai
achega
2187eb0448
Modificáronse 1 ficheiros con 18 adicións e 5 borrados
  1. 18 5
      src/google/protobuf/compiler/php/php_generator.cc

+ 18 - 5
src/google/protobuf/compiler/php/php_generator.cc

@@ -999,16 +999,29 @@ void GenerateAddFileToPool(
       string files_data;
       string files_data;
       files.SerializeToString(&files_data);
       files.SerializeToString(&files_data);
 
 
-      printer->Print("$pool->internalAddGeneratedFile(hex2bin(\n");
+      printer->Print("$pool->internalAddGeneratedFile(\n");
       Indent(printer);
       Indent(printer);
+      printer->Print("'");
+
+      for (auto ch : files_data) {
+        switch (ch) {
+          case '\\':
+            printer->Print(R"(\\)");
+            break;
+          case '\'':
+            printer->Print(R"(\')");
+            break;
+          default:
+            printer->Print("^char^", "char", std::string(1, ch));
+            break;
+        }
+      }
 
 
-      printer->Print(
-          "\"^data^\"\n",
-          "data", BinaryToHex(files_data));
+      printer->Print("'\n");
 
 
       Outdent(printer);
       Outdent(printer);
       printer->Print(
       printer->Print(
-          "), true);\n\n");
+          ", true);\n\n");
     }
     }
     printer->Print(
     printer->Print(
         "static::$is_initialized = true;\n");
         "static::$is_initialized = true;\n");