Open therealprof opened 3 years ago
Or look for a 0
tag?
@Override
public BuilderType mergeFrom(
final CodedInputStream input, final ExtensionRegistryLite extensionRegistry)
throws IOException {
boolean discardUnknown = input.shouldDiscardUnknownFields();
final UnknownFieldSet.Builder unknownFields =
discardUnknown ? null : UnknownFieldSet.newBuilder(getUnknownFields());
while (true) {
final int tag = input.readTag();
if (tag == 0) {
break;
}
MessageReflection.BuilderAdapter builderAdapter =
new MessageReflection.BuilderAdapter(this);
if (!MessageReflection.mergeFieldFrom(
input, unknownFields, extensionRegistry, getDescriptorForType(), builderAdapter, tag)) {
// end group tag
break;
}
}
if (unknownFields != null) {
setUnknownFields(unknownFields.build());
}
return (BuilderType) this;
}
I just noticed that the generated code does something like:
which means that if it is fed a buffer with multiple protobuf messages included it will parse each message, fill in the structures and then overwrite it with the next until eof is reached (hopefully exactly at a message boundary without excess bytes) and then return the last of the messages.
Wouldn't it make more sense to only check for EOF once at the beginning of each (sub-)message to return an error and then only parse the first message, allowing the
BytesReader
state to be reused by the application to parse more messages or gracefully ignore excess data?