如何要求protoc使用值而不是指针作为Go映射的值端?
我使用的协议缓冲区定义如下:如何要求protoc使用值而不是指针作为Go映射的值端?,go,protocol-buffers,Go,Protocol Buffers,我使用的协议缓冲区定义如下: message Index { message albums { repeated string name = 1; } map<string, albums> artists_albums= 1; map<int32, albums> year_albums = 2; } type Index struct { ArtistsAlbums map[string]*Index
message Index {
message albums {
repeated string name = 1;
}
map<string, albums> artists_albums= 1;
map<int32, albums> year_albums = 2;
}
type Index struct {
ArtistsAlbums map[string]*IndexAlbums
YearAlbums map[int32]*IndexAlbums
}
如何使其生成类型为IndexAlbums
而不是*IndexAlbums
的映射值?如果使用,则有一个扩展将允许此操作
map<string, albums> artists_albums = 1 [(gogoproto.nullable) = false];
map-artists\u-albums=1[(gogoproto.nullable)=false];
我不相信有什么办法
可为null,如果为false,则生成不带指针的字段(请参见下面的警告)
关于nullable的警告:根据协议
缓冲区规范,您应该能够判断字段是否为
设置或取消设置。使用选项nullable=false时,此功能将丢失,
因为将始终设置不可为空的字段。这可以被看作是一种挑战
协议缓冲区顶部的层,在编组之前和之后
所有不可为空的字段都已设置,不能取消设置