{"action":"created","issue":{"url":"https://api.github.com/repos/golang/protobuf/issues/194","repository_url":"https://api.github.com/repos/golang/protobuf","labels_url":"https://api.github.com/repos/golang/protobuf/issues/194/labels{/name}","comments_url":"https://api.github.com/repos/golang/protobuf/issues/194/comments","events_url":"https://api.github.com/repos/golang/protobuf/issues/194/events","html_url":"https://github.com/golang/protobuf/issues/194","id":160627748,"number":194,"title":"Expose registered message types on generated code","user":{"login":"thinxer","id":66073,"avatar_url":"https://avatars.githubusercontent.com/u/66073?v=3","gravatar_id":"","url":"https://api.github.com/users/thinxer","html_url":"https://github.com/thinxer","followers_url":"https://api.github.com/users/thinxer/followers","following_url":"https://api.github.com/users/thinxer/following{/other_user}","gists_url":"https://api.github.com/users/thinxer/gists{/gist_id}","starred_url":"https://api.github.com/users/thinxer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thinxer/subscriptions","organizations_url":"https://api.github.com/users/thinxer/orgs","repos_url":"https://api.github.com/users/thinxer/repos","events_url":"https://api.github.com/users/thinxer/events{/privacy}","received_events_url":"https://api.github.com/users/thinxer/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"zombiezen","id":181535,"avatar_url":"https://avatars.githubusercontent.com/u/181535?v=3","gravatar_id":"","url":"https://api.github.com/users/zombiezen","html_url":"https://github.com/zombiezen","followers_url":"https://api.github.com/users/zombiezen/followers","following_url":"https://api.github.com/users/zombiezen/following{/other_user}","gists_url":"https://api.github.com/users/zombiezen/gists{/gist_id}","starred_url":"https://api.github.com/users/zombiezen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zombiezen/subscriptions","organizations_url":"https://api.github.com/users/zombiezen/orgs","repos_url":"https://api.github.com/users/zombiezen/repos","events_url":"https://api.github.com/users/zombiezen/events{/privacy}","received_events_url":"https://api.github.com/users/zombiezen/received_events","type":"User","site_admin":false},"assignees":[{"login":"zombiezen","id":181535,"avatar_url":"https://avatars.githubusercontent.com/u/181535?v=3","gravatar_id":"","url":"https://api.github.com/users/zombiezen","html_url":"https://github.com/zombiezen","followers_url":"https://api.github.com/users/zombiezen/followers","following_url":"https://api.github.com/users/zombiezen/following{/other_user}","gists_url":"https://api.github.com/users/zombiezen/gists{/gist_id}","starred_url":"https://api.github.com/users/zombiezen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zombiezen/subscriptions","organizations_url":"https://api.github.com/users/zombiezen/orgs","repos_url":"https://api.github.com/users/zombiezen/repos","events_url":"https://api.github.com/users/zombiezen/events{/privacy}","received_events_url":"https://api.github.com/users/zombiezen/received_events","type":"User","site_admin":false}],"milestone":null,"comments":5,"created_at":"2016-06-16T10:22:17Z","updated_at":"2016-07-27T17:52:25Z","closed_at":null,"body":"Currently generated code registers with `proto.RegisterType` and we can retrieve the type based on a string name.  However, it is not possible to list all registered types.  The types map is there but not exposed.\r\n\r\nI'd suggest\r\n\r\n1. Add `ListTypes()` and `ListEnums()`  to `golang/protobuf/proto` to get all the type names.\r\n2. Or add the above methods to the generated package to list local types."},"comment":{"url":"https://api.github.com/repos/golang/protobuf/issues/comments/235665685","html_url":"https://github.com/golang/protobuf/issues/194#issuecomment-235665685","issue_url":"https://api.github.com/repos/golang/protobuf/issues/194","id":235665685,"user":{"login":"zombiezen","id":181535,"avatar_url":"https://avatars.githubusercontent.com/u/181535?v=3","gravatar_id":"","url":"https://api.github.com/users/zombiezen","html_url":"https://github.com/zombiezen","followers_url":"https://api.github.com/users/zombiezen/followers","following_url":"https://api.github.com/users/zombiezen/following{/other_user}","gists_url":"https://api.github.com/users/zombiezen/gists{/gist_id}","starred_url":"https://api.github.com/users/zombiezen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zombiezen/subscriptions","organizations_url":"https://api.github.com/users/zombiezen/orgs","repos_url":"https://api.github.com/users/zombiezen/repos","events_url":"https://api.github.com/users/zombiezen/events{/privacy}","received_events_url":"https://api.github.com/users/zombiezen/received_events","type":"User","site_admin":false},"created_at":"2016-07-27T17:52:25Z","updated_at":"2016-07-27T17:52:25Z","body":"You don't need to hook into `protoc-gen-go`.  gRPC uses this to add extra metadata, but if you just need a list of filenames, you can set up a registry yourself.  Slightly tweaking the code from gRPC:\r\n\r\n```go\r\nvar filenames map[string]bool\r\n\r\nfunc register(msg proto.Message) {\r\n  d := msg.(interface {\r\n    Descriptor() ([]byte, []int)\r\n  })\r\n  desc, _ := d.Descriptor()\r\n  fd := new(descriptor.FileDescriptorProto)\r\n  if err := proto.Unmarshal(decompress(desc), fd); err != nil {\r\n    panic(err)\r\n  }\r\n  filenames[fd.GetName()] = true\r\n}\r\n\r\nfunc init() {\r\n  register((*mypb.Message)(nil))\r\n}\r\n\r\n// later in app...\r\nfor _, fname := range filenames {\r\n  fdBytes := proto.FileDescriptor(fname)\r\n  // ...\r\n}\r\n```\r\n\r\nI realize that exposing the map is not a difficult change, but it does lock the package's implementation into always using a map as the data structure.  The file descriptor map is lists all of the file descriptors present at link-time.  The reason we generally don't export this is because that list can change depending on what protos your dependencies bring in, which can cause action-at-a-distance.  The benefit of the more explicit registry I propose in that code snippet is that it ensures that all of the types and files that you expect are linked in, because you have a reference in code, and doesn't bring in additional types."}}
{"actor":{"display_login":"zombiezen"}}