定制 thesis/protobuf-known-types 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

thesis/protobuf-known-types

Composer 安装命令:

composer require thesis/protobuf-known-types

包简介

Google protobuf known types collection.

README 文档

README

Installation

composer require thesis/protobuf-known-types

Usage

To encode or decode google.protobuf.Any type use encodeAny/decodeAny respectively.

use Google\Protobuf;
use Thesis\Protobuf\Encoder;

$any = Protobuf\encodeAny(X::class, Encoder\Builder::buildDefault());

Note that in this case, X should be autoloaded to the descriptor pool (Thesis\Protobuf\Pool\Registry) using autoload.metadata.php in composer.json or any other custom mechanism. Otherwise, an RuntimeException will be thrown.

If you strongly understand what you are doing and your types are not registered in the Pool\Registry, pass your own object type name resolver:

use Google\Protobuf;
use Thesis\Protobuf\Encoder;

$any = Protobuf\encodeAny(
    X::class,
    Encoder\Builder::buildDefault(),
    static fn(X $x) => 'x',
);

To decode google.protobuf.Any do the opposite using decodeAny:

use Google\Protobuf;
use Thesis\Protobuf\Decoder;

$x = Protobuf\decodeAny(
    new Protobuf\Any('type.googleapis.com/x', '...'),
    Decoder\Builder::buildDefault(),
);

Again, if you understand what you are doing, you can use custom class resolver:

use Google\Protobuf;
use Thesis\Protobuf\Decoder;

$x = Protobuf\decodeAny(
    new Protobuf\Any('type.googleapis.com/x', '...'),
    Decoder\Builder::buildDefault(),
    static fn(string $type) => X::class,
);

In both cases, in encodeAny and decodeAny, your resolvers may return null to fall back to default type resolution using Pool\Registry.

统计信息

  • 总下载量: 791
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 4
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固