如何在 nodejs 中动态创建 gRPC 原型模式?

How to dynamically create gRPC proto schema in nodejs?

加载 .proto 文件可以通过提供文件路径来完成 (PROTO_PATH)

var packageDefinition = protoLoader.loadSync(
    PROTO_PATH,
    {keepCase: true,
     longs: String,
     enums: String,
     defaults: true,
     oneofs: true
    });

如何在 node.js 中动态执行此操作? 我想在 运行 时间构建原型模式(数据类型和函数)。

@grpc/proto-loader库是专门用来加载.proto文件的,不支持在运行时动态构建protobuf消息或服务类型。

但是,Protobuf.js 确实支持在运行时构造 protobuf 反射类型(see its README for details), and it is possible to use that to construct a PackageDefinition object explicitly using that, and then load that into the grpc library. The type definitions in this document 可能更清楚。