慕的地10843
这可以使用自定义编解码器来实现。自定义编解码器可以定义为type StubbedCodec struct{}func (cb StubbedCodec) Marshal(v interface{}) ([]byte, error) { return v.([]byte), nil}func (cb StubbedCodec) Unmarshal(data []byte, v interface{}) error { ba, _ := v.([]byte) for index, byte := range data { ba[index] = byte } return nil}一旦我们有了这个,我们可以将编解码器作为拨号选项传递为grpc.Dial(grpcServer, grpc.WithInsecure(), grpc.WithBlock(), grpc.WithDefaultCallOptions(grpc.ForceCodec(StubbedCodec{})))这将强制 grpc 使用您的编解码器,它基本上什么都不做(如上定义)。