如何解码被拦截的gRPC请求/响应,以查看golang中已发送/已接收的protobuf消息?

I am intercepting the raw gRPC requests/responses going across a UNIX socket (the containerd socket using the cri-api, using eBPF to perform the interception) and I want to work out what is being sent/received. I have access to the .proto file used to generate the gRPC interface using the gRPC plugin so this should be possible to do but I'm not sure how to start as I am not part the gRPC connection.

How can I go about doing this in golang?

  1. Use GRPC basic support

https://godoc.org/google.golang.org/grpc#StreamInterceptor

https://godoc.org/google.golang.org/grpc#UnaryInterceptor

  1. Use GRPC middleware

https://github.com/grpc-ecosystem/go-grpc-middleware

  1. The simple and stupid way
// GRPC handler
func (x *M) GRPCHanler(ctx context.Context, req *REQ) (rsp *RSP, eRR error) {
    rsp = new(RSP)
    method = "GRPCHanler"
    log.Infof("GRPC-%s Request:%+v", method, req)
    defer func() {
        log.Infof("GRPC-%s Response:%+v", method, rsp)
        if eRR != nil {
            log.Errorf("GRPC-%s Error:%v", method,eRR)
        }
        // eRR = nil
    }
    // handler
}