Skip to content

Instantly share code, notes, and snippets.

@jasonkeene
Created April 17, 2018 01:32
Show Gist options
  • Save jasonkeene/1e153e4c4c387db44891150c72c5ea58 to your computer and use it in GitHub Desktop.
Save jasonkeene/1e153e4c4c387db44891150c72c5ea58 to your computer and use it in GitHub Desktop.
An Exercise in dumping the file descriptor of the grpc-go helloworld example
package main
import (
"bytes"
"compress/gzip"
"io/ioutil"
"log"
"github.com/davecgh/go-spew/spew"
"github.com/golang/protobuf/proto"
_ "google.golang.org/grpc/examples/helloworld/helloworld"
"github.com/golang/protobuf/protoc-gen-go/descriptor"
)
func main() {
c := proto.FileDescriptor("helloworld.proto")
r, err := gzip.NewReader(bytes.NewReader(c))
if err != nil {
log.Fatal(err)
}
u, err := ioutil.ReadAll(r)
if err != nil {
log.Fatal(err)
}
var d descriptor.FileDescriptorProto
err = proto.Unmarshal(u, &d)
if err != nil {
log.Fatal(err)
}
spew.Dump(d)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment