Brocken Metadata课程通过Protobuf在高山Docker图像上

发布于 2025-02-09 07:26:02 字数 2596 浏览 2 评论 0原文

某个时候,我已经通过ProtoC Lib使用了Ubuntu Image来生成PHP文件,并生成了一些元数据类,其中Protobuf使用了正常的哈希。 它的生成SMTH类似:

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

Sometime ago I've used ubuntu image for PHP files generation via protoc lib and it generates some metadata classes with normal hashes used by protobuf.
It was generated smth like:

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've created Dockerfile with 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 generates new classes it generates metadata classes in some strange view:

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

Does anyone hit with similar problem?
Is any way to fix lib installation or some compile to return pretty code with hex2bin usage?

compilation was made via commands with RoadRunner usage:

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

Host system is MacOS

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我们只是彼此的过ke 2025-02-16 07:26:02

这是故意完成的,您的高山可能只是运行了最新版的Protoc。

这是删除Hex2bin调用的PR: httpps://gith/github.com/protocolbuffers/protobobuf/拉/8006

This was done on purpose, your Alpine is probably just running a more recent version of protoc.

Here is the PR which removed the hex2bin call: https://github.com/protocolbuffers/protobuf/pull/8006

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文