How to model protobuf proto file

36 views
Skip to first unread message

Novice User

unread,
Aug 27, 2020, 9:16:37 PM8/27/20
to Protocol Buffers
My application has various clients (say for example Client1, Client 2, Client3 ....and so on). Clients share some generic properties and has some unique data.

In my .proto file I want to model this kind of behavior. I came up with :

message MyClientsData { 
  BaseClientData baseData; 
  Client1SpecificData client1; 
  Client2SpecificData client2;
... and so forth... 
}

BaseClientData is the common data across all clients.

This works for simple use case when number of clients are very limited, but becomes hard to read if it grows. Is there some good practice on how to handle this kind of situation when there are unique data across different deserialization request?

Adam Cozzette

unread,
Aug 28, 2020, 11:53:31 AM8/28/20
to Novice User, Protocol Buffers
If you're using proto2 then you can use extensions to allow clients to extend the base message with their own fields. The one caveat is that you have to figure out a scheme to ensure that each client chooses a unique extension number.

--
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/1e6bc232-3271-4752-b48e-46cef09ae14en%40googlegroups.com.

Novice User

unread,
Aug 28, 2020, 12:06:35 PM8/28/20
to Protocol Buffers
Thanks, but i am using proto3.
Reply all
Reply to author
Forward
0 new messages