Skip to content

Commit

Permalink
Merge pull request #294 from tristanang/master
Browse files Browse the repository at this point in the history
Add support for passing Protoset Binary as runner option
  • Loading branch information
bojand committed Aug 4, 2021
2 parents da65756 + 73fc140 commit 5713414
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
16 changes: 13 additions & 3 deletions protodesc/protodesc.go
Expand Up @@ -41,17 +41,27 @@ func GetMethodDescFromProto(call, proto string, imports []string) (*desc.MethodD
return getMethodDesc(call, files)
}

// GetMethodDescFromProtoSet gets method descritor for the given call symbol from protoset file given my path protoset
// GetMethodDescFromProtoSet gets method descriptor for the given call symbol from protoset file given my path protoset
func GetMethodDescFromProtoSet(call, protoset string) (*desc.MethodDescriptor, error) {
b, err := ioutil.ReadFile(protoset)
if err != nil {
return nil, fmt.Errorf("could not load protoset file %q: %v", protoset, err)
}

res, err := GetMethodDescFromProtoSetBinary(call, b)
if err != nil && strings.Contains(err.Error(), "could not parse contents of protoset binary") {
return nil, fmt.Errorf("could not parse contents of protoset file %q: %v", protoset, err)
}

return res, err
}

// GetMethodDescFromProtoSetBinary gets method descriptor for the given call symbol from protoset binary
func GetMethodDescFromProtoSetBinary(call string, b []byte) (*desc.MethodDescriptor, error) {
var fds descriptor.FileDescriptorSet
err = proto.Unmarshal(b, &fds)
err := proto.Unmarshal(b, &fds)
if err != nil {
return nil, fmt.Errorf("could not parse contents of protoset file %q: %v", protoset, err)
return nil, fmt.Errorf("could not parse contents of protoset binary: %v", err)
}

unresolved := map[string]*descriptor.FileDescriptorProto{}
Expand Down
9 changes: 9 additions & 0 deletions runner/options.go
Expand Up @@ -43,6 +43,7 @@ type RunConfig struct {
proto string
importPaths []string
protoset string
protosetBinary []byte
enableCompression bool

// security settings
Expand Down Expand Up @@ -716,6 +717,14 @@ func WithProtoset(protoset string) Option {
}
}

func WithProtosetBinary(b []byte) Option {
return func(o *RunConfig) error {
o.protosetBinary = b

return nil
}
}

// WithStreamInterval sets the stream interval
func WithStreamInterval(d time.Duration) Option {
return func(o *RunConfig) error {
Expand Down
2 changes: 2 additions & 0 deletions runner/requester.go
Expand Up @@ -78,6 +78,8 @@ func NewRequester(c *RunConfig) (*Requester, error) {
mtd, err = protodesc.GetMethodDescFromProto(c.call, c.proto, c.importPaths)
} else if c.protoset != "" {
mtd, err = protodesc.GetMethodDescFromProtoSet(c.call, c.protoset)
} else if c.protosetBinary != nil {
mtd, err = protodesc.GetMethodDescFromProtoSetBinary(c.call, c.protosetBinary)
} else {
// use reflection to get method descriptor
var cc *grpc.ClientConn
Expand Down

0 comments on commit 5713414

Please sign in to comment.