我有以下 protobuf 消息:
syntax = "proto3";
message MyMessage {
string id = 1;
map<string, Any> attributeChanges = 2;
}
在打字稿中,我试图根据看起来像这样的打字稿映射来设置 protobuf 消息的映射条目。
type Nullable<T> = T | undefined | null;
export interface IAuditChanges {
currentValue: Nullable<string>;
previousValue: Nullable<string>;
fields?: Map<string, IAuditChanges>
}
我尝试遍历映射对象中的条目并以这种方式设置映射条目。
var attributesMap = message.getAttributechangesMap();
for (let key of Array.from(mappedChanges.keys())) {
const mapEntry: any = mappedChanges.get(key);
attributesMap.set(key, mapEntry);
}
我收到错误“TypeError:b.toArray 不是函数。” 知道如何转换/序列化/打包每个打字稿映射条目,以便将其设置在 protobuf 中吗?我在几个地方找了一些没有运气的例子。
https://developers.google.com/protocol-buffers/docs/proto3#any https://developers.google.com/protocol-buffers/docs/proto3#maps
谢谢你。