Protobuf supports optional fields proto documentation <https://protobuf.dev/programming-guides/proto3/#field-labels>. Since one is a subset of the other, this would work great for you. If you want to make it easy to identify the type of product, you can have a field that represents the type as either a string or an enum. Protobuf also supports repeated values and nested types so while the XML may be large, it can be compressed a lot when sent as a proto.
On Mon, Dec 18, 2023 at 11:21 AM Juan Carlos Parra Morillo < jc.parr...@gmail.com> wrote: > I want to develop a grPc service. I already have the input message object > defined but not the response object. > > The issue is that this new grPc service, once it receives a request, makes > a call to another service that returns an XML like the one I show > > more below in the example > > <products> > > <product id="account"> > > <field name="balance" value="123"> > > <field name="currency" value="USD"> > > <field name="product name" value="savings"> > > <field name="number" value="123456"> > > </product> > > <product id="account"> > > <field name="balance" value="123"> > > <field name="currency" value="USD"> > > <field name="product name" value="savings"> > > <field name="number" value="14533456"> > > </product> > > <product id="loan"> > > <field name="balance" value="123"> > > <field name="currency" value="USD"> > > <field name="product name" value="savings"> > > <field name="payment date" value="12/17/2023"> > > <field name="quota" value="150"> > > <field name="number" value="1455454"> > > </product> > > </products> > > As you can see, the fields of each product may vary. There are more > products that I do not show in the example that also > > They can have more fields within the product tag > > I would like to know what is the best way to represent the response object > for this. I have two options > > 1. Through arrangements that represent each product to me. Example > > message products{ > > ACCOUNTS account=1; > > LOANS loans=2; > > ..... > > } > > message ACCOUNT{ > > String balance=1; > > String currency=2; > > String product_name=3; > > String number=4; > > } > > message ACCOUNT{ > > String balance=1; > > String currency=2; > > String product_name=3; > > String number=4; > > String payment_date=5; > > String quota=6; > > } > > 2. With a data type that saves a meta-data like google.protobuf.Any > > message products{ > > google.protobuf.Any XML_Products=1; > > } > > Please guide me on what would be the most optimal way to return the > message. Option 1 causes me a > > a little afraid of the performance it could have since the service must go > through the response XML > > and then identify what type of product it is to add it to the array of its > corresponding product > > and then the service that made the request to the grPc service receives > the products object as a response > > You must also go through it to create a response json. I am also concerned > about the fact that a client > > You can have several products of different types so the products XML can > become very large. > > What is your opinion or if there is a better way to do it please let me > know...thank you. > > -- > You received this message because you are subscribed to the Google Groups " > grpc.io" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to grpc-io+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/grpc-io/7d20aa39-28c9-48ec-84a3-19e69fda6633n%40googlegroups.com > <https://groups.google.com/d/msgid/grpc-io/7d20aa39-28c9-48ec-84a3-19e69fda6633n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "grpc.io" group. To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/CANuT3qXGXhfiZfzVuj7k%2BfEQH-8ooAvV%3Ds8YtZgMFDjCqdmEPg%40mail.gmail.com.