Skip to content

proto: support looking up by package #623

Closed
@jmillikin-stripe

Description

@jmillikin-stripe

The proto.MessageType and proto.GetProperties functions can, together, be used to introspect the fields available to a protobuf message type identified by name. This request is for corresponding functionality that operates at the level of protobuf packages.

syntax = "proto3";
package k8s.io.some.package;

message SomeMessage { ... }
message OtherMessage { ... }

The API doesn't need to be very complex, just enough to figure out which messages are available:

type Package struct {
  Name string // "k8s.io.some.package"
}
func (*Package) MessageTypes() []reflect.Type

// []string{"k8s.io.some.package.SomeMessage", "k8s.io.some.package.OtherMessage"}
func (*Package) MessageNames() []string

Use case: I want to add type safety to an existing protobuf-compatible config system. The user-visible behavior and error messages will be much more pleasant if the code can introspect the set of messages available to a named Protobuf package.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions