热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

如何在protobuff中获取具体类型的切片(不是指针)

如何解决《如何在protobuff中获取具体类型的切片(不是指针)》经验,为你挑选了1个好方法。

对于原型:

syntax = "proto3";
package messagepb;

import "github.com/gogo/protobuf/gogoproto/gogo.proto";

option (gogoproto.marshaler_all) = true;
option (gogoproto.sizer_all) = true;
option (gogoproto.unmarshaler_all) = true;
option (gogoproto.goproto_getters_all) = false;

service KV {
  // Put puts the given key into the store.
  // A put request increases the revision of the store,
  // and generates one event in the event history.
  rpc Put(PutRequest) returns (PutResponse) {}
}

message PutRequest {
  bytes key = 1;
  bytes value = 2;
}

message ResponseHeader {
  repeated PutRequest l = 3;
}

我得到以下原型结构:

type ResponseHeader struct {
    L     []*PutRequest `protobuf:"bytes,3,rep,name=l" json:"l,omitempty"`
}

但是我如何遵循protostruct:

type ResponseHeader struct {
    L     []PutRequest `protobuf:"bytes,3,rep,name=l" json:"l,omitempty"`
}

那就是我想拥有数据局部性(因此有连续数据的切片,而不是散布东西的指针)



1> nmiculinic..:

我需要使用:[(gogoproto.nullable)= false]如下所示:

repeated PutRequest l = 3 [(gogoproto.nullable) = false];

并得到:

    L     []PutRequest `protobuf:"bytes,3,rep,name=l" json:"l"`


是的,我问了一个问题,然后几个小时后找到了解决方案
推荐阅读
author-avatar
Ruby
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有