Home  >  Q&A  >  body text

Generate Brocken metadata classes on alpine Docker image via protobuf

A while ago I used an ubuntu image to generate PHP files via protoc lib and it generated some metadata classes containing normal hashes used by protobuf. It is generated as follows:

namespace MyApp\ProtobufMetadata\Schema\v1;

class Request
{
    public static $is_initialized = false;

    public static function initOnce() {
        $pool = \Google\Protobuf\Internal\DescriptorPool::getGeneratedPool();

        if (static::$is_initialized == true) {
          return;
        }
        $pool->internalAddGeneratedFile(hex2bin(
            "0acd010a236170692f636174616c6f672f736368656d612f76312f726571756573742e70726f746f121d6170692e636174616c6f672e736368656d612e76312e72657175657374221d0a0a47657452657175657374120f0a0776657273696f6e18012001280d4260ca022d4350515c5368617265645c53657276696365735c436174616c6f675c536368656d615c76315c52657175657374e2022d4350515c5368617265645c50726f746f6275664d657461646174615c436174616c6f675c536368656d615c7631620670726f746f33"
        ), true);

        static::$is_initialized = true;
    }
}

But now I need to use alpine usage. I created the Dockerfile by installing protobuf from github:

ENV PROTOBUF_VERSION 3.19.4
ENV PROTOBUF_URL https://github.com/google/protobuf/releases/download/v"$PROTOBUF_VERSION"/protobuf-cpp-"$PROTOBUF_VERSION".zip
RUN curl -L -o protobuf.zip "$PROTOBUF_URL"
RUN unzip protobuf.zip && cd protobuf-"$PROTOBUF_VERSION" && ./configure && make -j$(nproc) && make install

RUN cd .. && rm protobuf.zip

But after this, when I generate new classes, it generates metadata classes with some weird views:

<?php
# Generated by the protocol buffer compiler.  DO NOT EDIT!
# source: api/schema/v1/request.proto

namespace MyApp\ProtobufMetadata\Schema\v1;

class Request
{
    public static $is_initialized = false;

    public static function initOnce() {
        $pool = \Google\Protobuf\Internal\DescriptorPool::getGeneratedPool();

        if (static::$is_initialized == true) {
          return;
        }
        $pool->internalAddGeneratedFile(
            '
�
#api/schema/v1/request.protoapi.schema.v1.request"

GetRequest
version (
B`�-MyApp\Services\Catalog\Schema\v1\Request�-MyApp\ProtobufMetadata\Catalog\Schema\v1bproto3'
        , true);

        static::$is_initialized = true;
    }
}

Has anyone encountered similar problems? Is there any way to fix the lib installation or some compilation to return pretty code using hex2bin?

Compile by using RoadRunner's command:

[ -f ./protoc-gen-php-grpc ] || ./rr get-protoc-binary
      && chmod +x ./protoc-gen-php-grpc
      && ./rr compile-proto-files"

The host system is MacOS

P粉824889650P粉824889650268 days ago361

reply all(1)I'll reply

  • P粉018653751

    P粉0186537512024-02-18 14:38:35

    This is done on purpose, your Alpine may just be running a newer version of the protocol.

    The following is the PR to delete the hex2bin call: https://github.com/protocolbuffers /protobuf/pull/8006

    reply
    0
  • Cancelreply