Hi Florian,

Thanks a lot for your quick response. It works like a charm.

Thanks,

Joan.


On Tuesday, May 9, 2023 at 12:08:44 PM UTC+2 Florian Enner wrote:

> You could manually iterate through the data and only check for that field, 
> e.g., in Java (untested):
>
> import com.google.protobuf.CodedInputStream;
> import com.google.protobuf.WireFormat;
>
> private static boolean containsHotels(byte[] data) throws IOException {
> return containsField(CodedInputStream.newInstance(data), Message.
> HOTELS_FIELD_NUMBER);
> }
>
> private static boolean containsField(CodedInputStream input, int fieldNumber) 
> throws IOException {
> while (!input.isAtEnd()) {
> int tag = input.readTag();
> if (WireFormat.getTagFieldNumber(tag) == fieldNumber) {
> return true;
> }
> input.skipField(tag);
> }
> return false;
> }
>
>
> On Tuesday, May 9, 2023 at 11:46:52 AM UTC+2 Joan Balagueró wrote:
>
>> Hello,
>>
>> I'm receiving protobuf messages from a client (I can't modify them in any 
>> way) with a list of hotels. There are hotels in the 90% of the times, but I 
>> need to differentitate when I receive hotels and when not.
>>
>> The proto file for "no hotels" is something like below (simplified):
>> 1: {
>> 1: {}
>> 2: {}
>> }
>>
>> Is there any way to check the "2:" element is empty without loading the 
>> whole proto into memory?
>>
>> Thanks,
>>
>> Joan.
>>
>>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/protobuf/499e572f-ed3b-4e2f-88bc-1185549d10e1n%40googlegroups.com.

Reply via email to