Re: [protobuf] Can the client parse the interface and message structures of the server?

155 views
Skip to first unread message

Adam Cozzette

unread,
Dec 13, 2019, 1:55:23 PM12/13/19
to erik stroeken, Protocol Buffers
Protobuf reflection is about doing things like introspecting over the structure of a message. You could do things like recurse down from a top-level message and set every unset field to a default value for example. I'm not very familiar with C# but I guess C# reflection would let you do some of the same things. Protobuf reflection is independent of any client-server setup, so it is just about introspecting on local messages. However, with some work you could kind of make it useful in an RPC context as well. For example, the server could serialize its descriptors and send them over the wire and then the client could reflectively manipulate messages based on the server's version of the schema. The Java and C++ protobuf implementations both have a class called DynamicMessage that lets you work with a message using a schema that is known only at runtime, using reflection.

On Fri, Dec 13, 2019 at 10:15 AM erik stroeken <erik.s...@gmail.com> wrote:
This might be a dumb question but when you talk about Protobuf reflection, does that mean that the client can iterate through the interfaces and message structures of the connected client? I program C# and reflecting through the generated classes client side is already supported by C# itself so it must be that Protobuf reflection is used to analyze the server. Right?
Not that it would solve my current problem because Protobuf reflection isn't implemented in C# yet (depending on the answer it would be redundant anyway). Thanks for the answer.

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/protobuf/4531a885-b3e5-4847-8d0d-945aa72f412a%40googlegroups.com.

Nadav Samet

unread,
Dec 13, 2019, 4:24:08 PM12/13/19
to Adam Cozzette, erik stroeken, Protocol Buffers
If you are using gRPC, then it provides a way for introspecting methods and parameters for a remote server. This is a functionality that has to be enabled on the server side. See:




--
-Nadav

erik stroeken

unread,
Dec 14, 2019, 7:22:55 AM12/14/19
to Protocol Buffers
Thanks Nadav Samet
I've been trying to implement the concepts described in https://github.com/grpc/grpc/blob/master/doc/server-reflection.md and for C#: https://github.com/grpc/grpc/blob/master/doc/csharp/server_reflection.md in the implementation of ASP.NET Core. You have to somehow configure Kestrel to enable Reflection first. I just don't succeed and have to give up. Does somebody know how to enable serverside reflection in ASP.NET Core with Kestrel? Or even better has a complete working example of serverside reflection in C# ASP.NET Core?
Thanks, Erik

Marc Gravell

unread,
Dec 14, 2019, 8:10:21 AM12/14/19
to erik stroeken, Protocol Buffers
That would prpbably be a great question for James NK over on the relevant GitHub repo. IIRC the sample server includes reflection, though: https://github.com/grpc/grpc-dotnet/

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+u...@googlegroups.com.

erik stroeken

unread,
Dec 14, 2019, 1:36:51 PM12/14/19
to Protocol Buffers
Thanks Marc. The current implementation of ASP.NET Core 3.1 doesn't support the Reflection but with the NuGet of James NK I managed to list the services. I can't figure out from the example how to list methods on a service or fields in messages. Shall I ask James NK or do you know someone who can help? 
Reply all
Reply to author
Forward
0 new messages