第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Protobuf/Go 無(wú)法在數(shù)組或切片文字中使用文字 * (type *) 作為類型 *

Protobuf/Go 無(wú)法在數(shù)組或切片文字中使用文字 * (type *) 作為類型 *

Go
富國(guó)滬深 2023-08-21 14:22:43
我生成的原型文件中有一個(gè)結(jié)構(gòu),如下所示(簡(jiǎn)化):type Record struct {    Field1           int64  `protobuf:"varint,1,opt,name=field1,proto3" json:"field1,omitempty"`    Field2           []byte `protobuf:"bytes,2,opt,name=field2,proto3" json:"field2,omitempty"`}我試圖在我的 Go 文件中調(diào)用它func foo(c messagepb.MessageServiceClient){    fmt.Println("Starting to send message...")    msgs := []*messagepb.MessageRequest{        recordpb.Record{ //error msg here            Field1:             1,            Field2:             []byte{byte('a')},        }    }    ...}但我在 recordpb.Record 行收到此錯(cuò)誤:cannot use recordpb.Record literal (type recordpb.Record) as type *messagepb.MessageRequest in array or slice literal如果有幫助,這是我的messagepb:message.protomessage MessageRequest { recordpb.Record records = 1; }message.pb.gotype MessageRequest struct {    Record               *recordpb.Record `protobuf:"bytes,1,opt,name=record,proto3" json:"record,omitempty"`}我找不到任何有用的信息來(lái)解釋為什么會(huì)發(fā)生這種情況......有什么想法嗎?
查看完整描述

1 回答

?
阿波羅的戰(zhàn)車

TA貢獻(xiàn)1862條經(jīng)驗(yàn) 獲得超6個(gè)贊

看起來(lái)您正在創(chuàng)建一個(gè)切片[]*messagepb.MessageRequest,然后recordpb.Record向其中添加一個(gè)。recordpb.Record與 不是同一類型*messagepb.MessageRequest。


鑒于這種類型


type MessageRequest struct {

? ? Record *recordpb.Record `protobuf:"bytes,1,opt,name=record,proto3" json:"record,omitempty"`

}

看起來(lái)你的msgsvar 應(yīng)該是


msgs := []*messagepb.MessageRequest{

? ? {

? ? ? ? Record: &recordpb.Record{

? ? ? ? ? ? Field1: 1,

? ? ? ? ? ? Field2: []byte{byte('a')},

? ? ? ? },

? ? },

}


查看完整回答
反對(duì) 回復(fù) 2023-08-21
  • 1 回答
  • 0 關(guān)注
  • 152 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)