Description
I'm struggling to grok APIv2 and apologize if this is a stupid question and the wrong place to ask.
Background
I'm toying with a solution in which some client may submit requests to a (remote) server that invokes functions on the server. While the client and server may use gRPC and protobufs, the functions do not implement protobufs, may be hosted by different server runtimes but, in Go are of the type func f([]byte) ([]byte,error)
and may be invoked as result,err := host.invoke(f,params)
. The requirement will be that the incoming params will be a []interface{}
and parseable by the function. I'm thinking to envelope the functions' types as protobuf services (==functions) and messages (*Request
==params; *Response
==result
).
Implementation
protoc
generates descriptor set- descriptor set parsed into
protoregistry.Files
MessageDescriptors
gleaned fromFileDescriptors
in FilesFind*ByName
andFind*ByPath
- Marshaled into
anypb.Any
usingdynamicpb.NewMessage()
andproto.Unmarshal()
- Shipped to the server
After much reading of the Godocs and struggling to grasp the API, this appears to work.
Challenge
I'm challenged to perform the reverse.
The package structure suggests that, whereas I used protoregistry.Files
on the way in, I will use protoregistry.Types
on the way out... With anypb.Any
I should have as TypeURL
that I could FindMessageBy*
to get a MessageType
(Go type) rather than the MessageDescriptor
(protobuf).
The server is able to invoke the desired function, it is able to determine which function to invoke and the types of the request and response from the incoming request message's envelope metadata and it has a concrete anypb.Any
message corresponding to the parameters.
But, I need but don't have MessageType
to populate protoregistry.Types
IIUC MessageType
correspond to Go concrete types. I'm OK to use Golang for this implementation but I'd like the possibility that the server be implemented in e.g. Rust too. So, I think I'd prefer to have messages convey protobuf types rather than language-specific representations.
If I had `protoregistry.Types, this #1085 issue helps get me where I need to (I think).
Questions
- Is there example code for constructing
protoregistry.Types
? - Is there example code for moving to|from
anypb.Any
usingTypeURL
as the key? - If my explanation is understandable, am I on the right path?
Looking through other issues, other developers appear to be less challenged by this API than me. But assuming that I'm representative of the other half the normal distribution, please blog more describing use-cases and best-practices with this API.