Split 1 protobuf into N protobufs

33 views
Skip to first unread message

Joan Balagueró

unread,
Feb 29, 2024, 12:06:57 PMFeb 29
to Protocol Buffers
Hello,

I'm new in protobuf, and I was wondering if the following is possible. I have a protobuf response coming from an api that contains a list of hotels. If we imagine this response  in xml, it would be something as follows:
<response><hotels><hotel id="1">H1</hotel><hotel id="2">H2</hotel></hotels></response>

I need to split this into 2 pieces:
<response><hotels><hotel id="1">H1</hotel></hotels></response>
<response><hotels><hotel id="2">H2</hotel></hotels></response>

Is it possible to do this if the response is protobuf? Can I put "marks" on this protobuf in any way? Something like using "*" below:
<response><hotels>*<hotel id="1">H1</hotel>*<hotel id="2">H2</hotel>*</hotels></response>

So I can know where a hotel starts and ends just checking this mark or field, and then be able to substract portions of the proto byte array to build each piece.

What I want to avoid is to parse the proto, create a java object with the whole response, then split each response and convert each one into a protobuf again. The idea would be to get this split by only streaming the proto.

Thanks,
Joan.



Reply all
Reply to author
Forward
0 new messages