我正在尝试在 JavaScript 中获取我的 Protobuf 消息类型的完全限定路径。例如,给定以下文件:status.proto
package my.messages.proto;
message Status {
string code = 1;
}
使用 protoc 编译后,我可以执行以下操作:
import { Status } from 'gen/my/messages/proto/status_pb.js';
const status = new Status();
但是,我怎样才能得到这条消息的完全限定路径呢?我想要一个字符串my.messages.proto.Status
,但我似乎找不到任何可能的 API。我基本上想要 C++ 函数的等价物message.GetDescriptor()->full_name()
。
如果我这样做console.log(status);
,我会看到打印出来的内容,例如:
my.messages.proto.Status {wrappers_: null, messageId_: undefined, arrayIndexOffset_: -1, array: Array(1), pivot_: 1.7976931348623157e+308, …}
所以,信息就在那里,但只是不知道如何访问它。这在带有 Protobuf 的 JavaScript 中是否可行?