From 2187eb0448fc101490b0fc9964e4e0b6f7b66213 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Wed, 14 Oct 2020 21:23:29 -0700 Subject: [PATCH] Updated PHP generator to output raw binary strings instead of requiring hex2bin() at runtime. --- .../protobuf/compiler/php/php_generator.cc | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/google/protobuf/compiler/php/php_generator.cc b/src/google/protobuf/compiler/php/php_generator.cc index 365cb64e53..d96bdd5545 100644 --- a/src/google/protobuf/compiler/php/php_generator.cc +++ b/src/google/protobuf/compiler/php/php_generator.cc @@ -999,16 +999,29 @@ void GenerateAddFileToPool( string files_data; files.SerializeToString(&files_data); - printer->Print("$pool->internalAddGeneratedFile(hex2bin(\n"); + printer->Print("$pool->internalAddGeneratedFile(\n"); 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); printer->Print( - "), true);\n\n"); + ", true);\n\n"); } printer->Print( "static::$is_initialized = true;\n");