Skip to content

Commit

Permalink
Internal Change
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 690909150
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Oct 29, 2024
1 parent 367ef9c commit 85bbcee
Showing 1 changed file with 30 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -496,24 +496,20 @@ public BuilderType mergeFrom(MessageType message) {
return (BuilderType) this;
}

private static <MessageType> void mergeFromInstance(MessageType dest, MessageType src) {
Protobuf.getInstance().schemaFor(dest).mergeFrom(dest, src);
}

@Override
public MessageType getDefaultInstanceForType() {
return defaultInstance;
}

@Override
public BuilderType mergeFrom(
byte[] input, int offset, int length, ExtensionRegistryLite extensionRegistry)
throws InvalidProtocolBufferException {
copyOnWrite();
try {
Protobuf.getInstance().schemaFor(instance).mergeFrom(
instance, input, offset, offset + length,
new ArrayDecoders.Registers(extensionRegistry));
Protobuf.getInstance()
.schemaFor(instance)
.mergeFrom(
instance,
input,
offset,
offset + length,
new ArrayDecoders.Registers(extensionRegistry));
} catch (InvalidProtocolBufferException e) {
throw e;
} catch (IndexOutOfBoundsException e) {
Expand All @@ -525,8 +521,7 @@ public BuilderType mergeFrom(
}

@Override
public BuilderType mergeFrom(
byte[] input, int offset, int length)
public BuilderType mergeFrom(byte[] input, int offset, int length)
throws InvalidProtocolBufferException {
return mergeFrom(input, offset, length, ExtensionRegistryLite.getEmptyRegistry());
}
Expand All @@ -540,8 +535,9 @@ public BuilderType mergeFrom(
try {
// TODO: Try to make input with type CodedInputStream.ArrayDecoder use
// fast path.
Protobuf.getInstance().schemaFor(instance).mergeFrom(
instance, CodedInputStreamReader.forCodedInput(input), extensionRegistry);
Protobuf.getInstance()
.schemaFor(instance)
.mergeFrom(instance, CodedInputStreamReader.forCodedInput(input), extensionRegistry);
} catch (RuntimeException e) {
if (e.getCause() instanceof IOException) {
throw (IOException) e.getCause();
Expand All @@ -550,6 +546,15 @@ public BuilderType mergeFrom(
}
return (BuilderType) this;
}

private static <MessageType> void mergeFromInstance(MessageType dest, MessageType src) {
Protobuf.getInstance().schemaFor(dest).mergeFrom(dest, src);
}

@Override
public MessageType getDefaultInstanceForType() {
return defaultInstance;
}
}

// =================================================================
Expand Down Expand Up @@ -667,7 +672,7 @@ private boolean parseExtension(
while (input.getBytesUntilLimit() > 0) {
Object value =
FieldSet.readPrimitiveField(
input, extension.descriptor.getLiteType(), /*checkUtf8=*/ false);
input, extension.descriptor.getLiteType(), /* checkUtf8= */ false);
extensions.addRepeatedField(extension.descriptor, value);
}
}
Expand Down Expand Up @@ -708,7 +713,7 @@ private boolean parseExtension(
default:
value =
FieldSet.readPrimitiveField(
input, extension.descriptor.getLiteType(), /*checkUtf8=*/ false);
input, extension.descriptor.getLiteType(), /* checkUtf8= */ false);
break;
}

Expand Down Expand Up @@ -1422,8 +1427,10 @@ protected Object readResolve() throws ObjectStreamException {
java.lang.reflect.Field defaultInstanceField =
messageClass.getDeclaredField("DEFAULT_INSTANCE");
defaultInstanceField.setAccessible(true);
MessageLite defaultInstance = (MessageLite) defaultInstanceField.get(null);
return defaultInstance.newBuilderForType().mergeFrom(asBytes).buildPartial();
MessageLite.Builder builder =
((MessageLite) defaultInstanceField.get(null)).newBuilderForType();
builder.mergeFrom(asBytes);
return builder.buildPartial();
} catch (ClassNotFoundException e) {
throw new RuntimeException("Unable to find proto buffer class: " + messageClassName, e);
} catch (NoSuchFieldException e) {
Expand Down Expand Up @@ -1698,8 +1705,9 @@ public T parsePartialFrom(
// Validates last tag.
protected static <T extends GeneratedMessageLite<T, ?>> T parseFrom(
T defaultInstance, byte[] data) throws InvalidProtocolBufferException {
return checkMessageInitialized(parsePartialFrom(
defaultInstance, data, 0, data.length, ExtensionRegistryLite.getEmptyRegistry()));
return checkMessageInitialized(
parsePartialFrom(
defaultInstance, data, 0, data.length, ExtensionRegistryLite.getEmptyRegistry()));
}

// Validates last tag.
Expand Down

0 comments on commit 85bbcee

Please sign in to comment.