理想情況下,以下 RPC 應(yīng)該接收消息并編組為 JSON。但是,遇到以下錯誤:ERROR: 2018/08/12 13:43:07 grpc: server failed to encode response: rpc error: code = Internal desc = grpc: error while marshaling: proto: Marshal called with nilfunc (s *beaconServer) Transmit(ctx context.Context, batch *pb.Batch) (*pb.Empty, error) { var empty *pb.Empty var messageJSON bytes.Buffer marshaler := &jsonpb.Marshaler{ OrigName: true, } err := marshaler.Marshal(&messageJSON, batch) if err != nil { return empty, err } log.Println(string(messageJSON.Bytes())) return empty, nil}.. 回報2018/08/12 14:24:09 beacon.go:34: {"stream_id":"abc11","event_type":"e","events":[{"file_path":"/tmp/python.py","location":"256","count":"30"},{"file_path":"/tmp/temp.py","location":"253","count":"305"}],"start_time":"2038-01-19 03:14:07","end_time":"2038-01-19 03:14:27"}ERROR: 2018/08/12 14:24:09 grpc: server failed to encode response: rpc error: code = Internal desc = grpc: error while marshaling: proto: Marshal called with nil
1 回答

千萬里不及你
TA貢獻(xiàn)1784條經(jīng)驗 獲得超9個贊
該錯誤可能不是由此代碼塊中的編組器引起的
當(dāng)您這樣做時,var empty *pb.Empty
您正在創(chuàng)建一個未初始化的變量*pb.Empty
,即nil
.?很可能是上游試圖整理它的東西empty
導(dǎo)致了錯誤。
如果你想初始化為空,那么你應(yīng)該做return new(pb.Empty), nil
- 1 回答
- 0 關(guān)注
- 961 瀏覽
添加回答
舉報
0/150
提交
取消