从go客户端到python服务器的Protobuff消息
我想从go客户端向python服务器发送一条消息。 我也在使用protobuff Go-side消息结构从go客户端到python服务器的Protobuff消息,python,go,protocol-buffers,Python,Go,Protocol Buffers,我想从go客户端向python服务器发送一条消息。 我也在使用protobuff Go-side消息结构 type CreateProductInfo struct { name string fruits []*Fruits } type Fruits struct { name string } 我希望在我的python服务器中得到以下响应 { name : "product_info" fruits : [ {
type CreateProductInfo struct {
name string
fruits []*Fruits
}
type Fruits struct {
name string
}
我希望在我的python服务器中得到以下响应
{
name : "product_info"
fruits : [
{
name : "Apple"
}
]
}
相反,我得到了这个
{
name : "product_info"
fruits : [
name : "Apple"
]
}
如果我正确理解了您的问题,则rpc消息传输没有问题。相反,您收到的消息类型错误。 请确保您正在以正确的格式准备protobuf消息
package main
import (
"encoding/json"
"fmt"
"os"
)
type CreateProductInfo struct {
Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
Fruits []*Fruits `protobuf:"bytes,2,opt,name=fruits" json:"fruits,omitempty"`
}
type Fruits struct {
Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
}
func main() {
productInfo := &CreateProductInfo{
Name: "product_info",
Fruits: []*Fruits{
&Fruits{
Name: "apple",
},
&Fruits{
Name: "orange",
},
&Fruits{
Name: "mango",
},
},
}
b, err := json.MarshalIndent(&productInfo, "", "\t")
if err != nil {
fmt.Println("error:", err)
}
os.Stdout.Write(b)
}
这是这样返回的
{
"name": "product_info",
"fruits": [
{
"name": "apple"
},
{
"name": "orange"
},
{
"name": "mango"
}
]
}
请出示您的原始文件