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/8582fd3a-e134-427c-9dcf-8a163aa198a7n%40googlegroups.com.

Reply via email to