首頁  >  問答  >  主體

透過 protobuf 在 alpine Docker 映像上產生 Brocken 元資料類

不久前,我使用 ubuntu 映像透過 protoc lib 產生 PHP 文件,它產生一些元資料類,其中包含 protobuf 使用的正常雜湊值。 它的生成方式如下:

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;
    }
}

但現在我需要使用高山用法。 我透過從 github 安裝 protobuf 建立了 Dockerfile:

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

但是在此之後,當我產生新類別時,它會以一些奇怪的視圖產生元資料類別:

<?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;
    }
}

有人遇到類似的問題嗎? 有什麼方法可以修復 lib 安裝或某些編譯以使用 hex2bin 使用返回漂亮的程式碼嗎?

透過使用 RoadRunner 的指令進行編譯:

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

主機系統為MacOS

P粉824889650P粉824889650219 天前324

全部回覆(1)我來回復

  • P粉018653751

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

    這是故意完成的,您的 Alpine 可能只是運行更新版本的協定。

    以下是刪除 hex2bin 呼叫的 PR:https://github.com/protocolbuffers /protobuf/pull/8006

    回覆
    0
  • 取消回覆