From fadc82b4ae5d50a253a2d34464e4345b9c370044 Mon Sep 17 00:00:00 2001 From: blakeli Date: Tue, 11 Mar 2025 10:59:19 -0400 Subject: [PATCH 01/42] Introduce FlattenedGeneratedMessageV3 --- .../com/google/protobuf/AbstractMessage.java | 2 +- .../com/google/protobuf/DescriptorProtos.java | 1936 ++++---- .../protobuf/FlattenedAbstractMessage.java | 864 ++++ .../protobuf/FlattenedGeneratedMessageV3.java | 4302 +++++++++++++++++ .../java/com/google/protobuf/MapEntry.java | 785 ++- .../java/com/google/protobuf/Message.java | 21 + .../protobuf/RepeatedFieldBuilderV3.java | 22 +- .../google/protobuf/SingleFieldBuilderV3.java | 18 +- 8 files changed, 6958 insertions(+), 992 deletions(-) create mode 100644 protobuf-api/src/main/java/com/google/protobuf/FlattenedAbstractMessage.java create mode 100644 protobuf-api/src/main/java/com/google/protobuf/FlattenedGeneratedMessageV3.java diff --git a/protobuf-api/src/main/java/com/google/protobuf/AbstractMessage.java b/protobuf-api/src/main/java/com/google/protobuf/AbstractMessage.java index f383625..9c6e207 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/AbstractMessage.java +++ b/protobuf-api/src/main/java/com/google/protobuf/AbstractMessage.java @@ -39,7 +39,7 @@ public boolean isInitialized() { * Interface for the parent of a Builder that allows the builder to communicate invalidations back * to the parent for use when using nested builders. */ - protected interface BuilderParent { + protected interface BuilderParent extends Message.BuilderParent{ /** * A builder becomes dirty whenever a field is modified -- including fields in nested builders diff --git a/protobuf-api/src/main/java/com/google/protobuf/DescriptorProtos.java b/protobuf-api/src/main/java/com/google/protobuf/DescriptorProtos.java index bc20823..28e300d 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/DescriptorProtos.java +++ b/protobuf-api/src/main/java/com/google/protobuf/DescriptorProtos.java @@ -273,7 +273,7 @@ private Edition(int value) { public interface FileDescriptorSetOrBuilder extends // @@protoc_insertion_point(interface_extends:google.protobuf.FileDescriptorSet) - com.google.protobuf.GeneratedMessageV3. + com.google.protobuf.FlattenedGeneratedMessageV3. ExtendableMessageOrBuilder { /** @@ -309,13 +309,13 @@ com.google.protobuf.DescriptorProtos.FileDescriptorProtoOrBuilder getFileOrBuild * Protobuf type {@code google.protobuf.FileDescriptorSet} */ public static final class FileDescriptorSet extends - com.google.protobuf.GeneratedMessageV3.ExtendableMessage< + com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableMessage< FileDescriptorSet> implements // @@protoc_insertion_point(message_implements:google.protobuf.FileDescriptorSet) FileDescriptorSetOrBuilder { private static final long serialVersionUID = 0L; // Use FileDescriptorSet.newBuilder() to construct. - private FileDescriptorSet(com.google.protobuf.GeneratedMessageV3.ExtendableBuilder builder) { + private FileDescriptorSet(com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableBuilder builder) { super(builder); } private FileDescriptorSet() { @@ -335,7 +335,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_FileDescriptorSet_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -407,7 +407,7 @@ public final boolean isInitialized() { @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - com.google.protobuf.GeneratedMessageV3 + com.google.protobuf.FlattenedGeneratedMessageV3 .ExtendableMessage.ExtensionWriter extensionWriter = newExtensionWriter(); for (int i = 0; i < file_.size(); i++) { @@ -502,20 +502,20 @@ public static com.google.protobuf.DescriptorProtos.FileDescriptorSet parseFrom( } public static com.google.protobuf.DescriptorProtos.FileDescriptorSet parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.FileDescriptorSet parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.FileDescriptorSet parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -523,20 +523,20 @@ public static com.google.protobuf.DescriptorProtos.FileDescriptorSet parseDelimi java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.FileDescriptorSet parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.FileDescriptorSet parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -556,7 +556,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -569,7 +569,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.FileDescriptorSet} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.ExtendableBuilder< + com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableBuilder< com.google.protobuf.DescriptorProtos.FileDescriptorSet, Builder> implements // @@protoc_insertion_point(builder_implements:google.protobuf.FileDescriptorSet) com.google.protobuf.DescriptorProtos.FileDescriptorSetOrBuilder { @@ -579,7 +579,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_FileDescriptorSet_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -592,7 +592,7 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); } @@ -687,33 +687,33 @@ public Builder addRepeatedField( java.lang.Object value) { return super.addRepeatedField(field, value); } - @java.lang.Override - public Builder setExtension( - com.google.protobuf.GeneratedMessage.GeneratedExtension< - com.google.protobuf.DescriptorProtos.FileDescriptorSet, Type> extension, - Type value) { - return super.setExtension(extension, value); - } - @java.lang.Override - public Builder setExtension( - com.google.protobuf.GeneratedMessage.GeneratedExtension< - com.google.protobuf.DescriptorProtos.FileDescriptorSet, java.util.List> extension, - int index, Type value) { - return super.setExtension(extension, index, value); - } - @java.lang.Override - public Builder addExtension( - com.google.protobuf.GeneratedMessage.GeneratedExtension< - com.google.protobuf.DescriptorProtos.FileDescriptorSet, java.util.List> extension, - Type value) { - return super.addExtension(extension, value); - } - @java.lang.Override - public Builder clearExtension( - com.google.protobuf.GeneratedMessage.GeneratedExtension< - com.google.protobuf.DescriptorProtos.FileDescriptorSet, T> extension) { - return super.clearExtension(extension); - } +// @java.lang.Override +// public Builder setExtension( +// com.google.protobuf.GeneratedMessage.GeneratedExtension< +// com.google.protobuf.DescriptorProtos.FileDescriptorSet, Type> extension, +// Type value) { +// return super.setExtension(extension, value); +// } +// @java.lang.Override +// public Builder setExtension( +// com.google.protobuf.GeneratedMessage.GeneratedExtension< +// com.google.protobuf.DescriptorProtos.FileDescriptorSet, java.util.List> extension, +// int index, Type value) { +// return super.setExtension(extension, index, value); +// } +// @java.lang.Override +// public Builder addExtension( +// com.google.protobuf.GeneratedMessage.GeneratedExtension< +// com.google.protobuf.DescriptorProtos.FileDescriptorSet, java.util.List> extension, +// Type value) { +// return super.addExtension(extension, value); +// } +// @java.lang.Override +// public Builder clearExtension( +// com.google.protobuf.GeneratedMessage.GeneratedExtension< +// com.google.protobuf.DescriptorProtos.FileDescriptorSet, T> extension) { +// return super.clearExtension(extension); +// } @java.lang.Override public Builder mergeFrom(com.google.protobuf.Message other) { if (other instanceof com.google.protobuf.DescriptorProtos.FileDescriptorSet) { @@ -745,7 +745,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.FileDescriptorSet file_ = other.file_; bitField0_ = (bitField0_ & ~0x00000001); fileBuilder_ = - com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? getFileFieldBuilder() : null; } else { fileBuilder_.addAllMessages(other.file_); @@ -1531,12 +1531,12 @@ com.google.protobuf.DescriptorProtos.FieldDescriptorProtoOrBuilder getExtensionO * Protobuf type {@code google.protobuf.FileDescriptorProto} */ public static final class FileDescriptorProto extends - com.google.protobuf.GeneratedMessageV3 implements + com.google.protobuf.FlattenedGeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:google.protobuf.FileDescriptorProto) FileDescriptorProtoOrBuilder { private static final long serialVersionUID = 0L; // Use FileDescriptorProto.newBuilder() to construct. - private FileDescriptorProto(com.google.protobuf.GeneratedMessageV3.Builder builder) { + private FileDescriptorProto(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { super(builder); } private FileDescriptorProto() { @@ -1567,7 +1567,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_FileDescriptorProto_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -2254,13 +2254,13 @@ public final boolean isInitialized() { public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { if (((bitField0_ & 0x00000001) != 0)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 1, name_); + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 1, name_); } if (((bitField0_ & 0x00000002) != 0)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 2, package_); + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 2, package_); } for (int i = 0; i < dependency_.size(); i++) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 3, dependency_.getRaw(i)); + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 3, dependency_.getRaw(i)); } for (int i = 0; i < messageType_.size(); i++) { output.writeMessage(4, messageType_.get(i)); @@ -2287,7 +2287,7 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) output.writeInt32(11, weakDependency_.getInt(i)); } if (((bitField0_ & 0x00000010) != 0)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 12, syntax_); + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 12, syntax_); } if (((bitField0_ & 0x00000020) != 0)) { output.writeEnum(14, edition_); @@ -2302,10 +2302,10 @@ public int getSerializedSize() { size = 0; if (((bitField0_ & 0x00000001) != 0)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, name_); + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(1, name_); } if (((bitField0_ & 0x00000002) != 0)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, package_); + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(2, package_); } { int dataSize = 0; @@ -2358,7 +2358,7 @@ public int getSerializedSize() { size += 1 * getWeakDependencyList().size(); } if (((bitField0_ & 0x00000010) != 0)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(12, syntax_); + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(12, syntax_); } if (((bitField0_ & 0x00000020) != 0)) { size += com.google.protobuf.CodedOutputStream @@ -2524,20 +2524,20 @@ public static com.google.protobuf.DescriptorProtos.FileDescriptorProto parseFrom } public static com.google.protobuf.DescriptorProtos.FileDescriptorProto parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.FileDescriptorProto parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.FileDescriptorProto parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -2545,20 +2545,20 @@ public static com.google.protobuf.DescriptorProtos.FileDescriptorProto parseDeli java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.FileDescriptorProto parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.FileDescriptorProto parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -2578,7 +2578,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -2590,7 +2590,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.FileDescriptorProto} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements + com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.FileDescriptorProto) com.google.protobuf.DescriptorProtos.FileDescriptorProtoOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -2599,7 +2599,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_FileDescriptorProto_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -2612,12 +2612,12 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 + if (com.google.protobuf.FlattenedGeneratedMessageV3 .alwaysUseFieldBuilders) { getMessageTypeFieldBuilder(); getEnumTypeFieldBuilder(); @@ -2899,7 +2899,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.FileDescriptorProt messageType_ = other.messageType_; bitField0_ = (bitField0_ & ~0x00000020); messageTypeBuilder_ = - com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? getMessageTypeFieldBuilder() : null; } else { messageTypeBuilder_.addAllMessages(other.messageType_); @@ -2925,7 +2925,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.FileDescriptorProt enumType_ = other.enumType_; bitField0_ = (bitField0_ & ~0x00000040); enumTypeBuilder_ = - com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? getEnumTypeFieldBuilder() : null; } else { enumTypeBuilder_.addAllMessages(other.enumType_); @@ -2951,7 +2951,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.FileDescriptorProt service_ = other.service_; bitField0_ = (bitField0_ & ~0x00000080); serviceBuilder_ = - com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? getServiceFieldBuilder() : null; } else { serviceBuilder_.addAllMessages(other.service_); @@ -2977,7 +2977,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.FileDescriptorProt extension_ = other.extension_; bitField0_ = (bitField0_ & ~0x00000100); extensionBuilder_ = - com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? getExtensionFieldBuilder() : null; } else { extensionBuilder_.addAllMessages(other.extension_); @@ -5654,12 +5654,12 @@ com.google.protobuf.DescriptorProtos.DescriptorProto.ReservedRangeOrBuilder getR * Protobuf type {@code google.protobuf.DescriptorProto} */ public static final class DescriptorProto extends - com.google.protobuf.GeneratedMessageV3 implements + com.google.protobuf.FlattenedGeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:google.protobuf.DescriptorProto) DescriptorProtoOrBuilder { private static final long serialVersionUID = 0L; // Use DescriptorProto.newBuilder() to construct. - private DescriptorProto(com.google.protobuf.GeneratedMessageV3.Builder builder) { + private DescriptorProto(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { super(builder); } private DescriptorProto() { @@ -5688,7 +5688,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_DescriptorProto_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -5756,12 +5756,12 @@ public interface ExtensionRangeOrBuilder extends * Protobuf type {@code google.protobuf.DescriptorProto.ExtensionRange} */ public static final class ExtensionRange extends - com.google.protobuf.GeneratedMessageV3 implements + com.google.protobuf.FlattenedGeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:google.protobuf.DescriptorProto.ExtensionRange) ExtensionRangeOrBuilder { private static final long serialVersionUID = 0L; // Use ExtensionRange.newBuilder() to construct. - private ExtensionRange(com.google.protobuf.GeneratedMessageV3.Builder builder) { + private ExtensionRange(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { super(builder); } private ExtensionRange() { @@ -5780,7 +5780,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_DescriptorProto_ExtensionRange_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -6010,20 +6010,20 @@ public static com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRang } public static com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -6031,20 +6031,20 @@ public static com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRang java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -6064,7 +6064,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -6072,7 +6072,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.DescriptorProto.ExtensionRange} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements + com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.DescriptorProto.ExtensionRange) com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRangeOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -6081,7 +6081,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_DescriptorProto_ExtensionRange_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -6094,12 +6094,12 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 + if (com.google.protobuf.FlattenedGeneratedMessageV3 .alwaysUseFieldBuilders) { getOptionsFieldBuilder(); } @@ -6632,12 +6632,12 @@ public interface ReservedRangeOrBuilder extends * Protobuf type {@code google.protobuf.DescriptorProto.ReservedRange} */ public static final class ReservedRange extends - com.google.protobuf.GeneratedMessageV3 implements + com.google.protobuf.FlattenedGeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:google.protobuf.DescriptorProto.ReservedRange) ReservedRangeOrBuilder { private static final long serialVersionUID = 0L; // Use ReservedRange.newBuilder() to construct. - private ReservedRange(com.google.protobuf.GeneratedMessageV3.Builder builder) { + private ReservedRange(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { super(builder); } private ReservedRange() { @@ -6656,7 +6656,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_DescriptorProto_ReservedRange_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -6838,20 +6838,20 @@ public static com.google.protobuf.DescriptorProtos.DescriptorProto.ReservedRange } public static com.google.protobuf.DescriptorProtos.DescriptorProto.ReservedRange parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.DescriptorProto.ReservedRange parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.DescriptorProto.ReservedRange parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -6859,20 +6859,20 @@ public static com.google.protobuf.DescriptorProtos.DescriptorProto.ReservedRange java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.DescriptorProto.ReservedRange parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.DescriptorProto.ReservedRange parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -6892,7 +6892,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -6906,7 +6906,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.DescriptorProto.ReservedRange} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements + com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.DescriptorProto.ReservedRange) com.google.protobuf.DescriptorProtos.DescriptorProto.ReservedRangeOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -6915,7 +6915,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_DescriptorProto_ReservedRange_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -6928,7 +6928,7 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); } @@ -7738,7 +7738,7 @@ public final boolean isInitialized() { public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { if (((bitField0_ & 0x00000001) != 0)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 1, name_); + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 1, name_); } for (int i = 0; i < field_.size(); i++) { output.writeMessage(2, field_.get(i)); @@ -7765,7 +7765,7 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) output.writeMessage(9, reservedRange_.get(i)); } for (int i = 0; i < reservedName_.size(); i++) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 10, reservedName_.getRaw(i)); + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 10, reservedName_.getRaw(i)); } getUnknownFields().writeTo(output); } @@ -7777,7 +7777,7 @@ public int getSerializedSize() { size = 0; if (((bitField0_ & 0x00000001) != 0)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, name_); + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(1, name_); } for (int i = 0; i < field_.size(); i++) { size += com.google.protobuf.CodedOutputStream @@ -7950,20 +7950,20 @@ public static com.google.protobuf.DescriptorProtos.DescriptorProto parseFrom( } public static com.google.protobuf.DescriptorProtos.DescriptorProto parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.DescriptorProto parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.DescriptorProto parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -7971,20 +7971,20 @@ public static com.google.protobuf.DescriptorProtos.DescriptorProto parseDelimite java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.DescriptorProto parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.DescriptorProto parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -8004,7 +8004,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -8016,7 +8016,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.DescriptorProto} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements + com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.DescriptorProto) com.google.protobuf.DescriptorProtos.DescriptorProtoOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -8025,7 +8025,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_DescriptorProto_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -8038,12 +8038,12 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 + if (com.google.protobuf.FlattenedGeneratedMessageV3 .alwaysUseFieldBuilders) { getFieldFieldBuilder(); getExtensionFieldBuilder(); @@ -8302,7 +8302,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.DescriptorProto ot field_ = other.field_; bitField0_ = (bitField0_ & ~0x00000002); fieldBuilder_ = - com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? getFieldFieldBuilder() : null; } else { fieldBuilder_.addAllMessages(other.field_); @@ -8328,7 +8328,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.DescriptorProto ot extension_ = other.extension_; bitField0_ = (bitField0_ & ~0x00000004); extensionBuilder_ = - com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? getExtensionFieldBuilder() : null; } else { extensionBuilder_.addAllMessages(other.extension_); @@ -8354,7 +8354,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.DescriptorProto ot nestedType_ = other.nestedType_; bitField0_ = (bitField0_ & ~0x00000008); nestedTypeBuilder_ = - com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? getNestedTypeFieldBuilder() : null; } else { nestedTypeBuilder_.addAllMessages(other.nestedType_); @@ -8380,7 +8380,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.DescriptorProto ot enumType_ = other.enumType_; bitField0_ = (bitField0_ & ~0x00000010); enumTypeBuilder_ = - com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? getEnumTypeFieldBuilder() : null; } else { enumTypeBuilder_.addAllMessages(other.enumType_); @@ -8406,7 +8406,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.DescriptorProto ot extensionRange_ = other.extensionRange_; bitField0_ = (bitField0_ & ~0x00000020); extensionRangeBuilder_ = - com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? getExtensionRangeFieldBuilder() : null; } else { extensionRangeBuilder_.addAllMessages(other.extensionRange_); @@ -8432,7 +8432,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.DescriptorProto ot oneofDecl_ = other.oneofDecl_; bitField0_ = (bitField0_ & ~0x00000040); oneofDeclBuilder_ = - com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? getOneofDeclFieldBuilder() : null; } else { oneofDeclBuilder_.addAllMessages(other.oneofDecl_); @@ -8461,7 +8461,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.DescriptorProto ot reservedRange_ = other.reservedRange_; bitField0_ = (bitField0_ & ~0x00000100); reservedRangeBuilder_ = - com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? getReservedRangeFieldBuilder() : null; } else { reservedRangeBuilder_.addAllMessages(other.reservedRange_); @@ -10766,7 +10766,7 @@ public com.google.protobuf.DescriptorProtos.DescriptorProto getDefaultInstanceFo public interface ExtensionRangeOptionsOrBuilder extends // @@protoc_insertion_point(interface_extends:google.protobuf.ExtensionRangeOptions) - com.google.protobuf.GeneratedMessageV3. + com.google.protobuf.FlattenedGeneratedMessageV3. ExtendableMessageOrBuilder { /** @@ -10921,13 +10921,13 @@ com.google.protobuf.DescriptorProtos.ExtensionRangeOptions.DeclarationOrBuilder * Protobuf type {@code google.protobuf.ExtensionRangeOptions} */ public static final class ExtensionRangeOptions extends - com.google.protobuf.GeneratedMessageV3.ExtendableMessage< + com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableMessage< ExtensionRangeOptions> implements // @@protoc_insertion_point(message_implements:google.protobuf.ExtensionRangeOptions) ExtensionRangeOptionsOrBuilder { private static final long serialVersionUID = 0L; // Use ExtensionRangeOptions.newBuilder() to construct. - private ExtensionRangeOptions(com.google.protobuf.GeneratedMessageV3.ExtendableBuilder builder) { + private ExtensionRangeOptions(com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableBuilder builder) { super(builder); } private ExtensionRangeOptions() { @@ -10949,7 +10949,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_ExtensionRangeOptions_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -11202,12 +11202,12 @@ public interface DeclarationOrBuilder extends * Protobuf type {@code google.protobuf.ExtensionRangeOptions.Declaration} */ public static final class Declaration extends - com.google.protobuf.GeneratedMessageV3 implements + com.google.protobuf.FlattenedGeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:google.protobuf.ExtensionRangeOptions.Declaration) DeclarationOrBuilder { private static final long serialVersionUID = 0L; // Use Declaration.newBuilder() to construct. - private Declaration(com.google.protobuf.GeneratedMessageV3.Builder builder) { + private Declaration(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { super(builder); } private Declaration() { @@ -11228,7 +11228,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_ExtensionRangeOptions_Declaration_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -11472,10 +11472,10 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) output.writeInt32(1, number_); } if (((bitField0_ & 0x00000002) != 0)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 2, fullName_); + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 2, fullName_); } if (((bitField0_ & 0x00000004) != 0)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 3, type_); + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 3, type_); } if (((bitField0_ & 0x00000008) != 0)) { output.writeBool(5, reserved_); @@ -11497,10 +11497,10 @@ public int getSerializedSize() { .computeInt32Size(1, number_); } if (((bitField0_ & 0x00000002) != 0)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, fullName_); + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(2, fullName_); } if (((bitField0_ & 0x00000004) != 0)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(3, type_); + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(3, type_); } if (((bitField0_ & 0x00000008) != 0)) { size += com.google.protobuf.CodedOutputStream @@ -11622,20 +11622,20 @@ public static com.google.protobuf.DescriptorProtos.ExtensionRangeOptions.Declara } public static com.google.protobuf.DescriptorProtos.ExtensionRangeOptions.Declaration parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.ExtensionRangeOptions.Declaration parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.ExtensionRangeOptions.Declaration parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -11643,20 +11643,20 @@ public static com.google.protobuf.DescriptorProtos.ExtensionRangeOptions.Declara java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.ExtensionRangeOptions.Declaration parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.ExtensionRangeOptions.Declaration parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -11676,7 +11676,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -11684,7 +11684,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.ExtensionRangeOptions.Declaration} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements + com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.ExtensionRangeOptions.Declaration) com.google.protobuf.DescriptorProtos.ExtensionRangeOptions.DeclarationOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -11693,7 +11693,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_ExtensionRangeOptions_Declaration_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -11706,7 +11706,7 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); } @@ -12607,7 +12607,7 @@ public final boolean isInitialized() { @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - com.google.protobuf.GeneratedMessageV3 + com.google.protobuf.FlattenedGeneratedMessageV3 .ExtendableMessage.ExtensionWriter extensionWriter = newExtensionWriter(); for (int i = 0; i < declaration_.size(); i++) { @@ -12746,20 +12746,20 @@ public static com.google.protobuf.DescriptorProtos.ExtensionRangeOptions parseFr } public static com.google.protobuf.DescriptorProtos.ExtensionRangeOptions parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.ExtensionRangeOptions parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.ExtensionRangeOptions parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -12767,20 +12767,20 @@ public static com.google.protobuf.DescriptorProtos.ExtensionRangeOptions parseDe java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.ExtensionRangeOptions parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.ExtensionRangeOptions parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -12800,7 +12800,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -12808,7 +12808,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.ExtensionRangeOptions} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.ExtendableBuilder< + com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableBuilder< com.google.protobuf.DescriptorProtos.ExtensionRangeOptions, Builder> implements // @@protoc_insertion_point(builder_implements:google.protobuf.ExtensionRangeOptions) com.google.protobuf.DescriptorProtos.ExtensionRangeOptionsOrBuilder { @@ -12818,7 +12818,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_ExtensionRangeOptions_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -12831,12 +12831,12 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 + if (com.google.protobuf.FlattenedGeneratedMessageV3 .alwaysUseFieldBuilders) { getUninterpretedOptionFieldBuilder(); getDeclarationFieldBuilder(); @@ -12968,33 +12968,33 @@ public Builder addRepeatedField( java.lang.Object value) { return super.addRepeatedField(field, value); } - @java.lang.Override - public Builder setExtension( - com.google.protobuf.GeneratedMessage.GeneratedExtension< - com.google.protobuf.DescriptorProtos.ExtensionRangeOptions, Type> extension, - Type value) { - return super.setExtension(extension, value); - } - @java.lang.Override - public Builder setExtension( - com.google.protobuf.GeneratedMessage.GeneratedExtension< - com.google.protobuf.DescriptorProtos.ExtensionRangeOptions, java.util.List> extension, - int index, Type value) { - return super.setExtension(extension, index, value); - } - @java.lang.Override - public Builder addExtension( - com.google.protobuf.GeneratedMessage.GeneratedExtension< - com.google.protobuf.DescriptorProtos.ExtensionRangeOptions, java.util.List> extension, - Type value) { - return super.addExtension(extension, value); - } - @java.lang.Override - public Builder clearExtension( - com.google.protobuf.GeneratedMessage.GeneratedExtension< - com.google.protobuf.DescriptorProtos.ExtensionRangeOptions, T> extension) { - return super.clearExtension(extension); - } +// @java.lang.Override +// public Builder setExtension( +// com.google.protobuf.GeneratedMessage.GeneratedExtension< +// com.google.protobuf.DescriptorProtos.ExtensionRangeOptions, Type> extension, +// Type value) { +// return super.setExtension(extension, value); +// } +// @java.lang.Override +// public Builder setExtension( +// com.google.protobuf.GeneratedMessage.GeneratedExtension< +// com.google.protobuf.DescriptorProtos.ExtensionRangeOptions, java.util.List> extension, +// int index, Type value) { +// return super.setExtension(extension, index, value); +// } +// @java.lang.Override +// public Builder addExtension( +// com.google.protobuf.GeneratedMessage.GeneratedExtension< +// com.google.protobuf.DescriptorProtos.ExtensionRangeOptions, java.util.List> extension, +// Type value) { +// return super.addExtension(extension, value); +// } +// @java.lang.Override +// public Builder clearExtension( +// com.google.protobuf.GeneratedMessage.GeneratedExtension< +// com.google.protobuf.DescriptorProtos.ExtensionRangeOptions, T> extension) { +// return super.clearExtension(extension); +// } @java.lang.Override public Builder mergeFrom(com.google.protobuf.Message other) { if (other instanceof com.google.protobuf.DescriptorProtos.ExtensionRangeOptions) { @@ -13026,7 +13026,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.ExtensionRangeOpti uninterpretedOption_ = other.uninterpretedOption_; bitField0_ = (bitField0_ & ~0x00000001); uninterpretedOptionBuilder_ = - com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? getUninterpretedOptionFieldBuilder() : null; } else { uninterpretedOptionBuilder_.addAllMessages(other.uninterpretedOption_); @@ -13052,7 +13052,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.ExtensionRangeOpti declaration_ = other.declaration_; bitField0_ = (bitField0_ & ~0x00000002); declarationBuilder_ = - com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? getDeclarationFieldBuilder() : null; } else { declarationBuilder_.addAllMessages(other.declaration_); @@ -14429,12 +14429,12 @@ public interface FieldDescriptorProtoOrBuilder extends * Protobuf type {@code google.protobuf.FieldDescriptorProto} */ public static final class FieldDescriptorProto extends - com.google.protobuf.GeneratedMessageV3 implements + com.google.protobuf.FlattenedGeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:google.protobuf.FieldDescriptorProto) FieldDescriptorProtoOrBuilder { private static final long serialVersionUID = 0L; // Use FieldDescriptorProto.newBuilder() to construct. - private FieldDescriptorProto(com.google.protobuf.GeneratedMessageV3.Builder builder) { + private FieldDescriptorProto(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { super(builder); } private FieldDescriptorProto() { @@ -14460,7 +14460,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_FieldDescriptorProto_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -15445,10 +15445,10 @@ public final boolean isInitialized() { public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { if (((bitField0_ & 0x00000001) != 0)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 1, name_); + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 1, name_); } if (((bitField0_ & 0x00000020) != 0)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 2, extendee_); + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 2, extendee_); } if (((bitField0_ & 0x00000002) != 0)) { output.writeInt32(3, number_); @@ -15460,10 +15460,10 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) output.writeEnum(5, type_); } if (((bitField0_ & 0x00000010) != 0)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 6, typeName_); + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 6, typeName_); } if (((bitField0_ & 0x00000040) != 0)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 7, defaultValue_); + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 7, defaultValue_); } if (((bitField0_ & 0x00000200) != 0)) { output.writeMessage(8, getOptions()); @@ -15472,7 +15472,7 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) output.writeInt32(9, oneofIndex_); } if (((bitField0_ & 0x00000100) != 0)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 10, jsonName_); + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 10, jsonName_); } if (((bitField0_ & 0x00000400) != 0)) { output.writeBool(17, proto3Optional_); @@ -15487,10 +15487,10 @@ public int getSerializedSize() { size = 0; if (((bitField0_ & 0x00000001) != 0)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, name_); + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(1, name_); } if (((bitField0_ & 0x00000020) != 0)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, extendee_); + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(2, extendee_); } if (((bitField0_ & 0x00000002) != 0)) { size += com.google.protobuf.CodedOutputStream @@ -15505,10 +15505,10 @@ public int getSerializedSize() { .computeEnumSize(5, type_); } if (((bitField0_ & 0x00000010) != 0)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(6, typeName_); + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(6, typeName_); } if (((bitField0_ & 0x00000040) != 0)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(7, defaultValue_); + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(7, defaultValue_); } if (((bitField0_ & 0x00000200) != 0)) { size += com.google.protobuf.CodedOutputStream @@ -15519,7 +15519,7 @@ public int getSerializedSize() { .computeInt32Size(9, oneofIndex_); } if (((bitField0_ & 0x00000100) != 0)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(10, jsonName_); + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(10, jsonName_); } if (((bitField0_ & 0x00000400) != 0)) { size += com.google.protobuf.CodedOutputStream @@ -15688,20 +15688,20 @@ public static com.google.protobuf.DescriptorProtos.FieldDescriptorProto parseFro } public static com.google.protobuf.DescriptorProtos.FieldDescriptorProto parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.FieldDescriptorProto parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.FieldDescriptorProto parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -15709,20 +15709,20 @@ public static com.google.protobuf.DescriptorProtos.FieldDescriptorProto parseDel java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.FieldDescriptorProto parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.FieldDescriptorProto parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -15742,7 +15742,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -15754,7 +15754,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.FieldDescriptorProto} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements + com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.FieldDescriptorProto) com.google.protobuf.DescriptorProtos.FieldDescriptorProtoOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -15763,7 +15763,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_FieldDescriptorProto_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -15776,12 +15776,12 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 + if (com.google.protobuf.FlattenedGeneratedMessageV3 .alwaysUseFieldBuilders) { getOptionsFieldBuilder(); } @@ -17224,12 +17224,12 @@ public interface OneofDescriptorProtoOrBuilder extends * Protobuf type {@code google.protobuf.OneofDescriptorProto} */ public static final class OneofDescriptorProto extends - com.google.protobuf.GeneratedMessageV3 implements + com.google.protobuf.FlattenedGeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:google.protobuf.OneofDescriptorProto) OneofDescriptorProtoOrBuilder { private static final long serialVersionUID = 0L; // Use OneofDescriptorProto.newBuilder() to construct. - private OneofDescriptorProto(com.google.protobuf.GeneratedMessageV3.Builder builder) { + private OneofDescriptorProto(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { super(builder); } private OneofDescriptorProto() { @@ -17249,7 +17249,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_OneofDescriptorProto_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -17353,7 +17353,7 @@ public final boolean isInitialized() { public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { if (((bitField0_ & 0x00000001) != 0)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 1, name_); + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 1, name_); } if (((bitField0_ & 0x00000002) != 0)) { output.writeMessage(2, getOptions()); @@ -17368,7 +17368,7 @@ public int getSerializedSize() { size = 0; if (((bitField0_ & 0x00000001) != 0)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, name_); + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(1, name_); } if (((bitField0_ & 0x00000002) != 0)) { size += com.google.protobuf.CodedOutputStream @@ -17457,20 +17457,20 @@ public static com.google.protobuf.DescriptorProtos.OneofDescriptorProto parseFro } public static com.google.protobuf.DescriptorProtos.OneofDescriptorProto parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.OneofDescriptorProto parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.OneofDescriptorProto parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -17478,20 +17478,20 @@ public static com.google.protobuf.DescriptorProtos.OneofDescriptorProto parseDel java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.OneofDescriptorProto parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.OneofDescriptorProto parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -17511,7 +17511,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -17523,7 +17523,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.OneofDescriptorProto} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements + com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.OneofDescriptorProto) com.google.protobuf.DescriptorProtos.OneofDescriptorProtoOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -17532,7 +17532,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_OneofDescriptorProto_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -17545,12 +17545,12 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 + if (com.google.protobuf.FlattenedGeneratedMessageV3 .alwaysUseFieldBuilders) { getOptionsFieldBuilder(); } @@ -18155,12 +18155,12 @@ com.google.protobuf.DescriptorProtos.EnumDescriptorProto.EnumReservedRangeOrBuil * Protobuf type {@code google.protobuf.EnumDescriptorProto} */ public static final class EnumDescriptorProto extends - com.google.protobuf.GeneratedMessageV3 implements + com.google.protobuf.FlattenedGeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:google.protobuf.EnumDescriptorProto) EnumDescriptorProtoOrBuilder { private static final long serialVersionUID = 0L; // Use EnumDescriptorProto.newBuilder() to construct. - private EnumDescriptorProto(com.google.protobuf.GeneratedMessageV3.Builder builder) { + private EnumDescriptorProto(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { super(builder); } private EnumDescriptorProto() { @@ -18184,7 +18184,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_EnumDescriptorProto_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -18246,12 +18246,12 @@ public interface EnumReservedRangeOrBuilder extends * Protobuf type {@code google.protobuf.EnumDescriptorProto.EnumReservedRange} */ public static final class EnumReservedRange extends - com.google.protobuf.GeneratedMessageV3 implements + com.google.protobuf.FlattenedGeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:google.protobuf.EnumDescriptorProto.EnumReservedRange) EnumReservedRangeOrBuilder { private static final long serialVersionUID = 0L; // Use EnumReservedRange.newBuilder() to construct. - private EnumReservedRange(com.google.protobuf.GeneratedMessageV3.Builder builder) { + private EnumReservedRange(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { super(builder); } private EnumReservedRange() { @@ -18270,7 +18270,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_EnumDescriptorProto_EnumReservedRange_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -18452,20 +18452,20 @@ public static com.google.protobuf.DescriptorProtos.EnumDescriptorProto.EnumReser } public static com.google.protobuf.DescriptorProtos.EnumDescriptorProto.EnumReservedRange parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.EnumDescriptorProto.EnumReservedRange parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.EnumDescriptorProto.EnumReservedRange parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -18473,20 +18473,20 @@ public static com.google.protobuf.DescriptorProtos.EnumDescriptorProto.EnumReser java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.EnumDescriptorProto.EnumReservedRange parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.EnumDescriptorProto.EnumReservedRange parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -18506,7 +18506,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -18523,7 +18523,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.EnumDescriptorProto.EnumReservedRange} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements + com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.EnumDescriptorProto.EnumReservedRange) com.google.protobuf.DescriptorProtos.EnumDescriptorProto.EnumReservedRangeOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -18532,7 +18532,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_EnumDescriptorProto_EnumReservedRange_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -18545,7 +18545,7 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); } @@ -19150,7 +19150,7 @@ public final boolean isInitialized() { public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { if (((bitField0_ & 0x00000001) != 0)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 1, name_); + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 1, name_); } for (int i = 0; i < value_.size(); i++) { output.writeMessage(2, value_.get(i)); @@ -19162,7 +19162,7 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) output.writeMessage(4, reservedRange_.get(i)); } for (int i = 0; i < reservedName_.size(); i++) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 5, reservedName_.getRaw(i)); + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 5, reservedName_.getRaw(i)); } getUnknownFields().writeTo(output); } @@ -19174,7 +19174,7 @@ public int getSerializedSize() { size = 0; if (((bitField0_ & 0x00000001) != 0)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, name_); + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(1, name_); } for (int i = 0; i < value_.size(); i++) { size += com.google.protobuf.CodedOutputStream @@ -19297,20 +19297,20 @@ public static com.google.protobuf.DescriptorProtos.EnumDescriptorProto parseFrom } public static com.google.protobuf.DescriptorProtos.EnumDescriptorProto parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.EnumDescriptorProto parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.EnumDescriptorProto parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -19318,20 +19318,20 @@ public static com.google.protobuf.DescriptorProtos.EnumDescriptorProto parseDeli java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.EnumDescriptorProto parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.EnumDescriptorProto parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -19351,7 +19351,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -19363,7 +19363,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.EnumDescriptorProto} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements + com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.EnumDescriptorProto) com.google.protobuf.DescriptorProtos.EnumDescriptorProtoOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -19372,7 +19372,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_EnumDescriptorProto_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -19385,12 +19385,12 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 + if (com.google.protobuf.FlattenedGeneratedMessageV3 .alwaysUseFieldBuilders) { getValueFieldBuilder(); getOptionsFieldBuilder(); @@ -19564,7 +19564,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.EnumDescriptorProt value_ = other.value_; bitField0_ = (bitField0_ & ~0x00000002); valueBuilder_ = - com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? getValueFieldBuilder() : null; } else { valueBuilder_.addAllMessages(other.value_); @@ -19593,7 +19593,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.EnumDescriptorProt reservedRange_ = other.reservedRange_; bitField0_ = (bitField0_ & ~0x00000008); reservedRangeBuilder_ = - com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? getReservedRangeFieldBuilder() : null; } else { reservedRangeBuilder_.addAllMessages(other.reservedRange_); @@ -20769,12 +20769,12 @@ public interface EnumValueDescriptorProtoOrBuilder extends * Protobuf type {@code google.protobuf.EnumValueDescriptorProto} */ public static final class EnumValueDescriptorProto extends - com.google.protobuf.GeneratedMessageV3 implements + com.google.protobuf.FlattenedGeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:google.protobuf.EnumValueDescriptorProto) EnumValueDescriptorProtoOrBuilder { private static final long serialVersionUID = 0L; // Use EnumValueDescriptorProto.newBuilder() to construct. - private EnumValueDescriptorProto(com.google.protobuf.GeneratedMessageV3.Builder builder) { + private EnumValueDescriptorProto(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { super(builder); } private EnumValueDescriptorProto() { @@ -20794,7 +20794,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_EnumValueDescriptorProto_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -20917,7 +20917,7 @@ public final boolean isInitialized() { public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { if (((bitField0_ & 0x00000001) != 0)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 1, name_); + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 1, name_); } if (((bitField0_ & 0x00000002) != 0)) { output.writeInt32(2, number_); @@ -20935,7 +20935,7 @@ public int getSerializedSize() { size = 0; if (((bitField0_ & 0x00000001) != 0)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, name_); + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(1, name_); } if (((bitField0_ & 0x00000002) != 0)) { size += com.google.protobuf.CodedOutputStream @@ -21037,20 +21037,20 @@ public static com.google.protobuf.DescriptorProtos.EnumValueDescriptorProto pars } public static com.google.protobuf.DescriptorProtos.EnumValueDescriptorProto parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.EnumValueDescriptorProto parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.EnumValueDescriptorProto parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -21058,20 +21058,20 @@ public static com.google.protobuf.DescriptorProtos.EnumValueDescriptorProto pars java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.EnumValueDescriptorProto parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.EnumValueDescriptorProto parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -21091,7 +21091,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -21103,7 +21103,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.EnumValueDescriptorProto} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements + com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.EnumValueDescriptorProto) com.google.protobuf.DescriptorProtos.EnumValueDescriptorProtoOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -21112,7 +21112,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_EnumValueDescriptorProto_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -21125,12 +21125,12 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 + if (com.google.protobuf.FlattenedGeneratedMessageV3 .alwaysUseFieldBuilders) { getOptionsFieldBuilder(); } @@ -21689,12 +21689,12 @@ com.google.protobuf.DescriptorProtos.MethodDescriptorProtoOrBuilder getMethodOrB * Protobuf type {@code google.protobuf.ServiceDescriptorProto} */ public static final class ServiceDescriptorProto extends - com.google.protobuf.GeneratedMessageV3 implements + com.google.protobuf.FlattenedGeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:google.protobuf.ServiceDescriptorProto) ServiceDescriptorProtoOrBuilder { private static final long serialVersionUID = 0L; // Use ServiceDescriptorProto.newBuilder() to construct. - private ServiceDescriptorProto(com.google.protobuf.GeneratedMessageV3.Builder builder) { + private ServiceDescriptorProto(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { super(builder); } private ServiceDescriptorProto() { @@ -21715,7 +21715,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_ServiceDescriptorProto_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -21866,7 +21866,7 @@ public final boolean isInitialized() { public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { if (((bitField0_ & 0x00000001) != 0)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 1, name_); + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 1, name_); } for (int i = 0; i < method_.size(); i++) { output.writeMessage(2, method_.get(i)); @@ -21884,7 +21884,7 @@ public int getSerializedSize() { size = 0; if (((bitField0_ & 0x00000001) != 0)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, name_); + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(1, name_); } for (int i = 0; i < method_.size(); i++) { size += com.google.protobuf.CodedOutputStream @@ -21983,20 +21983,20 @@ public static com.google.protobuf.DescriptorProtos.ServiceDescriptorProto parseF } public static com.google.protobuf.DescriptorProtos.ServiceDescriptorProto parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.ServiceDescriptorProto parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.ServiceDescriptorProto parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -22004,20 +22004,20 @@ public static com.google.protobuf.DescriptorProtos.ServiceDescriptorProto parseD java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.ServiceDescriptorProto parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.ServiceDescriptorProto parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -22037,7 +22037,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -22049,7 +22049,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.ServiceDescriptorProto} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements + com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.ServiceDescriptorProto) com.google.protobuf.DescriptorProtos.ServiceDescriptorProtoOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -22058,7 +22058,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_ServiceDescriptorProto_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -22071,12 +22071,12 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 + if (com.google.protobuf.FlattenedGeneratedMessageV3 .alwaysUseFieldBuilders) { getMethodFieldBuilder(); getOptionsFieldBuilder(); @@ -22227,7 +22227,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.ServiceDescriptorP method_ = other.method_; bitField0_ = (bitField0_ & ~0x00000002); methodBuilder_ = - com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? getMethodFieldBuilder() : null; } else { methodBuilder_.addAllMessages(other.method_); @@ -22950,12 +22950,12 @@ public interface MethodDescriptorProtoOrBuilder extends * Protobuf type {@code google.protobuf.MethodDescriptorProto} */ public static final class MethodDescriptorProto extends - com.google.protobuf.GeneratedMessageV3 implements + com.google.protobuf.FlattenedGeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:google.protobuf.MethodDescriptorProto) MethodDescriptorProtoOrBuilder { private static final long serialVersionUID = 0L; // Use MethodDescriptorProto.newBuilder() to construct. - private MethodDescriptorProto(com.google.protobuf.GeneratedMessageV3.Builder builder) { + private MethodDescriptorProto(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { super(builder); } private MethodDescriptorProto() { @@ -22977,7 +22977,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_MethodDescriptorProto_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -23248,13 +23248,13 @@ public final boolean isInitialized() { public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { if (((bitField0_ & 0x00000001) != 0)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 1, name_); + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 1, name_); } if (((bitField0_ & 0x00000002) != 0)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 2, inputType_); + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 2, inputType_); } if (((bitField0_ & 0x00000004) != 0)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 3, outputType_); + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 3, outputType_); } if (((bitField0_ & 0x00000008) != 0)) { output.writeMessage(4, getOptions()); @@ -23275,13 +23275,13 @@ public int getSerializedSize() { size = 0; if (((bitField0_ & 0x00000001) != 0)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, name_); + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(1, name_); } if (((bitField0_ & 0x00000002) != 0)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, inputType_); + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(2, inputType_); } if (((bitField0_ & 0x00000004) != 0)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(3, outputType_); + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(3, outputType_); } if (((bitField0_ & 0x00000008) != 0)) { size += com.google.protobuf.CodedOutputStream @@ -23416,20 +23416,20 @@ public static com.google.protobuf.DescriptorProtos.MethodDescriptorProto parseFr } public static com.google.protobuf.DescriptorProtos.MethodDescriptorProto parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.MethodDescriptorProto parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.MethodDescriptorProto parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -23437,20 +23437,20 @@ public static com.google.protobuf.DescriptorProtos.MethodDescriptorProto parseDe java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.MethodDescriptorProto parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.MethodDescriptorProto parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -23470,7 +23470,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -23482,7 +23482,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.MethodDescriptorProto} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements + com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.MethodDescriptorProto) com.google.protobuf.DescriptorProtos.MethodDescriptorProtoOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -23491,7 +23491,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_MethodDescriptorProto_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -23504,12 +23504,12 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 + if (com.google.protobuf.FlattenedGeneratedMessageV3 .alwaysUseFieldBuilders) { getOptionsFieldBuilder(); } @@ -24307,7 +24307,7 @@ public com.google.protobuf.DescriptorProtos.MethodDescriptorProto getDefaultInst public interface FileOptionsOrBuilder extends // @@protoc_insertion_point(interface_extends:google.protobuf.FileOptions) - com.google.protobuf.GeneratedMessageV3. + com.google.protobuf.FlattenedGeneratedMessageV3. ExtendableMessageOrBuilder { /** @@ -24960,13 +24960,13 @@ com.google.protobuf.DescriptorProtos.UninterpretedOptionOrBuilder getUninterpret * Protobuf type {@code google.protobuf.FileOptions} */ public static final class FileOptions extends - com.google.protobuf.GeneratedMessageV3.ExtendableMessage< + com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableMessage< FileOptions> implements // @@protoc_insertion_point(message_implements:google.protobuf.FileOptions) FileOptionsOrBuilder { private static final long serialVersionUID = 0L; // Use FileOptions.newBuilder() to construct. - private FileOptions(com.google.protobuf.GeneratedMessageV3.ExtendableBuilder builder) { + private FileOptions(com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableBuilder builder) { super(builder); } private FileOptions() { @@ -24998,7 +24998,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_FileOptions_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -26234,14 +26234,14 @@ public final boolean isInitialized() { @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - com.google.protobuf.GeneratedMessageV3 + com.google.protobuf.FlattenedGeneratedMessageV3 .ExtendableMessage.ExtensionWriter extensionWriter = newExtensionWriter(); if (((bitField0_ & 0x00000001) != 0)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 1, javaPackage_); + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 1, javaPackage_); } if (((bitField0_ & 0x00000002) != 0)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 8, javaOuterClassname_); + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 8, javaOuterClassname_); } if (((bitField0_ & 0x00000020) != 0)) { output.writeEnum(9, optimizeFor_); @@ -26250,7 +26250,7 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) output.writeBool(10, javaMultipleFiles_); } if (((bitField0_ & 0x00000040) != 0)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 11, goPackage_); + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 11, goPackage_); } if (((bitField0_ & 0x00000080) != 0)) { output.writeBool(16, ccGenericServices_); @@ -26274,25 +26274,25 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) output.writeBool(31, ccEnableArenas_); } if (((bitField0_ & 0x00001000) != 0)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 36, objcClassPrefix_); + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 36, objcClassPrefix_); } if (((bitField0_ & 0x00002000) != 0)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 37, csharpNamespace_); + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 37, csharpNamespace_); } if (((bitField0_ & 0x00004000) != 0)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 39, swiftPrefix_); + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 39, swiftPrefix_); } if (((bitField0_ & 0x00008000) != 0)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 40, phpClassPrefix_); + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 40, phpClassPrefix_); } if (((bitField0_ & 0x00010000) != 0)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 41, phpNamespace_); + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 41, phpNamespace_); } if (((bitField0_ & 0x00020000) != 0)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 44, phpMetadataNamespace_); + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 44, phpMetadataNamespace_); } if (((bitField0_ & 0x00040000) != 0)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 45, rubyPackage_); + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 45, rubyPackage_); } if (((bitField0_ & 0x00080000) != 0)) { output.writeMessage(50, getFeatures()); @@ -26311,10 +26311,10 @@ public int getSerializedSize() { size = 0; if (((bitField0_ & 0x00000001) != 0)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, javaPackage_); + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(1, javaPackage_); } if (((bitField0_ & 0x00000002) != 0)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(8, javaOuterClassname_); + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(8, javaOuterClassname_); } if (((bitField0_ & 0x00000020) != 0)) { size += com.google.protobuf.CodedOutputStream @@ -26325,7 +26325,7 @@ public int getSerializedSize() { .computeBoolSize(10, javaMultipleFiles_); } if (((bitField0_ & 0x00000040) != 0)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(11, goPackage_); + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(11, goPackage_); } if (((bitField0_ & 0x00000080) != 0)) { size += com.google.protobuf.CodedOutputStream @@ -26356,25 +26356,25 @@ public int getSerializedSize() { .computeBoolSize(31, ccEnableArenas_); } if (((bitField0_ & 0x00001000) != 0)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(36, objcClassPrefix_); + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(36, objcClassPrefix_); } if (((bitField0_ & 0x00002000) != 0)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(37, csharpNamespace_); + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(37, csharpNamespace_); } if (((bitField0_ & 0x00004000) != 0)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(39, swiftPrefix_); + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(39, swiftPrefix_); } if (((bitField0_ & 0x00008000) != 0)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(40, phpClassPrefix_); + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(40, phpClassPrefix_); } if (((bitField0_ & 0x00010000) != 0)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(41, phpNamespace_); + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(41, phpNamespace_); } if (((bitField0_ & 0x00020000) != 0)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(44, phpMetadataNamespace_); + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(44, phpMetadataNamespace_); } if (((bitField0_ & 0x00040000) != 0)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(45, rubyPackage_); + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(45, rubyPackage_); } if (((bitField0_ & 0x00080000) != 0)) { size += com.google.protobuf.CodedOutputStream @@ -26646,20 +26646,20 @@ public static com.google.protobuf.DescriptorProtos.FileOptions parseFrom( } public static com.google.protobuf.DescriptorProtos.FileOptions parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.FileOptions parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.FileOptions parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -26667,20 +26667,20 @@ public static com.google.protobuf.DescriptorProtos.FileOptions parseDelimitedFro java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.FileOptions parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.FileOptions parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -26700,7 +26700,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -26708,7 +26708,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.FileOptions} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.ExtendableBuilder< + com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableBuilder< com.google.protobuf.DescriptorProtos.FileOptions, Builder> implements // @@protoc_insertion_point(builder_implements:google.protobuf.FileOptions) com.google.protobuf.DescriptorProtos.FileOptionsOrBuilder { @@ -26718,7 +26718,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_FileOptions_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -26731,12 +26731,12 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 + if (com.google.protobuf.FlattenedGeneratedMessageV3 .alwaysUseFieldBuilders) { getFeaturesFieldBuilder(); getUninterpretedOptionFieldBuilder(); @@ -26941,33 +26941,33 @@ public Builder addRepeatedField( java.lang.Object value) { return super.addRepeatedField(field, value); } - @java.lang.Override - public Builder setExtension( - com.google.protobuf.GeneratedMessage.GeneratedExtension< - com.google.protobuf.DescriptorProtos.FileOptions, Type> extension, - Type value) { - return super.setExtension(extension, value); - } - @java.lang.Override - public Builder setExtension( - com.google.protobuf.GeneratedMessage.GeneratedExtension< - com.google.protobuf.DescriptorProtos.FileOptions, java.util.List> extension, - int index, Type value) { - return super.setExtension(extension, index, value); - } - @java.lang.Override - public Builder addExtension( - com.google.protobuf.GeneratedMessage.GeneratedExtension< - com.google.protobuf.DescriptorProtos.FileOptions, java.util.List> extension, - Type value) { - return super.addExtension(extension, value); - } - @java.lang.Override - public Builder clearExtension( - com.google.protobuf.GeneratedMessage.GeneratedExtension< - com.google.protobuf.DescriptorProtos.FileOptions, T> extension) { - return super.clearExtension(extension); - } +// @java.lang.Override +// public Builder setExtension( +// com.google.protobuf.GeneratedMessage.GeneratedExtension< +// com.google.protobuf.DescriptorProtos.FileOptions, Type> extension, +// Type value) { +// return super.setExtension(extension, value); +// } +// @java.lang.Override +// public Builder setExtension( +// com.google.protobuf.GeneratedMessage.GeneratedExtension< +// com.google.protobuf.DescriptorProtos.FileOptions, java.util.List> extension, +// int index, Type value) { +// return super.setExtension(extension, index, value); +// } +// @java.lang.Override +// public Builder addExtension( +// com.google.protobuf.GeneratedMessage.GeneratedExtension< +// com.google.protobuf.DescriptorProtos.FileOptions, java.util.List> extension, +// Type value) { +// return super.addExtension(extension, value); +// } +// @java.lang.Override +// public Builder clearExtension( +// com.google.protobuf.GeneratedMessage.GeneratedExtension< +// com.google.protobuf.DescriptorProtos.FileOptions, T> extension) { +// return super.clearExtension(extension); +// } @java.lang.Override public Builder mergeFrom(com.google.protobuf.Message other) { if (other instanceof com.google.protobuf.DescriptorProtos.FileOptions) { @@ -27079,7 +27079,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.FileOptions other) uninterpretedOption_ = other.uninterpretedOption_; bitField0_ = (bitField0_ & ~0x00100000); uninterpretedOptionBuilder_ = - com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? getUninterpretedOptionFieldBuilder() : null; } else { uninterpretedOptionBuilder_.addAllMessages(other.uninterpretedOption_); @@ -29590,7 +29590,7 @@ public com.google.protobuf.DescriptorProtos.FileOptions getDefaultInstanceForTyp public interface MessageOptionsOrBuilder extends // @@protoc_insertion_point(interface_extends:google.protobuf.MessageOptions) - com.google.protobuf.GeneratedMessageV3. + com.google.protobuf.FlattenedGeneratedMessageV3. ExtendableMessageOrBuilder { /** @@ -29878,13 +29878,13 @@ com.google.protobuf.DescriptorProtos.UninterpretedOptionOrBuilder getUninterpret * Protobuf type {@code google.protobuf.MessageOptions} */ public static final class MessageOptions extends - com.google.protobuf.GeneratedMessageV3.ExtendableMessage< + com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableMessage< MessageOptions> implements // @@protoc_insertion_point(message_implements:google.protobuf.MessageOptions) MessageOptionsOrBuilder { private static final long serialVersionUID = 0L; // Use MessageOptions.newBuilder() to construct. - private MessageOptions(com.google.protobuf.GeneratedMessageV3.ExtendableBuilder builder) { + private MessageOptions(com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableBuilder builder) { super(builder); } private MessageOptions() { @@ -29904,7 +29904,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_MessageOptions_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -30291,7 +30291,7 @@ public final boolean isInitialized() { @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - com.google.protobuf.GeneratedMessageV3 + com.google.protobuf.FlattenedGeneratedMessageV3 .ExtendableMessage.ExtensionWriter extensionWriter = newExtensionWriter(); if (((bitField0_ & 0x00000001) != 0)) { @@ -30487,20 +30487,20 @@ public static com.google.protobuf.DescriptorProtos.MessageOptions parseFrom( } public static com.google.protobuf.DescriptorProtos.MessageOptions parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.MessageOptions parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.MessageOptions parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -30508,20 +30508,20 @@ public static com.google.protobuf.DescriptorProtos.MessageOptions parseDelimited java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.MessageOptions parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.MessageOptions parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -30541,7 +30541,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -30549,7 +30549,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.MessageOptions} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.ExtendableBuilder< + com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableBuilder< com.google.protobuf.DescriptorProtos.MessageOptions, Builder> implements // @@protoc_insertion_point(builder_implements:google.protobuf.MessageOptions) com.google.protobuf.DescriptorProtos.MessageOptionsOrBuilder { @@ -30559,7 +30559,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_MessageOptions_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -30572,12 +30572,12 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 + if (com.google.protobuf.FlattenedGeneratedMessageV3 .alwaysUseFieldBuilders) { getFeaturesFieldBuilder(); getUninterpretedOptionFieldBuilder(); @@ -30712,33 +30712,33 @@ public Builder addRepeatedField( java.lang.Object value) { return super.addRepeatedField(field, value); } - @java.lang.Override - public Builder setExtension( - com.google.protobuf.GeneratedMessage.GeneratedExtension< - com.google.protobuf.DescriptorProtos.MessageOptions, Type> extension, - Type value) { - return super.setExtension(extension, value); - } - @java.lang.Override - public Builder setExtension( - com.google.protobuf.GeneratedMessage.GeneratedExtension< - com.google.protobuf.DescriptorProtos.MessageOptions, java.util.List> extension, - int index, Type value) { - return super.setExtension(extension, index, value); - } - @java.lang.Override - public Builder addExtension( - com.google.protobuf.GeneratedMessage.GeneratedExtension< - com.google.protobuf.DescriptorProtos.MessageOptions, java.util.List> extension, - Type value) { - return super.addExtension(extension, value); - } - @java.lang.Override - public Builder clearExtension( - com.google.protobuf.GeneratedMessage.GeneratedExtension< - com.google.protobuf.DescriptorProtos.MessageOptions, T> extension) { - return super.clearExtension(extension); - } +// @java.lang.Override +// public Builder setExtension( +// com.google.protobuf.GeneratedMessage.GeneratedExtension< +// com.google.protobuf.DescriptorProtos.MessageOptions, Type> extension, +// Type value) { +// return super.setExtension(extension, value); +// } +// @java.lang.Override +// public Builder setExtension( +// com.google.protobuf.GeneratedMessage.GeneratedExtension< +// com.google.protobuf.DescriptorProtos.MessageOptions, java.util.List> extension, +// int index, Type value) { +// return super.setExtension(extension, index, value); +// } +// @java.lang.Override +// public Builder addExtension( +// com.google.protobuf.GeneratedMessage.GeneratedExtension< +// com.google.protobuf.DescriptorProtos.MessageOptions, java.util.List> extension, +// Type value) { +// return super.addExtension(extension, value); +// } +// @java.lang.Override +// public Builder clearExtension( +// com.google.protobuf.GeneratedMessage.GeneratedExtension< +// com.google.protobuf.DescriptorProtos.MessageOptions, T> extension) { +// return super.clearExtension(extension); +// } @java.lang.Override public Builder mergeFrom(com.google.protobuf.Message other) { if (other instanceof com.google.protobuf.DescriptorProtos.MessageOptions) { @@ -30788,7 +30788,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.MessageOptions oth uninterpretedOption_ = other.uninterpretedOption_; bitField0_ = (bitField0_ & ~0x00000040); uninterpretedOptionBuilder_ = - com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? getUninterpretedOptionFieldBuilder() : null; } else { uninterpretedOptionBuilder_.addAllMessages(other.uninterpretedOption_); @@ -31950,7 +31950,7 @@ public com.google.protobuf.DescriptorProtos.MessageOptions getDefaultInstanceFor public interface FieldOptionsOrBuilder extends // @@protoc_insertion_point(interface_extends:google.protobuf.FieldOptions) - com.google.protobuf.GeneratedMessageV3. + com.google.protobuf.FlattenedGeneratedMessageV3. ExtendableMessageOrBuilder { /** @@ -32354,13 +32354,13 @@ com.google.protobuf.DescriptorProtos.UninterpretedOptionOrBuilder getUninterpret * Protobuf type {@code google.protobuf.FieldOptions} */ public static final class FieldOptions extends - com.google.protobuf.GeneratedMessageV3.ExtendableMessage< + com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableMessage< FieldOptions> implements // @@protoc_insertion_point(message_implements:google.protobuf.FieldOptions) FieldOptionsOrBuilder { private static final long serialVersionUID = 0L; // Use FieldOptions.newBuilder() to construct. - private FieldOptions(com.google.protobuf.GeneratedMessageV3.ExtendableBuilder builder) { + private FieldOptions(com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableBuilder builder) { super(builder); } private FieldOptions() { @@ -32385,7 +32385,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_FieldOptions_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -32983,12 +32983,12 @@ public interface EditionDefaultOrBuilder extends * Protobuf type {@code google.protobuf.FieldOptions.EditionDefault} */ public static final class EditionDefault extends - com.google.protobuf.GeneratedMessageV3 implements + com.google.protobuf.FlattenedGeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:google.protobuf.FieldOptions.EditionDefault) EditionDefaultOrBuilder { private static final long serialVersionUID = 0L; // Use EditionDefault.newBuilder() to construct. - private EditionDefault(com.google.protobuf.GeneratedMessageV3.Builder builder) { + private EditionDefault(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { super(builder); } private EditionDefault() { @@ -33009,7 +33009,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_FieldOptions_EditionDefault_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -33111,7 +33111,7 @@ public final boolean isInitialized() { public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { if (((bitField0_ & 0x00000002) != 0)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 2, value_); + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 2, value_); } if (((bitField0_ & 0x00000001) != 0)) { output.writeEnum(3, edition_); @@ -33126,7 +33126,7 @@ public int getSerializedSize() { size = 0; if (((bitField0_ & 0x00000002) != 0)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, value_); + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(2, value_); } if (((bitField0_ & 0x00000001) != 0)) { size += com.google.protobuf.CodedOutputStream @@ -33214,20 +33214,20 @@ public static com.google.protobuf.DescriptorProtos.FieldOptions.EditionDefault p } public static com.google.protobuf.DescriptorProtos.FieldOptions.EditionDefault parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.FieldOptions.EditionDefault parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.FieldOptions.EditionDefault parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -33235,20 +33235,20 @@ public static com.google.protobuf.DescriptorProtos.FieldOptions.EditionDefault p java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.FieldOptions.EditionDefault parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.FieldOptions.EditionDefault parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -33268,7 +33268,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -33276,7 +33276,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.FieldOptions.EditionDefault} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements + com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.FieldOptions.EditionDefault) com.google.protobuf.DescriptorProtos.FieldOptions.EditionDefaultOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -33285,7 +33285,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_FieldOptions_EditionDefault_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -33298,7 +33298,7 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); } @@ -33785,12 +33785,12 @@ public interface FeatureSupportOrBuilder extends * Protobuf type {@code google.protobuf.FieldOptions.FeatureSupport} */ public static final class FeatureSupport extends - com.google.protobuf.GeneratedMessageV3 implements + com.google.protobuf.FlattenedGeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:google.protobuf.FieldOptions.FeatureSupport) FeatureSupportOrBuilder { private static final long serialVersionUID = 0L; // Use FeatureSupport.newBuilder() to construct. - private FeatureSupport(com.google.protobuf.GeneratedMessageV3.Builder builder) { + private FeatureSupport(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { super(builder); } private FeatureSupport() { @@ -33813,7 +33813,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_FieldOptions_FeatureSupport_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -33994,7 +33994,7 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) output.writeEnum(2, editionDeprecated_); } if (((bitField0_ & 0x00000004) != 0)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 3, deprecationWarning_); + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 3, deprecationWarning_); } if (((bitField0_ & 0x00000008) != 0)) { output.writeEnum(4, editionRemoved_); @@ -34017,7 +34017,7 @@ public int getSerializedSize() { .computeEnumSize(2, editionDeprecated_); } if (((bitField0_ & 0x00000004) != 0)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(3, deprecationWarning_); + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(3, deprecationWarning_); } if (((bitField0_ & 0x00000008) != 0)) { size += com.google.protobuf.CodedOutputStream @@ -34121,20 +34121,20 @@ public static com.google.protobuf.DescriptorProtos.FieldOptions.FeatureSupport p } public static com.google.protobuf.DescriptorProtos.FieldOptions.FeatureSupport parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.FieldOptions.FeatureSupport parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.FieldOptions.FeatureSupport parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -34142,20 +34142,20 @@ public static com.google.protobuf.DescriptorProtos.FieldOptions.FeatureSupport p java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.FieldOptions.FeatureSupport parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.FieldOptions.FeatureSupport parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -34175,7 +34175,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -34187,7 +34187,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.FieldOptions.FeatureSupport} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements + com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.FieldOptions.FeatureSupport) com.google.protobuf.DescriptorProtos.FieldOptions.FeatureSupportOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -34196,7 +34196,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_FieldOptions_FeatureSupport_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -34209,7 +34209,7 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); } @@ -35358,7 +35358,7 @@ public final boolean isInitialized() { @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - com.google.protobuf.GeneratedMessageV3 + com.google.protobuf.FlattenedGeneratedMessageV3 .ExtendableMessage.ExtensionWriter extensionWriter = newExtensionWriter(); if (((bitField0_ & 0x00000001) != 0)) { @@ -35662,20 +35662,20 @@ public static com.google.protobuf.DescriptorProtos.FieldOptions parseFrom( } public static com.google.protobuf.DescriptorProtos.FieldOptions parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.FieldOptions parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.FieldOptions parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -35683,20 +35683,20 @@ public static com.google.protobuf.DescriptorProtos.FieldOptions parseDelimitedFr java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.FieldOptions parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.FieldOptions parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -35716,7 +35716,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -35724,7 +35724,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.FieldOptions} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.ExtendableBuilder< + com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableBuilder< com.google.protobuf.DescriptorProtos.FieldOptions, Builder> implements // @@protoc_insertion_point(builder_implements:google.protobuf.FieldOptions) com.google.protobuf.DescriptorProtos.FieldOptionsOrBuilder { @@ -35734,7 +35734,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_FieldOptions_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -35747,12 +35747,12 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 + if (com.google.protobuf.FlattenedGeneratedMessageV3 .alwaysUseFieldBuilders) { getEditionDefaultsFieldBuilder(); getFeaturesFieldBuilder(); @@ -35943,33 +35943,33 @@ public Builder addRepeatedField( java.lang.Object value) { return super.addRepeatedField(field, value); } - @java.lang.Override - public Builder setExtension( - com.google.protobuf.GeneratedMessage.GeneratedExtension< - com.google.protobuf.DescriptorProtos.FieldOptions, Type> extension, - Type value) { - return super.setExtension(extension, value); - } - @java.lang.Override - public Builder setExtension( - com.google.protobuf.GeneratedMessage.GeneratedExtension< - com.google.protobuf.DescriptorProtos.FieldOptions, java.util.List> extension, - int index, Type value) { - return super.setExtension(extension, index, value); - } - @java.lang.Override - public Builder addExtension( - com.google.protobuf.GeneratedMessage.GeneratedExtension< - com.google.protobuf.DescriptorProtos.FieldOptions, java.util.List> extension, - Type value) { - return super.addExtension(extension, value); - } - @java.lang.Override - public Builder clearExtension( - com.google.protobuf.GeneratedMessage.GeneratedExtension< - com.google.protobuf.DescriptorProtos.FieldOptions, T> extension) { - return super.clearExtension(extension); - } +// @java.lang.Override +// public Builder setExtension( +// com.google.protobuf.GeneratedMessage.GeneratedExtension< +// com.google.protobuf.DescriptorProtos.FieldOptions, Type> extension, +// Type value) { +// return super.setExtension(extension, value); +// } +// @java.lang.Override +// public Builder setExtension( +// com.google.protobuf.GeneratedMessage.GeneratedExtension< +// com.google.protobuf.DescriptorProtos.FieldOptions, java.util.List> extension, +// int index, Type value) { +// return super.setExtension(extension, index, value); +// } +// @java.lang.Override +// public Builder addExtension( +// com.google.protobuf.GeneratedMessage.GeneratedExtension< +// com.google.protobuf.DescriptorProtos.FieldOptions, java.util.List> extension, +// Type value) { +// return super.addExtension(extension, value); +// } +// @java.lang.Override +// public Builder clearExtension( +// com.google.protobuf.GeneratedMessage.GeneratedExtension< +// com.google.protobuf.DescriptorProtos.FieldOptions, T> extension) { +// return super.clearExtension(extension); +// } @java.lang.Override public Builder mergeFrom(com.google.protobuf.Message other) { if (other instanceof com.google.protobuf.DescriptorProtos.FieldOptions) { @@ -36038,7 +36038,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.FieldOptions other editionDefaults_ = other.editionDefaults_; bitField0_ = (bitField0_ & ~0x00000400); editionDefaultsBuilder_ = - com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? getEditionDefaultsFieldBuilder() : null; } else { editionDefaultsBuilder_.addAllMessages(other.editionDefaults_); @@ -36070,7 +36070,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.FieldOptions other uninterpretedOption_ = other.uninterpretedOption_; bitField0_ = (bitField0_ & ~0x00002000); uninterpretedOptionBuilder_ = - com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? getUninterpretedOptionFieldBuilder() : null; } else { uninterpretedOptionBuilder_.addAllMessages(other.uninterpretedOption_); @@ -37967,7 +37967,7 @@ public com.google.protobuf.DescriptorProtos.FieldOptions getDefaultInstanceForTy public interface OneofOptionsOrBuilder extends // @@protoc_insertion_point(interface_extends:google.protobuf.OneofOptions) - com.google.protobuf.GeneratedMessageV3. + com.google.protobuf.FlattenedGeneratedMessageV3. ExtendableMessageOrBuilder { /** @@ -38054,13 +38054,13 @@ com.google.protobuf.DescriptorProtos.UninterpretedOptionOrBuilder getUninterpret * Protobuf type {@code google.protobuf.OneofOptions} */ public static final class OneofOptions extends - com.google.protobuf.GeneratedMessageV3.ExtendableMessage< + com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableMessage< OneofOptions> implements // @@protoc_insertion_point(message_implements:google.protobuf.OneofOptions) OneofOptionsOrBuilder { private static final long serialVersionUID = 0L; // Use OneofOptions.newBuilder() to construct. - private OneofOptions(com.google.protobuf.GeneratedMessageV3.ExtendableBuilder builder) { + private OneofOptions(com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableBuilder builder) { super(builder); } private OneofOptions() { @@ -38080,7 +38080,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_OneofOptions_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -38226,7 +38226,7 @@ public final boolean isInitialized() { @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - com.google.protobuf.GeneratedMessageV3 + com.google.protobuf.FlattenedGeneratedMessageV3 .ExtendableMessage.ExtensionWriter extensionWriter = newExtensionWriter(); if (((bitField0_ & 0x00000001) != 0)) { @@ -38337,20 +38337,20 @@ public static com.google.protobuf.DescriptorProtos.OneofOptions parseFrom( } public static com.google.protobuf.DescriptorProtos.OneofOptions parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.OneofOptions parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.OneofOptions parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -38358,20 +38358,20 @@ public static com.google.protobuf.DescriptorProtos.OneofOptions parseDelimitedFr java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.OneofOptions parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.OneofOptions parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -38391,7 +38391,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -38399,7 +38399,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.OneofOptions} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.ExtendableBuilder< + com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableBuilder< com.google.protobuf.DescriptorProtos.OneofOptions, Builder> implements // @@protoc_insertion_point(builder_implements:google.protobuf.OneofOptions) com.google.protobuf.DescriptorProtos.OneofOptionsOrBuilder { @@ -38409,7 +38409,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_OneofOptions_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -38422,12 +38422,12 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 + if (com.google.protobuf.FlattenedGeneratedMessageV3 .alwaysUseFieldBuilders) { getFeaturesFieldBuilder(); getUninterpretedOptionFieldBuilder(); @@ -38537,33 +38537,33 @@ public Builder addRepeatedField( java.lang.Object value) { return super.addRepeatedField(field, value); } - @java.lang.Override - public Builder setExtension( - com.google.protobuf.GeneratedMessage.GeneratedExtension< - com.google.protobuf.DescriptorProtos.OneofOptions, Type> extension, - Type value) { - return super.setExtension(extension, value); - } - @java.lang.Override - public Builder setExtension( - com.google.protobuf.GeneratedMessage.GeneratedExtension< - com.google.protobuf.DescriptorProtos.OneofOptions, java.util.List> extension, - int index, Type value) { - return super.setExtension(extension, index, value); - } - @java.lang.Override - public Builder addExtension( - com.google.protobuf.GeneratedMessage.GeneratedExtension< - com.google.protobuf.DescriptorProtos.OneofOptions, java.util.List> extension, - Type value) { - return super.addExtension(extension, value); - } - @java.lang.Override - public Builder clearExtension( - com.google.protobuf.GeneratedMessage.GeneratedExtension< - com.google.protobuf.DescriptorProtos.OneofOptions, T> extension) { - return super.clearExtension(extension); - } +// @java.lang.Override +// public Builder setExtension( +// com.google.protobuf.GeneratedMessage.GeneratedExtension< +// com.google.protobuf.DescriptorProtos.OneofOptions, Type> extension, +// Type value) { +// return super.setExtension(extension, value); +// } +// @java.lang.Override +// public Builder setExtension( +// com.google.protobuf.GeneratedMessage.GeneratedExtension< +// com.google.protobuf.DescriptorProtos.OneofOptions, java.util.List> extension, +// int index, Type value) { +// return super.setExtension(extension, index, value); +// } +// @java.lang.Override +// public Builder addExtension( +// com.google.protobuf.GeneratedMessage.GeneratedExtension< +// com.google.protobuf.DescriptorProtos.OneofOptions, java.util.List> extension, +// Type value) { +// return super.addExtension(extension, value); +// } +// @java.lang.Override +// public Builder clearExtension( +// com.google.protobuf.GeneratedMessage.GeneratedExtension< +// com.google.protobuf.DescriptorProtos.OneofOptions, T> extension) { +// return super.clearExtension(extension); +// } @java.lang.Override public Builder mergeFrom(com.google.protobuf.Message other) { if (other instanceof com.google.protobuf.DescriptorProtos.OneofOptions) { @@ -38598,7 +38598,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.OneofOptions other uninterpretedOption_ = other.uninterpretedOption_; bitField0_ = (bitField0_ & ~0x00000002); uninterpretedOptionBuilder_ = - com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? getUninterpretedOptionFieldBuilder() : null; } else { uninterpretedOptionBuilder_.addAllMessages(other.uninterpretedOption_); @@ -39243,7 +39243,7 @@ public com.google.protobuf.DescriptorProtos.OneofOptions getDefaultInstanceForTy public interface EnumOptionsOrBuilder extends // @@protoc_insertion_point(interface_extends:google.protobuf.EnumOptions) - com.google.protobuf.GeneratedMessageV3. + com.google.protobuf.FlattenedGeneratedMessageV3. ExtendableMessageOrBuilder { /** @@ -39409,13 +39409,13 @@ com.google.protobuf.DescriptorProtos.UninterpretedOptionOrBuilder getUninterpret * Protobuf type {@code google.protobuf.EnumOptions} */ public static final class EnumOptions extends - com.google.protobuf.GeneratedMessageV3.ExtendableMessage< + com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableMessage< EnumOptions> implements // @@protoc_insertion_point(message_implements:google.protobuf.EnumOptions) EnumOptionsOrBuilder { private static final long serialVersionUID = 0L; // Use EnumOptions.newBuilder() to construct. - private EnumOptions(com.google.protobuf.GeneratedMessageV3.ExtendableBuilder builder) { + private EnumOptions(com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableBuilder builder) { super(builder); } private EnumOptions() { @@ -39435,7 +39435,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_EnumOptions_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -39684,7 +39684,7 @@ public final boolean isInitialized() { @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - com.google.protobuf.GeneratedMessageV3 + com.google.protobuf.FlattenedGeneratedMessageV3 .ExtendableMessage.ExtensionWriter extensionWriter = newExtensionWriter(); if (((bitField0_ & 0x00000001) != 0)) { @@ -39846,20 +39846,20 @@ public static com.google.protobuf.DescriptorProtos.EnumOptions parseFrom( } public static com.google.protobuf.DescriptorProtos.EnumOptions parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.EnumOptions parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.EnumOptions parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -39867,20 +39867,20 @@ public static com.google.protobuf.DescriptorProtos.EnumOptions parseDelimitedFro java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.EnumOptions parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.EnumOptions parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -39900,7 +39900,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -39908,7 +39908,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.EnumOptions} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.ExtendableBuilder< + com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableBuilder< com.google.protobuf.DescriptorProtos.EnumOptions, Builder> implements // @@protoc_insertion_point(builder_implements:google.protobuf.EnumOptions) com.google.protobuf.DescriptorProtos.EnumOptionsOrBuilder { @@ -39918,7 +39918,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_EnumOptions_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -39931,12 +39931,12 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 + if (com.google.protobuf.FlattenedGeneratedMessageV3 .alwaysUseFieldBuilders) { getFeaturesFieldBuilder(); getUninterpretedOptionFieldBuilder(); @@ -40061,33 +40061,33 @@ public Builder addRepeatedField( java.lang.Object value) { return super.addRepeatedField(field, value); } - @java.lang.Override - public Builder setExtension( - com.google.protobuf.GeneratedMessage.GeneratedExtension< - com.google.protobuf.DescriptorProtos.EnumOptions, Type> extension, - Type value) { - return super.setExtension(extension, value); - } - @java.lang.Override - public Builder setExtension( - com.google.protobuf.GeneratedMessage.GeneratedExtension< - com.google.protobuf.DescriptorProtos.EnumOptions, java.util.List> extension, - int index, Type value) { - return super.setExtension(extension, index, value); - } - @java.lang.Override - public Builder addExtension( - com.google.protobuf.GeneratedMessage.GeneratedExtension< - com.google.protobuf.DescriptorProtos.EnumOptions, java.util.List> extension, - Type value) { - return super.addExtension(extension, value); - } - @java.lang.Override - public Builder clearExtension( - com.google.protobuf.GeneratedMessage.GeneratedExtension< - com.google.protobuf.DescriptorProtos.EnumOptions, T> extension) { - return super.clearExtension(extension); - } +// @java.lang.Override +// public Builder setExtension( +// com.google.protobuf.GeneratedMessage.GeneratedExtension< +// com.google.protobuf.DescriptorProtos.EnumOptions, Type> extension, +// Type value) { +// return super.setExtension(extension, value); +// } +// @java.lang.Override +// public Builder setExtension( +// com.google.protobuf.GeneratedMessage.GeneratedExtension< +// com.google.protobuf.DescriptorProtos.EnumOptions, java.util.List> extension, +// int index, Type value) { +// return super.setExtension(extension, index, value); +// } +// @java.lang.Override +// public Builder addExtension( +// com.google.protobuf.GeneratedMessage.GeneratedExtension< +// com.google.protobuf.DescriptorProtos.EnumOptions, java.util.List> extension, +// Type value) { +// return super.addExtension(extension, value); +// } +// @java.lang.Override +// public Builder clearExtension( +// com.google.protobuf.GeneratedMessage.GeneratedExtension< +// com.google.protobuf.DescriptorProtos.EnumOptions, T> extension) { +// return super.clearExtension(extension); +// } @java.lang.Override public Builder mergeFrom(com.google.protobuf.Message other) { if (other instanceof com.google.protobuf.DescriptorProtos.EnumOptions) { @@ -40131,7 +40131,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.EnumOptions other) uninterpretedOption_ = other.uninterpretedOption_; bitField0_ = (bitField0_ & ~0x00000010); uninterpretedOptionBuilder_ = - com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? getUninterpretedOptionFieldBuilder() : null; } else { uninterpretedOptionBuilder_.addAllMessages(other.uninterpretedOption_); @@ -41003,7 +41003,7 @@ public com.google.protobuf.DescriptorProtos.EnumOptions getDefaultInstanceForTyp public interface EnumValueOptionsOrBuilder extends // @@protoc_insertion_point(interface_extends:google.protobuf.EnumValueOptions) - com.google.protobuf.GeneratedMessageV3. + com.google.protobuf.FlattenedGeneratedMessageV3. ExtendableMessageOrBuilder { /** @@ -41165,13 +41165,13 @@ com.google.protobuf.DescriptorProtos.UninterpretedOptionOrBuilder getUninterpret * Protobuf type {@code google.protobuf.EnumValueOptions} */ public static final class EnumValueOptions extends - com.google.protobuf.GeneratedMessageV3.ExtendableMessage< + com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableMessage< EnumValueOptions> implements // @@protoc_insertion_point(message_implements:google.protobuf.EnumValueOptions) EnumValueOptionsOrBuilder { private static final long serialVersionUID = 0L; // Use EnumValueOptions.newBuilder() to construct. - private EnumValueOptions(com.google.protobuf.GeneratedMessageV3.ExtendableBuilder builder) { + private EnumValueOptions(com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableBuilder builder) { super(builder); } private EnumValueOptions() { @@ -41191,7 +41191,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_EnumValueOptions_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -41439,7 +41439,7 @@ public final boolean isInitialized() { @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - com.google.protobuf.GeneratedMessageV3 + com.google.protobuf.FlattenedGeneratedMessageV3 .ExtendableMessage.ExtensionWriter extensionWriter = newExtensionWriter(); if (((bitField0_ & 0x00000001) != 0)) { @@ -41600,20 +41600,20 @@ public static com.google.protobuf.DescriptorProtos.EnumValueOptions parseFrom( } public static com.google.protobuf.DescriptorProtos.EnumValueOptions parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.EnumValueOptions parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.EnumValueOptions parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -41621,20 +41621,20 @@ public static com.google.protobuf.DescriptorProtos.EnumValueOptions parseDelimit java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.EnumValueOptions parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.EnumValueOptions parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -41654,7 +41654,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -41662,7 +41662,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.EnumValueOptions} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.ExtendableBuilder< + com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableBuilder< com.google.protobuf.DescriptorProtos.EnumValueOptions, Builder> implements // @@protoc_insertion_point(builder_implements:google.protobuf.EnumValueOptions) com.google.protobuf.DescriptorProtos.EnumValueOptionsOrBuilder { @@ -41672,7 +41672,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_EnumValueOptions_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -41685,12 +41685,12 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 + if (com.google.protobuf.FlattenedGeneratedMessageV3 .alwaysUseFieldBuilders) { getFeaturesFieldBuilder(); getFeatureSupportFieldBuilder(); @@ -41822,33 +41822,33 @@ public Builder addRepeatedField( java.lang.Object value) { return super.addRepeatedField(field, value); } - @java.lang.Override - public Builder setExtension( - com.google.protobuf.GeneratedMessage.GeneratedExtension< - com.google.protobuf.DescriptorProtos.EnumValueOptions, Type> extension, - Type value) { - return super.setExtension(extension, value); - } - @java.lang.Override - public Builder setExtension( - com.google.protobuf.GeneratedMessage.GeneratedExtension< - com.google.protobuf.DescriptorProtos.EnumValueOptions, java.util.List> extension, - int index, Type value) { - return super.setExtension(extension, index, value); - } - @java.lang.Override - public Builder addExtension( - com.google.protobuf.GeneratedMessage.GeneratedExtension< - com.google.protobuf.DescriptorProtos.EnumValueOptions, java.util.List> extension, - Type value) { - return super.addExtension(extension, value); - } - @java.lang.Override - public Builder clearExtension( - com.google.protobuf.GeneratedMessage.GeneratedExtension< - com.google.protobuf.DescriptorProtos.EnumValueOptions, T> extension) { - return super.clearExtension(extension); - } +// @java.lang.Override +// public Builder setExtension( +// com.google.protobuf.GeneratedMessage.GeneratedExtension< +// com.google.protobuf.DescriptorProtos.EnumValueOptions, Type> extension, +// Type value) { +// return super.setExtension(extension, value); +// } +// @java.lang.Override +// public Builder setExtension( +// com.google.protobuf.GeneratedMessage.GeneratedExtension< +// com.google.protobuf.DescriptorProtos.EnumValueOptions, java.util.List> extension, +// int index, Type value) { +// return super.setExtension(extension, index, value); +// } +// @java.lang.Override +// public Builder addExtension( +// com.google.protobuf.GeneratedMessage.GeneratedExtension< +// com.google.protobuf.DescriptorProtos.EnumValueOptions, java.util.List> extension, +// Type value) { +// return super.addExtension(extension, value); +// } +// @java.lang.Override +// public Builder clearExtension( +// com.google.protobuf.GeneratedMessage.GeneratedExtension< +// com.google.protobuf.DescriptorProtos.EnumValueOptions, T> extension) { +// return super.clearExtension(extension); +// } @java.lang.Override public Builder mergeFrom(com.google.protobuf.Message other) { if (other instanceof com.google.protobuf.DescriptorProtos.EnumValueOptions) { @@ -41892,7 +41892,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.EnumValueOptions o uninterpretedOption_ = other.uninterpretedOption_; bitField0_ = (bitField0_ & ~0x00000010); uninterpretedOptionBuilder_ = - com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? getUninterpretedOptionFieldBuilder() : null; } else { uninterpretedOptionBuilder_.addAllMessages(other.uninterpretedOption_); @@ -42843,7 +42843,7 @@ public com.google.protobuf.DescriptorProtos.EnumValueOptions getDefaultInstanceF public interface ServiceOptionsOrBuilder extends // @@protoc_insertion_point(interface_extends:google.protobuf.ServiceOptions) - com.google.protobuf.GeneratedMessageV3. + com.google.protobuf.FlattenedGeneratedMessageV3. ExtendableMessageOrBuilder { /** @@ -42955,13 +42955,13 @@ com.google.protobuf.DescriptorProtos.UninterpretedOptionOrBuilder getUninterpret * Protobuf type {@code google.protobuf.ServiceOptions} */ public static final class ServiceOptions extends - com.google.protobuf.GeneratedMessageV3.ExtendableMessage< + com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableMessage< ServiceOptions> implements // @@protoc_insertion_point(message_implements:google.protobuf.ServiceOptions) ServiceOptionsOrBuilder { private static final long serialVersionUID = 0L; // Use ServiceOptions.newBuilder() to construct. - private ServiceOptions(com.google.protobuf.GeneratedMessageV3.ExtendableBuilder builder) { + private ServiceOptions(com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableBuilder builder) { super(builder); } private ServiceOptions() { @@ -42981,7 +42981,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_ServiceOptions_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -43160,7 +43160,7 @@ public final boolean isInitialized() { @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - com.google.protobuf.GeneratedMessageV3 + com.google.protobuf.FlattenedGeneratedMessageV3 .ExtendableMessage.ExtensionWriter extensionWriter = newExtensionWriter(); if (((bitField0_ & 0x00000002) != 0)) { @@ -43288,20 +43288,20 @@ public static com.google.protobuf.DescriptorProtos.ServiceOptions parseFrom( } public static com.google.protobuf.DescriptorProtos.ServiceOptions parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.ServiceOptions parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.ServiceOptions parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -43309,20 +43309,20 @@ public static com.google.protobuf.DescriptorProtos.ServiceOptions parseDelimited java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.ServiceOptions parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.ServiceOptions parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -43342,7 +43342,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -43350,7 +43350,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.ServiceOptions} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.ExtendableBuilder< + com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableBuilder< com.google.protobuf.DescriptorProtos.ServiceOptions, Builder> implements // @@protoc_insertion_point(builder_implements:google.protobuf.ServiceOptions) com.google.protobuf.DescriptorProtos.ServiceOptionsOrBuilder { @@ -43360,7 +43360,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_ServiceOptions_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -43373,12 +43373,12 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 + if (com.google.protobuf.FlattenedGeneratedMessageV3 .alwaysUseFieldBuilders) { getFeaturesFieldBuilder(); getUninterpretedOptionFieldBuilder(); @@ -43493,33 +43493,33 @@ public Builder addRepeatedField( java.lang.Object value) { return super.addRepeatedField(field, value); } - @java.lang.Override - public Builder setExtension( - com.google.protobuf.GeneratedMessage.GeneratedExtension< - com.google.protobuf.DescriptorProtos.ServiceOptions, Type> extension, - Type value) { - return super.setExtension(extension, value); - } - @java.lang.Override - public Builder setExtension( - com.google.protobuf.GeneratedMessage.GeneratedExtension< - com.google.protobuf.DescriptorProtos.ServiceOptions, java.util.List> extension, - int index, Type value) { - return super.setExtension(extension, index, value); - } - @java.lang.Override - public Builder addExtension( - com.google.protobuf.GeneratedMessage.GeneratedExtension< - com.google.protobuf.DescriptorProtos.ServiceOptions, java.util.List> extension, - Type value) { - return super.addExtension(extension, value); - } - @java.lang.Override - public Builder clearExtension( - com.google.protobuf.GeneratedMessage.GeneratedExtension< - com.google.protobuf.DescriptorProtos.ServiceOptions, T> extension) { - return super.clearExtension(extension); - } +// @java.lang.Override +// public Builder setExtension( +// com.google.protobuf.GeneratedMessage.GeneratedExtension< +// com.google.protobuf.DescriptorProtos.ServiceOptions, Type> extension, +// Type value) { +// return super.setExtension(extension, value); +// } +// @java.lang.Override +// public Builder setExtension( +// com.google.protobuf.GeneratedMessage.GeneratedExtension< +// com.google.protobuf.DescriptorProtos.ServiceOptions, java.util.List> extension, +// int index, Type value) { +// return super.setExtension(extension, index, value); +// } +// @java.lang.Override +// public Builder addExtension( +// com.google.protobuf.GeneratedMessage.GeneratedExtension< +// com.google.protobuf.DescriptorProtos.ServiceOptions, java.util.List> extension, +// Type value) { +// return super.addExtension(extension, value); +// } +// @java.lang.Override +// public Builder clearExtension( +// com.google.protobuf.GeneratedMessage.GeneratedExtension< +// com.google.protobuf.DescriptorProtos.ServiceOptions, T> extension) { +// return super.clearExtension(extension); +// } @java.lang.Override public Builder mergeFrom(com.google.protobuf.Message other) { if (other instanceof com.google.protobuf.DescriptorProtos.ServiceOptions) { @@ -43557,7 +43557,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.ServiceOptions oth uninterpretedOption_ = other.uninterpretedOption_; bitField0_ = (bitField0_ & ~0x00000004); uninterpretedOptionBuilder_ = - com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? getUninterpretedOptionFieldBuilder() : null; } else { uninterpretedOptionBuilder_.addAllMessages(other.uninterpretedOption_); @@ -44275,7 +44275,7 @@ public com.google.protobuf.DescriptorProtos.ServiceOptions getDefaultInstanceFor public interface MethodOptionsOrBuilder extends // @@protoc_insertion_point(interface_extends:google.protobuf.MethodOptions) - com.google.protobuf.GeneratedMessageV3. + com.google.protobuf.FlattenedGeneratedMessageV3. ExtendableMessageOrBuilder { /** @@ -44398,13 +44398,13 @@ com.google.protobuf.DescriptorProtos.UninterpretedOptionOrBuilder getUninterpret * Protobuf type {@code google.protobuf.MethodOptions} */ public static final class MethodOptions extends - com.google.protobuf.GeneratedMessageV3.ExtendableMessage< + com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableMessage< MethodOptions> implements // @@protoc_insertion_point(message_implements:google.protobuf.MethodOptions) MethodOptionsOrBuilder { private static final long serialVersionUID = 0L; // Use MethodOptions.newBuilder() to construct. - private MethodOptions(com.google.protobuf.GeneratedMessageV3.ExtendableBuilder builder) { + private MethodOptions(com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableBuilder builder) { super(builder); } private MethodOptions() { @@ -44425,7 +44425,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_MethodOptions_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -44749,7 +44749,7 @@ public final boolean isInitialized() { @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - com.google.protobuf.GeneratedMessageV3 + com.google.protobuf.FlattenedGeneratedMessageV3 .ExtendableMessage.ExtensionWriter extensionWriter = newExtensionWriter(); if (((bitField0_ & 0x00000001) != 0)) { @@ -44892,20 +44892,20 @@ public static com.google.protobuf.DescriptorProtos.MethodOptions parseFrom( } public static com.google.protobuf.DescriptorProtos.MethodOptions parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.MethodOptions parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.MethodOptions parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -44913,20 +44913,20 @@ public static com.google.protobuf.DescriptorProtos.MethodOptions parseDelimitedF java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.MethodOptions parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.MethodOptions parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -44946,7 +44946,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -44954,7 +44954,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.MethodOptions} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.ExtendableBuilder< + com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableBuilder< com.google.protobuf.DescriptorProtos.MethodOptions, Builder> implements // @@protoc_insertion_point(builder_implements:google.protobuf.MethodOptions) com.google.protobuf.DescriptorProtos.MethodOptionsOrBuilder { @@ -44964,7 +44964,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_MethodOptions_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -44977,12 +44977,12 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 + if (com.google.protobuf.FlattenedGeneratedMessageV3 .alwaysUseFieldBuilders) { getFeaturesFieldBuilder(); getUninterpretedOptionFieldBuilder(); @@ -45102,33 +45102,33 @@ public Builder addRepeatedField( java.lang.Object value) { return super.addRepeatedField(field, value); } - @java.lang.Override - public Builder setExtension( - com.google.protobuf.GeneratedMessage.GeneratedExtension< - com.google.protobuf.DescriptorProtos.MethodOptions, Type> extension, - Type value) { - return super.setExtension(extension, value); - } - @java.lang.Override - public Builder setExtension( - com.google.protobuf.GeneratedMessage.GeneratedExtension< - com.google.protobuf.DescriptorProtos.MethodOptions, java.util.List> extension, - int index, Type value) { - return super.setExtension(extension, index, value); - } - @java.lang.Override - public Builder addExtension( - com.google.protobuf.GeneratedMessage.GeneratedExtension< - com.google.protobuf.DescriptorProtos.MethodOptions, java.util.List> extension, - Type value) { - return super.addExtension(extension, value); - } - @java.lang.Override - public Builder clearExtension( - com.google.protobuf.GeneratedMessage.GeneratedExtension< - com.google.protobuf.DescriptorProtos.MethodOptions, T> extension) { - return super.clearExtension(extension); - } +// @java.lang.Override +// public Builder setExtension( +// com.google.protobuf.GeneratedMessage.GeneratedExtension< +// com.google.protobuf.DescriptorProtos.MethodOptions, Type> extension, +// Type value) { +// return super.setExtension(extension, value); +// } +// @java.lang.Override +// public Builder setExtension( +// com.google.protobuf.GeneratedMessage.GeneratedExtension< +// com.google.protobuf.DescriptorProtos.MethodOptions, java.util.List> extension, +// int index, Type value) { +// return super.setExtension(extension, index, value); +// } +// @java.lang.Override +// public Builder addExtension( +// com.google.protobuf.GeneratedMessage.GeneratedExtension< +// com.google.protobuf.DescriptorProtos.MethodOptions, java.util.List> extension, +// Type value) { +// return super.addExtension(extension, value); +// } +// @java.lang.Override +// public Builder clearExtension( +// com.google.protobuf.GeneratedMessage.GeneratedExtension< +// com.google.protobuf.DescriptorProtos.MethodOptions, T> extension) { +// return super.clearExtension(extension); +// } @java.lang.Override public Builder mergeFrom(com.google.protobuf.Message other) { if (other instanceof com.google.protobuf.DescriptorProtos.MethodOptions) { @@ -45169,7 +45169,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.MethodOptions othe uninterpretedOption_ = other.uninterpretedOption_; bitField0_ = (bitField0_ & ~0x00000008); uninterpretedOptionBuilder_ = - com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? getUninterpretedOptionFieldBuilder() : null; } else { uninterpretedOptionBuilder_.addAllMessages(other.uninterpretedOption_); @@ -46073,12 +46073,12 @@ com.google.protobuf.DescriptorProtos.UninterpretedOption.NamePartOrBuilder getNa * Protobuf type {@code google.protobuf.UninterpretedOption} */ public static final class UninterpretedOption extends - com.google.protobuf.GeneratedMessageV3 implements + com.google.protobuf.FlattenedGeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:google.protobuf.UninterpretedOption) UninterpretedOptionOrBuilder { private static final long serialVersionUID = 0L; // Use UninterpretedOption.newBuilder() to construct. - private UninterpretedOption(com.google.protobuf.GeneratedMessageV3.Builder builder) { + private UninterpretedOption(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { super(builder); } private UninterpretedOption() { @@ -46101,7 +46101,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_UninterpretedOption_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -46152,12 +46152,12 @@ public interface NamePartOrBuilder extends * Protobuf type {@code google.protobuf.UninterpretedOption.NamePart} */ public static final class NamePart extends - com.google.protobuf.GeneratedMessageV3 implements + com.google.protobuf.FlattenedGeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:google.protobuf.UninterpretedOption.NamePart) NamePartOrBuilder { private static final long serialVersionUID = 0L; // Use NamePart.newBuilder() to construct. - private NamePart(com.google.protobuf.GeneratedMessageV3.Builder builder) { + private NamePart(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { super(builder); } private NamePart() { @@ -46177,7 +46177,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_UninterpretedOption_NamePart_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -46276,7 +46276,7 @@ public final boolean isInitialized() { public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { if (((bitField0_ & 0x00000001) != 0)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 1, namePart_); + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 1, namePart_); } if (((bitField0_ & 0x00000002) != 0)) { output.writeBool(2, isExtension_); @@ -46291,7 +46291,7 @@ public int getSerializedSize() { size = 0; if (((bitField0_ & 0x00000001) != 0)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, namePart_); + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(1, namePart_); } if (((bitField0_ & 0x00000002) != 0)) { size += com.google.protobuf.CodedOutputStream @@ -46381,20 +46381,20 @@ public static com.google.protobuf.DescriptorProtos.UninterpretedOption.NamePart } public static com.google.protobuf.DescriptorProtos.UninterpretedOption.NamePart parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.UninterpretedOption.NamePart parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.UninterpretedOption.NamePart parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -46402,20 +46402,20 @@ public static com.google.protobuf.DescriptorProtos.UninterpretedOption.NamePart java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.UninterpretedOption.NamePart parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.UninterpretedOption.NamePart parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -46435,7 +46435,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -46451,7 +46451,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.UninterpretedOption.NamePart} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements + com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.UninterpretedOption.NamePart) com.google.protobuf.DescriptorProtos.UninterpretedOption.NamePartOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -46460,7 +46460,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_UninterpretedOption_NamePart_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -46473,7 +46473,7 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); } @@ -47077,7 +47077,7 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) output.writeMessage(2, name_.get(i)); } if (((bitField0_ & 0x00000001) != 0)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 3, identifierValue_); + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 3, identifierValue_); } if (((bitField0_ & 0x00000002) != 0)) { output.writeUInt64(4, positiveIntValue_); @@ -47092,7 +47092,7 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) output.writeBytes(7, stringValue_); } if (((bitField0_ & 0x00000020) != 0)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 8, aggregateValue_); + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 8, aggregateValue_); } getUnknownFields().writeTo(output); } @@ -47108,7 +47108,7 @@ public int getSerializedSize() { .computeMessageSize(2, name_.get(i)); } if (((bitField0_ & 0x00000001) != 0)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(3, identifierValue_); + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(3, identifierValue_); } if (((bitField0_ & 0x00000002) != 0)) { size += com.google.protobuf.CodedOutputStream @@ -47127,7 +47127,7 @@ public int getSerializedSize() { .computeBytesSize(7, stringValue_); } if (((bitField0_ & 0x00000020) != 0)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(8, aggregateValue_); + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(8, aggregateValue_); } size += getUnknownFields().getSerializedSize(); memoizedSize = size; @@ -47258,20 +47258,20 @@ public static com.google.protobuf.DescriptorProtos.UninterpretedOption parseFrom } public static com.google.protobuf.DescriptorProtos.UninterpretedOption parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.UninterpretedOption parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.UninterpretedOption parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -47279,20 +47279,20 @@ public static com.google.protobuf.DescriptorProtos.UninterpretedOption parseDeli java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.UninterpretedOption parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.UninterpretedOption parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -47312,7 +47312,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -47329,7 +47329,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.UninterpretedOption} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements + com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.UninterpretedOption) com.google.protobuf.DescriptorProtos.UninterpretedOptionOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -47338,7 +47338,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_UninterpretedOption_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -47351,7 +47351,7 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); } @@ -47509,7 +47509,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.UninterpretedOptio name_ = other.name_; bitField0_ = (bitField0_ & ~0x00000001); nameBuilder_ = - com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? getNameFieldBuilder() : null; } else { nameBuilder_.addAllMessages(other.name_); @@ -48284,7 +48284,7 @@ public com.google.protobuf.DescriptorProtos.UninterpretedOption getDefaultInstan public interface FeatureSetOrBuilder extends // @@protoc_insertion_point(interface_extends:google.protobuf.FeatureSet) - com.google.protobuf.GeneratedMessageV3. + com.google.protobuf.FlattenedGeneratedMessageV3. ExtendableMessageOrBuilder { /** @@ -48366,13 +48366,13 @@ public interface FeatureSetOrBuilder extends * Protobuf type {@code google.protobuf.FeatureSet} */ public static final class FeatureSet extends - com.google.protobuf.GeneratedMessageV3.ExtendableMessage< + com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableMessage< FeatureSet> implements // @@protoc_insertion_point(message_implements:google.protobuf.FeatureSet) FeatureSetOrBuilder { private static final long serialVersionUID = 0L; // Use FeatureSet.newBuilder() to construct. - private FeatureSet(com.google.protobuf.GeneratedMessageV3.ExtendableBuilder builder) { + private FeatureSet(com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableBuilder builder) { super(builder); } private FeatureSet() { @@ -48397,7 +48397,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_FeatureSet_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -49170,7 +49170,7 @@ public final boolean isInitialized() { @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - com.google.protobuf.GeneratedMessageV3 + com.google.protobuf.FlattenedGeneratedMessageV3 .ExtendableMessage.ExtensionWriter extensionWriter = newExtensionWriter(); if (((bitField0_ & 0x00000001) != 0)) { @@ -49342,20 +49342,20 @@ public static com.google.protobuf.DescriptorProtos.FeatureSet parseFrom( } public static com.google.protobuf.DescriptorProtos.FeatureSet parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.FeatureSet parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.FeatureSet parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -49363,20 +49363,20 @@ public static com.google.protobuf.DescriptorProtos.FeatureSet parseDelimitedFrom java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.FeatureSet parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.FeatureSet parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -49396,7 +49396,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -49413,7 +49413,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.FeatureSet} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.ExtendableBuilder< + com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableBuilder< com.google.protobuf.DescriptorProtos.FeatureSet, Builder> implements // @@protoc_insertion_point(builder_implements:google.protobuf.FeatureSet) com.google.protobuf.DescriptorProtos.FeatureSetOrBuilder { @@ -49423,7 +49423,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_FeatureSet_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -49436,7 +49436,7 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); } @@ -49543,33 +49543,33 @@ public Builder addRepeatedField( java.lang.Object value) { return super.addRepeatedField(field, value); } - @java.lang.Override - public Builder setExtension( - com.google.protobuf.GeneratedMessage.GeneratedExtension< - com.google.protobuf.DescriptorProtos.FeatureSet, Type> extension, - Type value) { - return super.setExtension(extension, value); - } - @java.lang.Override - public Builder setExtension( - com.google.protobuf.GeneratedMessage.GeneratedExtension< - com.google.protobuf.DescriptorProtos.FeatureSet, java.util.List> extension, - int index, Type value) { - return super.setExtension(extension, index, value); - } - @java.lang.Override - public Builder addExtension( - com.google.protobuf.GeneratedMessage.GeneratedExtension< - com.google.protobuf.DescriptorProtos.FeatureSet, java.util.List> extension, - Type value) { - return super.addExtension(extension, value); - } - @java.lang.Override - public Builder clearExtension( - com.google.protobuf.GeneratedMessage.GeneratedExtension< - com.google.protobuf.DescriptorProtos.FeatureSet, T> extension) { - return super.clearExtension(extension); - } +// @java.lang.Override +// public Builder setExtension( +// com.google.protobuf.GeneratedMessage.GeneratedExtension< +// com.google.protobuf.DescriptorProtos.FeatureSet, Type> extension, +// Type value) { +// return super.setExtension(extension, value); +// } +// @java.lang.Override +// public Builder setExtension( +// com.google.protobuf.GeneratedMessage.GeneratedExtension< +// com.google.protobuf.DescriptorProtos.FeatureSet, java.util.List> extension, +// int index, Type value) { +// return super.setExtension(extension, index, value); +// } +// @java.lang.Override +// public Builder addExtension( +// com.google.protobuf.GeneratedMessage.GeneratedExtension< +// com.google.protobuf.DescriptorProtos.FeatureSet, java.util.List> extension, +// Type value) { +// return super.addExtension(extension, value); +// } +// @java.lang.Override +// public Builder clearExtension( +// com.google.protobuf.GeneratedMessage.GeneratedExtension< +// com.google.protobuf.DescriptorProtos.FeatureSet, T> extension) { +// return super.clearExtension(extension); +// } @java.lang.Override public Builder mergeFrom(com.google.protobuf.Message other) { if (other instanceof com.google.protobuf.DescriptorProtos.FeatureSet) { @@ -50115,12 +50115,12 @@ com.google.protobuf.DescriptorProtos.FeatureSetDefaults.FeatureSetEditionDefault * Protobuf type {@code google.protobuf.FeatureSetDefaults} */ public static final class FeatureSetDefaults extends - com.google.protobuf.GeneratedMessageV3 implements + com.google.protobuf.FlattenedGeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:google.protobuf.FeatureSetDefaults) FeatureSetDefaultsOrBuilder { private static final long serialVersionUID = 0L; // Use FeatureSetDefaults.newBuilder() to construct. - private FeatureSetDefaults(com.google.protobuf.GeneratedMessageV3.Builder builder) { + private FeatureSetDefaults(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { super(builder); } private FeatureSetDefaults() { @@ -50142,7 +50142,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_FeatureSetDefaults_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -50229,12 +50229,12 @@ public interface FeatureSetEditionDefaultOrBuilder extends * Protobuf type {@code google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault} */ public static final class FeatureSetEditionDefault extends - com.google.protobuf.GeneratedMessageV3 implements + com.google.protobuf.FlattenedGeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault) FeatureSetEditionDefaultOrBuilder { private static final long serialVersionUID = 0L; // Use FeatureSetEditionDefault.newBuilder() to construct. - private FeatureSetEditionDefault(com.google.protobuf.GeneratedMessageV3.Builder builder) { + private FeatureSetEditionDefault(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { super(builder); } private FeatureSetEditionDefault() { @@ -50254,7 +50254,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -50503,20 +50503,20 @@ public static com.google.protobuf.DescriptorProtos.FeatureSetDefaults.FeatureSet } public static com.google.protobuf.DescriptorProtos.FeatureSetDefaults.FeatureSetEditionDefault parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.FeatureSetDefaults.FeatureSetEditionDefault parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.FeatureSetDefaults.FeatureSetEditionDefault parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -50524,20 +50524,20 @@ public static com.google.protobuf.DescriptorProtos.FeatureSetDefaults.FeatureSet java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.FeatureSetDefaults.FeatureSetEditionDefault parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.FeatureSetDefaults.FeatureSetEditionDefault parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -50557,7 +50557,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -50572,7 +50572,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements + com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault) com.google.protobuf.DescriptorProtos.FeatureSetDefaults.FeatureSetEditionDefaultOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -50581,7 +50581,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -50594,12 +50594,12 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 + if (com.google.protobuf.FlattenedGeneratedMessageV3 .alwaysUseFieldBuilders) { getOverridableFeaturesFieldBuilder(); getFixedFeaturesFieldBuilder(); @@ -51459,20 +51459,20 @@ public static com.google.protobuf.DescriptorProtos.FeatureSetDefaults parseFrom( } public static com.google.protobuf.DescriptorProtos.FeatureSetDefaults parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.FeatureSetDefaults parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.FeatureSetDefaults parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -51480,20 +51480,20 @@ public static com.google.protobuf.DescriptorProtos.FeatureSetDefaults parseDelim java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.FeatureSetDefaults parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.FeatureSetDefaults parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -51513,7 +51513,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -51528,7 +51528,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.FeatureSetDefaults} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements + com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.FeatureSetDefaults) com.google.protobuf.DescriptorProtos.FeatureSetDefaultsOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -51537,7 +51537,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_FeatureSetDefaults_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -51550,7 +51550,7 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); } @@ -51688,7 +51688,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.FeatureSetDefaults defaults_ = other.defaults_; bitField0_ = (bitField0_ & ~0x00000001); defaultsBuilder_ = - com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? getDefaultsFieldBuilder() : null; } else { defaultsBuilder_.addAllMessages(other.defaults_); @@ -52215,7 +52215,7 @@ public com.google.protobuf.DescriptorProtos.FeatureSetDefaults getDefaultInstanc public interface SourceCodeInfoOrBuilder extends // @@protoc_insertion_point(interface_extends:google.protobuf.SourceCodeInfo) - com.google.protobuf.GeneratedMessageV3. + com.google.protobuf.FlattenedGeneratedMessageV3. ExtendableMessageOrBuilder { /** @@ -52481,13 +52481,13 @@ com.google.protobuf.DescriptorProtos.SourceCodeInfo.LocationOrBuilder getLocatio * Protobuf type {@code google.protobuf.SourceCodeInfo} */ public static final class SourceCodeInfo extends - com.google.protobuf.GeneratedMessageV3.ExtendableMessage< + com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableMessage< SourceCodeInfo> implements // @@protoc_insertion_point(message_implements:google.protobuf.SourceCodeInfo) SourceCodeInfoOrBuilder { private static final long serialVersionUID = 0L; // Use SourceCodeInfo.newBuilder() to construct. - private SourceCodeInfo(com.google.protobuf.GeneratedMessageV3.ExtendableBuilder builder) { + private SourceCodeInfo(com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableBuilder builder) { super(builder); } private SourceCodeInfo() { @@ -52507,7 +52507,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_SourceCodeInfo_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -52867,12 +52867,12 @@ public interface LocationOrBuilder extends * Protobuf type {@code google.protobuf.SourceCodeInfo.Location} */ public static final class Location extends - com.google.protobuf.GeneratedMessageV3 implements + com.google.protobuf.FlattenedGeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:google.protobuf.SourceCodeInfo.Location) LocationOrBuilder { private static final long serialVersionUID = 0L; // Use Location.newBuilder() to construct. - private Location(com.google.protobuf.GeneratedMessageV3.Builder builder) { + private Location(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { super(builder); } private Location() { @@ -52897,7 +52897,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_SourceCodeInfo_Location_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -53382,13 +53382,13 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) output.writeInt32NoTag(span_.getInt(i)); } if (((bitField0_ & 0x00000001) != 0)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 3, leadingComments_); + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 3, leadingComments_); } if (((bitField0_ & 0x00000002) != 0)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 4, trailingComments_); + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 4, trailingComments_); } for (int i = 0; i < leadingDetachedComments_.size(); i++) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 6, leadingDetachedComments_.getRaw(i)); + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 6, leadingDetachedComments_.getRaw(i)); } getUnknownFields().writeTo(output); } @@ -53428,10 +53428,10 @@ public int getSerializedSize() { spanMemoizedSerializedSize = dataSize; } if (((bitField0_ & 0x00000001) != 0)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(3, leadingComments_); + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(3, leadingComments_); } if (((bitField0_ & 0x00000002) != 0)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(4, trailingComments_); + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(4, trailingComments_); } { int dataSize = 0; @@ -53542,20 +53542,20 @@ public static com.google.protobuf.DescriptorProtos.SourceCodeInfo.Location parse } public static com.google.protobuf.DescriptorProtos.SourceCodeInfo.Location parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.SourceCodeInfo.Location parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.SourceCodeInfo.Location parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -53563,20 +53563,20 @@ public static com.google.protobuf.DescriptorProtos.SourceCodeInfo.Location parse java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.SourceCodeInfo.Location parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.SourceCodeInfo.Location parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -53596,7 +53596,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -53604,7 +53604,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.SourceCodeInfo.Location} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements + com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.SourceCodeInfo.Location) com.google.protobuf.DescriptorProtos.SourceCodeInfo.LocationOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -53613,7 +53613,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_SourceCodeInfo_Location_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -53626,7 +53626,7 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); } @@ -55202,7 +55202,7 @@ public final boolean isInitialized() { @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - com.google.protobuf.GeneratedMessageV3 + com.google.protobuf.FlattenedGeneratedMessageV3 .ExtendableMessage.ExtensionWriter extensionWriter = newExtensionWriter(); for (int i = 0; i < location_.size(); i++) { @@ -55297,20 +55297,20 @@ public static com.google.protobuf.DescriptorProtos.SourceCodeInfo parseFrom( } public static com.google.protobuf.DescriptorProtos.SourceCodeInfo parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.SourceCodeInfo parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.SourceCodeInfo parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -55318,20 +55318,20 @@ public static com.google.protobuf.DescriptorProtos.SourceCodeInfo parseDelimited java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.SourceCodeInfo parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.SourceCodeInfo parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -55351,7 +55351,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -55364,7 +55364,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.SourceCodeInfo} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.ExtendableBuilder< + com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableBuilder< com.google.protobuf.DescriptorProtos.SourceCodeInfo, Builder> implements // @@protoc_insertion_point(builder_implements:google.protobuf.SourceCodeInfo) com.google.protobuf.DescriptorProtos.SourceCodeInfoOrBuilder { @@ -55374,7 +55374,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_SourceCodeInfo_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -55387,7 +55387,7 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); } @@ -55482,33 +55482,33 @@ public Builder addRepeatedField( java.lang.Object value) { return super.addRepeatedField(field, value); } - @java.lang.Override - public Builder setExtension( - com.google.protobuf.GeneratedMessage.GeneratedExtension< - com.google.protobuf.DescriptorProtos.SourceCodeInfo, Type> extension, - Type value) { - return super.setExtension(extension, value); - } - @java.lang.Override - public Builder setExtension( - com.google.protobuf.GeneratedMessage.GeneratedExtension< - com.google.protobuf.DescriptorProtos.SourceCodeInfo, java.util.List> extension, - int index, Type value) { - return super.setExtension(extension, index, value); - } - @java.lang.Override - public Builder addExtension( - com.google.protobuf.GeneratedMessage.GeneratedExtension< - com.google.protobuf.DescriptorProtos.SourceCodeInfo, java.util.List> extension, - Type value) { - return super.addExtension(extension, value); - } - @java.lang.Override - public Builder clearExtension( - com.google.protobuf.GeneratedMessage.GeneratedExtension< - com.google.protobuf.DescriptorProtos.SourceCodeInfo, T> extension) { - return super.clearExtension(extension); - } +// @java.lang.Override +// public Builder setExtension( +// com.google.protobuf.GeneratedMessage.GeneratedExtension< +// com.google.protobuf.DescriptorProtos.SourceCodeInfo, Type> extension, +// Type value) { +// return super.setExtension(extension, value); +// } +// @java.lang.Override +// public Builder setExtension( +// com.google.protobuf.GeneratedMessage.GeneratedExtension< +// com.google.protobuf.DescriptorProtos.SourceCodeInfo, java.util.List> extension, +// int index, Type value) { +// return super.setExtension(extension, index, value); +// } +// @java.lang.Override +// public Builder addExtension( +// com.google.protobuf.GeneratedMessage.GeneratedExtension< +// com.google.protobuf.DescriptorProtos.SourceCodeInfo, java.util.List> extension, +// Type value) { +// return super.addExtension(extension, value); +// } +// @java.lang.Override +// public Builder clearExtension( +// com.google.protobuf.GeneratedMessage.GeneratedExtension< +// com.google.protobuf.DescriptorProtos.SourceCodeInfo, T> extension) { +// return super.clearExtension(extension); +// } @java.lang.Override public Builder mergeFrom(com.google.protobuf.Message other) { if (other instanceof com.google.protobuf.DescriptorProtos.SourceCodeInfo) { @@ -55540,7 +55540,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.SourceCodeInfo oth location_ = other.location_; bitField0_ = (bitField0_ & ~0x00000001); locationBuilder_ = - com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? getLocationFieldBuilder() : null; } else { locationBuilder_.addAllMessages(other.location_); @@ -56801,12 +56801,12 @@ com.google.protobuf.DescriptorProtos.GeneratedCodeInfo.AnnotationOrBuilder getAn * Protobuf type {@code google.protobuf.GeneratedCodeInfo} */ public static final class GeneratedCodeInfo extends - com.google.protobuf.GeneratedMessageV3 implements + com.google.protobuf.FlattenedGeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:google.protobuf.GeneratedCodeInfo) GeneratedCodeInfoOrBuilder { private static final long serialVersionUID = 0L; // Use GeneratedCodeInfo.newBuilder() to construct. - private GeneratedCodeInfo(com.google.protobuf.GeneratedMessageV3.Builder builder) { + private GeneratedCodeInfo(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { super(builder); } private GeneratedCodeInfo() { @@ -56826,7 +56826,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_GeneratedCodeInfo_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -56957,12 +56957,12 @@ public interface AnnotationOrBuilder extends * Protobuf type {@code google.protobuf.GeneratedCodeInfo.Annotation} */ public static final class Annotation extends - com.google.protobuf.GeneratedMessageV3 implements + com.google.protobuf.FlattenedGeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:google.protobuf.GeneratedCodeInfo.Annotation) AnnotationOrBuilder { private static final long serialVersionUID = 0L; // Use Annotation.newBuilder() to construct. - private Annotation(com.google.protobuf.GeneratedMessageV3.Builder builder) { + private Annotation(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { super(builder); } private Annotation() { @@ -56984,7 +56984,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_GeneratedCodeInfo_Annotation_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -57333,7 +57333,7 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) output.writeInt32NoTag(path_.getInt(i)); } if (((bitField0_ & 0x00000001) != 0)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 2, sourceFile_); + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 2, sourceFile_); } if (((bitField0_ & 0x00000002) != 0)) { output.writeInt32(3, begin_); @@ -57368,7 +57368,7 @@ public int getSerializedSize() { pathMemoizedSerializedSize = dataSize; } if (((bitField0_ & 0x00000001) != 0)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, sourceFile_); + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(2, sourceFile_); } if (((bitField0_ & 0x00000002) != 0)) { size += com.google.protobuf.CodedOutputStream @@ -57488,20 +57488,20 @@ public static com.google.protobuf.DescriptorProtos.GeneratedCodeInfo.Annotation } public static com.google.protobuf.DescriptorProtos.GeneratedCodeInfo.Annotation parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.GeneratedCodeInfo.Annotation parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.GeneratedCodeInfo.Annotation parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -57509,20 +57509,20 @@ public static com.google.protobuf.DescriptorProtos.GeneratedCodeInfo.Annotation java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.GeneratedCodeInfo.Annotation parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.GeneratedCodeInfo.Annotation parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -57542,7 +57542,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -57550,7 +57550,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.GeneratedCodeInfo.Annotation} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements + com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.GeneratedCodeInfo.Annotation) com.google.protobuf.DescriptorProtos.GeneratedCodeInfo.AnnotationOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -57559,7 +57559,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_GeneratedCodeInfo_Annotation_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -57572,7 +57572,7 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); } @@ -58416,20 +58416,20 @@ public static com.google.protobuf.DescriptorProtos.GeneratedCodeInfo parseFrom( } public static com.google.protobuf.DescriptorProtos.GeneratedCodeInfo parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.GeneratedCodeInfo parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.GeneratedCodeInfo parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -58437,20 +58437,20 @@ public static com.google.protobuf.DescriptorProtos.GeneratedCodeInfo parseDelimi java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.GeneratedCodeInfo parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.GeneratedCodeInfo parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -58470,7 +58470,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -58484,7 +58484,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.GeneratedCodeInfo} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements + com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.GeneratedCodeInfo) com.google.protobuf.DescriptorProtos.GeneratedCodeInfoOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -58493,7 +58493,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_GeneratedCodeInfo_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -58506,7 +58506,7 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); } @@ -58632,7 +58632,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.GeneratedCodeInfo annotation_ = other.annotation_; bitField0_ = (bitField0_ & ~0x00000001); annotationBuilder_ = - com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? getAnnotationFieldBuilder() : null; } else { annotationBuilder_.addAllMessages(other.annotation_); @@ -59091,167 +59091,167 @@ public com.google.protobuf.DescriptorProtos.GeneratedCodeInfo getDefaultInstance private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_FileDescriptorSet_descriptor; private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_FileDescriptorSet_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_FileDescriptorProto_descriptor; private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_FileDescriptorProto_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_DescriptorProto_descriptor; private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_DescriptorProto_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_DescriptorProto_ExtensionRange_descriptor; private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_DescriptorProto_ExtensionRange_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_DescriptorProto_ReservedRange_descriptor; private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_DescriptorProto_ReservedRange_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_ExtensionRangeOptions_descriptor; private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_ExtensionRangeOptions_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_ExtensionRangeOptions_Declaration_descriptor; private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_ExtensionRangeOptions_Declaration_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_FieldDescriptorProto_descriptor; private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_FieldDescriptorProto_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_OneofDescriptorProto_descriptor; private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_OneofDescriptorProto_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_EnumDescriptorProto_descriptor; private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_EnumDescriptorProto_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_EnumDescriptorProto_EnumReservedRange_descriptor; private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_EnumDescriptorProto_EnumReservedRange_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_EnumValueDescriptorProto_descriptor; private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_EnumValueDescriptorProto_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_ServiceDescriptorProto_descriptor; private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_ServiceDescriptorProto_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_MethodDescriptorProto_descriptor; private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_MethodDescriptorProto_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_FileOptions_descriptor; private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_FileOptions_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_MessageOptions_descriptor; private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_MessageOptions_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_FieldOptions_descriptor; private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_FieldOptions_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_FieldOptions_EditionDefault_descriptor; private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_FieldOptions_EditionDefault_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_FieldOptions_FeatureSupport_descriptor; private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_FieldOptions_FeatureSupport_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_OneofOptions_descriptor; private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_OneofOptions_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_EnumOptions_descriptor; private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_EnumOptions_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_EnumValueOptions_descriptor; private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_EnumValueOptions_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_ServiceOptions_descriptor; private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_ServiceOptions_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_MethodOptions_descriptor; private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_MethodOptions_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_UninterpretedOption_descriptor; private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_UninterpretedOption_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_UninterpretedOption_NamePart_descriptor; private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_UninterpretedOption_NamePart_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_FeatureSet_descriptor; private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_FeatureSet_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_FeatureSetDefaults_descriptor; private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_FeatureSetDefaults_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_descriptor; private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_SourceCodeInfo_descriptor; private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_SourceCodeInfo_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_SourceCodeInfo_Location_descriptor; private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_SourceCodeInfo_Location_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_GeneratedCodeInfo_descriptor; private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_GeneratedCodeInfo_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_GeneratedCodeInfo_Annotation_descriptor; private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_GeneratedCodeInfo_Annotation_fieldAccessorTable; public static com.google.protobuf.Descriptors.FileDescriptor @@ -59523,199 +59523,199 @@ public com.google.protobuf.DescriptorProtos.GeneratedCodeInfo getDefaultInstance internal_static_google_protobuf_FileDescriptorSet_descriptor = getDescriptor().getMessageTypes().get(0); internal_static_google_protobuf_FileDescriptorSet_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_FileDescriptorSet_descriptor, new java.lang.String[] { "File", }); internal_static_google_protobuf_FileDescriptorProto_descriptor = getDescriptor().getMessageTypes().get(1); internal_static_google_protobuf_FileDescriptorProto_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_FileDescriptorProto_descriptor, new java.lang.String[] { "Name", "Package", "Dependency", "PublicDependency", "WeakDependency", "MessageType", "EnumType", "Service", "Extension", "Options", "SourceCodeInfo", "Syntax", "Edition", }); internal_static_google_protobuf_DescriptorProto_descriptor = getDescriptor().getMessageTypes().get(2); internal_static_google_protobuf_DescriptorProto_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_DescriptorProto_descriptor, new java.lang.String[] { "Name", "Field", "Extension", "NestedType", "EnumType", "ExtensionRange", "OneofDecl", "Options", "ReservedRange", "ReservedName", }); internal_static_google_protobuf_DescriptorProto_ExtensionRange_descriptor = internal_static_google_protobuf_DescriptorProto_descriptor.getNestedTypes().get(0); internal_static_google_protobuf_DescriptorProto_ExtensionRange_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_DescriptorProto_ExtensionRange_descriptor, new java.lang.String[] { "Start", "End", "Options", }); internal_static_google_protobuf_DescriptorProto_ReservedRange_descriptor = internal_static_google_protobuf_DescriptorProto_descriptor.getNestedTypes().get(1); internal_static_google_protobuf_DescriptorProto_ReservedRange_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_DescriptorProto_ReservedRange_descriptor, new java.lang.String[] { "Start", "End", }); internal_static_google_protobuf_ExtensionRangeOptions_descriptor = getDescriptor().getMessageTypes().get(3); internal_static_google_protobuf_ExtensionRangeOptions_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_ExtensionRangeOptions_descriptor, new java.lang.String[] { "UninterpretedOption", "Declaration", "Features", "Verification", }); internal_static_google_protobuf_ExtensionRangeOptions_Declaration_descriptor = internal_static_google_protobuf_ExtensionRangeOptions_descriptor.getNestedTypes().get(0); internal_static_google_protobuf_ExtensionRangeOptions_Declaration_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_ExtensionRangeOptions_Declaration_descriptor, new java.lang.String[] { "Number", "FullName", "Type", "Reserved", "Repeated", }); internal_static_google_protobuf_FieldDescriptorProto_descriptor = getDescriptor().getMessageTypes().get(4); internal_static_google_protobuf_FieldDescriptorProto_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_FieldDescriptorProto_descriptor, new java.lang.String[] { "Name", "Number", "Label", "Type", "TypeName", "Extendee", "DefaultValue", "OneofIndex", "JsonName", "Options", "Proto3Optional", }); internal_static_google_protobuf_OneofDescriptorProto_descriptor = getDescriptor().getMessageTypes().get(5); internal_static_google_protobuf_OneofDescriptorProto_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_OneofDescriptorProto_descriptor, new java.lang.String[] { "Name", "Options", }); internal_static_google_protobuf_EnumDescriptorProto_descriptor = getDescriptor().getMessageTypes().get(6); internal_static_google_protobuf_EnumDescriptorProto_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_EnumDescriptorProto_descriptor, new java.lang.String[] { "Name", "Value", "Options", "ReservedRange", "ReservedName", }); internal_static_google_protobuf_EnumDescriptorProto_EnumReservedRange_descriptor = internal_static_google_protobuf_EnumDescriptorProto_descriptor.getNestedTypes().get(0); internal_static_google_protobuf_EnumDescriptorProto_EnumReservedRange_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_EnumDescriptorProto_EnumReservedRange_descriptor, new java.lang.String[] { "Start", "End", }); internal_static_google_protobuf_EnumValueDescriptorProto_descriptor = getDescriptor().getMessageTypes().get(7); internal_static_google_protobuf_EnumValueDescriptorProto_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_EnumValueDescriptorProto_descriptor, new java.lang.String[] { "Name", "Number", "Options", }); internal_static_google_protobuf_ServiceDescriptorProto_descriptor = getDescriptor().getMessageTypes().get(8); internal_static_google_protobuf_ServiceDescriptorProto_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_ServiceDescriptorProto_descriptor, new java.lang.String[] { "Name", "Method", "Options", }); internal_static_google_protobuf_MethodDescriptorProto_descriptor = getDescriptor().getMessageTypes().get(9); internal_static_google_protobuf_MethodDescriptorProto_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_MethodDescriptorProto_descriptor, new java.lang.String[] { "Name", "InputType", "OutputType", "Options", "ClientStreaming", "ServerStreaming", }); internal_static_google_protobuf_FileOptions_descriptor = getDescriptor().getMessageTypes().get(10); internal_static_google_protobuf_FileOptions_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_FileOptions_descriptor, new java.lang.String[] { "JavaPackage", "JavaOuterClassname", "JavaMultipleFiles", "JavaGenerateEqualsAndHash", "JavaStringCheckUtf8", "OptimizeFor", "GoPackage", "CcGenericServices", "JavaGenericServices", "PyGenericServices", "Deprecated", "CcEnableArenas", "ObjcClassPrefix", "CsharpNamespace", "SwiftPrefix", "PhpClassPrefix", "PhpNamespace", "PhpMetadataNamespace", "RubyPackage", "Features", "UninterpretedOption", }); internal_static_google_protobuf_MessageOptions_descriptor = getDescriptor().getMessageTypes().get(11); internal_static_google_protobuf_MessageOptions_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_MessageOptions_descriptor, new java.lang.String[] { "MessageSetWireFormat", "NoStandardDescriptorAccessor", "Deprecated", "MapEntry", "DeprecatedLegacyJsonFieldConflicts", "Features", "UninterpretedOption", }); internal_static_google_protobuf_FieldOptions_descriptor = getDescriptor().getMessageTypes().get(12); internal_static_google_protobuf_FieldOptions_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_FieldOptions_descriptor, new java.lang.String[] { "Ctype", "Packed", "Jstype", "Lazy", "UnverifiedLazy", "Deprecated", "Weak", "DebugRedact", "Retention", "Targets", "EditionDefaults", "Features", "FeatureSupport", "UninterpretedOption", }); internal_static_google_protobuf_FieldOptions_EditionDefault_descriptor = internal_static_google_protobuf_FieldOptions_descriptor.getNestedTypes().get(0); internal_static_google_protobuf_FieldOptions_EditionDefault_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_FieldOptions_EditionDefault_descriptor, new java.lang.String[] { "Edition", "Value", }); internal_static_google_protobuf_FieldOptions_FeatureSupport_descriptor = internal_static_google_protobuf_FieldOptions_descriptor.getNestedTypes().get(1); internal_static_google_protobuf_FieldOptions_FeatureSupport_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_FieldOptions_FeatureSupport_descriptor, new java.lang.String[] { "EditionIntroduced", "EditionDeprecated", "DeprecationWarning", "EditionRemoved", }); internal_static_google_protobuf_OneofOptions_descriptor = getDescriptor().getMessageTypes().get(13); internal_static_google_protobuf_OneofOptions_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_OneofOptions_descriptor, new java.lang.String[] { "Features", "UninterpretedOption", }); internal_static_google_protobuf_EnumOptions_descriptor = getDescriptor().getMessageTypes().get(14); internal_static_google_protobuf_EnumOptions_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_EnumOptions_descriptor, new java.lang.String[] { "AllowAlias", "Deprecated", "DeprecatedLegacyJsonFieldConflicts", "Features", "UninterpretedOption", }); internal_static_google_protobuf_EnumValueOptions_descriptor = getDescriptor().getMessageTypes().get(15); internal_static_google_protobuf_EnumValueOptions_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_EnumValueOptions_descriptor, new java.lang.String[] { "Deprecated", "Features", "DebugRedact", "FeatureSupport", "UninterpretedOption", }); internal_static_google_protobuf_ServiceOptions_descriptor = getDescriptor().getMessageTypes().get(16); internal_static_google_protobuf_ServiceOptions_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_ServiceOptions_descriptor, new java.lang.String[] { "Features", "Deprecated", "UninterpretedOption", }); internal_static_google_protobuf_MethodOptions_descriptor = getDescriptor().getMessageTypes().get(17); internal_static_google_protobuf_MethodOptions_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_MethodOptions_descriptor, new java.lang.String[] { "Deprecated", "IdempotencyLevel", "Features", "UninterpretedOption", }); internal_static_google_protobuf_UninterpretedOption_descriptor = getDescriptor().getMessageTypes().get(18); internal_static_google_protobuf_UninterpretedOption_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_UninterpretedOption_descriptor, new java.lang.String[] { "Name", "IdentifierValue", "PositiveIntValue", "NegativeIntValue", "DoubleValue", "StringValue", "AggregateValue", }); internal_static_google_protobuf_UninterpretedOption_NamePart_descriptor = internal_static_google_protobuf_UninterpretedOption_descriptor.getNestedTypes().get(0); internal_static_google_protobuf_UninterpretedOption_NamePart_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_UninterpretedOption_NamePart_descriptor, new java.lang.String[] { "NamePart", "IsExtension", }); internal_static_google_protobuf_FeatureSet_descriptor = getDescriptor().getMessageTypes().get(19); internal_static_google_protobuf_FeatureSet_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_FeatureSet_descriptor, new java.lang.String[] { "FieldPresence", "EnumType", "RepeatedFieldEncoding", "Utf8Validation", "MessageEncoding", "JsonFormat", }); internal_static_google_protobuf_FeatureSetDefaults_descriptor = getDescriptor().getMessageTypes().get(20); internal_static_google_protobuf_FeatureSetDefaults_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_FeatureSetDefaults_descriptor, new java.lang.String[] { "Defaults", "MinimumEdition", "MaximumEdition", }); internal_static_google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_descriptor = internal_static_google_protobuf_FeatureSetDefaults_descriptor.getNestedTypes().get(0); internal_static_google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_descriptor, new java.lang.String[] { "Edition", "OverridableFeatures", "FixedFeatures", }); internal_static_google_protobuf_SourceCodeInfo_descriptor = getDescriptor().getMessageTypes().get(21); internal_static_google_protobuf_SourceCodeInfo_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_SourceCodeInfo_descriptor, new java.lang.String[] { "Location", }); internal_static_google_protobuf_SourceCodeInfo_Location_descriptor = internal_static_google_protobuf_SourceCodeInfo_descriptor.getNestedTypes().get(0); internal_static_google_protobuf_SourceCodeInfo_Location_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_SourceCodeInfo_Location_descriptor, new java.lang.String[] { "Path", "Span", "LeadingComments", "TrailingComments", "LeadingDetachedComments", }); internal_static_google_protobuf_GeneratedCodeInfo_descriptor = getDescriptor().getMessageTypes().get(22); internal_static_google_protobuf_GeneratedCodeInfo_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_GeneratedCodeInfo_descriptor, new java.lang.String[] { "Annotation", }); internal_static_google_protobuf_GeneratedCodeInfo_Annotation_descriptor = internal_static_google_protobuf_GeneratedCodeInfo_descriptor.getNestedTypes().get(0); internal_static_google_protobuf_GeneratedCodeInfo_Annotation_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_GeneratedCodeInfo_Annotation_descriptor, new java.lang.String[] { "Path", "SourceFile", "Begin", "End", "Semantic", }); } diff --git a/protobuf-api/src/main/java/com/google/protobuf/FlattenedAbstractMessage.java b/protobuf-api/src/main/java/com/google/protobuf/FlattenedAbstractMessage.java new file mode 100644 index 0000000..68d8da9 --- /dev/null +++ b/protobuf-api/src/main/java/com/google/protobuf/FlattenedAbstractMessage.java @@ -0,0 +1,864 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd + +package com.google.protobuf; + +import com.google.protobuf.Descriptors.EnumValueDescriptor; +import com.google.protobuf.Descriptors.FieldDescriptor; +import com.google.protobuf.Descriptors.OneofDescriptor; +import com.google.protobuf.Internal.EnumLite; + +import java.io.FilterInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import static com.google.protobuf.Internal.checkNotNull; + +/** + * A partial implementation of the {@link Message} interface which implements as many methods of + * that interface as possible in terms of other methods. + * + * @author kenton@google.com Kenton Varda + */ +public abstract class FlattenedAbstractMessage + // TODO: Update GeneratedMessage to parameterize with MessageType and BuilderType. + implements Message { + + protected int memoizedHashCode = 0; + + @Override + public ByteString toByteString() { + try { + final ByteString.CodedBuilder out = ByteString.newCodedBuilder(getSerializedSize()); + writeTo(out.getCodedOutput()); + return out.build(); + } catch (IOException e) { + throw new RuntimeException(getSerializingExceptionMessage("ByteString"), e); + } + } + + @Override + public byte[] toByteArray() { + try { + final byte[] result = new byte[getSerializedSize()]; + final CodedOutputStream output = CodedOutputStream.newInstance(result); + writeTo(output); + output.checkNoSpaceLeft(); + return result; + } catch (IOException e) { + throw new RuntimeException(getSerializingExceptionMessage("byte array"), e); + } + } + + @Override + public void writeTo(final OutputStream output) throws IOException { + final int bufferSize = CodedOutputStream.computePreferredBufferSize(getSerializedSize()); + final CodedOutputStream codedOutput = CodedOutputStream.newInstance(output, bufferSize); + writeTo(codedOutput); + codedOutput.flush(); + } + + @Override + public void writeDelimitedTo(final OutputStream output) throws IOException { + final int serialized = getSerializedSize(); + final int bufferSize = + CodedOutputStream.computePreferredBufferSize( + CodedOutputStream.computeUInt32SizeNoTag(serialized) + serialized); + final CodedOutputStream codedOutput = CodedOutputStream.newInstance(output, bufferSize); + codedOutput.writeUInt32NoTag(serialized); + writeTo(codedOutput); + codedOutput.flush(); + } + + int getSerializedSize( + Schema schema) { + int memoizedSerializedSize = getMemoizedSerializedSize(); + if (memoizedSerializedSize == -1) { + memoizedSerializedSize = schema.getSerializedSize(this); + setMemoizedSerializedSize(memoizedSerializedSize); + } + return memoizedSerializedSize; + } + + private String getSerializingExceptionMessage(String target) { + return "Serializing " + + getClass().getName() + + " to a " + + target + + " threw an IOException (should never happen)."; + } + + protected static void checkByteStringIsUtf8(ByteString byteString) + throws IllegalArgumentException { + if (!byteString.isValidUtf8()) { + throw new IllegalArgumentException("Byte string is not UTF-8."); + } + } + + /** Interface for an enum which signifies which field in a {@code oneof} was specified. */ + protected interface InternalOneOfEnum { + /** + * Retrieves the field number of the field which was set in this {@code oneof}, or {@code 0} if + * none were. + */ + int getNumber(); + } + + @Override + public boolean isInitialized() { + return MessageReflection.isInitialized(this); + } + + /** + * Interface for the parent of a Builder that allows the builder to communicate invalidations back + * to the parent for use when using nested builders. + */ + protected interface BuilderParent { + + /** + * A builder becomes dirty whenever a field is modified -- including fields in nested builders + * -- and becomes clean when build() is called. Thus, when a builder becomes dirty, all its + * parents become dirty as well, and when it becomes clean, all its children become clean. The + * dirtiness state is used to invalidate certain cached values. + * + *

To this end, a builder calls markDirty() on its parent whenever it transitions from clean + * to dirty. The parent must propagate this call to its own parent, unless it was already dirty, + * in which case the grandparent must necessarily already be dirty as well. The parent can only + * transition back to "clean" after calling build() on all children. + */ + void markDirty(); + } + + /** Create a nested builder. */ + protected Message.Builder newBuilderForType(BuilderParent parent) { + throw new UnsupportedOperationException("Nested builder is not supported for this type."); + } + + @Override + public List findInitializationErrors() { + return MessageReflection.findMissingFields(this); + } + + @Override + public String getInitializationErrorString() { + return MessageReflection.delimitWithCommas(findInitializationErrors()); + } + + // TODO: Clear it when all subclasses have implemented this method. + @Override + public boolean hasOneof(OneofDescriptor oneof) { + throw new UnsupportedOperationException("hasOneof() is not implemented."); + } + + // TODO: Clear it when all subclasses have implemented this method. + @Override + public FieldDescriptor getOneofFieldDescriptor(OneofDescriptor oneof) { + throw new UnsupportedOperationException("getOneofFieldDescriptor() is not implemented."); + } + + @Override + public final String toString() { + return TextFormat.printer().printToString(this); + } + + @Override + public void writeTo(final CodedOutputStream output) throws IOException { + MessageReflection.writeMessageTo(this, getAllFields(), output, false); + } + + protected int memoizedSize = -1; + + int getMemoizedSerializedSize() { + return memoizedSize; + } + + void setMemoizedSerializedSize(int size) { + memoizedSize = size; + } + + @Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) { + return size; + } + + memoizedSize = MessageReflection.getSerializedSize(this, getAllFields()); + return memoizedSize; + } + + @Override + public boolean equals(final Object other) { + if (other == this) { + return true; + } + if (!(other instanceof Message)) { + return false; + } + final Message otherMessage = (Message) other; + if (getDescriptorForType() != otherMessage.getDescriptorForType()) { + return false; + } + return compareFields(getAllFields(), otherMessage.getAllFields()) + && getUnknownFields().equals(otherMessage.getUnknownFields()); + } + + @Override + public int hashCode() { + int hash = memoizedHashCode; + if (hash == 0) { + hash = 41; + hash = (19 * hash) + getDescriptorForType().hashCode(); + hash = hashFields(hash, getAllFields()); + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + } + return hash; + } + + private static ByteString toByteString(Object value) { + if (value instanceof byte[]) { + return ByteString.copyFrom((byte[]) value); + } else { + return (ByteString) value; + } + } + + /** + * Compares two bytes fields. The parameters must be either a byte array or a ByteString object. + * They can be of different type though. + */ + private static boolean compareBytes(Object a, Object b) { + if (a instanceof byte[] && b instanceof byte[]) { + return Arrays.equals((byte[]) a, (byte[]) b); + } + return toByteString(a).equals(toByteString(b)); + } + + /** Converts a list of MapEntry messages into a Map used for equals() and hashCode(). */ + @SuppressWarnings({"rawtypes", "unchecked"}) + private static Map convertMapEntryListToMap(List list) { + if (list.isEmpty()) { + return Collections.emptyMap(); + } + Map result = new HashMap<>(); + Iterator iterator = list.iterator(); + Message entry = (Message) iterator.next(); + Descriptors.Descriptor descriptor = entry.getDescriptorForType(); + FieldDescriptor key = descriptor.findFieldByName("key"); + FieldDescriptor value = descriptor.findFieldByName("value"); + Object fieldValue = entry.getField(value); + if (fieldValue instanceof EnumValueDescriptor) { + fieldValue = ((EnumValueDescriptor) fieldValue).getNumber(); + } + result.put(entry.getField(key), fieldValue); + while (iterator.hasNext()) { + entry = (Message) iterator.next(); + fieldValue = entry.getField(value); + if (fieldValue instanceof EnumValueDescriptor) { + fieldValue = ((EnumValueDescriptor) fieldValue).getNumber(); + } + result.put(entry.getField(key), fieldValue); + } + return result; + } + + /** Compares two map fields. The parameters must be a list of MapEntry messages. */ + @SuppressWarnings({"rawtypes", "unchecked"}) + private static boolean compareMapField(Object a, Object b) { + Map ma = convertMapEntryListToMap((List) a); + Map mb = convertMapEntryListToMap((List) b); + return MapFieldLite.equals(ma, mb); + } + + /** + * Compares two sets of fields. This method is used to implement {@link + * FlattenedAbstractMessage#equals(Object)} and {@link AbstractMutableMessage#equals(Object)}. It takes + * special care of bytes fields because immutable messages and mutable messages use different Java + * type to represent a bytes field and this method should be able to compare immutable messages, + * mutable messages and also an immutable message to a mutable message. + */ + static boolean compareFields(Map a, Map b) { + if (a.size() != b.size()) { + return false; + } + for (FieldDescriptor descriptor : a.keySet()) { + if (!b.containsKey(descriptor)) { + return false; + } + Object value1 = a.get(descriptor); + Object value2 = b.get(descriptor); + if (descriptor.getType() == FieldDescriptor.Type.BYTES) { + if (descriptor.isRepeated()) { + List list1 = (List) value1; + List list2 = (List) value2; + if (list1.size() != list2.size()) { + return false; + } + for (int i = 0; i < list1.size(); i++) { + if (!compareBytes(list1.get(i), list2.get(i))) { + return false; + } + } + } else { + // Compares a singular bytes field. + if (!compareBytes(value1, value2)) { + return false; + } + } + } else if (descriptor.isMapField()) { + if (!compareMapField(value1, value2)) { + return false; + } + } else { + // Compare non-bytes fields. + if (!value1.equals(value2)) { + return false; + } + } + } + return true; + } + + /** Calculates the hash code of a map field. {@code value} must be a list of MapEntry messages. */ + @SuppressWarnings("unchecked") + private static int hashMapField(Object value) { + return MapFieldLite.calculateHashCodeForMap(convertMapEntryListToMap((List) value)); + } + + /** Get a hash code for given fields and values, using the given seed. */ + @SuppressWarnings("unchecked") + protected static int hashFields(int hash, Map map) { + for (Map.Entry entry : map.entrySet()) { + FieldDescriptor field = entry.getKey(); + Object value = entry.getValue(); + hash = (37 * hash) + field.getNumber(); + if (field.isMapField()) { + hash = (53 * hash) + hashMapField(value); + } else if (field.getType() != FieldDescriptor.Type.ENUM) { + hash = (53 * hash) + value.hashCode(); + } else if (field.isRepeated()) { + List list = (List) value; + hash = (53 * hash) + Internal.hashEnumList(list); + } else { + hash = (53 * hash) + Internal.hashEnum((EnumLite) value); + } + } + return hash; + } + + /** + * Package private helper method for AbstractParser to create UninitializedMessageException with + * missing field information. + */ + UninitializedMessageException newUninitializedMessageException() { + return Builder.newUninitializedMessageException(this); + } + + // ================================================================= + + /** + * A partial implementation of the {@link Message.Builder} interface which implements as many + * methods of that interface as possible in terms of other methods. + */ + @SuppressWarnings("unchecked") + public abstract static class Builder> implements Message.Builder { + + /** + * An InputStream implementations which reads from some other InputStream but is limited to a + * particular number of bytes. Used by mergeDelimitedFrom(). This is intentionally + * package-private so that UnknownFieldSet can share it. + */ + static final class LimitedInputStream extends FilterInputStream { + private int limit; + + LimitedInputStream(InputStream in, int limit) { + super(in); + this.limit = limit; + } + + @Override + public int available() throws IOException { + return Math.min(super.available(), limit); + } + + @Override + public int read() throws IOException { + if (limit <= 0) { + return -1; + } + final int result = super.read(); + if (result >= 0) { + --limit; + } + return result; + } + + @Override + public int read(final byte[] b, final int off, int len) throws IOException { + if (limit <= 0) { + return -1; + } + len = Math.min(len, limit); + final int result = super.read(b, off, len); + if (result >= 0) { + limit -= result; + } + return result; + } + + @Override + public long skip(final long n) throws IOException { + // because we take the minimum of an int and a long, result is guaranteed to be + // less than or equal to Integer.MAX_INT so this cast is safe + int result = (int) super.skip(Math.min(n, limit)); + if (result >= 0) { + // if the superclass adheres to the contract for skip, this condition is always true + limit -= result; + } + return result; + } + } + + @Override + public boolean mergeDelimitedFrom( + final InputStream input, final ExtensionRegistryLite extensionRegistry) throws IOException { + final int firstByte = input.read(); + if (firstByte == -1) { + return false; + } + final int size = CodedInputStream.readRawVarint32(firstByte, input); + final InputStream limitedInput = new AbstractMessageLite.Builder.LimitedInputStream(input, size); + mergeFrom(limitedInput, extensionRegistry); + return true; + } + + @Override + public boolean mergeDelimitedFrom(final InputStream input) throws IOException { + return mergeDelimitedFrom(input, ExtensionRegistryLite.getEmptyRegistry()); + } + + @Override + @SuppressWarnings("unchecked") // isInstance takes care of this + public BuilderType mergeFrom(final MessageLite other) { + if (!getDefaultInstanceForType().getClass().isInstance(other)) { + throw new IllegalArgumentException( + "mergeFrom(MessageLite) can only merge messages of the same type."); + } + + return internalMergeFrom(other); + } + + private String getReadingExceptionMessage(String target) { + return "Reading " + + getClass().getName() + + " from a " + + target + + " threw an IOException (should never happen)."; + } + + // We check nulls as we iterate to avoid iterating over values twice. + private static void addAllCheckingNulls(Iterable values, List list) { + if (list instanceof ArrayList && values instanceof Collection) { + ((ArrayList) list).ensureCapacity(list.size() + ((Collection) values).size()); + } + int begin = list.size(); + for (T value : values) { + if (value == null) { + // encountered a null value so we must undo our modifications prior to throwing + String message = "Element at index " + (list.size() - begin) + " is null."; + for (int i = list.size() - 1; i >= begin; i--) { + list.remove(i); + } + throw new NullPointerException(message); + } + list.add(value); + } + } + + /** Construct an UninitializedMessageException reporting missing fields in the given message. */ + protected static UninitializedMessageException newUninitializedMessageException( + MessageLite message) { + return new UninitializedMessageException(message); + } + + // For binary compatibility. + @Deprecated + protected static void addAll(final Iterable values, final Collection list) { + addAll(values, (List) list); + } + + /** + * Adds the {@code values} to the {@code list}. This is a helper method used by generated code. + * Users should ignore it. + * + * @throws NullPointerException if {@code values} or any of the elements of {@code values} is + * null. + */ + protected static void addAll(final Iterable values, final List list) { + checkNotNull(values); + if (values instanceof LazyStringList) { + // For StringOrByteStringLists, check the underlying elements to avoid + // forcing conversions of ByteStrings to Strings. + // TODO: Could we just prohibit nulls in all protobuf lists and get rid of this? Is + // if even possible to hit this condition as all protobuf methods check for null first, + // right? + List lazyValues = ((LazyStringList) values).getUnderlyingElements(); + LazyStringList lazyList = (LazyStringList) list; + int begin = list.size(); + for (Object value : lazyValues) { + if (value == null) { + // encountered a null value so we must undo our modifications prior to throwing + String message = "Element at index " + (lazyList.size() - begin) + " is null."; + for (int i = lazyList.size() - 1; i >= begin; i--) { + lazyList.remove(i); + } + throw new NullPointerException(message); + } + if (value instanceof ByteString) { + lazyList.add((ByteString) value); + } else { + lazyList.add((String) value); + } + } + } else { + if (values instanceof PrimitiveNonBoxingCollection) { + list.addAll((Collection) values); + } else { + addAllCheckingNulls(values, list); + } + } + } + + // The compiler produces an error if this is not declared explicitly. + // Method isn't abstract to bypass Java 1.6 compiler issue: + // http://bugs.java.com/view_bug.do?bug_id=6908259 + @Override + public BuilderType clone() { + throw new UnsupportedOperationException("clone() should be implemented in subclasses."); + } + + /** TODO: Clear it when all subclasses have implemented this method. */ + @Override + public boolean hasOneof(OneofDescriptor oneof) { + throw new UnsupportedOperationException("hasOneof() is not implemented."); + } + + /** TODO: Clear it when all subclasses have implemented this method. */ + @Override + public FieldDescriptor getOneofFieldDescriptor(OneofDescriptor oneof) { + throw new UnsupportedOperationException("getOneofFieldDescriptor() is not implemented."); + } + + /** TODO: Clear it when all subclasses have implemented this method. */ + @Override + public BuilderType clearOneof(OneofDescriptor oneof) { + throw new UnsupportedOperationException("clearOneof() is not implemented."); + } + + @Override + public BuilderType clear() { + for (final Map.Entry entry : getAllFields().entrySet()) { + clearField(entry.getKey()); + } + return (BuilderType) this; + } + + @Override + public List findInitializationErrors() { + return MessageReflection.findMissingFields(this); + } + + @Override + public String getInitializationErrorString() { + return MessageReflection.delimitWithCommas(findInitializationErrors()); + } + + protected BuilderType internalMergeFrom(MessageLite other) { + return mergeFrom((Message) other); + } + + @Override + public BuilderType mergeFrom(final Message other) { + return mergeFrom(other, other.getAllFields()); + } + + BuilderType mergeFrom(final Message other, Map allFields) { + if (other.getDescriptorForType() != getDescriptorForType()) { + throw new IllegalArgumentException( + "mergeFrom(Message) can only merge messages of the same type."); + } + + // Note: We don't attempt to verify that other's fields have valid + // types. Doing so would be a losing battle. We'd have to verify + // all sub-messages as well, and we'd have to make copies of all of + // them to insure that they don't change after verification (since + // the Message interface itself cannot enforce immutability of + // implementations). + + for (final Map.Entry entry : allFields.entrySet()) { + final FieldDescriptor field = entry.getKey(); + if (field.isRepeated()) { + for (final Object element : (List) entry.getValue()) { + addRepeatedField(field, element); + } + } else if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { + final Message existingValue = (Message) getField(field); + if (existingValue == existingValue.getDefaultInstanceForType()) { + setField(field, entry.getValue()); + } else { + setField( + field, + existingValue + .newBuilderForType() + .mergeFrom(existingValue) + .mergeFrom((Message) entry.getValue()) + .build()); + } + } else { + setField(field, entry.getValue()); + } + } + + mergeUnknownFields(other.getUnknownFields()); + + return (BuilderType) this; + } + + @Override + public BuilderType mergeFrom(final CodedInputStream input) throws IOException { + return mergeFrom(input, ExtensionRegistry.getEmptyRegistry()); + } + + @Override + public BuilderType mergeFrom( + final CodedInputStream input, final ExtensionRegistryLite extensionRegistry) + throws IOException { + boolean discardUnknown = input.shouldDiscardUnknownFields(); + final UnknownFieldSet.Builder unknownFields = + discardUnknown ? null : getUnknownFieldSetBuilder(); + MessageReflection.mergeMessageFrom(this, unknownFields, input, extensionRegistry); + if (unknownFields != null) { + setUnknownFieldSetBuilder(unknownFields); + } + return (BuilderType) this; + } + + protected UnknownFieldSet.Builder getUnknownFieldSetBuilder() { + return UnknownFieldSet.newBuilder(getUnknownFields()); + } + + protected void setUnknownFieldSetBuilder(final UnknownFieldSet.Builder builder) { + setUnknownFields(builder.build()); + } + + @Override + public BuilderType mergeUnknownFields(final UnknownFieldSet unknownFields) { + setUnknownFields( + UnknownFieldSet.newBuilder(getUnknownFields()).mergeFrom(unknownFields).build()); + return (BuilderType) this; + } + + @Override + public Message.Builder getFieldBuilder(final FieldDescriptor field) { + throw new UnsupportedOperationException( + "getFieldBuilder() called on an unsupported message type."); + } + + @Override + public Message.Builder getRepeatedFieldBuilder(final FieldDescriptor field, int index) { + throw new UnsupportedOperationException( + "getRepeatedFieldBuilder() called on an unsupported message type."); + } + + @Override + public String toString() { + return TextFormat.printer().printToString(this); + } + + /** Construct an UninitializedMessageException reporting missing fields in the given message. */ + protected static UninitializedMessageException newUninitializedMessageException( + Message message) { + return new UninitializedMessageException(MessageReflection.findMissingFields(message)); + } + + /** + * Used to support nested builders and called to mark this builder as clean. Clean builders will + * propagate the {@link BuilderParent#markDirty()} event to their parent builders, while dirty + * builders will not, as their parents should be dirty already. + * + *

NOTE: Implementations that don't support nested builders don't need to override this + * method. + */ + void markClean() { + throw new IllegalStateException("Should be overridden by subclasses."); + } + + /** + * Used to support nested builders and called when this nested builder is no longer used by its + * parent builder and should release the reference to its parent builder. + * + *

NOTE: Implementations that don't support nested builders don't need to override this + * method. + */ + void dispose() { + throw new IllegalStateException("Should be overridden by subclasses."); + } + + // =============================================================== + // The following definitions seem to be required in order to make javac + // not produce weird errors like: + // + // java/com/google/protobuf/DynamicMessage.java:203: types + // com.google.protobuf.AbstractMessage.Builder< + // com.google.protobuf.DynamicMessage.Builder> and + // com.google.protobuf.AbstractMessage.Builder< + // com.google.protobuf.DynamicMessage.Builder> are incompatible; both + // define mergeFrom(com.google.protobuf.ByteString), but with unrelated + // return types. + // + // Strangely, these lines are only needed if javac is invoked separately + // on AbstractMessage.java and AbstractMessageLite.java. If javac is + // invoked on both simultaneously, it works. (Or maybe the important + // point is whether or not DynamicMessage.java is compiled together with + // AbstractMessageLite.java -- not sure.) I suspect this is a compiler + // bug. + + public BuilderType mergeFrom(final ByteString data) throws InvalidProtocolBufferException { + try { + final CodedInputStream input = data.newCodedInput(); + mergeFrom(input); + input.checkLastTagWas(0); + return (BuilderType) this; + } catch (InvalidProtocolBufferException e) { + throw e; + } catch (IOException e) { + throw new RuntimeException(getReadingExceptionMessage("ByteString"), e); + } + } + + public BuilderType mergeFrom( + final ByteString data, final ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + try { + final CodedInputStream input = data.newCodedInput(); + mergeFrom(input, extensionRegistry); + input.checkLastTagWas(0); + return (BuilderType) this; + } catch (InvalidProtocolBufferException e) { + throw e; + } catch (IOException e) { + throw new RuntimeException(getReadingExceptionMessage("ByteString"), e); + } + } + + public BuilderType mergeFrom(final byte[] data) throws InvalidProtocolBufferException { + return mergeFrom(data, 0, data.length); + } + + public BuilderType mergeFrom(final byte[] data, final int off, final int len) + throws InvalidProtocolBufferException { + try { + final CodedInputStream input = CodedInputStream.newInstance(data, off, len); + mergeFrom(input); + input.checkLastTagWas(0); + return (BuilderType) this; + } catch (InvalidProtocolBufferException e) { + throw e; + } catch (IOException e) { + throw new RuntimeException(getReadingExceptionMessage("byte array"), e); + } + } + + public BuilderType mergeFrom(final byte[] data, final ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + return mergeFrom(data, 0, data.length, extensionRegistry); + } + + public BuilderType mergeFrom( + final byte[] data, + final int off, + final int len, + final ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + try { + final CodedInputStream input = CodedInputStream.newInstance(data, off, len); + mergeFrom(input, extensionRegistry); + input.checkLastTagWas(0); + return (BuilderType) this; + } catch (InvalidProtocolBufferException e) { + throw e; + } catch (IOException e) { + throw new RuntimeException(getReadingExceptionMessage("byte array"), e); + } + } + + public BuilderType mergeFrom(final InputStream input) throws IOException { + final CodedInputStream codedInput = CodedInputStream.newInstance(input); + mergeFrom(codedInput); + codedInput.checkLastTagWas(0); + return (BuilderType) this; + } + + public BuilderType mergeFrom( + final InputStream input, final ExtensionRegistryLite extensionRegistry) throws IOException { + final CodedInputStream codedInput = CodedInputStream.newInstance(input); + mergeFrom(codedInput, extensionRegistry); + codedInput.checkLastTagWas(0); + return (BuilderType) this; + } + + /** + * @deprecated from v3.0.0-beta-3+, for compatibility with v2.5.0 and v2.6.1 + * generated code. + */ + @Deprecated + protected static int hashLong(long n) { + return (int) (n ^ (n >>> 32)); + } + + /** + * @deprecated from v3.0.0-beta-3+, for compatibility with v2.5.0 and v2.6.1 + * generated code. + */ + @Deprecated + protected static int hashBoolean(boolean b) { + return b ? 1231 : 1237; + } + + /** + * @deprecated from v3.0.0-beta-3+, for compatibility with v2.5.0 and v2.6.1 + * generated code. + */ + @Deprecated + protected static int hashEnum(EnumLite e) { + return e.getNumber(); + } + + /** + * @deprecated from v3.0.0-beta-3+, for compatibility with v2.5.0 and v2.6.1 + * generated code. + */ + @Deprecated + protected static int hashEnumList(List list) { + int hash = 1; + for (EnumLite e : list) { + hash = 31 * hash + hashEnum(e); + } + return hash; + } +} +} diff --git a/protobuf-api/src/main/java/com/google/protobuf/FlattenedGeneratedMessageV3.java b/protobuf-api/src/main/java/com/google/protobuf/FlattenedGeneratedMessageV3.java new file mode 100644 index 0000000..6b1933a --- /dev/null +++ b/protobuf-api/src/main/java/com/google/protobuf/FlattenedGeneratedMessageV3.java @@ -0,0 +1,4302 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd + +package com.google.protobuf; + +import com.google.protobuf.Descriptors.Descriptor; +import com.google.protobuf.Descriptors.EnumDescriptor; +import com.google.protobuf.Descriptors.EnumValueDescriptor; +import com.google.protobuf.Descriptors.FieldDescriptor; +import com.google.protobuf.Descriptors.FileDescriptor; +import com.google.protobuf.Descriptors.OneofDescriptor; +import com.google.protobuf.Internal.BooleanList; +import com.google.protobuf.Internal.DoubleList; +import com.google.protobuf.Internal.FloatList; +import com.google.protobuf.Internal.IntList; +import com.google.protobuf.Internal.LongList; +import com.google.protobuf.Internal.ProtobufList; + +import java.io.FilterInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.ObjectStreamException; +import java.io.OutputStream; +import java.io.Serializable; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + +import static com.google.protobuf.Internal.checkNotNull; + +/** + * All generated protocol message classes extend this class. This class implements most of the + * Message and Builder interfaces using Java reflection. Users can ignore this class and pretend + * that generated messages implement the Message interface directly. + * + * @author kenton@google.com Kenton Varda + */ +abstract class FlattenedGeneratedMessageV3 implements Message, Serializable { + private static final long serialVersionUID = 1L; + + /** + * For testing. Allows a test to disable the optimization that avoids using field builders for + * nested messages until they are requested. By disabling this optimization, existing tests can be + * reused to test the field builders. + */ + protected static boolean alwaysUseFieldBuilders = false; + + /** + * For use by generated code only. + * + *

TODO: mark this private and final (breaking change) + */ + protected UnknownFieldSet unknownFields; + + protected FlattenedGeneratedMessageV3() { + unknownFields = UnknownFieldSet.getDefaultInstance(); + } + + protected FlattenedGeneratedMessageV3(Builder builder) { + unknownFields = builder.getUnknownFields(); + } + + protected int memoizedHashCode = 0; + + public ByteString toByteString() { + try { + final ByteString.CodedBuilder out = ByteString.newCodedBuilder(getSerializedSize()); + writeTo(out.getCodedOutput()); + return out.build(); + } catch (IOException e) { + throw new RuntimeException(getSerializingExceptionMessage("ByteString"), e); + } + } + + public byte[] toByteArray() { + try { + final byte[] result = new byte[getSerializedSize()]; + final CodedOutputStream output = CodedOutputStream.newInstance(result); + writeTo(output); + output.checkNoSpaceLeft(); + return result; + } catch (IOException e) { + throw new RuntimeException(getSerializingExceptionMessage("byte array"), e); + } + } + + public void writeTo(final OutputStream output) throws IOException { + final int bufferSize = CodedOutputStream.computePreferredBufferSize(getSerializedSize()); + final CodedOutputStream codedOutput = CodedOutputStream.newInstance(output, bufferSize); + writeTo(codedOutput); + codedOutput.flush(); + } + + public void writeDelimitedTo(final OutputStream output) throws IOException { + final int serialized = getSerializedSize(); + final int bufferSize = + CodedOutputStream.computePreferredBufferSize( + CodedOutputStream.computeUInt32SizeNoTag(serialized) + serialized); + final CodedOutputStream codedOutput = CodedOutputStream.newInstance(output, bufferSize); + codedOutput.writeUInt32NoTag(serialized); + writeTo(codedOutput); + codedOutput.flush(); + } + + int getSerializedSize( + Schema schema) { + int memoizedSerializedSize = getMemoizedSerializedSize(); + if (memoizedSerializedSize == -1) { + memoizedSerializedSize = schema.getSerializedSize(this); + setMemoizedSerializedSize(memoizedSerializedSize); + } + return memoizedSerializedSize; + } + + private String getSerializingExceptionMessage(String target) { + return "Serializing " + + getClass().getName() + + " to a " + + target + + " threw an IOException (should never happen)."; + } + + protected static void checkByteStringIsUtf8(ByteString byteString) + throws IllegalArgumentException { + if (!byteString.isValidUtf8()) { + throw new IllegalArgumentException("Byte string is not UTF-8."); + } + } + + /** Interface for an enum which signifies which field in a {@code oneof} was specified. */ + protected interface InternalOneOfEnum { + /** + * Retrieves the field number of the field which was set in this {@code oneof}, or {@code 0} if + * none were. + */ + int getNumber(); + } + + /** + * Interface for the parent of a Builder that allows the builder to communicate invalidations back + * to the parent for use when using nested builders. + */ + protected interface BuilderParent extends Message.BuilderParent{ + + /** + * A builder becomes dirty whenever a field is modified -- including fields in nested builders + * -- and becomes clean when build() is called. Thus, when a builder becomes dirty, all its + * parents become dirty as well, and when it becomes clean, all its children become clean. The + * dirtiness state is used to invalidate certain cached values. + * + *

To this end, a builder calls markDirty() on its parent whenever it transitions from clean + * to dirty. The parent must propagate this call to its own parent, unless it was already dirty, + * in which case the grandparent must necessarily already be dirty as well. The parent can only + * transition back to "clean" after calling build() on all children. + */ + void markDirty(); + } + + public List findInitializationErrors() { + return MessageReflection.findMissingFields(this); + } + + public String getInitializationErrorString() { + return MessageReflection.delimitWithCommas(findInitializationErrors()); + } + + protected int memoizedSize = -1; + + int getMemoizedSerializedSize() { + return memoizedSize; + } + + void setMemoizedSerializedSize(int size) { + memoizedSize = size; + } + + @Override + public boolean equals(final Object other) { + if (other == this) { + return true; + } + if (!(other instanceof Message)) { + return false; + } + final Message otherMessage = (Message) other; + if (getDescriptorForType() != otherMessage.getDescriptorForType()) { + return false; + } + return compareFields(getAllFields(), otherMessage.getAllFields()) + && getUnknownFields().equals(otherMessage.getUnknownFields()); + } + + @Override + public int hashCode() { + int hash = memoizedHashCode; + if (hash == 0) { + hash = 41; + hash = (19 * hash) + getDescriptorForType().hashCode(); + hash = hashFields(hash, getAllFields()); + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + } + return hash; + } + + private static ByteString toByteString(Object value) { + if (value instanceof byte[]) { + return ByteString.copyFrom((byte[]) value); + } else { + return (ByteString) value; + } + } + + /** + * Compares two bytes fields. The parameters must be either a byte array or a ByteString object. + * They can be of different type though. + */ + private static boolean compareBytes(Object a, Object b) { + if (a instanceof byte[] && b instanceof byte[]) { + return Arrays.equals((byte[]) a, (byte[]) b); + } + return toByteString(a).equals(toByteString(b)); + } + + /** Converts a list of MapEntry messages into a Map used for equals() and hashCode(). */ + @SuppressWarnings({"rawtypes", "unchecked"}) + private static Map convertMapEntryListToMap(List list) { + if (list.isEmpty()) { + return Collections.emptyMap(); + } + Map result = new HashMap<>(); + Iterator iterator = list.iterator(); + Message entry = (Message) iterator.next(); + Descriptor descriptor = entry.getDescriptorForType(); + FieldDescriptor key = descriptor.findFieldByName("key"); + FieldDescriptor value = descriptor.findFieldByName("value"); + Object fieldValue = entry.getField(value); + if (fieldValue instanceof EnumValueDescriptor) { + fieldValue = ((EnumValueDescriptor) fieldValue).getNumber(); + } + result.put(entry.getField(key), fieldValue); + while (iterator.hasNext()) { + entry = (Message) iterator.next(); + fieldValue = entry.getField(value); + if (fieldValue instanceof EnumValueDescriptor) { + fieldValue = ((EnumValueDescriptor) fieldValue).getNumber(); + } + result.put(entry.getField(key), fieldValue); + } + return result; + } + + /** Compares two map fields. The parameters must be a list of MapEntry messages. */ + @SuppressWarnings({"rawtypes", "unchecked"}) + private static boolean compareMapField(Object a, Object b) { + Map ma = convertMapEntryListToMap((List) a); + Map mb = convertMapEntryListToMap((List) b); + return MapFieldLite.equals(ma, mb); + } + + /** + * Compares two sets of fields. This method is used to implement {@link + * AbstractMessage#equals(Object)} and {@link AbstractMutableMessage#equals(Object)}. It takes + * special care of bytes fields because immutable messages and mutable messages use different Java + * type to represent a bytes field and this method should be able to compare immutable messages, + * mutable messages and also an immutable message to a mutable message. + */ + static boolean compareFields(Map a, Map b) { + if (a.size() != b.size()) { + return false; + } + for (FieldDescriptor descriptor : a.keySet()) { + if (!b.containsKey(descriptor)) { + return false; + } + Object value1 = a.get(descriptor); + Object value2 = b.get(descriptor); + if (descriptor.getType() == FieldDescriptor.Type.BYTES) { + if (descriptor.isRepeated()) { + List list1 = (List) value1; + List list2 = (List) value2; + if (list1.size() != list2.size()) { + return false; + } + for (int i = 0; i < list1.size(); i++) { + if (!compareBytes(list1.get(i), list2.get(i))) { + return false; + } + } + } else { + // Compares a singular bytes field. + if (!compareBytes(value1, value2)) { + return false; + } + } + } else if (descriptor.isMapField()) { + if (!compareMapField(value1, value2)) { + return false; + } + } else { + // Compare non-bytes fields. + if (!value1.equals(value2)) { + return false; + } + } + } + return true; + } + + /** Calculates the hash code of a map field. {@code value} must be a list of MapEntry messages. */ + @SuppressWarnings("unchecked") + private static int hashMapField(Object value) { + return MapFieldLite.calculateHashCodeForMap(convertMapEntryListToMap((List) value)); + } + + /** Get a hash code for given fields and values, using the given seed. */ + @SuppressWarnings("unchecked") + protected static int hashFields(int hash, Map map) { + for (Map.Entry entry : map.entrySet()) { + FieldDescriptor field = entry.getKey(); + Object value = entry.getValue(); + hash = (37 * hash) + field.getNumber(); + if (field.isMapField()) { + hash = (53 * hash) + hashMapField(value); + } else if (field.getType() != FieldDescriptor.Type.ENUM) { + hash = (53 * hash) + value.hashCode(); + } else if (field.isRepeated()) { + List list = (List) value; + hash = (53 * hash) + Internal.hashEnumList(list); + } else { + hash = (53 * hash) + Internal.hashEnum((Internal.EnumLite) value); + } + } + return hash; + } + +// /** +// * Package private helper method for AbstractParser to create UninitializedMessageException with +// * missing field information. +// */ +// UninitializedMessageException newUninitializedMessageException() { +// return AbstractMessage.Builder.newUninitializedMessageException(this); +// } + + /** TODO: Remove this unnecessary intermediate implementation of this method. */ + @Override + public Parser getParserForType() { + throw new UnsupportedOperationException("This is supposed to be overridden by subclasses."); + } + + /** + * TODO: Stop using SingleFieldBuilder and remove this setting + * + * @see #setAlwaysUseFieldBuildersForTesting(boolean) + */ + static void enableAlwaysUseFieldBuildersForTesting() { + setAlwaysUseFieldBuildersForTesting(true); + } + + /** + * For testing. Allows a test to disable/re-enable the optimization that avoids using field + * builders for nested messages until they are requested. By disabling this optimization, existing + * tests can be reused to test the field builders. See {@link RepeatedFieldBuilder} and {@link + * SingleFieldBuilder}. + * + *

TODO: Stop using SingleFieldBuilder and remove this setting + */ + static void setAlwaysUseFieldBuildersForTesting(boolean useBuilders) { + alwaysUseFieldBuilders = useBuilders; + } + + /** + * Get the FieldAccessorTable for this type. We can't have the message class pass this in to the + * constructor because of bootstrapping trouble with DescriptorProtos. + */ + protected abstract FieldAccessorTable internalGetFieldAccessorTable(); + + public Descriptor getDescriptorForType() { + return internalGetFieldAccessorTable().descriptor; + } + + /** + * TODO: This method should be removed. It enables parsing directly into an + * "immutable" message. Have to leave it for now to support old gencode. + * + * @deprecated use newBuilder().mergeFrom() instead + */ + @Deprecated + protected void mergeFromAndMakeImmutableInternal( + CodedInputStream input, ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + Schema schema = Protobuf.getInstance().schemaFor(this); + try { + schema.mergeFrom(this, CodedInputStreamReader.forCodedInput(input), extensionRegistry); + } catch (InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(this); + } catch (IOException e) { + throw new InvalidProtocolBufferException(e).setUnfinishedMessage(this); + } + schema.makeImmutable(this); + } + + /** + * Internal helper to return a modifiable map containing all the fields. The returned Map is + * modifiable so that the caller can add additional extension fields to implement {@link + * #getAllFields()}. + * + * @param getBytesForString whether to generate ByteString for string fields + */ + private Map getAllFieldsMutable(boolean getBytesForString) { + final TreeMap result = new TreeMap<>(); + final Descriptor descriptor = internalGetFieldAccessorTable().descriptor; + final List fields = descriptor.getFields(); + + for (int i = 0; i < fields.size(); i++) { + FieldDescriptor field = fields.get(i); + final OneofDescriptor oneofDescriptor = field.getContainingOneof(); + + /* + * If the field is part of a Oneof, then at maximum one field in the Oneof is set + * and it is not repeated. There is no need to iterate through the others. + */ + if (oneofDescriptor != null) { + // Skip other fields in the Oneof we know are not set + i += oneofDescriptor.getFieldCount() - 1; + if (!hasOneof(oneofDescriptor)) { + // If no field is set in the Oneof, skip all the fields in the Oneof + continue; + } + // Get the pointer to the only field which is set in the Oneof + field = getOneofFieldDescriptor(oneofDescriptor); + } else { + // If we are not in a Oneof, we need to check if the field is set and if it is repeated + if (field.isRepeated()) { + final List value = (List) getField(field); + if (!value.isEmpty()) { + result.put(field, value); + } + continue; + } + if (!hasField(field)) { + continue; + } + } + // Add the field to the map + if (getBytesForString && field.getJavaType() == FieldDescriptor.JavaType.STRING) { + result.put(field, getFieldRaw(field)); + } else { + result.put(field, getField(field)); + } + } + return result; + } + + // TODO: compute this at {@code build()} time in the Builder class. + public boolean isInitialized() { + for (final FieldDescriptor field : getDescriptorForType().getFields()) { + // Check that all required fields are present. + if (field.isRequired()) { + if (!hasField(field)) { + return false; + } + } + // Check that embedded messages are initialized. + if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { + if (field.isRepeated()) { + @SuppressWarnings("unchecked") + final List messageList = (List) getField(field); + for (final Message element : messageList) { + if (!element.isInitialized()) { + return false; + } + } + } else { + if (hasField(field) && !((Message) getField(field)).isInitialized()) { + return false; + } + } + } + } + + return true; + } + + public Map getAllFields() { + return Collections.unmodifiableMap(getAllFieldsMutable(/* getBytesForString= */ false)); + } + + /** + * Returns a collection of all the fields in this message which are set and their corresponding + * values. A singular ("required" or "optional") field is set iff hasField() returns true for that + * field. A "repeated" field is set iff getRepeatedFieldCount() is greater than zero. The values + * are exactly what would be returned by calling {@link #getFieldRaw(FieldDescriptor)} + * for each field. The map is guaranteed to be a sorted map, so iterating over it will return + * fields in order by field number. + */ + Map getAllFieldsRaw() { + return Collections.unmodifiableMap(getAllFieldsMutable(/* getBytesForString= */ true)); + } + + public boolean hasOneof(final OneofDescriptor oneof) { + return internalGetFieldAccessorTable().getOneof(oneof).has(this); + } + + public FieldDescriptor getOneofFieldDescriptor(final OneofDescriptor oneof) { + return internalGetFieldAccessorTable().getOneof(oneof).get(this); + } + + public boolean hasField(final FieldDescriptor field) { + return internalGetFieldAccessorTable().getField(field).has(this); + } + + public Object getField(final FieldDescriptor field) { + return internalGetFieldAccessorTable().getField(field).get(this); + } + + /** + * Obtains the value of the given field, or the default value if it is not set. For primitive + * fields, the boxed primitive value is returned. For enum fields, the EnumValueDescriptor for the + * value is returned. For embedded message fields, the sub-message is returned. For repeated + * fields, a java.util.List is returned. For present string fields, a ByteString is returned + * representing the bytes that the field contains. + */ + Object getFieldRaw(final FieldDescriptor field) { + return internalGetFieldAccessorTable().getField(field).getRaw(this); + } + + public int getRepeatedFieldCount(final FieldDescriptor field) { + return internalGetFieldAccessorTable().getField(field).getRepeatedCount(this); + } + + public Object getRepeatedField(final FieldDescriptor field, final int index) { + return internalGetFieldAccessorTable().getField(field).getRepeated(this, index); + } + + // TODO: This method should be final. + public UnknownFieldSet getUnknownFields() { + return unknownFields; + } + + // TODO: This should go away when Schema classes cannot modify immutable + // GeneratedMessageV3 objects anymore. + void setUnknownFields(UnknownFieldSet unknownFields) { + this.unknownFields = unknownFields; + } + + /** + * Called by subclasses to parse an unknown field. + * + *

TODO remove this method + * + * @return {@code true} unless the tag is an end-group tag. + */ + protected boolean parseUnknownField( + CodedInputStream input, + UnknownFieldSet.Builder unknownFields, + ExtensionRegistryLite extensionRegistry, + int tag) + throws IOException { + if (input.shouldDiscardUnknownFields()) { + return input.skipField(tag); + } + return unknownFields.mergeFieldFrom(tag, input); + } + + /** + * Delegates to parseUnknownField. This method is obsolete, but we must retain it for + * compatibility with older generated code. + * + *

TODO remove this method + */ + protected boolean parseUnknownFieldProto3( + CodedInputStream input, + UnknownFieldSet.Builder unknownFields, + ExtensionRegistryLite extensionRegistry, + int tag) + throws IOException { + return parseUnknownField(input, unknownFields, extensionRegistry, tag); + } + + /** Used by generated code. */ + @SuppressWarnings("ProtoParseWithRegistry") + protected static M parseWithIOException(Parser parser, InputStream input) + throws IOException { + try { + return parser.parseFrom(input); + } catch (InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } + } + + /** Used by generated code. */ + protected static M parseWithIOException( + Parser parser, InputStream input, ExtensionRegistryLite extensions) throws IOException { + try { + return parser.parseFrom(input, extensions); + } catch (InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } + } + + /** Used by generated code. */ + @SuppressWarnings("ProtoParseWithRegistry") + protected static M parseWithIOException( + Parser parser, CodedInputStream input) throws IOException { + try { + return parser.parseFrom(input); + } catch (InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } + } + + /** Used by generated code. */ + protected static M parseWithIOException( + Parser parser, CodedInputStream input, ExtensionRegistryLite extensions) + throws IOException { + try { + return parser.parseFrom(input, extensions); + } catch (InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } + } + + /** Used by generated code. */ + @SuppressWarnings("ProtoParseWithRegistry") + protected static M parseDelimitedWithIOException( + Parser parser, InputStream input) throws IOException { + try { + return parser.parseDelimitedFrom(input); + } catch (InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } + } + + /** Used by generated code. */ + protected static M parseDelimitedWithIOException( + Parser parser, InputStream input, ExtensionRegistryLite extensions) throws IOException { + try { + return parser.parseDelimitedFrom(input, extensions); + } catch (InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } + } + + protected static boolean canUseUnsafe() { + return UnsafeUtil.hasUnsafeArrayOperations() && UnsafeUtil.hasUnsafeByteBufferOperations(); + } + + protected static IntList emptyIntList() { + return IntArrayList.emptyList(); + } + + // TODO: Unused. Remove. + protected static IntList newIntList() { + return new IntArrayList(); + } + + // TODO: Redundant with makeMutableCopy(). Remove. + protected static IntList mutableCopy(IntList list) { + return makeMutableCopy(list); + } + + // TODO: Redundant with makeMutableCopy(). Remove. + protected static LongList mutableCopy(LongList list) { + return makeMutableCopy(list); + } + + // TODO: Redundant with makeMutableCopy(). Remove. + protected static FloatList mutableCopy(FloatList list) { + return makeMutableCopy(list); + } + + // TODO: Redundant with makeMutableCopy(). Remove. + protected static DoubleList mutableCopy(DoubleList list) { + return makeMutableCopy(list); + } + + // TODO: Redundant with makeMutableCopy(). Remove. + protected static BooleanList mutableCopy(BooleanList list) { + return makeMutableCopy(list); + } + + protected static LongList emptyLongList() { + return LongArrayList.emptyList(); + } + + // TODO: Unused. Remove. + protected static LongList newLongList() { + return new LongArrayList(); + } + + protected static FloatList emptyFloatList() { + return FloatArrayList.emptyList(); + } + + // TODO: Unused. Remove. + protected static FloatList newFloatList() { + return new FloatArrayList(); + } + + protected static DoubleList emptyDoubleList() { + return DoubleArrayList.emptyList(); + } + + // TODO: Unused. Remove. + protected static DoubleList newDoubleList() { + return new DoubleArrayList(); + } + + protected static BooleanList emptyBooleanList() { + return BooleanArrayList.emptyList(); + } + + // TODO: Unused. Remove. + protected static BooleanList newBooleanList() { + return new BooleanArrayList(); + } + + protected static > ListT makeMutableCopy(ListT list) { + return makeMutableCopy(list, 0); + } + + @SuppressWarnings("unchecked") // Guaranteed by proto runtime. + protected static > ListT makeMutableCopy( + ListT list, int minCapacity) { + int size = list.size(); + if (minCapacity <= size) { + minCapacity = size * 2; + } + if (minCapacity <= 0) { + minCapacity = AbstractProtobufList.DEFAULT_CAPACITY; + } + + return (ListT) list.mutableCopyWithCapacity(minCapacity); + } + + @SuppressWarnings("unchecked") // The empty list can be safely cast + protected static ProtobufList emptyList(Class elementType) { + return (ProtobufList) ProtobufArrayList.emptyList(); + } + + public void writeTo(final CodedOutputStream output) throws IOException { + MessageReflection.writeMessageTo(this, getAllFieldsRaw(), output, false); + } + + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) { + return size; + } + + memoizedSize = MessageReflection.getSerializedSize( + this, getAllFieldsRaw()); + return memoizedSize; + } + + /** + * This class is used to make a generated protected method inaccessible from user's code (e.g., + * the {@link #newInstance} method below). When this class is used as a parameter's type in a + * generated protected method, the method is visible to user's code in the same package, but since + * the constructor of this class is private to protobuf runtime, user's code can't obtain an + * instance of this class and as such can't actually make a method call on the protected method. + */ + protected static final class UnusedPrivateParameter { + static final UnusedPrivateParameter INSTANCE = new UnusedPrivateParameter(); + + private UnusedPrivateParameter() {} + } + + /** Creates a new instance of this message type. Overridden in the generated code. */ + @SuppressWarnings({"unused"}) + protected Object newInstance(UnusedPrivateParameter unused) { + throw new UnsupportedOperationException("This method must be overridden by the subclass."); + } + + /** + * Used by parsing constructors in generated classes. + * + *

TODO: remove unused method (extensions should be immutable after build) + */ + protected void makeExtensionsImmutable() { + // Noop for messages without extensions. + } + + /** TODO: remove this together with GeneratedMessageV3.BuilderParent. */ + protected abstract Message.Builder newBuilderForType(BuilderParent parent); + + /** TODO: generated class should implement this directly */ + protected Message.Builder newBuilderForType(final Message.BuilderParent parent) { + return newBuilderForType( + new BuilderParent() { + @Override + public void markDirty() { + parent.markDirty(); + } + }); + } + + /** Builder class for {@link FlattenedGeneratedMessageV3}. */ + @SuppressWarnings("unchecked") + public abstract static class Builder> + implements Message.Builder { + + private BuilderParent builderParent; + + private BuilderParentImpl meAsParent; + + // Indicates that we've built a message and so we are now obligated + // to dispatch dirty invalidations. See GeneratedMessageV3.BuilderListener. + private boolean isClean; + + /** + * This field holds either an {@link UnknownFieldSet} or {@link UnknownFieldSet.Builder}. + * + *

We use an object because it should only be one or the other of those things at a time and + * Object is the only common base. This also saves space. + * + *

Conversions are lazy: if {@link #setUnknownFields} is called, this will contain {@link + * UnknownFieldSet}. If unknown fields are merged into this builder, the current {@link + * UnknownFieldSet} will be converted to a {@link UnknownFieldSet.Builder} and left that way + * until either {@link #setUnknownFields} or {@link #buildPartial} or {@link #build} is called. + */ + private Object unknownFieldsOrBuilder = UnknownFieldSet.getDefaultInstance(); + + protected Builder() { + this(null); + } + + protected Builder(BuilderParent builderParent) { + this.builderParent = builderParent; + } + + static final class LimitedInputStream extends FilterInputStream { + private int limit; + + LimitedInputStream(InputStream in, int limit) { + super(in); + this.limit = limit; + } + + @Override + public int available() throws IOException { + return Math.min(super.available(), limit); + } + + @Override + public int read() throws IOException { + if (limit <= 0) { + return -1; + } + final int result = super.read(); + if (result >= 0) { + --limit; + } + return result; + } + + @Override + public int read(final byte[] b, final int off, int len) throws IOException { + if (limit <= 0) { + return -1; + } + len = Math.min(len, limit); + final int result = super.read(b, off, len); + if (result >= 0) { + limit -= result; + } + return result; + } + + @Override + public long skip(final long n) throws IOException { + // because we take the minimum of an int and a long, result is guaranteed to be + // less than or equal to Integer.MAX_INT so this cast is safe + int result = (int) super.skip(Math.min(n, limit)); + if (result >= 0) { + // if the superclass adheres to the contract for skip, this condition is always true + limit -= result; + } + return result; + } + } + + @Override + public boolean mergeDelimitedFrom( + final InputStream input, final ExtensionRegistryLite extensionRegistry) throws IOException { + final int firstByte = input.read(); + if (firstByte == -1) { + return false; + } + final int size = CodedInputStream.readRawVarint32(firstByte, input); + final InputStream limitedInput = new AbstractMessageLite.Builder.LimitedInputStream(input, size); + mergeFrom(limitedInput, extensionRegistry); + return true; + } + + @Override + public boolean mergeDelimitedFrom(final InputStream input) throws IOException { + return mergeDelimitedFrom(input, ExtensionRegistryLite.getEmptyRegistry()); + } + + @Override + @SuppressWarnings("unchecked") // isInstance takes care of this + public BuilderT mergeFrom(final MessageLite other) { + if (!getDefaultInstanceForType().getClass().isInstance(other)) { + throw new IllegalArgumentException( + "mergeFrom(MessageLite) can only merge messages of the same type."); + } + + return internalMergeFrom(other); + } + + private String getReadingExceptionMessage(String target) { + return "Reading " + + getClass().getName() + + " from a " + + target + + " threw an IOException (should never happen)."; + } + + // We check nulls as we iterate to avoid iterating over values twice. + private static void addAllCheckingNulls(Iterable values, List list) { + if (list instanceof ArrayList && values instanceof Collection) { + ((ArrayList) list).ensureCapacity(list.size() + ((Collection) values).size()); + } + int begin = list.size(); + for (T value : values) { + if (value == null) { + // encountered a null value so we must undo our modifications prior to throwing + String message = "Element at index " + (list.size() - begin) + " is null."; + for (int i = list.size() - 1; i >= begin; i--) { + list.remove(i); + } + throw new NullPointerException(message); + } + list.add(value); + } + } + + /** Construct an UninitializedMessageException reporting missing fields in the given message. */ + protected static UninitializedMessageException newUninitializedMessageException( + MessageLite message) { + return new UninitializedMessageException(message); + } + + // For binary compatibility. + @Deprecated + protected static void addAll(final Iterable values, final Collection list) { + addAll(values, (List) list); + } + + /** + * Adds the {@code values} to the {@code list}. This is a helper method used by generated code. + * Users should ignore it. + * + * @throws NullPointerException if {@code values} or any of the elements of {@code values} is + * null. + */ + protected static void addAll(final Iterable values, final List list) { + checkNotNull(values); + if (values instanceof LazyStringList) { + // For StringOrByteStringLists, check the underlying elements to avoid + // forcing conversions of ByteStrings to Strings. + // TODO: Could we just prohibit nulls in all protobuf lists and get rid of this? Is + // if even possible to hit this condition as all protobuf methods check for null first, + // right? + List lazyValues = ((LazyStringList) values).getUnderlyingElements(); + LazyStringList lazyList = (LazyStringList) list; + int begin = list.size(); + for (Object value : lazyValues) { + if (value == null) { + // encountered a null value so we must undo our modifications prior to throwing + String message = "Element at index " + (lazyList.size() - begin) + " is null."; + for (int i = lazyList.size() - 1; i >= begin; i--) { + lazyList.remove(i); + } + throw new NullPointerException(message); + } + if (value instanceof ByteString) { + lazyList.add((ByteString) value); + } else { + lazyList.add((String) value); + } + } + } else { + if (values instanceof PrimitiveNonBoxingCollection) { + list.addAll((Collection) values); + } else { + addAllCheckingNulls(values, list); + } + } + } + + @Override + public List findInitializationErrors() { + return MessageReflection.findMissingFields(this); + } + + @Override + public String getInitializationErrorString() { + return MessageReflection.delimitWithCommas(findInitializationErrors()); + } + + protected BuilderT internalMergeFrom(MessageLite other) { + return mergeFrom((Message) other); + } + + @Override + public BuilderT mergeFrom(final Message other) { + return mergeFrom(other, other.getAllFields()); + } + + BuilderT mergeFrom(final Message other, Map allFields) { + if (other.getDescriptorForType() != getDescriptorForType()) { + throw new IllegalArgumentException( + "mergeFrom(Message) can only merge messages of the same type."); + } + + // Note: We don't attempt to verify that other's fields have valid + // types. Doing so would be a losing battle. We'd have to verify + // all sub-messages as well, and we'd have to make copies of all of + // them to insure that they don't change after verification (since + // the Message interface itself cannot enforce immutability of + // implementations). + + for (final Map.Entry entry : allFields.entrySet()) { + final FieldDescriptor field = entry.getKey(); + if (field.isRepeated()) { + for (final Object element : (List) entry.getValue()) { + addRepeatedField(field, element); + } + } else if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { + final Message existingValue = (Message) getField(field); + if (existingValue == existingValue.getDefaultInstanceForType()) { + setField(field, entry.getValue()); + } else { + setField( + field, + existingValue + .newBuilderForType() + .mergeFrom(existingValue) + .mergeFrom((Message) entry.getValue()) + .build()); + } + } else { + setField(field, entry.getValue()); + } + } + + mergeUnknownFields(other.getUnknownFields()); + + return (BuilderT) this; + } + + @Override + public BuilderT mergeFrom(final CodedInputStream input) throws IOException { + return mergeFrom(input, ExtensionRegistry.getEmptyRegistry()); + } + + @Override + public BuilderT mergeFrom( + final CodedInputStream input, final ExtensionRegistryLite extensionRegistry) + throws IOException { + boolean discardUnknown = input.shouldDiscardUnknownFields(); + final UnknownFieldSet.Builder unknownFields = + discardUnknown ? null : getUnknownFieldSetBuilder(); + MessageReflection.mergeMessageFrom(this, unknownFields, input, extensionRegistry); + if (unknownFields != null) { + setUnknownFieldSetBuilder(unknownFields); + } + return (BuilderT) this; + } + + @Override + public String toString() { + return TextFormat.printer().printToString(this); + } + + /** Construct an UninitializedMessageException reporting missing fields in the given message. */ + protected static UninitializedMessageException newUninitializedMessageException( + Message message) { + return new UninitializedMessageException(MessageReflection.findMissingFields(message)); + } + + // =============================================================== + // The following definitions seem to be required in order to make javac + // not produce weird errors like: + // + // java/com/google/protobuf/DynamicMessage.java:203: types + // com.google.protobuf.AbstractMessage.Builder< + // com.google.protobuf.DynamicMessage.Builder> and + // com.google.protobuf.AbstractMessage.Builder< + // com.google.protobuf.DynamicMessage.Builder> are incompatible; both + // define mergeFrom(com.google.protobuf.ByteString), but with unrelated + // return types. + // + // Strangely, these lines are only needed if javac is invoked separately + // on AbstractMessage.java and AbstractMessageLite.java. If javac is + // invoked on both simultaneously, it works. (Or maybe the important + // point is whether or not DynamicMessage.java is compiled together with + // AbstractMessageLite.java -- not sure.) I suspect this is a compiler + // bug. + + public BuilderT mergeFrom(final ByteString data) throws InvalidProtocolBufferException { + try { + final CodedInputStream input = data.newCodedInput(); + mergeFrom(input); + input.checkLastTagWas(0); + return (BuilderT) this; + } catch (InvalidProtocolBufferException e) { + throw e; + } catch (IOException e) { + throw new RuntimeException(getReadingExceptionMessage("ByteString"), e); + } + } + + public BuilderT mergeFrom( + final ByteString data, final ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + try { + final CodedInputStream input = data.newCodedInput(); + mergeFrom(input, extensionRegistry); + input.checkLastTagWas(0); + return (BuilderT) this; + } catch (InvalidProtocolBufferException e) { + throw e; + } catch (IOException e) { + throw new RuntimeException(getReadingExceptionMessage("ByteString"), e); + } + } + + public BuilderT mergeFrom(final byte[] data) throws InvalidProtocolBufferException { + return mergeFrom(data, 0, data.length); + } + + public BuilderT mergeFrom(final byte[] data, final int off, final int len) + throws InvalidProtocolBufferException { + try { + final CodedInputStream input = CodedInputStream.newInstance(data, off, len); + mergeFrom(input); + input.checkLastTagWas(0); + return (BuilderT) this; + } catch (InvalidProtocolBufferException e) { + throw e; + } catch (IOException e) { + throw new RuntimeException(getReadingExceptionMessage("byte array"), e); + } + } + + public BuilderT mergeFrom(final byte[] data, final ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + return mergeFrom(data, 0, data.length, extensionRegistry); + } + + public BuilderT mergeFrom( + final byte[] data, + final int off, + final int len, + final ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + try { + final CodedInputStream input = CodedInputStream.newInstance(data, off, len); + mergeFrom(input, extensionRegistry); + input.checkLastTagWas(0); + return (BuilderT) this; + } catch (InvalidProtocolBufferException e) { + throw e; + } catch (IOException e) { + throw new RuntimeException(getReadingExceptionMessage("byte array"), e); + } + } + + public BuilderT mergeFrom(final InputStream input) throws IOException { + final CodedInputStream codedInput = CodedInputStream.newInstance(input); + mergeFrom(codedInput); + codedInput.checkLastTagWas(0); + return (BuilderT) this; + } + + public BuilderT mergeFrom( + final InputStream input, final ExtensionRegistryLite extensionRegistry) throws IOException { + final CodedInputStream codedInput = CodedInputStream.newInstance(input); + mergeFrom(codedInput, extensionRegistry); + codedInput.checkLastTagWas(0); + return (BuilderT) this; + } + + /** + * @deprecated from v3.0.0-beta-3+, for compatibility with v2.5.0 and v2.6.1 + * generated code. + */ + @Deprecated + protected static int hashLong(long n) { + return (int) (n ^ (n >>> 32)); + } + + /** + * @deprecated from v3.0.0-beta-3+, for compatibility with v2.5.0 and v2.6.1 + * generated code. + */ + @Deprecated + protected static int hashBoolean(boolean b) { + return b ? 1231 : 1237; + } + + /** + * @deprecated from v3.0.0-beta-3+, for compatibility with v2.5.0 and v2.6.1 + * generated code. + */ + @Deprecated + protected static int hashEnum(Internal.EnumLite e) { + return e.getNumber(); + } + + /** + * @deprecated from v3.0.0-beta-3+, for compatibility with v2.5.0 and v2.6.1 + * generated code. + */ + @Deprecated + protected static int hashEnumList(List list) { + int hash = 1; + for (Internal.EnumLite e : list) { + hash = 31 * hash + hashEnum(e); + } + return hash; + } + + void dispose() { + builderParent = null; + } + + /** Called by the subclass when a message is built. */ + protected void onBuilt() { + if (builderParent != null) { + markClean(); + } + } + + /** + * Called by the subclass or a builder to notify us that a message was built and may be cached + * and therefore invalidations are needed. + */ + protected void markClean() { + this.isClean = true; + } + + /** + * Gets whether invalidations are needed + * + * @return whether invalidations are needed + */ + protected boolean isClean() { + return isClean; + } + + @Override + public BuilderT clone() { + BuilderT builder = (BuilderT) getDefaultInstanceForType().newBuilderForType(); + builder.mergeFrom(buildPartial()); + return builder; + } + + /** + * Called by the initialization and clear code paths to allow subclasses to reset any of their + * builtin fields back to the initial values. + */ + @Override + public BuilderT clear() { + unknownFieldsOrBuilder = UnknownFieldSet.getDefaultInstance(); + onChanged(); + return (BuilderT) this; + } + + /** + * Get the FieldAccessorTable for this type. We can't have the message class pass this in to the + * constructor because of bootstrapping trouble with DescriptorProtos. + */ + protected abstract FieldAccessorTable internalGetFieldAccessorTable(); + + @Override + public Descriptor getDescriptorForType() { + return internalGetFieldAccessorTable().descriptor; + } + + @Override + public Map getAllFields() { + return Collections.unmodifiableMap(getAllFieldsMutable()); + } + + /** Internal helper which returns a mutable map. */ + private Map getAllFieldsMutable() { + final TreeMap result = new TreeMap<>(); + final Descriptor descriptor = internalGetFieldAccessorTable().descriptor; + final List fields = descriptor.getFields(); + + for (int i = 0; i < fields.size(); i++) { + FieldDescriptor field = fields.get(i); + final OneofDescriptor oneofDescriptor = field.getContainingOneof(); + + /* + * If the field is part of a Oneof, then at maximum one field in the Oneof is set + * and it is not repeated. There is no need to iterate through the others. + */ + if (oneofDescriptor != null) { + // Skip other fields in the Oneof we know are not set + i += oneofDescriptor.getFieldCount() - 1; + if (!hasOneof(oneofDescriptor)) { + // If no field is set in the Oneof, skip all the fields in the Oneof + continue; + } + // Get the pointer to the only field which is set in the Oneof + field = getOneofFieldDescriptor(oneofDescriptor); + } else { + // If we are not in a Oneof, we need to check if the field is set and if it is repeated + if (field.isRepeated()) { + final List value = (List) getField(field); + if (!value.isEmpty()) { + result.put(field, value); + } + continue; + } + if (!hasField(field)) { + continue; + } + } + // Add the field to the map + result.put(field, getField(field)); + } + return result; + } + + @Override + public Message.Builder newBuilderForField(final FieldDescriptor field) { + return internalGetFieldAccessorTable().getField(field).newBuilder(); + } + + @Override + public Message.Builder getFieldBuilder(final FieldDescriptor field) { + return internalGetFieldAccessorTable().getField(field).getBuilder(this); + } + + @Override + public Message.Builder getRepeatedFieldBuilder(final FieldDescriptor field, int index) { + return internalGetFieldAccessorTable().getField(field).getRepeatedBuilder(this, index); + } + + @Override + public boolean hasOneof(final OneofDescriptor oneof) { + return internalGetFieldAccessorTable().getOneof(oneof).has(this); + } + + @Override + public FieldDescriptor getOneofFieldDescriptor(final OneofDescriptor oneof) { + return internalGetFieldAccessorTable().getOneof(oneof).get(this); + } + + @Override + public boolean hasField(final FieldDescriptor field) { + return internalGetFieldAccessorTable().getField(field).has(this); + } + + @Override + public Object getField(final FieldDescriptor field) { + Object object = internalGetFieldAccessorTable().getField(field).get(this); + if (field.isRepeated()) { + // The underlying list object is still modifiable at this point. + // Make sure not to expose the modifiable list to the caller. + return Collections.unmodifiableList((List) object); + } else { + return object; + } + } + + @Override + public BuilderT setField(final FieldDescriptor field, final Object value) { + internalGetFieldAccessorTable().getField(field).set(this, value); + return (BuilderT) this; + } + + @Override + public BuilderT clearField(final FieldDescriptor field) { + internalGetFieldAccessorTable().getField(field).clear(this); + return (BuilderT) this; + } + + @Override + public BuilderT clearOneof(final OneofDescriptor oneof) { + internalGetFieldAccessorTable().getOneof(oneof).clear(this); + return (BuilderT) this; + } + + @Override + public int getRepeatedFieldCount(final FieldDescriptor field) { + return internalGetFieldAccessorTable().getField(field).getRepeatedCount(this); + } + + @Override + public Object getRepeatedField(final FieldDescriptor field, final int index) { + return internalGetFieldAccessorTable().getField(field).getRepeated(this, index); + } + + @Override + public BuilderT setRepeatedField( + final FieldDescriptor field, final int index, final Object value) { + internalGetFieldAccessorTable().getField(field).setRepeated(this, index, value); + return (BuilderT) this; + } + + @Override + public BuilderT addRepeatedField(final FieldDescriptor field, final Object value) { + internalGetFieldAccessorTable().getField(field).addRepeated(this, value); + return (BuilderT) this; + } + + private BuilderT setUnknownFieldsInternal(final UnknownFieldSet unknownFields) { + unknownFieldsOrBuilder = unknownFields; + onChanged(); + return (BuilderT) this; + } + + @Override + public BuilderT setUnknownFields(final UnknownFieldSet unknownFields) { + return setUnknownFieldsInternal(unknownFields); + } + + /** + * This method is obsolete, but we must retain it for compatibility with older generated code. + */ + protected BuilderT setUnknownFieldsProto3(final UnknownFieldSet unknownFields) { + return setUnknownFieldsInternal(unknownFields); + } + + @Override + public BuilderT mergeUnknownFields(final UnknownFieldSet unknownFields) { + if (UnknownFieldSet.getDefaultInstance().equals(unknownFields)) { + return (BuilderT) this; + } + + if (UnknownFieldSet.getDefaultInstance().equals(unknownFieldsOrBuilder)) { + unknownFieldsOrBuilder = unknownFields; + onChanged(); + return (BuilderT) this; + } + + getUnknownFieldSetBuilder().mergeFrom(unknownFields); + onChanged(); + return (BuilderT) this; + } + + @Override + public boolean isInitialized() { + for (final FieldDescriptor field : getDescriptorForType().getFields()) { + // Check that all required fields are present. + if (field.isRequired()) { + if (!hasField(field)) { + return false; + } + } + // Check that embedded messages are initialized. + if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { + if (field.isRepeated()) { + @SuppressWarnings("unchecked") + final List messageList = (List) getField(field); + for (final Message element : messageList) { + if (!element.isInitialized()) { + return false; + } + } + } else { + if (hasField(field) && !((Message) getField(field)).isInitialized()) { + return false; + } + } + } + } + return true; + } + + @Override + public final UnknownFieldSet getUnknownFields() { + if (unknownFieldsOrBuilder instanceof UnknownFieldSet) { + return (UnknownFieldSet) unknownFieldsOrBuilder; + } else { + return ((UnknownFieldSet.Builder) unknownFieldsOrBuilder).buildPartial(); + } + } + + /** + * Called by generated subclasses to parse an unknown field. + * + * @return {@code true} unless the tag is an end-group tag. + */ + protected boolean parseUnknownField( + CodedInputStream input, ExtensionRegistryLite extensionRegistry, int tag) + throws IOException { + if (input.shouldDiscardUnknownFields()) { + return input.skipField(tag); + } + return getUnknownFieldSetBuilder().mergeFieldFrom(tag, input); + } + + /** Called by generated subclasses to add to the unknown field set. */ + protected final void mergeUnknownLengthDelimitedField(int number, ByteString bytes) { + getUnknownFieldSetBuilder().mergeLengthDelimitedField(number, bytes); + } + + /** Called by generated subclasses to add to the unknown field set. */ + protected final void mergeUnknownVarintField(int number, int value) { + getUnknownFieldSetBuilder().mergeVarintField(number, value); + } + + protected UnknownFieldSet.Builder getUnknownFieldSetBuilder() { + if (unknownFieldsOrBuilder instanceof UnknownFieldSet) { + unknownFieldsOrBuilder = ((UnknownFieldSet) unknownFieldsOrBuilder).toBuilder(); + } + onChanged(); + return (UnknownFieldSet.Builder) unknownFieldsOrBuilder; + } + + protected void setUnknownFieldSetBuilder(UnknownFieldSet.Builder builder) { + unknownFieldsOrBuilder = builder; + onChanged(); + } + + /** + * Implementation of {@link BuilderParent} for giving to our children. This small inner class + * makes it so we don't publicly expose the BuilderParent methods. + */ + private class BuilderParentImpl implements BuilderParent { + + @Override + public void markDirty() { + onChanged(); + } + } + + /** + * Gets the {@link BuilderParent} for giving to our children. + * + * @return The builder parent for our children. + */ + protected BuilderParent getParentForChildren() { + if (meAsParent == null) { + meAsParent = new BuilderParentImpl(); + } + return meAsParent; + } + + /** + * Called when a builder or one of its nested children has changed and any parent should be + * notified of its invalidation. + */ + protected final void onChanged() { + if (isClean && builderParent != null) { + builderParent.markDirty(); + + // Don't keep dispatching invalidations until build is called again. + isClean = false; + } + } + + /** + * Gets the map field with the given field number. This method should be overridden in the + * generated message class if the message contains map fields. + * + *

Unlike other field types, reflection support for map fields can't be implemented based on + * generated public API because we need to access a map field as a list in reflection API but + * the generated API only allows us to access it as a map. This method returns the underlying + * map field directly and thus enables us to access the map field as a list. + */ + @SuppressWarnings({"unused", "rawtypes"}) + protected MapFieldReflectionAccessor internalGetMapFieldReflection(int fieldNumber) { + return internalGetMapField(fieldNumber); + } + + /** TODO: Remove, exists for compatibility with generated code. */ + @Deprecated + @SuppressWarnings({"unused", "rawtypes"}) + protected MapField internalGetMapField(int fieldNumber) { + // Note that we can't use descriptor names here because this method will + // be called when descriptor is being initialized. + throw new IllegalArgumentException("No map fields found in " + getClass().getName()); + } + + /** Like {@link #internalGetMapFieldReflection} but return a mutable version. */ + @SuppressWarnings({"unused", "rawtypes"}) + protected MapFieldReflectionAccessor internalGetMutableMapFieldReflection(int fieldNumber) { + return internalGetMutableMapField(fieldNumber); + } + + /** TODO: Remove, exists for compatibility with generated code. */ + @Deprecated + @SuppressWarnings({"unused", "rawtypes"}) + protected MapField internalGetMutableMapField(int fieldNumber) { + // Note that we can't use descriptor names here because this method will + // be called when descriptor is being initialized. + throw new IllegalArgumentException("No map fields found in " + getClass().getName()); + } + } + + // ================================================================= + // Extensions-related stuff + + /** Extends {@link MessageOrBuilder} with extension-related functions. */ + public interface ExtendableMessageOrBuilder> + extends MessageOrBuilder { + // Re-define for return type covariance. + @Override + Message getDefaultInstanceForType(); + + /** Check if a singular extension is present. */ + boolean hasExtension(ExtensionLite extension); + + /** Get the number of elements in a repeated extension. */ + int getExtensionCount(ExtensionLite> extension); + + /** Get the value of an extension. */ + T getExtension(ExtensionLite extension); + + /** Get one element of a repeated extension. */ + T getExtension(ExtensionLite> extension, int index); + + /** + * Check if a singular extension is present. + *

TODO: handled by ExtensionLite version + */ + boolean hasExtension( + Extension extension); + /** + * Check if a singular extension is present. + *

TODO: handled by ExtensionLite version + */ + boolean hasExtension( + GeneratedExtension extension); + /** + * Get the number of elements in a repeated extension. + *

TODO: handled by ExtensionLite version + */ + int getExtensionCount( + Extension> extension); + /** + * Get the number of elements in a repeated extension. + *

TODO: handled by ExtensionLite version + */ + int getExtensionCount( + GeneratedExtension> extension); + /** + * Get the value of an extension. + *

TODO: handled by ExtensionLite version + */ + T getExtension( + Extension extension); + /** + * Get the value of an extension. + *

TODO: handled by ExtensionLite version + */ + T getExtension( + GeneratedExtension extension); + /** + * Get one element of a repeated extension. + *

TODO: handled by ExtensionLite version + */ + T getExtension( + Extension> extension, + int index); + /** + * Get one element of a repeated extension. + *

TODO: handled by ExtensionLite version + */ + T getExtension( + GeneratedExtension> extension, + int index); + } + + /** + * Generated message classes for message types that contain extension ranges subclass this. + * + *

This class implements type-safe accessors for extensions. They implement all the same + * operations that you can do with normal fields -- e.g. "has", "get", and "getCount" -- but for + * extensions. The extensions are identified using instances of the class {@link + * GeneratedExtension}; the protocol compiler generates a static instance of this class for every + * extension in its input. Through the magic of generics, all is made type-safe. + * + *

For example, imagine you have the {@code .proto} file: + * + *

+   * option java_class = "MyProto";
+   *
+   * message Foo {
+   *   extensions 1000 to max;
+   * }
+   *
+   * extend Foo {
+   *   optional int32 bar;
+   * }
+   * 
+ * + *

Then you might write code like: + * + *

+   * MyProto.Foo foo = getFoo();
+   * int i = foo.getExtension(MyProto.bar);
+   * 
+ * + *

See also {@link ExtendableBuilder}. + */ + public abstract static class ExtendableMessage> + extends FlattenedGeneratedMessageV3 implements ExtendableMessageOrBuilder { + + private static final long serialVersionUID = 1L; + + private final FieldSet extensions; + + protected ExtendableMessage() { + this.extensions = FieldSet.newFieldSet(); + } + + protected ExtendableMessage(ExtendableBuilder builder) { + super(builder); + this.extensions = builder.buildExtensions(); + } + + private void verifyExtensionContainingType(final Extension extension) { + if (extension.getDescriptor().getContainingType() != getDescriptorForType()) { + // This can only happen if someone uses unchecked operations. + throw new IllegalArgumentException( + "Extension is for type \"" + + extension.getDescriptor().getContainingType().getFullName() + + "\" which does not match message type \"" + + getDescriptorForType().getFullName() + + "\"."); + } + } + + /** Check if a singular extension is present. */ + @Override + public final boolean hasExtension(final ExtensionLite extensionLite) { + Extension extension = checkNotLite(extensionLite); + + verifyExtensionContainingType(extension); + return extensions.hasField(extension.getDescriptor()); + } + + /** Get the number of elements in a repeated extension. */ + @Override + public final int getExtensionCount(final ExtensionLite> extensionLite) { + Extension> extension = checkNotLite(extensionLite); + + verifyExtensionContainingType(extension); + final FieldDescriptor descriptor = extension.getDescriptor(); + return extensions.getRepeatedFieldCount(descriptor); + } + + /** Get the value of an extension. */ + @Override + @SuppressWarnings("unchecked") + public final T getExtension(final ExtensionLite extensionLite) { + Extension extension = checkNotLite(extensionLite); + + verifyExtensionContainingType(extension); + FieldDescriptor descriptor = extension.getDescriptor(); + final Object value = extensions.getField(descriptor); + if (value == null) { + if (descriptor.isRepeated()) { + return (T) Collections.emptyList(); + } else if (descriptor.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { + return (T) extension.getMessageDefaultInstance(); + } else { + return (T) extension.fromReflectionType(descriptor.getDefaultValue()); + } + } else { + return (T) extension.fromReflectionType(value); + } + } + + /** Get one element of a repeated extension. */ + @Override + @SuppressWarnings("unchecked") + public final T getExtension( + final ExtensionLite> extensionLite, final int index) { + Extension> extension = checkNotLite(extensionLite); + + verifyExtensionContainingType(extension); + FieldDescriptor descriptor = extension.getDescriptor(); + return (T) + extension.singularFromReflectionType(extensions.getRepeatedField(descriptor, index)); + } + + /** + * Check if a singular extension is present. + *

TODO: handled by ExtensionLite version + */ + @Override + public final boolean hasExtension(final Extension extension) { + return hasExtension((ExtensionLite) extension); + } + /** + * Check if a singular extension is present. + *

TODO: handled by ExtensionLite version + */ + @Override + public final boolean hasExtension( + final GeneratedExtension extension) { + return hasExtension((ExtensionLite) extension); + } + /** + * Get the number of elements in a repeated extension. + *

TODO: handled by ExtensionLite version + */ + @Override + public final int getExtensionCount( + final Extension> extension) { + return getExtensionCount((ExtensionLite>) extension); + } + /** + * Get the number of elements in a repeated extension. + *

TODO: handled by ExtensionLite version + */ + @Override + public final int getExtensionCount( + final GeneratedExtension> extension) { + return getExtensionCount((ExtensionLite>) extension); + } + /** + * Get the value of an extension. + *

TODO: handled by ExtensionLite version + */ + @Override + public final T getExtension(final Extension extension) { + return getExtension((ExtensionLite) extension); + } + /** + * Get the value of an extension. + *

TODO: handled by ExtensionLite version + */ + @Override + public final T getExtension( + final GeneratedExtension extension) { + return getExtension((ExtensionLite) extension); + } + /** + * Get one element of a repeated extension. + *

TODO: handled by ExtensionLite version + */ + @Override + public final T getExtension( + final Extension> extension, final int index) { + return getExtension((ExtensionLite>) extension, index); + } + /** + * Get one element of a repeated extension. + *

TODO: handled by ExtensionLite version + */ + @Override + public final T getExtension( + final GeneratedExtension> extension, final int index) { + return getExtension((ExtensionLite>) extension, index); + } + + /** Called by subclasses to check if all extensions are initialized. */ + protected boolean extensionsAreInitialized() { + return extensions.isInitialized(); + } + + // TODO: compute this in the builder at {@code build()} time. + @Override + public boolean isInitialized() { + return super.isInitialized() && extensionsAreInitialized(); + } + + // TODO: remove mutating method from immutable type + @Override + protected boolean parseUnknownField( + CodedInputStream input, + UnknownFieldSet.Builder unknownFields, + ExtensionRegistryLite extensionRegistry, + int tag) + throws IOException { + return MessageReflection.mergeFieldFrom( + input, + input.shouldDiscardUnknownFields() ? null : unknownFields, + extensionRegistry, + getDescriptorForType(), + new MessageReflection.ExtensionAdapter(extensions), + tag); + } + + /** + * Delegates to parseUnknownField. This method is obsolete, but we must retain it for + * compatibility with older generated code. + * + *

TODO: remove mutating method from immutable type + */ + @Override + protected boolean parseUnknownFieldProto3( + CodedInputStream input, + UnknownFieldSet.Builder unknownFields, + ExtensionRegistryLite extensionRegistry, + int tag) + throws IOException { + return parseUnknownField(input, unknownFields, extensionRegistry, tag); + } + + /** + * Used by parsing constructors in generated classes. + * + *

TODO: remove unused method (extensions should be immutable after build) + */ + @Override + protected void makeExtensionsImmutable() { + extensions.makeImmutable(); + } + + /** + * Used by subclasses to serialize extensions. Extension ranges may be interleaved with field + * numbers, but we must write them in canonical (sorted by field number) order. ExtensionWriter + * helps us write individual ranges of extensions at once. + */ + protected class ExtensionWriter { + // Imagine how much simpler this code would be if Java iterators had + // a way to get the next element without advancing the iterator. + + private final Iterator> iter = extensions.iterator(); + private Map.Entry next; + private final boolean messageSetWireFormat; + + private ExtensionWriter(final boolean messageSetWireFormat) { + if (iter.hasNext()) { + next = iter.next(); + } + this.messageSetWireFormat = messageSetWireFormat; + } + + public void writeUntil(final int end, final CodedOutputStream output) throws IOException { + while (next != null && next.getKey().getNumber() < end) { + FieldDescriptor descriptor = next.getKey(); + if (messageSetWireFormat + && descriptor.getLiteJavaType() == WireFormat.JavaType.MESSAGE + && !descriptor.isRepeated()) { + if (next instanceof LazyField.LazyEntry) { + output.writeRawMessageSetExtension( + descriptor.getNumber(), + ((LazyField.LazyEntry) next).getField().toByteString()); + } else { + output.writeMessageSetExtension(descriptor.getNumber(), (Message) next.getValue()); + } + } else { + // TODO: Taken care of following code, it may cause + // problem when we use LazyField for normal fields/extensions. + // Due to the optional field can be duplicated at the end of + // serialized bytes, which will make the serialized size change + // after lazy field parsed. So when we use LazyField globally, + // we need to change the following write method to write cached + // bytes directly rather than write the parsed message. + FieldSet.writeField(descriptor, next.getValue(), output); + } + if (iter.hasNext()) { + next = iter.next(); + } else { + next = null; + } + } + } + } + + protected ExtensionWriter newExtensionWriter() { + return new ExtensionWriter(false); + } + + protected ExtensionWriter newMessageSetExtensionWriter() { + return new ExtensionWriter(true); + } + + /** Called by subclasses to compute the size of extensions. */ + protected int extensionsSerializedSize() { + return extensions.getSerializedSize(); + } + + protected int extensionsSerializedSizeAsMessageSet() { + return extensions.getMessageSetSerializedSize(); + } + + // --------------------------------------------------------------- + // Reflection + + protected Map getExtensionFields() { + return extensions.getAllFields(); + } + + @Override + public Map getAllFields() { + final Map result = + super.getAllFieldsMutable(/* getBytesForString= */ false); + result.putAll(getExtensionFields()); + return Collections.unmodifiableMap(result); + } + + @Override + public Map getAllFieldsRaw() { + final Map result = + super.getAllFieldsMutable(/* getBytesForString= */ false); + result.putAll(getExtensionFields()); + return Collections.unmodifiableMap(result); + } + + @Override + public boolean hasField(final FieldDescriptor field) { + if (field.isExtension()) { + verifyContainingType(field); + return extensions.hasField(field); + } else { + return super.hasField(field); + } + } + + @Override + public Object getField(final FieldDescriptor field) { + if (field.isExtension()) { + verifyContainingType(field); + final Object value = extensions.getField(field); + if (value == null) { + if (field.isRepeated()) { + return Collections.emptyList(); + } else if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { + // Lacking an ExtensionRegistry, we have no way to determine the + // extension's real type, so we return a DynamicMessage. + return DynamicMessage.getDefaultInstance(field.getMessageType()); + } else { + return field.getDefaultValue(); + } + } else { + return value; + } + } else { + return super.getField(field); + } + } + + @Override + public int getRepeatedFieldCount(final FieldDescriptor field) { + if (field.isExtension()) { + verifyContainingType(field); + return extensions.getRepeatedFieldCount(field); + } else { + return super.getRepeatedFieldCount(field); + } + } + + @Override + public Object getRepeatedField(final FieldDescriptor field, final int index) { + if (field.isExtension()) { + verifyContainingType(field); + return extensions.getRepeatedField(field, index); + } else { + return super.getRepeatedField(field, index); + } + } + + private void verifyContainingType(final FieldDescriptor field) { + if (field.getContainingType() != getDescriptorForType()) { + throw new IllegalArgumentException("FieldDescriptor does not match message type."); + } + } + } + + /** + * Type used to represent generated extensions. The protocol compiler generates a static singleton + * instance of this class for each extension. + * + *

For example, imagine you have the {@code .proto} file: + * + *

+   * option java_class = "MyProto";
+   *
+   * message Foo {
+   *   extensions 1000 to max;
+   * }
+   *
+   * extend Foo {
+   *   optional int32 bar;
+   * }
+   * 
+ * + *

Then, {@code MyProto.Foo.bar} has type {@code GeneratedExtension}. + * + *

In general, users should ignore the details of this type, and simply use these static + * singletons as parameters to the extension accessors defined in {@link GeneratedMessage.ExtendableMessage} and + * {@link GeneratedMessage.ExtendableBuilder}. + */ + public static class GeneratedExtension + extends Extension { + // TODO: Find ways to avoid using Java reflection within this + // class. Also try to avoid suppressing unchecked warnings. + + // We can't always initialize the descriptor of a GeneratedExtension when + // we first construct it due to initialization order difficulties (namely, + // the descriptor may not have been constructed yet, since it is often + // constructed by the initializer of a separate module). + // + // In the case of nested extensions, we initialize the + // ExtensionDescriptorRetriever with an instance that uses the scoping + // Message's default instance to retrieve the extension's descriptor. + // + // In the case of non-nested extensions, we initialize the + // ExtensionDescriptorRetriever to null and rely on the outer class's static + // initializer to call internalInit() after the descriptor has been parsed. + GeneratedExtension( + ExtensionDescriptorRetriever descriptorRetriever, + Class singularType, + Message messageDefaultInstance, + ExtensionType extensionType) { + if (Message.class.isAssignableFrom(singularType) + && !singularType.isInstance(messageDefaultInstance)) { + throw new IllegalArgumentException( + "Bad messageDefaultInstance for " + singularType.getName()); + } + this.descriptorRetriever = descriptorRetriever; + this.singularType = singularType; + this.messageDefaultInstance = messageDefaultInstance; + + if (ProtocolMessageEnum.class.isAssignableFrom(singularType)) { + this.enumValueOf = getMethodOrDie(singularType, "valueOf", EnumValueDescriptor.class); + this.enumGetValueDescriptor = getMethodOrDie(singularType, "getValueDescriptor"); + } else { + this.enumValueOf = null; + this.enumGetValueDescriptor = null; + } + this.extensionType = extensionType; + } + + /** For use by generated code only. */ + public void internalInit(final FieldDescriptor descriptor) { + if (descriptorRetriever != null) { + throw new IllegalStateException("Already initialized."); + } + descriptorRetriever = + new ExtensionDescriptorRetriever() { + @Override + public FieldDescriptor getDescriptor() { + return descriptor; + } + }; + } + + /** + * Gets the descriptor for an extension. The implementation depends on whether the extension is + * scoped in the top level of a file or scoped in a Message. + */ + static interface ExtensionDescriptorRetriever { + FieldDescriptor getDescriptor(); + } + + private ExtensionDescriptorRetriever descriptorRetriever; + private final Class singularType; + private final Message messageDefaultInstance; + private final Method enumValueOf; + private final Method enumGetValueDescriptor; + private final ExtensionType extensionType; + + @Override + public FieldDescriptor getDescriptor() { + if (descriptorRetriever == null) { + throw new IllegalStateException("getDescriptor() called before internalInit()"); + } + return descriptorRetriever.getDescriptor(); + } + + /** + * If the extension is an embedded message or group, returns the default instance of the + * message. + */ + @Override + public Message getMessageDefaultInstance() { + return messageDefaultInstance; + } + + @Override + protected ExtensionType getExtensionType() { + return extensionType; + } + + /** + * Convert from the type used by the reflection accessors to the type used by native accessors. + * E.g., for enums, the reflection accessors use EnumValueDescriptors but the native accessors + * use the generated enum type. + */ + @Override + @SuppressWarnings("unchecked") + protected Object fromReflectionType(final Object value) { + FieldDescriptor descriptor = getDescriptor(); + if (descriptor.isRepeated()) { + if (descriptor.getJavaType() == FieldDescriptor.JavaType.MESSAGE + || descriptor.getJavaType() == FieldDescriptor.JavaType.ENUM) { + // Must convert the whole list. + final List result = new ArrayList(); + for (final Object element : (List) value) { + result.add(singularFromReflectionType(element)); + } + return result; + } else { + return value; + } + } else { + return singularFromReflectionType(value); + } + } + + /** + * Like {@link #fromReflectionType(Object)}, but if the type is a repeated type, this converts a + * single element. + */ + @Override + protected Object singularFromReflectionType(final Object value) { + FieldDescriptor descriptor = getDescriptor(); + switch (descriptor.getJavaType()) { + case MESSAGE: + if (singularType.isInstance(value)) { + return value; + } else { + return messageDefaultInstance.newBuilderForType().mergeFrom((Message) value).build(); + } + case ENUM: + return invokeOrDie(enumValueOf, null, (EnumValueDescriptor) value); + default: + return value; + } + } + + /** + * Convert from the type used by the native accessors to the type used by reflection accessors. + * E.g., for enums, the reflection accessors use EnumValueDescriptors but the native accessors + * use the generated enum type. + */ + @Override + @SuppressWarnings("unchecked") + protected Object toReflectionType(final Object value) { + FieldDescriptor descriptor = getDescriptor(); + if (descriptor.isRepeated()) { + if (descriptor.getJavaType() == FieldDescriptor.JavaType.ENUM) { + // Must convert the whole list. + final List result = new ArrayList(); + for (final Object element : (List) value) { + result.add(singularToReflectionType(element)); + } + return result; + } else { + return value; + } + } else { + return singularToReflectionType(value); + } + } + + /** + * Like {@link #toReflectionType(Object)}, but if the type is a repeated type, this converts a + * single element. + */ + @Override + protected Object singularToReflectionType(final Object value) { + FieldDescriptor descriptor = getDescriptor(); + switch (descriptor.getJavaType()) { + case ENUM: + return invokeOrDie(enumGetValueDescriptor, value); + default: + return value; + } + } + + @Override + public int getNumber() { + return getDescriptor().getNumber(); + } + + @Override + public WireFormat.FieldType getLiteType() { + return getDescriptor().getLiteType(); + } + + @Override + public boolean isRepeated() { + return getDescriptor().isRepeated(); + } + + @Override + @SuppressWarnings("unchecked") + public Type getDefaultValue() { + if (isRepeated()) { + return (Type) Collections.emptyList(); + } + if (getDescriptor().getJavaType() == FieldDescriptor.JavaType.MESSAGE) { + return (Type) messageDefaultInstance; + } + return (Type) singularFromReflectionType(getDescriptor().getDefaultValue()); + } + } + + + /** + * Generated message builders for message types that contain extension ranges subclass this. + * + *

This class implements type-safe accessors for extensions. They implement all the same + * operations that you can do with normal fields -- e.g. "get", "set", and "add" -- but for + * extensions. The extensions are identified using instances of the class {@link + * GeneratedExtension}; the protocol compiler generates a static instance of this class for every + * extension in its input. Through the magic of generics, all is made type-safe. + * + *

For example, imagine you have the {@code .proto} file: + * + *

+   * option java_class = "MyProto";
+   *
+   * message Foo {
+   *   extensions 1000 to max;
+   * }
+   *
+   * extend Foo {
+   *   optional int32 bar;
+   * }
+   * 
+ * + *

Then you might write code like: + * + *

+   * MyProto.Foo foo =
+   *   MyProto.Foo.newBuilder()
+   *     .setExtension(MyProto.bar, 123)
+   *     .build();
+   * 
+ * + *

See also {@link ExtendableMessage}. + */ + @SuppressWarnings("unchecked") + public abstract static class ExtendableBuilder< + MessageT extends ExtendableMessage, + BuilderT extends ExtendableBuilder> + extends Builder implements ExtendableMessageOrBuilder { + + private FieldSet.Builder extensions; + + protected ExtendableBuilder() {} + + protected ExtendableBuilder(BuilderParent parent) { + super(parent); + } + + // For immutable message conversion. + void internalSetExtensionSet(FieldSet extensions) { + this.extensions = FieldSet.Builder.fromFieldSet(extensions); + } + + @Override + public BuilderT clear() { + extensions = null; + return super.clear(); + } + + private void ensureExtensionsIsMutable() { + if (extensions == null) { + extensions = FieldSet.newBuilder(); + } + } + + private void verifyExtensionContainingType(final Extension extension) { + if (extension.getDescriptor().getContainingType() != getDescriptorForType()) { + // This can only happen if someone uses unchecked operations. + throw new IllegalArgumentException( + "Extension is for type \"" + + extension.getDescriptor().getContainingType().getFullName() + + "\" which does not match message type \"" + + getDescriptorForType().getFullName() + + "\"."); + } + } + + /** Check if a singular extension is present. */ + @Override + public final boolean hasExtension(final ExtensionLite extensionLite) { + Extension extension = checkNotLite(extensionLite); + + verifyExtensionContainingType(extension); + return extensions != null && extensions.hasField(extension.getDescriptor()); + } + + /** Get the number of elements in a repeated extension. */ + @Override + public final int getExtensionCount(final ExtensionLite> extensionLite) { + Extension> extension = checkNotLite(extensionLite); + + verifyExtensionContainingType(extension); + final FieldDescriptor descriptor = extension.getDescriptor(); + return extensions == null ? 0 : extensions.getRepeatedFieldCount(descriptor); + } + + /** Get the value of an extension. */ + @Override + public final T getExtension(final ExtensionLite extensionLite) { + Extension extension = checkNotLite(extensionLite); + + verifyExtensionContainingType(extension); + FieldDescriptor descriptor = extension.getDescriptor(); + final Object value = extensions == null ? null : extensions.getField(descriptor); + if (value == null) { + if (descriptor.isRepeated()) { + return (T) Collections.emptyList(); + } else if (descriptor.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { + return (T) extension.getMessageDefaultInstance(); + } else { + return (T) extension.fromReflectionType(descriptor.getDefaultValue()); + } + } else { + return (T) extension.fromReflectionType(value); + } + } + + /** Get one element of a repeated extension. */ + @Override + public final T getExtension( + final ExtensionLite> extensionLite, final int index) { + Extension> extension = checkNotLite(extensionLite); + + verifyExtensionContainingType(extension); + FieldDescriptor descriptor = extension.getDescriptor(); + if (extensions == null) { + throw new IndexOutOfBoundsException(); + } + return (T) + extension.singularFromReflectionType(extensions.getRepeatedField(descriptor, index)); + } + + /** Set the value of an extension. */ + public final BuilderT setExtension( + final ExtensionLite extensionLite, final T value) { + Extension extension = checkNotLite(extensionLite); + + verifyExtensionContainingType(extension); + ensureExtensionsIsMutable(); + final FieldDescriptor descriptor = extension.getDescriptor(); + extensions.setField(descriptor, extension.toReflectionType(value)); + onChanged(); + return (BuilderT) this; + } + + /** Set the value of one element of a repeated extension. */ + public final BuilderT setExtension( + final ExtensionLite> extensionLite, final int index, final T value) { + Extension> extension = checkNotLite(extensionLite); + + verifyExtensionContainingType(extension); + ensureExtensionsIsMutable(); + final FieldDescriptor descriptor = extension.getDescriptor(); + extensions.setRepeatedField(descriptor, index, extension.singularToReflectionType(value)); + onChanged(); + return (BuilderT) this; + } + + /** Append a value to a repeated extension. */ + public final BuilderT addExtension( + final ExtensionLite> extensionLite, final T value) { + Extension> extension = checkNotLite(extensionLite); + + verifyExtensionContainingType(extension); + ensureExtensionsIsMutable(); + final FieldDescriptor descriptor = extension.getDescriptor(); + extensions.addRepeatedField(descriptor, extension.singularToReflectionType(value)); + onChanged(); + return (BuilderT) this; + } + + /** Clear an extension. */ + public final BuilderT clearExtension(final ExtensionLite extensionLite) { + Extension extension = checkNotLite(extensionLite); + + verifyExtensionContainingType(extension); + ensureExtensionsIsMutable(); + extensions.clearField(extension.getDescriptor()); + onChanged(); + return (BuilderT) this; + } + + /** + * Check if a singular extension is present. + *

TODO: handled by ExtensionLite version + */ + @Override + public final boolean hasExtension(final Extension extension) { + return hasExtension((ExtensionLite) extension); + } + /** + * Check if a singular extension is present. + *

TODO: handled by ExtensionLite version + */ + @Override + public final boolean hasExtension( + final FlattenedGeneratedMessageV3.GeneratedExtension extension) { + return hasExtension((ExtensionLite) extension); + } + /** + * Get the number of elements in a repeated extension. + *

TODO: handled by ExtensionLite version + */ + @Override + public final int getExtensionCount( + final Extension> extension) { + return getExtensionCount((ExtensionLite>) extension); + } + /** + * Get the number of elements in a repeated extension. + *

TODO: handled by ExtensionLite version + */ + @Override + public final int getExtensionCount( + final FlattenedGeneratedMessageV3.GeneratedExtension> extension) { + return getExtensionCount((ExtensionLite>) extension); + } + /** + * Get the value of an extension. + *

TODO: handled by ExtensionLite version + */ + @Override + public final T getExtension(final Extension extension) { + return getExtension((ExtensionLite) extension); + } + /** Get the value of an extension. + *

TODO: handled by ExtensionLite version + */ + @Override + public final T getExtension( + final GeneratedExtension extension) { + return getExtension((ExtensionLite) extension); + } + /** + * Get the value of an extension. + *

TODO: handled by ExtensionLite version + */ + @Override + public final T getExtension( + final Extension> extension, final int index) { + return getExtension((ExtensionLite>) extension, index); + } + /** + * Get the value of an extension. + *

TODO: handled by ExtensionLite version + */ + @Override + public final T getExtension( + final GeneratedExtension> extension, final int index) { + return getExtension((ExtensionLite>) extension, index); + } + /** + * Set the value of an extension. + *

TODO: handled by ExtensionLite version + */ + public final BuilderT setExtension( + final Extension extension, final T value) { + return setExtension((ExtensionLite) extension, value); + } + /** + * Set the value of an extension. + *

TODO: handled by ExtensionLite version + */ + public BuilderT setExtension( + final GeneratedExtension extension, final T value) { + return setExtension((ExtensionLite) extension, value); + } + /** + * Set the value of one element of a repeated extension. + *

TODO: handled by ExtensionLite version + */ + public final BuilderT setExtension( + final Extension> extension, + final int index, final T value) { + return setExtension((ExtensionLite>) extension, index, value); + } + /** + * Set the value of one element of a repeated extension. + *

TODO: handled by ExtensionLite version + */ + public BuilderT setExtension( + final GeneratedExtension> extension, + final int index, final T value) { + return setExtension((ExtensionLite>) extension, index, value); + } + /** + * Append a value to a repeated extension. + *

TODO: handled by ExtensionLite version + */ + public final BuilderT addExtension( + final Extension> extension, final T value) { + return addExtension((ExtensionLite>) extension, value); + } + /** + * Append a value to a repeated extension. + *

TODO: handled by ExtensionLite version + */ + public BuilderT addExtension( + final GeneratedExtension> extension, final T value) { + return addExtension((ExtensionLite>) extension, value); + } + /** + * Clear an extension. + *

TODO: handled by ExtensionLite version + */ + public final BuilderT clearExtension( + final Extension extension) { + return clearExtension((ExtensionLite) extension); + } + /** + * Clears an extension. + *

TODO: handled by ExtensionLite version + */ + public BuilderT clearExtension( + final GeneratedExtension extension) { + return clearExtension((ExtensionLite) extension); + } + + /** Called by subclasses to check if all extensions are initialized. */ + protected boolean extensionsAreInitialized() { + return extensions == null || extensions.isInitialized(); + } + + /** + * Called by the build code path to create a copy of the extensions for building the message. + */ + private FieldSet buildExtensions() { + return extensions == null + ? (FieldSet) FieldSet.emptySet() + : extensions.buildPartial(); + } + + @Override + public boolean isInitialized() { + return super.isInitialized() && extensionsAreInitialized(); + } + + // --------------------------------------------------------------- + // Reflection + + @Override + public Map getAllFields() { + final Map result = super.getAllFieldsMutable(); + if (extensions != null) { + result.putAll(extensions.getAllFields()); + } + return Collections.unmodifiableMap(result); + } + + @Override + public Object getField(final FieldDescriptor field) { + if (field.isExtension()) { + verifyContainingType(field); + final Object value = extensions == null ? null : extensions.getField(field); + if (value == null) { + if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { + // Lacking an ExtensionRegistry, we have no way to determine the + // extension's real type, so we return a DynamicMessage. + return DynamicMessage.getDefaultInstance(field.getMessageType()); + } else { + return field.getDefaultValue(); + } + } else { + return value; + } + } else { + return super.getField(field); + } + } + + @Override + public Message.Builder getFieldBuilder(final FieldDescriptor field) { + if (field.isExtension()) { + verifyContainingType(field); + if (field.getJavaType() != FieldDescriptor.JavaType.MESSAGE) { + throw new UnsupportedOperationException( + "getFieldBuilder() called on a non-Message type."); + } + ensureExtensionsIsMutable(); + final Object value = extensions.getFieldAllowBuilders(field); + if (value == null) { + Message.Builder builder = DynamicMessage.newBuilder(field.getMessageType()); + extensions.setField(field, builder); + onChanged(); + return builder; + } else { + if (value instanceof Message.Builder) { + return (Message.Builder) value; + } else if (value instanceof Message) { + Message.Builder builder = ((Message) value).toBuilder(); + extensions.setField(field, builder); + onChanged(); + return builder; + } else { + throw new UnsupportedOperationException( + "getRepeatedFieldBuilder() called on a non-Message type."); + } + } + } else { + return super.getFieldBuilder(field); + } + } + + @Override + public int getRepeatedFieldCount(final FieldDescriptor field) { + if (field.isExtension()) { + verifyContainingType(field); + return extensions == null ? 0 : extensions.getRepeatedFieldCount(field); + } else { + return super.getRepeatedFieldCount(field); + } + } + + @Override + public Object getRepeatedField(final FieldDescriptor field, final int index) { + if (field.isExtension()) { + verifyContainingType(field); + if (extensions == null) { + throw new IndexOutOfBoundsException(); + } + return extensions.getRepeatedField(field, index); + } else { + return super.getRepeatedField(field, index); + } + } + + @Override + public Message.Builder getRepeatedFieldBuilder(final FieldDescriptor field, final int index) { + if (field.isExtension()) { + verifyContainingType(field); + ensureExtensionsIsMutable(); + if (field.getJavaType() != FieldDescriptor.JavaType.MESSAGE) { + throw new UnsupportedOperationException( + "getRepeatedFieldBuilder() called on a non-Message type."); + } + final Object value = extensions.getRepeatedFieldAllowBuilders(field, index); + if (value instanceof Message.Builder) { + return (Message.Builder) value; + } else if (value instanceof Message) { + Message.Builder builder = ((Message) value).toBuilder(); + extensions.setRepeatedField(field, index, builder); + onChanged(); + return builder; + } else { + throw new UnsupportedOperationException( + "getRepeatedFieldBuilder() called on a non-Message type."); + } + } else { + return super.getRepeatedFieldBuilder(field, index); + } + } + + @Override + public boolean hasField(final FieldDescriptor field) { + if (field.isExtension()) { + verifyContainingType(field); + return extensions != null && extensions.hasField(field); + } else { + return super.hasField(field); + } + } + + @Override + public BuilderT setField(final FieldDescriptor field, final Object value) { + if (field.isExtension()) { + verifyContainingType(field); + ensureExtensionsIsMutable(); + extensions.setField(field, value); + onChanged(); + return (BuilderT) this; + } else { + return super.setField(field, value); + } + } + + @Override + public BuilderT clearField(final FieldDescriptor field) { + if (field.isExtension()) { + verifyContainingType(field); + ensureExtensionsIsMutable(); + extensions.clearField(field); + onChanged(); + return (BuilderT) this; + } else { + return super.clearField(field); + } + } + + @Override + public BuilderT setRepeatedField( + final FieldDescriptor field, final int index, final Object value) { + if (field.isExtension()) { + verifyContainingType(field); + ensureExtensionsIsMutable(); + extensions.setRepeatedField(field, index, value); + onChanged(); + return (BuilderT) this; + } else { + return super.setRepeatedField(field, index, value); + } + } + + @Override + public BuilderT addRepeatedField(final FieldDescriptor field, final Object value) { + if (field.isExtension()) { + verifyContainingType(field); + ensureExtensionsIsMutable(); + extensions.addRepeatedField(field, value); + onChanged(); + return (BuilderT) this; + } else { + return super.addRepeatedField(field, value); + } + } + + @Override + public Message.Builder newBuilderForField(final FieldDescriptor field) { + if (field.isExtension()) { + return DynamicMessage.newBuilder(field.getMessageType()); + } else { + return super.newBuilderForField(field); + } + } + + protected final void mergeExtensionFields(final ExtendableMessage other) { + if (other.extensions != null) { + ensureExtensionsIsMutable(); + extensions.mergeFrom(other.extensions); + onChanged(); + } + } + + @Override + protected boolean parseUnknownField( + CodedInputStream input, ExtensionRegistryLite extensionRegistry, int tag) + throws IOException { + ensureExtensionsIsMutable(); + return MessageReflection.mergeFieldFrom( + input, + input.shouldDiscardUnknownFields() ? null : getUnknownFieldSetBuilder(), + extensionRegistry, + getDescriptorForType(), + new MessageReflection.ExtensionBuilderAdapter(extensions), + tag); + } + + private void verifyContainingType(final FieldDescriptor field) { + if (field.getContainingType() != getDescriptorForType()) { + throw new IllegalArgumentException("FieldDescriptor does not match message type."); + } + } + } + + // ----------------------------------------------------------------- + + /** + * Gets the descriptor for an extension. The implementation depends on whether the extension is + * scoped in the top level of a file or scoped in a Message. + */ + interface ExtensionDescriptorRetriever { + FieldDescriptor getDescriptor(); + } + + // ================================================================= + + /** Calls Class.getMethod and throws a RuntimeException if it fails. */ + private static Method getMethodOrDie( + final Class clazz, final String name, final Class... params) { + try { + return clazz.getMethod(name, params); + } catch (NoSuchMethodException e) { + throw new IllegalStateException( + "Generated message class \"" + clazz.getName() + "\" missing method \"" + name + "\".", + e); + } + } + + /** Calls invoke and throws a RuntimeException if it fails. */ + @CanIgnoreReturnValue + private static Object invokeOrDie( + final Method method, final Object object, final Object... params) { + try { + return method.invoke(object, params); + } catch (IllegalAccessException e) { + throw new IllegalStateException( + "Couldn't use Java reflection to implement protocol message reflection.", e); + } catch (InvocationTargetException e) { + final Throwable cause = e.getCause(); + if (cause instanceof RuntimeException) { + throw (RuntimeException) cause; + } else if (cause instanceof Error) { + throw (Error) cause; + } else { + throw new IllegalStateException( + "Unexpected exception thrown by generated accessor method.", cause); + } + } + } + + /** + * Gets the map field with the given field number. This method should be overridden in the + * generated message class if the message contains map fields. + * + *

Unlike other field types, reflection support for map fields can't be implemented based on + * generated public API because we need to access a map field as a list in reflection API but the + * generated API only allows us to access it as a map. This method returns the underlying map + * field directly and thus enables us to access the map field as a list. + */ + @SuppressWarnings("unused") + protected MapFieldReflectionAccessor internalGetMapFieldReflection(int fieldNumber) { + return internalGetMapField(fieldNumber); + } + + /** TODO: Remove, exists for compatibility with generated code. */ + @Deprecated + @SuppressWarnings({"rawtypes", "unused"}) + protected MapField internalGetMapField(int fieldNumber) { + // Note that we can't use descriptor names here because this method will + // be called when descriptor is being initialized. + throw new IllegalArgumentException("No map fields found in " + getClass().getName()); + } + + /** + * Users should ignore this class. This class provides the implementation with access to the + * fields of a message object using Java reflection. + */ + public static final class FieldAccessorTable { + + /** + * Construct a FieldAccessorTable for a particular message class. Only one FieldAccessorTable + * should ever be constructed per class. + * + * @param descriptor The type's descriptor. + * @param camelCaseNames The camelcase names of all fields in the message. These are used to + * derive the accessor method names. + * @param messageClass The message type. + * @param builderClass The builder type. + */ + public FieldAccessorTable( + final Descriptor descriptor, + final String[] camelCaseNames, + final Class messageClass, + final Class> builderClass) { + this(descriptor, camelCaseNames); + ensureFieldAccessorsInitialized(messageClass, builderClass); + } + + /** + * Construct a FieldAccessorTable for a particular message class without initializing + * FieldAccessors. + */ + public FieldAccessorTable(final Descriptor descriptor, final String[] camelCaseNames) { + this.descriptor = descriptor; + this.camelCaseNames = camelCaseNames; + fields = new FieldAccessor[descriptor.getFields().size()]; + oneofs = new OneofAccessor[descriptor.getOneofs().size()]; + initialized = false; + } + + /** + * Ensures the field accessors are initialized. This method is thread-safe. + * + * @param messageClass The message type. + * @param builderClass The builder type. + * @return this + */ + public FieldAccessorTable ensureFieldAccessorsInitialized( + Class messageClass, Class> builderClass) { + if (initialized) { + return this; + } + synchronized (this) { + if (initialized) { + return this; + } + int fieldsSize = fields.length; + for (int i = 0; i < fieldsSize; i++) { + FieldDescriptor field = descriptor.getFields().get(i); + String containingOneofCamelCaseName = null; + if (field.getContainingOneof() != null) { + int index = fieldsSize + field.getContainingOneof().getIndex(); + if (index < camelCaseNames.length) { + containingOneofCamelCaseName = camelCaseNames[index]; + } + } + if (field.isRepeated()) { + if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { + if (field.isMapField()) { + fields[i] = new MapFieldAccessor(field, messageClass); + } else { + fields[i] = + new RepeatedMessageFieldAccessor( + field, camelCaseNames[i], messageClass, builderClass); + } + } else if (field.getJavaType() == FieldDescriptor.JavaType.ENUM) { + fields[i] = + new RepeatedEnumFieldAccessor( + field, camelCaseNames[i], messageClass, builderClass); + } else { + fields[i] = + new RepeatedFieldAccessor(field, camelCaseNames[i], messageClass, builderClass); + } + } else { + if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { + fields[i] = + new SingularMessageFieldAccessor( + field, + camelCaseNames[i], + messageClass, + builderClass, + containingOneofCamelCaseName); + } else if (field.getJavaType() == FieldDescriptor.JavaType.ENUM) { + fields[i] = + new SingularEnumFieldAccessor( + field, + camelCaseNames[i], + messageClass, + builderClass, + containingOneofCamelCaseName); + } else if (field.getJavaType() == FieldDescriptor.JavaType.STRING) { + fields[i] = + new SingularStringFieldAccessor( + field, + camelCaseNames[i], + messageClass, + builderClass, + containingOneofCamelCaseName); + } else { + fields[i] = + new SingularFieldAccessor( + field, + camelCaseNames[i], + messageClass, + builderClass, + containingOneofCamelCaseName); + } + } + } + + for (int i = 0; i < descriptor.getOneofs().size(); i++) { + if (i < descriptor.getRealOneofs().size()) { + oneofs[i] = + new RealOneofAccessor( + descriptor, i, camelCaseNames[i + fieldsSize], messageClass, builderClass); + } else { + oneofs[i] = new SyntheticOneofAccessor(descriptor, i); + } + } + + initialized = true; + camelCaseNames = null; + return this; + } + } + + private final Descriptor descriptor; + private final FieldAccessor[] fields; + private String[] camelCaseNames; + private final OneofAccessor[] oneofs; + private volatile boolean initialized; + + /** Get the FieldAccessor for a particular field. */ + private FieldAccessor getField(final FieldDescriptor field) { + if (field.getContainingType() != descriptor) { + throw new IllegalArgumentException("FieldDescriptor does not match message type."); + } else if (field.isExtension()) { + // If this type had extensions, it would subclass ExtendableMessage, + // which overrides the reflection interface to handle extensions. + throw new IllegalArgumentException("This type does not have extensions."); + } + return fields[field.getIndex()]; + } + + /** Get the OneofAccessor for a particular oneof. */ + private OneofAccessor getOneof(final OneofDescriptor oneof) { + if (oneof.getContainingType() != descriptor) { + throw new IllegalArgumentException("OneofDescriptor does not match message type."); + } + return oneofs[oneof.getIndex()]; + } + + /** + * Abstract interface that provides access to a single field. This is implemented differently + * depending on the field type and cardinality. + */ + private interface FieldAccessor { + Object get(FlattenedGeneratedMessageV3 message); + + Object get(FlattenedGeneratedMessageV3.Builder builder); + + Object getRaw(FlattenedGeneratedMessageV3 message); + + void set(Builder builder, Object value); + + Object getRepeated(FlattenedGeneratedMessageV3 message, int index); + + Object getRepeated(FlattenedGeneratedMessageV3.Builder builder, int index); + + void setRepeated(Builder builder, int index, Object value); + + void addRepeated(Builder builder, Object value); + + boolean has(FlattenedGeneratedMessageV3 message); + + boolean has(FlattenedGeneratedMessageV3.Builder builder); + + int getRepeatedCount(FlattenedGeneratedMessageV3 message); + + int getRepeatedCount(FlattenedGeneratedMessageV3.Builder builder); + + void clear(Builder builder); + + Message.Builder newBuilder(); + + Message.Builder getBuilder(FlattenedGeneratedMessageV3.Builder builder); + + Message.Builder getRepeatedBuilder(FlattenedGeneratedMessageV3.Builder builder, int index); + } + + /** OneofAccessor provides access to a single oneof. */ + private static interface OneofAccessor { + public boolean has(final FlattenedGeneratedMessageV3 message); + + public boolean has(FlattenedGeneratedMessageV3.Builder builder); + + public FieldDescriptor get(final FlattenedGeneratedMessageV3 message); + + public FieldDescriptor get(FlattenedGeneratedMessageV3.Builder builder); + + public void clear(final Builder builder); + } + + /** RealOneofAccessor provides access to a single real oneof. */ + private static class RealOneofAccessor implements OneofAccessor { + RealOneofAccessor( + final Descriptor descriptor, + final int oneofIndex, + final String camelCaseName, + final Class messageClass, + final Class> builderClass) { + this.descriptor = descriptor; + caseMethod = getMethodOrDie(messageClass, "get" + camelCaseName + "Case"); + caseMethodBuilder = getMethodOrDie(builderClass, "get" + camelCaseName + "Case"); + clearMethod = getMethodOrDie(builderClass, "clear" + camelCaseName); + } + + private final Descriptor descriptor; + private final Method caseMethod; + private final Method caseMethodBuilder; + private final Method clearMethod; + + @Override + public boolean has(final FlattenedGeneratedMessageV3 message) { + return ((Internal.EnumLite) invokeOrDie(caseMethod, message)).getNumber() != 0; + } + + @Override + public boolean has(FlattenedGeneratedMessageV3.Builder builder) { + return ((Internal.EnumLite) invokeOrDie(caseMethodBuilder, builder)).getNumber() != 0; + } + + @Override + public FieldDescriptor get(final FlattenedGeneratedMessageV3 message) { + int fieldNumber = ((Internal.EnumLite) invokeOrDie(caseMethod, message)).getNumber(); + if (fieldNumber > 0) { + return descriptor.findFieldByNumber(fieldNumber); + } + return null; + } + + @Override + public FieldDescriptor get(FlattenedGeneratedMessageV3.Builder builder) { + int fieldNumber = ((Internal.EnumLite) invokeOrDie(caseMethodBuilder, builder)).getNumber(); + if (fieldNumber > 0) { + return descriptor.findFieldByNumber(fieldNumber); + } + return null; + } + + @Override + public void clear(final Builder builder) { + // TODO: remove the unused variable + Object unused = invokeOrDie(clearMethod, builder); + } + } + + /** SyntheticOneofAccessor provides access to a single synthetic oneof. */ + private static class SyntheticOneofAccessor implements OneofAccessor { + SyntheticOneofAccessor(final Descriptor descriptor, final int oneofIndex) { + OneofDescriptor oneofDescriptor = descriptor.getOneofs().get(oneofIndex); + fieldDescriptor = oneofDescriptor.getFields().get(0); + } + + private final FieldDescriptor fieldDescriptor; + + @Override + public boolean has(final FlattenedGeneratedMessageV3 message) { + return message.hasField(fieldDescriptor); + } + + @Override + public boolean has(FlattenedGeneratedMessageV3.Builder builder) { + return builder.hasField(fieldDescriptor); + } + + @Override + public FieldDescriptor get(final FlattenedGeneratedMessageV3 message) { + return message.hasField(fieldDescriptor) ? fieldDescriptor : null; + } + + public FieldDescriptor get(FlattenedGeneratedMessageV3.Builder builder) { + return builder.hasField(fieldDescriptor) ? fieldDescriptor : null; + } + + @Override + public void clear(final Builder builder) { + builder.clearField(fieldDescriptor); + } + } + + // --------------------------------------------------------------- + + @SuppressWarnings("SameNameButDifferent") + private static class SingularFieldAccessor implements FieldAccessor { + private interface MethodInvoker { + Object get(final FlattenedGeneratedMessageV3 message); + + Object get(FlattenedGeneratedMessageV3.Builder builder); + + int getOneofFieldNumber(final FlattenedGeneratedMessageV3 message); + + int getOneofFieldNumber(final FlattenedGeneratedMessageV3.Builder builder); + + void set(final FlattenedGeneratedMessageV3.Builder builder, final Object value); + + boolean has(final FlattenedGeneratedMessageV3 message); + + boolean has(FlattenedGeneratedMessageV3.Builder builder); + + void clear(final FlattenedGeneratedMessageV3.Builder builder); + } + + private static final class ReflectionInvoker implements MethodInvoker { + private final Method getMethod; + private final Method getMethodBuilder; + private final Method setMethod; + private final Method hasMethod; + private final Method hasMethodBuilder; + private final Method clearMethod; + private final Method caseMethod; + private final Method caseMethodBuilder; + + ReflectionInvoker( + final FieldDescriptor descriptor, + final String camelCaseName, + final Class messageClass, + final Class> builderClass, + final String containingOneofCamelCaseName, + boolean isOneofField, + boolean hasHasMethod) { + getMethod = getMethodOrDie(messageClass, "get" + camelCaseName); + getMethodBuilder = getMethodOrDie(builderClass, "get" + camelCaseName); + Class type = getMethod.getReturnType(); + setMethod = getMethodOrDie(builderClass, "set" + camelCaseName, type); + hasMethod = hasHasMethod ? getMethodOrDie(messageClass, "has" + camelCaseName) : null; + hasMethodBuilder = + hasHasMethod ? getMethodOrDie(builderClass, "has" + camelCaseName) : null; + clearMethod = getMethodOrDie(builderClass, "clear" + camelCaseName); + caseMethod = + isOneofField + ? getMethodOrDie(messageClass, "get" + containingOneofCamelCaseName + "Case") + : null; + caseMethodBuilder = + isOneofField + ? getMethodOrDie(builderClass, "get" + containingOneofCamelCaseName + "Case") + : null; + } + + @Override + public Object get(final FlattenedGeneratedMessageV3 message) { + return invokeOrDie(getMethod, message); + } + + @Override + public Object get(FlattenedGeneratedMessageV3.Builder builder) { + return invokeOrDie(getMethodBuilder, builder); + } + + @Override + public int getOneofFieldNumber(final FlattenedGeneratedMessageV3 message) { + return ((Internal.EnumLite) invokeOrDie(caseMethod, message)).getNumber(); + } + + @Override + public int getOneofFieldNumber(final FlattenedGeneratedMessageV3.Builder builder) { + return ((Internal.EnumLite) invokeOrDie(caseMethodBuilder, builder)).getNumber(); + } + + @Override + public void set(final FlattenedGeneratedMessageV3.Builder builder, final Object value) { + // TODO: remove the unused variable + Object unused = invokeOrDie(setMethod, builder, value); + } + + @Override + public boolean has(final FlattenedGeneratedMessageV3 message) { + return (Boolean) invokeOrDie(hasMethod, message); + } + + @Override + public boolean has(FlattenedGeneratedMessageV3.Builder builder) { + return (Boolean) invokeOrDie(hasMethodBuilder, builder); + } + + @Override + public void clear(final FlattenedGeneratedMessageV3.Builder builder) { + // TODO: remove the unused variable + Object unused = invokeOrDie(clearMethod, builder); + } + } + + SingularFieldAccessor( + final FieldDescriptor descriptor, + final String camelCaseName, + final Class messageClass, + final Class> builderClass, + final String containingOneofCamelCaseName) { + isOneofField = + descriptor.getRealContainingOneof() != null; + hasHasMethod = + descriptor.getFile().getSyntax() == FileDescriptor.Syntax.EDITIONS && descriptor.hasPresence() + || descriptor.getFile().getSyntax() == FileDescriptor.Syntax.PROTO2 + || descriptor.hasOptionalKeyword() + || (!isOneofField && descriptor.getJavaType() == FieldDescriptor.JavaType.MESSAGE); + ReflectionInvoker reflectionInvoker = + new ReflectionInvoker( + descriptor, + camelCaseName, + messageClass, + builderClass, + containingOneofCamelCaseName, + isOneofField, + hasHasMethod); + field = descriptor; + type = reflectionInvoker.getMethod.getReturnType(); + invoker = getMethodInvoker(reflectionInvoker); + } + + static MethodInvoker getMethodInvoker(ReflectionInvoker accessor) { + return accessor; + } + + // Note: We use Java reflection to call public methods rather than + // access private fields directly as this avoids runtime security + // checks. + protected final Class type; + protected final FieldDescriptor field; + protected final boolean isOneofField; + protected final boolean hasHasMethod; + protected final MethodInvoker invoker; + + @Override + public Object get(final FlattenedGeneratedMessageV3 message) { + return invoker.get(message); + } + + @Override + public Object get(FlattenedGeneratedMessageV3.Builder builder) { + return invoker.get(builder); + } + + @Override + public Object getRaw(final FlattenedGeneratedMessageV3 message) { + return get(message); + } + + @Override + public void set(final Builder builder, final Object value) { + invoker.set(builder, value); + } + + @Override + public Object getRepeated(final FlattenedGeneratedMessageV3 message, final int index) { + throw new UnsupportedOperationException("getRepeatedField() called on a singular field."); + } + + @Override + public Object getRepeated(FlattenedGeneratedMessageV3.Builder builder, int index) { + throw new UnsupportedOperationException("getRepeatedField() called on a singular field."); + } + + @Override + public void setRepeated(final Builder builder, final int index, final Object value) { + throw new UnsupportedOperationException("setRepeatedField() called on a singular field."); + } + + @Override + public void addRepeated(final Builder builder, final Object value) { + throw new UnsupportedOperationException("addRepeatedField() called on a singular field."); + } + + @Override + public boolean has(final FlattenedGeneratedMessageV3 message) { + if (!hasHasMethod) { + if (isOneofField) { + return invoker.getOneofFieldNumber(message) == field.getNumber(); + } + return !get(message).equals(field.getDefaultValue()); + } + return invoker.has(message); + } + + @Override + public boolean has(FlattenedGeneratedMessageV3.Builder builder) { + if (!hasHasMethod) { + if (isOneofField) { + return invoker.getOneofFieldNumber(builder) == field.getNumber(); + } + return !get(builder).equals(field.getDefaultValue()); + } + return invoker.has(builder); + } + + @Override + public int getRepeatedCount(final FlattenedGeneratedMessageV3 message) { + throw new UnsupportedOperationException( + "getRepeatedFieldSize() called on a singular field."); + } + + @Override + public int getRepeatedCount(FlattenedGeneratedMessageV3.Builder builder) { + throw new UnsupportedOperationException( + "getRepeatedFieldSize() called on a singular field."); + } + + @Override + public void clear(final Builder builder) { + invoker.clear(builder); + } + + @Override + public Message.Builder newBuilder() { + throw new UnsupportedOperationException( + "newBuilderForField() called on a non-Message type."); + } + + @Override + public Message.Builder getBuilder(FlattenedGeneratedMessageV3.Builder builder) { + throw new UnsupportedOperationException("getFieldBuilder() called on a non-Message type."); + } + + @Override + public Message.Builder getRepeatedBuilder(FlattenedGeneratedMessageV3.Builder builder, int index) { + throw new UnsupportedOperationException( + "getRepeatedFieldBuilder() called on a non-Message type."); + } + } + + @SuppressWarnings("SameNameButDifferent") + private static class RepeatedFieldAccessor implements FieldAccessor { + interface MethodInvoker { + Object get(final FlattenedGeneratedMessageV3 message); + + Object get(FlattenedGeneratedMessageV3.Builder builder); + + Object getRepeated(final FlattenedGeneratedMessageV3 message, final int index); + + Object getRepeated(FlattenedGeneratedMessageV3.Builder builder, int index); + + void setRepeated( + final FlattenedGeneratedMessageV3.Builder builder, final int index, final Object value); + + void addRepeated(final FlattenedGeneratedMessageV3.Builder builder, final Object value); + + int getRepeatedCount(final FlattenedGeneratedMessageV3 message); + + int getRepeatedCount(FlattenedGeneratedMessageV3.Builder builder); + + void clear(final FlattenedGeneratedMessageV3.Builder builder); + } + + private static final class ReflectionInvoker implements MethodInvoker { + private final Method getMethod; + private final Method getMethodBuilder; + private final Method getRepeatedMethod; + private final Method getRepeatedMethodBuilder; + private final Method setRepeatedMethod; + private final Method addRepeatedMethod; + private final Method getCountMethod; + private final Method getCountMethodBuilder; + private final Method clearMethod; + + ReflectionInvoker( + final FieldDescriptor descriptor, + final String camelCaseName, + final Class messageClass, + final Class> builderClass) { + getMethod = getMethodOrDie(messageClass, "get" + camelCaseName + "List"); + getMethodBuilder = getMethodOrDie(builderClass, "get" + camelCaseName + "List"); + getRepeatedMethod = getMethodOrDie(messageClass, "get" + camelCaseName, Integer.TYPE); + getRepeatedMethodBuilder = + getMethodOrDie(builderClass, "get" + camelCaseName, Integer.TYPE); + Class type = getRepeatedMethod.getReturnType(); + setRepeatedMethod = + getMethodOrDie(builderClass, "set" + camelCaseName, Integer.TYPE, type); + addRepeatedMethod = getMethodOrDie(builderClass, "add" + camelCaseName, type); + getCountMethod = getMethodOrDie(messageClass, "get" + camelCaseName + "Count"); + getCountMethodBuilder = getMethodOrDie(builderClass, "get" + camelCaseName + "Count"); + clearMethod = getMethodOrDie(builderClass, "clear" + camelCaseName); + } + + @Override + public Object get(final FlattenedGeneratedMessageV3 message) { + return invokeOrDie(getMethod, message); + } + + @Override + public Object get(FlattenedGeneratedMessageV3.Builder builder) { + return invokeOrDie(getMethodBuilder, builder); + } + + @Override + public Object getRepeated(final FlattenedGeneratedMessageV3 message, final int index) { + return invokeOrDie(getRepeatedMethod, message, index); + } + + @Override + public Object getRepeated(FlattenedGeneratedMessageV3.Builder builder, int index) { + return invokeOrDie(getRepeatedMethodBuilder, builder, index); + } + + @Override + public void setRepeated( + final FlattenedGeneratedMessageV3.Builder builder, final int index, final Object value) { + // TODO: remove the unused variable + Object unused = invokeOrDie(setRepeatedMethod, builder, index, value); + } + + @Override + public void addRepeated(final FlattenedGeneratedMessageV3.Builder builder, final Object value) { + // TODO: remove the unused variable + Object unused = invokeOrDie(addRepeatedMethod, builder, value); + } + + @Override + public int getRepeatedCount(final FlattenedGeneratedMessageV3 message) { + return (Integer) invokeOrDie(getCountMethod, message); + } + + @Override + public int getRepeatedCount(FlattenedGeneratedMessageV3.Builder builder) { + return (Integer) invokeOrDie(getCountMethodBuilder, builder); + } + + @Override + public void clear(final FlattenedGeneratedMessageV3.Builder builder) { + // TODO: remove the unused variable + Object unused = invokeOrDie(clearMethod, builder); + } + } + + protected final Class type; + protected final MethodInvoker invoker; + + RepeatedFieldAccessor( + final FieldDescriptor descriptor, + final String camelCaseName, + final Class messageClass, + final Class> builderClass) { + ReflectionInvoker reflectionInvoker = + new ReflectionInvoker(descriptor, camelCaseName, messageClass, builderClass); + type = reflectionInvoker.getRepeatedMethod.getReturnType(); + invoker = getMethodInvoker(reflectionInvoker); + } + + static MethodInvoker getMethodInvoker(ReflectionInvoker accessor) { + return accessor; + } + + @Override + public Object get(final FlattenedGeneratedMessageV3 message) { + return invoker.get(message); + } + + @Override + public Object get(FlattenedGeneratedMessageV3.Builder builder) { + return invoker.get(builder); + } + + @Override + public Object getRaw(final FlattenedGeneratedMessageV3 message) { + return get(message); + } + + @Override + public void set(final Builder builder, final Object value) { + // Add all the elements individually. This serves two purposes: + // 1) Verifies that each element has the correct type. + // 2) Insures that the caller cannot modify the list later on and + // have the modifications be reflected in the message. + clear(builder); + for (final Object element : (List) value) { + addRepeated(builder, element); + } + } + + @Override + public Object getRepeated(final FlattenedGeneratedMessageV3 message, final int index) { + return invoker.getRepeated(message, index); + } + + @Override + public Object getRepeated(FlattenedGeneratedMessageV3.Builder builder, int index) { + return invoker.getRepeated(builder, index); + } + + @Override + public void setRepeated(final Builder builder, final int index, final Object value) { + invoker.setRepeated(builder, index, value); + } + + @Override + public void addRepeated(final Builder builder, final Object value) { + invoker.addRepeated(builder, value); + } + + @Override + public boolean has(final FlattenedGeneratedMessageV3 message) { + throw new UnsupportedOperationException("hasField() called on a repeated field."); + } + + @Override + public boolean has(FlattenedGeneratedMessageV3.Builder builder) { + throw new UnsupportedOperationException("hasField() called on a repeated field."); + } + + @Override + public int getRepeatedCount(final FlattenedGeneratedMessageV3 message) { + return invoker.getRepeatedCount(message); + } + + @Override + public int getRepeatedCount(FlattenedGeneratedMessageV3.Builder builder) { + return invoker.getRepeatedCount(builder); + } + + @Override + public void clear(final Builder builder) { + invoker.clear(builder); + } + + @Override + public Message.Builder newBuilder() { + throw new UnsupportedOperationException( + "newBuilderForField() called on a non-Message type."); + } + + @Override + public Message.Builder getBuilder(FlattenedGeneratedMessageV3.Builder builder) { + throw new UnsupportedOperationException("getFieldBuilder() called on a non-Message type."); + } + + @Override + public Message.Builder getRepeatedBuilder(FlattenedGeneratedMessageV3.Builder builder, int index) { + throw new UnsupportedOperationException( + "getRepeatedFieldBuilder() called on a non-Message type."); + } + } + + private static class MapFieldAccessor implements FieldAccessor { + MapFieldAccessor( + final FieldDescriptor descriptor, final Class messageClass) { + field = descriptor; + Method getDefaultInstanceMethod = getMethodOrDie(messageClass, "getDefaultInstance"); + MapFieldReflectionAccessor defaultMapField = + getMapField((FlattenedGeneratedMessageV3) invokeOrDie(getDefaultInstanceMethod, null)); + mapEntryMessageDefaultInstance = defaultMapField.getMapEntryMessageDefaultInstance(); + } + + private final FieldDescriptor field; + private final Message mapEntryMessageDefaultInstance; + + private MapFieldReflectionAccessor getMapField(FlattenedGeneratedMessageV3 message) { + return message.internalGetMapFieldReflection(field.getNumber()); + } + + private MapFieldReflectionAccessor getMapField(FlattenedGeneratedMessageV3.Builder builder) { + return builder.internalGetMapFieldReflection(field.getNumber()); + } + + private MapFieldReflectionAccessor getMutableMapField(FlattenedGeneratedMessageV3.Builder builder) { + return builder.internalGetMutableMapFieldReflection(field.getNumber()); + } + + private Message coerceType(Message value) { + if (value == null) { + return null; + } + if (mapEntryMessageDefaultInstance.getClass().isInstance(value)) { + return value; + } + // The value is not the exact right message type. However, if it + // is an alternative implementation of the same type -- e.g. a + // DynamicMessage -- we should accept it. In this case we can make + // a copy of the message. + return mapEntryMessageDefaultInstance.toBuilder().mergeFrom(value).build(); + } + + @Override + public Object get(FlattenedGeneratedMessageV3 message) { + List result = new ArrayList<>(); + for (int i = 0; i < getRepeatedCount(message); i++) { + result.add(getRepeated(message, i)); + } + return Collections.unmodifiableList(result); + } + + @Override + public Object get(Builder builder) { + List result = new ArrayList<>(); + for (int i = 0; i < getRepeatedCount(builder); i++) { + result.add(getRepeated(builder, i)); + } + return Collections.unmodifiableList(result); + } + + @Override + public Object getRaw(FlattenedGeneratedMessageV3 message) { + return get(message); + } + + @Override + public void set(Builder builder, Object value) { + clear(builder); + for (Object entry : (List) value) { + addRepeated(builder, entry); + } + } + + @Override + public Object getRepeated(FlattenedGeneratedMessageV3 message, int index) { + return getMapField(message).getList().get(index); + } + + @Override + public Object getRepeated(Builder builder, int index) { + return getMapField(builder).getList().get(index); + } + + @Override + public void setRepeated(Builder builder, int index, Object value) { + getMutableMapField(builder).getMutableList().set(index, coerceType((Message) value)); + } + + @Override + public void addRepeated(Builder builder, Object value) { + getMutableMapField(builder).getMutableList().add(coerceType((Message) value)); + } + + @Override + public boolean has(FlattenedGeneratedMessageV3 message) { + throw new UnsupportedOperationException("hasField() is not supported for repeated fields."); + } + + @Override + public boolean has(Builder builder) { + throw new UnsupportedOperationException("hasField() is not supported for repeated fields."); + } + + @Override + public int getRepeatedCount(FlattenedGeneratedMessageV3 message) { + return getMapField(message).getList().size(); + } + + @Override + public int getRepeatedCount(Builder builder) { + return getMapField(builder).getList().size(); + } + + @Override + public void clear(Builder builder) { + getMutableMapField(builder).getMutableList().clear(); + } + + @Override + public Message.Builder newBuilder() { + return mapEntryMessageDefaultInstance.newBuilderForType(); + } + + @Override + public Message.Builder getBuilder(Builder builder) { + throw new UnsupportedOperationException("Nested builder not supported for map fields."); + } + + @Override + public Message.Builder getRepeatedBuilder(Builder builder, int index) { + throw new UnsupportedOperationException("Map fields cannot be repeated"); + } + } + + // --------------------------------------------------------------- + + private static final class SingularEnumFieldAccessor extends SingularFieldAccessor { + SingularEnumFieldAccessor( + final FieldDescriptor descriptor, + final String camelCaseName, + final Class messageClass, + final Class> builderClass, + final String containingOneofCamelCaseName) { + super(descriptor, camelCaseName, messageClass, builderClass, containingOneofCamelCaseName); + + enumDescriptor = descriptor.getEnumType(); + + valueOfMethod = getMethodOrDie(type, "valueOf", EnumValueDescriptor.class); + getValueDescriptorMethod = getMethodOrDie(type, "getValueDescriptor"); + + supportUnknownEnumValue = !descriptor.legacyEnumFieldTreatedAsClosed(); + if (supportUnknownEnumValue) { + getValueMethod = getMethodOrDie(messageClass, "get" + camelCaseName + "Value"); + getValueMethodBuilder = getMethodOrDie(builderClass, "get" + camelCaseName + "Value"); + setValueMethod = getMethodOrDie(builderClass, "set" + camelCaseName + "Value", int.class); + } + } + + private final EnumDescriptor enumDescriptor; + + private final Method valueOfMethod; + private final Method getValueDescriptorMethod; + + private final boolean supportUnknownEnumValue; + private Method getValueMethod; + private Method getValueMethodBuilder; + private Method setValueMethod; + + @Override + public Object get(final FlattenedGeneratedMessageV3 message) { + if (supportUnknownEnumValue) { + int value = (Integer) invokeOrDie(getValueMethod, message); + return enumDescriptor.findValueByNumberCreatingIfUnknown(value); + } + return invokeOrDie(getValueDescriptorMethod, super.get(message)); + } + + @Override + public Object get(final FlattenedGeneratedMessageV3.Builder builder) { + if (supportUnknownEnumValue) { + int value = (Integer) invokeOrDie(getValueMethodBuilder, builder); + return enumDescriptor.findValueByNumberCreatingIfUnknown(value); + } + return invokeOrDie(getValueDescriptorMethod, super.get(builder)); + } + + @Override + public void set(final Builder builder, final Object value) { + if (supportUnknownEnumValue) { + // TODO: remove the unused variable + Object unused = + invokeOrDie(setValueMethod, builder, ((EnumValueDescriptor) value).getNumber()); + return; + } + super.set(builder, invokeOrDie(valueOfMethod, null, value)); + } + } + + private static final class RepeatedEnumFieldAccessor extends RepeatedFieldAccessor { + RepeatedEnumFieldAccessor( + final FieldDescriptor descriptor, + final String camelCaseName, + final Class messageClass, + final Class> builderClass) { + super(descriptor, camelCaseName, messageClass, builderClass); + + enumDescriptor = descriptor.getEnumType(); + + valueOfMethod = getMethodOrDie(type, "valueOf", EnumValueDescriptor.class); + getValueDescriptorMethod = getMethodOrDie(type, "getValueDescriptor"); + + supportUnknownEnumValue = !descriptor.legacyEnumFieldTreatedAsClosed(); + if (supportUnknownEnumValue) { + getRepeatedValueMethod = + getMethodOrDie(messageClass, "get" + camelCaseName + "Value", int.class); + getRepeatedValueMethodBuilder = + getMethodOrDie(builderClass, "get" + camelCaseName + "Value", int.class); + setRepeatedValueMethod = + getMethodOrDie(builderClass, "set" + camelCaseName + "Value", int.class, int.class); + addRepeatedValueMethod = + getMethodOrDie(builderClass, "add" + camelCaseName + "Value", int.class); + } + } + + private final EnumDescriptor enumDescriptor; + + private final Method valueOfMethod; + private final Method getValueDescriptorMethod; + + private final boolean supportUnknownEnumValue; + + private Method getRepeatedValueMethod; + private Method getRepeatedValueMethodBuilder; + private Method setRepeatedValueMethod; + private Method addRepeatedValueMethod; + + @Override + public Object get(final FlattenedGeneratedMessageV3 message) { + final List newList = new ArrayList<>(); + final int size = getRepeatedCount(message); + for (int i = 0; i < size; i++) { + newList.add(getRepeated(message, i)); + } + return Collections.unmodifiableList(newList); + } + + @Override + public Object get(final FlattenedGeneratedMessageV3.Builder builder) { + final List newList = new ArrayList<>(); + final int size = getRepeatedCount(builder); + for (int i = 0; i < size; i++) { + newList.add(getRepeated(builder, i)); + } + return Collections.unmodifiableList(newList); + } + + @Override + public Object getRepeated(final FlattenedGeneratedMessageV3 message, final int index) { + if (supportUnknownEnumValue) { + int value = (Integer) invokeOrDie(getRepeatedValueMethod, message, index); + return enumDescriptor.findValueByNumberCreatingIfUnknown(value); + } + return invokeOrDie(getValueDescriptorMethod, super.getRepeated(message, index)); + } + + @Override + public Object getRepeated(final FlattenedGeneratedMessageV3.Builder builder, final int index) { + if (supportUnknownEnumValue) { + int value = (Integer) invokeOrDie(getRepeatedValueMethodBuilder, builder, index); + return enumDescriptor.findValueByNumberCreatingIfUnknown(value); + } + return invokeOrDie(getValueDescriptorMethod, super.getRepeated(builder, index)); + } + + @Override + public void setRepeated(final Builder builder, final int index, final Object value) { + if (supportUnknownEnumValue) { + // TODO: remove the unused variable + Object unused = + invokeOrDie( + setRepeatedValueMethod, + builder, + index, + ((EnumValueDescriptor) value).getNumber()); + return; + } + super.setRepeated(builder, index, invokeOrDie(valueOfMethod, null, value)); + } + + @Override + public void addRepeated(final Builder builder, final Object value) { + if (supportUnknownEnumValue) { + // TODO: remove the unused variable + Object unused = + invokeOrDie( + addRepeatedValueMethod, builder, ((EnumValueDescriptor) value).getNumber()); + return; + } + super.addRepeated(builder, invokeOrDie(valueOfMethod, null, value)); + } + } + + // --------------------------------------------------------------- + + /** + * Field accessor for string fields. + * + *

This class makes getFooBytes() and setFooBytes() available for reflection API so that + * reflection based serialize/parse functions can access the raw bytes of the field to preserve + * non-UTF8 bytes in the string. + * + *

This ensures the serialize/parse round-trip safety, which is important for servers which + * forward messages. + */ + private static final class SingularStringFieldAccessor extends SingularFieldAccessor { + SingularStringFieldAccessor( + final FieldDescriptor descriptor, + final String camelCaseName, + final Class messageClass, + final Class> builderClass, + final String containingOneofCamelCaseName) { + super(descriptor, camelCaseName, messageClass, builderClass, containingOneofCamelCaseName); + getBytesMethod = getMethodOrDie(messageClass, "get" + camelCaseName + "Bytes"); + setBytesMethodBuilder = + getMethodOrDie(builderClass, "set" + camelCaseName + "Bytes", ByteString.class); + } + + private final Method getBytesMethod; + private final Method setBytesMethodBuilder; + + @Override + public Object getRaw(final FlattenedGeneratedMessageV3 message) { + return invokeOrDie(getBytesMethod, message); + } + + @Override + public void set(FlattenedGeneratedMessageV3.Builder builder, Object value) { + if (value instanceof ByteString) { + // TODO: remove the unused variable + Object unused = invokeOrDie(setBytesMethodBuilder, builder, value); + } else { + super.set(builder, value); + } + } + } + + // --------------------------------------------------------------- + + private static final class SingularMessageFieldAccessor extends SingularFieldAccessor { + SingularMessageFieldAccessor( + final FieldDescriptor descriptor, + final String camelCaseName, + final Class messageClass, + final Class> builderClass, + final String containingOneofCamelCaseName) { + super(descriptor, camelCaseName, messageClass, builderClass, containingOneofCamelCaseName); + + newBuilderMethod = getMethodOrDie(type, "newBuilder"); + getBuilderMethodBuilder = getMethodOrDie(builderClass, "get" + camelCaseName + "Builder"); + } + + private final Method newBuilderMethod; + private final Method getBuilderMethodBuilder; + + private Object coerceType(final Object value) { + if (type.isInstance(value)) { + return value; + } else { + // The value is not the exact right message type. However, if it + // is an alternative implementation of the same type -- e.g. a + // DynamicMessage -- we should accept it. In this case we can make + // a copy of the message. + return ((Message.Builder) invokeOrDie(newBuilderMethod, null)) + .mergeFrom((Message) value) + .buildPartial(); + } + } + + @Override + public void set(final Builder builder, final Object value) { + super.set(builder, coerceType(value)); + } + + @Override + public Message.Builder newBuilder() { + return (Message.Builder) invokeOrDie(newBuilderMethod, null); + } + + @Override + public Message.Builder getBuilder(FlattenedGeneratedMessageV3.Builder builder) { + return (Message.Builder) invokeOrDie(getBuilderMethodBuilder, builder); + } + } + + private static final class RepeatedMessageFieldAccessor extends RepeatedFieldAccessor { + RepeatedMessageFieldAccessor( + final FieldDescriptor descriptor, + final String camelCaseName, + final Class messageClass, + final Class> builderClass) { + super(descriptor, camelCaseName, messageClass, builderClass); + + newBuilderMethod = getMethodOrDie(type, "newBuilder"); + getBuilderMethodBuilder = + getMethodOrDie(builderClass, "get" + camelCaseName + "Builder", Integer.TYPE); + } + + private final Method newBuilderMethod; + private final Method getBuilderMethodBuilder; + + private Object coerceType(final Object value) { + if (type.isInstance(value)) { + return value; + } else { + // The value is not the exact right message type. However, if it + // is an alternative implementation of the same type -- e.g. a + // DynamicMessage -- we should accept it. In this case we can make + // a copy of the message. + return ((Message.Builder) invokeOrDie(newBuilderMethod, null)) + .mergeFrom((Message) value) + .build(); + } + } + + @Override + public void setRepeated(final Builder builder, final int index, final Object value) { + super.setRepeated(builder, index, coerceType(value)); + } + + @Override + public void addRepeated(final Builder builder, final Object value) { + super.addRepeated(builder, coerceType(value)); + } + + @Override + public Message.Builder newBuilder() { + return (Message.Builder) invokeOrDie(newBuilderMethod, null); + } + + @Override + public Message.Builder getRepeatedBuilder( + final FlattenedGeneratedMessageV3.Builder builder, final int index) { + return (Message.Builder) invokeOrDie(getBuilderMethodBuilder, builder, index); + } + } + } + + /** + * Replaces this object in the output stream with a serialized form. Part of Java's serialization + * magic. Generated sub-classes must override this method by calling {@code return + * super.writeReplace();} + * + * @return a SerializedForm of this message + */ + protected Object writeReplace() throws ObjectStreamException { + return new GeneratedMessageLite.SerializedForm(this); + } + + /** + * Checks that the {@link Extension} is non-Lite and returns it as a {@link GeneratedExtension}. + */ + private static , T> + Extension checkNotLite(ExtensionLite extension) { + if (extension.isLite()) { + throw new IllegalArgumentException("Expected non-lite extension."); + } + + return (Extension) extension; + } + + protected static boolean isStringEmpty(final Object value) { + if (value instanceof String) { + return ((String) value).isEmpty(); + } else { + return ((ByteString) value).isEmpty(); + } + } + + protected static int computeStringSize(final int fieldNumber, final Object value) { + if (value instanceof String) { + return CodedOutputStream.computeStringSize(fieldNumber, (String) value); + } else { + return CodedOutputStream.computeBytesSize(fieldNumber, (ByteString) value); + } + } + + protected static int computeStringSizeNoTag(final Object value) { + if (value instanceof String) { + return CodedOutputStream.computeStringSizeNoTag((String) value); + } else { + return CodedOutputStream.computeBytesSizeNoTag((ByteString) value); + } + } + + protected static void writeString( + CodedOutputStream output, final int fieldNumber, final Object value) throws IOException { + if (value instanceof String) { + output.writeString(fieldNumber, (String) value); + } else { + output.writeBytes(fieldNumber, (ByteString) value); + } + } + + protected static void writeStringNoTag(CodedOutputStream output, final Object value) + throws IOException { + if (value instanceof String) { + output.writeStringNoTag((String) value); + } else { + output.writeBytesNoTag((ByteString) value); + } + } + + protected static void serializeIntegerMapTo( + CodedOutputStream out, + MapField field, + MapEntry defaultEntry, + int fieldNumber) + throws IOException { + Map m = field.getMap(); + if (!out.isSerializationDeterministic()) { + serializeMapTo(out, m, defaultEntry, fieldNumber); + return; + } + // Sorting the unboxed keys and then look up the values during serialization is 2x faster + // than sorting map entries with a custom comparator directly. + int[] keys = new int[m.size()]; + int index = 0; + for (int k : m.keySet()) { + keys[index++] = k; + } + Arrays.sort(keys); + for (int key : keys) { + out.writeMessage( + fieldNumber, defaultEntry.newBuilderForType().setKey(key).setValue(m.get(key)).build()); + } + } + + protected static void serializeLongMapTo( + CodedOutputStream out, + MapField field, + MapEntry defaultEntry, + int fieldNumber) + throws IOException { + Map m = field.getMap(); + if (!out.isSerializationDeterministic()) { + serializeMapTo(out, m, defaultEntry, fieldNumber); + return; + } + + long[] keys = new long[m.size()]; + int index = 0; + for (long k : m.keySet()) { + keys[index++] = k; + } + Arrays.sort(keys); + for (long key : keys) { + out.writeMessage( + fieldNumber, defaultEntry.newBuilderForType().setKey(key).setValue(m.get(key)).build()); + } + } + + protected static void serializeStringMapTo( + CodedOutputStream out, + MapField field, + MapEntry defaultEntry, + int fieldNumber) + throws IOException { + Map m = field.getMap(); + if (!out.isSerializationDeterministic()) { + serializeMapTo(out, m, defaultEntry, fieldNumber); + return; + } + + // Sorting the String keys and then look up the values during serialization is 25% faster than + // sorting map entries with a custom comparator directly. + String[] keys = new String[m.size()]; + keys = m.keySet().toArray(keys); + Arrays.sort(keys); + for (String key : keys) { + out.writeMessage( + fieldNumber, defaultEntry.newBuilderForType().setKey(key).setValue(m.get(key)).build()); + } + } + + protected static void serializeBooleanMapTo( + CodedOutputStream out, + MapField field, + MapEntry defaultEntry, + int fieldNumber) + throws IOException { + Map m = field.getMap(); + if (!out.isSerializationDeterministic()) { + serializeMapTo(out, m, defaultEntry, fieldNumber); + return; + } + maybeSerializeBooleanEntryTo(out, m, defaultEntry, fieldNumber, false); + maybeSerializeBooleanEntryTo(out, m, defaultEntry, fieldNumber, true); + } + + private static void maybeSerializeBooleanEntryTo( + CodedOutputStream out, + Map m, + MapEntry defaultEntry, + int fieldNumber, + boolean key) + throws IOException { + if (m.containsKey(key)) { + out.writeMessage( + fieldNumber, defaultEntry.newBuilderForType().setKey(key).setValue(m.get(key)).build()); + } + } + + /** Serialize the map using the iteration order. */ + private static void serializeMapTo( + CodedOutputStream out, Map m, MapEntry defaultEntry, int fieldNumber) + throws IOException { + for (Map.Entry entry : m.entrySet()) { + out.writeMessage( + fieldNumber, + defaultEntry + .newBuilderForType() + .setKey(entry.getKey()) + .setValue(entry.getValue()) + .build()); + } + } +} diff --git a/protobuf-api/src/main/java/com/google/protobuf/MapEntry.java b/protobuf-api/src/main/java/com/google/protobuf/MapEntry.java index c065bee..8cd34ee 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/MapEntry.java +++ b/protobuf-api/src/main/java/com/google/protobuf/MapEntry.java @@ -10,11 +10,23 @@ import com.google.protobuf.Descriptors.Descriptor; import com.google.protobuf.Descriptors.EnumValueDescriptor; import com.google.protobuf.Descriptors.FieldDescriptor; + +import java.io.FilterInputStream; import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.TreeMap; +import static com.google.protobuf.Internal.checkNotNull; + /** * Implements MapEntry messages. * @@ -24,7 +36,7 @@ * *

Protobuf internal. Users shouldn't use this class. */ -public final class MapEntry extends AbstractMessage { +public final class MapEntry implements Message { private static final class Metadata extends MapEntryLite.Metadata { @@ -216,8 +228,319 @@ public UnknownFieldSet getUnknownFields() { return UnknownFieldSet.getDefaultInstance(); } + protected int memoizedHashCode = 0; + + @Override + public ByteString toByteString() { + try { + final ByteString.CodedBuilder out = ByteString.newCodedBuilder(getSerializedSize()); + writeTo(out.getCodedOutput()); + return out.build(); + } catch (IOException e) { + throw new RuntimeException(getSerializingExceptionMessage("ByteString"), e); + } + } + + @Override + public byte[] toByteArray() { + try { + final byte[] result = new byte[getSerializedSize()]; + final CodedOutputStream output = CodedOutputStream.newInstance(result); + writeTo(output); + output.checkNoSpaceLeft(); + return result; + } catch (IOException e) { + throw new RuntimeException(getSerializingExceptionMessage("byte array"), e); + } + } + + @Override + public void writeTo(final OutputStream output) throws IOException { + final int bufferSize = CodedOutputStream.computePreferredBufferSize(getSerializedSize()); + final CodedOutputStream codedOutput = CodedOutputStream.newInstance(output, bufferSize); + writeTo(codedOutput); + codedOutput.flush(); + } + + @Override + public void writeDelimitedTo(final OutputStream output) throws IOException { + final int serialized = getSerializedSize(); + final int bufferSize = + CodedOutputStream.computePreferredBufferSize( + CodedOutputStream.computeUInt32SizeNoTag(serialized) + serialized); + final CodedOutputStream codedOutput = CodedOutputStream.newInstance(output, bufferSize); + codedOutput.writeUInt32NoTag(serialized); + writeTo(codedOutput); + codedOutput.flush(); + } + + int getSerializedSize( + Schema schema) { + int memoizedSerializedSize = getMemoizedSerializedSize(); + if (memoizedSerializedSize == -1) { + memoizedSerializedSize = schema.getSerializedSize(this); + setMemoizedSerializedSize(memoizedSerializedSize); + } + return memoizedSerializedSize; + } + + private String getSerializingExceptionMessage(String target) { + return "Serializing " + + getClass().getName() + + " to a " + + target + + " threw an IOException (should never happen)."; + } + + protected static void checkByteStringIsUtf8(ByteString byteString) + throws IllegalArgumentException { + if (!byteString.isValidUtf8()) { + throw new IllegalArgumentException("Byte string is not UTF-8."); + } + } + + /** Interface for an enum which signifies which field in a {@code oneof} was specified. */ + protected interface InternalOneOfEnum { + /** + * Retrieves the field number of the field which was set in this {@code oneof}, or {@code 0} if + * none were. + */ + int getNumber(); + } + + /** + * Interface for the parent of a Builder that allows the builder to communicate invalidations back + * to the parent for use when using nested builders. + */ + protected interface BuilderParent { + + /** + * A builder becomes dirty whenever a field is modified -- including fields in nested builders + * -- and becomes clean when build() is called. Thus, when a builder becomes dirty, all its + * parents become dirty as well, and when it becomes clean, all its children become clean. The + * dirtiness state is used to invalidate certain cached values. + * + *

To this end, a builder calls markDirty() on its parent whenever it transitions from clean + * to dirty. The parent must propagate this call to its own parent, unless it was already dirty, + * in which case the grandparent must necessarily already be dirty as well. The parent can only + * transition back to "clean" after calling build() on all children. + */ + void markDirty(); + } + + /** Create a nested builder. */ + protected Message.Builder newBuilderForType(Message.BuilderParent parent) { + throw new UnsupportedOperationException("Nested builder is not supported for this type."); + } + + @Override + public List findInitializationErrors() { + return MessageReflection.findMissingFields(this); + } + + @Override + public String getInitializationErrorString() { + return MessageReflection.delimitWithCommas(findInitializationErrors()); + } + + // TODO: Clear it when all subclasses have implemented this method. + @Override + public boolean hasOneof(Descriptors.OneofDescriptor oneof) { + throw new UnsupportedOperationException("hasOneof() is not implemented."); + } + + // TODO: Clear it when all subclasses have implemented this method. + @Override + public FieldDescriptor getOneofFieldDescriptor(Descriptors.OneofDescriptor oneof) { + throw new UnsupportedOperationException("getOneofFieldDescriptor() is not implemented."); + } + + @Override + public final String toString() { + return TextFormat.printer().printToString(this); + } + + protected int memoizedSize = -1; + + int getMemoizedSerializedSize() { + return memoizedSize; + } + + void setMemoizedSerializedSize(int size) { + memoizedSize = size; + } + + @Override + public boolean equals(final Object other) { + if (other == this) { + return true; + } + if (!(other instanceof Message)) { + return false; + } + final Message otherMessage = (Message) other; + if (getDescriptorForType() != otherMessage.getDescriptorForType()) { + return false; + } + return compareFields(getAllFields(), otherMessage.getAllFields()) + && getUnknownFields().equals(otherMessage.getUnknownFields()); + } + + @Override + public int hashCode() { + int hash = memoizedHashCode; + if (hash == 0) { + hash = 41; + hash = (19 * hash) + getDescriptorForType().hashCode(); + hash = hashFields(hash, getAllFields()); + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + } + return hash; + } + + private static ByteString toByteString(Object value) { + if (value instanceof byte[]) { + return ByteString.copyFrom((byte[]) value); + } else { + return (ByteString) value; + } + } + + /** + * Compares two bytes fields. The parameters must be either a byte array or a ByteString object. + * They can be of different type though. + */ + private static boolean compareBytes(Object a, Object b) { + if (a instanceof byte[] && b instanceof byte[]) { + return Arrays.equals((byte[]) a, (byte[]) b); + } + return toByteString(a).equals(toByteString(b)); + } + + /** Converts a list of MapEntry messages into a Map used for equals() and hashCode(). */ + @SuppressWarnings({"rawtypes", "unchecked"}) + private static Map convertMapEntryListToMap(List list) { + if (list.isEmpty()) { + return Collections.emptyMap(); + } + Map result = new HashMap<>(); + Iterator iterator = list.iterator(); + Message entry = (Message) iterator.next(); + Descriptors.Descriptor descriptor = entry.getDescriptorForType(); + FieldDescriptor key = descriptor.findFieldByName("key"); + FieldDescriptor value = descriptor.findFieldByName("value"); + Object fieldValue = entry.getField(value); + if (fieldValue instanceof EnumValueDescriptor) { + fieldValue = ((EnumValueDescriptor) fieldValue).getNumber(); + } + result.put(entry.getField(key), fieldValue); + while (iterator.hasNext()) { + entry = (Message) iterator.next(); + fieldValue = entry.getField(value); + if (fieldValue instanceof EnumValueDescriptor) { + fieldValue = ((EnumValueDescriptor) fieldValue).getNumber(); + } + result.put(entry.getField(key), fieldValue); + } + return result; + } + + /** Compares two map fields. The parameters must be a list of MapEntry messages. */ + @SuppressWarnings({"rawtypes", "unchecked"}) + private static boolean compareMapField(Object a, Object b) { + Map ma = convertMapEntryListToMap((List) a); + Map mb = convertMapEntryListToMap((List) b); + return MapFieldLite.equals(ma, mb); + } + + /** + * Compares two sets of fields. This method is used to implement {@link + * Message#equals(Object)} and {@link AbstractMutableMessage#equals(Object)}. It takes + * special care of bytes fields because immutable messages and mutable messages use different Java + * type to represent a bytes field and this method should be able to compare immutable messages, + * mutable messages and also an immutable message to a mutable message. + */ + static boolean compareFields(Map a, Map b) { + if (a.size() != b.size()) { + return false; + } + for (FieldDescriptor descriptor : a.keySet()) { + if (!b.containsKey(descriptor)) { + return false; + } + Object value1 = a.get(descriptor); + Object value2 = b.get(descriptor); + if (descriptor.getType() == FieldDescriptor.Type.BYTES) { + if (descriptor.isRepeated()) { + List list1 = (List) value1; + List list2 = (List) value2; + if (list1.size() != list2.size()) { + return false; + } + for (int i = 0; i < list1.size(); i++) { + if (!compareBytes(list1.get(i), list2.get(i))) { + return false; + } + } + } else { + // Compares a singular bytes field. + if (!compareBytes(value1, value2)) { + return false; + } + } + } else if (descriptor.isMapField()) { + if (!compareMapField(value1, value2)) { + return false; + } + } else { + // Compare non-bytes fields. + if (!value1.equals(value2)) { + return false; + } + } + } + return true; + } + + /** Calculates the hash code of a map field. {@code value} must be a list of MapEntry messages. */ + @SuppressWarnings("unchecked") + private static int hashMapField(Object value) { + return MapFieldLite.calculateHashCodeForMap(convertMapEntryListToMap((List) value)); + } + + /** Get a hash code for given fields and values, using the given seed. */ + @SuppressWarnings("unchecked") + protected static int hashFields(int hash, Map map) { + for (Map.Entry entry : map.entrySet()) { + FieldDescriptor field = entry.getKey(); + Object value = entry.getValue(); + hash = (37 * hash) + field.getNumber(); + if (field.isMapField()) { + hash = (53 * hash) + hashMapField(value); + } else if (field.getType() != FieldDescriptor.Type.ENUM) { + hash = (53 * hash) + value.hashCode(); + } else if (field.isRepeated()) { + List list = (List) value; + hash = (53 * hash) + Internal.hashEnumList(list); + } else { + hash = (53 * hash) + Internal.hashEnum((Internal.EnumLite) value); + } + } + return hash; + } + + /** + * Package private helper method for AbstractParser to create UninitializedMessageException with + * missing field information. + */ + UninitializedMessageException newUninitializedMessageException() { + return Builder.newUninitializedMessageException(this); + } + + /** Builder to create {@link MapEntry} messages. */ - public static class Builder extends AbstractMessage.Builder> { + public static class Builder implements Message.Builder { private final Metadata metadata; private K key; private V value; @@ -417,10 +740,466 @@ public UnknownFieldSet getUnknownFields() { return UnknownFieldSet.getDefaultInstance(); } - @Override public Builder clone() { return new Builder<>(metadata, key, value, hasKey, hasValue); } + + /** + * An InputStream implementations which reads from some other InputStream but is limited to a + * particular number of bytes. Used by mergeDelimitedFrom(). This is intentionally + * package-private so that UnknownFieldSet can share it. + */ + static final class LimitedInputStream extends FilterInputStream { + private int limit; + + LimitedInputStream(InputStream in, int limit) { + super(in); + this.limit = limit; + } + + @Override + public int available() throws IOException { + return Math.min(super.available(), limit); + } + + @Override + public int read() throws IOException { + if (limit <= 0) { + return -1; + } + final int result = super.read(); + if (result >= 0) { + --limit; + } + return result; + } + + @Override + public int read(final byte[] b, final int off, int len) throws IOException { + if (limit <= 0) { + return -1; + } + len = Math.min(len, limit); + final int result = super.read(b, off, len); + if (result >= 0) { + limit -= result; + } + return result; + } + + @Override + public long skip(final long n) throws IOException { + // because we take the minimum of an int and a long, result is guaranteed to be + // less than or equal to Integer.MAX_INT so this cast is safe + int result = (int) super.skip(Math.min(n, limit)); + if (result >= 0) { + // if the superclass adheres to the contract for skip, this condition is always true + limit -= result; + } + return result; + } + } + + @Override + public boolean mergeDelimitedFrom( + final InputStream input, final ExtensionRegistryLite extensionRegistry) throws IOException { + final int firstByte = input.read(); + if (firstByte == -1) { + return false; + } + final int size = CodedInputStream.readRawVarint32(firstByte, input); + final InputStream limitedInput = new AbstractMessageLite.Builder.LimitedInputStream(input, size); + mergeFrom(limitedInput, extensionRegistry); + return true; + } + + @Override + public boolean mergeDelimitedFrom(final InputStream input) throws IOException { + return mergeDelimitedFrom(input, ExtensionRegistryLite.getEmptyRegistry()); + } + + @Override + @SuppressWarnings("unchecked") // isInstance takes care of this + public MapEntry.Builder mergeFrom(final MessageLite other) { + if (!getDefaultInstanceForType().getClass().isInstance(other)) { + throw new IllegalArgumentException( + "mergeFrom(MessageLite) can only merge messages of the same type."); + } + + return internalMergeFrom(other); + } + + private String getReadingExceptionMessage(String target) { + return "Reading " + + getClass().getName() + + " from a " + + target + + " threw an IOException (should never happen)."; + } + + // We check nulls as we iterate to avoid iterating over values twice. + private static void addAllCheckingNulls(Iterable values, List list) { + if (list instanceof ArrayList && values instanceof Collection) { + ((ArrayList) list).ensureCapacity(list.size() + ((Collection) values).size()); + } + int begin = list.size(); + for (T value : values) { + if (value == null) { + // encountered a null value so we must undo our modifications prior to throwing + String message = "Element at index " + (list.size() - begin) + " is null."; + for (int i = list.size() - 1; i >= begin; i--) { + list.remove(i); + } + throw new NullPointerException(message); + } + list.add(value); + } + } + + /** Construct an UninitializedMessageException reporting missing fields in the given message. */ + protected static UninitializedMessageException newUninitializedMessageException( + MessageLite message) { + return new UninitializedMessageException(message); + } + + // For binary compatibility. + @Deprecated + protected static void addAll(final Iterable values, final Collection list) { + addAll(values, (List) list); + } + + /** + * Adds the {@code values} to the {@code list}. This is a helper method used by generated code. + * Users should ignore it. + * + * @throws NullPointerException if {@code values} or any of the elements of {@code values} is + * null. + */ + protected static void addAll(final Iterable values, final List list) { + checkNotNull(values); + if (values instanceof LazyStringList) { + // For StringOrByteStringLists, check the underlying elements to avoid + // forcing conversions of ByteStrings to Strings. + // TODO: Could we just prohibit nulls in all protobuf lists and get rid of this? Is + // if even possible to hit this condition as all protobuf methods check for null first, + // right? + List lazyValues = ((LazyStringList) values).getUnderlyingElements(); + LazyStringList lazyList = (LazyStringList) list; + int begin = list.size(); + for (Object value : lazyValues) { + if (value == null) { + // encountered a null value so we must undo our modifications prior to throwing + String message = "Element at index " + (lazyList.size() - begin) + " is null."; + for (int i = lazyList.size() - 1; i >= begin; i--) { + lazyList.remove(i); + } + throw new NullPointerException(message); + } + if (value instanceof ByteString) { + lazyList.add((ByteString) value); + } else { + lazyList.add((String) value); + } + } + } else { + if (values instanceof PrimitiveNonBoxingCollection) { + list.addAll((Collection) values); + } else { + addAllCheckingNulls(values, list); + } + } + } + + /** TODO: Clear it when all subclasses have implemented this method. */ + @Override + public boolean hasOneof(Descriptors.OneofDescriptor oneof) { + throw new UnsupportedOperationException("hasOneof() is not implemented."); + } + + /** TODO: Clear it when all subclasses have implemented this method. */ + @Override + public FieldDescriptor getOneofFieldDescriptor(Descriptors.OneofDescriptor oneof) { + throw new UnsupportedOperationException("getOneofFieldDescriptor() is not implemented."); + } + + /** TODO: Clear it when all subclasses have implemented this method. */ + @Override + public MapEntry.Builder clearOneof(Descriptors.OneofDescriptor oneof) { + throw new UnsupportedOperationException("clearOneof() is not implemented."); + } + + @Override + public MapEntry.Builder clear() { + for (final Map.Entry entry : getAllFields().entrySet()) { + clearField(entry.getKey()); + } + return (MapEntry.Builder) this; + } + + @Override + public List findInitializationErrors() { + return MessageReflection.findMissingFields(this); + } + + @Override + public String getInitializationErrorString() { + return MessageReflection.delimitWithCommas(findInitializationErrors()); + } + + protected MapEntry.Builder internalMergeFrom(MessageLite other) { + return mergeFrom((Message) other); + } + + @Override + public MapEntry.Builder mergeFrom(final Message other) { + return mergeFrom(other, other.getAllFields()); + } + + MapEntry.Builder mergeFrom(final Message other, Map allFields) { + if (other.getDescriptorForType() != getDescriptorForType()) { + throw new IllegalArgumentException( + "mergeFrom(Message) can only merge messages of the same type."); + } + + // Note: We don't attempt to verify that other's fields have valid + // types. Doing so would be a losing battle. We'd have to verify + // all sub-messages as well, and we'd have to make copies of all of + // them to insure that they don't change after verification (since + // the Message interface itself cannot enforce immutability of + // implementations). + + for (final Map.Entry entry : allFields.entrySet()) { + final FieldDescriptor field = entry.getKey(); + if (field.isRepeated()) { + for (final Object element : (List) entry.getValue()) { + addRepeatedField(field, element); + } + } else if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { + final Message existingValue = (Message) getField(field); + if (existingValue == existingValue.getDefaultInstanceForType()) { + setField(field, entry.getValue()); + } else { + setField( + field, + existingValue + .newBuilderForType() + .mergeFrom(existingValue) + .mergeFrom((Message) entry.getValue()) + .build()); + } + } else { + setField(field, entry.getValue()); + } + } + + mergeUnknownFields(other.getUnknownFields()); + + return (MapEntry.Builder) this; + } + + @Override + public MapEntry.Builder mergeFrom(final CodedInputStream input) throws IOException { + return mergeFrom(input, ExtensionRegistry.getEmptyRegistry()); + } + + @Override + public MapEntry.Builder mergeFrom( + final CodedInputStream input, final ExtensionRegistryLite extensionRegistry) + throws IOException { + boolean discardUnknown = input.shouldDiscardUnknownFields(); + final UnknownFieldSet.Builder unknownFields = + discardUnknown ? null : getUnknownFieldSetBuilder(); + MessageReflection.mergeMessageFrom(this, unknownFields, input, extensionRegistry); + if (unknownFields != null) { + setUnknownFieldSetBuilder(unknownFields); + } + return (MapEntry.Builder) this; + } + + protected UnknownFieldSet.Builder getUnknownFieldSetBuilder() { + return UnknownFieldSet.newBuilder(getUnknownFields()); + } + + protected void setUnknownFieldSetBuilder(final UnknownFieldSet.Builder builder) { + setUnknownFields(builder.build()); + } + + @Override + public MapEntry.Builder mergeUnknownFields(final UnknownFieldSet unknownFields) { + setUnknownFields( + UnknownFieldSet.newBuilder(getUnknownFields()).mergeFrom(unknownFields).build()); + return (MapEntry.Builder) this; + } + + @Override + public MapEntry.Builder getFieldBuilder(final FieldDescriptor field) { + throw new UnsupportedOperationException( + "getFieldBuilder() called on an unsupported message type."); + } + + @Override + public MapEntry.Builder getRepeatedFieldBuilder(final FieldDescriptor field, int index) { + throw new UnsupportedOperationException( + "getRepeatedFieldBuilder() called on an unsupported message type."); + } + + @Override + public String toString() { + return TextFormat.printer().printToString(this); + } + + /** Construct an UninitializedMessageException reporting missing fields in the given message. */ + protected static UninitializedMessageException newUninitializedMessageException( + Message message) { + return new UninitializedMessageException(MessageReflection.findMissingFields(message)); + } + + /** + * Used to support nested builders and called to mark this builder as clean. Clean builders will + * propagate the {@link FlattenedAbstractMapEntry.BuilderParent#markDirty()} event to their parent builders, while dirty + * builders will not, as their parents should be dirty already. + * + *

NOTE: Implementations that don't support nested builders don't need to override this + * method. + */ + void markClean() { + throw new IllegalStateException("Should be overridden by subclasses."); + } + + /** + * Used to support nested builders and called when this nested builder is no longer used by its + * parent builder and should release the reference to its parent builder. + * + *

NOTE: Implementations that don't support nested builders don't need to override this + * method. + */ + void dispose() { + throw new IllegalStateException("Should be overridden by subclasses."); + } + + public MapEntry.Builder mergeFrom(final ByteString data) throws InvalidProtocolBufferException { + try { + final CodedInputStream input = data.newCodedInput(); + mergeFrom(input); + input.checkLastTagWas(0); + return (MapEntry.Builder) this; + } catch (InvalidProtocolBufferException e) { + throw e; + } catch (IOException e) { + throw new RuntimeException(getReadingExceptionMessage("ByteString"), e); + } + } + + public MapEntry.Builder mergeFrom( + final ByteString data, final ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + try { + final CodedInputStream input = data.newCodedInput(); + mergeFrom(input, extensionRegistry); + input.checkLastTagWas(0); + return (MapEntry.Builder) this; + } catch (InvalidProtocolBufferException e) { + throw e; + } catch (IOException e) { + throw new RuntimeException(getReadingExceptionMessage("ByteString"), e); + } + } + + public MapEntry.Builder mergeFrom(final byte[] data) throws InvalidProtocolBufferException { + return mergeFrom(data, 0, data.length); + } + + public MapEntry.Builder mergeFrom(final byte[] data, final int off, final int len) + throws InvalidProtocolBufferException { + try { + final CodedInputStream input = CodedInputStream.newInstance(data, off, len); + mergeFrom(input); + input.checkLastTagWas(0); + return (MapEntry.Builder) this; + } catch (InvalidProtocolBufferException e) { + throw e; + } catch (IOException e) { + throw new RuntimeException(getReadingExceptionMessage("byte array"), e); + } + } + + public MapEntry.Builder mergeFrom(final byte[] data, final ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + return mergeFrom(data, 0, data.length, extensionRegistry); + } + + public MapEntry.Builder mergeFrom( + final byte[] data, + final int off, + final int len, + final ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + try { + final CodedInputStream input = CodedInputStream.newInstance(data, off, len); + mergeFrom(input, extensionRegistry); + input.checkLastTagWas(0); + return (MapEntry.Builder) this; + } catch (InvalidProtocolBufferException e) { + throw e; + } catch (IOException e) { + throw new RuntimeException(getReadingExceptionMessage("byte array"), e); + } + } + + public MapEntry.Builder mergeFrom(final InputStream input) throws IOException { + final CodedInputStream codedInput = CodedInputStream.newInstance(input); + mergeFrom(codedInput); + codedInput.checkLastTagWas(0); + return (MapEntry.Builder) this; + } + + public MapEntry.Builder mergeFrom( + final InputStream input, final ExtensionRegistryLite extensionRegistry) throws IOException { + final CodedInputStream codedInput = CodedInputStream.newInstance(input); + mergeFrom(codedInput, extensionRegistry); + codedInput.checkLastTagWas(0); + return (MapEntry.Builder) this; + } + + /** + * @deprecated from v3.0.0-beta-3+, for compatibility with v2.5.0 and v2.6.1 + * generated code. + */ + @Deprecated + protected static int hashLong(long n) { + return (int) (n ^ (n >>> 32)); + } + + /** + * @deprecated from v3.0.0-beta-3+, for compatibility with v2.5.0 and v2.6.1 + * generated code. + */ + @Deprecated + protected static int hashBoolean(boolean b) { + return b ? 1231 : 1237; + } + + /** + * @deprecated from v3.0.0-beta-3+, for compatibility with v2.5.0 and v2.6.1 + * generated code. + */ + @Deprecated + protected static int hashEnum(Internal.EnumLite e) { + return e.getNumber(); + } + + /** + * @deprecated from v3.0.0-beta-3+, for compatibility with v2.5.0 and v2.6.1 + * generated code. + */ + @Deprecated + protected static int hashEnumList(List list) { + int hash = 1; + for (Internal.EnumLite e : list) { + hash = 31 * hash + hashEnum(e); + } + return hash; + } } private static boolean isInitialized(Metadata metadata, V value) { diff --git a/protobuf-api/src/main/java/com/google/protobuf/Message.java b/protobuf-api/src/main/java/com/google/protobuf/Message.java index 5b02c46..34c765a 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/Message.java +++ b/protobuf-api/src/main/java/com/google/protobuf/Message.java @@ -24,6 +24,26 @@ @CheckReturnValue public interface Message extends MessageLite, MessageOrBuilder { + /** + * Interface for the parent of a Builder that allows the builder to communicate invalidations back + * to the parent for use when using nested builders. + */ + interface BuilderParent { + + /** + * A builder becomes dirty whenever a field is modified -- including fields in nested builders + * -- and becomes clean when build() is called. Thus, when a builder becomes dirty, all its + * parents become dirty as well, and when it becomes clean, all its children become clean. The + * dirtiness state is used to invalidate certain cached values. + * + *

To this end, a builder calls markDirty() on its parent whenever it transitions from clean + * to dirty. The parent must propagate this call to its own parent, unless it was already dirty, + * in which case the grandparent must necessarily already be dirty as well. The parent can only + * transition back to "clean" after calling build() on all children. + */ + void markDirty(); + } + // (From MessageLite, re-declared here only for return type covariance.) @Override Parser getParserForType(); @@ -76,6 +96,7 @@ public interface Message extends MessageLite, MessageOrBuilder { /** Abstract interface implemented by Protocol Message builders. */ interface Builder extends MessageLite.Builder, MessageOrBuilder { + // (From MessageLite.Builder, re-declared here only for return type // covariance.) @Override diff --git a/protobuf-api/src/main/java/com/google/protobuf/RepeatedFieldBuilderV3.java b/protobuf-api/src/main/java/com/google/protobuf/RepeatedFieldBuilderV3.java index b36794f..f418b3a 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/RepeatedFieldBuilderV3.java +++ b/protobuf-api/src/main/java/com/google/protobuf/RepeatedFieldBuilderV3.java @@ -37,13 +37,13 @@ * @author jonp@google.com (Jon Perlow) */ public class RepeatedFieldBuilderV3< - MType extends AbstractMessage, - BType extends AbstractMessage.Builder, + MType extends Message, + BType extends Message.Builder, IType extends MessageOrBuilder> - implements AbstractMessage.BuilderParent { + implements Message.BuilderParent { // Parent to send changes to. - private AbstractMessage.BuilderParent parent; + private Message.BuilderParent parent; // List of messages. Never null. It may be immutable, in which case // isMessagesListMutable will be false. See note below. @@ -104,7 +104,7 @@ public class RepeatedFieldBuilderV3< public RepeatedFieldBuilderV3( List messages, boolean isMessagesListMutable, - AbstractMessage.BuilderParent parent, + Message.BuilderParent parent, boolean isClean) { this.messages = messages; this.isMessagesListMutable = isMessagesListMutable; @@ -551,8 +551,8 @@ private void incrementModCounts() { * @param the common interface for the message and the builder */ private static class MessageExternalList< - MType extends AbstractMessage, - BType extends AbstractMessage.Builder, + MType extends Message, + BType extends Message.Builder, IType extends MessageOrBuilder> extends AbstractList implements List, RandomAccess { @@ -585,8 +585,8 @@ void incrementModCount() { * @param the common interface for the message and the builder */ private static class BuilderExternalList< - MType extends AbstractMessage, - BType extends AbstractMessage.Builder, + MType extends Message, + BType extends Message.Builder, IType extends MessageOrBuilder> extends AbstractList implements List, RandomAccess { @@ -619,8 +619,8 @@ void incrementModCount() { * @param the common interface for the message and the builder */ private static class MessageOrBuilderExternalList< - MType extends AbstractMessage, - BType extends AbstractMessage.Builder, + MType extends Message, + BType extends Message.Builder, IType extends MessageOrBuilder> extends AbstractList implements List, RandomAccess { diff --git a/protobuf-api/src/main/java/com/google/protobuf/SingleFieldBuilderV3.java b/protobuf-api/src/main/java/com/google/protobuf/SingleFieldBuilderV3.java index 0aff2b8..cad278e 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/SingleFieldBuilderV3.java +++ b/protobuf-api/src/main/java/com/google/protobuf/SingleFieldBuilderV3.java @@ -30,13 +30,13 @@ * @author jonp@google.com (Jon Perlow) */ public class SingleFieldBuilderV3< - MType extends AbstractMessage, - BType extends AbstractMessage.Builder, + MType extends Message, + BType extends Message.Builder, IType extends MessageOrBuilder> - implements AbstractMessage.BuilderParent { + implements Message.BuilderParent { // Parent to send changes to. - private AbstractMessage.BuilderParent parent; + private Message.BuilderParent parent; // Invariant: one of builder or message fields must be non-null. @@ -53,7 +53,7 @@ public class SingleFieldBuilderV3< // to dispatch dirty invalidations. See AbstractMessage.BuilderListener. private boolean isClean; - public SingleFieldBuilderV3(MType message, AbstractMessage.BuilderParent parent, boolean isClean) { + public SingleFieldBuilderV3(MType message, Message.BuilderParent parent, boolean isClean) { this.message = checkNotNull(message); this.parent = parent; this.isClean = isClean; @@ -105,9 +105,9 @@ public BType getBuilder() { // does not create any sub-objects with independent clean/dirty states, // therefore setting the builder itself to clean without actually calling // build() cannot break any invariants. - builder = (BType) message.newBuilderForType(this); + builder = (BType) message.newBuilderForType(); builder.mergeFrom(message); // no-op if message is the default message - builder.markClean(); +// builder.markClean(); } return builder; } @@ -137,7 +137,7 @@ public IType getMessageOrBuilder() { public SingleFieldBuilderV3 setMessage(MType message) { this.message = checkNotNull(message); if (builder != null) { - builder.dispose(); +// builder.dispose(); builder = null; } onChanged(); @@ -175,7 +175,7 @@ public SingleFieldBuilderV3 clear() { ? message.getDefaultInstanceForType() : builder.getDefaultInstanceForType()); if (builder != null) { - builder.dispose(); +// builder.dispose(); builder = null; } onChanged(); From 3aa128717eaa9b5884cd2b18e0b8ed2a51cc5938 Mon Sep 17 00:00:00 2001 From: blakeli Date: Thu, 20 Mar 2025 18:12:43 -0400 Subject: [PATCH 02/42] Move GeneratedMessageV3 to SDK package. --- .../src/main/java/com/google/protobuf/GeneratedMessageV3.java | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {protobuf-api => protobuf-sdk}/src/main/java/com/google/protobuf/GeneratedMessageV3.java (100%) diff --git a/protobuf-api/src/main/java/com/google/protobuf/GeneratedMessageV3.java b/protobuf-sdk/src/main/java/com/google/protobuf/GeneratedMessageV3.java similarity index 100% rename from protobuf-api/src/main/java/com/google/protobuf/GeneratedMessageV3.java rename to protobuf-sdk/src/main/java/com/google/protobuf/GeneratedMessageV3.java From 0ca49b545a48ad9db5ab5ba9609500812738f7bc Mon Sep 17 00:00:00 2001 From: blakeli Date: Mon, 24 Mar 2025 20:38:30 -0400 Subject: [PATCH 03/42] Move implementations of CodedOutputStream to SDK package. --- .../google/protobuf/CodedOutputStream.java | 1982 +---------------- .../protobuf/AbstractBufferedEncoder.java | 160 ++ .../com/google/protobuf/ArrayEncoder.java | 354 +++ .../google/protobuf/ByteOutputEncoder.java | 322 +++ .../com/google/protobuf/HeapNioEncoder.java | 27 + .../google/protobuf/OutputStreamEncoder.java | 371 +++ .../google/protobuf/SafeDirectNioEncoder.java | 328 +++ .../protobuf/UnsafeDirectNioEncoder.java | 369 +++ 8 files changed, 2010 insertions(+), 1903 deletions(-) create mode 100644 protobuf-sdk/src/main/java/com/google/protobuf/AbstractBufferedEncoder.java create mode 100644 protobuf-sdk/src/main/java/com/google/protobuf/ArrayEncoder.java create mode 100644 protobuf-sdk/src/main/java/com/google/protobuf/ByteOutputEncoder.java create mode 100644 protobuf-sdk/src/main/java/com/google/protobuf/HeapNioEncoder.java create mode 100644 protobuf-sdk/src/main/java/com/google/protobuf/OutputStreamEncoder.java create mode 100644 protobuf-sdk/src/main/java/com/google/protobuf/SafeDirectNioEncoder.java create mode 100644 protobuf-sdk/src/main/java/com/google/protobuf/UnsafeDirectNioEncoder.java diff --git a/protobuf-api/src/main/java/com/google/protobuf/CodedOutputStream.java b/protobuf-api/src/main/java/com/google/protobuf/CodedOutputStream.java index 37bb44a..26b8829 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/CodedOutputStream.java +++ b/protobuf-api/src/main/java/com/google/protobuf/CodedOutputStream.java @@ -9,16 +9,15 @@ import static com.google.protobuf.WireFormat.FIXED32_SIZE; import static com.google.protobuf.WireFormat.FIXED64_SIZE; -import static com.google.protobuf.WireFormat.MAX_VARINT32_SIZE; import static com.google.protobuf.WireFormat.MAX_VARINT_SIZE; import static java.lang.Math.max; import com.google.protobuf.Utf8.UnpairedSurrogateException; import java.io.IOException; import java.io.OutputStream; -import java.nio.BufferOverflowException; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; import java.nio.ByteBuffer; -import java.nio.ByteOrder; import java.util.logging.Level; import java.util.logging.Logger; @@ -35,8 +34,14 @@ */ public abstract class CodedOutputStream extends ByteOutput { private static final Logger logger = Logger.getLogger(CodedOutputStream.class.getName()); - private static final boolean HAS_UNSAFE_ARRAY_OPERATIONS = UnsafeUtil.hasUnsafeArrayOperations(); - + static final boolean HAS_UNSAFE_ARRAY_OPERATIONS = UnsafeUtil.hasUnsafeArrayOperations(); + private static final Class ARRAY_ENCODER = getClassForName("com.google.protobuf.ArrayEncoder"); + private static final Class ABSTRACT_BUFFERED_ENCODER = getClassForName("com.google.protobuf.AbstractBufferedEncoder"); + private static final Class BYTE_OUTPUT_ENCODER = getClassForName("com.google.protobuf.ByteOutputEncoder"); + private static final Class HEAP_NIO_ENCODER = getClassForName("com.google.protobuf.HeapNioEncoder"); + private static final Class OUTPUT_STREAM_ENCODER = getClassForName("com.google.protobuf.OutputStreamEncoder"); + private static final Class SAFE_DIRECT_NIO_ENCODER = getClassForName("com.google.protobuf.SafeDirectNioEncoder"); + private static final Class UNSAFE_DIRECT_NIO_ENCODER = getClassForName("com.google.protobuf.UnsafeDirectNioEncoder"); /** Used to adapt to the experimental {@link Writer} interface. */ CodedOutputStreamWriter wrapper; @@ -46,6 +51,13 @@ public abstract class CodedOutputStream extends ByteOutput { /** The buffer size used in {@link #newInstance(OutputStream)}. */ public static final int DEFAULT_BUFFER_SIZE = 4096; + private static Class getClassForName(String name) { + try { + return (Class) Class.forName(name); + } catch (Throwable e) { + return null; + } + } /** * Returns the buffer size to efficiently write dataLength bytes to this CodedOutputStream. Used * by AbstractMessageLite. @@ -79,7 +91,16 @@ public static CodedOutputStream newInstance(final OutputStream output) { * debug. */ public static CodedOutputStream newInstance(final OutputStream output, final int bufferSize) { - return new OutputStreamEncoder(output, bufferSize); + try { + Constructor constructor = OUTPUT_STREAM_ENCODER.getConstructors()[0]; + return (CodedOutputStream)constructor.newInstance(output, bufferSize); + } catch (InstantiationException e) { + throw new RuntimeException(e); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } catch (InvocationTargetException e) { + throw new RuntimeException(e); + } } /** @@ -100,16 +121,34 @@ public static CodedOutputStream newInstance(final byte[] flatArray) { */ public static CodedOutputStream newInstance( final byte[] flatArray, final int offset, final int length) { - return new ArrayEncoder(flatArray, offset, length); + try { + Constructor constructor = ARRAY_ENCODER.getConstructors()[0]; + return (CodedOutputStream)constructor.newInstance(flatArray, offset, length); + } catch (InstantiationException e) { + throw new RuntimeException(e); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } catch (InvocationTargetException e) { + throw new RuntimeException(e); + } } /** Create a new {@code CodedOutputStream} that writes to the given {@link ByteBuffer}. */ public static CodedOutputStream newInstance(ByteBuffer buffer) { if (buffer.hasArray()) { - return new HeapNioEncoder(buffer); + try { + Constructor constructor = HEAP_NIO_ENCODER.getConstructors()[0]; + return (CodedOutputStream)constructor.newInstance(buffer); + } catch (InstantiationException e) { + throw new RuntimeException(e); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } catch (InvocationTargetException e) { + throw new RuntimeException(e); + } } if (buffer.isDirect() && !buffer.isReadOnly()) { - return UnsafeDirectNioEncoder.isSupported() + return UnsafeUtil.hasUnsafeByteBufferOperations() ? newUnsafeInstance(buffer) : newSafeInstance(buffer); } @@ -118,12 +157,30 @@ public static CodedOutputStream newInstance(ByteBuffer buffer) { /** For testing purposes only. */ static CodedOutputStream newUnsafeInstance(ByteBuffer buffer) { - return new UnsafeDirectNioEncoder(buffer); + try { + Constructor constructor = UNSAFE_DIRECT_NIO_ENCODER.getConstructors()[0]; + return (CodedOutputStream)constructor.newInstance(buffer); + } catch (InstantiationException e) { + throw new RuntimeException(e); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } catch (InvocationTargetException e) { + throw new RuntimeException(e); + } } /** For testing purposes only. */ static CodedOutputStream newSafeInstance(ByteBuffer buffer) { - return new SafeDirectNioEncoder(buffer); + try { + Constructor constructor = SAFE_DIRECT_NIO_ENCODER.getConstructors()[0]; + return (CodedOutputStream)constructor.newInstance(buffer); + } catch (InstantiationException e) { + throw new RuntimeException(e); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } catch (InvocationTargetException e) { + throw new RuntimeException(e); + } } /** @@ -193,12 +250,20 @@ static CodedOutputStream newInstance(ByteOutput byteOutput, int bufferSize) { if (bufferSize < 0) { throw new IllegalArgumentException("bufferSize must be positive"); } - - return new ByteOutputEncoder(byteOutput, bufferSize); + try { + Constructor constructor = BYTE_OUTPUT_ENCODER.getConstructors()[0]; + return (CodedOutputStream)constructor.newInstance(byteOutput, bufferSize); + } catch (InstantiationException e) { + throw new RuntimeException(e); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } catch (InvocationTargetException e) { + throw new RuntimeException(e); + } } // Disallow construction outside of this class. - private CodedOutputStream() {} + CodedOutputStream() {} // ----------------------------------------------------------------- @@ -1130,1893 +1195,4 @@ public final void writeRawLittleEndian64(final long value) throws IOException { writeFixed64NoTag(value); } - // ================================================================= - - /** A {@link CodedOutputStream} that writes directly to a byte array. */ - private static class ArrayEncoder extends CodedOutputStream { - private final byte[] buffer; - private final int offset; - private final int limit; - private int position; - - ArrayEncoder(byte[] buffer, int offset, int length) { - if (buffer == null) { - throw new NullPointerException("buffer"); - } - if ((offset | length | (buffer.length - (offset + length))) < 0) { - throw new IllegalArgumentException( - String.format( - "Array range is invalid. Buffer.length=%d, offset=%d, length=%d", - buffer.length, offset, length)); - } - this.buffer = buffer; - this.offset = offset; - position = offset; - limit = offset + length; - } - - @Override - public final void writeTag(final int fieldNumber, final int wireType) throws IOException { - writeUInt32NoTag(WireFormat.makeTag(fieldNumber, wireType)); - } - - @Override - public final void writeInt32(final int fieldNumber, final int value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); - writeInt32NoTag(value); - } - - @Override - public final void writeUInt32(final int fieldNumber, final int value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); - writeUInt32NoTag(value); - } - - @Override - public final void writeFixed32(final int fieldNumber, final int value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED32); - writeFixed32NoTag(value); - } - - @Override - public final void writeUInt64(final int fieldNumber, final long value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); - writeUInt64NoTag(value); - } - - @Override - public final void writeFixed64(final int fieldNumber, final long value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED64); - writeFixed64NoTag(value); - } - - @Override - public final void writeBool(final int fieldNumber, final boolean value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); - write((byte) (value ? 1 : 0)); - } - - @Override - public final void writeString(final int fieldNumber, final String value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeStringNoTag(value); - } - - @Override - public final void writeBytes(final int fieldNumber, final ByteString value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeBytesNoTag(value); - } - - @Override - public final void writeByteArray(final int fieldNumber, final byte[] value) throws IOException { - writeByteArray(fieldNumber, value, 0, value.length); - } - - @Override - public final void writeByteArray( - final int fieldNumber, final byte[] value, final int offset, final int length) - throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeByteArrayNoTag(value, offset, length); - } - - @Override - public final void writeByteBuffer(final int fieldNumber, final ByteBuffer value) - throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeUInt32NoTag(value.capacity()); - writeRawBytes(value); - } - - @Override - public final void writeBytesNoTag(final ByteString value) throws IOException { - writeUInt32NoTag(value.size()); - value.writeTo(this); - } - - @Override - public final void writeByteArrayNoTag(final byte[] value, int offset, int length) - throws IOException { - writeUInt32NoTag(length); - write(value, offset, length); - } - - @Override - public final void writeRawBytes(final ByteBuffer value) throws IOException { - if (value.hasArray()) { - write(value.array(), value.arrayOffset(), value.capacity()); - } else { - ByteBuffer duplicated = value.duplicate(); - Java8Compatibility.clear(duplicated); - write(duplicated); - } - } - - @Override - public final void writeMessage(final int fieldNumber, final MessageLite value) - throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeMessageNoTag(value); - } - - @Override - final void writeMessage(final int fieldNumber, final MessageLite value, Schema schema) - throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeUInt32NoTag(((AbstractMessageLite) value).getSerializedSize(schema)); - schema.writeTo(value, wrapper); - } - - @Override - public final void writeMessageSetExtension(final int fieldNumber, final MessageLite value) - throws IOException { - writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_START_GROUP); - writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber); - writeMessage(WireFormat.MESSAGE_SET_MESSAGE, value); - writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP); - } - - @Override - public final void writeRawMessageSetExtension(final int fieldNumber, final ByteString value) - throws IOException { - writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_START_GROUP); - writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber); - writeBytes(WireFormat.MESSAGE_SET_MESSAGE, value); - writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP); - } - - @Override - public final void writeMessageNoTag(final MessageLite value) throws IOException { - writeUInt32NoTag(value.getSerializedSize()); - value.writeTo(this); - } - - @Override - final void writeMessageNoTag(final MessageLite value, Schema schema) throws IOException { - writeUInt32NoTag(((AbstractMessageLite) value).getSerializedSize(schema)); - schema.writeTo(value, wrapper); - } - - @Override - public final void write(byte value) throws IOException { - try { - buffer[position++] = value; - } catch (IndexOutOfBoundsException e) { - throw new OutOfSpaceException( - String.format("Pos: %d, limit: %d, len: %d", position, limit, 1), e); - } - } - - @Override - public final void writeInt32NoTag(int value) throws IOException { - if (value >= 0) { - writeUInt32NoTag(value); - } else { - // Must sign-extend. - writeUInt64NoTag(value); - } - } - - @Override - public final void writeUInt32NoTag(int value) throws IOException { - try { - while (true) { - if ((value & ~0x7F) == 0) { - buffer[position++] = (byte) value; - return; - } else { - buffer[position++] = (byte) ((value & 0x7F) | 0x80); - value >>>= 7; - } - } - } catch (IndexOutOfBoundsException e) { - throw new OutOfSpaceException( - String.format("Pos: %d, limit: %d, len: %d", position, limit, 1), e); - } - } - - @Override - public final void writeFixed32NoTag(int value) throws IOException { - try { - buffer[position++] = (byte) (value & 0xFF); - buffer[position++] = (byte) ((value >> 8) & 0xFF); - buffer[position++] = (byte) ((value >> 16) & 0xFF); - buffer[position++] = (byte) ((value >> 24) & 0xFF); - } catch (IndexOutOfBoundsException e) { - throw new OutOfSpaceException( - String.format("Pos: %d, limit: %d, len: %d", position, limit, 1), e); - } - } - - @Override - public final void writeUInt64NoTag(long value) throws IOException { - if (HAS_UNSAFE_ARRAY_OPERATIONS && spaceLeft() >= MAX_VARINT_SIZE) { - while (true) { - if ((value & ~0x7FL) == 0) { - UnsafeUtil.putByte(buffer, position++, (byte) value); - return; - } else { - UnsafeUtil.putByte(buffer, position++, (byte) (((int) value & 0x7F) | 0x80)); - value >>>= 7; - } - } - } else { - try { - while (true) { - if ((value & ~0x7FL) == 0) { - buffer[position++] = (byte) value; - return; - } else { - buffer[position++] = (byte) (((int) value & 0x7F) | 0x80); - value >>>= 7; - } - } - } catch (IndexOutOfBoundsException e) { - throw new OutOfSpaceException( - String.format("Pos: %d, limit: %d, len: %d", position, limit, 1), e); - } - } - } - - @Override - public final void writeFixed64NoTag(long value) throws IOException { - try { - buffer[position++] = (byte) ((int) (value) & 0xFF); - buffer[position++] = (byte) ((int) (value >> 8) & 0xFF); - buffer[position++] = (byte) ((int) (value >> 16) & 0xFF); - buffer[position++] = (byte) ((int) (value >> 24) & 0xFF); - buffer[position++] = (byte) ((int) (value >> 32) & 0xFF); - buffer[position++] = (byte) ((int) (value >> 40) & 0xFF); - buffer[position++] = (byte) ((int) (value >> 48) & 0xFF); - buffer[position++] = (byte) ((int) (value >> 56) & 0xFF); - } catch (IndexOutOfBoundsException e) { - throw new OutOfSpaceException( - String.format("Pos: %d, limit: %d, len: %d", position, limit, 1), e); - } - } - - @Override - public final void write(byte[] value, int offset, int length) throws IOException { - try { - System.arraycopy(value, offset, buffer, position, length); - position += length; - } catch (IndexOutOfBoundsException e) { - throw new OutOfSpaceException( - String.format("Pos: %d, limit: %d, len: %d", position, limit, length), e); - } - } - - @Override - public final void writeLazy(byte[] value, int offset, int length) throws IOException { - write(value, offset, length); - } - - @Override - public final void write(ByteBuffer value) throws IOException { - final int length = value.remaining(); - try { - value.get(buffer, position, length); - position += length; - } catch (IndexOutOfBoundsException e) { - throw new OutOfSpaceException( - String.format("Pos: %d, limit: %d, len: %d", position, limit, length), e); - } - } - - @Override - public final void writeLazy(ByteBuffer value) throws IOException { - write(value); - } - - @Override - public final void writeStringNoTag(String value) throws IOException { - final int oldPosition = position; - try { - // UTF-8 byte length of the string is at least its UTF-16 code unit length (value.length()), - // and at most 3 times of it. We take advantage of this in both branches below. - final int maxLength = value.length() * Utf8.MAX_BYTES_PER_CHAR; - final int maxLengthVarIntSize = computeUInt32SizeNoTag(maxLength); - final int minLengthVarIntSize = computeUInt32SizeNoTag(value.length()); - if (minLengthVarIntSize == maxLengthVarIntSize) { - position = oldPosition + minLengthVarIntSize; - int newPosition = Utf8.encode(value, buffer, position, spaceLeft()); - // Since this class is stateful and tracks the position, we rewind and store the state, - // prepend the length, then reset it back to the end of the string. - position = oldPosition; - int length = newPosition - oldPosition - minLengthVarIntSize; - writeUInt32NoTag(length); - position = newPosition; - } else { - int length = Utf8.encodedLength(value); - writeUInt32NoTag(length); - position = Utf8.encode(value, buffer, position, spaceLeft()); - } - } catch (UnpairedSurrogateException e) { - // Roll back the change - we fall back to inefficient path. - position = oldPosition; - - // TODO: We should throw an IOException here instead. - inefficientWriteStringNoTag(value, e); - } catch (IndexOutOfBoundsException e) { - throw new OutOfSpaceException(e); - } - } - - @Override - public void flush() { - // Do nothing. - } - - @Override - public final int spaceLeft() { - return limit - position; - } - - @Override - public final int getTotalBytesWritten() { - return position - offset; - } - } - - /** - * A {@link CodedOutputStream} that writes directly to a heap {@link ByteBuffer}. Writes are done - * directly to the underlying array. The buffer position is only updated after a flush. - */ - private static final class HeapNioEncoder extends ArrayEncoder { - private final ByteBuffer byteBuffer; - private int initialPosition; - - HeapNioEncoder(ByteBuffer byteBuffer) { - super( - byteBuffer.array(), - byteBuffer.arrayOffset() + byteBuffer.position(), - byteBuffer.remaining()); - this.byteBuffer = byteBuffer; - this.initialPosition = byteBuffer.position(); - } - - @Override - public void flush() { - // Update the position on the buffer. - Java8Compatibility.position(byteBuffer, initialPosition + getTotalBytesWritten()); - } - } - - /** - * A {@link CodedOutputStream} that writes directly to a direct {@link ByteBuffer}, using only - * safe operations.. - */ - private static final class SafeDirectNioEncoder extends CodedOutputStream { - private final ByteBuffer originalBuffer; - private final ByteBuffer buffer; - private final int initialPosition; - - SafeDirectNioEncoder(ByteBuffer buffer) { - this.originalBuffer = buffer; - this.buffer = buffer.duplicate().order(ByteOrder.LITTLE_ENDIAN); - initialPosition = buffer.position(); - } - - @Override - public void writeTag(final int fieldNumber, final int wireType) throws IOException { - writeUInt32NoTag(WireFormat.makeTag(fieldNumber, wireType)); - } - - @Override - public void writeInt32(final int fieldNumber, final int value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); - writeInt32NoTag(value); - } - - @Override - public void writeUInt32(final int fieldNumber, final int value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); - writeUInt32NoTag(value); - } - - @Override - public void writeFixed32(final int fieldNumber, final int value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED32); - writeFixed32NoTag(value); - } - - @Override - public void writeUInt64(final int fieldNumber, final long value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); - writeUInt64NoTag(value); - } - - @Override - public void writeFixed64(final int fieldNumber, final long value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED64); - writeFixed64NoTag(value); - } - - @Override - public void writeBool(final int fieldNumber, final boolean value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); - write((byte) (value ? 1 : 0)); - } - - @Override - public void writeString(final int fieldNumber, final String value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeStringNoTag(value); - } - - @Override - public void writeBytes(final int fieldNumber, final ByteString value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeBytesNoTag(value); - } - - @Override - public void writeByteArray(final int fieldNumber, final byte[] value) throws IOException { - writeByteArray(fieldNumber, value, 0, value.length); - } - - @Override - public void writeByteArray( - final int fieldNumber, final byte[] value, final int offset, final int length) - throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeByteArrayNoTag(value, offset, length); - } - - @Override - public void writeByteBuffer(final int fieldNumber, final ByteBuffer value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeUInt32NoTag(value.capacity()); - writeRawBytes(value); - } - - @Override - public void writeMessage(final int fieldNumber, final MessageLite value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeMessageNoTag(value); - } - - @Override - void writeMessage(final int fieldNumber, final MessageLite value, Schema schema) - throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeMessageNoTag(value, schema); - } - - @Override - public void writeMessageSetExtension(final int fieldNumber, final MessageLite value) - throws IOException { - writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_START_GROUP); - writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber); - writeMessage(WireFormat.MESSAGE_SET_MESSAGE, value); - writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP); - } - - @Override - public void writeRawMessageSetExtension(final int fieldNumber, final ByteString value) - throws IOException { - writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_START_GROUP); - writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber); - writeBytes(WireFormat.MESSAGE_SET_MESSAGE, value); - writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP); - } - - @Override - public void writeMessageNoTag(final MessageLite value) throws IOException { - writeUInt32NoTag(value.getSerializedSize()); - value.writeTo(this); - } - - @Override - void writeMessageNoTag(final MessageLite value, Schema schema) throws IOException { - writeUInt32NoTag(((AbstractMessageLite) value).getSerializedSize(schema)); - schema.writeTo(value, wrapper); - } - - @Override - public void write(byte value) throws IOException { - try { - buffer.put(value); - } catch (BufferOverflowException e) { - throw new OutOfSpaceException(e); - } - } - - @Override - public void writeBytesNoTag(final ByteString value) throws IOException { - writeUInt32NoTag(value.size()); - value.writeTo(this); - } - - @Override - public void writeByteArrayNoTag(final byte[] value, int offset, int length) throws IOException { - writeUInt32NoTag(length); - write(value, offset, length); - } - - @Override - public void writeRawBytes(final ByteBuffer value) throws IOException { - if (value.hasArray()) { - write(value.array(), value.arrayOffset(), value.capacity()); - } else { - ByteBuffer duplicated = value.duplicate(); - Java8Compatibility.clear(duplicated); - write(duplicated); - } - } - - @Override - public void writeInt32NoTag(int value) throws IOException { - if (value >= 0) { - writeUInt32NoTag(value); - } else { - // Must sign-extend. - writeUInt64NoTag(value); - } - } - - @Override - public void writeUInt32NoTag(int value) throws IOException { - try { - while (true) { - if ((value & ~0x7F) == 0) { - buffer.put((byte) value); - return; - } else { - buffer.put((byte) ((value & 0x7F) | 0x80)); - value >>>= 7; - } - } - } catch (BufferOverflowException e) { - throw new OutOfSpaceException(e); - } - } - - @Override - public void writeFixed32NoTag(int value) throws IOException { - try { - buffer.putInt(value); - } catch (BufferOverflowException e) { - throw new OutOfSpaceException(e); - } - } - - @Override - public void writeUInt64NoTag(long value) throws IOException { - try { - while (true) { - if ((value & ~0x7FL) == 0) { - buffer.put((byte) value); - return; - } else { - buffer.put((byte) (((int) value & 0x7F) | 0x80)); - value >>>= 7; - } - } - } catch (BufferOverflowException e) { - throw new OutOfSpaceException(e); - } - } - - @Override - public void writeFixed64NoTag(long value) throws IOException { - try { - buffer.putLong(value); - } catch (BufferOverflowException e) { - throw new OutOfSpaceException(e); - } - } - - @Override - public void write(byte[] value, int offset, int length) throws IOException { - try { - buffer.put(value, offset, length); - } catch (IndexOutOfBoundsException e) { - throw new OutOfSpaceException(e); - } catch (BufferOverflowException e) { - throw new OutOfSpaceException(e); - } - } - - @Override - public void writeLazy(byte[] value, int offset, int length) throws IOException { - write(value, offset, length); - } - - @Override - public void write(ByteBuffer value) throws IOException { - try { - buffer.put(value); - } catch (BufferOverflowException e) { - throw new OutOfSpaceException(e); - } - } - - @Override - public void writeLazy(ByteBuffer value) throws IOException { - write(value); - } - - @Override - public void writeStringNoTag(String value) throws IOException { - final int startPos = buffer.position(); - try { - // UTF-8 byte length of the string is at least its UTF-16 code unit length (value.length()), - // and at most 3 times of it. We take advantage of this in both branches below. - final int maxEncodedSize = value.length() * Utf8.MAX_BYTES_PER_CHAR; - final int maxLengthVarIntSize = computeUInt32SizeNoTag(maxEncodedSize); - final int minLengthVarIntSize = computeUInt32SizeNoTag(value.length()); - if (minLengthVarIntSize == maxLengthVarIntSize) { - // Save the current position and increment past the length field. We'll come back - // and write the length field after the encoding is complete. - final int startOfBytes = buffer.position() + minLengthVarIntSize; - Java8Compatibility.position(buffer, startOfBytes); - - // Encode the string. - encode(value); - - // Now go back to the beginning and write the length. - int endOfBytes = buffer.position(); - Java8Compatibility.position(buffer, startPos); - writeUInt32NoTag(endOfBytes - startOfBytes); - - // Reposition the buffer past the written data. - Java8Compatibility.position(buffer, endOfBytes); - } else { - final int length = Utf8.encodedLength(value); - writeUInt32NoTag(length); - encode(value); - } - } catch (UnpairedSurrogateException e) { - // Roll back the change and convert to an IOException. - Java8Compatibility.position(buffer, startPos); - - // TODO: We should throw an IOException here instead. - inefficientWriteStringNoTag(value, e); - } catch (IllegalArgumentException e) { - // Thrown by buffer.position() if out of range. - throw new OutOfSpaceException(e); - } - } - - @Override - public void flush() { - // Update the position of the original buffer. - Java8Compatibility.position(originalBuffer, buffer.position()); - } - - @Override - public int spaceLeft() { - return buffer.remaining(); - } - - @Override - public int getTotalBytesWritten() { - return buffer.position() - initialPosition; - } - - private void encode(String value) throws IOException { - try { - Utf8.encodeUtf8(value, buffer); - } catch (IndexOutOfBoundsException e) { - throw new OutOfSpaceException(e); - } - } - } - - /** - * A {@link CodedOutputStream} that writes directly to a direct {@link ByteBuffer} using {@code - * sun.misc.Unsafe}. - */ - private static final class UnsafeDirectNioEncoder extends CodedOutputStream { - private final ByteBuffer originalBuffer; - private final ByteBuffer buffer; - private final long address; - private final long initialPosition; - private final long limit; - private final long oneVarintLimit; - private long position; - - UnsafeDirectNioEncoder(ByteBuffer buffer) { - this.originalBuffer = buffer; - this.buffer = buffer.duplicate().order(ByteOrder.LITTLE_ENDIAN); - address = UnsafeUtil.addressOffset(buffer); - initialPosition = address + buffer.position(); - limit = address + buffer.limit(); - oneVarintLimit = limit - MAX_VARINT_SIZE; - position = initialPosition; - } - - static boolean isSupported() { - return UnsafeUtil.hasUnsafeByteBufferOperations(); - } - - @Override - public void writeTag(int fieldNumber, int wireType) throws IOException { - writeUInt32NoTag(WireFormat.makeTag(fieldNumber, wireType)); - } - - @Override - public void writeInt32(int fieldNumber, int value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); - writeInt32NoTag(value); - } - - @Override - public void writeUInt32(int fieldNumber, int value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); - writeUInt32NoTag(value); - } - - @Override - public void writeFixed32(int fieldNumber, int value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED32); - writeFixed32NoTag(value); - } - - @Override - public void writeUInt64(int fieldNumber, long value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); - writeUInt64NoTag(value); - } - - @Override - public void writeFixed64(int fieldNumber, long value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED64); - writeFixed64NoTag(value); - } - - @Override - public void writeBool(int fieldNumber, boolean value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); - write((byte) (value ? 1 : 0)); - } - - @Override - public void writeString(int fieldNumber, String value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeStringNoTag(value); - } - - @Override - public void writeBytes(int fieldNumber, ByteString value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeBytesNoTag(value); - } - - @Override - public void writeByteArray(int fieldNumber, byte[] value) throws IOException { - writeByteArray(fieldNumber, value, 0, value.length); - } - - @Override - public void writeByteArray(int fieldNumber, byte[] value, int offset, int length) - throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeByteArrayNoTag(value, offset, length); - } - - @Override - public void writeByteBuffer(int fieldNumber, ByteBuffer value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeUInt32NoTag(value.capacity()); - writeRawBytes(value); - } - - @Override - public void writeMessage(int fieldNumber, MessageLite value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeMessageNoTag(value); - } - - @Override - void writeMessage(int fieldNumber, MessageLite value, Schema schema) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeMessageNoTag(value, schema); - } - - @Override - public void writeMessageSetExtension(int fieldNumber, MessageLite value) throws IOException { - writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_START_GROUP); - writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber); - writeMessage(WireFormat.MESSAGE_SET_MESSAGE, value); - writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP); - } - - @Override - public void writeRawMessageSetExtension(int fieldNumber, ByteString value) throws IOException { - writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_START_GROUP); - writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber); - writeBytes(WireFormat.MESSAGE_SET_MESSAGE, value); - writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP); - } - - @Override - public void writeMessageNoTag(MessageLite value) throws IOException { - writeUInt32NoTag(value.getSerializedSize()); - value.writeTo(this); - } - - @Override - void writeMessageNoTag(MessageLite value, Schema schema) throws IOException { - writeUInt32NoTag(((AbstractMessageLite) value).getSerializedSize(schema)); - schema.writeTo(value, wrapper); - } - - @Override - public void write(byte value) throws IOException { - if (position >= limit) { - throw new OutOfSpaceException( - String.format("Pos: %d, limit: %d, len: %d", position, limit, 1)); - } - UnsafeUtil.putByte(position++, value); - } - - @Override - public void writeBytesNoTag(ByteString value) throws IOException { - writeUInt32NoTag(value.size()); - value.writeTo(this); - } - - @Override - public void writeByteArrayNoTag(byte[] value, int offset, int length) throws IOException { - writeUInt32NoTag(length); - write(value, offset, length); - } - - @Override - public void writeRawBytes(ByteBuffer value) throws IOException { - if (value.hasArray()) { - write(value.array(), value.arrayOffset(), value.capacity()); - } else { - ByteBuffer duplicated = value.duplicate(); - Java8Compatibility.clear(duplicated); - write(duplicated); - } - } - - @Override - public void writeInt32NoTag(int value) throws IOException { - if (value >= 0) { - writeUInt32NoTag(value); - } else { - // Must sign-extend. - writeUInt64NoTag(value); - } - } - - @Override - public void writeUInt32NoTag(int value) throws IOException { - if (position <= oneVarintLimit) { - // Optimization to avoid bounds checks on each iteration. - while (true) { - if ((value & ~0x7F) == 0) { - UnsafeUtil.putByte(position++, (byte) value); - return; - } else { - UnsafeUtil.putByte(position++, (byte) ((value & 0x7F) | 0x80)); - value >>>= 7; - } - } - } else { - while (position < limit) { - if ((value & ~0x7F) == 0) { - UnsafeUtil.putByte(position++, (byte) value); - return; - } else { - UnsafeUtil.putByte(position++, (byte) ((value & 0x7F) | 0x80)); - value >>>= 7; - } - } - throw new OutOfSpaceException( - String.format("Pos: %d, limit: %d, len: %d", position, limit, 1)); - } - } - - @Override - public void writeFixed32NoTag(int value) throws IOException { - buffer.putInt(bufferPos(position), value); - position += FIXED32_SIZE; - } - - @Override - public void writeUInt64NoTag(long value) throws IOException { - if (position <= oneVarintLimit) { - // Optimization to avoid bounds checks on each iteration. - while (true) { - if ((value & ~0x7FL) == 0) { - UnsafeUtil.putByte(position++, (byte) value); - return; - } else { - UnsafeUtil.putByte(position++, (byte) (((int) value & 0x7F) | 0x80)); - value >>>= 7; - } - } - } else { - while (position < limit) { - if ((value & ~0x7FL) == 0) { - UnsafeUtil.putByte(position++, (byte) value); - return; - } else { - UnsafeUtil.putByte(position++, (byte) (((int) value & 0x7F) | 0x80)); - value >>>= 7; - } - } - throw new OutOfSpaceException( - String.format("Pos: %d, limit: %d, len: %d", position, limit, 1)); - } - } - - @Override - public void writeFixed64NoTag(long value) throws IOException { - buffer.putLong(bufferPos(position), value); - position += FIXED64_SIZE; - } - - @Override - public void write(byte[] value, int offset, int length) throws IOException { - if (value == null - || offset < 0 - || length < 0 - || (value.length - length) < offset - || (limit - length) < position) { - if (value == null) { - throw new NullPointerException("value"); - } - throw new OutOfSpaceException( - String.format("Pos: %d, limit: %d, len: %d", position, limit, length)); - } - - UnsafeUtil.copyMemory(value, offset, position, length); - position += length; - } - - @Override - public void writeLazy(byte[] value, int offset, int length) throws IOException { - write(value, offset, length); - } - - @Override - public void write(ByteBuffer value) throws IOException { - try { - int length = value.remaining(); - repositionBuffer(position); - buffer.put(value); - position += length; - } catch (BufferOverflowException e) { - throw new OutOfSpaceException(e); - } - } - - @Override - public void writeLazy(ByteBuffer value) throws IOException { - write(value); - } - - @Override - public void writeStringNoTag(String value) throws IOException { - long prevPos = position; - try { - // UTF-8 byte length of the string is at least its UTF-16 code unit length (value.length()), - // and at most 3 times of it. We take advantage of this in both branches below. - int maxEncodedSize = value.length() * Utf8.MAX_BYTES_PER_CHAR; - int maxLengthVarIntSize = computeUInt32SizeNoTag(maxEncodedSize); - int minLengthVarIntSize = computeUInt32SizeNoTag(value.length()); - if (minLengthVarIntSize == maxLengthVarIntSize) { - // Save the current position and increment past the length field. We'll come back - // and write the length field after the encoding is complete. - int stringStart = bufferPos(position) + minLengthVarIntSize; - Java8Compatibility.position(buffer, stringStart); - - // Encode the string. - Utf8.encodeUtf8(value, buffer); - - // Write the length and advance the position. - int length = buffer.position() - stringStart; - writeUInt32NoTag(length); - position += length; - } else { - // Calculate and write the encoded length. - int length = Utf8.encodedLength(value); - writeUInt32NoTag(length); - - // Write the string and advance the position. - repositionBuffer(position); - Utf8.encodeUtf8(value, buffer); - position += length; - } - } catch (UnpairedSurrogateException e) { - // Roll back the change and convert to an IOException. - position = prevPos; - repositionBuffer(position); - - // TODO: We should throw an IOException here instead. - inefficientWriteStringNoTag(value, e); - } catch (IllegalArgumentException e) { - // Thrown by buffer.position() if out of range. - throw new OutOfSpaceException(e); - } catch (IndexOutOfBoundsException e) { - throw new OutOfSpaceException(e); - } - } - - @Override - public void flush() { - // Update the position of the original buffer. - Java8Compatibility.position(originalBuffer, bufferPos(position)); - } - - @Override - public int spaceLeft() { - return (int) (limit - position); - } - - @Override - public int getTotalBytesWritten() { - return (int) (position - initialPosition); - } - - private void repositionBuffer(long pos) { - Java8Compatibility.position(buffer, bufferPos(pos)); - } - - private int bufferPos(long pos) { - return (int) (pos - address); - } - } - - /** Abstract base class for buffered encoders. */ - private abstract static class AbstractBufferedEncoder extends CodedOutputStream { - final byte[] buffer; - final int limit; - int position; - int totalBytesWritten; - - AbstractBufferedEncoder(int bufferSize) { - if (bufferSize < 0) { - throw new IllegalArgumentException("bufferSize must be >= 0"); - } - // As an optimization, we require that the buffer be able to store at least 2 - // varints so that we can buffer any integer write (tag + value). This reduces the - // number of range checks for a single write to 1 (i.e. if there is not enough space - // to buffer the tag+value, flush and then buffer it). - this.buffer = new byte[max(bufferSize, MAX_VARINT_SIZE * 2)]; - this.limit = buffer.length; - } - - @Override - public final int spaceLeft() { - throw new UnsupportedOperationException( - "spaceLeft() can only be called on CodedOutputStreams that are " - + "writing to a flat array or ByteBuffer."); - } - - @Override - public final int getTotalBytesWritten() { - return totalBytesWritten; - } - - /** - * This method does not perform bounds checking on the array. Checking array bounds is the - * responsibility of the caller. - */ - final void buffer(byte value) { - buffer[position++] = value; - totalBytesWritten++; - } - - /** - * This method does not perform bounds checking on the array. Checking array bounds is the - * responsibility of the caller. - */ - final void bufferTag(final int fieldNumber, final int wireType) { - bufferUInt32NoTag(WireFormat.makeTag(fieldNumber, wireType)); - } - - /** - * This method does not perform bounds checking on the array. Checking array bounds is the - * responsibility of the caller. - */ - final void bufferInt32NoTag(final int value) { - if (value >= 0) { - bufferUInt32NoTag(value); - } else { - // Must sign-extend. - bufferUInt64NoTag(value); - } - } - - /** - * This method does not perform bounds checking on the array. Checking array bounds is the - * responsibility of the caller. - */ - final void bufferUInt32NoTag(int value) { - if (HAS_UNSAFE_ARRAY_OPERATIONS) { - final long originalPos = position; - while (true) { - if ((value & ~0x7F) == 0) { - UnsafeUtil.putByte(buffer, position++, (byte) value); - break; - } else { - UnsafeUtil.putByte(buffer, position++, (byte) ((value & 0x7F) | 0x80)); - value >>>= 7; - } - } - int delta = (int) (position - originalPos); - totalBytesWritten += delta; - } else { - while (true) { - if ((value & ~0x7F) == 0) { - buffer[position++] = (byte) value; - totalBytesWritten++; - return; - } else { - buffer[position++] = (byte) ((value & 0x7F) | 0x80); - totalBytesWritten++; - value >>>= 7; - } - } - } - } - - /** - * This method does not perform bounds checking on the array. Checking array bounds is the - * responsibility of the caller. - */ - final void bufferUInt64NoTag(long value) { - if (HAS_UNSAFE_ARRAY_OPERATIONS) { - final long originalPos = position; - while (true) { - if ((value & ~0x7FL) == 0) { - UnsafeUtil.putByte(buffer, position++, (byte) value); - break; - } else { - UnsafeUtil.putByte(buffer, position++, (byte) (((int) value & 0x7F) | 0x80)); - value >>>= 7; - } - } - int delta = (int) (position - originalPos); - totalBytesWritten += delta; - } else { - while (true) { - if ((value & ~0x7FL) == 0) { - buffer[position++] = (byte) value; - totalBytesWritten++; - return; - } else { - buffer[position++] = (byte) (((int) value & 0x7F) | 0x80); - totalBytesWritten++; - value >>>= 7; - } - } - } - } - - /** - * This method does not perform bounds checking on the array. Checking array bounds is the - * responsibility of the caller. - */ - final void bufferFixed32NoTag(int value) { - buffer[position++] = (byte) (value & 0xFF); - buffer[position++] = (byte) ((value >> 8) & 0xFF); - buffer[position++] = (byte) ((value >> 16) & 0xFF); - buffer[position++] = (byte) ((value >> 24) & 0xFF); - totalBytesWritten += FIXED32_SIZE; - } - - /** - * This method does not perform bounds checking on the array. Checking array bounds is the - * responsibility of the caller. - */ - final void bufferFixed64NoTag(long value) { - buffer[position++] = (byte) (value & 0xFF); - buffer[position++] = (byte) ((value >> 8) & 0xFF); - buffer[position++] = (byte) ((value >> 16) & 0xFF); - buffer[position++] = (byte) ((value >> 24) & 0xFF); - buffer[position++] = (byte) ((int) (value >> 32) & 0xFF); - buffer[position++] = (byte) ((int) (value >> 40) & 0xFF); - buffer[position++] = (byte) ((int) (value >> 48) & 0xFF); - buffer[position++] = (byte) ((int) (value >> 56) & 0xFF); - totalBytesWritten += FIXED64_SIZE; - } - } - - /** - * A {@link CodedOutputStream} that decorates a {@link ByteOutput}. It internal buffer only to - * support string encoding operations. All other writes are just passed through to the {@link - * ByteOutput}. - */ - private static final class ByteOutputEncoder extends AbstractBufferedEncoder { - private final ByteOutput out; - - ByteOutputEncoder(ByteOutput out, int bufferSize) { - super(bufferSize); - if (out == null) { - throw new NullPointerException("out"); - } - this.out = out; - } - - @Override - public void writeTag(final int fieldNumber, final int wireType) throws IOException { - writeUInt32NoTag(WireFormat.makeTag(fieldNumber, wireType)); - } - - @Override - public void writeInt32(final int fieldNumber, final int value) throws IOException { - flushIfNotAvailable(MAX_VARINT_SIZE * 2); - bufferTag(fieldNumber, WireFormat.WIRETYPE_VARINT); - bufferInt32NoTag(value); - } - - @Override - public void writeUInt32(final int fieldNumber, final int value) throws IOException { - flushIfNotAvailable(MAX_VARINT_SIZE * 2); - bufferTag(fieldNumber, WireFormat.WIRETYPE_VARINT); - bufferUInt32NoTag(value); - } - - @Override - public void writeFixed32(final int fieldNumber, final int value) throws IOException { - flushIfNotAvailable(MAX_VARINT_SIZE + FIXED32_SIZE); - bufferTag(fieldNumber, WireFormat.WIRETYPE_FIXED32); - bufferFixed32NoTag(value); - } - - @Override - public void writeUInt64(final int fieldNumber, final long value) throws IOException { - flushIfNotAvailable(MAX_VARINT_SIZE * 2); - bufferTag(fieldNumber, WireFormat.WIRETYPE_VARINT); - bufferUInt64NoTag(value); - } - - @Override - public void writeFixed64(final int fieldNumber, final long value) throws IOException { - flushIfNotAvailable(MAX_VARINT_SIZE + FIXED64_SIZE); - bufferTag(fieldNumber, WireFormat.WIRETYPE_FIXED64); - bufferFixed64NoTag(value); - } - - @Override - public void writeBool(final int fieldNumber, final boolean value) throws IOException { - flushIfNotAvailable(MAX_VARINT_SIZE + 1); - bufferTag(fieldNumber, WireFormat.WIRETYPE_VARINT); - buffer((byte) (value ? 1 : 0)); - } - - @Override - public void writeString(final int fieldNumber, final String value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeStringNoTag(value); - } - - @Override - public void writeBytes(final int fieldNumber, final ByteString value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeBytesNoTag(value); - } - - @Override - public void writeByteArray(final int fieldNumber, final byte[] value) throws IOException { - writeByteArray(fieldNumber, value, 0, value.length); - } - - @Override - public void writeByteArray( - final int fieldNumber, final byte[] value, final int offset, final int length) - throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeByteArrayNoTag(value, offset, length); - } - - @Override - public void writeByteBuffer(final int fieldNumber, final ByteBuffer value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeUInt32NoTag(value.capacity()); - writeRawBytes(value); - } - - @Override - public void writeBytesNoTag(final ByteString value) throws IOException { - writeUInt32NoTag(value.size()); - value.writeTo(this); - } - - @Override - public void writeByteArrayNoTag(final byte[] value, int offset, int length) throws IOException { - writeUInt32NoTag(length); - write(value, offset, length); - } - - @Override - public void writeRawBytes(final ByteBuffer value) throws IOException { - if (value.hasArray()) { - write(value.array(), value.arrayOffset(), value.capacity()); - } else { - ByteBuffer duplicated = value.duplicate(); - Java8Compatibility.clear(duplicated); - write(duplicated); - } - } - - @Override - public void writeMessage(final int fieldNumber, final MessageLite value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeMessageNoTag(value); - } - - @Override - void writeMessage(final int fieldNumber, final MessageLite value, Schema schema) - throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeMessageNoTag(value, schema); - } - - @Override - public void writeMessageSetExtension(final int fieldNumber, final MessageLite value) - throws IOException { - writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_START_GROUP); - writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber); - writeMessage(WireFormat.MESSAGE_SET_MESSAGE, value); - writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP); - } - - @Override - public void writeRawMessageSetExtension(final int fieldNumber, final ByteString value) - throws IOException { - writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_START_GROUP); - writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber); - writeBytes(WireFormat.MESSAGE_SET_MESSAGE, value); - writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP); - } - - @Override - public void writeMessageNoTag(final MessageLite value) throws IOException { - writeUInt32NoTag(value.getSerializedSize()); - value.writeTo(this); - } - - @Override - void writeMessageNoTag(final MessageLite value, Schema schema) throws IOException { - writeUInt32NoTag(((AbstractMessageLite) value).getSerializedSize(schema)); - schema.writeTo(value, wrapper); - } - - @Override - public void write(byte value) throws IOException { - if (position == limit) { - doFlush(); - } - - buffer(value); - } - - @Override - public void writeInt32NoTag(int value) throws IOException { - if (value >= 0) { - writeUInt32NoTag(value); - } else { - // Must sign-extend. - writeUInt64NoTag(value); - } - } - - @Override - public void writeUInt32NoTag(int value) throws IOException { - flushIfNotAvailable(MAX_VARINT32_SIZE); - bufferUInt32NoTag(value); - } - - @Override - public void writeFixed32NoTag(final int value) throws IOException { - flushIfNotAvailable(FIXED32_SIZE); - bufferFixed32NoTag(value); - } - - @Override - public void writeUInt64NoTag(long value) throws IOException { - flushIfNotAvailable(MAX_VARINT_SIZE); - bufferUInt64NoTag(value); - } - - @Override - public void writeFixed64NoTag(final long value) throws IOException { - flushIfNotAvailable(FIXED64_SIZE); - bufferFixed64NoTag(value); - } - - @Override - public void writeStringNoTag(String value) throws IOException { - // UTF-8 byte length of the string is at least its UTF-16 code unit length (value.length()), - // and at most 3 times of it. We take advantage of this in both branches below. - final int maxLength = value.length() * Utf8.MAX_BYTES_PER_CHAR; - final int maxLengthVarIntSize = computeUInt32SizeNoTag(maxLength); - - // If we are streaming and the potential length is too big to fit in our buffer, we take the - // slower path. - if (maxLengthVarIntSize + maxLength > limit) { - // Allocate a byte[] that we know can fit the string and encode into it. String.getBytes() - // does the same internally and then does *another copy* to return a byte[] of exactly the - // right size. We can skip that copy and just writeRawBytes up to the actualLength of the - // UTF-8 encoded bytes. - final byte[] encodedBytes = new byte[maxLength]; - int actualLength = Utf8.encode(value, encodedBytes, 0, maxLength); - writeUInt32NoTag(actualLength); - writeLazy(encodedBytes, 0, actualLength); - return; - } - - // Fast path: we have enough space available in our buffer for the string... - if (maxLengthVarIntSize + maxLength > limit - position) { - // Flush to free up space. - doFlush(); - } - - final int oldPosition = position; - try { - // Optimize for the case where we know this length results in a constant varint length as - // this saves a pass for measuring the length of the string. - final int minLengthVarIntSize = computeUInt32SizeNoTag(value.length()); - - if (minLengthVarIntSize == maxLengthVarIntSize) { - position = oldPosition + minLengthVarIntSize; - int newPosition = Utf8.encode(value, buffer, position, limit - position); - // Since this class is stateful and tracks the position, we rewind and store the state, - // prepend the length, then reset it back to the end of the string. - position = oldPosition; - int length = newPosition - oldPosition - minLengthVarIntSize; - bufferUInt32NoTag(length); - position = newPosition; - totalBytesWritten += length; - } else { - int length = Utf8.encodedLength(value); - bufferUInt32NoTag(length); - position = Utf8.encode(value, buffer, position, length); - totalBytesWritten += length; - } - } catch (UnpairedSurrogateException e) { - // Roll back the change and convert to an IOException. - totalBytesWritten -= position - oldPosition; - position = oldPosition; - - // TODO: We should throw an IOException here instead. - inefficientWriteStringNoTag(value, e); - } catch (IndexOutOfBoundsException e) { - throw new OutOfSpaceException(e); - } - } - - @Override - public void flush() throws IOException { - if (position > 0) { - // Flush the buffer. - doFlush(); - } - } - - @Override - public void write(byte[] value, int offset, int length) throws IOException { - flush(); - out.write(value, offset, length); - totalBytesWritten += length; - } - - @Override - public void writeLazy(byte[] value, int offset, int length) throws IOException { - flush(); - out.writeLazy(value, offset, length); - totalBytesWritten += length; - } - - @Override - public void write(ByteBuffer value) throws IOException { - flush(); - int length = value.remaining(); - out.write(value); - totalBytesWritten += length; - } - - @Override - public void writeLazy(ByteBuffer value) throws IOException { - flush(); - int length = value.remaining(); - out.writeLazy(value); - totalBytesWritten += length; - } - - private void flushIfNotAvailable(int requiredSize) throws IOException { - if (limit - position < requiredSize) { - doFlush(); - } - } - - private void doFlush() throws IOException { - out.write(buffer, 0, position); - position = 0; - } - } - - /** - * An {@link CodedOutputStream} that decorates an {@link OutputStream}. It performs internal - * buffering to optimize writes to the {@link OutputStream}. - */ - private static final class OutputStreamEncoder extends AbstractBufferedEncoder { - private final OutputStream out; - - OutputStreamEncoder(OutputStream out, int bufferSize) { - super(bufferSize); - if (out == null) { - throw new NullPointerException("out"); - } - this.out = out; - } - - @Override - public void writeTag(final int fieldNumber, final int wireType) throws IOException { - writeUInt32NoTag(WireFormat.makeTag(fieldNumber, wireType)); - } - - @Override - public void writeInt32(final int fieldNumber, final int value) throws IOException { - flushIfNotAvailable(MAX_VARINT_SIZE * 2); - bufferTag(fieldNumber, WireFormat.WIRETYPE_VARINT); - bufferInt32NoTag(value); - } - - @Override - public void writeUInt32(final int fieldNumber, final int value) throws IOException { - flushIfNotAvailable(MAX_VARINT_SIZE * 2); - bufferTag(fieldNumber, WireFormat.WIRETYPE_VARINT); - bufferUInt32NoTag(value); - } - - @Override - public void writeFixed32(final int fieldNumber, final int value) throws IOException { - flushIfNotAvailable(MAX_VARINT_SIZE + FIXED32_SIZE); - bufferTag(fieldNumber, WireFormat.WIRETYPE_FIXED32); - bufferFixed32NoTag(value); - } - - @Override - public void writeUInt64(final int fieldNumber, final long value) throws IOException { - flushIfNotAvailable(MAX_VARINT_SIZE * 2); - bufferTag(fieldNumber, WireFormat.WIRETYPE_VARINT); - bufferUInt64NoTag(value); - } - - @Override - public void writeFixed64(final int fieldNumber, final long value) throws IOException { - flushIfNotAvailable(MAX_VARINT_SIZE + FIXED64_SIZE); - bufferTag(fieldNumber, WireFormat.WIRETYPE_FIXED64); - bufferFixed64NoTag(value); - } - - @Override - public void writeBool(final int fieldNumber, final boolean value) throws IOException { - flushIfNotAvailable(MAX_VARINT_SIZE + 1); - bufferTag(fieldNumber, WireFormat.WIRETYPE_VARINT); - buffer((byte) (value ? 1 : 0)); - } - - @Override - public void writeString(final int fieldNumber, final String value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeStringNoTag(value); - } - - @Override - public void writeBytes(final int fieldNumber, final ByteString value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeBytesNoTag(value); - } - - @Override - public void writeByteArray(final int fieldNumber, final byte[] value) throws IOException { - writeByteArray(fieldNumber, value, 0, value.length); - } - - @Override - public void writeByteArray( - final int fieldNumber, final byte[] value, final int offset, final int length) - throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeByteArrayNoTag(value, offset, length); - } - - @Override - public void writeByteBuffer(final int fieldNumber, final ByteBuffer value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeUInt32NoTag(value.capacity()); - writeRawBytes(value); - } - - @Override - public void writeBytesNoTag(final ByteString value) throws IOException { - writeUInt32NoTag(value.size()); - value.writeTo(this); - } - - @Override - public void writeByteArrayNoTag(final byte[] value, int offset, int length) throws IOException { - writeUInt32NoTag(length); - write(value, offset, length); - } - - @Override - public void writeRawBytes(final ByteBuffer value) throws IOException { - if (value.hasArray()) { - write(value.array(), value.arrayOffset(), value.capacity()); - } else { - ByteBuffer duplicated = value.duplicate(); - Java8Compatibility.clear(duplicated); - write(duplicated); - } - } - - @Override - public void writeMessage(final int fieldNumber, final MessageLite value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeMessageNoTag(value); - } - - @Override - void writeMessage(final int fieldNumber, final MessageLite value, Schema schema) - throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeMessageNoTag(value, schema); - } - - @Override - public void writeMessageSetExtension(final int fieldNumber, final MessageLite value) - throws IOException { - writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_START_GROUP); - writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber); - writeMessage(WireFormat.MESSAGE_SET_MESSAGE, value); - writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP); - } - - @Override - public void writeRawMessageSetExtension(final int fieldNumber, final ByteString value) - throws IOException { - writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_START_GROUP); - writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber); - writeBytes(WireFormat.MESSAGE_SET_MESSAGE, value); - writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP); - } - - @Override - public void writeMessageNoTag(final MessageLite value) throws IOException { - writeUInt32NoTag(value.getSerializedSize()); - value.writeTo(this); - } - - @Override - void writeMessageNoTag(final MessageLite value, Schema schema) throws IOException { - writeUInt32NoTag(((AbstractMessageLite) value).getSerializedSize(schema)); - schema.writeTo(value, wrapper); - } - - @Override - public void write(byte value) throws IOException { - if (position == limit) { - doFlush(); - } - - buffer(value); - } - - @Override - public void writeInt32NoTag(int value) throws IOException { - if (value >= 0) { - writeUInt32NoTag(value); - } else { - // Must sign-extend. - writeUInt64NoTag(value); - } - } - - @Override - public void writeUInt32NoTag(int value) throws IOException { - flushIfNotAvailable(MAX_VARINT32_SIZE); - bufferUInt32NoTag(value); - } - - @Override - public void writeFixed32NoTag(final int value) throws IOException { - flushIfNotAvailable(FIXED32_SIZE); - bufferFixed32NoTag(value); - } - - @Override - public void writeUInt64NoTag(long value) throws IOException { - flushIfNotAvailable(MAX_VARINT_SIZE); - bufferUInt64NoTag(value); - } - - @Override - public void writeFixed64NoTag(final long value) throws IOException { - flushIfNotAvailable(FIXED64_SIZE); - bufferFixed64NoTag(value); - } - - @Override - public void writeStringNoTag(String value) throws IOException { - try { - // UTF-8 byte length of the string is at least its UTF-16 code unit length (value.length()), - // and at most 3 times of it. We take advantage of this in both branches below. - final int maxLength = value.length() * Utf8.MAX_BYTES_PER_CHAR; - final int maxLengthVarIntSize = computeUInt32SizeNoTag(maxLength); - - // If we are streaming and the potential length is too big to fit in our buffer, we take the - // slower path. - if (maxLengthVarIntSize + maxLength > limit) { - // Allocate a byte[] that we know can fit the string and encode into it. String.getBytes() - // does the same internally and then does *another copy* to return a byte[] of exactly the - // right size. We can skip that copy and just writeRawBytes up to the actualLength of the - // UTF-8 encoded bytes. - final byte[] encodedBytes = new byte[maxLength]; - int actualLength = Utf8.encode(value, encodedBytes, 0, maxLength); - writeUInt32NoTag(actualLength); - writeLazy(encodedBytes, 0, actualLength); - return; - } - - // Fast path: we have enough space available in our buffer for the string... - if (maxLengthVarIntSize + maxLength > limit - position) { - // Flush to free up space. - doFlush(); - } - - // Optimize for the case where we know this length results in a constant varint length as - // this saves a pass for measuring the length of the string. - final int minLengthVarIntSize = computeUInt32SizeNoTag(value.length()); - int oldPosition = position; - final int length; - try { - if (minLengthVarIntSize == maxLengthVarIntSize) { - position = oldPosition + minLengthVarIntSize; - int newPosition = Utf8.encode(value, buffer, position, limit - position); - // Since this class is stateful and tracks the position, we rewind and store the - // state, prepend the length, then reset it back to the end of the string. - position = oldPosition; - length = newPosition - oldPosition - minLengthVarIntSize; - bufferUInt32NoTag(length); - position = newPosition; - } else { - length = Utf8.encodedLength(value); - bufferUInt32NoTag(length); - position = Utf8.encode(value, buffer, position, length); - } - totalBytesWritten += length; - } catch (UnpairedSurrogateException e) { - // Be extra careful and restore the original position for retrying the write with the - // less efficient path. - totalBytesWritten -= position - oldPosition; - position = oldPosition; - throw e; - } catch (ArrayIndexOutOfBoundsException e) { - throw new OutOfSpaceException(e); - } - } catch (UnpairedSurrogateException e) { - inefficientWriteStringNoTag(value, e); - } - } - - @Override - public void flush() throws IOException { - if (position > 0) { - // Flush the buffer. - doFlush(); - } - } - - @Override - public void write(byte[] value, int offset, int length) throws IOException { - if (limit - position >= length) { - // We have room in the current buffer. - System.arraycopy(value, offset, buffer, position, length); - position += length; - totalBytesWritten += length; - } else { - // Write extends past current buffer. Fill the rest of this buffer and - // flush. - final int bytesWritten = limit - position; - System.arraycopy(value, offset, buffer, position, bytesWritten); - offset += bytesWritten; - length -= bytesWritten; - position = limit; - totalBytesWritten += bytesWritten; - doFlush(); - - // Now deal with the rest. - // Since we have an output stream, this is our buffer - // and buffer offset == 0 - if (length <= limit) { - // Fits in new buffer. - System.arraycopy(value, offset, buffer, 0, length); - position = length; - } else { - // Write is very big. Let's do it all at once. - out.write(value, offset, length); - } - totalBytesWritten += length; - } - } - - @Override - public void writeLazy(byte[] value, int offset, int length) throws IOException { - write(value, offset, length); - } - - @Override - public void write(ByteBuffer value) throws IOException { - int length = value.remaining(); - if (limit - position >= length) { - // We have room in the current buffer. - value.get(buffer, position, length); - position += length; - totalBytesWritten += length; - } else { - // Write extends past current buffer. Fill the rest of this buffer and - // flush. - final int bytesWritten = limit - position; - value.get(buffer, position, bytesWritten); - length -= bytesWritten; - position = limit; - totalBytesWritten += bytesWritten; - doFlush(); - - // Now deal with the rest. - // Since we have an output stream, this is our buffer - // and buffer offset == 0 - while (length > limit) { - // Copy data into the buffer before writing it to OutputStream. - value.get(buffer, 0, limit); - out.write(buffer, 0, limit); - length -= limit; - totalBytesWritten += limit; - } - value.get(buffer, 0, length); - position = length; - totalBytesWritten += length; - } - } - - @Override - public void writeLazy(ByteBuffer value) throws IOException { - write(value); - } - - private void flushIfNotAvailable(int requiredSize) throws IOException { - if (limit - position < requiredSize) { - doFlush(); - } - } - - private void doFlush() throws IOException { - out.write(buffer, 0, position); - position = 0; - } - } } diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/AbstractBufferedEncoder.java b/protobuf-sdk/src/main/java/com/google/protobuf/AbstractBufferedEncoder.java new file mode 100644 index 0000000..cafbf01 --- /dev/null +++ b/protobuf-sdk/src/main/java/com/google/protobuf/AbstractBufferedEncoder.java @@ -0,0 +1,160 @@ +package com.google.protobuf; + +import static com.google.protobuf.WireFormat.*; +import static java.lang.Math.max; + +/** Abstract base class for buffered encoders. */ +abstract class AbstractBufferedEncoder extends CodedOutputStream { + final byte[] buffer; + final int limit; + int position; + int totalBytesWritten; + + AbstractBufferedEncoder(int bufferSize) { + if (bufferSize < 0) { + throw new IllegalArgumentException("bufferSize must be >= 0"); + } + // As an optimization, we require that the buffer be able to store at least 2 + // varints so that we can buffer any integer write (tag + value). This reduces the + // number of range checks for a single write to 1 (i.e. if there is not enough space + // to buffer the tag+value, flush and then buffer it). + this.buffer = new byte[max(bufferSize, MAX_VARINT_SIZE * 2)]; + this.limit = buffer.length; + } + + @Override + public final int spaceLeft() { + throw new UnsupportedOperationException( + "spaceLeft() can only be called on CodedOutputStreams that are " + + "writing to a flat array or ByteBuffer."); + } + + @Override + public final int getTotalBytesWritten() { + return totalBytesWritten; + } + + /** + * This method does not perform bounds checking on the array. Checking array bounds is the + * responsibility of the caller. + */ + final void buffer(byte value) { + buffer[position++] = value; + totalBytesWritten++; + } + + /** + * This method does not perform bounds checking on the array. Checking array bounds is the + * responsibility of the caller. + */ + final void bufferTag(final int fieldNumber, final int wireType) { + bufferUInt32NoTag(WireFormat.makeTag(fieldNumber, wireType)); + } + + /** + * This method does not perform bounds checking on the array. Checking array bounds is the + * responsibility of the caller. + */ + final void bufferInt32NoTag(final int value) { + if (value >= 0) { + bufferUInt32NoTag(value); + } else { + // Must sign-extend. + bufferUInt64NoTag(value); + } + } + + /** + * This method does not perform bounds checking on the array. Checking array bounds is the + * responsibility of the caller. + */ + final void bufferUInt32NoTag(int value) { + if (HAS_UNSAFE_ARRAY_OPERATIONS) { + final long originalPos = position; + while (true) { + if ((value & ~0x7F) == 0) { + UnsafeUtil.putByte(buffer, position++, (byte) value); + break; + } else { + UnsafeUtil.putByte(buffer, position++, (byte) ((value & 0x7F) | 0x80)); + value >>>= 7; + } + } + int delta = (int) (position - originalPos); + totalBytesWritten += delta; + } else { + while (true) { + if ((value & ~0x7F) == 0) { + buffer[position++] = (byte) value; + totalBytesWritten++; + return; + } else { + buffer[position++] = (byte) ((value & 0x7F) | 0x80); + totalBytesWritten++; + value >>>= 7; + } + } + } + } + + /** + * This method does not perform bounds checking on the array. Checking array bounds is the + * responsibility of the caller. + */ + final void bufferUInt64NoTag(long value) { + if (HAS_UNSAFE_ARRAY_OPERATIONS) { + final long originalPos = position; + while (true) { + if ((value & ~0x7FL) == 0) { + UnsafeUtil.putByte(buffer, position++, (byte) value); + break; + } else { + UnsafeUtil.putByte(buffer, position++, (byte) (((int) value & 0x7F) | 0x80)); + value >>>= 7; + } + } + int delta = (int) (position - originalPos); + totalBytesWritten += delta; + } else { + while (true) { + if ((value & ~0x7FL) == 0) { + buffer[position++] = (byte) value; + totalBytesWritten++; + return; + } else { + buffer[position++] = (byte) (((int) value & 0x7F) | 0x80); + totalBytesWritten++; + value >>>= 7; + } + } + } + } + + /** + * This method does not perform bounds checking on the array. Checking array bounds is the + * responsibility of the caller. + */ + final void bufferFixed32NoTag(int value) { + buffer[position++] = (byte) (value & 0xFF); + buffer[position++] = (byte) ((value >> 8) & 0xFF); + buffer[position++] = (byte) ((value >> 16) & 0xFF); + buffer[position++] = (byte) ((value >> 24) & 0xFF); + totalBytesWritten += FIXED32_SIZE; + } + + /** + * This method does not perform bounds checking on the array. Checking array bounds is the + * responsibility of the caller. + */ + final void bufferFixed64NoTag(long value) { + buffer[position++] = (byte) (value & 0xFF); + buffer[position++] = (byte) ((value >> 8) & 0xFF); + buffer[position++] = (byte) ((value >> 16) & 0xFF); + buffer[position++] = (byte) ((value >> 24) & 0xFF); + buffer[position++] = (byte) ((int) (value >> 32) & 0xFF); + buffer[position++] = (byte) ((int) (value >> 40) & 0xFF); + buffer[position++] = (byte) ((int) (value >> 48) & 0xFF); + buffer[position++] = (byte) ((int) (value >> 56) & 0xFF); + totalBytesWritten += FIXED64_SIZE; + } +} \ No newline at end of file diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/ArrayEncoder.java b/protobuf-sdk/src/main/java/com/google/protobuf/ArrayEncoder.java new file mode 100644 index 0000000..efd2860 --- /dev/null +++ b/protobuf-sdk/src/main/java/com/google/protobuf/ArrayEncoder.java @@ -0,0 +1,354 @@ +package com.google.protobuf; + +import java.io.IOException; +import java.nio.ByteBuffer; + +import static com.google.protobuf.WireFormat.MAX_VARINT_SIZE; + +/** A {@link CodedOutputStream} that writes directly to a byte array. */ +class ArrayEncoder extends CodedOutputStream { + private final byte[] buffer; + private final int offset; + private final int limit; + private int position; + + ArrayEncoder(byte[] buffer, int offset, int length) { + super(); + if (buffer == null) { + throw new NullPointerException("buffer"); + } + if ((offset | length | (buffer.length - (offset + length))) < 0) { + throw new IllegalArgumentException( + String.format( + "Array range is invalid. Buffer.length=%d, offset=%d, length=%d", + buffer.length, offset, length)); + } + this.buffer = buffer; + this.offset = offset; + position = offset; + limit = offset + length; + } + + @Override + public final void writeTag(final int fieldNumber, final int wireType) throws IOException { + writeUInt32NoTag(WireFormat.makeTag(fieldNumber, wireType)); + } + + @Override + public final void writeInt32(final int fieldNumber, final int value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); + writeInt32NoTag(value); + } + + @Override + public final void writeUInt32(final int fieldNumber, final int value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); + writeUInt32NoTag(value); + } + + @Override + public final void writeFixed32(final int fieldNumber, final int value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED32); + writeFixed32NoTag(value); + } + + @Override + public final void writeUInt64(final int fieldNumber, final long value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); + writeUInt64NoTag(value); + } + + @Override + public final void writeFixed64(final int fieldNumber, final long value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED64); + writeFixed64NoTag(value); + } + + @Override + public final void writeBool(final int fieldNumber, final boolean value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); + write((byte) (value ? 1 : 0)); + } + + @Override + public final void writeString(final int fieldNumber, final String value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeStringNoTag(value); + } + + @Override + public final void writeBytes(final int fieldNumber, final ByteString value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeBytesNoTag(value); + } + + @Override + public final void writeByteArray(final int fieldNumber, final byte[] value) throws IOException { + writeByteArray(fieldNumber, value, 0, value.length); + } + + @Override + public final void writeByteArray( + final int fieldNumber, final byte[] value, final int offset, final int length) + throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeByteArrayNoTag(value, offset, length); + } + + @Override + public final void writeByteBuffer(final int fieldNumber, final ByteBuffer value) + throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeUInt32NoTag(value.capacity()); + writeRawBytes(value); + } + + @Override + public final void writeBytesNoTag(final ByteString value) throws IOException { + writeUInt32NoTag(value.size()); + value.writeTo(this); + } + + @Override + public final void writeByteArrayNoTag(final byte[] value, int offset, int length) + throws IOException { + writeUInt32NoTag(length); + write(value, offset, length); + } + + @Override + public final void writeRawBytes(final ByteBuffer value) throws IOException { + if (value.hasArray()) { + write(value.array(), value.arrayOffset(), value.capacity()); + } else { + ByteBuffer duplicated = value.duplicate(); + Java8Compatibility.clear(duplicated); + write(duplicated); + } + } + + @Override + public final void writeMessage(final int fieldNumber, final MessageLite value) + throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeMessageNoTag(value); + } + + @Override + final void writeMessage(final int fieldNumber, final MessageLite value, Schema schema) + throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeUInt32NoTag(((AbstractMessageLite) value).getSerializedSize(schema)); + schema.writeTo(value, wrapper); + } + + @Override + public final void writeMessageSetExtension(final int fieldNumber, final MessageLite value) + throws IOException { + writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_START_GROUP); + writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber); + writeMessage(WireFormat.MESSAGE_SET_MESSAGE, value); + writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP); + } + + @Override + public final void writeRawMessageSetExtension(final int fieldNumber, final ByteString value) + throws IOException { + writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_START_GROUP); + writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber); + writeBytes(WireFormat.MESSAGE_SET_MESSAGE, value); + writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP); + } + + @Override + public final void writeMessageNoTag(final MessageLite value) throws IOException { + writeUInt32NoTag(value.getSerializedSize()); + ((AbstractMessageLite) value).writeTo(this); + } + + @Override + final void writeMessageNoTag(final MessageLite value, Schema schema) throws IOException { + writeUInt32NoTag(((AbstractMessageLite) value).getSerializedSize(schema)); + schema.writeTo(value, wrapper); + } + + @Override + public final void write(byte value) throws IOException { + try { + buffer[position++] = value; + } catch (IndexOutOfBoundsException e) { + throw new OutOfSpaceException( + String.format("Pos: %d, limit: %d, len: %d", position, limit, 1), e); + } + } + + @Override + public final void writeInt32NoTag(int value) throws IOException { + if (value >= 0) { + writeUInt32NoTag(value); + } else { + // Must sign-extend. + writeUInt64NoTag(value); + } + } + + @Override + public final void writeUInt32NoTag(int value) throws IOException { + try { + while (true) { + if ((value & ~0x7F) == 0) { + buffer[position++] = (byte) value; + return; + } else { + buffer[position++] = (byte) ((value & 0x7F) | 0x80); + value >>>= 7; + } + } + } catch (IndexOutOfBoundsException e) { + throw new OutOfSpaceException( + String.format("Pos: %d, limit: %d, len: %d", position, limit, 1), e); + } + } + + @Override + public final void writeFixed32NoTag(int value) throws IOException { + try { + buffer[position++] = (byte) (value & 0xFF); + buffer[position++] = (byte) ((value >> 8) & 0xFF); + buffer[position++] = (byte) ((value >> 16) & 0xFF); + buffer[position++] = (byte) ((value >> 24) & 0xFF); + } catch (IndexOutOfBoundsException e) { + throw new OutOfSpaceException( + String.format("Pos: %d, limit: %d, len: %d", position, limit, 1), e); + } + } + + @Override + public final void writeUInt64NoTag(long value) throws IOException { + if (HAS_UNSAFE_ARRAY_OPERATIONS && spaceLeft() >= MAX_VARINT_SIZE) { + while (true) { + if ((value & ~0x7FL) == 0) { + UnsafeUtil.putByte(buffer, position++, (byte) value); + return; + } else { + UnsafeUtil.putByte(buffer, position++, (byte) (((int) value & 0x7F) | 0x80)); + value >>>= 7; + } + } + } else { + try { + while (true) { + if ((value & ~0x7FL) == 0) { + buffer[position++] = (byte) value; + return; + } else { + buffer[position++] = (byte) (((int) value & 0x7F) | 0x80); + value >>>= 7; + } + } + } catch (IndexOutOfBoundsException e) { + throw new OutOfSpaceException( + String.format("Pos: %d, limit: %d, len: %d", position, limit, 1), e); + } + } + } + + @Override + public final void writeFixed64NoTag(long value) throws IOException { + try { + buffer[position++] = (byte) ((int) (value) & 0xFF); + buffer[position++] = (byte) ((int) (value >> 8) & 0xFF); + buffer[position++] = (byte) ((int) (value >> 16) & 0xFF); + buffer[position++] = (byte) ((int) (value >> 24) & 0xFF); + buffer[position++] = (byte) ((int) (value >> 32) & 0xFF); + buffer[position++] = (byte) ((int) (value >> 40) & 0xFF); + buffer[position++] = (byte) ((int) (value >> 48) & 0xFF); + buffer[position++] = (byte) ((int) (value >> 56) & 0xFF); + } catch (IndexOutOfBoundsException e) { + throw new OutOfSpaceException( + String.format("Pos: %d, limit: %d, len: %d", position, limit, 1), e); + } + } + + @Override + public final void write(byte[] value, int offset, int length) throws IOException { + try { + System.arraycopy(value, offset, buffer, position, length); + position += length; + } catch (IndexOutOfBoundsException e) { + throw new OutOfSpaceException( + String.format("Pos: %d, limit: %d, len: %d", position, limit, length), e); + } + } + + @Override + public final void writeLazy(byte[] value, int offset, int length) throws IOException { + write(value, offset, length); + } + + @Override + public final void write(ByteBuffer value) throws IOException { + final int length = value.remaining(); + try { + value.get(buffer, position, length); + position += length; + } catch (IndexOutOfBoundsException e) { + throw new OutOfSpaceException( + String.format("Pos: %d, limit: %d, len: %d", position, limit, length), e); + } + } + + @Override + public final void writeLazy(ByteBuffer value) throws IOException { + write(value); + } + + @Override + public final void writeStringNoTag(String value) throws IOException { + final int oldPosition = position; + try { + // UTF-8 byte length of the string is at least its UTF-16 code unit length (value.length()), + // and at most 3 times of it. We take advantage of this in both branches below. + final int maxLength = value.length() * Utf8.MAX_BYTES_PER_CHAR; + final int maxLengthVarIntSize = computeUInt32SizeNoTag(maxLength); + final int minLengthVarIntSize = computeUInt32SizeNoTag(value.length()); + if (minLengthVarIntSize == maxLengthVarIntSize) { + position = oldPosition + minLengthVarIntSize; + int newPosition = Utf8.encode(value, buffer, position, spaceLeft()); + // Since this class is stateful and tracks the position, we rewind and store the state, + // prepend the length, then reset it back to the end of the string. + position = oldPosition; + int length = newPosition - oldPosition - minLengthVarIntSize; + writeUInt32NoTag(length); + position = newPosition; + } else { + int length = Utf8.encodedLength(value); + writeUInt32NoTag(length); + position = Utf8.encode(value, buffer, position, spaceLeft()); + } + } catch (Utf8.UnpairedSurrogateException e) { + // Roll back the change - we fall back to inefficient path. + position = oldPosition; + + // TODO: We should throw an IOException here instead. + inefficientWriteStringNoTag(value, e); + } catch (IndexOutOfBoundsException e) { + throw new OutOfSpaceException(e); + } + } + + @Override + public void flush() { + // Do nothing. + } + + @Override + public final int spaceLeft() { + return limit - position; + } + + @Override + public final int getTotalBytesWritten() { + return position - offset; + } +} \ No newline at end of file diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/ByteOutputEncoder.java b/protobuf-sdk/src/main/java/com/google/protobuf/ByteOutputEncoder.java new file mode 100644 index 0000000..060d095 --- /dev/null +++ b/protobuf-sdk/src/main/java/com/google/protobuf/ByteOutputEncoder.java @@ -0,0 +1,322 @@ +package com.google.protobuf; + +import java.io.IOException; +import java.nio.ByteBuffer; + +import static com.google.protobuf.WireFormat.*; +import static com.google.protobuf.WireFormat.FIXED64_SIZE; + +/** + * A {@link CodedOutputStream} that decorates a {@link ByteOutput}. It internal buffer only to + * support string encoding operations. All other writes are just passed through to the {@link + * ByteOutput}. + */ +final class ByteOutputEncoder extends AbstractBufferedEncoder { + private final ByteOutput out; + + ByteOutputEncoder(ByteOutput out, int bufferSize) { + super(bufferSize); + if (out == null) { + throw new NullPointerException("out"); + } + this.out = out; + } + + @Override + public void writeTag(final int fieldNumber, final int wireType) throws IOException { + writeUInt32NoTag(WireFormat.makeTag(fieldNumber, wireType)); + } + + @Override + public void writeInt32(final int fieldNumber, final int value) throws IOException { + flushIfNotAvailable(MAX_VARINT_SIZE * 2); + bufferTag(fieldNumber, WireFormat.WIRETYPE_VARINT); + bufferInt32NoTag(value); + } + + @Override + public void writeUInt32(final int fieldNumber, final int value) throws IOException { + flushIfNotAvailable(MAX_VARINT_SIZE * 2); + bufferTag(fieldNumber, WireFormat.WIRETYPE_VARINT); + bufferUInt32NoTag(value); + } + + @Override + public void writeFixed32(final int fieldNumber, final int value) throws IOException { + flushIfNotAvailable(MAX_VARINT_SIZE + FIXED32_SIZE); + bufferTag(fieldNumber, WireFormat.WIRETYPE_FIXED32); + bufferFixed32NoTag(value); + } + + @Override + public void writeUInt64(final int fieldNumber, final long value) throws IOException { + flushIfNotAvailable(MAX_VARINT_SIZE * 2); + bufferTag(fieldNumber, WireFormat.WIRETYPE_VARINT); + bufferUInt64NoTag(value); + } + + @Override + public void writeFixed64(final int fieldNumber, final long value) throws IOException { + flushIfNotAvailable(MAX_VARINT_SIZE + FIXED64_SIZE); + bufferTag(fieldNumber, WireFormat.WIRETYPE_FIXED64); + bufferFixed64NoTag(value); + } + + @Override + public void writeBool(final int fieldNumber, final boolean value) throws IOException { + flushIfNotAvailable(MAX_VARINT_SIZE + 1); + bufferTag(fieldNumber, WireFormat.WIRETYPE_VARINT); + buffer((byte) (value ? 1 : 0)); + } + + @Override + public void writeString(final int fieldNumber, final String value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeStringNoTag(value); + } + + @Override + public void writeBytes(final int fieldNumber, final ByteString value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeBytesNoTag(value); + } + + @Override + public void writeByteArray(final int fieldNumber, final byte[] value) throws IOException { + writeByteArray(fieldNumber, value, 0, value.length); + } + + @Override + public void writeByteArray( + final int fieldNumber, final byte[] value, final int offset, final int length) + throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeByteArrayNoTag(value, offset, length); + } + + @Override + public void writeByteBuffer(final int fieldNumber, final ByteBuffer value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeUInt32NoTag(value.capacity()); + writeRawBytes(value); + } + + @Override + public void writeBytesNoTag(final ByteString value) throws IOException { + writeUInt32NoTag(value.size()); + value.writeTo(this); + } + + @Override + public void writeByteArrayNoTag(final byte[] value, int offset, int length) throws IOException { + writeUInt32NoTag(length); + write(value, offset, length); + } + + @Override + public void writeRawBytes(final ByteBuffer value) throws IOException { + if (value.hasArray()) { + write(value.array(), value.arrayOffset(), value.capacity()); + } else { + ByteBuffer duplicated = value.duplicate(); + Java8Compatibility.clear(duplicated); + write(duplicated); + } + } + + @Override + public void writeMessage(final int fieldNumber, final MessageLite value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeMessageNoTag(value); + } + + @Override + void writeMessage(final int fieldNumber, final MessageLite value, Schema schema) + throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeMessageNoTag(value, schema); + } + + @Override + public void writeMessageSetExtension(final int fieldNumber, final MessageLite value) + throws IOException { + writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_START_GROUP); + writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber); + writeMessage(WireFormat.MESSAGE_SET_MESSAGE, value); + writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP); + } + + @Override + public void writeRawMessageSetExtension(final int fieldNumber, final ByteString value) + throws IOException { + writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_START_GROUP); + writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber); + writeBytes(WireFormat.MESSAGE_SET_MESSAGE, value); + writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP); + } + + @Override + public void writeMessageNoTag(final MessageLite value) throws IOException { + writeUInt32NoTag(value.getSerializedSize()); + value.writeTo(this); + } + + @Override + void writeMessageNoTag(final MessageLite value, Schema schema) throws IOException { + writeUInt32NoTag(((AbstractMessageLite) value).getSerializedSize(schema)); + schema.writeTo(value, wrapper); + } + + @Override + public void write(byte value) throws IOException { + if (position == limit) { + doFlush(); + } + + buffer(value); + } + + @Override + public void writeInt32NoTag(int value) throws IOException { + if (value >= 0) { + writeUInt32NoTag(value); + } else { + // Must sign-extend. + writeUInt64NoTag(value); + } + } + + @Override + public void writeUInt32NoTag(int value) throws IOException { + flushIfNotAvailable(MAX_VARINT32_SIZE); + bufferUInt32NoTag(value); + } + + @Override + public void writeFixed32NoTag(final int value) throws IOException { + flushIfNotAvailable(FIXED32_SIZE); + bufferFixed32NoTag(value); + } + + @Override + public void writeUInt64NoTag(long value) throws IOException { + flushIfNotAvailable(MAX_VARINT_SIZE); + bufferUInt64NoTag(value); + } + + @Override + public void writeFixed64NoTag(final long value) throws IOException { + flushIfNotAvailable(FIXED64_SIZE); + bufferFixed64NoTag(value); + } + + @Override + public void writeStringNoTag(String value) throws IOException { + // UTF-8 byte length of the string is at least its UTF-16 code unit length (value.length()), + // and at most 3 times of it. We take advantage of this in both branches below. + final int maxLength = value.length() * Utf8.MAX_BYTES_PER_CHAR; + final int maxLengthVarIntSize = computeUInt32SizeNoTag(maxLength); + + // If we are streaming and the potential length is too big to fit in our buffer, we take the + // slower path. + if (maxLengthVarIntSize + maxLength > limit) { + // Allocate a byte[] that we know can fit the string and encode into it. String.getBytes() + // does the same internally and then does *another copy* to return a byte[] of exactly the + // right size. We can skip that copy and just writeRawBytes up to the actualLength of the + // UTF-8 encoded bytes. + final byte[] encodedBytes = new byte[maxLength]; + int actualLength = Utf8.encode(value, encodedBytes, 0, maxLength); + writeUInt32NoTag(actualLength); + writeLazy(encodedBytes, 0, actualLength); + return; + } + + // Fast path: we have enough space available in our buffer for the string... + if (maxLengthVarIntSize + maxLength > limit - position) { + // Flush to free up space. + doFlush(); + } + + final int oldPosition = position; + try { + // Optimize for the case where we know this length results in a constant varint length as + // this saves a pass for measuring the length of the string. + final int minLengthVarIntSize = computeUInt32SizeNoTag(value.length()); + + if (minLengthVarIntSize == maxLengthVarIntSize) { + position = oldPosition + minLengthVarIntSize; + int newPosition = Utf8.encode(value, buffer, position, limit - position); + // Since this class is stateful and tracks the position, we rewind and store the state, + // prepend the length, then reset it back to the end of the string. + position = oldPosition; + int length = newPosition - oldPosition - minLengthVarIntSize; + bufferUInt32NoTag(length); + position = newPosition; + totalBytesWritten += length; + } else { + int length = Utf8.encodedLength(value); + bufferUInt32NoTag(length); + position = Utf8.encode(value, buffer, position, length); + totalBytesWritten += length; + } + } catch (Utf8.UnpairedSurrogateException e) { + // Roll back the change and convert to an IOException. + totalBytesWritten -= position - oldPosition; + position = oldPosition; + + // TODO: We should throw an IOException here instead. + inefficientWriteStringNoTag(value, e); + } catch (IndexOutOfBoundsException e) { + throw new OutOfSpaceException(e); + } + } + + @Override + public void flush() throws IOException { + if (position > 0) { + // Flush the buffer. + doFlush(); + } + } + + @Override + public void write(byte[] value, int offset, int length) throws IOException { + flush(); + out.write(value, offset, length); + totalBytesWritten += length; + } + + @Override + public void writeLazy(byte[] value, int offset, int length) throws IOException { + flush(); + out.writeLazy(value, offset, length); + totalBytesWritten += length; + } + + @Override + public void write(ByteBuffer value) throws IOException { + flush(); + int length = value.remaining(); + out.write(value); + totalBytesWritten += length; + } + + @Override + public void writeLazy(ByteBuffer value) throws IOException { + flush(); + int length = value.remaining(); + out.writeLazy(value); + totalBytesWritten += length; + } + + private void flushIfNotAvailable(int requiredSize) throws IOException { + if (limit - position < requiredSize) { + doFlush(); + } + } + + private void doFlush() throws IOException { + out.write(buffer, 0, position); + position = 0; + } +} \ No newline at end of file diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/HeapNioEncoder.java b/protobuf-sdk/src/main/java/com/google/protobuf/HeapNioEncoder.java new file mode 100644 index 0000000..0c0bdd0 --- /dev/null +++ b/protobuf-sdk/src/main/java/com/google/protobuf/HeapNioEncoder.java @@ -0,0 +1,27 @@ +package com.google.protobuf; + +import java.nio.ByteBuffer; + +/** + * A {@link CodedOutputStream} that writes directly to a heap {@link ByteBuffer}. Writes are done + * directly to the underlying array. The buffer position is only updated after a flush. + */ +final class HeapNioEncoder extends ArrayEncoder { + private final ByteBuffer byteBuffer; + private int initialPosition; + + HeapNioEncoder(ByteBuffer byteBuffer) { + super( + byteBuffer.array(), + byteBuffer.arrayOffset() + byteBuffer.position(), + byteBuffer.remaining()); + this.byteBuffer = byteBuffer; + this.initialPosition = byteBuffer.position(); + } + + @Override + public void flush() { + // Update the position on the buffer. + Java8Compatibility.position(byteBuffer, initialPosition + getTotalBytesWritten()); + } +} \ No newline at end of file diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/OutputStreamEncoder.java b/protobuf-sdk/src/main/java/com/google/protobuf/OutputStreamEncoder.java new file mode 100644 index 0000000..04e6c04 --- /dev/null +++ b/protobuf-sdk/src/main/java/com/google/protobuf/OutputStreamEncoder.java @@ -0,0 +1,371 @@ +package com.google.protobuf; + +import java.io.IOException; +import java.io.OutputStream; +import java.nio.ByteBuffer; + +import static com.google.protobuf.WireFormat.*; +import static com.google.protobuf.WireFormat.FIXED64_SIZE; + +/** + * An {@link CodedOutputStream} that decorates an {@link OutputStream}. It performs internal + * buffering to optimize writes to the {@link OutputStream}. + */ +final class OutputStreamEncoder extends AbstractBufferedEncoder { + private final OutputStream out; + + OutputStreamEncoder(OutputStream out, int bufferSize) { + super(bufferSize); + if (out == null) { + throw new NullPointerException("out"); + } + this.out = out; + } + + @Override + public void writeTag(final int fieldNumber, final int wireType) throws IOException { + writeUInt32NoTag(WireFormat.makeTag(fieldNumber, wireType)); + } + + @Override + public void writeInt32(final int fieldNumber, final int value) throws IOException { + flushIfNotAvailable(MAX_VARINT_SIZE * 2); + bufferTag(fieldNumber, WireFormat.WIRETYPE_VARINT); + bufferInt32NoTag(value); + } + + @Override + public void writeUInt32(final int fieldNumber, final int value) throws IOException { + flushIfNotAvailable(MAX_VARINT_SIZE * 2); + bufferTag(fieldNumber, WireFormat.WIRETYPE_VARINT); + bufferUInt32NoTag(value); + } + + @Override + public void writeFixed32(final int fieldNumber, final int value) throws IOException { + flushIfNotAvailable(MAX_VARINT_SIZE + FIXED32_SIZE); + bufferTag(fieldNumber, WireFormat.WIRETYPE_FIXED32); + bufferFixed32NoTag(value); + } + + @Override + public void writeUInt64(final int fieldNumber, final long value) throws IOException { + flushIfNotAvailable(MAX_VARINT_SIZE * 2); + bufferTag(fieldNumber, WireFormat.WIRETYPE_VARINT); + bufferUInt64NoTag(value); + } + + @Override + public void writeFixed64(final int fieldNumber, final long value) throws IOException { + flushIfNotAvailable(MAX_VARINT_SIZE + FIXED64_SIZE); + bufferTag(fieldNumber, WireFormat.WIRETYPE_FIXED64); + bufferFixed64NoTag(value); + } + + @Override + public void writeBool(final int fieldNumber, final boolean value) throws IOException { + flushIfNotAvailable(MAX_VARINT_SIZE + 1); + bufferTag(fieldNumber, WireFormat.WIRETYPE_VARINT); + buffer((byte) (value ? 1 : 0)); + } + + @Override + public void writeString(final int fieldNumber, final String value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeStringNoTag(value); + } + + @Override + public void writeBytes(final int fieldNumber, final ByteString value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeBytesNoTag(value); + } + + @Override + public void writeByteArray(final int fieldNumber, final byte[] value) throws IOException { + writeByteArray(fieldNumber, value, 0, value.length); + } + + @Override + public void writeByteArray( + final int fieldNumber, final byte[] value, final int offset, final int length) + throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeByteArrayNoTag(value, offset, length); + } + + @Override + public void writeByteBuffer(final int fieldNumber, final ByteBuffer value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeUInt32NoTag(value.capacity()); + writeRawBytes(value); + } + + @Override + public void writeBytesNoTag(final ByteString value) throws IOException { + writeUInt32NoTag(value.size()); + value.writeTo(this); + } + + @Override + public void writeByteArrayNoTag(final byte[] value, int offset, int length) throws IOException { + writeUInt32NoTag(length); + write(value, offset, length); + } + + @Override + public void writeRawBytes(final ByteBuffer value) throws IOException { + if (value.hasArray()) { + write(value.array(), value.arrayOffset(), value.capacity()); + } else { + ByteBuffer duplicated = value.duplicate(); + Java8Compatibility.clear(duplicated); + write(duplicated); + } + } + + @Override + public void writeMessage(final int fieldNumber, final MessageLite value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeMessageNoTag(value); + } + + @Override + void writeMessage(final int fieldNumber, final MessageLite value, Schema schema) + throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeMessageNoTag(value, schema); + } + + @Override + public void writeMessageSetExtension(final int fieldNumber, final MessageLite value) + throws IOException { + writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_START_GROUP); + writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber); + writeMessage(WireFormat.MESSAGE_SET_MESSAGE, value); + writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP); + } + + @Override + public void writeRawMessageSetExtension(final int fieldNumber, final ByteString value) + throws IOException { + writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_START_GROUP); + writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber); + writeBytes(WireFormat.MESSAGE_SET_MESSAGE, value); + writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP); + } + + @Override + public void writeMessageNoTag(final MessageLite value) throws IOException { + writeUInt32NoTag(value.getSerializedSize()); + value.writeTo(this); + } + + @Override + void writeMessageNoTag(final MessageLite value, Schema schema) throws IOException { + writeUInt32NoTag(((AbstractMessageLite) value).getSerializedSize(schema)); + schema.writeTo(value, wrapper); + } + + @Override + public void write(byte value) throws IOException { + if (position == limit) { + doFlush(); + } + + buffer(value); + } + + @Override + public void writeInt32NoTag(int value) throws IOException { + if (value >= 0) { + writeUInt32NoTag(value); + } else { + // Must sign-extend. + writeUInt64NoTag(value); + } + } + + @Override + public void writeUInt32NoTag(int value) throws IOException { + flushIfNotAvailable(MAX_VARINT32_SIZE); + bufferUInt32NoTag(value); + } + + @Override + public void writeFixed32NoTag(final int value) throws IOException { + flushIfNotAvailable(FIXED32_SIZE); + bufferFixed32NoTag(value); + } + + @Override + public void writeUInt64NoTag(long value) throws IOException { + flushIfNotAvailable(MAX_VARINT_SIZE); + bufferUInt64NoTag(value); + } + + @Override + public void writeFixed64NoTag(final long value) throws IOException { + flushIfNotAvailable(FIXED64_SIZE); + bufferFixed64NoTag(value); + } + + @Override + public void writeStringNoTag(String value) throws IOException { + try { + // UTF-8 byte length of the string is at least its UTF-16 code unit length (value.length()), + // and at most 3 times of it. We take advantage of this in both branches below. + final int maxLength = value.length() * Utf8.MAX_BYTES_PER_CHAR; + final int maxLengthVarIntSize = computeUInt32SizeNoTag(maxLength); + + // If we are streaming and the potential length is too big to fit in our buffer, we take the + // slower path. + if (maxLengthVarIntSize + maxLength > limit) { + // Allocate a byte[] that we know can fit the string and encode into it. String.getBytes() + // does the same internally and then does *another copy* to return a byte[] of exactly the + // right size. We can skip that copy and just writeRawBytes up to the actualLength of the + // UTF-8 encoded bytes. + final byte[] encodedBytes = new byte[maxLength]; + int actualLength = Utf8.encode(value, encodedBytes, 0, maxLength); + writeUInt32NoTag(actualLength); + writeLazy(encodedBytes, 0, actualLength); + return; + } + + // Fast path: we have enough space available in our buffer for the string... + if (maxLengthVarIntSize + maxLength > limit - position) { + // Flush to free up space. + doFlush(); + } + + // Optimize for the case where we know this length results in a constant varint length as + // this saves a pass for measuring the length of the string. + final int minLengthVarIntSize = computeUInt32SizeNoTag(value.length()); + int oldPosition = position; + final int length; + try { + if (minLengthVarIntSize == maxLengthVarIntSize) { + position = oldPosition + minLengthVarIntSize; + int newPosition = Utf8.encode(value, buffer, position, limit - position); + // Since this class is stateful and tracks the position, we rewind and store the + // state, prepend the length, then reset it back to the end of the string. + position = oldPosition; + length = newPosition - oldPosition - minLengthVarIntSize; + bufferUInt32NoTag(length); + position = newPosition; + } else { + length = Utf8.encodedLength(value); + bufferUInt32NoTag(length); + position = Utf8.encode(value, buffer, position, length); + } + totalBytesWritten += length; + } catch (Utf8.UnpairedSurrogateException e) { + // Be extra careful and restore the original position for retrying the write with the + // less efficient path. + totalBytesWritten -= position - oldPosition; + position = oldPosition; + throw e; + } catch (ArrayIndexOutOfBoundsException e) { + throw new OutOfSpaceException(e); + } + } catch (Utf8.UnpairedSurrogateException e) { + inefficientWriteStringNoTag(value, e); + } + } + + @Override + public void flush() throws IOException { + if (position > 0) { + // Flush the buffer. + doFlush(); + } + } + + @Override + public void write(byte[] value, int offset, int length) throws IOException { + if (limit - position >= length) { + // We have room in the current buffer. + System.arraycopy(value, offset, buffer, position, length); + position += length; + totalBytesWritten += length; + } else { + // Write extends past current buffer. Fill the rest of this buffer and + // flush. + final int bytesWritten = limit - position; + System.arraycopy(value, offset, buffer, position, bytesWritten); + offset += bytesWritten; + length -= bytesWritten; + position = limit; + totalBytesWritten += bytesWritten; + doFlush(); + + // Now deal with the rest. + // Since we have an output stream, this is our buffer + // and buffer offset == 0 + if (length <= limit) { + // Fits in new buffer. + System.arraycopy(value, offset, buffer, 0, length); + position = length; + } else { + // Write is very big. Let's do it all at once. + out.write(value, offset, length); + } + totalBytesWritten += length; + } + } + + @Override + public void writeLazy(byte[] value, int offset, int length) throws IOException { + write(value, offset, length); + } + + @Override + public void write(ByteBuffer value) throws IOException { + int length = value.remaining(); + if (limit - position >= length) { + // We have room in the current buffer. + value.get(buffer, position, length); + position += length; + totalBytesWritten += length; + } else { + // Write extends past current buffer. Fill the rest of this buffer and + // flush. + final int bytesWritten = limit - position; + value.get(buffer, position, bytesWritten); + length -= bytesWritten; + position = limit; + totalBytesWritten += bytesWritten; + doFlush(); + + // Now deal with the rest. + // Since we have an output stream, this is our buffer + // and buffer offset == 0 + while (length > limit) { + // Copy data into the buffer before writing it to OutputStream. + value.get(buffer, 0, limit); + out.write(buffer, 0, limit); + length -= limit; + totalBytesWritten += limit; + } + value.get(buffer, 0, length); + position = length; + totalBytesWritten += length; + } + } + + @Override + public void writeLazy(ByteBuffer value) throws IOException { + write(value); + } + + private void flushIfNotAvailable(int requiredSize) throws IOException { + if (limit - position < requiredSize) { + doFlush(); + } + } + + private void doFlush() throws IOException { + out.write(buffer, 0, position); + position = 0; + } +} \ No newline at end of file diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/SafeDirectNioEncoder.java b/protobuf-sdk/src/main/java/com/google/protobuf/SafeDirectNioEncoder.java new file mode 100644 index 0000000..3b879d0 --- /dev/null +++ b/protobuf-sdk/src/main/java/com/google/protobuf/SafeDirectNioEncoder.java @@ -0,0 +1,328 @@ +package com.google.protobuf; + +import java.io.IOException; +import java.nio.BufferOverflowException; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +/** + * A {@link CodedOutputStream} that writes directly to a direct {@link ByteBuffer}, using only + * safe operations.. + */ +final class SafeDirectNioEncoder extends CodedOutputStream { + private final ByteBuffer originalBuffer; + private final ByteBuffer buffer; + private final int initialPosition; + + SafeDirectNioEncoder(ByteBuffer buffer) { + this.originalBuffer = buffer; + this.buffer = buffer.duplicate().order(ByteOrder.LITTLE_ENDIAN); + initialPosition = buffer.position(); + } + + @Override + public void writeTag(final int fieldNumber, final int wireType) throws IOException { + writeUInt32NoTag(WireFormat.makeTag(fieldNumber, wireType)); + } + + @Override + public void writeInt32(final int fieldNumber, final int value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); + writeInt32NoTag(value); + } + + @Override + public void writeUInt32(final int fieldNumber, final int value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); + writeUInt32NoTag(value); + } + + @Override + public void writeFixed32(final int fieldNumber, final int value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED32); + writeFixed32NoTag(value); + } + + @Override + public void writeUInt64(final int fieldNumber, final long value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); + writeUInt64NoTag(value); + } + + @Override + public void writeFixed64(final int fieldNumber, final long value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED64); + writeFixed64NoTag(value); + } + + @Override + public void writeBool(final int fieldNumber, final boolean value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); + write((byte) (value ? 1 : 0)); + } + + @Override + public void writeString(final int fieldNumber, final String value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeStringNoTag(value); + } + + @Override + public void writeBytes(final int fieldNumber, final ByteString value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeBytesNoTag(value); + } + + @Override + public void writeByteArray(final int fieldNumber, final byte[] value) throws IOException { + writeByteArray(fieldNumber, value, 0, value.length); + } + + @Override + public void writeByteArray( + final int fieldNumber, final byte[] value, final int offset, final int length) + throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeByteArrayNoTag(value, offset, length); + } + + @Override + public void writeByteBuffer(final int fieldNumber, final ByteBuffer value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeUInt32NoTag(value.capacity()); + writeRawBytes(value); + } + + @Override + public void writeMessage(final int fieldNumber, final MessageLite value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeMessageNoTag(value); + } + + @Override + void writeMessage(final int fieldNumber, final MessageLite value, Schema schema) + throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeMessageNoTag(value, schema); + } + + @Override + public void writeMessageSetExtension(final int fieldNumber, final MessageLite value) + throws IOException { + writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_START_GROUP); + writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber); + writeMessage(WireFormat.MESSAGE_SET_MESSAGE, value); + writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP); + } + + @Override + public void writeRawMessageSetExtension(final int fieldNumber, final ByteString value) + throws IOException { + writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_START_GROUP); + writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber); + writeBytes(WireFormat.MESSAGE_SET_MESSAGE, value); + writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP); + } + + @Override + public void writeMessageNoTag(final MessageLite value) throws IOException { + writeUInt32NoTag(value.getSerializedSize()); + value.writeTo(this); + } + + @Override + void writeMessageNoTag(final MessageLite value, Schema schema) throws IOException { + writeUInt32NoTag(((AbstractMessageLite) value).getSerializedSize(schema)); + schema.writeTo(value, wrapper); + } + + @Override + public void write(byte value) throws IOException { + try { + buffer.put(value); + } catch (BufferOverflowException e) { + throw new OutOfSpaceException(e); + } + } + + @Override + public void writeBytesNoTag(final ByteString value) throws IOException { + writeUInt32NoTag(value.size()); + value.writeTo(this); + } + + @Override + public void writeByteArrayNoTag(final byte[] value, int offset, int length) throws IOException { + writeUInt32NoTag(length); + write(value, offset, length); + } + + @Override + public void writeRawBytes(final ByteBuffer value) throws IOException { + if (value.hasArray()) { + write(value.array(), value.arrayOffset(), value.capacity()); + } else { + ByteBuffer duplicated = value.duplicate(); + Java8Compatibility.clear(duplicated); + write(duplicated); + } + } + + @Override + public void writeInt32NoTag(int value) throws IOException { + if (value >= 0) { + writeUInt32NoTag(value); + } else { + // Must sign-extend. + writeUInt64NoTag(value); + } + } + + @Override + public void writeUInt32NoTag(int value) throws IOException { + try { + while (true) { + if ((value & ~0x7F) == 0) { + buffer.put((byte) value); + return; + } else { + buffer.put((byte) ((value & 0x7F) | 0x80)); + value >>>= 7; + } + } + } catch (BufferOverflowException e) { + throw new OutOfSpaceException(e); + } + } + + @Override + public void writeFixed32NoTag(int value) throws IOException { + try { + buffer.putInt(value); + } catch (BufferOverflowException e) { + throw new OutOfSpaceException(e); + } + } + + @Override + public void writeUInt64NoTag(long value) throws IOException { + try { + while (true) { + if ((value & ~0x7FL) == 0) { + buffer.put((byte) value); + return; + } else { + buffer.put((byte) (((int) value & 0x7F) | 0x80)); + value >>>= 7; + } + } + } catch (BufferOverflowException e) { + throw new OutOfSpaceException(e); + } + } + + @Override + public void writeFixed64NoTag(long value) throws IOException { + try { + buffer.putLong(value); + } catch (BufferOverflowException e) { + throw new OutOfSpaceException(e); + } + } + + @Override + public void write(byte[] value, int offset, int length) throws IOException { + try { + buffer.put(value, offset, length); + } catch (IndexOutOfBoundsException e) { + throw new OutOfSpaceException(e); + } catch (BufferOverflowException e) { + throw new OutOfSpaceException(e); + } + } + + @Override + public void writeLazy(byte[] value, int offset, int length) throws IOException { + write(value, offset, length); + } + + @Override + public void write(ByteBuffer value) throws IOException { + try { + buffer.put(value); + } catch (BufferOverflowException e) { + throw new OutOfSpaceException(e); + } + } + + @Override + public void writeLazy(ByteBuffer value) throws IOException { + write(value); + } + + @Override + public void writeStringNoTag(String value) throws IOException { + final int startPos = buffer.position(); + try { + // UTF-8 byte length of the string is at least its UTF-16 code unit length (value.length()), + // and at most 3 times of it. We take advantage of this in both branches below. + final int maxEncodedSize = value.length() * Utf8.MAX_BYTES_PER_CHAR; + final int maxLengthVarIntSize = computeUInt32SizeNoTag(maxEncodedSize); + final int minLengthVarIntSize = computeUInt32SizeNoTag(value.length()); + if (minLengthVarIntSize == maxLengthVarIntSize) { + // Save the current position and increment past the length field. We'll come back + // and write the length field after the encoding is complete. + final int startOfBytes = buffer.position() + minLengthVarIntSize; + Java8Compatibility.position(buffer, startOfBytes); + + // Encode the string. + encode(value); + + // Now go back to the beginning and write the length. + int endOfBytes = buffer.position(); + Java8Compatibility.position(buffer, startPos); + writeUInt32NoTag(endOfBytes - startOfBytes); + + // Reposition the buffer past the written data. + Java8Compatibility.position(buffer, endOfBytes); + } else { + final int length = Utf8.encodedLength(value); + writeUInt32NoTag(length); + encode(value); + } + } catch (Utf8.UnpairedSurrogateException e) { + // Roll back the change and convert to an IOException. + Java8Compatibility.position(buffer, startPos); + + // TODO: We should throw an IOException here instead. + inefficientWriteStringNoTag(value, e); + } catch (IllegalArgumentException e) { + // Thrown by buffer.position() if out of range. + throw new OutOfSpaceException(e); + } + } + + @Override + public void flush() { + // Update the position of the original buffer. + Java8Compatibility.position(originalBuffer, buffer.position()); + } + + @Override + public int spaceLeft() { + return buffer.remaining(); + } + + @Override + public int getTotalBytesWritten() { + return buffer.position() - initialPosition; + } + + private void encode(String value) throws IOException { + try { + Utf8.encodeUtf8(value, buffer); + } catch (IndexOutOfBoundsException e) { + throw new OutOfSpaceException(e); + } + } +} \ No newline at end of file diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/UnsafeDirectNioEncoder.java b/protobuf-sdk/src/main/java/com/google/protobuf/UnsafeDirectNioEncoder.java new file mode 100644 index 0000000..07ef277 --- /dev/null +++ b/protobuf-sdk/src/main/java/com/google/protobuf/UnsafeDirectNioEncoder.java @@ -0,0 +1,369 @@ +package com.google.protobuf; + +import java.io.IOException; +import java.nio.BufferOverflowException; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +import static com.google.protobuf.WireFormat.*; + +/** + * A {@link CodedOutputStream} that writes directly to a direct {@link ByteBuffer} using {@code + * sun.misc.Unsafe}. + */ +final class UnsafeDirectNioEncoder extends CodedOutputStream { + private final ByteBuffer originalBuffer; + private final ByteBuffer buffer; + private final long address; + private final long initialPosition; + private final long limit; + private final long oneVarintLimit; + private long position; + + UnsafeDirectNioEncoder(ByteBuffer buffer) { + this.originalBuffer = buffer; + this.buffer = buffer.duplicate().order(ByteOrder.LITTLE_ENDIAN); + address = UnsafeUtil.addressOffset(buffer); + initialPosition = address + buffer.position(); + limit = address + buffer.limit(); + oneVarintLimit = limit - MAX_VARINT_SIZE; + position = initialPosition; + } + + static boolean isSupported() { + return UnsafeUtil.hasUnsafeByteBufferOperations(); + } + + @Override + public void writeTag(int fieldNumber, int wireType) throws IOException { + writeUInt32NoTag(WireFormat.makeTag(fieldNumber, wireType)); + } + + @Override + public void writeInt32(int fieldNumber, int value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); + writeInt32NoTag(value); + } + + @Override + public void writeUInt32(int fieldNumber, int value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); + writeUInt32NoTag(value); + } + + @Override + public void writeFixed32(int fieldNumber, int value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED32); + writeFixed32NoTag(value); + } + + @Override + public void writeUInt64(int fieldNumber, long value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); + writeUInt64NoTag(value); + } + + @Override + public void writeFixed64(int fieldNumber, long value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED64); + writeFixed64NoTag(value); + } + + @Override + public void writeBool(int fieldNumber, boolean value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); + write((byte) (value ? 1 : 0)); + } + + @Override + public void writeString(int fieldNumber, String value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeStringNoTag(value); + } + + @Override + public void writeBytes(int fieldNumber, ByteString value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeBytesNoTag(value); + } + + @Override + public void writeByteArray(int fieldNumber, byte[] value) throws IOException { + writeByteArray(fieldNumber, value, 0, value.length); + } + + @Override + public void writeByteArray(int fieldNumber, byte[] value, int offset, int length) + throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeByteArrayNoTag(value, offset, length); + } + + @Override + public void writeByteBuffer(int fieldNumber, ByteBuffer value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeUInt32NoTag(value.capacity()); + writeRawBytes(value); + } + + @Override + public void writeMessage(int fieldNumber, MessageLite value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeMessageNoTag(value); + } + + @Override + void writeMessage(int fieldNumber, MessageLite value, Schema schema) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeMessageNoTag(value, schema); + } + + @Override + public void writeMessageSetExtension(int fieldNumber, MessageLite value) throws IOException { + writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_START_GROUP); + writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber); + writeMessage(WireFormat.MESSAGE_SET_MESSAGE, value); + writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP); + } + + @Override + public void writeRawMessageSetExtension(int fieldNumber, ByteString value) throws IOException { + writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_START_GROUP); + writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber); + writeBytes(WireFormat.MESSAGE_SET_MESSAGE, value); + writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP); + } + + @Override + public void writeMessageNoTag(MessageLite value) throws IOException { + writeUInt32NoTag(value.getSerializedSize()); + value.writeTo(this); + } + + @Override + void writeMessageNoTag(MessageLite value, Schema schema) throws IOException { + writeUInt32NoTag(((AbstractMessageLite) value).getSerializedSize(schema)); + schema.writeTo(value, wrapper); + } + + @Override + public void write(byte value) throws IOException { + if (position >= limit) { + throw new OutOfSpaceException( + String.format("Pos: %d, limit: %d, len: %d", position, limit, 1)); + } + UnsafeUtil.putByte(position++, value); + } + + @Override + public void writeBytesNoTag(ByteString value) throws IOException { + writeUInt32NoTag(value.size()); + value.writeTo(this); + } + + @Override + public void writeByteArrayNoTag(byte[] value, int offset, int length) throws IOException { + writeUInt32NoTag(length); + write(value, offset, length); + } + + @Override + public void writeRawBytes(ByteBuffer value) throws IOException { + if (value.hasArray()) { + write(value.array(), value.arrayOffset(), value.capacity()); + } else { + ByteBuffer duplicated = value.duplicate(); + Java8Compatibility.clear(duplicated); + write(duplicated); + } + } + + @Override + public void writeInt32NoTag(int value) throws IOException { + if (value >= 0) { + writeUInt32NoTag(value); + } else { + // Must sign-extend. + writeUInt64NoTag(value); + } + } + + @Override + public void writeUInt32NoTag(int value) throws IOException { + if (position <= oneVarintLimit) { + // Optimization to avoid bounds checks on each iteration. + while (true) { + if ((value & ~0x7F) == 0) { + UnsafeUtil.putByte(position++, (byte) value); + return; + } else { + UnsafeUtil.putByte(position++, (byte) ((value & 0x7F) | 0x80)); + value >>>= 7; + } + } + } else { + while (position < limit) { + if ((value & ~0x7F) == 0) { + UnsafeUtil.putByte(position++, (byte) value); + return; + } else { + UnsafeUtil.putByte(position++, (byte) ((value & 0x7F) | 0x80)); + value >>>= 7; + } + } + throw new OutOfSpaceException( + String.format("Pos: %d, limit: %d, len: %d", position, limit, 1)); + } + } + + @Override + public void writeFixed32NoTag(int value) throws IOException { + buffer.putInt(bufferPos(position), value); + position += FIXED32_SIZE; + } + + @Override + public void writeUInt64NoTag(long value) throws IOException { + if (position <= oneVarintLimit) { + // Optimization to avoid bounds checks on each iteration. + while (true) { + if ((value & ~0x7FL) == 0) { + UnsafeUtil.putByte(position++, (byte) value); + return; + } else { + UnsafeUtil.putByte(position++, (byte) (((int) value & 0x7F) | 0x80)); + value >>>= 7; + } + } + } else { + while (position < limit) { + if ((value & ~0x7FL) == 0) { + UnsafeUtil.putByte(position++, (byte) value); + return; + } else { + UnsafeUtil.putByte(position++, (byte) (((int) value & 0x7F) | 0x80)); + value >>>= 7; + } + } + throw new OutOfSpaceException( + String.format("Pos: %d, limit: %d, len: %d", position, limit, 1)); + } + } + + @Override + public void writeFixed64NoTag(long value) throws IOException { + buffer.putLong(bufferPos(position), value); + position += FIXED64_SIZE; + } + + @Override + public void write(byte[] value, int offset, int length) throws IOException { + if (value == null + || offset < 0 + || length < 0 + || (value.length - length) < offset + || (limit - length) < position) { + if (value == null) { + throw new NullPointerException("value"); + } + throw new OutOfSpaceException( + String.format("Pos: %d, limit: %d, len: %d", position, limit, length)); + } + + UnsafeUtil.copyMemory(value, offset, position, length); + position += length; + } + + @Override + public void writeLazy(byte[] value, int offset, int length) throws IOException { + write(value, offset, length); + } + + @Override + public void write(ByteBuffer value) throws IOException { + try { + int length = value.remaining(); + repositionBuffer(position); + buffer.put(value); + position += length; + } catch (BufferOverflowException e) { + throw new OutOfSpaceException(e); + } + } + + @Override + public void writeLazy(ByteBuffer value) throws IOException { + write(value); + } + + @Override + public void writeStringNoTag(String value) throws IOException { + long prevPos = position; + try { + // UTF-8 byte length of the string is at least its UTF-16 code unit length (value.length()), + // and at most 3 times of it. We take advantage of this in both branches below. + int maxEncodedSize = value.length() * Utf8.MAX_BYTES_PER_CHAR; + int maxLengthVarIntSize = computeUInt32SizeNoTag(maxEncodedSize); + int minLengthVarIntSize = computeUInt32SizeNoTag(value.length()); + if (minLengthVarIntSize == maxLengthVarIntSize) { + // Save the current position and increment past the length field. We'll come back + // and write the length field after the encoding is complete. + int stringStart = bufferPos(position) + minLengthVarIntSize; + Java8Compatibility.position(buffer, stringStart); + + // Encode the string. + Utf8.encodeUtf8(value, buffer); + + // Write the length and advance the position. + int length = buffer.position() - stringStart; + writeUInt32NoTag(length); + position += length; + } else { + // Calculate and write the encoded length. + int length = Utf8.encodedLength(value); + writeUInt32NoTag(length); + + // Write the string and advance the position. + repositionBuffer(position); + Utf8.encodeUtf8(value, buffer); + position += length; + } + } catch (Utf8.UnpairedSurrogateException e) { + // Roll back the change and convert to an IOException. + position = prevPos; + repositionBuffer(position); + + // TODO: We should throw an IOException here instead. + inefficientWriteStringNoTag(value, e); + } catch (IllegalArgumentException e) { + // Thrown by buffer.position() if out of range. + throw new OutOfSpaceException(e); + } catch (IndexOutOfBoundsException e) { + throw new OutOfSpaceException(e); + } + } + + @Override + public void flush() { + // Update the position of the original buffer. + Java8Compatibility.position(originalBuffer, bufferPos(position)); + } + + @Override + public int spaceLeft() { + return (int) (limit - position); + } + + @Override + public int getTotalBytesWritten() { + return (int) (position - initialPosition); + } + + private void repositionBuffer(long pos) { + Java8Compatibility.position(buffer, bufferPos(pos)); + } + + private int bufferPos(long pos) { + return (int) (pos - address); + } +} \ No newline at end of file From 2e042b3a21ebb39dbc89a3629112a84ecaaeb468 Mon Sep 17 00:00:00 2001 From: blakeli Date: Mon, 24 Mar 2025 20:54:52 -0400 Subject: [PATCH 04/42] Use getDeclaredConstructors --- .../java/com/google/protobuf/CodedOutputStream.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/protobuf-api/src/main/java/com/google/protobuf/CodedOutputStream.java b/protobuf-api/src/main/java/com/google/protobuf/CodedOutputStream.java index 26b8829..8a31d31 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/CodedOutputStream.java +++ b/protobuf-api/src/main/java/com/google/protobuf/CodedOutputStream.java @@ -92,7 +92,7 @@ public static CodedOutputStream newInstance(final OutputStream output) { */ public static CodedOutputStream newInstance(final OutputStream output, final int bufferSize) { try { - Constructor constructor = OUTPUT_STREAM_ENCODER.getConstructors()[0]; + Constructor constructor = OUTPUT_STREAM_ENCODER.getDeclaredConstructors()[0]; return (CodedOutputStream)constructor.newInstance(output, bufferSize); } catch (InstantiationException e) { throw new RuntimeException(e); @@ -122,7 +122,7 @@ public static CodedOutputStream newInstance(final byte[] flatArray) { public static CodedOutputStream newInstance( final byte[] flatArray, final int offset, final int length) { try { - Constructor constructor = ARRAY_ENCODER.getConstructors()[0]; + Constructor constructor = ARRAY_ENCODER.getDeclaredConstructors()[0]; return (CodedOutputStream)constructor.newInstance(flatArray, offset, length); } catch (InstantiationException e) { throw new RuntimeException(e); @@ -137,7 +137,7 @@ public static CodedOutputStream newInstance( public static CodedOutputStream newInstance(ByteBuffer buffer) { if (buffer.hasArray()) { try { - Constructor constructor = HEAP_NIO_ENCODER.getConstructors()[0]; + Constructor constructor = HEAP_NIO_ENCODER.getDeclaredConstructors()[0]; return (CodedOutputStream)constructor.newInstance(buffer); } catch (InstantiationException e) { throw new RuntimeException(e); @@ -158,7 +158,7 @@ public static CodedOutputStream newInstance(ByteBuffer buffer) { /** For testing purposes only. */ static CodedOutputStream newUnsafeInstance(ByteBuffer buffer) { try { - Constructor constructor = UNSAFE_DIRECT_NIO_ENCODER.getConstructors()[0]; + Constructor constructor = UNSAFE_DIRECT_NIO_ENCODER.getDeclaredConstructors()[0]; return (CodedOutputStream)constructor.newInstance(buffer); } catch (InstantiationException e) { throw new RuntimeException(e); @@ -172,7 +172,7 @@ static CodedOutputStream newUnsafeInstance(ByteBuffer buffer) { /** For testing purposes only. */ static CodedOutputStream newSafeInstance(ByteBuffer buffer) { try { - Constructor constructor = SAFE_DIRECT_NIO_ENCODER.getConstructors()[0]; + Constructor constructor = SAFE_DIRECT_NIO_ENCODER.getDeclaredConstructors()[0]; return (CodedOutputStream)constructor.newInstance(buffer); } catch (InstantiationException e) { throw new RuntimeException(e); @@ -251,7 +251,7 @@ static CodedOutputStream newInstance(ByteOutput byteOutput, int bufferSize) { throw new IllegalArgumentException("bufferSize must be positive"); } try { - Constructor constructor = BYTE_OUTPUT_ENCODER.getConstructors()[0]; + Constructor constructor = BYTE_OUTPUT_ENCODER.getDeclaredConstructors()[0]; return (CodedOutputStream)constructor.newInstance(byteOutput, bufferSize); } catch (InstantiationException e) { throw new RuntimeException(e); From bef8090fa53a265d41a329a23627aea2277a9c6c Mon Sep 17 00:00:00 2001 From: blakeli Date: Fri, 28 Mar 2025 16:53:18 -0400 Subject: [PATCH 05/42] Move implementation of CodedInputStream to SDK package. --- .../com/google/protobuf/CodedInputStream.java | 3388 +---------------- .../google/protobuf/CodedOutputStream.java | 1 - .../com/google/protobuf/ArrayDecoder.java | 672 ++++ .../IterableDirectByteBufferDecoder.java | 835 ++++ .../com/google/protobuf/StreamDecoder.java | 1106 ++++++ .../protobuf/UnsafeDirectNioDecoder.java | 737 ++++ 6 files changed, 3412 insertions(+), 3327 deletions(-) create mode 100644 protobuf-sdk/src/main/java/com/google/protobuf/ArrayDecoder.java create mode 100644 protobuf-sdk/src/main/java/com/google/protobuf/IterableDirectByteBufferDecoder.java create mode 100644 protobuf-sdk/src/main/java/com/google/protobuf/StreamDecoder.java create mode 100644 protobuf-sdk/src/main/java/com/google/protobuf/UnsafeDirectNioDecoder.java diff --git a/protobuf-api/src/main/java/com/google/protobuf/CodedInputStream.java b/protobuf-api/src/main/java/com/google/protobuf/CodedInputStream.java index fd29913..ae4ad1c 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/CodedInputStream.java +++ b/protobuf-api/src/main/java/com/google/protobuf/CodedInputStream.java @@ -8,22 +8,13 @@ package com.google.protobuf; import static com.google.protobuf.Internal.EMPTY_BYTE_ARRAY; -import static com.google.protobuf.Internal.EMPTY_BYTE_BUFFER; -import static com.google.protobuf.Internal.UTF_8; import static com.google.protobuf.Internal.checkNotNull; -import static com.google.protobuf.WireFormat.FIXED32_SIZE; -import static com.google.protobuf.WireFormat.FIXED64_SIZE; -import static com.google.protobuf.WireFormat.MAX_VARINT_SIZE; -import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; -import java.nio.Buffer; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; /** * Reads and decodes protocol message fields. @@ -37,11 +28,24 @@ * @author kenton@google.com Kenton Varda */ public abstract class CodedInputStream { - private static final int DEFAULT_BUFFER_SIZE = 4096; + static final int DEFAULT_BUFFER_SIZE = 4096; // Integer.MAX_VALUE == 0x7FFFFFF == INT_MAX from limits.h private static final int DEFAULT_SIZE_LIMIT = Integer.MAX_VALUE; private static volatile int defaultRecursionLimit = 100; + private static final Class ARRAY_DECODER = getClassForName("com.google.protobuf.ArrayDecoder"); + private static final Class ITERABLE_DIRECT_BYTE_BUFFER_DECODER = getClassForName("com.google.protobuf.IterableDirectByteBufferDecoder"); + private static final Class STREAM_DECODER = getClassForName("com.google.protobuf.StreamDecoder"); + private static final Class UNSAFE_DIRECT_NIO_DECODER = getClassForName("com.google.protobuf.UnsafeDirectNioDecoder"); + + private static Class getClassForName(String name) { + try { + return (Class) Class.forName(name); + } catch (Throwable e) { + return null; + } + } + /** Visible for subclasses. See setRecursionLimit() */ int recursionDepth; @@ -67,12 +71,21 @@ public static CodedInputStream newInstance(final InputStream input, int bufferSi // Ideally we would throw here. This is done for backward compatibility. return newInstance(EMPTY_BYTE_ARRAY); } - return new StreamDecoder(input, bufferSize); + try { + Constructor constructor = STREAM_DECODER.getDeclaredConstructors()[0]; + return (CodedInputStream) constructor.newInstance(input, bufferSize); + } catch (InstantiationException e) { + throw new RuntimeException(e); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } catch (InvocationTargetException e) { + throw new RuntimeException(e); + } } /** Create a new CodedInputStream wrapping the given {@code Iterable }. */ public static CodedInputStream newInstance(final Iterable input) { - if (!UnsafeDirectNioDecoder.isSupported()) { + if (!UnsafeUtil.hasUnsafeByteBufferOperations()) { return newInstance(new IterableByteBufferInputStream(input)); } return newInstance(input, false); @@ -100,7 +113,16 @@ static CodedInputStream newInstance( } } if (flag == 2) { - return new IterableDirectByteBufferDecoder(bufs, totalSize, bufferIsImmutable); + try { + Constructor constructor = ITERABLE_DIRECT_BYTE_BUFFER_DECODER.getDeclaredConstructors()[0]; + return (CodedInputStream) constructor.newInstance(bufs, totalSize, bufferIsImmutable); + } catch (InstantiationException e) { + throw new RuntimeException(e); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } catch (InvocationTargetException e) { + throw new RuntimeException(e); + } } else { // TODO: add another decoders to deal case 1 and 3. return newInstance(new IterableByteBufferInputStream(bufs)); @@ -120,14 +142,24 @@ public static CodedInputStream newInstance(final byte[] buf, final int off, fina /** Create a new CodedInputStream wrapping the given byte array slice. */ static CodedInputStream newInstance( final byte[] buf, final int off, final int len, final boolean bufferIsImmutable) { - ArrayDecoder result = new ArrayDecoder(buf, off, len, bufferIsImmutable); + CodedInputStream arrayDecoder; + try { + Constructor constructor = ARRAY_DECODER.getDeclaredConstructors()[0]; + arrayDecoder = (CodedInputStream) constructor.newInstance(buf, off, len, bufferIsImmutable); + } catch (InstantiationException e) { + throw new RuntimeException(e); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } catch (InvocationTargetException e) { + throw new RuntimeException(e); + } try { // Some uses of CodedInputStream can be more efficient if they know // exactly how many bytes are available. By pushing the end point of the // buffer as a limit, we allow them to get this information via // getBytesUntilLimit(). Pushing a limit that we know is at the end of // the stream can never hurt, since we can never past that point anyway. - result.pushLimit(len); + arrayDecoder.pushLimit(len); } catch (InvalidProtocolBufferException ex) { // The only reason pushLimit() might throw an exception here is if len // is negative. Normally pushLimit()'s parameter comes directly off the @@ -138,7 +170,7 @@ static CodedInputStream newInstance( // appropriate. throw new IllegalArgumentException(ex); } - return result; + return arrayDecoder; } /** @@ -160,8 +192,17 @@ static CodedInputStream newInstance(ByteBuffer buf, boolean bufferIsImmutable) { buf.array(), buf.arrayOffset() + buf.position(), buf.remaining(), bufferIsImmutable); } - if (buf.isDirect() && UnsafeDirectNioDecoder.isSupported()) { - return new UnsafeDirectNioDecoder(buf, bufferIsImmutable); + if (buf.isDirect() && UnsafeUtil.hasUnsafeByteBufferOperations()) { + try { + Constructor constructor = UNSAFE_DIRECT_NIO_DECODER.getDeclaredConstructors()[0]; + return (CodedInputStream) constructor.newInstance(buf, bufferIsImmutable); + } catch (InstantiationException e) { + throw new RuntimeException(e); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } catch (InvocationTargetException e) { + throw new RuntimeException(e); + } } // The buffer is non-direct and does not expose the underlying array. Using the ByteBuffer API @@ -178,7 +219,7 @@ public void checkRecursionLimit() throws InvalidProtocolBufferException { } } /** Disable construction/inheritance outside of this class. */ - private CodedInputStream() {} + CodedInputStream() {} // ----------------------------------------------------------------- @@ -598,3309 +639,4 @@ static int readRawVarint32(final InputStream input) throws IOException { } return readRawVarint32(firstByte, input); } - - /** A {@link CodedInputStream} implementation that uses a backing array as the input. */ - private static final class ArrayDecoder extends CodedInputStream { - private final byte[] buffer; - private final boolean immutable; - private int limit; - private int bufferSizeAfterLimit; - private int pos; - private int startPos; - private int lastTag; - private boolean enableAliasing; - - /** The absolute position of the end of the current message. */ - private int currentLimit = Integer.MAX_VALUE; - - private ArrayDecoder(final byte[] buffer, final int offset, final int len, boolean immutable) { - this.buffer = buffer; - limit = offset + len; - pos = offset; - startPos = pos; - this.immutable = immutable; - } - - @Override - public int readTag() throws IOException { - if (isAtEnd()) { - lastTag = 0; - return 0; - } - - lastTag = readRawVarint32(); - if (WireFormat.getTagFieldNumber(lastTag) == 0) { - // If we actually read zero (or any tag number corresponding to field - // number zero), that's not a valid tag. - throw InvalidProtocolBufferException.invalidTag(); - } - return lastTag; - } - - @Override - public void checkLastTagWas(final int value) throws InvalidProtocolBufferException { - if (lastTag != value) { - throw InvalidProtocolBufferException.invalidEndTag(); - } - } - - @Override - public int getLastTag() { - return lastTag; - } - - @Override - public boolean skipField(final int tag) throws IOException { - switch (WireFormat.getTagWireType(tag)) { - case WireFormat.WIRETYPE_VARINT: - skipRawVarint(); - return true; - case WireFormat.WIRETYPE_FIXED64: - skipRawBytes(FIXED64_SIZE); - return true; - case WireFormat.WIRETYPE_LENGTH_DELIMITED: - skipRawBytes(readRawVarint32()); - return true; - case WireFormat.WIRETYPE_START_GROUP: - skipMessage(); - checkLastTagWas( - WireFormat.makeTag(WireFormat.getTagFieldNumber(tag), WireFormat.WIRETYPE_END_GROUP)); - return true; - case WireFormat.WIRETYPE_END_GROUP: - return false; - case WireFormat.WIRETYPE_FIXED32: - skipRawBytes(FIXED32_SIZE); - return true; - default: - throw InvalidProtocolBufferException.invalidWireType(); - } - } - - @Override - public boolean skipField(final int tag, final CodedOutputStream output) throws IOException { - switch (WireFormat.getTagWireType(tag)) { - case WireFormat.WIRETYPE_VARINT: - { - long value = readInt64(); - output.writeUInt32NoTag(tag); - output.writeUInt64NoTag(value); - return true; - } - case WireFormat.WIRETYPE_FIXED64: - { - long value = readRawLittleEndian64(); - output.writeUInt32NoTag(tag); - output.writeFixed64NoTag(value); - return true; - } - case WireFormat.WIRETYPE_LENGTH_DELIMITED: - { - ByteString value = readBytes(); - output.writeUInt32NoTag(tag); - output.writeBytesNoTag(value); - return true; - } - case WireFormat.WIRETYPE_START_GROUP: - { - output.writeUInt32NoTag(tag); - skipMessage(output); - int endtag = - WireFormat.makeTag( - WireFormat.getTagFieldNumber(tag), WireFormat.WIRETYPE_END_GROUP); - checkLastTagWas(endtag); - output.writeUInt32NoTag(endtag); - return true; - } - case WireFormat.WIRETYPE_END_GROUP: - { - return false; - } - case WireFormat.WIRETYPE_FIXED32: - { - int value = readRawLittleEndian32(); - output.writeUInt32NoTag(tag); - output.writeFixed32NoTag(value); - return true; - } - default: - throw InvalidProtocolBufferException.invalidWireType(); - } - } - - // ----------------------------------------------------------------- - - @Override - public double readDouble() throws IOException { - return Double.longBitsToDouble(readRawLittleEndian64()); - } - - @Override - public float readFloat() throws IOException { - return Float.intBitsToFloat(readRawLittleEndian32()); - } - - @Override - public long readUInt64() throws IOException { - return readRawVarint64(); - } - - @Override - public long readInt64() throws IOException { - return readRawVarint64(); - } - - @Override - public int readInt32() throws IOException { - return readRawVarint32(); - } - - @Override - public long readFixed64() throws IOException { - return readRawLittleEndian64(); - } - - @Override - public int readFixed32() throws IOException { - return readRawLittleEndian32(); - } - - @Override - public boolean readBool() throws IOException { - return readRawVarint64() != 0; - } - - @Override - public String readString() throws IOException { - final int size = readRawVarint32(); - if (size > 0 && size <= (limit - pos)) { - // Fast path: We already have the bytes in a contiguous buffer, so - // just copy directly from it. - final String result = new String(buffer, pos, size, UTF_8); - pos += size; - return result; - } - - if (size == 0) { - return ""; - } - if (size < 0) { - throw InvalidProtocolBufferException.negativeSize(); - } - throw InvalidProtocolBufferException.truncatedMessage(); - } - - @Override - public String readStringRequireUtf8() throws IOException { - final int size = readRawVarint32(); - if (size > 0 && size <= (limit - pos)) { - String result = Utf8.decodeUtf8(buffer, pos, size); - pos += size; - return result; - } - - if (size == 0) { - return ""; - } - if (size <= 0) { - throw InvalidProtocolBufferException.negativeSize(); - } - throw InvalidProtocolBufferException.truncatedMessage(); - } - - @Override - public void readGroup( - final int fieldNumber, - final MessageLite.Builder builder, - final ExtensionRegistryLite extensionRegistry) - throws IOException { - checkRecursionLimit(); - ++recursionDepth; - builder.mergeFrom(this, extensionRegistry); - checkLastTagWas(WireFormat.makeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP)); - --recursionDepth; - } - - @Override - public T readGroup( - final int fieldNumber, - final Parser parser, - final ExtensionRegistryLite extensionRegistry) - throws IOException { - checkRecursionLimit(); - ++recursionDepth; - T result = parser.parsePartialFrom(this, extensionRegistry); - checkLastTagWas(WireFormat.makeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP)); - --recursionDepth; - return result; - } - - @Deprecated - @Override - public void readUnknownGroup(final int fieldNumber, final MessageLite.Builder builder) - throws IOException { - readGroup(fieldNumber, builder, ExtensionRegistryLite.getEmptyRegistry()); - } - - @Override - public void readMessage( - final MessageLite.Builder builder, final ExtensionRegistryLite extensionRegistry) - throws IOException { - final int length = readRawVarint32(); - checkRecursionLimit(); - final int oldLimit = pushLimit(length); - ++recursionDepth; - builder.mergeFrom(this, extensionRegistry); - checkLastTagWas(0); - --recursionDepth; - if (getBytesUntilLimit() != 0) { - throw InvalidProtocolBufferException.truncatedMessage(); - } - popLimit(oldLimit); - } - - @Override - public T readMessage( - final Parser parser, final ExtensionRegistryLite extensionRegistry) throws IOException { - int length = readRawVarint32(); - checkRecursionLimit(); - final int oldLimit = pushLimit(length); - ++recursionDepth; - T result = parser.parsePartialFrom(this, extensionRegistry); - checkLastTagWas(0); - --recursionDepth; - if (getBytesUntilLimit() != 0) { - throw InvalidProtocolBufferException.truncatedMessage(); - } - popLimit(oldLimit); - return result; - } - - @Override - public ByteString readBytes() throws IOException { - final int size = readRawVarint32(); - if (size > 0 && size <= (limit - pos)) { - // Fast path: We already have the bytes in a contiguous buffer, so - // just copy directly from it. - final ByteString result = - immutable && enableAliasing - ? ByteString.wrap(buffer, pos, size) - : ByteString.copyFrom(buffer, pos, size); - pos += size; - return result; - } - if (size == 0) { - return ByteString.EMPTY; - } - // Slow path: Build a byte array first then copy it. - return ByteString.wrap(readRawBytes(size)); - } - - @Override - public byte[] readByteArray() throws IOException { - final int size = readRawVarint32(); - return readRawBytes(size); - } - - @Override - public ByteBuffer readByteBuffer() throws IOException { - final int size = readRawVarint32(); - if (size > 0 && size <= (limit - pos)) { - // Fast path: We already have the bytes in a contiguous buffer. - // When aliasing is enabled, we can return a ByteBuffer pointing directly - // into the underlying byte array without copy if the CodedInputStream is - // constructed from a byte array. If aliasing is disabled or the input is - // from an InputStream or ByteString, we have to make a copy of the bytes. - ByteBuffer result = - !immutable && enableAliasing - ? ByteBuffer.wrap(buffer, pos, size).slice() - : ByteBuffer.wrap(Arrays.copyOfRange(buffer, pos, pos + size)); - pos += size; - // TODO: Investigate making the ByteBuffer be made read-only - return result; - } - - if (size == 0) { - return EMPTY_BYTE_BUFFER; - } - if (size < 0) { - throw InvalidProtocolBufferException.negativeSize(); - } - throw InvalidProtocolBufferException.truncatedMessage(); - } - - @Override - public int readUInt32() throws IOException { - return readRawVarint32(); - } - - @Override - public int readEnum() throws IOException { - return readRawVarint32(); - } - - @Override - public int readSFixed32() throws IOException { - return readRawLittleEndian32(); - } - - @Override - public long readSFixed64() throws IOException { - return readRawLittleEndian64(); - } - - @Override - public int readSInt32() throws IOException { - return decodeZigZag32(readRawVarint32()); - } - - @Override - public long readSInt64() throws IOException { - return decodeZigZag64(readRawVarint64()); - } - - // ================================================================= - - @Override - public int readRawVarint32() throws IOException { - // See implementation notes for readRawVarint64 - fastpath: - { - int tempPos = pos; - - if (limit == tempPos) { - break fastpath; - } - - final byte[] buffer = this.buffer; - int x; - if ((x = buffer[tempPos++]) >= 0) { - pos = tempPos; - return x; - } else if (limit - tempPos < 9) { - break fastpath; - } else if ((x ^= (buffer[tempPos++] << 7)) < 0) { - x ^= (~0 << 7); - } else if ((x ^= (buffer[tempPos++] << 14)) >= 0) { - x ^= (~0 << 7) ^ (~0 << 14); - } else if ((x ^= (buffer[tempPos++] << 21)) < 0) { - x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21); - } else { - int y = buffer[tempPos++]; - x ^= y << 28; - x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21) ^ (~0 << 28); - if (y < 0 - && buffer[tempPos++] < 0 - && buffer[tempPos++] < 0 - && buffer[tempPos++] < 0 - && buffer[tempPos++] < 0 - && buffer[tempPos++] < 0) { - break fastpath; // Will throw malformedVarint() - } - } - pos = tempPos; - return x; - } - return (int) readRawVarint64SlowPath(); - } - - private void skipRawVarint() throws IOException { - if (limit - pos >= MAX_VARINT_SIZE) { - skipRawVarintFastPath(); - } else { - skipRawVarintSlowPath(); - } - } - - private void skipRawVarintFastPath() throws IOException { - for (int i = 0; i < MAX_VARINT_SIZE; i++) { - if (buffer[pos++] >= 0) { - return; - } - } - throw InvalidProtocolBufferException.malformedVarint(); - } - - private void skipRawVarintSlowPath() throws IOException { - for (int i = 0; i < MAX_VARINT_SIZE; i++) { - if (readRawByte() >= 0) { - return; - } - } - throw InvalidProtocolBufferException.malformedVarint(); - } - - @Override - public long readRawVarint64() throws IOException { - // Implementation notes: - // - // Optimized for one-byte values, expected to be common. - // The particular code below was selected from various candidates - // empirically, by winning VarintBenchmark. - // - // Sign extension of (signed) Java bytes is usually a nuisance, but - // we exploit it here to more easily obtain the sign of bytes read. - // Instead of cleaning up the sign extension bits by masking eagerly, - // we delay until we find the final (positive) byte, when we clear all - // accumulated bits with one xor. We depend on javac to constant fold. - fastpath: - { - int tempPos = pos; - - if (limit == tempPos) { - break fastpath; - } - - final byte[] buffer = this.buffer; - long x; - int y; - if ((y = buffer[tempPos++]) >= 0) { - pos = tempPos; - return y; - } else if (limit - tempPos < 9) { - break fastpath; - } else if ((y ^= (buffer[tempPos++] << 7)) < 0) { - x = y ^ (~0 << 7); - } else if ((y ^= (buffer[tempPos++] << 14)) >= 0) { - x = y ^ ((~0 << 7) ^ (~0 << 14)); - } else if ((y ^= (buffer[tempPos++] << 21)) < 0) { - x = y ^ ((~0 << 7) ^ (~0 << 14) ^ (~0 << 21)); - } else if ((x = y ^ ((long) buffer[tempPos++] << 28)) >= 0L) { - x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28); - } else if ((x ^= ((long) buffer[tempPos++] << 35)) < 0L) { - x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35); - } else if ((x ^= ((long) buffer[tempPos++] << 42)) >= 0L) { - x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35) ^ (~0L << 42); - } else if ((x ^= ((long) buffer[tempPos++] << 49)) < 0L) { - x ^= - (~0L << 7) - ^ (~0L << 14) - ^ (~0L << 21) - ^ (~0L << 28) - ^ (~0L << 35) - ^ (~0L << 42) - ^ (~0L << 49); - } else { - x ^= ((long) buffer[tempPos++] << 56); - x ^= - (~0L << 7) - ^ (~0L << 14) - ^ (~0L << 21) - ^ (~0L << 28) - ^ (~0L << 35) - ^ (~0L << 42) - ^ (~0L << 49) - ^ (~0L << 56); - if (x < 0L) { - if (buffer[tempPos++] < 0L) { - break fastpath; // Will throw malformedVarint() - } - } - } - pos = tempPos; - return x; - } - return readRawVarint64SlowPath(); - } - - @Override - long readRawVarint64SlowPath() throws IOException { - long result = 0; - for (int shift = 0; shift < 64; shift += 7) { - final byte b = readRawByte(); - result |= (long) (b & 0x7F) << shift; - if ((b & 0x80) == 0) { - return result; - } - } - throw InvalidProtocolBufferException.malformedVarint(); - } - - @Override - public int readRawLittleEndian32() throws IOException { - int tempPos = pos; - - if (limit - tempPos < FIXED32_SIZE) { - throw InvalidProtocolBufferException.truncatedMessage(); - } - - final byte[] buffer = this.buffer; - pos = tempPos + FIXED32_SIZE; - return ((buffer[tempPos] & 0xff) - | ((buffer[tempPos + 1] & 0xff) << 8) - | ((buffer[tempPos + 2] & 0xff) << 16) - | ((buffer[tempPos + 3] & 0xff) << 24)); - } - - @Override - public long readRawLittleEndian64() throws IOException { - int tempPos = pos; - - if (limit - tempPos < FIXED64_SIZE) { - throw InvalidProtocolBufferException.truncatedMessage(); - } - - final byte[] buffer = this.buffer; - pos = tempPos + FIXED64_SIZE; - return ((buffer[tempPos] & 0xffL) - | ((buffer[tempPos + 1] & 0xffL) << 8) - | ((buffer[tempPos + 2] & 0xffL) << 16) - | ((buffer[tempPos + 3] & 0xffL) << 24) - | ((buffer[tempPos + 4] & 0xffL) << 32) - | ((buffer[tempPos + 5] & 0xffL) << 40) - | ((buffer[tempPos + 6] & 0xffL) << 48) - | ((buffer[tempPos + 7] & 0xffL) << 56)); - } - - @Override - public void enableAliasing(boolean enabled) { - this.enableAliasing = enabled; - } - - @Override - public void resetSizeCounter() { - startPos = pos; - } - - @Override - public int pushLimit(int byteLimit) throws InvalidProtocolBufferException { - if (byteLimit < 0) { - throw InvalidProtocolBufferException.negativeSize(); - } - byteLimit += getTotalBytesRead(); - if (byteLimit < 0) { - throw InvalidProtocolBufferException.parseFailure(); - } - final int oldLimit = currentLimit; - if (byteLimit > oldLimit) { - throw InvalidProtocolBufferException.truncatedMessage(); - } - currentLimit = byteLimit; - - recomputeBufferSizeAfterLimit(); - - return oldLimit; - } - - private void recomputeBufferSizeAfterLimit() { - limit += bufferSizeAfterLimit; - final int bufferEnd = limit - startPos; - if (bufferEnd > currentLimit) { - // Limit is in current buffer. - bufferSizeAfterLimit = bufferEnd - currentLimit; - limit -= bufferSizeAfterLimit; - } else { - bufferSizeAfterLimit = 0; - } - } - - @Override - public void popLimit(final int oldLimit) { - currentLimit = oldLimit; - recomputeBufferSizeAfterLimit(); - } - - @Override - public int getBytesUntilLimit() { - if (currentLimit == Integer.MAX_VALUE) { - return -1; - } - - return currentLimit - getTotalBytesRead(); - } - - @Override - public boolean isAtEnd() throws IOException { - return pos == limit; - } - - @Override - public int getTotalBytesRead() { - return pos - startPos; - } - - @Override - public byte readRawByte() throws IOException { - if (pos == limit) { - throw InvalidProtocolBufferException.truncatedMessage(); - } - return buffer[pos++]; - } - - @Override - public byte[] readRawBytes(final int length) throws IOException { - if (length > 0 && length <= (limit - pos)) { - final int tempPos = pos; - pos += length; - return Arrays.copyOfRange(buffer, tempPos, pos); - } - - if (length <= 0) { - if (length == 0) { - return Internal.EMPTY_BYTE_ARRAY; - } else { - throw InvalidProtocolBufferException.negativeSize(); - } - } - throw InvalidProtocolBufferException.truncatedMessage(); - } - - @Override - public void skipRawBytes(final int length) throws IOException { - if (length >= 0 && length <= (limit - pos)) { - // We have all the bytes we need already. - pos += length; - return; - } - - if (length < 0) { - throw InvalidProtocolBufferException.negativeSize(); - } - throw InvalidProtocolBufferException.truncatedMessage(); - } - } - - /** - * A {@link CodedInputStream} implementation that uses a backing direct ByteBuffer as the input. - * Requires the use of {@code sun.misc.Unsafe} to perform fast reads on the buffer. - */ - private static final class UnsafeDirectNioDecoder extends CodedInputStream { - /** The direct buffer that is backing this stream. */ - private final ByteBuffer buffer; - - /** - * If {@code true}, indicates that the buffer is backing a {@link ByteString} and is therefore - * considered to be an immutable input source. - */ - private final boolean immutable; - - /** The unsafe address of the content of {@link #buffer}. */ - private final long address; - - /** The unsafe address of the current read limit of the buffer. */ - private long limit; - - /** The unsafe address of the current read position of the buffer. */ - private long pos; - - /** The unsafe address of the starting read position. */ - private long startPos; - - /** The amount of available data in the buffer beyond {@link #limit}. */ - private int bufferSizeAfterLimit; - - /** The last tag that was read from this stream. */ - private int lastTag; - - /** - * If {@code true}, indicates that calls to read {@link ByteString} or {@code byte[]} - * may return slices of the underlying buffer, rather than copies. - */ - private boolean enableAliasing; - - /** The absolute position of the end of the current message. */ - private int currentLimit = Integer.MAX_VALUE; - - static boolean isSupported() { - return UnsafeUtil.hasUnsafeByteBufferOperations(); - } - - private UnsafeDirectNioDecoder(ByteBuffer buffer, boolean immutable) { - this.buffer = buffer; - address = UnsafeUtil.addressOffset(buffer); - limit = address + buffer.limit(); - pos = address + buffer.position(); - startPos = pos; - this.immutable = immutable; - } - - @Override - public int readTag() throws IOException { - if (isAtEnd()) { - lastTag = 0; - return 0; - } - - lastTag = readRawVarint32(); - if (WireFormat.getTagFieldNumber(lastTag) == 0) { - // If we actually read zero (or any tag number corresponding to field - // number zero), that's not a valid tag. - throw InvalidProtocolBufferException.invalidTag(); - } - return lastTag; - } - - @Override - public void checkLastTagWas(final int value) throws InvalidProtocolBufferException { - if (lastTag != value) { - throw InvalidProtocolBufferException.invalidEndTag(); - } - } - - @Override - public int getLastTag() { - return lastTag; - } - - @Override - public boolean skipField(final int tag) throws IOException { - switch (WireFormat.getTagWireType(tag)) { - case WireFormat.WIRETYPE_VARINT: - skipRawVarint(); - return true; - case WireFormat.WIRETYPE_FIXED64: - skipRawBytes(FIXED64_SIZE); - return true; - case WireFormat.WIRETYPE_LENGTH_DELIMITED: - skipRawBytes(readRawVarint32()); - return true; - case WireFormat.WIRETYPE_START_GROUP: - skipMessage(); - checkLastTagWas( - WireFormat.makeTag(WireFormat.getTagFieldNumber(tag), WireFormat.WIRETYPE_END_GROUP)); - return true; - case WireFormat.WIRETYPE_END_GROUP: - return false; - case WireFormat.WIRETYPE_FIXED32: - skipRawBytes(FIXED32_SIZE); - return true; - default: - throw InvalidProtocolBufferException.invalidWireType(); - } - } - - @Override - public boolean skipField(final int tag, final CodedOutputStream output) throws IOException { - switch (WireFormat.getTagWireType(tag)) { - case WireFormat.WIRETYPE_VARINT: - { - long value = readInt64(); - output.writeUInt32NoTag(tag); - output.writeUInt64NoTag(value); - return true; - } - case WireFormat.WIRETYPE_FIXED64: - { - long value = readRawLittleEndian64(); - output.writeUInt32NoTag(tag); - output.writeFixed64NoTag(value); - return true; - } - case WireFormat.WIRETYPE_LENGTH_DELIMITED: - { - ByteString value = readBytes(); - output.writeUInt32NoTag(tag); - output.writeBytesNoTag(value); - return true; - } - case WireFormat.WIRETYPE_START_GROUP: - { - output.writeUInt32NoTag(tag); - skipMessage(output); - int endtag = - WireFormat.makeTag( - WireFormat.getTagFieldNumber(tag), WireFormat.WIRETYPE_END_GROUP); - checkLastTagWas(endtag); - output.writeUInt32NoTag(endtag); - return true; - } - case WireFormat.WIRETYPE_END_GROUP: - { - return false; - } - case WireFormat.WIRETYPE_FIXED32: - { - int value = readRawLittleEndian32(); - output.writeUInt32NoTag(tag); - output.writeFixed32NoTag(value); - return true; - } - default: - throw InvalidProtocolBufferException.invalidWireType(); - } - } - - // ----------------------------------------------------------------- - - @Override - public double readDouble() throws IOException { - return Double.longBitsToDouble(readRawLittleEndian64()); - } - - @Override - public float readFloat() throws IOException { - return Float.intBitsToFloat(readRawLittleEndian32()); - } - - @Override - public long readUInt64() throws IOException { - return readRawVarint64(); - } - - @Override - public long readInt64() throws IOException { - return readRawVarint64(); - } - - @Override - public int readInt32() throws IOException { - return readRawVarint32(); - } - - @Override - public long readFixed64() throws IOException { - return readRawLittleEndian64(); - } - - @Override - public int readFixed32() throws IOException { - return readRawLittleEndian32(); - } - - @Override - public boolean readBool() throws IOException { - return readRawVarint64() != 0; - } - - @Override - public String readString() throws IOException { - final int size = readRawVarint32(); - if (size > 0 && size <= remaining()) { - // TODO: Is there a way to avoid this copy? - // TODO: It might be possible to share the optimized loop with - // readStringRequireUtf8 by implementing Java replacement logic there. - // The same as readBytes' logic - byte[] bytes = new byte[size]; - UnsafeUtil.copyMemory(pos, bytes, 0, size); - String result = new String(bytes, UTF_8); - pos += size; - return result; - } - - if (size == 0) { - return ""; - } - if (size < 0) { - throw InvalidProtocolBufferException.negativeSize(); - } - throw InvalidProtocolBufferException.truncatedMessage(); - } - - @Override - public String readStringRequireUtf8() throws IOException { - final int size = readRawVarint32(); - if (size > 0 && size <= remaining()) { - final int bufferPos = bufferPos(pos); - String result = Utf8.decodeUtf8(buffer, bufferPos, size); - pos += size; - return result; - } - - if (size == 0) { - return ""; - } - if (size <= 0) { - throw InvalidProtocolBufferException.negativeSize(); - } - throw InvalidProtocolBufferException.truncatedMessage(); - } - - @Override - public void readGroup( - final int fieldNumber, - final MessageLite.Builder builder, - final ExtensionRegistryLite extensionRegistry) - throws IOException { - checkRecursionLimit(); - ++recursionDepth; - builder.mergeFrom(this, extensionRegistry); - checkLastTagWas(WireFormat.makeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP)); - --recursionDepth; - } - - @Override - public T readGroup( - final int fieldNumber, - final Parser parser, - final ExtensionRegistryLite extensionRegistry) - throws IOException { - checkRecursionLimit(); - ++recursionDepth; - T result = parser.parsePartialFrom(this, extensionRegistry); - checkLastTagWas(WireFormat.makeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP)); - --recursionDepth; - return result; - } - - @Deprecated - @Override - public void readUnknownGroup(final int fieldNumber, final MessageLite.Builder builder) - throws IOException { - readGroup(fieldNumber, builder, ExtensionRegistryLite.getEmptyRegistry()); - } - - @Override - public void readMessage( - final MessageLite.Builder builder, final ExtensionRegistryLite extensionRegistry) - throws IOException { - final int length = readRawVarint32(); - checkRecursionLimit(); - final int oldLimit = pushLimit(length); - ++recursionDepth; - builder.mergeFrom(this, extensionRegistry); - checkLastTagWas(0); - --recursionDepth; - if (getBytesUntilLimit() != 0) { - throw InvalidProtocolBufferException.truncatedMessage(); - } - popLimit(oldLimit); - } - - @Override - public T readMessage( - final Parser parser, final ExtensionRegistryLite extensionRegistry) throws IOException { - int length = readRawVarint32(); - checkRecursionLimit(); - final int oldLimit = pushLimit(length); - ++recursionDepth; - T result = parser.parsePartialFrom(this, extensionRegistry); - checkLastTagWas(0); - --recursionDepth; - if (getBytesUntilLimit() != 0) { - throw InvalidProtocolBufferException.truncatedMessage(); - } - popLimit(oldLimit); - return result; - } - - @Override - public ByteString readBytes() throws IOException { - final int size = readRawVarint32(); - if (size > 0 && size <= remaining()) { - if (immutable && enableAliasing) { - final ByteBuffer result = slice(pos, pos + size); - pos += size; - return ByteString.wrap(result); - } else { - // Use UnsafeUtil to copy the memory to bytes instead of using ByteBuffer ways. - byte[] bytes = new byte[size]; - UnsafeUtil.copyMemory(pos, bytes, 0, size); - pos += size; - return ByteString.wrap(bytes); - } - } - - if (size == 0) { - return ByteString.EMPTY; - } - if (size < 0) { - throw InvalidProtocolBufferException.negativeSize(); - } - throw InvalidProtocolBufferException.truncatedMessage(); - } - - @Override - public byte[] readByteArray() throws IOException { - return readRawBytes(readRawVarint32()); - } - - @Override - public ByteBuffer readByteBuffer() throws IOException { - final int size = readRawVarint32(); - if (size > 0 && size <= remaining()) { - // "Immutable" implies that buffer is backing a ByteString. - // Disallow slicing in this case to prevent the caller from modifying the contents - // of the ByteString. - if (!immutable && enableAliasing) { - final ByteBuffer result = slice(pos, pos + size); - pos += size; - return result; - } else { - // The same as readBytes' logic - byte[] bytes = new byte[size]; - UnsafeUtil.copyMemory(pos, bytes, 0, size); - pos += size; - return ByteBuffer.wrap(bytes); - } - // TODO: Investigate making the ByteBuffer be made read-only - } - - if (size == 0) { - return EMPTY_BYTE_BUFFER; - } - if (size < 0) { - throw InvalidProtocolBufferException.negativeSize(); - } - throw InvalidProtocolBufferException.truncatedMessage(); - } - - @Override - public int readUInt32() throws IOException { - return readRawVarint32(); - } - - @Override - public int readEnum() throws IOException { - return readRawVarint32(); - } - - @Override - public int readSFixed32() throws IOException { - return readRawLittleEndian32(); - } - - @Override - public long readSFixed64() throws IOException { - return readRawLittleEndian64(); - } - - @Override - public int readSInt32() throws IOException { - return decodeZigZag32(readRawVarint32()); - } - - @Override - public long readSInt64() throws IOException { - return decodeZigZag64(readRawVarint64()); - } - - // ================================================================= - - @Override - public int readRawVarint32() throws IOException { - // See implementation notes for readRawVarint64 - fastpath: - { - long tempPos = pos; - - if (limit == tempPos) { - break fastpath; - } - - int x; - if ((x = UnsafeUtil.getByte(tempPos++)) >= 0) { - pos = tempPos; - return x; - } else if (limit - tempPos < 9) { - break fastpath; - } else if ((x ^= (UnsafeUtil.getByte(tempPos++) << 7)) < 0) { - x ^= (~0 << 7); - } else if ((x ^= (UnsafeUtil.getByte(tempPos++) << 14)) >= 0) { - x ^= (~0 << 7) ^ (~0 << 14); - } else if ((x ^= (UnsafeUtil.getByte(tempPos++) << 21)) < 0) { - x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21); - } else { - int y = UnsafeUtil.getByte(tempPos++); - x ^= y << 28; - x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21) ^ (~0 << 28); - if (y < 0 - && UnsafeUtil.getByte(tempPos++) < 0 - && UnsafeUtil.getByte(tempPos++) < 0 - && UnsafeUtil.getByte(tempPos++) < 0 - && UnsafeUtil.getByte(tempPos++) < 0 - && UnsafeUtil.getByte(tempPos++) < 0) { - break fastpath; // Will throw malformedVarint() - } - } - pos = tempPos; - return x; - } - return (int) readRawVarint64SlowPath(); - } - - private void skipRawVarint() throws IOException { - if (remaining() >= MAX_VARINT_SIZE) { - skipRawVarintFastPath(); - } else { - skipRawVarintSlowPath(); - } - } - - private void skipRawVarintFastPath() throws IOException { - for (int i = 0; i < MAX_VARINT_SIZE; i++) { - if (UnsafeUtil.getByte(pos++) >= 0) { - return; - } - } - throw InvalidProtocolBufferException.malformedVarint(); - } - - private void skipRawVarintSlowPath() throws IOException { - for (int i = 0; i < MAX_VARINT_SIZE; i++) { - if (readRawByte() >= 0) { - return; - } - } - throw InvalidProtocolBufferException.malformedVarint(); - } - - @Override - public long readRawVarint64() throws IOException { - // Implementation notes: - // - // Optimized for one-byte values, expected to be common. - // The particular code below was selected from various candidates - // empirically, by winning VarintBenchmark. - // - // Sign extension of (signed) Java bytes is usually a nuisance, but - // we exploit it here to more easily obtain the sign of bytes read. - // Instead of cleaning up the sign extension bits by masking eagerly, - // we delay until we find the final (positive) byte, when we clear all - // accumulated bits with one xor. We depend on javac to constant fold. - fastpath: - { - long tempPos = pos; - - if (limit == tempPos) { - break fastpath; - } - - long x; - int y; - if ((y = UnsafeUtil.getByte(tempPos++)) >= 0) { - pos = tempPos; - return y; - } else if (limit - tempPos < 9) { - break fastpath; - } else if ((y ^= (UnsafeUtil.getByte(tempPos++) << 7)) < 0) { - x = y ^ (~0 << 7); - } else if ((y ^= (UnsafeUtil.getByte(tempPos++) << 14)) >= 0) { - x = y ^ ((~0 << 7) ^ (~0 << 14)); - } else if ((y ^= (UnsafeUtil.getByte(tempPos++) << 21)) < 0) { - x = y ^ ((~0 << 7) ^ (~0 << 14) ^ (~0 << 21)); - } else if ((x = y ^ ((long) UnsafeUtil.getByte(tempPos++) << 28)) >= 0L) { - x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28); - } else if ((x ^= ((long) UnsafeUtil.getByte(tempPos++) << 35)) < 0L) { - x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35); - } else if ((x ^= ((long) UnsafeUtil.getByte(tempPos++) << 42)) >= 0L) { - x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35) ^ (~0L << 42); - } else if ((x ^= ((long) UnsafeUtil.getByte(tempPos++) << 49)) < 0L) { - x ^= - (~0L << 7) - ^ (~0L << 14) - ^ (~0L << 21) - ^ (~0L << 28) - ^ (~0L << 35) - ^ (~0L << 42) - ^ (~0L << 49); - } else { - x ^= ((long) UnsafeUtil.getByte(tempPos++) << 56); - x ^= - (~0L << 7) - ^ (~0L << 14) - ^ (~0L << 21) - ^ (~0L << 28) - ^ (~0L << 35) - ^ (~0L << 42) - ^ (~0L << 49) - ^ (~0L << 56); - if (x < 0L) { - if (UnsafeUtil.getByte(tempPos++) < 0L) { - break fastpath; // Will throw malformedVarint() - } - } - } - pos = tempPos; - return x; - } - return readRawVarint64SlowPath(); - } - - @Override - long readRawVarint64SlowPath() throws IOException { - long result = 0; - for (int shift = 0; shift < 64; shift += 7) { - final byte b = readRawByte(); - result |= (long) (b & 0x7F) << shift; - if ((b & 0x80) == 0) { - return result; - } - } - throw InvalidProtocolBufferException.malformedVarint(); - } - - @Override - public int readRawLittleEndian32() throws IOException { - long tempPos = pos; - - if (limit - tempPos < FIXED32_SIZE) { - throw InvalidProtocolBufferException.truncatedMessage(); - } - - pos = tempPos + FIXED32_SIZE; - return ((UnsafeUtil.getByte(tempPos) & 0xff) - | ((UnsafeUtil.getByte(tempPos + 1) & 0xff) << 8) - | ((UnsafeUtil.getByte(tempPos + 2) & 0xff) << 16) - | ((UnsafeUtil.getByte(tempPos + 3) & 0xff) << 24)); - } - - @Override - public long readRawLittleEndian64() throws IOException { - long tempPos = pos; - - if (limit - tempPos < FIXED64_SIZE) { - throw InvalidProtocolBufferException.truncatedMessage(); - } - - pos = tempPos + FIXED64_SIZE; - return ((UnsafeUtil.getByte(tempPos) & 0xffL) - | ((UnsafeUtil.getByte(tempPos + 1) & 0xffL) << 8) - | ((UnsafeUtil.getByte(tempPos + 2) & 0xffL) << 16) - | ((UnsafeUtil.getByte(tempPos + 3) & 0xffL) << 24) - | ((UnsafeUtil.getByte(tempPos + 4) & 0xffL) << 32) - | ((UnsafeUtil.getByte(tempPos + 5) & 0xffL) << 40) - | ((UnsafeUtil.getByte(tempPos + 6) & 0xffL) << 48) - | ((UnsafeUtil.getByte(tempPos + 7) & 0xffL) << 56)); - } - - @Override - public void enableAliasing(boolean enabled) { - this.enableAliasing = enabled; - } - - @Override - public void resetSizeCounter() { - startPos = pos; - } - - @Override - public int pushLimit(int byteLimit) throws InvalidProtocolBufferException { - if (byteLimit < 0) { - throw InvalidProtocolBufferException.negativeSize(); - } - byteLimit += getTotalBytesRead(); - final int oldLimit = currentLimit; - if (byteLimit > oldLimit) { - throw InvalidProtocolBufferException.truncatedMessage(); - } - currentLimit = byteLimit; - - recomputeBufferSizeAfterLimit(); - - return oldLimit; - } - - @Override - public void popLimit(final int oldLimit) { - currentLimit = oldLimit; - recomputeBufferSizeAfterLimit(); - } - - @Override - public int getBytesUntilLimit() { - if (currentLimit == Integer.MAX_VALUE) { - return -1; - } - - return currentLimit - getTotalBytesRead(); - } - - @Override - public boolean isAtEnd() throws IOException { - return pos == limit; - } - - @Override - public int getTotalBytesRead() { - return (int) (pos - startPos); - } - - @Override - public byte readRawByte() throws IOException { - if (pos == limit) { - throw InvalidProtocolBufferException.truncatedMessage(); - } - return UnsafeUtil.getByte(pos++); - } - - @Override - public byte[] readRawBytes(final int length) throws IOException { - if (length >= 0 && length <= remaining()) { - byte[] bytes = new byte[length]; - slice(pos, pos + length).get(bytes); - pos += length; - return bytes; - } - - if (length <= 0) { - if (length == 0) { - return EMPTY_BYTE_ARRAY; - } else { - throw InvalidProtocolBufferException.negativeSize(); - } - } - - throw InvalidProtocolBufferException.truncatedMessage(); - } - - @Override - public void skipRawBytes(final int length) throws IOException { - if (length >= 0 && length <= remaining()) { - // We have all the bytes we need already. - pos += length; - return; - } - - if (length < 0) { - throw InvalidProtocolBufferException.negativeSize(); - } - throw InvalidProtocolBufferException.truncatedMessage(); - } - - private void recomputeBufferSizeAfterLimit() { - limit += bufferSizeAfterLimit; - final int bufferEnd = (int) (limit - startPos); - if (bufferEnd > currentLimit) { - // Limit is in current buffer. - bufferSizeAfterLimit = bufferEnd - currentLimit; - limit -= bufferSizeAfterLimit; - } else { - bufferSizeAfterLimit = 0; - } - } - - private int remaining() { - return (int) (limit - pos); - } - - private int bufferPos(long pos) { - return (int) (pos - address); - } - - private ByteBuffer slice(long begin, long end) throws IOException { - int prevPos = buffer.position(); - int prevLimit = buffer.limit(); - // View ByteBuffer as Buffer to avoid cross-Java version issues. - // See https://issues.apache.org/jira/browse/MRESOLVER-85 - Buffer asBuffer = buffer; - try { - asBuffer.position(bufferPos(begin)); - asBuffer.limit(bufferPos(end)); - return buffer.slice(); - } catch (IllegalArgumentException e) { - InvalidProtocolBufferException ex = InvalidProtocolBufferException.truncatedMessage(); - ex.initCause(e); - throw ex; - } finally { - asBuffer.position(prevPos); - asBuffer.limit(prevLimit); - } - } - } - - /** - * Implementation of {@link CodedInputStream} that uses an {@link InputStream} as the data source. - */ - private static final class StreamDecoder extends CodedInputStream { - private final InputStream input; - private final byte[] buffer; - /** bufferSize represents how many bytes are currently filled in the buffer */ - private int bufferSize; - - private int bufferSizeAfterLimit; - private int pos; - private int lastTag; - - /** - * The total number of bytes read before the current buffer. The total bytes read up to the - * current position can be computed as {@code totalBytesRetired + pos}. This value may be - * negative if reading started in the middle of the current buffer (e.g. if the constructor that - * takes a byte array and an offset was used). - */ - private int totalBytesRetired; - - /** The absolute position of the end of the current message. */ - private int currentLimit = Integer.MAX_VALUE; - - private StreamDecoder(final InputStream input, int bufferSize) { - checkNotNull(input, "input"); - this.input = input; - this.buffer = new byte[bufferSize]; - this.bufferSize = 0; - pos = 0; - totalBytesRetired = 0; - } - - /* - * The following wrapper methods exist so that InvalidProtocolBufferExceptions thrown by the - * InputStream can be differentiated from ones thrown by CodedInputStream itself. Each call to - * an InputStream method that can throw IOException must be wrapped like this. We do this - * because we sometimes need to modify IPBE instances after they are thrown far away from where - * they are thrown (ex. to add unfinished messages) and we use this signal elsewhere in the - * exception catch chain to know when to perform these operations directly or to wrap the - * exception in their own IPBE so the extra information can be communicated without trampling - * downstream information. - */ - private static int read(InputStream input, byte[] data, int offset, int length) - throws IOException { - try { - return input.read(data, offset, length); - } catch (InvalidProtocolBufferException e) { - e.setThrownFromInputStream(); - throw e; - } - } - - private static long skip(InputStream input, long length) throws IOException { - try { - return input.skip(length); - } catch (InvalidProtocolBufferException e) { - e.setThrownFromInputStream(); - throw e; - } - } - - private static int available(InputStream input) throws IOException { - try { - return input.available(); - } catch (InvalidProtocolBufferException e) { - e.setThrownFromInputStream(); - throw e; - } - } - - @Override - public int readTag() throws IOException { - if (isAtEnd()) { - lastTag = 0; - return 0; - } - - lastTag = readRawVarint32(); - if (WireFormat.getTagFieldNumber(lastTag) == 0) { - // If we actually read zero (or any tag number corresponding to field - // number zero), that's not a valid tag. - throw InvalidProtocolBufferException.invalidTag(); - } - return lastTag; - } - - @Override - public void checkLastTagWas(final int value) throws InvalidProtocolBufferException { - if (lastTag != value) { - throw InvalidProtocolBufferException.invalidEndTag(); - } - } - - @Override - public int getLastTag() { - return lastTag; - } - - @Override - public boolean skipField(final int tag) throws IOException { - switch (WireFormat.getTagWireType(tag)) { - case WireFormat.WIRETYPE_VARINT: - skipRawVarint(); - return true; - case WireFormat.WIRETYPE_FIXED64: - skipRawBytes(FIXED64_SIZE); - return true; - case WireFormat.WIRETYPE_LENGTH_DELIMITED: - skipRawBytes(readRawVarint32()); - return true; - case WireFormat.WIRETYPE_START_GROUP: - skipMessage(); - checkLastTagWas( - WireFormat.makeTag(WireFormat.getTagFieldNumber(tag), WireFormat.WIRETYPE_END_GROUP)); - return true; - case WireFormat.WIRETYPE_END_GROUP: - return false; - case WireFormat.WIRETYPE_FIXED32: - skipRawBytes(FIXED32_SIZE); - return true; - default: - throw InvalidProtocolBufferException.invalidWireType(); - } - } - - @Override - public boolean skipField(final int tag, final CodedOutputStream output) throws IOException { - switch (WireFormat.getTagWireType(tag)) { - case WireFormat.WIRETYPE_VARINT: - { - long value = readInt64(); - output.writeUInt32NoTag(tag); - output.writeUInt64NoTag(value); - return true; - } - case WireFormat.WIRETYPE_FIXED64: - { - long value = readRawLittleEndian64(); - output.writeUInt32NoTag(tag); - output.writeFixed64NoTag(value); - return true; - } - case WireFormat.WIRETYPE_LENGTH_DELIMITED: - { - ByteString value = readBytes(); - output.writeUInt32NoTag(tag); - output.writeBytesNoTag(value); - return true; - } - case WireFormat.WIRETYPE_START_GROUP: - { - output.writeUInt32NoTag(tag); - skipMessage(output); - int endtag = - WireFormat.makeTag( - WireFormat.getTagFieldNumber(tag), WireFormat.WIRETYPE_END_GROUP); - checkLastTagWas(endtag); - output.writeUInt32NoTag(endtag); - return true; - } - case WireFormat.WIRETYPE_END_GROUP: - { - return false; - } - case WireFormat.WIRETYPE_FIXED32: - { - int value = readRawLittleEndian32(); - output.writeUInt32NoTag(tag); - output.writeFixed32NoTag(value); - return true; - } - default: - throw InvalidProtocolBufferException.invalidWireType(); - } - } - - /** Collects the bytes skipped and returns the data in a ByteBuffer. */ - private class SkippedDataSink implements RefillCallback { - private int lastPos = pos; - private ByteArrayOutputStream byteArrayStream; - - @Override - public void onRefill() { - if (byteArrayStream == null) { - byteArrayStream = new ByteArrayOutputStream(); - } - byteArrayStream.write(buffer, lastPos, pos - lastPos); - lastPos = 0; - } - - /** Gets skipped data in a ByteBuffer. This method should only be called once. */ - ByteBuffer getSkippedData() { - if (byteArrayStream == null) { - return ByteBuffer.wrap(buffer, lastPos, pos - lastPos); - } else { - byteArrayStream.write(buffer, lastPos, pos); - return ByteBuffer.wrap(byteArrayStream.toByteArray()); - } - } - } - - // ----------------------------------------------------------------- - - @Override - public double readDouble() throws IOException { - return Double.longBitsToDouble(readRawLittleEndian64()); - } - - @Override - public float readFloat() throws IOException { - return Float.intBitsToFloat(readRawLittleEndian32()); - } - - @Override - public long readUInt64() throws IOException { - return readRawVarint64(); - } - - @Override - public long readInt64() throws IOException { - return readRawVarint64(); - } - - @Override - public int readInt32() throws IOException { - return readRawVarint32(); - } - - @Override - public long readFixed64() throws IOException { - return readRawLittleEndian64(); - } - - @Override - public int readFixed32() throws IOException { - return readRawLittleEndian32(); - } - - @Override - public boolean readBool() throws IOException { - return readRawVarint64() != 0; - } - - @Override - public String readString() throws IOException { - final int size = readRawVarint32(); - if (size > 0 && size <= (bufferSize - pos)) { - // Fast path: We already have the bytes in a contiguous buffer, so - // just copy directly from it. - final String result = new String(buffer, pos, size, UTF_8); - pos += size; - return result; - } - if (size == 0) { - return ""; - } - if (size < 0) { - throw InvalidProtocolBufferException.negativeSize(); - } - if (size <= bufferSize) { - refillBuffer(size); - String result = new String(buffer, pos, size, UTF_8); - pos += size; - return result; - } - // Slow path: Build a byte array first then copy it. - return new String(readRawBytesSlowPath(size, /* ensureNoLeakedReferences= */ false), UTF_8); - } - - @Override - public String readStringRequireUtf8() throws IOException { - final int size = readRawVarint32(); - final byte[] bytes; - final int oldPos = pos; - final int tempPos; - if (size <= (bufferSize - oldPos) && size > 0) { - // Fast path: We already have the bytes in a contiguous buffer, so - // just copy directly from it. - bytes = buffer; - pos = oldPos + size; - tempPos = oldPos; - } else if (size == 0) { - return ""; - } else if (size < 0) { - throw InvalidProtocolBufferException.negativeSize(); - } else if (size <= bufferSize) { - refillBuffer(size); - bytes = buffer; - tempPos = 0; - pos = tempPos + size; - } else { - // Slow path: Build a byte array first then copy it. - bytes = readRawBytesSlowPath(size, /* ensureNoLeakedReferences= */ false); - tempPos = 0; - } - return Utf8.decodeUtf8(bytes, tempPos, size); - } - - @Override - public void readGroup( - final int fieldNumber, - final MessageLite.Builder builder, - final ExtensionRegistryLite extensionRegistry) - throws IOException { - checkRecursionLimit(); - ++recursionDepth; - builder.mergeFrom(this, extensionRegistry); - checkLastTagWas(WireFormat.makeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP)); - --recursionDepth; - } - - @Override - public T readGroup( - final int fieldNumber, - final Parser parser, - final ExtensionRegistryLite extensionRegistry) - throws IOException { - checkRecursionLimit(); - ++recursionDepth; - T result = parser.parsePartialFrom(this, extensionRegistry); - checkLastTagWas(WireFormat.makeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP)); - --recursionDepth; - return result; - } - - @Deprecated - @Override - public void readUnknownGroup(final int fieldNumber, final MessageLite.Builder builder) - throws IOException { - readGroup(fieldNumber, builder, ExtensionRegistryLite.getEmptyRegistry()); - } - - @Override - public void readMessage( - final MessageLite.Builder builder, final ExtensionRegistryLite extensionRegistry) - throws IOException { - final int length = readRawVarint32(); - checkRecursionLimit(); - final int oldLimit = pushLimit(length); - ++recursionDepth; - builder.mergeFrom(this, extensionRegistry); - checkLastTagWas(0); - --recursionDepth; - if (getBytesUntilLimit() != 0) { - throw InvalidProtocolBufferException.truncatedMessage(); - } - popLimit(oldLimit); - } - - @Override - public T readMessage( - final Parser parser, final ExtensionRegistryLite extensionRegistry) throws IOException { - int length = readRawVarint32(); - checkRecursionLimit(); - final int oldLimit = pushLimit(length); - ++recursionDepth; - T result = parser.parsePartialFrom(this, extensionRegistry); - checkLastTagWas(0); - --recursionDepth; - if (getBytesUntilLimit() != 0) { - throw InvalidProtocolBufferException.truncatedMessage(); - } - popLimit(oldLimit); - return result; - } - - @Override - public ByteString readBytes() throws IOException { - final int size = readRawVarint32(); - if (size <= (bufferSize - pos) && size > 0) { - // Fast path: We already have the bytes in a contiguous buffer, so - // just copy directly from it. - final ByteString result = ByteString.copyFrom(buffer, pos, size); - pos += size; - return result; - } - if (size == 0) { - return ByteString.EMPTY; - } - if (size < 0) { - throw InvalidProtocolBufferException.negativeSize(); - } - return readBytesSlowPath(size); - } - - @Override - public byte[] readByteArray() throws IOException { - final int size = readRawVarint32(); - if (size <= (bufferSize - pos) && size > 0) { - // Fast path: We already have the bytes in a contiguous buffer, so - // just copy directly from it. - final byte[] result = Arrays.copyOfRange(buffer, pos, pos + size); - pos += size; - return result; - } else if (size < 0) { - throw InvalidProtocolBufferException.negativeSize(); - } else { - // Slow path: Build a byte array first then copy it. - // TODO: Do we want to protect from malicious input streams here? - return readRawBytesSlowPath(size, /* ensureNoLeakedReferences= */ false); - } - } - - @Override - public ByteBuffer readByteBuffer() throws IOException { - final int size = readRawVarint32(); - if (size <= (bufferSize - pos) && size > 0) { - // Fast path: We already have the bytes in a contiguous buffer. - ByteBuffer result = ByteBuffer.wrap(Arrays.copyOfRange(buffer, pos, pos + size)); - pos += size; - return result; - } - if (size == 0) { - return Internal.EMPTY_BYTE_BUFFER; - } - if (size < 0) { - throw InvalidProtocolBufferException.negativeSize(); - } - // Slow path: Build a byte array first then copy it. - - // We must copy as the byte array was handed off to the InputStream and a malicious - // implementation could retain a reference. - return ByteBuffer.wrap(readRawBytesSlowPath(size, /* ensureNoLeakedReferences= */ true)); - } - - @Override - public int readUInt32() throws IOException { - return readRawVarint32(); - } - - @Override - public int readEnum() throws IOException { - return readRawVarint32(); - } - - @Override - public int readSFixed32() throws IOException { - return readRawLittleEndian32(); - } - - @Override - public long readSFixed64() throws IOException { - return readRawLittleEndian64(); - } - - @Override - public int readSInt32() throws IOException { - return decodeZigZag32(readRawVarint32()); - } - - @Override - public long readSInt64() throws IOException { - return decodeZigZag64(readRawVarint64()); - } - - // ================================================================= - - @Override - public int readRawVarint32() throws IOException { - // See implementation notes for readRawVarint64 - fastpath: - { - int tempPos = pos; - - if (bufferSize == tempPos) { - break fastpath; - } - - final byte[] buffer = this.buffer; - int x; - if ((x = buffer[tempPos++]) >= 0) { - pos = tempPos; - return x; - } else if (bufferSize - tempPos < 9) { - break fastpath; - } else if ((x ^= (buffer[tempPos++] << 7)) < 0) { - x ^= (~0 << 7); - } else if ((x ^= (buffer[tempPos++] << 14)) >= 0) { - x ^= (~0 << 7) ^ (~0 << 14); - } else if ((x ^= (buffer[tempPos++] << 21)) < 0) { - x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21); - } else { - int y = buffer[tempPos++]; - x ^= y << 28; - x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21) ^ (~0 << 28); - if (y < 0 - && buffer[tempPos++] < 0 - && buffer[tempPos++] < 0 - && buffer[tempPos++] < 0 - && buffer[tempPos++] < 0 - && buffer[tempPos++] < 0) { - break fastpath; // Will throw malformedVarint() - } - } - pos = tempPos; - return x; - } - return (int) readRawVarint64SlowPath(); - } - - private void skipRawVarint() throws IOException { - if (bufferSize - pos >= MAX_VARINT_SIZE) { - skipRawVarintFastPath(); - } else { - skipRawVarintSlowPath(); - } - } - - private void skipRawVarintFastPath() throws IOException { - for (int i = 0; i < MAX_VARINT_SIZE; i++) { - if (buffer[pos++] >= 0) { - return; - } - } - throw InvalidProtocolBufferException.malformedVarint(); - } - - private void skipRawVarintSlowPath() throws IOException { - for (int i = 0; i < MAX_VARINT_SIZE; i++) { - if (readRawByte() >= 0) { - return; - } - } - throw InvalidProtocolBufferException.malformedVarint(); - } - - @Override - public long readRawVarint64() throws IOException { - // Implementation notes: - // - // Optimized for one-byte values, expected to be common. - // The particular code below was selected from various candidates - // empirically, by winning VarintBenchmark. - // - // Sign extension of (signed) Java bytes is usually a nuisance, but - // we exploit it here to more easily obtain the sign of bytes read. - // Instead of cleaning up the sign extension bits by masking eagerly, - // we delay until we find the final (positive) byte, when we clear all - // accumulated bits with one xor. We depend on javac to constant fold. - fastpath: - { - int tempPos = pos; - - if (bufferSize == tempPos) { - break fastpath; - } - - final byte[] buffer = this.buffer; - long x; - int y; - if ((y = buffer[tempPos++]) >= 0) { - pos = tempPos; - return y; - } else if (bufferSize - tempPos < 9) { - break fastpath; - } else if ((y ^= (buffer[tempPos++] << 7)) < 0) { - x = y ^ (~0 << 7); - } else if ((y ^= (buffer[tempPos++] << 14)) >= 0) { - x = y ^ ((~0 << 7) ^ (~0 << 14)); - } else if ((y ^= (buffer[tempPos++] << 21)) < 0) { - x = y ^ ((~0 << 7) ^ (~0 << 14) ^ (~0 << 21)); - } else if ((x = y ^ ((long) buffer[tempPos++] << 28)) >= 0L) { - x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28); - } else if ((x ^= ((long) buffer[tempPos++] << 35)) < 0L) { - x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35); - } else if ((x ^= ((long) buffer[tempPos++] << 42)) >= 0L) { - x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35) ^ (~0L << 42); - } else if ((x ^= ((long) buffer[tempPos++] << 49)) < 0L) { - x ^= - (~0L << 7) - ^ (~0L << 14) - ^ (~0L << 21) - ^ (~0L << 28) - ^ (~0L << 35) - ^ (~0L << 42) - ^ (~0L << 49); - } else { - x ^= ((long) buffer[tempPos++] << 56); - x ^= - (~0L << 7) - ^ (~0L << 14) - ^ (~0L << 21) - ^ (~0L << 28) - ^ (~0L << 35) - ^ (~0L << 42) - ^ (~0L << 49) - ^ (~0L << 56); - if (x < 0L) { - if (buffer[tempPos++] < 0L) { - break fastpath; // Will throw malformedVarint() - } - } - } - pos = tempPos; - return x; - } - return readRawVarint64SlowPath(); - } - - @Override - long readRawVarint64SlowPath() throws IOException { - long result = 0; - for (int shift = 0; shift < 64; shift += 7) { - final byte b = readRawByte(); - result |= (long) (b & 0x7F) << shift; - if ((b & 0x80) == 0) { - return result; - } - } - throw InvalidProtocolBufferException.malformedVarint(); - } - - @Override - public int readRawLittleEndian32() throws IOException { - int tempPos = pos; - - if (bufferSize - tempPos < FIXED32_SIZE) { - refillBuffer(FIXED32_SIZE); - tempPos = pos; - } - - final byte[] buffer = this.buffer; - pos = tempPos + FIXED32_SIZE; - return ((buffer[tempPos] & 0xff) - | ((buffer[tempPos + 1] & 0xff) << 8) - | ((buffer[tempPos + 2] & 0xff) << 16) - | ((buffer[tempPos + 3] & 0xff) << 24)); - } - - @Override - public long readRawLittleEndian64() throws IOException { - int tempPos = pos; - - if (bufferSize - tempPos < FIXED64_SIZE) { - refillBuffer(FIXED64_SIZE); - tempPos = pos; - } - - final byte[] buffer = this.buffer; - pos = tempPos + FIXED64_SIZE; - return (((buffer[tempPos] & 0xffL)) - | ((buffer[tempPos + 1] & 0xffL) << 8) - | ((buffer[tempPos + 2] & 0xffL) << 16) - | ((buffer[tempPos + 3] & 0xffL) << 24) - | ((buffer[tempPos + 4] & 0xffL) << 32) - | ((buffer[tempPos + 5] & 0xffL) << 40) - | ((buffer[tempPos + 6] & 0xffL) << 48) - | ((buffer[tempPos + 7] & 0xffL) << 56)); - } - - // ----------------------------------------------------------------- - - @Override - public void enableAliasing(boolean enabled) { - // TODO: Ideally we should throw here. Do nothing for backward compatibility. - } - - @Override - public void resetSizeCounter() { - totalBytesRetired = -pos; - } - - @Override - public int pushLimit(int byteLimit) throws InvalidProtocolBufferException { - if (byteLimit < 0) { - throw InvalidProtocolBufferException.negativeSize(); - } - byteLimit += totalBytesRetired + pos; - final int oldLimit = currentLimit; - if (byteLimit > oldLimit) { - throw InvalidProtocolBufferException.truncatedMessage(); - } - currentLimit = byteLimit; - - recomputeBufferSizeAfterLimit(); - - return oldLimit; - } - - private void recomputeBufferSizeAfterLimit() { - bufferSize += bufferSizeAfterLimit; - final int bufferEnd = totalBytesRetired + bufferSize; - if (bufferEnd > currentLimit) { - // Limit is in current buffer. - bufferSizeAfterLimit = bufferEnd - currentLimit; - bufferSize -= bufferSizeAfterLimit; - } else { - bufferSizeAfterLimit = 0; - } - } - - @Override - public void popLimit(final int oldLimit) { - currentLimit = oldLimit; - recomputeBufferSizeAfterLimit(); - } - - @Override - public int getBytesUntilLimit() { - if (currentLimit == Integer.MAX_VALUE) { - return -1; - } - - final int currentAbsolutePosition = totalBytesRetired + pos; - return currentLimit - currentAbsolutePosition; - } - - @Override - public boolean isAtEnd() throws IOException { - return pos == bufferSize && !tryRefillBuffer(1); - } - - @Override - public int getTotalBytesRead() { - return totalBytesRetired + pos; - } - - private interface RefillCallback { - void onRefill(); - } - - private RefillCallback refillCallback = null; - - /** - * Reads more bytes from the input, making at least {@code n} bytes available in the buffer. - * Caller must ensure that the requested space is not yet available, and that the requested - * space is less than BUFFER_SIZE. - * - * @throws InvalidProtocolBufferException The end of the stream or the current limit was - * reached. - */ - private void refillBuffer(int n) throws IOException { - if (!tryRefillBuffer(n)) { - // We have to distinguish the exception between sizeLimitExceeded and truncatedMessage. So - // we just throw an sizeLimitExceeded exception here if it exceeds the sizeLimit - if (n > sizeLimit - totalBytesRetired - pos) { - throw InvalidProtocolBufferException.sizeLimitExceeded(); - } else { - throw InvalidProtocolBufferException.truncatedMessage(); - } - } - } - - /** - * Tries to read more bytes from the input, making at least {@code n} bytes available in the - * buffer. Caller must ensure that the requested space is not yet available, and that the - * requested space is less than BUFFER_SIZE. - * - * @return {@code true} If the bytes could be made available; {@code false} 1. Current at the - * end of the stream 2. The current limit was reached 3. The total size limit was reached - */ - private boolean tryRefillBuffer(int n) throws IOException { - if (pos + n <= bufferSize) { - throw new IllegalStateException( - "refillBuffer() called when " + n + " bytes were already available in buffer"); - } - - // Check whether the size of total message needs to read is bigger than the size limit. - // We shouldn't throw an exception here as isAtEnd() function needs to get this function's - // return as the result. - if (n > sizeLimit - totalBytesRetired - pos) { - return false; - } - - // Shouldn't throw the exception here either. - if (totalBytesRetired + pos + n > currentLimit) { - // Oops, we hit a limit. - return false; - } - - if (refillCallback != null) { - refillCallback.onRefill(); - } - - int tempPos = pos; - if (tempPos > 0) { - if (bufferSize > tempPos) { - System.arraycopy(buffer, tempPos, buffer, 0, bufferSize - tempPos); - } - totalBytesRetired += tempPos; - bufferSize -= tempPos; - pos = 0; - } - - // Here we should refill the buffer as many bytes as possible. - int bytesRead = - read( - input, - buffer, - bufferSize, - Math.min( - // the size of allocated but unused bytes in the buffer - buffer.length - bufferSize, - // do not exceed the total bytes limit - sizeLimit - totalBytesRetired - bufferSize)); - if (bytesRead == 0 || bytesRead < -1 || bytesRead > buffer.length) { - throw new IllegalStateException( - input.getClass() - + "#read(byte[]) returned invalid result: " - + bytesRead - + "\nThe InputStream implementation is buggy."); - } - if (bytesRead > 0) { - bufferSize += bytesRead; - recomputeBufferSizeAfterLimit(); - return (bufferSize >= n) ? true : tryRefillBuffer(n); - } - - return false; - } - - @Override - public byte readRawByte() throws IOException { - if (pos == bufferSize) { - refillBuffer(1); - } - return buffer[pos++]; - } - - @Override - public byte[] readRawBytes(final int size) throws IOException { - final int tempPos = pos; - if (size <= (bufferSize - tempPos) && size > 0) { - pos = tempPos + size; - return Arrays.copyOfRange(buffer, tempPos, tempPos + size); - } else { - // TODO: Do we want to protect from malicious input streams here? - return readRawBytesSlowPath(size, /* ensureNoLeakedReferences= */ false); - } - } - - /** - * Exactly like readRawBytes, but caller must have already checked the fast path: (size <= - * (bufferSize - pos) && size > 0) - * - * If ensureNoLeakedReferences is true, the value is guaranteed to have not escaped to - * untrusted code. - */ - private byte[] readRawBytesSlowPath( - final int size, boolean ensureNoLeakedReferences) throws IOException { - // Attempt to read the data in one byte array when it's safe to do. - byte[] result = readRawBytesSlowPathOneChunk(size); - if (result != null) { - return ensureNoLeakedReferences ? result.clone() : result; - } - - final int originalBufferPos = pos; - final int bufferedBytes = bufferSize - pos; - - // Mark the current buffer consumed. - totalBytesRetired += bufferSize; - pos = 0; - bufferSize = 0; - - // Determine the number of bytes we need to read from the input stream. - int sizeLeft = size - bufferedBytes; - - // The size is very large. For security reasons we read them in small - // chunks. - List chunks = readRawBytesSlowPathRemainingChunks(sizeLeft); - - // OK, got everything. Now concatenate it all into one buffer. - final byte[] bytes = new byte[size]; - - // Start by copying the leftover bytes from this.buffer. - System.arraycopy(buffer, originalBufferPos, bytes, 0, bufferedBytes); - - // And now all the chunks. - int tempPos = bufferedBytes; - for (final byte[] chunk : chunks) { - System.arraycopy(chunk, 0, bytes, tempPos, chunk.length); - tempPos += chunk.length; - } - - // Done. - return bytes; - } - - /** - * Attempts to read the data in one byte array when it's safe to do. Returns null if the size to - * read is too large and needs to be allocated in smaller chunks for security reasons. - * - *

Returns a byte[] that may have escaped to user code via InputStream APIs. - */ - private byte[] readRawBytesSlowPathOneChunk(final int size) throws IOException { - if (size == 0) { - return Internal.EMPTY_BYTE_ARRAY; - } - if (size < 0) { - throw InvalidProtocolBufferException.negativeSize(); - } - - // Integer-overflow-conscious check that the message size so far has not exceeded sizeLimit. - int currentMessageSize = totalBytesRetired + pos + size; - if (currentMessageSize - sizeLimit > 0) { - throw InvalidProtocolBufferException.sizeLimitExceeded(); - } - - // Verify that the message size so far has not exceeded currentLimit. - if (currentMessageSize > currentLimit) { - // Read to the end of the stream anyway. - skipRawBytes(currentLimit - totalBytesRetired - pos); - throw InvalidProtocolBufferException.truncatedMessage(); - } - - final int bufferedBytes = bufferSize - pos; - // Determine the number of bytes we need to read from the input stream. - int sizeLeft = size - bufferedBytes; - // TODO: Consider using a value larger than DEFAULT_BUFFER_SIZE. - if (sizeLeft < DEFAULT_BUFFER_SIZE || sizeLeft <= available(input)) { - // Either the bytes we need are known to be available, or the required buffer is - // within an allowed threshold - go ahead and allocate the buffer now. - final byte[] bytes = new byte[size]; - - // Copy all of the buffered bytes to the result buffer. - System.arraycopy(buffer, pos, bytes, 0, bufferedBytes); - totalBytesRetired += bufferSize; - pos = 0; - bufferSize = 0; - - // Fill the remaining bytes from the input stream. - int tempPos = bufferedBytes; - while (tempPos < bytes.length) { - int n = read(input, bytes, tempPos, size - tempPos); - if (n == -1) { - throw InvalidProtocolBufferException.truncatedMessage(); - } - totalBytesRetired += n; - tempPos += n; - } - - return bytes; - } - - return null; - } - - /** - * Reads the remaining data in small chunks from the input stream. - * - * Returns a byte[] that may have escaped to user code via InputStream APIs. - */ - private List readRawBytesSlowPathRemainingChunks(int sizeLeft) throws IOException { - // The size is very large. For security reasons, we can't allocate the - // entire byte array yet. The size comes directly from the input, so a - // maliciously-crafted message could provide a bogus very large size in - // order to trick the app into allocating a lot of memory. We avoid this - // by allocating and reading only a small chunk at a time, so that the - // malicious message must actually *be* extremely large to cause - // problems. Meanwhile, we limit the allowed size of a message elsewhere. - final List chunks = new ArrayList<>(); - - while (sizeLeft > 0) { - // TODO: Consider using a value larger than DEFAULT_BUFFER_SIZE. - final byte[] chunk = new byte[Math.min(sizeLeft, DEFAULT_BUFFER_SIZE)]; - int tempPos = 0; - while (tempPos < chunk.length) { - final int n = input.read(chunk, tempPos, chunk.length - tempPos); - if (n == -1) { - throw InvalidProtocolBufferException.truncatedMessage(); - } - totalBytesRetired += n; - tempPos += n; - } - sizeLeft -= chunk.length; - chunks.add(chunk); - } - - return chunks; - } - - /** - * Like readBytes, but caller must have already checked the fast path: (size <= (bufferSize - - * pos) && size > 0 || size == 0) - */ - private ByteString readBytesSlowPath(final int size) throws IOException { - final byte[] result = readRawBytesSlowPathOneChunk(size); - if (result != null) { - // We must copy as the byte array was handed off to the InputStream and a malicious - // implementation could retain a reference. - return ByteString.copyFrom(result); - } - - final int originalBufferPos = pos; - final int bufferedBytes = bufferSize - pos; - - // Mark the current buffer consumed. - totalBytesRetired += bufferSize; - pos = 0; - bufferSize = 0; - - // Determine the number of bytes we need to read from the input stream. - int sizeLeft = size - bufferedBytes; - - // The size is very large. For security reasons we read them in small - // chunks. - List chunks = readRawBytesSlowPathRemainingChunks(sizeLeft); - - // OK, got everything. Now concatenate it all into one buffer. - final byte[] bytes = new byte[size]; - - // Start by copying the leftover bytes from this.buffer. - System.arraycopy(buffer, originalBufferPos, bytes, 0, bufferedBytes); - - // And now all the chunks. - int tempPos = bufferedBytes; - for (final byte[] chunk : chunks) { - System.arraycopy(chunk, 0, bytes, tempPos, chunk.length); - tempPos += chunk.length; - } - - return ByteString.wrap(bytes); - } - - @Override - public void skipRawBytes(final int size) throws IOException { - if (size <= (bufferSize - pos) && size >= 0) { - // We have all the bytes we need already. - pos += size; - } else { - skipRawBytesSlowPath(size); - } - } - - /** - * Exactly like skipRawBytes, but caller must have already checked the fast path: (size <= - * (bufferSize - pos) && size >= 0) - */ - private void skipRawBytesSlowPath(final int size) throws IOException { - if (size < 0) { - throw InvalidProtocolBufferException.negativeSize(); - } - - if (totalBytesRetired + pos + size > currentLimit) { - // Read to the end of the stream anyway. - skipRawBytes(currentLimit - totalBytesRetired - pos); - // Then fail. - throw InvalidProtocolBufferException.truncatedMessage(); - } - - int totalSkipped = 0; - if (refillCallback == null) { - // Skipping more bytes than are in the buffer. First skip what we have. - totalBytesRetired += pos; - totalSkipped = bufferSize - pos; - bufferSize = 0; - pos = 0; - - try { - while (totalSkipped < size) { - int toSkip = size - totalSkipped; - long skipped = skip(input, toSkip); - if (skipped < 0 || skipped > toSkip) { - throw new IllegalStateException( - input.getClass() - + "#skip returned invalid result: " - + skipped - + "\nThe InputStream implementation is buggy."); - } else if (skipped == 0) { - // The API contract of skip() permits an inputstream to skip zero bytes for any reason - // it wants. In particular, ByteArrayInputStream will just return zero over and over - // when it's at the end of its input. In order to actually confirm that we've hit the - // end of input, we need to issue a read call via the other path. - break; - } - totalSkipped += (int) skipped; - } - } finally { - totalBytesRetired += totalSkipped; - recomputeBufferSizeAfterLimit(); - } - } - if (totalSkipped < size) { - // Skipping more bytes than are in the buffer. First skip what we have. - int tempPos = bufferSize - pos; - pos = bufferSize; - - // Keep refilling the buffer until we get to the point we wanted to skip to. - // This has the side effect of ensuring the limits are updated correctly. - refillBuffer(1); - while (size - tempPos > bufferSize) { - tempPos += bufferSize; - pos = bufferSize; - refillBuffer(1); - } - - pos = size - tempPos; - } - } - } - - /** - * Implementation of {@link CodedInputStream} that uses an {@link Iterable } as the - * data source. Requires the use of {@code sun.misc.Unsafe} to perform fast reads on the buffer. - */ - private static final class IterableDirectByteBufferDecoder extends CodedInputStream { - /** The object that need to decode. */ - private final Iterable input; - /** The {@link Iterator} with type {@link ByteBuffer} of {@code input} */ - private final Iterator iterator; - /** The current ByteBuffer; */ - private ByteBuffer currentByteBuffer; - /** - * If {@code true}, indicates that all the buffers are backing a {@link ByteString} and are - * therefore considered to be an immutable input source. - */ - private final boolean immutable; - /** - * If {@code true}, indicates that calls to read {@link ByteString} or {@code byte[]} - * may return slices of the underlying buffer, rather than copies. - */ - private boolean enableAliasing; - /** The global total message length limit */ - private int totalBufferSize; - /** The amount of available data in the input beyond {@link #currentLimit}. */ - private int bufferSizeAfterCurrentLimit; - /** The absolute position of the end of the current message. */ - private int currentLimit = Integer.MAX_VALUE; - /** The last tag that was read from this stream. */ - private int lastTag; - /** Total Bytes have been Read from the {@link Iterable} {@link ByteBuffer} */ - private int totalBytesRead; - /** The start position offset of the whole message, used as to reset the totalBytesRead */ - private int startOffset; - /** The current position for current ByteBuffer */ - private long currentByteBufferPos; - - private long currentByteBufferStartPos; - /** - * If the current ByteBuffer is unsafe-direct based, currentAddress is the start address of this - * ByteBuffer; otherwise should be zero. - */ - private long currentAddress; - /** The limit position for current ByteBuffer */ - private long currentByteBufferLimit; - - /** - * The constructor of {@code Iterable} decoder. - * - * @param inputBufs The input data. - * @param size The total size of the input data. - * @param immutableFlag whether the input data is immutable. - */ - private IterableDirectByteBufferDecoder( - Iterable inputBufs, int size, boolean immutableFlag) { - totalBufferSize = size; - input = inputBufs; - iterator = input.iterator(); - immutable = immutableFlag; - startOffset = totalBytesRead = 0; - if (size == 0) { - currentByteBuffer = EMPTY_BYTE_BUFFER; - currentByteBufferPos = 0; - currentByteBufferStartPos = 0; - currentByteBufferLimit = 0; - currentAddress = 0; - } else { - tryGetNextByteBuffer(); - } - } - - /** To get the next ByteBuffer from {@code input}, and then update the parameters */ - private void getNextByteBuffer() throws InvalidProtocolBufferException { - if (!iterator.hasNext()) { - throw InvalidProtocolBufferException.truncatedMessage(); - } - tryGetNextByteBuffer(); - } - - private void tryGetNextByteBuffer() { - currentByteBuffer = iterator.next(); - totalBytesRead += (int) (currentByteBufferPos - currentByteBufferStartPos); - currentByteBufferPos = currentByteBuffer.position(); - currentByteBufferStartPos = currentByteBufferPos; - currentByteBufferLimit = currentByteBuffer.limit(); - currentAddress = UnsafeUtil.addressOffset(currentByteBuffer); - currentByteBufferPos += currentAddress; - currentByteBufferStartPos += currentAddress; - currentByteBufferLimit += currentAddress; - } - - @Override - public int readTag() throws IOException { - if (isAtEnd()) { - lastTag = 0; - return 0; - } - - lastTag = readRawVarint32(); - if (WireFormat.getTagFieldNumber(lastTag) == 0) { - // If we actually read zero (or any tag number corresponding to field - // number zero), that's not a valid tag. - throw InvalidProtocolBufferException.invalidTag(); - } - return lastTag; - } - - @Override - public void checkLastTagWas(final int value) throws InvalidProtocolBufferException { - if (lastTag != value) { - throw InvalidProtocolBufferException.invalidEndTag(); - } - } - - @Override - public int getLastTag() { - return lastTag; - } - - @Override - public boolean skipField(final int tag) throws IOException { - switch (WireFormat.getTagWireType(tag)) { - case WireFormat.WIRETYPE_VARINT: - skipRawVarint(); - return true; - case WireFormat.WIRETYPE_FIXED64: - skipRawBytes(FIXED64_SIZE); - return true; - case WireFormat.WIRETYPE_LENGTH_DELIMITED: - skipRawBytes(readRawVarint32()); - return true; - case WireFormat.WIRETYPE_START_GROUP: - skipMessage(); - checkLastTagWas( - WireFormat.makeTag(WireFormat.getTagFieldNumber(tag), WireFormat.WIRETYPE_END_GROUP)); - return true; - case WireFormat.WIRETYPE_END_GROUP: - return false; - case WireFormat.WIRETYPE_FIXED32: - skipRawBytes(FIXED32_SIZE); - return true; - default: - throw InvalidProtocolBufferException.invalidWireType(); - } - } - - @Override - public boolean skipField(final int tag, final CodedOutputStream output) throws IOException { - switch (WireFormat.getTagWireType(tag)) { - case WireFormat.WIRETYPE_VARINT: - { - long value = readInt64(); - output.writeUInt32NoTag(tag); - output.writeUInt64NoTag(value); - return true; - } - case WireFormat.WIRETYPE_FIXED64: - { - long value = readRawLittleEndian64(); - output.writeUInt32NoTag(tag); - output.writeFixed64NoTag(value); - return true; - } - case WireFormat.WIRETYPE_LENGTH_DELIMITED: - { - ByteString value = readBytes(); - output.writeUInt32NoTag(tag); - output.writeBytesNoTag(value); - return true; - } - case WireFormat.WIRETYPE_START_GROUP: - { - output.writeUInt32NoTag(tag); - skipMessage(output); - int endtag = - WireFormat.makeTag( - WireFormat.getTagFieldNumber(tag), WireFormat.WIRETYPE_END_GROUP); - checkLastTagWas(endtag); - output.writeUInt32NoTag(endtag); - return true; - } - case WireFormat.WIRETYPE_END_GROUP: - { - return false; - } - case WireFormat.WIRETYPE_FIXED32: - { - int value = readRawLittleEndian32(); - output.writeUInt32NoTag(tag); - output.writeFixed32NoTag(value); - return true; - } - default: - throw InvalidProtocolBufferException.invalidWireType(); - } - } - - // ----------------------------------------------------------------- - - @Override - public double readDouble() throws IOException { - return Double.longBitsToDouble(readRawLittleEndian64()); - } - - @Override - public float readFloat() throws IOException { - return Float.intBitsToFloat(readRawLittleEndian32()); - } - - @Override - public long readUInt64() throws IOException { - return readRawVarint64(); - } - - @Override - public long readInt64() throws IOException { - return readRawVarint64(); - } - - @Override - public int readInt32() throws IOException { - return readRawVarint32(); - } - - @Override - public long readFixed64() throws IOException { - return readRawLittleEndian64(); - } - - @Override - public int readFixed32() throws IOException { - return readRawLittleEndian32(); - } - - @Override - public boolean readBool() throws IOException { - return readRawVarint64() != 0; - } - - @Override - public String readString() throws IOException { - final int size = readRawVarint32(); - if (size > 0 && size <= currentByteBufferLimit - currentByteBufferPos) { - byte[] bytes = new byte[size]; - UnsafeUtil.copyMemory(currentByteBufferPos, bytes, 0, size); - String result = new String(bytes, UTF_8); - currentByteBufferPos += size; - return result; - } else if (size > 0 && size <= remaining()) { - // TODO: To use an underlying bytes[] instead of allocating a new bytes[] - byte[] bytes = new byte[size]; - readRawBytesTo(bytes, 0, size); - String result = new String(bytes, UTF_8); - return result; - } - - if (size == 0) { - return ""; - } - if (size < 0) { - throw InvalidProtocolBufferException.negativeSize(); - } - throw InvalidProtocolBufferException.truncatedMessage(); - } - - @Override - public String readStringRequireUtf8() throws IOException { - final int size = readRawVarint32(); - if (size > 0 && size <= currentByteBufferLimit - currentByteBufferPos) { - final int bufferPos = (int) (currentByteBufferPos - currentByteBufferStartPos); - String result = Utf8.decodeUtf8(currentByteBuffer, bufferPos, size); - currentByteBufferPos += size; - return result; - } - if (size >= 0 && size <= remaining()) { - byte[] bytes = new byte[size]; - readRawBytesTo(bytes, 0, size); - return Utf8.decodeUtf8(bytes, 0, size); - } - - if (size == 0) { - return ""; - } - if (size <= 0) { - throw InvalidProtocolBufferException.negativeSize(); - } - throw InvalidProtocolBufferException.truncatedMessage(); - } - - @Override - public void readGroup( - final int fieldNumber, - final MessageLite.Builder builder, - final ExtensionRegistryLite extensionRegistry) - throws IOException { - checkRecursionLimit(); - ++recursionDepth; - builder.mergeFrom(this, extensionRegistry); - checkLastTagWas(WireFormat.makeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP)); - --recursionDepth; - } - - @Override - public T readGroup( - final int fieldNumber, - final Parser parser, - final ExtensionRegistryLite extensionRegistry) - throws IOException { - checkRecursionLimit(); - ++recursionDepth; - T result = parser.parsePartialFrom(this, extensionRegistry); - checkLastTagWas(WireFormat.makeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP)); - --recursionDepth; - return result; - } - - @Deprecated - @Override - public void readUnknownGroup(final int fieldNumber, final MessageLite.Builder builder) - throws IOException { - readGroup(fieldNumber, builder, ExtensionRegistryLite.getEmptyRegistry()); - } - - @Override - public void readMessage( - final MessageLite.Builder builder, final ExtensionRegistryLite extensionRegistry) - throws IOException { - final int length = readRawVarint32(); - checkRecursionLimit(); - final int oldLimit = pushLimit(length); - ++recursionDepth; - builder.mergeFrom(this, extensionRegistry); - checkLastTagWas(0); - --recursionDepth; - if (getBytesUntilLimit() != 0) { - throw InvalidProtocolBufferException.truncatedMessage(); - } - popLimit(oldLimit); - } - - @Override - public T readMessage( - final Parser parser, final ExtensionRegistryLite extensionRegistry) throws IOException { - int length = readRawVarint32(); - checkRecursionLimit(); - final int oldLimit = pushLimit(length); - ++recursionDepth; - T result = parser.parsePartialFrom(this, extensionRegistry); - checkLastTagWas(0); - --recursionDepth; - if (getBytesUntilLimit() != 0) { - throw InvalidProtocolBufferException.truncatedMessage(); - } - popLimit(oldLimit); - return result; - } - - @Override - public ByteString readBytes() throws IOException { - final int size = readRawVarint32(); - if (size > 0 && size <= currentByteBufferLimit - currentByteBufferPos) { - if (immutable && enableAliasing) { - final int idx = (int) (currentByteBufferPos - currentAddress); - final ByteString result = ByteString.wrap(slice(idx, idx + size)); - currentByteBufferPos += size; - return result; - } else { - byte[] bytes = new byte[size]; - UnsafeUtil.copyMemory(currentByteBufferPos, bytes, 0, size); - currentByteBufferPos += size; - return ByteString.wrap(bytes); - } - } else if (size > 0 && size <= remaining()) { - if (immutable && enableAliasing) { - ArrayList byteStrings = new ArrayList<>(); - int l = size; - while (l > 0) { - if (currentRemaining() == 0) { - getNextByteBuffer(); - } - int bytesToCopy = Math.min(l, (int) currentRemaining()); - int idx = (int) (currentByteBufferPos - currentAddress); - byteStrings.add(ByteString.wrap(slice(idx, idx + bytesToCopy))); - l -= bytesToCopy; - currentByteBufferPos += bytesToCopy; - } - return ByteString.copyFrom(byteStrings); - } else { - byte[] temp = new byte[size]; - readRawBytesTo(temp, 0, size); - return ByteString.wrap(temp); - } - } - - if (size == 0) { - return ByteString.EMPTY; - } - if (size < 0) { - throw InvalidProtocolBufferException.negativeSize(); - } - throw InvalidProtocolBufferException.truncatedMessage(); - } - - @Override - public byte[] readByteArray() throws IOException { - return readRawBytes(readRawVarint32()); - } - - @Override - public ByteBuffer readByteBuffer() throws IOException { - final int size = readRawVarint32(); - if (size > 0 && size <= currentRemaining()) { - if (!immutable && enableAliasing) { - currentByteBufferPos += size; - return slice( - (int) (currentByteBufferPos - currentAddress - size), - (int) (currentByteBufferPos - currentAddress)); - } else { - byte[] bytes = new byte[size]; - UnsafeUtil.copyMemory(currentByteBufferPos, bytes, 0, size); - currentByteBufferPos += size; - return ByteBuffer.wrap(bytes); - } - } else if (size > 0 && size <= remaining()) { - byte[] temp = new byte[size]; - readRawBytesTo(temp, 0, size); - return ByteBuffer.wrap(temp); - } - - if (size == 0) { - return EMPTY_BYTE_BUFFER; - } - if (size < 0) { - throw InvalidProtocolBufferException.negativeSize(); - } - throw InvalidProtocolBufferException.truncatedMessage(); - } - - @Override - public int readUInt32() throws IOException { - return readRawVarint32(); - } - - @Override - public int readEnum() throws IOException { - return readRawVarint32(); - } - - @Override - public int readSFixed32() throws IOException { - return readRawLittleEndian32(); - } - - @Override - public long readSFixed64() throws IOException { - return readRawLittleEndian64(); - } - - @Override - public int readSInt32() throws IOException { - return decodeZigZag32(readRawVarint32()); - } - - @Override - public long readSInt64() throws IOException { - return decodeZigZag64(readRawVarint64()); - } - - @Override - public int readRawVarint32() throws IOException { - fastpath: - { - long tempPos = currentByteBufferPos; - - if (currentByteBufferLimit == currentByteBufferPos) { - break fastpath; - } - - int x; - if ((x = UnsafeUtil.getByte(tempPos++)) >= 0) { - currentByteBufferPos++; - return x; - } else if (currentByteBufferLimit - currentByteBufferPos < 10) { - break fastpath; - } else if ((x ^= (UnsafeUtil.getByte(tempPos++) << 7)) < 0) { - x ^= (~0 << 7); - } else if ((x ^= (UnsafeUtil.getByte(tempPos++) << 14)) >= 0) { - x ^= (~0 << 7) ^ (~0 << 14); - } else if ((x ^= (UnsafeUtil.getByte(tempPos++) << 21)) < 0) { - x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21); - } else { - int y = UnsafeUtil.getByte(tempPos++); - x ^= y << 28; - x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21) ^ (~0 << 28); - if (y < 0 - && UnsafeUtil.getByte(tempPos++) < 0 - && UnsafeUtil.getByte(tempPos++) < 0 - && UnsafeUtil.getByte(tempPos++) < 0 - && UnsafeUtil.getByte(tempPos++) < 0 - && UnsafeUtil.getByte(tempPos++) < 0) { - break fastpath; // Will throw malformedVarint() - } - } - currentByteBufferPos = tempPos; - return x; - } - return (int) readRawVarint64SlowPath(); - } - - @Override - public long readRawVarint64() throws IOException { - fastpath: - { - long tempPos = currentByteBufferPos; - - if (currentByteBufferLimit == currentByteBufferPos) { - break fastpath; - } - - long x; - int y; - if ((y = UnsafeUtil.getByte(tempPos++)) >= 0) { - currentByteBufferPos++; - return y; - } else if (currentByteBufferLimit - currentByteBufferPos < 10) { - break fastpath; - } else if ((y ^= (UnsafeUtil.getByte(tempPos++) << 7)) < 0) { - x = y ^ (~0 << 7); - } else if ((y ^= (UnsafeUtil.getByte(tempPos++) << 14)) >= 0) { - x = y ^ ((~0 << 7) ^ (~0 << 14)); - } else if ((y ^= (UnsafeUtil.getByte(tempPos++) << 21)) < 0) { - x = y ^ ((~0 << 7) ^ (~0 << 14) ^ (~0 << 21)); - } else if ((x = y ^ ((long) UnsafeUtil.getByte(tempPos++) << 28)) >= 0L) { - x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28); - } else if ((x ^= ((long) UnsafeUtil.getByte(tempPos++) << 35)) < 0L) { - x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35); - } else if ((x ^= ((long) UnsafeUtil.getByte(tempPos++) << 42)) >= 0L) { - x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35) ^ (~0L << 42); - } else if ((x ^= ((long) UnsafeUtil.getByte(tempPos++) << 49)) < 0L) { - x ^= - (~0L << 7) - ^ (~0L << 14) - ^ (~0L << 21) - ^ (~0L << 28) - ^ (~0L << 35) - ^ (~0L << 42) - ^ (~0L << 49); - } else { - x ^= ((long) UnsafeUtil.getByte(tempPos++) << 56); - x ^= - (~0L << 7) - ^ (~0L << 14) - ^ (~0L << 21) - ^ (~0L << 28) - ^ (~0L << 35) - ^ (~0L << 42) - ^ (~0L << 49) - ^ (~0L << 56); - if (x < 0L) { - if (UnsafeUtil.getByte(tempPos++) < 0L) { - break fastpath; // Will throw malformedVarint() - } - } - } - currentByteBufferPos = tempPos; - return x; - } - return readRawVarint64SlowPath(); - } - - @Override - long readRawVarint64SlowPath() throws IOException { - long result = 0; - for (int shift = 0; shift < 64; shift += 7) { - final byte b = readRawByte(); - result |= (long) (b & 0x7F) << shift; - if ((b & 0x80) == 0) { - return result; - } - } - throw InvalidProtocolBufferException.malformedVarint(); - } - - @Override - public int readRawLittleEndian32() throws IOException { - if (currentRemaining() >= FIXED32_SIZE) { - long tempPos = currentByteBufferPos; - currentByteBufferPos += FIXED32_SIZE; - return ((UnsafeUtil.getByte(tempPos) & 0xff) - | ((UnsafeUtil.getByte(tempPos + 1) & 0xff) << 8) - | ((UnsafeUtil.getByte(tempPos + 2) & 0xff) << 16) - | ((UnsafeUtil.getByte(tempPos + 3) & 0xff) << 24)); - } - return ((readRawByte() & 0xff) - | ((readRawByte() & 0xff) << 8) - | ((readRawByte() & 0xff) << 16) - | ((readRawByte() & 0xff) << 24)); - } - - @Override - public long readRawLittleEndian64() throws IOException { - if (currentRemaining() >= FIXED64_SIZE) { - long tempPos = currentByteBufferPos; - currentByteBufferPos += FIXED64_SIZE; - return ((UnsafeUtil.getByte(tempPos) & 0xffL) - | ((UnsafeUtil.getByte(tempPos + 1) & 0xffL) << 8) - | ((UnsafeUtil.getByte(tempPos + 2) & 0xffL) << 16) - | ((UnsafeUtil.getByte(tempPos + 3) & 0xffL) << 24) - | ((UnsafeUtil.getByte(tempPos + 4) & 0xffL) << 32) - | ((UnsafeUtil.getByte(tempPos + 5) & 0xffL) << 40) - | ((UnsafeUtil.getByte(tempPos + 6) & 0xffL) << 48) - | ((UnsafeUtil.getByte(tempPos + 7) & 0xffL) << 56)); - } - return ((readRawByte() & 0xffL) - | ((readRawByte() & 0xffL) << 8) - | ((readRawByte() & 0xffL) << 16) - | ((readRawByte() & 0xffL) << 24) - | ((readRawByte() & 0xffL) << 32) - | ((readRawByte() & 0xffL) << 40) - | ((readRawByte() & 0xffL) << 48) - | ((readRawByte() & 0xffL) << 56)); - } - - @Override - public void enableAliasing(boolean enabled) { - this.enableAliasing = enabled; - } - - @Override - public void resetSizeCounter() { - startOffset = (int) (totalBytesRead + currentByteBufferPos - currentByteBufferStartPos); - } - - @Override - public int pushLimit(int byteLimit) throws InvalidProtocolBufferException { - if (byteLimit < 0) { - throw InvalidProtocolBufferException.negativeSize(); - } - byteLimit += getTotalBytesRead(); - final int oldLimit = currentLimit; - if (byteLimit > oldLimit) { - throw InvalidProtocolBufferException.truncatedMessage(); - } - currentLimit = byteLimit; - - recomputeBufferSizeAfterLimit(); - - return oldLimit; - } - - private void recomputeBufferSizeAfterLimit() { - totalBufferSize += bufferSizeAfterCurrentLimit; - final int bufferEnd = totalBufferSize - startOffset; - if (bufferEnd > currentLimit) { - // Limit is in current buffer. - bufferSizeAfterCurrentLimit = bufferEnd - currentLimit; - totalBufferSize -= bufferSizeAfterCurrentLimit; - } else { - bufferSizeAfterCurrentLimit = 0; - } - } - - @Override - public void popLimit(final int oldLimit) { - currentLimit = oldLimit; - recomputeBufferSizeAfterLimit(); - } - - @Override - public int getBytesUntilLimit() { - if (currentLimit == Integer.MAX_VALUE) { - return -1; - } - - return currentLimit - getTotalBytesRead(); - } - - @Override - public boolean isAtEnd() throws IOException { - return totalBytesRead + currentByteBufferPos - currentByteBufferStartPos == totalBufferSize; - } - - @Override - public int getTotalBytesRead() { - return (int) - (totalBytesRead - startOffset + currentByteBufferPos - currentByteBufferStartPos); - } - - @Override - public byte readRawByte() throws IOException { - if (currentRemaining() == 0) { - getNextByteBuffer(); - } - return UnsafeUtil.getByte(currentByteBufferPos++); - } - - @Override - public byte[] readRawBytes(final int length) throws IOException { - if (length >= 0 && length <= currentRemaining()) { - byte[] bytes = new byte[length]; - UnsafeUtil.copyMemory(currentByteBufferPos, bytes, 0, length); - currentByteBufferPos += length; - return bytes; - } - if (length >= 0 && length <= remaining()) { - byte[] bytes = new byte[length]; - readRawBytesTo(bytes, 0, length); - return bytes; - } - - if (length <= 0) { - if (length == 0) { - return EMPTY_BYTE_ARRAY; - } else { - throw InvalidProtocolBufferException.negativeSize(); - } - } - - throw InvalidProtocolBufferException.truncatedMessage(); - } - - /** - * Try to get raw bytes from {@code input} with the size of {@code length} and copy to {@code - * bytes} array. If the size is bigger than the number of remaining bytes in the input, then - * throw {@code truncatedMessage} exception. - */ - private void readRawBytesTo(byte[] bytes, int offset, final int length) throws IOException { - if (length >= 0 && length <= remaining()) { - int l = length; - while (l > 0) { - if (currentRemaining() == 0) { - getNextByteBuffer(); - } - int bytesToCopy = Math.min(l, (int) currentRemaining()); - UnsafeUtil.copyMemory(currentByteBufferPos, bytes, length - l + offset, bytesToCopy); - l -= bytesToCopy; - currentByteBufferPos += bytesToCopy; - } - return; - } - - if (length <= 0) { - if (length == 0) { - return; - } else { - throw InvalidProtocolBufferException.negativeSize(); - } - } - throw InvalidProtocolBufferException.truncatedMessage(); - } - - @Override - public void skipRawBytes(final int length) throws IOException { - if (length >= 0 - && length - <= (totalBufferSize - - totalBytesRead - - currentByteBufferPos - + currentByteBufferStartPos)) { - // We have all the bytes we need already. - int l = length; - while (l > 0) { - if (currentRemaining() == 0) { - getNextByteBuffer(); - } - int rl = Math.min(l, (int) currentRemaining()); - l -= rl; - currentByteBufferPos += rl; - } - return; - } - - if (length < 0) { - throw InvalidProtocolBufferException.negativeSize(); - } - throw InvalidProtocolBufferException.truncatedMessage(); - } - - // TODO: optimize to fastpath - private void skipRawVarint() throws IOException { - for (int i = 0; i < MAX_VARINT_SIZE; i++) { - if (readRawByte() >= 0) { - return; - } - } - throw InvalidProtocolBufferException.malformedVarint(); - } - - /** - * Try to get the number of remaining bytes in {@code input}. - * - * @return the number of remaining bytes in {@code input}. - */ - private int remaining() { - return (int) - (totalBufferSize - totalBytesRead - currentByteBufferPos + currentByteBufferStartPos); - } - - /** - * Try to get the number of remaining bytes in {@code currentByteBuffer}. - * - * @return the number of remaining bytes in {@code currentByteBuffer} - */ - private long currentRemaining() { - return (currentByteBufferLimit - currentByteBufferPos); - } - - private ByteBuffer slice(int begin, int end) throws IOException { - int prevPos = currentByteBuffer.position(); - int prevLimit = currentByteBuffer.limit(); - // View ByteBuffer as Buffer to avoid cross-Java version issues. - // See https://issues.apache.org/jira/browse/MRESOLVER-85 - Buffer asBuffer = currentByteBuffer; - try { - asBuffer.position(begin); - asBuffer.limit(end); - return currentByteBuffer.slice(); - } catch (IllegalArgumentException e) { - throw InvalidProtocolBufferException.truncatedMessage(); - } finally { - asBuffer.position(prevPos); - asBuffer.limit(prevLimit); - } - } - } } diff --git a/protobuf-api/src/main/java/com/google/protobuf/CodedOutputStream.java b/protobuf-api/src/main/java/com/google/protobuf/CodedOutputStream.java index 8a31d31..90ffcb5 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/CodedOutputStream.java +++ b/protobuf-api/src/main/java/com/google/protobuf/CodedOutputStream.java @@ -36,7 +36,6 @@ public abstract class CodedOutputStream extends ByteOutput { private static final Logger logger = Logger.getLogger(CodedOutputStream.class.getName()); static final boolean HAS_UNSAFE_ARRAY_OPERATIONS = UnsafeUtil.hasUnsafeArrayOperations(); private static final Class ARRAY_ENCODER = getClassForName("com.google.protobuf.ArrayEncoder"); - private static final Class ABSTRACT_BUFFERED_ENCODER = getClassForName("com.google.protobuf.AbstractBufferedEncoder"); private static final Class BYTE_OUTPUT_ENCODER = getClassForName("com.google.protobuf.ByteOutputEncoder"); private static final Class HEAP_NIO_ENCODER = getClassForName("com.google.protobuf.HeapNioEncoder"); private static final Class OUTPUT_STREAM_ENCODER = getClassForName("com.google.protobuf.OutputStreamEncoder"); diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/ArrayDecoder.java b/protobuf-sdk/src/main/java/com/google/protobuf/ArrayDecoder.java new file mode 100644 index 0000000..f61f939 --- /dev/null +++ b/protobuf-sdk/src/main/java/com/google/protobuf/ArrayDecoder.java @@ -0,0 +1,672 @@ +package com.google.protobuf; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.Arrays; + +import static com.google.protobuf.Internal.EMPTY_BYTE_BUFFER; +import static com.google.protobuf.Internal.UTF_8; +import static com.google.protobuf.WireFormat.*; +import static com.google.protobuf.WireFormat.FIXED64_SIZE; + + +/** A {@link CodedInputStream} implementation that uses a backing array as the input. */ +final class ArrayDecoder extends CodedInputStream { + private final byte[] buffer; + private final boolean immutable; + private int limit; + private int bufferSizeAfterLimit; + private int pos; + private int startPos; + private int lastTag; + private boolean enableAliasing; + + /** The absolute position of the end of the current message. */ + private int currentLimit = Integer.MAX_VALUE; + + ArrayDecoder(final byte[] buffer, final int offset, final int len, boolean immutable) { + super(); + this.buffer = buffer; + limit = offset + len; + pos = offset; + startPos = pos; + this.immutable = immutable; + } + + @Override + public int readTag() throws IOException { + if (isAtEnd()) { + lastTag = 0; + return 0; + } + + lastTag = readRawVarint32(); + if (WireFormat.getTagFieldNumber(lastTag) == 0) { + // If we actually read zero (or any tag number corresponding to field + // number zero), that's not a valid tag. + throw InvalidProtocolBufferException.invalidTag(); + } + return lastTag; + } + + @Override + public void checkLastTagWas(final int value) throws InvalidProtocolBufferException { + if (lastTag != value) { + throw InvalidProtocolBufferException.invalidEndTag(); + } + } + + @Override + public int getLastTag() { + return lastTag; + } + + @Override + public boolean skipField(final int tag) throws IOException { + switch (WireFormat.getTagWireType(tag)) { + case WireFormat.WIRETYPE_VARINT: + skipRawVarint(); + return true; + case WireFormat.WIRETYPE_FIXED64: + skipRawBytes(FIXED64_SIZE); + return true; + case WireFormat.WIRETYPE_LENGTH_DELIMITED: + skipRawBytes(readRawVarint32()); + return true; + case WireFormat.WIRETYPE_START_GROUP: + skipMessage(); + checkLastTagWas( + WireFormat.makeTag(WireFormat.getTagFieldNumber(tag), WireFormat.WIRETYPE_END_GROUP)); + return true; + case WireFormat.WIRETYPE_END_GROUP: + return false; + case WireFormat.WIRETYPE_FIXED32: + skipRawBytes(FIXED32_SIZE); + return true; + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + + @Override + public boolean skipField(final int tag, final CodedOutputStream output) throws IOException { + switch (WireFormat.getTagWireType(tag)) { + case WireFormat.WIRETYPE_VARINT: + { + long value = readInt64(); + output.writeUInt32NoTag(tag); + output.writeUInt64NoTag(value); + return true; + } + case WireFormat.WIRETYPE_FIXED64: + { + long value = readRawLittleEndian64(); + output.writeUInt32NoTag(tag); + output.writeFixed64NoTag(value); + return true; + } + case WireFormat.WIRETYPE_LENGTH_DELIMITED: + { + ByteString value = readBytes(); + output.writeUInt32NoTag(tag); + output.writeBytesNoTag(value); + return true; + } + case WireFormat.WIRETYPE_START_GROUP: + { + output.writeUInt32NoTag(tag); + skipMessage(output); + int endtag = + WireFormat.makeTag( + WireFormat.getTagFieldNumber(tag), WireFormat.WIRETYPE_END_GROUP); + checkLastTagWas(endtag); + output.writeUInt32NoTag(endtag); + return true; + } + case WireFormat.WIRETYPE_END_GROUP: + { + return false; + } + case WireFormat.WIRETYPE_FIXED32: + { + int value = readRawLittleEndian32(); + output.writeUInt32NoTag(tag); + output.writeFixed32NoTag(value); + return true; + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + + // ----------------------------------------------------------------- + + @Override + public double readDouble() throws IOException { + return Double.longBitsToDouble(readRawLittleEndian64()); + } + + @Override + public float readFloat() throws IOException { + return Float.intBitsToFloat(readRawLittleEndian32()); + } + + @Override + public long readUInt64() throws IOException { + return readRawVarint64(); + } + + @Override + public long readInt64() throws IOException { + return readRawVarint64(); + } + + @Override + public int readInt32() throws IOException { + return readRawVarint32(); + } + + @Override + public long readFixed64() throws IOException { + return readRawLittleEndian64(); + } + + @Override + public int readFixed32() throws IOException { + return readRawLittleEndian32(); + } + + @Override + public boolean readBool() throws IOException { + return readRawVarint64() != 0; + } + + @Override + public String readString() throws IOException { + final int size = readRawVarint32(); + if (size > 0 && size <= (limit - pos)) { + // Fast path: We already have the bytes in a contiguous buffer, so + // just copy directly from it. + final String result = new String(buffer, pos, size, UTF_8); + pos += size; + return result; + } + + if (size == 0) { + return ""; + } + if (size < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + throw InvalidProtocolBufferException.truncatedMessage(); + } + + @Override + public String readStringRequireUtf8() throws IOException { + final int size = readRawVarint32(); + if (size > 0 && size <= (limit - pos)) { + String result = Utf8.decodeUtf8(buffer, pos, size); + pos += size; + return result; + } + + if (size == 0) { + return ""; + } + if (size <= 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + throw InvalidProtocolBufferException.truncatedMessage(); + } + + @Override + public void readGroup( + final int fieldNumber, + final MessageLite.Builder builder, + final ExtensionRegistryLite extensionRegistry) + throws IOException { + checkRecursionLimit(); + ++recursionDepth; + builder.mergeFrom(this, extensionRegistry); + checkLastTagWas(WireFormat.makeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP)); + --recursionDepth; + } + + @Override + public T readGroup( + final int fieldNumber, + final Parser parser, + final ExtensionRegistryLite extensionRegistry) + throws IOException { + checkRecursionLimit(); + ++recursionDepth; + T result = parser.parsePartialFrom(this, extensionRegistry); + checkLastTagWas(WireFormat.makeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP)); + --recursionDepth; + return result; + } + + @Deprecated + @Override + public void readUnknownGroup(final int fieldNumber, final MessageLite.Builder builder) + throws IOException { + readGroup(fieldNumber, builder, ExtensionRegistryLite.getEmptyRegistry()); + } + + @Override + public void readMessage( + final MessageLite.Builder builder, final ExtensionRegistryLite extensionRegistry) + throws IOException { + final int length = readRawVarint32(); + checkRecursionLimit(); + final int oldLimit = pushLimit(length); + ++recursionDepth; + builder.mergeFrom(this, extensionRegistry); + checkLastTagWas(0); + --recursionDepth; + if (getBytesUntilLimit() != 0) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + popLimit(oldLimit); + } + + @Override + public T readMessage( + final Parser parser, final ExtensionRegistryLite extensionRegistry) throws IOException { + int length = readRawVarint32(); + checkRecursionLimit(); + final int oldLimit = pushLimit(length); + ++recursionDepth; + T result = parser.parsePartialFrom(this, extensionRegistry); + checkLastTagWas(0); + --recursionDepth; + if (getBytesUntilLimit() != 0) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + popLimit(oldLimit); + return result; + } + + @Override + public ByteString readBytes() throws IOException { + final int size = readRawVarint32(); + if (size > 0 && size <= (limit - pos)) { + // Fast path: We already have the bytes in a contiguous buffer, so + // just copy directly from it. + final ByteString result = + immutable && enableAliasing + ? ByteString.wrap(buffer, pos, size) + : ByteString.copyFrom(buffer, pos, size); + pos += size; + return result; + } + if (size == 0) { + return ByteString.EMPTY; + } + // Slow path: Build a byte array first then copy it. + return ByteString.wrap(readRawBytes(size)); + } + + @Override + public byte[] readByteArray() throws IOException { + final int size = readRawVarint32(); + return readRawBytes(size); + } + + @Override + public ByteBuffer readByteBuffer() throws IOException { + final int size = readRawVarint32(); + if (size > 0 && size <= (limit - pos)) { + // Fast path: We already have the bytes in a contiguous buffer. + // When aliasing is enabled, we can return a ByteBuffer pointing directly + // into the underlying byte array without copy if the CodedInputStream is + // constructed from a byte array. If aliasing is disabled or the input is + // from an InputStream or ByteString, we have to make a copy of the bytes. + ByteBuffer result = + !immutable && enableAliasing + ? ByteBuffer.wrap(buffer, pos, size).slice() + : ByteBuffer.wrap(Arrays.copyOfRange(buffer, pos, pos + size)); + pos += size; + // TODO: Investigate making the ByteBuffer be made read-only + return result; + } + + if (size == 0) { + return EMPTY_BYTE_BUFFER; + } + if (size < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + throw InvalidProtocolBufferException.truncatedMessage(); + } + + @Override + public int readUInt32() throws IOException { + return readRawVarint32(); + } + + @Override + public int readEnum() throws IOException { + return readRawVarint32(); + } + + @Override + public int readSFixed32() throws IOException { + return readRawLittleEndian32(); + } + + @Override + public long readSFixed64() throws IOException { + return readRawLittleEndian64(); + } + + @Override + public int readSInt32() throws IOException { + return decodeZigZag32(readRawVarint32()); + } + + @Override + public long readSInt64() throws IOException { + return decodeZigZag64(readRawVarint64()); + } + + // ================================================================= + + @Override + public int readRawVarint32() throws IOException { + // See implementation notes for readRawVarint64 + fastpath: + { + int tempPos = pos; + + if (limit == tempPos) { + break fastpath; + } + + final byte[] buffer = this.buffer; + int x; + if ((x = buffer[tempPos++]) >= 0) { + pos = tempPos; + return x; + } else if (limit - tempPos < 9) { + break fastpath; + } else if ((x ^= (buffer[tempPos++] << 7)) < 0) { + x ^= (~0 << 7); + } else if ((x ^= (buffer[tempPos++] << 14)) >= 0) { + x ^= (~0 << 7) ^ (~0 << 14); + } else if ((x ^= (buffer[tempPos++] << 21)) < 0) { + x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21); + } else { + int y = buffer[tempPos++]; + x ^= y << 28; + x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21) ^ (~0 << 28); + if (y < 0 + && buffer[tempPos++] < 0 + && buffer[tempPos++] < 0 + && buffer[tempPos++] < 0 + && buffer[tempPos++] < 0 + && buffer[tempPos++] < 0) { + break fastpath; // Will throw malformedVarint() + } + } + pos = tempPos; + return x; + } + return (int) readRawVarint64SlowPath(); + } + + private void skipRawVarint() throws IOException { + if (limit - pos >= MAX_VARINT_SIZE) { + skipRawVarintFastPath(); + } else { + skipRawVarintSlowPath(); + } + } + + private void skipRawVarintFastPath() throws IOException { + for (int i = 0; i < MAX_VARINT_SIZE; i++) { + if (buffer[pos++] >= 0) { + return; + } + } + throw InvalidProtocolBufferException.malformedVarint(); + } + + private void skipRawVarintSlowPath() throws IOException { + for (int i = 0; i < MAX_VARINT_SIZE; i++) { + if (readRawByte() >= 0) { + return; + } + } + throw InvalidProtocolBufferException.malformedVarint(); + } + + @Override + public long readRawVarint64() throws IOException { + // Implementation notes: + // + // Optimized for one-byte values, expected to be common. + // The particular code below was selected from various candidates + // empirically, by winning VarintBenchmark. + // + // Sign extension of (signed) Java bytes is usually a nuisance, but + // we exploit it here to more easily obtain the sign of bytes read. + // Instead of cleaning up the sign extension bits by masking eagerly, + // we delay until we find the final (positive) byte, when we clear all + // accumulated bits with one xor. We depend on javac to constant fold. + fastpath: + { + int tempPos = pos; + + if (limit == tempPos) { + break fastpath; + } + + final byte[] buffer = this.buffer; + long x; + int y; + if ((y = buffer[tempPos++]) >= 0) { + pos = tempPos; + return y; + } else if (limit - tempPos < 9) { + break fastpath; + } else if ((y ^= (buffer[tempPos++] << 7)) < 0) { + x = y ^ (~0 << 7); + } else if ((y ^= (buffer[tempPos++] << 14)) >= 0) { + x = y ^ ((~0 << 7) ^ (~0 << 14)); + } else if ((y ^= (buffer[tempPos++] << 21)) < 0) { + x = y ^ ((~0 << 7) ^ (~0 << 14) ^ (~0 << 21)); + } else if ((x = y ^ ((long) buffer[tempPos++] << 28)) >= 0L) { + x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28); + } else if ((x ^= ((long) buffer[tempPos++] << 35)) < 0L) { + x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35); + } else if ((x ^= ((long) buffer[tempPos++] << 42)) >= 0L) { + x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35) ^ (~0L << 42); + } else if ((x ^= ((long) buffer[tempPos++] << 49)) < 0L) { + x ^= + (~0L << 7) + ^ (~0L << 14) + ^ (~0L << 21) + ^ (~0L << 28) + ^ (~0L << 35) + ^ (~0L << 42) + ^ (~0L << 49); + } else { + x ^= ((long) buffer[tempPos++] << 56); + x ^= + (~0L << 7) + ^ (~0L << 14) + ^ (~0L << 21) + ^ (~0L << 28) + ^ (~0L << 35) + ^ (~0L << 42) + ^ (~0L << 49) + ^ (~0L << 56); + if (x < 0L) { + if (buffer[tempPos++] < 0L) { + break fastpath; // Will throw malformedVarint() + } + } + } + pos = tempPos; + return x; + } + return readRawVarint64SlowPath(); + } + + @Override + long readRawVarint64SlowPath() throws IOException { + long result = 0; + for (int shift = 0; shift < 64; shift += 7) { + final byte b = readRawByte(); + result |= (long) (b & 0x7F) << shift; + if ((b & 0x80) == 0) { + return result; + } + } + throw InvalidProtocolBufferException.malformedVarint(); + } + + @Override + public int readRawLittleEndian32() throws IOException { + int tempPos = pos; + + if (limit - tempPos < FIXED32_SIZE) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + + final byte[] buffer = this.buffer; + pos = tempPos + FIXED32_SIZE; + return ((buffer[tempPos] & 0xff) + | ((buffer[tempPos + 1] & 0xff) << 8) + | ((buffer[tempPos + 2] & 0xff) << 16) + | ((buffer[tempPos + 3] & 0xff) << 24)); + } + + @Override + public long readRawLittleEndian64() throws IOException { + int tempPos = pos; + + if (limit - tempPos < FIXED64_SIZE) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + + final byte[] buffer = this.buffer; + pos = tempPos + FIXED64_SIZE; + return ((buffer[tempPos] & 0xffL) + | ((buffer[tempPos + 1] & 0xffL) << 8) + | ((buffer[tempPos + 2] & 0xffL) << 16) + | ((buffer[tempPos + 3] & 0xffL) << 24) + | ((buffer[tempPos + 4] & 0xffL) << 32) + | ((buffer[tempPos + 5] & 0xffL) << 40) + | ((buffer[tempPos + 6] & 0xffL) << 48) + | ((buffer[tempPos + 7] & 0xffL) << 56)); + } + + @Override + public void enableAliasing(boolean enabled) { + this.enableAliasing = enabled; + } + + @Override + public void resetSizeCounter() { + startPos = pos; + } + + @Override + public int pushLimit(int byteLimit) throws InvalidProtocolBufferException { + if (byteLimit < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + byteLimit += getTotalBytesRead(); + if (byteLimit < 0) { + throw InvalidProtocolBufferException.parseFailure(); + } + final int oldLimit = currentLimit; + if (byteLimit > oldLimit) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + currentLimit = byteLimit; + + recomputeBufferSizeAfterLimit(); + + return oldLimit; + } + + private void recomputeBufferSizeAfterLimit() { + limit += bufferSizeAfterLimit; + final int bufferEnd = limit - startPos; + if (bufferEnd > currentLimit) { + // Limit is in current buffer. + bufferSizeAfterLimit = bufferEnd - currentLimit; + limit -= bufferSizeAfterLimit; + } else { + bufferSizeAfterLimit = 0; + } + } + + @Override + public void popLimit(final int oldLimit) { + currentLimit = oldLimit; + recomputeBufferSizeAfterLimit(); + } + + @Override + public int getBytesUntilLimit() { + if (currentLimit == Integer.MAX_VALUE) { + return -1; + } + + return currentLimit - getTotalBytesRead(); + } + + @Override + public boolean isAtEnd() throws IOException { + return pos == limit; + } + + @Override + public int getTotalBytesRead() { + return pos - startPos; + } + + @Override + public byte readRawByte() throws IOException { + if (pos == limit) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + return buffer[pos++]; + } + + @Override + public byte[] readRawBytes(final int length) throws IOException { + if (length > 0 && length <= (limit - pos)) { + final int tempPos = pos; + pos += length; + return Arrays.copyOfRange(buffer, tempPos, pos); + } + + if (length <= 0) { + if (length == 0) { + return Internal.EMPTY_BYTE_ARRAY; + } else { + throw InvalidProtocolBufferException.negativeSize(); + } + } + throw InvalidProtocolBufferException.truncatedMessage(); + } + + @Override + public void skipRawBytes(final int length) throws IOException { + if (length >= 0 && length <= (limit - pos)) { + // We have all the bytes we need already. + pos += length; + return; + } + + if (length < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + throw InvalidProtocolBufferException.truncatedMessage(); + } +} \ No newline at end of file diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/IterableDirectByteBufferDecoder.java b/protobuf-sdk/src/main/java/com/google/protobuf/IterableDirectByteBufferDecoder.java new file mode 100644 index 0000000..af8e6d9 --- /dev/null +++ b/protobuf-sdk/src/main/java/com/google/protobuf/IterableDirectByteBufferDecoder.java @@ -0,0 +1,835 @@ +package com.google.protobuf; + +import java.io.IOException; +import java.nio.Buffer; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.Iterator; + +import static com.google.protobuf.Internal.*; +import static com.google.protobuf.WireFormat.*; + +/** + * Implementation of {@link CodedInputStream} that uses an {@link Iterable } as the + * data source. Requires the use of {@code sun.misc.Unsafe} to perform fast reads on the buffer. + */ +final class IterableDirectByteBufferDecoder extends CodedInputStream { + /** The object that need to decode. */ + private final Iterable input; + /** The {@link Iterator} with type {@link ByteBuffer} of {@code input} */ + private final Iterator iterator; + /** The current ByteBuffer; */ + private ByteBuffer currentByteBuffer; + /** + * If {@code true}, indicates that all the buffers are backing a {@link ByteString} and are + * therefore considered to be an immutable input source. + */ + private final boolean immutable; + /** + * If {@code true}, indicates that calls to read {@link ByteString} or {@code byte[]} + * may return slices of the underlying buffer, rather than copies. + */ + private boolean enableAliasing; + /** The global total message length limit */ + private int totalBufferSize; + /** The amount of available data in the input beyond {@link #currentLimit}. */ + private int bufferSizeAfterCurrentLimit; + /** The absolute position of the end of the current message. */ + private int currentLimit = Integer.MAX_VALUE; + /** The last tag that was read from this stream. */ + private int lastTag; + /** Total Bytes have been Read from the {@link Iterable} {@link ByteBuffer} */ + private int totalBytesRead; + /** The start position offset of the whole message, used as to reset the totalBytesRead */ + private int startOffset; + /** The current position for current ByteBuffer */ + private long currentByteBufferPos; + + private long currentByteBufferStartPos; + /** + * If the current ByteBuffer is unsafe-direct based, currentAddress is the start address of this + * ByteBuffer; otherwise should be zero. + */ + private long currentAddress; + /** The limit position for current ByteBuffer */ + private long currentByteBufferLimit; + + /** + * The constructor of {@code Iterable} decoder. + * + * @param inputBufs The input data. + * @param size The total size of the input data. + * @param immutableFlag whether the input data is immutable. + */ + IterableDirectByteBufferDecoder( + Iterable inputBufs, int size, boolean immutableFlag) { + totalBufferSize = size; + input = inputBufs; + iterator = input.iterator(); + immutable = immutableFlag; + startOffset = totalBytesRead = 0; + if (size == 0) { + currentByteBuffer = EMPTY_BYTE_BUFFER; + currentByteBufferPos = 0; + currentByteBufferStartPos = 0; + currentByteBufferLimit = 0; + currentAddress = 0; + } else { + tryGetNextByteBuffer(); + } + } + + /** To get the next ByteBuffer from {@code input}, and then update the parameters */ + private void getNextByteBuffer() throws InvalidProtocolBufferException { + if (!iterator.hasNext()) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + tryGetNextByteBuffer(); + } + + private void tryGetNextByteBuffer() { + currentByteBuffer = iterator.next(); + totalBytesRead += (int) (currentByteBufferPos - currentByteBufferStartPos); + currentByteBufferPos = currentByteBuffer.position(); + currentByteBufferStartPos = currentByteBufferPos; + currentByteBufferLimit = currentByteBuffer.limit(); + currentAddress = UnsafeUtil.addressOffset(currentByteBuffer); + currentByteBufferPos += currentAddress; + currentByteBufferStartPos += currentAddress; + currentByteBufferLimit += currentAddress; + } + + @Override + public int readTag() throws IOException { + if (isAtEnd()) { + lastTag = 0; + return 0; + } + + lastTag = readRawVarint32(); + if (WireFormat.getTagFieldNumber(lastTag) == 0) { + // If we actually read zero (or any tag number corresponding to field + // number zero), that's not a valid tag. + throw InvalidProtocolBufferException.invalidTag(); + } + return lastTag; + } + + @Override + public void checkLastTagWas(final int value) throws InvalidProtocolBufferException { + if (lastTag != value) { + throw InvalidProtocolBufferException.invalidEndTag(); + } + } + + @Override + public int getLastTag() { + return lastTag; + } + + @Override + public boolean skipField(final int tag) throws IOException { + switch (WireFormat.getTagWireType(tag)) { + case WireFormat.WIRETYPE_VARINT: + skipRawVarint(); + return true; + case WireFormat.WIRETYPE_FIXED64: + skipRawBytes(FIXED64_SIZE); + return true; + case WireFormat.WIRETYPE_LENGTH_DELIMITED: + skipRawBytes(readRawVarint32()); + return true; + case WireFormat.WIRETYPE_START_GROUP: + skipMessage(); + checkLastTagWas( + WireFormat.makeTag(WireFormat.getTagFieldNumber(tag), WireFormat.WIRETYPE_END_GROUP)); + return true; + case WireFormat.WIRETYPE_END_GROUP: + return false; + case WireFormat.WIRETYPE_FIXED32: + skipRawBytes(FIXED32_SIZE); + return true; + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + + @Override + public boolean skipField(final int tag, final CodedOutputStream output) throws IOException { + switch (WireFormat.getTagWireType(tag)) { + case WireFormat.WIRETYPE_VARINT: + { + long value = readInt64(); + output.writeUInt32NoTag(tag); + output.writeUInt64NoTag(value); + return true; + } + case WireFormat.WIRETYPE_FIXED64: + { + long value = readRawLittleEndian64(); + output.writeUInt32NoTag(tag); + output.writeFixed64NoTag(value); + return true; + } + case WireFormat.WIRETYPE_LENGTH_DELIMITED: + { + ByteString value = readBytes(); + output.writeUInt32NoTag(tag); + output.writeBytesNoTag(value); + return true; + } + case WireFormat.WIRETYPE_START_GROUP: + { + output.writeUInt32NoTag(tag); + skipMessage(output); + int endtag = + WireFormat.makeTag( + WireFormat.getTagFieldNumber(tag), WireFormat.WIRETYPE_END_GROUP); + checkLastTagWas(endtag); + output.writeUInt32NoTag(endtag); + return true; + } + case WireFormat.WIRETYPE_END_GROUP: + { + return false; + } + case WireFormat.WIRETYPE_FIXED32: + { + int value = readRawLittleEndian32(); + output.writeUInt32NoTag(tag); + output.writeFixed32NoTag(value); + return true; + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + + // ----------------------------------------------------------------- + + @Override + public double readDouble() throws IOException { + return Double.longBitsToDouble(readRawLittleEndian64()); + } + + @Override + public float readFloat() throws IOException { + return Float.intBitsToFloat(readRawLittleEndian32()); + } + + @Override + public long readUInt64() throws IOException { + return readRawVarint64(); + } + + @Override + public long readInt64() throws IOException { + return readRawVarint64(); + } + + @Override + public int readInt32() throws IOException { + return readRawVarint32(); + } + + @Override + public long readFixed64() throws IOException { + return readRawLittleEndian64(); + } + + @Override + public int readFixed32() throws IOException { + return readRawLittleEndian32(); + } + + @Override + public boolean readBool() throws IOException { + return readRawVarint64() != 0; + } + + @Override + public String readString() throws IOException { + final int size = readRawVarint32(); + if (size > 0 && size <= currentByteBufferLimit - currentByteBufferPos) { + byte[] bytes = new byte[size]; + UnsafeUtil.copyMemory(currentByteBufferPos, bytes, 0, size); + String result = new String(bytes, UTF_8); + currentByteBufferPos += size; + return result; + } else if (size > 0 && size <= remaining()) { + // TODO: To use an underlying bytes[] instead of allocating a new bytes[] + byte[] bytes = new byte[size]; + readRawBytesTo(bytes, 0, size); + String result = new String(bytes, UTF_8); + return result; + } + + if (size == 0) { + return ""; + } + if (size < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + throw InvalidProtocolBufferException.truncatedMessage(); + } + + @Override + public String readStringRequireUtf8() throws IOException { + final int size = readRawVarint32(); + if (size > 0 && size <= currentByteBufferLimit - currentByteBufferPos) { + final int bufferPos = (int) (currentByteBufferPos - currentByteBufferStartPos); + String result = Utf8.decodeUtf8(currentByteBuffer, bufferPos, size); + currentByteBufferPos += size; + return result; + } + if (size >= 0 && size <= remaining()) { + byte[] bytes = new byte[size]; + readRawBytesTo(bytes, 0, size); + return Utf8.decodeUtf8(bytes, 0, size); + } + + if (size == 0) { + return ""; + } + if (size <= 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + throw InvalidProtocolBufferException.truncatedMessage(); + } + + @Override + public void readGroup( + final int fieldNumber, + final MessageLite.Builder builder, + final ExtensionRegistryLite extensionRegistry) + throws IOException { + checkRecursionLimit(); + ++recursionDepth; + builder.mergeFrom(this, extensionRegistry); + checkLastTagWas(WireFormat.makeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP)); + --recursionDepth; + } + + @Override + public T readGroup( + final int fieldNumber, + final Parser parser, + final ExtensionRegistryLite extensionRegistry) + throws IOException { + checkRecursionLimit(); + ++recursionDepth; + T result = parser.parsePartialFrom(this, extensionRegistry); + checkLastTagWas(WireFormat.makeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP)); + --recursionDepth; + return result; + } + + @Deprecated + @Override + public void readUnknownGroup(final int fieldNumber, final MessageLite.Builder builder) + throws IOException { + readGroup(fieldNumber, builder, ExtensionRegistryLite.getEmptyRegistry()); + } + + @Override + public void readMessage( + final MessageLite.Builder builder, final ExtensionRegistryLite extensionRegistry) + throws IOException { + final int length = readRawVarint32(); + checkRecursionLimit(); + final int oldLimit = pushLimit(length); + ++recursionDepth; + builder.mergeFrom(this, extensionRegistry); + checkLastTagWas(0); + --recursionDepth; + if (getBytesUntilLimit() != 0) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + popLimit(oldLimit); + } + + @Override + public T readMessage( + final Parser parser, final ExtensionRegistryLite extensionRegistry) throws IOException { + int length = readRawVarint32(); + checkRecursionLimit(); + final int oldLimit = pushLimit(length); + ++recursionDepth; + T result = parser.parsePartialFrom(this, extensionRegistry); + checkLastTagWas(0); + --recursionDepth; + if (getBytesUntilLimit() != 0) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + popLimit(oldLimit); + return result; + } + + @Override + public ByteString readBytes() throws IOException { + final int size = readRawVarint32(); + if (size > 0 && size <= currentByteBufferLimit - currentByteBufferPos) { + if (immutable && enableAliasing) { + final int idx = (int) (currentByteBufferPos - currentAddress); + final ByteString result = ByteString.wrap(slice(idx, idx + size)); + currentByteBufferPos += size; + return result; + } else { + byte[] bytes = new byte[size]; + UnsafeUtil.copyMemory(currentByteBufferPos, bytes, 0, size); + currentByteBufferPos += size; + return ByteString.wrap(bytes); + } + } else if (size > 0 && size <= remaining()) { + if (immutable && enableAliasing) { + ArrayList byteStrings = new ArrayList<>(); + int l = size; + while (l > 0) { + if (currentRemaining() == 0) { + getNextByteBuffer(); + } + int bytesToCopy = Math.min(l, (int) currentRemaining()); + int idx = (int) (currentByteBufferPos - currentAddress); + byteStrings.add(ByteString.wrap(slice(idx, idx + bytesToCopy))); + l -= bytesToCopy; + currentByteBufferPos += bytesToCopy; + } + return ByteString.copyFrom(byteStrings); + } else { + byte[] temp = new byte[size]; + readRawBytesTo(temp, 0, size); + return ByteString.wrap(temp); + } + } + + if (size == 0) { + return ByteString.EMPTY; + } + if (size < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + throw InvalidProtocolBufferException.truncatedMessage(); + } + + @Override + public byte[] readByteArray() throws IOException { + return readRawBytes(readRawVarint32()); + } + + @Override + public ByteBuffer readByteBuffer() throws IOException { + final int size = readRawVarint32(); + if (size > 0 && size <= currentRemaining()) { + if (!immutable && enableAliasing) { + currentByteBufferPos += size; + return slice( + (int) (currentByteBufferPos - currentAddress - size), + (int) (currentByteBufferPos - currentAddress)); + } else { + byte[] bytes = new byte[size]; + UnsafeUtil.copyMemory(currentByteBufferPos, bytes, 0, size); + currentByteBufferPos += size; + return ByteBuffer.wrap(bytes); + } + } else if (size > 0 && size <= remaining()) { + byte[] temp = new byte[size]; + readRawBytesTo(temp, 0, size); + return ByteBuffer.wrap(temp); + } + + if (size == 0) { + return EMPTY_BYTE_BUFFER; + } + if (size < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + throw InvalidProtocolBufferException.truncatedMessage(); + } + + @Override + public int readUInt32() throws IOException { + return readRawVarint32(); + } + + @Override + public int readEnum() throws IOException { + return readRawVarint32(); + } + + @Override + public int readSFixed32() throws IOException { + return readRawLittleEndian32(); + } + + @Override + public long readSFixed64() throws IOException { + return readRawLittleEndian64(); + } + + @Override + public int readSInt32() throws IOException { + return decodeZigZag32(readRawVarint32()); + } + + @Override + public long readSInt64() throws IOException { + return decodeZigZag64(readRawVarint64()); + } + + @Override + public int readRawVarint32() throws IOException { + fastpath: + { + long tempPos = currentByteBufferPos; + + if (currentByteBufferLimit == currentByteBufferPos) { + break fastpath; + } + + int x; + if ((x = UnsafeUtil.getByte(tempPos++)) >= 0) { + currentByteBufferPos++; + return x; + } else if (currentByteBufferLimit - currentByteBufferPos < 10) { + break fastpath; + } else if ((x ^= (UnsafeUtil.getByte(tempPos++) << 7)) < 0) { + x ^= (~0 << 7); + } else if ((x ^= (UnsafeUtil.getByte(tempPos++) << 14)) >= 0) { + x ^= (~0 << 7) ^ (~0 << 14); + } else if ((x ^= (UnsafeUtil.getByte(tempPos++) << 21)) < 0) { + x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21); + } else { + int y = UnsafeUtil.getByte(tempPos++); + x ^= y << 28; + x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21) ^ (~0 << 28); + if (y < 0 + && UnsafeUtil.getByte(tempPos++) < 0 + && UnsafeUtil.getByte(tempPos++) < 0 + && UnsafeUtil.getByte(tempPos++) < 0 + && UnsafeUtil.getByte(tempPos++) < 0 + && UnsafeUtil.getByte(tempPos++) < 0) { + break fastpath; // Will throw malformedVarint() + } + } + currentByteBufferPos = tempPos; + return x; + } + return (int) readRawVarint64SlowPath(); + } + + @Override + public long readRawVarint64() throws IOException { + fastpath: + { + long tempPos = currentByteBufferPos; + + if (currentByteBufferLimit == currentByteBufferPos) { + break fastpath; + } + + long x; + int y; + if ((y = UnsafeUtil.getByte(tempPos++)) >= 0) { + currentByteBufferPos++; + return y; + } else if (currentByteBufferLimit - currentByteBufferPos < 10) { + break fastpath; + } else if ((y ^= (UnsafeUtil.getByte(tempPos++) << 7)) < 0) { + x = y ^ (~0 << 7); + } else if ((y ^= (UnsafeUtil.getByte(tempPos++) << 14)) >= 0) { + x = y ^ ((~0 << 7) ^ (~0 << 14)); + } else if ((y ^= (UnsafeUtil.getByte(tempPos++) << 21)) < 0) { + x = y ^ ((~0 << 7) ^ (~0 << 14) ^ (~0 << 21)); + } else if ((x = y ^ ((long) UnsafeUtil.getByte(tempPos++) << 28)) >= 0L) { + x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28); + } else if ((x ^= ((long) UnsafeUtil.getByte(tempPos++) << 35)) < 0L) { + x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35); + } else if ((x ^= ((long) UnsafeUtil.getByte(tempPos++) << 42)) >= 0L) { + x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35) ^ (~0L << 42); + } else if ((x ^= ((long) UnsafeUtil.getByte(tempPos++) << 49)) < 0L) { + x ^= + (~0L << 7) + ^ (~0L << 14) + ^ (~0L << 21) + ^ (~0L << 28) + ^ (~0L << 35) + ^ (~0L << 42) + ^ (~0L << 49); + } else { + x ^= ((long) UnsafeUtil.getByte(tempPos++) << 56); + x ^= + (~0L << 7) + ^ (~0L << 14) + ^ (~0L << 21) + ^ (~0L << 28) + ^ (~0L << 35) + ^ (~0L << 42) + ^ (~0L << 49) + ^ (~0L << 56); + if (x < 0L) { + if (UnsafeUtil.getByte(tempPos++) < 0L) { + break fastpath; // Will throw malformedVarint() + } + } + } + currentByteBufferPos = tempPos; + return x; + } + return readRawVarint64SlowPath(); + } + + @Override + long readRawVarint64SlowPath() throws IOException { + long result = 0; + for (int shift = 0; shift < 64; shift += 7) { + final byte b = readRawByte(); + result |= (long) (b & 0x7F) << shift; + if ((b & 0x80) == 0) { + return result; + } + } + throw InvalidProtocolBufferException.malformedVarint(); + } + + @Override + public int readRawLittleEndian32() throws IOException { + if (currentRemaining() >= FIXED32_SIZE) { + long tempPos = currentByteBufferPos; + currentByteBufferPos += FIXED32_SIZE; + return ((UnsafeUtil.getByte(tempPos) & 0xff) + | ((UnsafeUtil.getByte(tempPos + 1) & 0xff) << 8) + | ((UnsafeUtil.getByte(tempPos + 2) & 0xff) << 16) + | ((UnsafeUtil.getByte(tempPos + 3) & 0xff) << 24)); + } + return ((readRawByte() & 0xff) + | ((readRawByte() & 0xff) << 8) + | ((readRawByte() & 0xff) << 16) + | ((readRawByte() & 0xff) << 24)); + } + + @Override + public long readRawLittleEndian64() throws IOException { + if (currentRemaining() >= FIXED64_SIZE) { + long tempPos = currentByteBufferPos; + currentByteBufferPos += FIXED64_SIZE; + return ((UnsafeUtil.getByte(tempPos) & 0xffL) + | ((UnsafeUtil.getByte(tempPos + 1) & 0xffL) << 8) + | ((UnsafeUtil.getByte(tempPos + 2) & 0xffL) << 16) + | ((UnsafeUtil.getByte(tempPos + 3) & 0xffL) << 24) + | ((UnsafeUtil.getByte(tempPos + 4) & 0xffL) << 32) + | ((UnsafeUtil.getByte(tempPos + 5) & 0xffL) << 40) + | ((UnsafeUtil.getByte(tempPos + 6) & 0xffL) << 48) + | ((UnsafeUtil.getByte(tempPos + 7) & 0xffL) << 56)); + } + return ((readRawByte() & 0xffL) + | ((readRawByte() & 0xffL) << 8) + | ((readRawByte() & 0xffL) << 16) + | ((readRawByte() & 0xffL) << 24) + | ((readRawByte() & 0xffL) << 32) + | ((readRawByte() & 0xffL) << 40) + | ((readRawByte() & 0xffL) << 48) + | ((readRawByte() & 0xffL) << 56)); + } + + @Override + public void enableAliasing(boolean enabled) { + this.enableAliasing = enabled; + } + + @Override + public void resetSizeCounter() { + startOffset = (int) (totalBytesRead + currentByteBufferPos - currentByteBufferStartPos); + } + + @Override + public int pushLimit(int byteLimit) throws InvalidProtocolBufferException { + if (byteLimit < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + byteLimit += getTotalBytesRead(); + final int oldLimit = currentLimit; + if (byteLimit > oldLimit) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + currentLimit = byteLimit; + + recomputeBufferSizeAfterLimit(); + + return oldLimit; + } + + private void recomputeBufferSizeAfterLimit() { + totalBufferSize += bufferSizeAfterCurrentLimit; + final int bufferEnd = totalBufferSize - startOffset; + if (bufferEnd > currentLimit) { + // Limit is in current buffer. + bufferSizeAfterCurrentLimit = bufferEnd - currentLimit; + totalBufferSize -= bufferSizeAfterCurrentLimit; + } else { + bufferSizeAfterCurrentLimit = 0; + } + } + + @Override + public void popLimit(final int oldLimit) { + currentLimit = oldLimit; + recomputeBufferSizeAfterLimit(); + } + + @Override + public int getBytesUntilLimit() { + if (currentLimit == Integer.MAX_VALUE) { + return -1; + } + + return currentLimit - getTotalBytesRead(); + } + + @Override + public boolean isAtEnd() throws IOException { + return totalBytesRead + currentByteBufferPos - currentByteBufferStartPos == totalBufferSize; + } + + @Override + public int getTotalBytesRead() { + return (int) + (totalBytesRead - startOffset + currentByteBufferPos - currentByteBufferStartPos); + } + + @Override + public byte readRawByte() throws IOException { + if (currentRemaining() == 0) { + getNextByteBuffer(); + } + return UnsafeUtil.getByte(currentByteBufferPos++); + } + + @Override + public byte[] readRawBytes(final int length) throws IOException { + if (length >= 0 && length <= currentRemaining()) { + byte[] bytes = new byte[length]; + UnsafeUtil.copyMemory(currentByteBufferPos, bytes, 0, length); + currentByteBufferPos += length; + return bytes; + } + if (length >= 0 && length <= remaining()) { + byte[] bytes = new byte[length]; + readRawBytesTo(bytes, 0, length); + return bytes; + } + + if (length <= 0) { + if (length == 0) { + return EMPTY_BYTE_ARRAY; + } else { + throw InvalidProtocolBufferException.negativeSize(); + } + } + + throw InvalidProtocolBufferException.truncatedMessage(); + } + + /** + * Try to get raw bytes from {@code input} with the size of {@code length} and copy to {@code + * bytes} array. If the size is bigger than the number of remaining bytes in the input, then + * throw {@code truncatedMessage} exception. + */ + private void readRawBytesTo(byte[] bytes, int offset, final int length) throws IOException { + if (length >= 0 && length <= remaining()) { + int l = length; + while (l > 0) { + if (currentRemaining() == 0) { + getNextByteBuffer(); + } + int bytesToCopy = Math.min(l, (int) currentRemaining()); + UnsafeUtil.copyMemory(currentByteBufferPos, bytes, length - l + offset, bytesToCopy); + l -= bytesToCopy; + currentByteBufferPos += bytesToCopy; + } + return; + } + + if (length <= 0) { + if (length == 0) { + return; + } else { + throw InvalidProtocolBufferException.negativeSize(); + } + } + throw InvalidProtocolBufferException.truncatedMessage(); + } + + @Override + public void skipRawBytes(final int length) throws IOException { + if (length >= 0 + && length + <= (totalBufferSize + - totalBytesRead + - currentByteBufferPos + + currentByteBufferStartPos)) { + // We have all the bytes we need already. + int l = length; + while (l > 0) { + if (currentRemaining() == 0) { + getNextByteBuffer(); + } + int rl = Math.min(l, (int) currentRemaining()); + l -= rl; + currentByteBufferPos += rl; + } + return; + } + + if (length < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + throw InvalidProtocolBufferException.truncatedMessage(); + } + + // TODO: optimize to fastpath + private void skipRawVarint() throws IOException { + for (int i = 0; i < MAX_VARINT_SIZE; i++) { + if (readRawByte() >= 0) { + return; + } + } + throw InvalidProtocolBufferException.malformedVarint(); + } + + /** + * Try to get the number of remaining bytes in {@code input}. + * + * @return the number of remaining bytes in {@code input}. + */ + private int remaining() { + return (int) + (totalBufferSize - totalBytesRead - currentByteBufferPos + currentByteBufferStartPos); + } + + /** + * Try to get the number of remaining bytes in {@code currentByteBuffer}. + * + * @return the number of remaining bytes in {@code currentByteBuffer} + */ + private long currentRemaining() { + return (currentByteBufferLimit - currentByteBufferPos); + } + + private ByteBuffer slice(int begin, int end) throws IOException { + int prevPos = currentByteBuffer.position(); + int prevLimit = currentByteBuffer.limit(); + // View ByteBuffer as Buffer to avoid cross-Java version issues. + // See https://issues.apache.org/jira/browse/MRESOLVER-85 + Buffer asBuffer = currentByteBuffer; + try { + asBuffer.position(begin); + asBuffer.limit(end); + return currentByteBuffer.slice(); + } catch (IllegalArgumentException e) { + throw InvalidProtocolBufferException.truncatedMessage(); + } finally { + asBuffer.position(prevPos); + asBuffer.limit(prevLimit); + } + } +} \ No newline at end of file diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/StreamDecoder.java b/protobuf-sdk/src/main/java/com/google/protobuf/StreamDecoder.java new file mode 100644 index 0000000..9ce5786 --- /dev/null +++ b/protobuf-sdk/src/main/java/com/google/protobuf/StreamDecoder.java @@ -0,0 +1,1106 @@ +package com.google.protobuf; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import static com.google.protobuf.Internal.UTF_8; +import static com.google.protobuf.Internal.checkNotNull; +import static com.google.protobuf.WireFormat.*; +import static com.google.protobuf.WireFormat.FIXED64_SIZE; + +/** + * Implementation of {@link CodedInputStream} that uses an {@link InputStream} as the data source. + */ +final class StreamDecoder extends CodedInputStream { + private final InputStream input; + private final byte[] buffer; + /** bufferSize represents how many bytes are currently filled in the buffer */ + private int bufferSize; + + private int bufferSizeAfterLimit; + private int pos; + private int lastTag; + + /** + * The total number of bytes read before the current buffer. The total bytes read up to the + * current position can be computed as {@code totalBytesRetired + pos}. This value may be + * negative if reading started in the middle of the current buffer (e.g. if the constructor that + * takes a byte array and an offset was used). + */ + private int totalBytesRetired; + + /** The absolute position of the end of the current message. */ + private int currentLimit = Integer.MAX_VALUE; + + StreamDecoder(final InputStream input, int bufferSize) { + checkNotNull(input, "input"); + this.input = input; + this.buffer = new byte[bufferSize]; + this.bufferSize = 0; + pos = 0; + totalBytesRetired = 0; + } + + /* + * The following wrapper methods exist so that InvalidProtocolBufferExceptions thrown by the + * InputStream can be differentiated from ones thrown by CodedInputStream itself. Each call to + * an InputStream method that can throw IOException must be wrapped like this. We do this + * because we sometimes need to modify IPBE instances after they are thrown far away from where + * they are thrown (ex. to add unfinished messages) and we use this signal elsewhere in the + * exception catch chain to know when to perform these operations directly or to wrap the + * exception in their own IPBE so the extra information can be communicated without trampling + * downstream information. + */ + private static int read(InputStream input, byte[] data, int offset, int length) + throws IOException { + try { + return input.read(data, offset, length); + } catch (InvalidProtocolBufferException e) { + e.setThrownFromInputStream(); + throw e; + } + } + + private static long skip(InputStream input, long length) throws IOException { + try { + return input.skip(length); + } catch (InvalidProtocolBufferException e) { + e.setThrownFromInputStream(); + throw e; + } + } + + private static int available(InputStream input) throws IOException { + try { + return input.available(); + } catch (InvalidProtocolBufferException e) { + e.setThrownFromInputStream(); + throw e; + } + } + + @Override + public int readTag() throws IOException { + if (isAtEnd()) { + lastTag = 0; + return 0; + } + + lastTag = readRawVarint32(); + if (WireFormat.getTagFieldNumber(lastTag) == 0) { + // If we actually read zero (or any tag number corresponding to field + // number zero), that's not a valid tag. + throw InvalidProtocolBufferException.invalidTag(); + } + return lastTag; + } + + @Override + public void checkLastTagWas(final int value) throws InvalidProtocolBufferException { + if (lastTag != value) { + throw InvalidProtocolBufferException.invalidEndTag(); + } + } + + @Override + public int getLastTag() { + return lastTag; + } + + @Override + public boolean skipField(final int tag) throws IOException { + switch (WireFormat.getTagWireType(tag)) { + case WireFormat.WIRETYPE_VARINT: + skipRawVarint(); + return true; + case WireFormat.WIRETYPE_FIXED64: + skipRawBytes(FIXED64_SIZE); + return true; + case WireFormat.WIRETYPE_LENGTH_DELIMITED: + skipRawBytes(readRawVarint32()); + return true; + case WireFormat.WIRETYPE_START_GROUP: + skipMessage(); + checkLastTagWas( + WireFormat.makeTag(WireFormat.getTagFieldNumber(tag), WireFormat.WIRETYPE_END_GROUP)); + return true; + case WireFormat.WIRETYPE_END_GROUP: + return false; + case WireFormat.WIRETYPE_FIXED32: + skipRawBytes(FIXED32_SIZE); + return true; + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + + @Override + public boolean skipField(final int tag, final CodedOutputStream output) throws IOException { + switch (WireFormat.getTagWireType(tag)) { + case WireFormat.WIRETYPE_VARINT: + { + long value = readInt64(); + output.writeUInt32NoTag(tag); + output.writeUInt64NoTag(value); + return true; + } + case WireFormat.WIRETYPE_FIXED64: + { + long value = readRawLittleEndian64(); + output.writeUInt32NoTag(tag); + output.writeFixed64NoTag(value); + return true; + } + case WireFormat.WIRETYPE_LENGTH_DELIMITED: + { + ByteString value = readBytes(); + output.writeUInt32NoTag(tag); + output.writeBytesNoTag(value); + return true; + } + case WireFormat.WIRETYPE_START_GROUP: + { + output.writeUInt32NoTag(tag); + skipMessage(output); + int endtag = + WireFormat.makeTag( + WireFormat.getTagFieldNumber(tag), WireFormat.WIRETYPE_END_GROUP); + checkLastTagWas(endtag); + output.writeUInt32NoTag(endtag); + return true; + } + case WireFormat.WIRETYPE_END_GROUP: + { + return false; + } + case WireFormat.WIRETYPE_FIXED32: + { + int value = readRawLittleEndian32(); + output.writeUInt32NoTag(tag); + output.writeFixed32NoTag(value); + return true; + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + + /** Collects the bytes skipped and returns the data in a ByteBuffer. */ + private class SkippedDataSink implements RefillCallback { + private int lastPos = pos; + private ByteArrayOutputStream byteArrayStream; + + @Override + public void onRefill() { + if (byteArrayStream == null) { + byteArrayStream = new ByteArrayOutputStream(); + } + byteArrayStream.write(buffer, lastPos, pos - lastPos); + lastPos = 0; + } + + /** Gets skipped data in a ByteBuffer. This method should only be called once. */ + ByteBuffer getSkippedData() { + if (byteArrayStream == null) { + return ByteBuffer.wrap(buffer, lastPos, pos - lastPos); + } else { + byteArrayStream.write(buffer, lastPos, pos); + return ByteBuffer.wrap(byteArrayStream.toByteArray()); + } + } + } + + // ----------------------------------------------------------------- + + @Override + public double readDouble() throws IOException { + return Double.longBitsToDouble(readRawLittleEndian64()); + } + + @Override + public float readFloat() throws IOException { + return Float.intBitsToFloat(readRawLittleEndian32()); + } + + @Override + public long readUInt64() throws IOException { + return readRawVarint64(); + } + + @Override + public long readInt64() throws IOException { + return readRawVarint64(); + } + + @Override + public int readInt32() throws IOException { + return readRawVarint32(); + } + + @Override + public long readFixed64() throws IOException { + return readRawLittleEndian64(); + } + + @Override + public int readFixed32() throws IOException { + return readRawLittleEndian32(); + } + + @Override + public boolean readBool() throws IOException { + return readRawVarint64() != 0; + } + + @Override + public String readString() throws IOException { + final int size = readRawVarint32(); + if (size > 0 && size <= (bufferSize - pos)) { + // Fast path: We already have the bytes in a contiguous buffer, so + // just copy directly from it. + final String result = new String(buffer, pos, size, UTF_8); + pos += size; + return result; + } + if (size == 0) { + return ""; + } + if (size < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + if (size <= bufferSize) { + refillBuffer(size); + String result = new String(buffer, pos, size, UTF_8); + pos += size; + return result; + } + // Slow path: Build a byte array first then copy it. + return new String(readRawBytesSlowPath(size, /* ensureNoLeakedReferences= */ false), UTF_8); + } + + @Override + public String readStringRequireUtf8() throws IOException { + final int size = readRawVarint32(); + final byte[] bytes; + final int oldPos = pos; + final int tempPos; + if (size <= (bufferSize - oldPos) && size > 0) { + // Fast path: We already have the bytes in a contiguous buffer, so + // just copy directly from it. + bytes = buffer; + pos = oldPos + size; + tempPos = oldPos; + } else if (size == 0) { + return ""; + } else if (size < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } else if (size <= bufferSize) { + refillBuffer(size); + bytes = buffer; + tempPos = 0; + pos = tempPos + size; + } else { + // Slow path: Build a byte array first then copy it. + bytes = readRawBytesSlowPath(size, /* ensureNoLeakedReferences= */ false); + tempPos = 0; + } + return Utf8.decodeUtf8(bytes, tempPos, size); + } + + @Override + public void readGroup( + final int fieldNumber, + final MessageLite.Builder builder, + final ExtensionRegistryLite extensionRegistry) + throws IOException { + checkRecursionLimit(); + ++recursionDepth; + builder.mergeFrom(this, extensionRegistry); + checkLastTagWas(WireFormat.makeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP)); + --recursionDepth; + } + + @Override + public T readGroup( + final int fieldNumber, + final Parser parser, + final ExtensionRegistryLite extensionRegistry) + throws IOException { + checkRecursionLimit(); + ++recursionDepth; + T result = parser.parsePartialFrom(this, extensionRegistry); + checkLastTagWas(WireFormat.makeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP)); + --recursionDepth; + return result; + } + + @Deprecated + @Override + public void readUnknownGroup(final int fieldNumber, final MessageLite.Builder builder) + throws IOException { + readGroup(fieldNumber, builder, ExtensionRegistryLite.getEmptyRegistry()); + } + + @Override + public void readMessage( + final MessageLite.Builder builder, final ExtensionRegistryLite extensionRegistry) + throws IOException { + final int length = readRawVarint32(); + checkRecursionLimit(); + final int oldLimit = pushLimit(length); + ++recursionDepth; + builder.mergeFrom(this, extensionRegistry); + checkLastTagWas(0); + --recursionDepth; + if (getBytesUntilLimit() != 0) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + popLimit(oldLimit); + } + + @Override + public T readMessage( + final Parser parser, final ExtensionRegistryLite extensionRegistry) throws IOException { + int length = readRawVarint32(); + checkRecursionLimit(); + final int oldLimit = pushLimit(length); + ++recursionDepth; + T result = parser.parsePartialFrom(this, extensionRegistry); + checkLastTagWas(0); + --recursionDepth; + if (getBytesUntilLimit() != 0) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + popLimit(oldLimit); + return result; + } + + @Override + public ByteString readBytes() throws IOException { + final int size = readRawVarint32(); + if (size <= (bufferSize - pos) && size > 0) { + // Fast path: We already have the bytes in a contiguous buffer, so + // just copy directly from it. + final ByteString result = ByteString.copyFrom(buffer, pos, size); + pos += size; + return result; + } + if (size == 0) { + return ByteString.EMPTY; + } + if (size < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + return readBytesSlowPath(size); + } + + @Override + public byte[] readByteArray() throws IOException { + final int size = readRawVarint32(); + if (size <= (bufferSize - pos) && size > 0) { + // Fast path: We already have the bytes in a contiguous buffer, so + // just copy directly from it. + final byte[] result = Arrays.copyOfRange(buffer, pos, pos + size); + pos += size; + return result; + } else if (size < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } else { + // Slow path: Build a byte array first then copy it. + // TODO: Do we want to protect from malicious input streams here? + return readRawBytesSlowPath(size, /* ensureNoLeakedReferences= */ false); + } + } + + @Override + public ByteBuffer readByteBuffer() throws IOException { + final int size = readRawVarint32(); + if (size <= (bufferSize - pos) && size > 0) { + // Fast path: We already have the bytes in a contiguous buffer. + ByteBuffer result = ByteBuffer.wrap(Arrays.copyOfRange(buffer, pos, pos + size)); + pos += size; + return result; + } + if (size == 0) { + return Internal.EMPTY_BYTE_BUFFER; + } + if (size < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + // Slow path: Build a byte array first then copy it. + + // We must copy as the byte array was handed off to the InputStream and a malicious + // implementation could retain a reference. + return ByteBuffer.wrap(readRawBytesSlowPath(size, /* ensureNoLeakedReferences= */ true)); + } + + @Override + public int readUInt32() throws IOException { + return readRawVarint32(); + } + + @Override + public int readEnum() throws IOException { + return readRawVarint32(); + } + + @Override + public int readSFixed32() throws IOException { + return readRawLittleEndian32(); + } + + @Override + public long readSFixed64() throws IOException { + return readRawLittleEndian64(); + } + + @Override + public int readSInt32() throws IOException { + return decodeZigZag32(readRawVarint32()); + } + + @Override + public long readSInt64() throws IOException { + return decodeZigZag64(readRawVarint64()); + } + + // ================================================================= + + @Override + public int readRawVarint32() throws IOException { + // See implementation notes for readRawVarint64 + fastpath: + { + int tempPos = pos; + + if (bufferSize == tempPos) { + break fastpath; + } + + final byte[] buffer = this.buffer; + int x; + if ((x = buffer[tempPos++]) >= 0) { + pos = tempPos; + return x; + } else if (bufferSize - tempPos < 9) { + break fastpath; + } else if ((x ^= (buffer[tempPos++] << 7)) < 0) { + x ^= (~0 << 7); + } else if ((x ^= (buffer[tempPos++] << 14)) >= 0) { + x ^= (~0 << 7) ^ (~0 << 14); + } else if ((x ^= (buffer[tempPos++] << 21)) < 0) { + x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21); + } else { + int y = buffer[tempPos++]; + x ^= y << 28; + x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21) ^ (~0 << 28); + if (y < 0 + && buffer[tempPos++] < 0 + && buffer[tempPos++] < 0 + && buffer[tempPos++] < 0 + && buffer[tempPos++] < 0 + && buffer[tempPos++] < 0) { + break fastpath; // Will throw malformedVarint() + } + } + pos = tempPos; + return x; + } + return (int) readRawVarint64SlowPath(); + } + + private void skipRawVarint() throws IOException { + if (bufferSize - pos >= MAX_VARINT_SIZE) { + skipRawVarintFastPath(); + } else { + skipRawVarintSlowPath(); + } + } + + private void skipRawVarintFastPath() throws IOException { + for (int i = 0; i < MAX_VARINT_SIZE; i++) { + if (buffer[pos++] >= 0) { + return; + } + } + throw InvalidProtocolBufferException.malformedVarint(); + } + + private void skipRawVarintSlowPath() throws IOException { + for (int i = 0; i < MAX_VARINT_SIZE; i++) { + if (readRawByte() >= 0) { + return; + } + } + throw InvalidProtocolBufferException.malformedVarint(); + } + + @Override + public long readRawVarint64() throws IOException { + // Implementation notes: + // + // Optimized for one-byte values, expected to be common. + // The particular code below was selected from various candidates + // empirically, by winning VarintBenchmark. + // + // Sign extension of (signed) Java bytes is usually a nuisance, but + // we exploit it here to more easily obtain the sign of bytes read. + // Instead of cleaning up the sign extension bits by masking eagerly, + // we delay until we find the final (positive) byte, when we clear all + // accumulated bits with one xor. We depend on javac to constant fold. + fastpath: + { + int tempPos = pos; + + if (bufferSize == tempPos) { + break fastpath; + } + + final byte[] buffer = this.buffer; + long x; + int y; + if ((y = buffer[tempPos++]) >= 0) { + pos = tempPos; + return y; + } else if (bufferSize - tempPos < 9) { + break fastpath; + } else if ((y ^= (buffer[tempPos++] << 7)) < 0) { + x = y ^ (~0 << 7); + } else if ((y ^= (buffer[tempPos++] << 14)) >= 0) { + x = y ^ ((~0 << 7) ^ (~0 << 14)); + } else if ((y ^= (buffer[tempPos++] << 21)) < 0) { + x = y ^ ((~0 << 7) ^ (~0 << 14) ^ (~0 << 21)); + } else if ((x = y ^ ((long) buffer[tempPos++] << 28)) >= 0L) { + x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28); + } else if ((x ^= ((long) buffer[tempPos++] << 35)) < 0L) { + x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35); + } else if ((x ^= ((long) buffer[tempPos++] << 42)) >= 0L) { + x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35) ^ (~0L << 42); + } else if ((x ^= ((long) buffer[tempPos++] << 49)) < 0L) { + x ^= + (~0L << 7) + ^ (~0L << 14) + ^ (~0L << 21) + ^ (~0L << 28) + ^ (~0L << 35) + ^ (~0L << 42) + ^ (~0L << 49); + } else { + x ^= ((long) buffer[tempPos++] << 56); + x ^= + (~0L << 7) + ^ (~0L << 14) + ^ (~0L << 21) + ^ (~0L << 28) + ^ (~0L << 35) + ^ (~0L << 42) + ^ (~0L << 49) + ^ (~0L << 56); + if (x < 0L) { + if (buffer[tempPos++] < 0L) { + break fastpath; // Will throw malformedVarint() + } + } + } + pos = tempPos; + return x; + } + return readRawVarint64SlowPath(); + } + + @Override + long readRawVarint64SlowPath() throws IOException { + long result = 0; + for (int shift = 0; shift < 64; shift += 7) { + final byte b = readRawByte(); + result |= (long) (b & 0x7F) << shift; + if ((b & 0x80) == 0) { + return result; + } + } + throw InvalidProtocolBufferException.malformedVarint(); + } + + @Override + public int readRawLittleEndian32() throws IOException { + int tempPos = pos; + + if (bufferSize - tempPos < FIXED32_SIZE) { + refillBuffer(FIXED32_SIZE); + tempPos = pos; + } + + final byte[] buffer = this.buffer; + pos = tempPos + FIXED32_SIZE; + return ((buffer[tempPos] & 0xff) + | ((buffer[tempPos + 1] & 0xff) << 8) + | ((buffer[tempPos + 2] & 0xff) << 16) + | ((buffer[tempPos + 3] & 0xff) << 24)); + } + + @Override + public long readRawLittleEndian64() throws IOException { + int tempPos = pos; + + if (bufferSize - tempPos < FIXED64_SIZE) { + refillBuffer(FIXED64_SIZE); + tempPos = pos; + } + + final byte[] buffer = this.buffer; + pos = tempPos + FIXED64_SIZE; + return (((buffer[tempPos] & 0xffL)) + | ((buffer[tempPos + 1] & 0xffL) << 8) + | ((buffer[tempPos + 2] & 0xffL) << 16) + | ((buffer[tempPos + 3] & 0xffL) << 24) + | ((buffer[tempPos + 4] & 0xffL) << 32) + | ((buffer[tempPos + 5] & 0xffL) << 40) + | ((buffer[tempPos + 6] & 0xffL) << 48) + | ((buffer[tempPos + 7] & 0xffL) << 56)); + } + + // ----------------------------------------------------------------- + + @Override + public void enableAliasing(boolean enabled) { + // TODO: Ideally we should throw here. Do nothing for backward compatibility. + } + + @Override + public void resetSizeCounter() { + totalBytesRetired = -pos; + } + + @Override + public int pushLimit(int byteLimit) throws InvalidProtocolBufferException { + if (byteLimit < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + byteLimit += totalBytesRetired + pos; + final int oldLimit = currentLimit; + if (byteLimit > oldLimit) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + currentLimit = byteLimit; + + recomputeBufferSizeAfterLimit(); + + return oldLimit; + } + + private void recomputeBufferSizeAfterLimit() { + bufferSize += bufferSizeAfterLimit; + final int bufferEnd = totalBytesRetired + bufferSize; + if (bufferEnd > currentLimit) { + // Limit is in current buffer. + bufferSizeAfterLimit = bufferEnd - currentLimit; + bufferSize -= bufferSizeAfterLimit; + } else { + bufferSizeAfterLimit = 0; + } + } + + @Override + public void popLimit(final int oldLimit) { + currentLimit = oldLimit; + recomputeBufferSizeAfterLimit(); + } + + @Override + public int getBytesUntilLimit() { + if (currentLimit == Integer.MAX_VALUE) { + return -1; + } + + final int currentAbsolutePosition = totalBytesRetired + pos; + return currentLimit - currentAbsolutePosition; + } + + @Override + public boolean isAtEnd() throws IOException { + return pos == bufferSize && !tryRefillBuffer(1); + } + + @Override + public int getTotalBytesRead() { + return totalBytesRetired + pos; + } + + private interface RefillCallback { + void onRefill(); + } + + private RefillCallback refillCallback = null; + + /** + * Reads more bytes from the input, making at least {@code n} bytes available in the buffer. + * Caller must ensure that the requested space is not yet available, and that the requested + * space is less than BUFFER_SIZE. + * + * @throws InvalidProtocolBufferException The end of the stream or the current limit was + * reached. + */ + private void refillBuffer(int n) throws IOException { + if (!tryRefillBuffer(n)) { + // We have to distinguish the exception between sizeLimitExceeded and truncatedMessage. So + // we just throw an sizeLimitExceeded exception here if it exceeds the sizeLimit + if (n > sizeLimit - totalBytesRetired - pos) { + throw InvalidProtocolBufferException.sizeLimitExceeded(); + } else { + throw InvalidProtocolBufferException.truncatedMessage(); + } + } + } + + /** + * Tries to read more bytes from the input, making at least {@code n} bytes available in the + * buffer. Caller must ensure that the requested space is not yet available, and that the + * requested space is less than BUFFER_SIZE. + * + * @return {@code true} If the bytes could be made available; {@code false} 1. Current at the + * end of the stream 2. The current limit was reached 3. The total size limit was reached + */ + private boolean tryRefillBuffer(int n) throws IOException { + if (pos + n <= bufferSize) { + throw new IllegalStateException( + "refillBuffer() called when " + n + " bytes were already available in buffer"); + } + + // Check whether the size of total message needs to read is bigger than the size limit. + // We shouldn't throw an exception here as isAtEnd() function needs to get this function's + // return as the result. + if (n > sizeLimit - totalBytesRetired - pos) { + return false; + } + + // Shouldn't throw the exception here either. + if (totalBytesRetired + pos + n > currentLimit) { + // Oops, we hit a limit. + return false; + } + + if (refillCallback != null) { + refillCallback.onRefill(); + } + + int tempPos = pos; + if (tempPos > 0) { + if (bufferSize > tempPos) { + System.arraycopy(buffer, tempPos, buffer, 0, bufferSize - tempPos); + } + totalBytesRetired += tempPos; + bufferSize -= tempPos; + pos = 0; + } + + // Here we should refill the buffer as many bytes as possible. + int bytesRead = + read( + input, + buffer, + bufferSize, + Math.min( + // the size of allocated but unused bytes in the buffer + buffer.length - bufferSize, + // do not exceed the total bytes limit + sizeLimit - totalBytesRetired - bufferSize)); + if (bytesRead == 0 || bytesRead < -1 || bytesRead > buffer.length) { + throw new IllegalStateException( + input.getClass() + + "#read(byte[]) returned invalid result: " + + bytesRead + + "\nThe InputStream implementation is buggy."); + } + if (bytesRead > 0) { + bufferSize += bytesRead; + recomputeBufferSizeAfterLimit(); + return (bufferSize >= n) ? true : tryRefillBuffer(n); + } + + return false; + } + + @Override + public byte readRawByte() throws IOException { + if (pos == bufferSize) { + refillBuffer(1); + } + return buffer[pos++]; + } + + @Override + public byte[] readRawBytes(final int size) throws IOException { + final int tempPos = pos; + if (size <= (bufferSize - tempPos) && size > 0) { + pos = tempPos + size; + return Arrays.copyOfRange(buffer, tempPos, tempPos + size); + } else { + // TODO: Do we want to protect from malicious input streams here? + return readRawBytesSlowPath(size, /* ensureNoLeakedReferences= */ false); + } + } + + /** + * Exactly like readRawBytes, but caller must have already checked the fast path: (size <= + * (bufferSize - pos) && size > 0) + * + * If ensureNoLeakedReferences is true, the value is guaranteed to have not escaped to + * untrusted code. + */ + private byte[] readRawBytesSlowPath( + final int size, boolean ensureNoLeakedReferences) throws IOException { + // Attempt to read the data in one byte array when it's safe to do. + byte[] result = readRawBytesSlowPathOneChunk(size); + if (result != null) { + return ensureNoLeakedReferences ? result.clone() : result; + } + + final int originalBufferPos = pos; + final int bufferedBytes = bufferSize - pos; + + // Mark the current buffer consumed. + totalBytesRetired += bufferSize; + pos = 0; + bufferSize = 0; + + // Determine the number of bytes we need to read from the input stream. + int sizeLeft = size - bufferedBytes; + + // The size is very large. For security reasons we read them in small + // chunks. + List chunks = readRawBytesSlowPathRemainingChunks(sizeLeft); + + // OK, got everything. Now concatenate it all into one buffer. + final byte[] bytes = new byte[size]; + + // Start by copying the leftover bytes from this.buffer. + System.arraycopy(buffer, originalBufferPos, bytes, 0, bufferedBytes); + + // And now all the chunks. + int tempPos = bufferedBytes; + for (final byte[] chunk : chunks) { + System.arraycopy(chunk, 0, bytes, tempPos, chunk.length); + tempPos += chunk.length; + } + + // Done. + return bytes; + } + + /** + * Attempts to read the data in one byte array when it's safe to do. Returns null if the size to + * read is too large and needs to be allocated in smaller chunks for security reasons. + * + *

Returns a byte[] that may have escaped to user code via InputStream APIs. + */ + private byte[] readRawBytesSlowPathOneChunk(final int size) throws IOException { + if (size == 0) { + return Internal.EMPTY_BYTE_ARRAY; + } + if (size < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + + // Integer-overflow-conscious check that the message size so far has not exceeded sizeLimit. + int currentMessageSize = totalBytesRetired + pos + size; + if (currentMessageSize - sizeLimit > 0) { + throw InvalidProtocolBufferException.sizeLimitExceeded(); + } + + // Verify that the message size so far has not exceeded currentLimit. + if (currentMessageSize > currentLimit) { + // Read to the end of the stream anyway. + skipRawBytes(currentLimit - totalBytesRetired - pos); + throw InvalidProtocolBufferException.truncatedMessage(); + } + + final int bufferedBytes = bufferSize - pos; + // Determine the number of bytes we need to read from the input stream. + int sizeLeft = size - bufferedBytes; + // TODO: Consider using a value larger than DEFAULT_BUFFER_SIZE. + if (sizeLeft < DEFAULT_BUFFER_SIZE || sizeLeft <= available(input)) { + // Either the bytes we need are known to be available, or the required buffer is + // within an allowed threshold - go ahead and allocate the buffer now. + final byte[] bytes = new byte[size]; + + // Copy all of the buffered bytes to the result buffer. + System.arraycopy(buffer, pos, bytes, 0, bufferedBytes); + totalBytesRetired += bufferSize; + pos = 0; + bufferSize = 0; + + // Fill the remaining bytes from the input stream. + int tempPos = bufferedBytes; + while (tempPos < bytes.length) { + int n = read(input, bytes, tempPos, size - tempPos); + if (n == -1) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + totalBytesRetired += n; + tempPos += n; + } + + return bytes; + } + + return null; + } + + /** + * Reads the remaining data in small chunks from the input stream. + * + * Returns a byte[] that may have escaped to user code via InputStream APIs. + */ + private List readRawBytesSlowPathRemainingChunks(int sizeLeft) throws IOException { + // The size is very large. For security reasons, we can't allocate the + // entire byte array yet. The size comes directly from the input, so a + // maliciously-crafted message could provide a bogus very large size in + // order to trick the app into allocating a lot of memory. We avoid this + // by allocating and reading only a small chunk at a time, so that the + // malicious message must actually *be* extremely large to cause + // problems. Meanwhile, we limit the allowed size of a message elsewhere. + final List chunks = new ArrayList<>(); + + while (sizeLeft > 0) { + // TODO: Consider using a value larger than DEFAULT_BUFFER_SIZE. + final byte[] chunk = new byte[Math.min(sizeLeft, DEFAULT_BUFFER_SIZE)]; + int tempPos = 0; + while (tempPos < chunk.length) { + final int n = input.read(chunk, tempPos, chunk.length - tempPos); + if (n == -1) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + totalBytesRetired += n; + tempPos += n; + } + sizeLeft -= chunk.length; + chunks.add(chunk); + } + + return chunks; + } + + /** + * Like readBytes, but caller must have already checked the fast path: (size <= (bufferSize - + * pos) && size > 0 || size == 0) + */ + private ByteString readBytesSlowPath(final int size) throws IOException { + final byte[] result = readRawBytesSlowPathOneChunk(size); + if (result != null) { + // We must copy as the byte array was handed off to the InputStream and a malicious + // implementation could retain a reference. + return ByteString.copyFrom(result); + } + + final int originalBufferPos = pos; + final int bufferedBytes = bufferSize - pos; + + // Mark the current buffer consumed. + totalBytesRetired += bufferSize; + pos = 0; + bufferSize = 0; + + // Determine the number of bytes we need to read from the input stream. + int sizeLeft = size - bufferedBytes; + + // The size is very large. For security reasons we read them in small + // chunks. + List chunks = readRawBytesSlowPathRemainingChunks(sizeLeft); + + // OK, got everything. Now concatenate it all into one buffer. + final byte[] bytes = new byte[size]; + + // Start by copying the leftover bytes from this.buffer. + System.arraycopy(buffer, originalBufferPos, bytes, 0, bufferedBytes); + + // And now all the chunks. + int tempPos = bufferedBytes; + for (final byte[] chunk : chunks) { + System.arraycopy(chunk, 0, bytes, tempPos, chunk.length); + tempPos += chunk.length; + } + + return ByteString.wrap(bytes); + } + + @Override + public void skipRawBytes(final int size) throws IOException { + if (size <= (bufferSize - pos) && size >= 0) { + // We have all the bytes we need already. + pos += size; + } else { + skipRawBytesSlowPath(size); + } + } + + /** + * Exactly like skipRawBytes, but caller must have already checked the fast path: (size <= + * (bufferSize - pos) && size >= 0) + */ + private void skipRawBytesSlowPath(final int size) throws IOException { + if (size < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + + if (totalBytesRetired + pos + size > currentLimit) { + // Read to the end of the stream anyway. + skipRawBytes(currentLimit - totalBytesRetired - pos); + // Then fail. + throw InvalidProtocolBufferException.truncatedMessage(); + } + + int totalSkipped = 0; + if (refillCallback == null) { + // Skipping more bytes than are in the buffer. First skip what we have. + totalBytesRetired += pos; + totalSkipped = bufferSize - pos; + bufferSize = 0; + pos = 0; + + try { + while (totalSkipped < size) { + int toSkip = size - totalSkipped; + long skipped = skip(input, toSkip); + if (skipped < 0 || skipped > toSkip) { + throw new IllegalStateException( + input.getClass() + + "#skip returned invalid result: " + + skipped + + "\nThe InputStream implementation is buggy."); + } else if (skipped == 0) { + // The API contract of skip() permits an inputstream to skip zero bytes for any reason + // it wants. In particular, ByteArrayInputStream will just return zero over and over + // when it's at the end of its input. In order to actually confirm that we've hit the + // end of input, we need to issue a read call via the other path. + break; + } + totalSkipped += (int) skipped; + } + } finally { + totalBytesRetired += totalSkipped; + recomputeBufferSizeAfterLimit(); + } + } + if (totalSkipped < size) { + // Skipping more bytes than are in the buffer. First skip what we have. + int tempPos = bufferSize - pos; + pos = bufferSize; + + // Keep refilling the buffer until we get to the point we wanted to skip to. + // This has the side effect of ensuring the limits are updated correctly. + refillBuffer(1); + while (size - tempPos > bufferSize) { + tempPos += bufferSize; + pos = bufferSize; + refillBuffer(1); + } + + pos = size - tempPos; + } + } +} \ No newline at end of file diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/UnsafeDirectNioDecoder.java b/protobuf-sdk/src/main/java/com/google/protobuf/UnsafeDirectNioDecoder.java new file mode 100644 index 0000000..5f14d17 --- /dev/null +++ b/protobuf-sdk/src/main/java/com/google/protobuf/UnsafeDirectNioDecoder.java @@ -0,0 +1,737 @@ +package com.google.protobuf; + +import java.io.IOException; +import java.nio.Buffer; +import java.nio.ByteBuffer; + +import static com.google.protobuf.Internal.*; +import static com.google.protobuf.WireFormat.*; +import static com.google.protobuf.WireFormat.FIXED64_SIZE; + +/** + * A {@link CodedInputStream} implementation that uses a backing direct ByteBuffer as the input. + * Requires the use of {@code sun.misc.Unsafe} to perform fast reads on the buffer. + */ +final class UnsafeDirectNioDecoder extends CodedInputStream { + /** The direct buffer that is backing this stream. */ + private final ByteBuffer buffer; + + /** + * If {@code true}, indicates that the buffer is backing a {@link ByteString} and is therefore + * considered to be an immutable input source. + */ + private final boolean immutable; + + /** The unsafe address of the content of {@link #buffer}. */ + private final long address; + + /** The unsafe address of the current read limit of the buffer. */ + private long limit; + + /** The unsafe address of the current read position of the buffer. */ + private long pos; + + /** The unsafe address of the starting read position. */ + private long startPos; + + /** The amount of available data in the buffer beyond {@link #limit}. */ + private int bufferSizeAfterLimit; + + /** The last tag that was read from this stream. */ + private int lastTag; + + /** + * If {@code true}, indicates that calls to read {@link ByteString} or {@code byte[]} + * may return slices of the underlying buffer, rather than copies. + */ + private boolean enableAliasing; + + /** The absolute position of the end of the current message. */ + private int currentLimit = Integer.MAX_VALUE; + + static boolean isSupported() { + return UnsafeUtil.hasUnsafeByteBufferOperations(); + } + + UnsafeDirectNioDecoder(ByteBuffer buffer, boolean immutable) { + this.buffer = buffer; + address = UnsafeUtil.addressOffset(buffer); + limit = address + buffer.limit(); + pos = address + buffer.position(); + startPos = pos; + this.immutable = immutable; + } + + @Override + public int readTag() throws IOException { + if (isAtEnd()) { + lastTag = 0; + return 0; + } + + lastTag = readRawVarint32(); + if (WireFormat.getTagFieldNumber(lastTag) == 0) { + // If we actually read zero (or any tag number corresponding to field + // number zero), that's not a valid tag. + throw InvalidProtocolBufferException.invalidTag(); + } + return lastTag; + } + + @Override + public void checkLastTagWas(final int value) throws InvalidProtocolBufferException { + if (lastTag != value) { + throw InvalidProtocolBufferException.invalidEndTag(); + } + } + + @Override + public int getLastTag() { + return lastTag; + } + + @Override + public boolean skipField(final int tag) throws IOException { + switch (WireFormat.getTagWireType(tag)) { + case WireFormat.WIRETYPE_VARINT: + skipRawVarint(); + return true; + case WireFormat.WIRETYPE_FIXED64: + skipRawBytes(FIXED64_SIZE); + return true; + case WireFormat.WIRETYPE_LENGTH_DELIMITED: + skipRawBytes(readRawVarint32()); + return true; + case WireFormat.WIRETYPE_START_GROUP: + skipMessage(); + checkLastTagWas( + WireFormat.makeTag(WireFormat.getTagFieldNumber(tag), WireFormat.WIRETYPE_END_GROUP)); + return true; + case WireFormat.WIRETYPE_END_GROUP: + return false; + case WireFormat.WIRETYPE_FIXED32: + skipRawBytes(FIXED32_SIZE); + return true; + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + + @Override + public boolean skipField(final int tag, final CodedOutputStream output) throws IOException { + switch (WireFormat.getTagWireType(tag)) { + case WireFormat.WIRETYPE_VARINT: + { + long value = readInt64(); + output.writeUInt32NoTag(tag); + output.writeUInt64NoTag(value); + return true; + } + case WireFormat.WIRETYPE_FIXED64: + { + long value = readRawLittleEndian64(); + output.writeUInt32NoTag(tag); + output.writeFixed64NoTag(value); + return true; + } + case WireFormat.WIRETYPE_LENGTH_DELIMITED: + { + ByteString value = readBytes(); + output.writeUInt32NoTag(tag); + output.writeBytesNoTag(value); + return true; + } + case WireFormat.WIRETYPE_START_GROUP: + { + output.writeUInt32NoTag(tag); + skipMessage(output); + int endtag = + WireFormat.makeTag( + WireFormat.getTagFieldNumber(tag), WireFormat.WIRETYPE_END_GROUP); + checkLastTagWas(endtag); + output.writeUInt32NoTag(endtag); + return true; + } + case WireFormat.WIRETYPE_END_GROUP: + { + return false; + } + case WireFormat.WIRETYPE_FIXED32: + { + int value = readRawLittleEndian32(); + output.writeUInt32NoTag(tag); + output.writeFixed32NoTag(value); + return true; + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + + // ----------------------------------------------------------------- + + @Override + public double readDouble() throws IOException { + return Double.longBitsToDouble(readRawLittleEndian64()); + } + + @Override + public float readFloat() throws IOException { + return Float.intBitsToFloat(readRawLittleEndian32()); + } + + @Override + public long readUInt64() throws IOException { + return readRawVarint64(); + } + + @Override + public long readInt64() throws IOException { + return readRawVarint64(); + } + + @Override + public int readInt32() throws IOException { + return readRawVarint32(); + } + + @Override + public long readFixed64() throws IOException { + return readRawLittleEndian64(); + } + + @Override + public int readFixed32() throws IOException { + return readRawLittleEndian32(); + } + + @Override + public boolean readBool() throws IOException { + return readRawVarint64() != 0; + } + + @Override + public String readString() throws IOException { + final int size = readRawVarint32(); + if (size > 0 && size <= remaining()) { + // TODO: Is there a way to avoid this copy? + // TODO: It might be possible to share the optimized loop with + // readStringRequireUtf8 by implementing Java replacement logic there. + // The same as readBytes' logic + byte[] bytes = new byte[size]; + UnsafeUtil.copyMemory(pos, bytes, 0, size); + String result = new String(bytes, UTF_8); + pos += size; + return result; + } + + if (size == 0) { + return ""; + } + if (size < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + throw InvalidProtocolBufferException.truncatedMessage(); + } + + @Override + public String readStringRequireUtf8() throws IOException { + final int size = readRawVarint32(); + if (size > 0 && size <= remaining()) { + final int bufferPos = bufferPos(pos); + String result = Utf8.decodeUtf8(buffer, bufferPos, size); + pos += size; + return result; + } + + if (size == 0) { + return ""; + } + if (size <= 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + throw InvalidProtocolBufferException.truncatedMessage(); + } + + @Override + public void readGroup( + final int fieldNumber, + final MessageLite.Builder builder, + final ExtensionRegistryLite extensionRegistry) + throws IOException { + checkRecursionLimit(); + ++recursionDepth; + builder.mergeFrom(this, extensionRegistry); + checkLastTagWas(WireFormat.makeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP)); + --recursionDepth; + } + + @Override + public T readGroup( + final int fieldNumber, + final Parser parser, + final ExtensionRegistryLite extensionRegistry) + throws IOException { + checkRecursionLimit(); + ++recursionDepth; + T result = parser.parsePartialFrom(this, extensionRegistry); + checkLastTagWas(WireFormat.makeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP)); + --recursionDepth; + return result; + } + + @Deprecated + @Override + public void readUnknownGroup(final int fieldNumber, final MessageLite.Builder builder) + throws IOException { + readGroup(fieldNumber, builder, ExtensionRegistryLite.getEmptyRegistry()); + } + + @Override + public void readMessage( + final MessageLite.Builder builder, final ExtensionRegistryLite extensionRegistry) + throws IOException { + final int length = readRawVarint32(); + checkRecursionLimit(); + final int oldLimit = pushLimit(length); + ++recursionDepth; + builder.mergeFrom(this, extensionRegistry); + checkLastTagWas(0); + --recursionDepth; + if (getBytesUntilLimit() != 0) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + popLimit(oldLimit); + } + + @Override + public T readMessage( + final Parser parser, final ExtensionRegistryLite extensionRegistry) throws IOException { + int length = readRawVarint32(); + checkRecursionLimit(); + final int oldLimit = pushLimit(length); + ++recursionDepth; + T result = parser.parsePartialFrom(this, extensionRegistry); + checkLastTagWas(0); + --recursionDepth; + if (getBytesUntilLimit() != 0) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + popLimit(oldLimit); + return result; + } + + @Override + public ByteString readBytes() throws IOException { + final int size = readRawVarint32(); + if (size > 0 && size <= remaining()) { + if (immutable && enableAliasing) { + final ByteBuffer result = slice(pos, pos + size); + pos += size; + return ByteString.wrap(result); + } else { + // Use UnsafeUtil to copy the memory to bytes instead of using ByteBuffer ways. + byte[] bytes = new byte[size]; + UnsafeUtil.copyMemory(pos, bytes, 0, size); + pos += size; + return ByteString.wrap(bytes); + } + } + + if (size == 0) { + return ByteString.EMPTY; + } + if (size < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + throw InvalidProtocolBufferException.truncatedMessage(); + } + + @Override + public byte[] readByteArray() throws IOException { + return readRawBytes(readRawVarint32()); + } + + @Override + public ByteBuffer readByteBuffer() throws IOException { + final int size = readRawVarint32(); + if (size > 0 && size <= remaining()) { + // "Immutable" implies that buffer is backing a ByteString. + // Disallow slicing in this case to prevent the caller from modifying the contents + // of the ByteString. + if (!immutable && enableAliasing) { + final ByteBuffer result = slice(pos, pos + size); + pos += size; + return result; + } else { + // The same as readBytes' logic + byte[] bytes = new byte[size]; + UnsafeUtil.copyMemory(pos, bytes, 0, size); + pos += size; + return ByteBuffer.wrap(bytes); + } + // TODO: Investigate making the ByteBuffer be made read-only + } + + if (size == 0) { + return EMPTY_BYTE_BUFFER; + } + if (size < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + throw InvalidProtocolBufferException.truncatedMessage(); + } + + @Override + public int readUInt32() throws IOException { + return readRawVarint32(); + } + + @Override + public int readEnum() throws IOException { + return readRawVarint32(); + } + + @Override + public int readSFixed32() throws IOException { + return readRawLittleEndian32(); + } + + @Override + public long readSFixed64() throws IOException { + return readRawLittleEndian64(); + } + + @Override + public int readSInt32() throws IOException { + return decodeZigZag32(readRawVarint32()); + } + + @Override + public long readSInt64() throws IOException { + return decodeZigZag64(readRawVarint64()); + } + + // ================================================================= + + @Override + public int readRawVarint32() throws IOException { + // See implementation notes for readRawVarint64 + fastpath: + { + long tempPos = pos; + + if (limit == tempPos) { + break fastpath; + } + + int x; + if ((x = UnsafeUtil.getByte(tempPos++)) >= 0) { + pos = tempPos; + return x; + } else if (limit - tempPos < 9) { + break fastpath; + } else if ((x ^= (UnsafeUtil.getByte(tempPos++) << 7)) < 0) { + x ^= (~0 << 7); + } else if ((x ^= (UnsafeUtil.getByte(tempPos++) << 14)) >= 0) { + x ^= (~0 << 7) ^ (~0 << 14); + } else if ((x ^= (UnsafeUtil.getByte(tempPos++) << 21)) < 0) { + x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21); + } else { + int y = UnsafeUtil.getByte(tempPos++); + x ^= y << 28; + x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21) ^ (~0 << 28); + if (y < 0 + && UnsafeUtil.getByte(tempPos++) < 0 + && UnsafeUtil.getByte(tempPos++) < 0 + && UnsafeUtil.getByte(tempPos++) < 0 + && UnsafeUtil.getByte(tempPos++) < 0 + && UnsafeUtil.getByte(tempPos++) < 0) { + break fastpath; // Will throw malformedVarint() + } + } + pos = tempPos; + return x; + } + return (int) readRawVarint64SlowPath(); + } + + private void skipRawVarint() throws IOException { + if (remaining() >= MAX_VARINT_SIZE) { + skipRawVarintFastPath(); + } else { + skipRawVarintSlowPath(); + } + } + + private void skipRawVarintFastPath() throws IOException { + for (int i = 0; i < MAX_VARINT_SIZE; i++) { + if (UnsafeUtil.getByte(pos++) >= 0) { + return; + } + } + throw InvalidProtocolBufferException.malformedVarint(); + } + + private void skipRawVarintSlowPath() throws IOException { + for (int i = 0; i < MAX_VARINT_SIZE; i++) { + if (readRawByte() >= 0) { + return; + } + } + throw InvalidProtocolBufferException.malformedVarint(); + } + + @Override + public long readRawVarint64() throws IOException { + // Implementation notes: + // + // Optimized for one-byte values, expected to be common. + // The particular code below was selected from various candidates + // empirically, by winning VarintBenchmark. + // + // Sign extension of (signed) Java bytes is usually a nuisance, but + // we exploit it here to more easily obtain the sign of bytes read. + // Instead of cleaning up the sign extension bits by masking eagerly, + // we delay until we find the final (positive) byte, when we clear all + // accumulated bits with one xor. We depend on javac to constant fold. + fastpath: + { + long tempPos = pos; + + if (limit == tempPos) { + break fastpath; + } + + long x; + int y; + if ((y = UnsafeUtil.getByte(tempPos++)) >= 0) { + pos = tempPos; + return y; + } else if (limit - tempPos < 9) { + break fastpath; + } else if ((y ^= (UnsafeUtil.getByte(tempPos++) << 7)) < 0) { + x = y ^ (~0 << 7); + } else if ((y ^= (UnsafeUtil.getByte(tempPos++) << 14)) >= 0) { + x = y ^ ((~0 << 7) ^ (~0 << 14)); + } else if ((y ^= (UnsafeUtil.getByte(tempPos++) << 21)) < 0) { + x = y ^ ((~0 << 7) ^ (~0 << 14) ^ (~0 << 21)); + } else if ((x = y ^ ((long) UnsafeUtil.getByte(tempPos++) << 28)) >= 0L) { + x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28); + } else if ((x ^= ((long) UnsafeUtil.getByte(tempPos++) << 35)) < 0L) { + x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35); + } else if ((x ^= ((long) UnsafeUtil.getByte(tempPos++) << 42)) >= 0L) { + x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35) ^ (~0L << 42); + } else if ((x ^= ((long) UnsafeUtil.getByte(tempPos++) << 49)) < 0L) { + x ^= + (~0L << 7) + ^ (~0L << 14) + ^ (~0L << 21) + ^ (~0L << 28) + ^ (~0L << 35) + ^ (~0L << 42) + ^ (~0L << 49); + } else { + x ^= ((long) UnsafeUtil.getByte(tempPos++) << 56); + x ^= + (~0L << 7) + ^ (~0L << 14) + ^ (~0L << 21) + ^ (~0L << 28) + ^ (~0L << 35) + ^ (~0L << 42) + ^ (~0L << 49) + ^ (~0L << 56); + if (x < 0L) { + if (UnsafeUtil.getByte(tempPos++) < 0L) { + break fastpath; // Will throw malformedVarint() + } + } + } + pos = tempPos; + return x; + } + return readRawVarint64SlowPath(); + } + + @Override + long readRawVarint64SlowPath() throws IOException { + long result = 0; + for (int shift = 0; shift < 64; shift += 7) { + final byte b = readRawByte(); + result |= (long) (b & 0x7F) << shift; + if ((b & 0x80) == 0) { + return result; + } + } + throw InvalidProtocolBufferException.malformedVarint(); + } + + @Override + public int readRawLittleEndian32() throws IOException { + long tempPos = pos; + + if (limit - tempPos < FIXED32_SIZE) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + + pos = tempPos + FIXED32_SIZE; + return ((UnsafeUtil.getByte(tempPos) & 0xff) + | ((UnsafeUtil.getByte(tempPos + 1) & 0xff) << 8) + | ((UnsafeUtil.getByte(tempPos + 2) & 0xff) << 16) + | ((UnsafeUtil.getByte(tempPos + 3) & 0xff) << 24)); + } + + @Override + public long readRawLittleEndian64() throws IOException { + long tempPos = pos; + + if (limit - tempPos < FIXED64_SIZE) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + + pos = tempPos + FIXED64_SIZE; + return ((UnsafeUtil.getByte(tempPos) & 0xffL) + | ((UnsafeUtil.getByte(tempPos + 1) & 0xffL) << 8) + | ((UnsafeUtil.getByte(tempPos + 2) & 0xffL) << 16) + | ((UnsafeUtil.getByte(tempPos + 3) & 0xffL) << 24) + | ((UnsafeUtil.getByte(tempPos + 4) & 0xffL) << 32) + | ((UnsafeUtil.getByte(tempPos + 5) & 0xffL) << 40) + | ((UnsafeUtil.getByte(tempPos + 6) & 0xffL) << 48) + | ((UnsafeUtil.getByte(tempPos + 7) & 0xffL) << 56)); + } + + @Override + public void enableAliasing(boolean enabled) { + this.enableAliasing = enabled; + } + + @Override + public void resetSizeCounter() { + startPos = pos; + } + + @Override + public int pushLimit(int byteLimit) throws InvalidProtocolBufferException { + if (byteLimit < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + byteLimit += getTotalBytesRead(); + final int oldLimit = currentLimit; + if (byteLimit > oldLimit) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + currentLimit = byteLimit; + + recomputeBufferSizeAfterLimit(); + + return oldLimit; + } + + @Override + public void popLimit(final int oldLimit) { + currentLimit = oldLimit; + recomputeBufferSizeAfterLimit(); + } + + @Override + public int getBytesUntilLimit() { + if (currentLimit == Integer.MAX_VALUE) { + return -1; + } + + return currentLimit - getTotalBytesRead(); + } + + @Override + public boolean isAtEnd() throws IOException { + return pos == limit; + } + + @Override + public int getTotalBytesRead() { + return (int) (pos - startPos); + } + + @Override + public byte readRawByte() throws IOException { + if (pos == limit) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + return UnsafeUtil.getByte(pos++); + } + + @Override + public byte[] readRawBytes(final int length) throws IOException { + if (length >= 0 && length <= remaining()) { + byte[] bytes = new byte[length]; + slice(pos, pos + length).get(bytes); + pos += length; + return bytes; + } + + if (length <= 0) { + if (length == 0) { + return EMPTY_BYTE_ARRAY; + } else { + throw InvalidProtocolBufferException.negativeSize(); + } + } + + throw InvalidProtocolBufferException.truncatedMessage(); + } + + @Override + public void skipRawBytes(final int length) throws IOException { + if (length >= 0 && length <= remaining()) { + // We have all the bytes we need already. + pos += length; + return; + } + + if (length < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + throw InvalidProtocolBufferException.truncatedMessage(); + } + + private void recomputeBufferSizeAfterLimit() { + limit += bufferSizeAfterLimit; + final int bufferEnd = (int) (limit - startPos); + if (bufferEnd > currentLimit) { + // Limit is in current buffer. + bufferSizeAfterLimit = bufferEnd - currentLimit; + limit -= bufferSizeAfterLimit; + } else { + bufferSizeAfterLimit = 0; + } + } + + private int remaining() { + return (int) (limit - pos); + } + + private int bufferPos(long pos) { + return (int) (pos - address); + } + + private ByteBuffer slice(long begin, long end) throws IOException { + int prevPos = buffer.position(); + int prevLimit = buffer.limit(); + // View ByteBuffer as Buffer to avoid cross-Java version issues. + // See https://issues.apache.org/jira/browse/MRESOLVER-85 + Buffer asBuffer = buffer; + try { + asBuffer.position(bufferPos(begin)); + asBuffer.limit(bufferPos(end)); + return buffer.slice(); + } catch (IllegalArgumentException e) { + InvalidProtocolBufferException ex = InvalidProtocolBufferException.truncatedMessage(); + ex.initCause(e); + throw ex; + } finally { + asBuffer.position(prevPos); + asBuffer.limit(prevLimit); + } + } +} \ No newline at end of file From be61c929b778c6b58d8c64ac33517a1a263f911b Mon Sep 17 00:00:00 2001 From: blakeli Date: Fri, 28 Mar 2025 19:17:03 -0400 Subject: [PATCH 06/42] Move implementation of ByteString to SDK package. --- .../java/com/google/protobuf/ByteString.java | 441 +++--------------- .../google/protobuf/BoundedByteString.java | 98 ++++ .../com/google/protobuf/LeafByteString.java | 34 ++ .../google/protobuf/LiteralByteString.java | 240 ++++++++++ .../com/google/protobuf/NioByteString.java | 2 +- .../com/google/protobuf/RopeByteString.java | 0 .../com/google/protobuf/java_features.proto | 52 --- 7 files changed, 447 insertions(+), 420 deletions(-) create mode 100644 protobuf-sdk/src/main/java/com/google/protobuf/BoundedByteString.java create mode 100644 protobuf-sdk/src/main/java/com/google/protobuf/LeafByteString.java create mode 100644 protobuf-sdk/src/main/java/com/google/protobuf/LiteralByteString.java rename {protobuf-api => protobuf-sdk}/src/main/java/com/google/protobuf/NioByteString.java (99%) rename {protobuf-api => protobuf-sdk}/src/main/java/com/google/protobuf/RopeByteString.java (100%) delete mode 100644 protobuf-sdk/src/main/java/com/google/protobuf/java_features.proto diff --git a/protobuf-api/src/main/java/com/google/protobuf/ByteString.java b/protobuf-api/src/main/java/com/google/protobuf/ByteString.java index 8ba729c..99823f5 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/ByteString.java +++ b/protobuf-api/src/main/java/com/google/protobuf/ByteString.java @@ -11,22 +11,21 @@ import static java.lang.Integer.toHexString; import static java.lang.System.identityHashCode; -import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; -import java.io.InvalidObjectException; -import java.io.ObjectInputStream; import java.io.OutputStream; import java.io.Serializable; import java.io.UnsupportedEncodingException; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.nio.ByteBuffer; import java.nio.charset.Charset; import java.nio.charset.UnsupportedCharsetException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import java.util.Comparator; import java.util.Iterator; import java.util.List; @@ -69,8 +68,22 @@ public abstract class ByteString implements Iterable, Serializable { static final int MAX_READ_FROM_CHUNK_SIZE = 0x2000; // 8k + private static final Class LITERAL_BYTE_STRING = getClassForName("com.google.protobuf.LiteralByteString"); + private static final Class LEAF_BYTE_STRING = getClassForName("com.google.protobuf.LeafByteString"); + private static final Class NIO_BYTE_STRING = getClassForName("com.google.protobuf.NioByteString"); + private static final Class ROPE_BYTE_STRING = getClassForName("com.google.protobuf.RopeByteString"); + private static final Class BOUNDED_BYTE_STRING = getClassForName("com.google.protobuf.BoundedByteString"); + + private static Class getClassForName(String name) { + try { + return (Class) Class.forName(name); + } catch (Throwable e) { + return null; + } + } + /** Empty {@code ByteString}. */ - public static final ByteString EMPTY = new LiteralByteString(Internal.EMPTY_BYTE_ARRAY); + public static final ByteString EMPTY = newLiteralByteString(Internal.EMPTY_BYTE_ARRAY); /** * An interface to efficiently copy {@code byte[]}. @@ -379,7 +392,21 @@ public static ByteString fromHex(@CompileTimeConstant String hexString) { int d2 = extractHexDigit(hexString, 2 * i + 1); bytes[i] = (byte) (d1 << 4 | d2); } - return new LiteralByteString(bytes); + + return newLiteralByteString(bytes); + } + + private static ByteString newLiteralByteString(byte[] bytes) { + try { + Constructor constructor = LITERAL_BYTE_STRING.getDeclaredConstructors()[0]; + return (ByteString) constructor.newInstance(bytes); + } catch (InstantiationException e) { + throw new RuntimeException(e); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } catch (InvocationTargetException e) { + throw new RuntimeException(e); + } } // ================================================================= @@ -396,7 +423,7 @@ public static ByteString fromHex(@CompileTimeConstant String hexString) { */ public static ByteString copyFrom(byte[] bytes, int offset, int size) { checkRange(offset, offset + size, bytes.length); - return new LiteralByteString(byteArrayCopier.copyFrom(bytes, offset, size)); + return newLiteralByteString(byteArrayCopier.copyFrom(bytes, offset, size)); } /** @@ -418,7 +445,16 @@ static ByteString wrap(ByteBuffer buffer) { final int offset = buffer.arrayOffset(); return ByteString.wrap(buffer.array(), offset + buffer.position(), buffer.remaining()); } else { - return new NioByteString(buffer); + try { + Constructor constructor = NIO_BYTE_STRING.getDeclaredConstructors()[0]; + return (ByteString) constructor.newInstance(buffer); + } catch (InstantiationException e) { + throw new RuntimeException(e); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } catch (InvocationTargetException e) { + throw new RuntimeException(e); + } } } @@ -428,7 +464,7 @@ static ByteString wrap(ByteBuffer buffer) { */ static ByteString wrap(byte[] bytes) { // TODO: Return EMPTY when bytes are empty to reduce allocations? - return new LiteralByteString(bytes); + return newLiteralByteString(bytes); } /** @@ -436,7 +472,16 @@ static ByteString wrap(byte[] bytes) { * to force a classload of ByteString before BoundedByteString and LiteralByteString. */ static ByteString wrap(byte[] bytes, int offset, int length) { - return new BoundedByteString(bytes, offset, length); + try { + Constructor constructor = BOUNDED_BYTE_STRING.getDeclaredConstructors()[0]; + return (ByteString) constructor.newInstance(bytes, offset, length); + } catch (InstantiationException e) { + throw new RuntimeException(e); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } catch (InvocationTargetException e) { + throw new RuntimeException(e); + } } /** @@ -452,7 +497,8 @@ public static ByteString copyFrom(ByteBuffer bytes, int size) { checkRange(0, size, bytes.remaining()); byte[] copy = new byte[size]; bytes.get(copy); - return new LiteralByteString(copy); + return newLiteralByteString(copy); + } /** @@ -476,7 +522,7 @@ public static ByteString copyFrom(ByteBuffer bytes) { */ public static ByteString copyFrom(String text, String charsetName) throws UnsupportedEncodingException { - return new LiteralByteString(text.getBytes(charsetName)); + return newLiteralByteString(text.getBytes(charsetName)); } /** @@ -488,7 +534,7 @@ public static ByteString copyFrom(String text, String charsetName) * @return new {@code ByteString} */ public static ByteString copyFrom(String text, Charset charset) { - return new LiteralByteString(text.getBytes(charset)); + return newLiteralByteString(text.getBytes(charset)); } /** @@ -499,7 +545,7 @@ public static ByteString copyFrom(String text, Charset charset) { * @return new {@code ByteString} */ public static ByteString copyFromUtf8(String text) { - return new LiteralByteString(text.getBytes(Internal.UTF_8)); + return newLiteralByteString(text.getBytes(Internal.UTF_8)); } // ================================================================= @@ -623,8 +669,16 @@ public final ByteString concat(ByteString other) { throw new IllegalArgumentException( "ByteString would be too long: " + size() + "+" + other.size()); } - - return RopeByteString.concatenate(this, other); + try { + Method concatenateMethod = ROPE_BYTE_STRING.getMethod("concatenate", ByteString.class, ByteString.class); + return (ByteString) concatenateMethod.invoke(null, this, other); + } catch (NoSuchMethodException e) { + throw new RuntimeException(e); + } catch (InvocationTargetException e) { + throw new RuntimeException(e); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } } /** @@ -924,37 +978,6 @@ public final String toStringUtf8() { @Override public abstract boolean equals(Object o); - /** Base class for leaf {@link ByteString}s (i.e. non-ropes). */ - abstract static class LeafByteString extends ByteString { - private static final long serialVersionUID = 1L; - - @Override - protected final int getTreeDepth() { - return 0; - } - - @Override - protected final boolean isBalanced() { - return true; - } - - @Override - void writeToReverse(ByteOutput byteOutput) throws IOException { - writeTo(byteOutput); - } - - /** - * Check equality of the substring of given length of this object starting at zero with another - * {@code ByteString} substring starting at offset. - * - * @param other what to compare a substring in - * @param offset offset into other - * @param length number of bytes to compare - * @return true for equality of substrings, else false. - */ - abstract boolean equalsRange(ByteString other, int offset, int length); - } - /** * Compute the hashCode using the traditional algorithm from {@link ByteString}. * @@ -1168,7 +1191,7 @@ public String toString() { * buffer whose size is at least the specified minimum size. */ private void flushFullBuffer(int minSize) { - flushedBuffers.add(new LiteralByteString(buffer)); + flushedBuffers.add(newLiteralByteString(buffer)); flushedBuffersTotalBytes += buffer.length; // We want to increase our total capacity by 50%, but as a minimum, // the new buffer should also at least be >= minSize and @@ -1186,12 +1209,12 @@ private void flushLastBuffer() { if (bufferPos < buffer.length) { if (bufferPos > 0) { byte[] bufferCopy = Arrays.copyOf(buffer, bufferPos); - flushedBuffers.add(new LiteralByteString(bufferCopy)); + flushedBuffers.add(newLiteralByteString(bufferCopy)); } // We reuse this buffer for further writes. } else { // Buffer is completely full. Huzzah. - flushedBuffers.add(new LiteralByteString(buffer)); + flushedBuffers.add(newLiteralByteString(buffer)); // 99% of the time, we're not going to use this OutputStream again. // We set buffer to an empty byte stream so that we're handling this // case without wasting space. In the rare case that more writes @@ -1236,7 +1259,7 @@ public ByteString build() { // We can be confident that the CodedOutputStream will not modify the // underlying bytes anymore because it already wrote all of them. So, // no need to make a copy. - return new LiteralByteString(buffer); + return newLiteralByteString(buffer); } public CodedOutputStream getCodedOutput() { @@ -1343,323 +1366,7 @@ private String truncateAndEscapeForDisplay() { return size() <= limit ? escapeBytes(this) : escapeBytes(substring(0, limit - 3)) + "..."; } - /** - * This class implements a {@link com.google.protobuf.ByteString} backed by a single array of - * bytes, contiguous in memory. It supports substring by pointing to only a sub-range of the - * underlying byte array, meaning that a substring will reference the full byte-array of the - * string it's made from, exactly as with {@link String}. - * - * @author carlanton@google.com (Carl Haverl) - */ - // Keep this class private to avoid deadlocks in classloading across threads as ByteString's - // static initializer loads LiteralByteString and another thread loads LiteralByteString. - private static class LiteralByteString extends ByteString.LeafByteString { - private static final long serialVersionUID = 1L; - - protected final byte[] bytes; - - /** - * Creates a {@code LiteralByteString} backed by the given array, without copying. - * - * @param bytes array to wrap - */ - LiteralByteString(byte[] bytes) { - if (bytes == null) { - throw new NullPointerException(); - } - this.bytes = bytes; - } - - @Override - public byte byteAt(int index) { - // Unlike most methods in this class, this one is a direct implementation - // ignoring the potential offset because we need to do range-checking in the - // substring case anyway. - return bytes[index]; - } - - @Override - byte internalByteAt(int index) { - return bytes[index]; - } - - @Override - public int size() { - return bytes.length; - } - - // ================================================================= - // ByteString -> substring - - @Override - public final ByteString substring(int beginIndex, int endIndex) { - final int length = checkRange(beginIndex, endIndex, size()); - - if (length == 0) { - return ByteString.EMPTY; - } - - return new BoundedByteString(bytes, getOffsetIntoBytes() + beginIndex, length); - } - - // ================================================================= - // ByteString -> byte[] - - @Override - protected void copyToInternal( - byte[] target, int sourceOffset, int targetOffset, int numberToCopy) { - // Optimized form, not for subclasses, since we don't call - // getOffsetIntoBytes() or check the 'numberToCopy' parameter. - // TODO: Is not calling getOffsetIntoBytes really saving that much? - System.arraycopy(bytes, sourceOffset, target, targetOffset, numberToCopy); - } - - @Override - public final void copyTo(ByteBuffer target) { - target.put(bytes, getOffsetIntoBytes(), size()); // Copies bytes - } - - @Override - public final ByteBuffer asReadOnlyByteBuffer() { - return ByteBuffer.wrap(bytes, getOffsetIntoBytes(), size()).asReadOnlyBuffer(); - } - - @Override - public final List asReadOnlyByteBufferList() { - return Collections.singletonList(asReadOnlyByteBuffer()); - } - - @Override - public final void writeTo(OutputStream outputStream) throws IOException { - outputStream.write(toByteArray()); - } - - @Override - final void writeToInternal(OutputStream outputStream, int sourceOffset, int numberToWrite) - throws IOException { - outputStream.write(bytes, getOffsetIntoBytes() + sourceOffset, numberToWrite); - } - - @Override - final void writeTo(ByteOutput output) throws IOException { - output.writeLazy(bytes, getOffsetIntoBytes(), size()); - } - - @Override - protected final String toStringInternal(Charset charset) { - return new String(bytes, getOffsetIntoBytes(), size(), charset); - } - - // ================================================================= - // UTF-8 decoding - - @Override - public final boolean isValidUtf8() { - int offset = getOffsetIntoBytes(); - return Utf8.isValidUtf8(bytes, offset, offset + size()); - } - - @Override - protected final int partialIsValidUtf8(int state, int offset, int length) { - int index = getOffsetIntoBytes() + offset; - return Utf8.partialIsValidUtf8(state, bytes, index, index + length); - } - - // ================================================================= - // equals() and hashCode() - - @Override - public final boolean equals(Object other) { - if (other == this) { - return true; - } - if (!(other instanceof ByteString)) { - return false; - } - - if (size() != ((ByteString) other).size()) { - return false; - } - if (size() == 0) { - return true; - } - - if (other instanceof LiteralByteString) { - LiteralByteString otherAsLiteral = (LiteralByteString) other; - // If we know the hash codes and they are not equal, we know the byte - // strings are not equal. - int thisHash = peekCachedHashCode(); - int thatHash = otherAsLiteral.peekCachedHashCode(); - if (thisHash != 0 && thatHash != 0 && thisHash != thatHash) { - return false; - } - - return equalsRange((LiteralByteString) other, 0, size()); - } else { - // RopeByteString and NioByteString. - return other.equals(this); - } - } - - /** - * Check equality of the substring of given length of this object starting at zero with another - * {@code LiteralByteString} substring starting at offset. - * - * @param other what to compare a substring in - * @param offset offset into other - * @param length number of bytes to compare - * @return true for equality of substrings, else false. - */ - @Override - final boolean equalsRange(ByteString other, int offset, int length) { - if (length > other.size()) { - throw new IllegalArgumentException("Length too large: " + length + size()); - } - if (offset + length > other.size()) { - throw new IllegalArgumentException( - "Ran off end of other: " + offset + ", " + length + ", " + other.size()); - } - - if (other instanceof LiteralByteString) { - LiteralByteString lbsOther = (LiteralByteString) other; - byte[] thisBytes = bytes; - byte[] otherBytes = lbsOther.bytes; - int thisLimit = getOffsetIntoBytes() + length; - for (int thisIndex = getOffsetIntoBytes(), - otherIndex = lbsOther.getOffsetIntoBytes() + offset; - (thisIndex < thisLimit); - ++thisIndex, ++otherIndex) { - if (thisBytes[thisIndex] != otherBytes[otherIndex]) { - return false; - } - } - return true; - } - - return other.substring(offset, offset + length).equals(substring(0, length)); - } - - @Override - protected final int partialHash(int h, int offset, int length) { - return Internal.partialHash(h, bytes, getOffsetIntoBytes() + offset, length); - } - - // ================================================================= - // Input stream - - @Override - public final InputStream newInput() { - return new ByteArrayInputStream(bytes, getOffsetIntoBytes(), size()); // No copy - } - - @Override - public final CodedInputStream newCodedInput() { - // We trust CodedInputStream not to modify the bytes, or to give anyone - // else access to them. - return CodedInputStream.newInstance( - bytes, getOffsetIntoBytes(), size(), /* bufferIsImmutable= */ true); - } - - // ================================================================= - // Internal methods - - /** - * Offset into {@code bytes[]} to use, non-zero for substrings. - * - * @return always 0 for this class - */ - protected int getOffsetIntoBytes() { - return 0; - } - } - - /** - * This class is used to represent the substring of a {@link ByteString} over a single byte array. - * In terms of the public API of {@link ByteString}, you end up here by calling {@link - * ByteString#copyFrom(byte[])} followed by {@link ByteString#substring(int, int)}. - * - *

This class contains most of the overhead involved in creating a substring from a {@link - * LiteralByteString}. The overhead involves some range-checking and two extra fields. - * - * @author carlanton@google.com (Carl Haverl) - */ - // Keep this class private to avoid deadlocks in classloading across threads as ByteString's - // static initializer loads LiteralByteString and another thread loads BoundedByteString. - private static final class BoundedByteString extends LiteralByteString { - private final int bytesOffset; - private final int bytesLength; - - /** - * Creates a {@code BoundedByteString} backed by the sub-range of given array, without copying. - * - * @param bytes array to wrap - * @param offset index to first byte to use in bytes - * @param length number of bytes to use from bytes - * @throws IllegalArgumentException if {@code offset < 0}, {@code length < 0}, or if {@code - * offset + length > bytes.length}. - */ - BoundedByteString(byte[] bytes, int offset, int length) { - super(bytes); - checkRange(offset, offset + length, bytes.length); - - this.bytesOffset = offset; - this.bytesLength = length; - } - - /** - * Gets the byte at the given index. Throws {@link ArrayIndexOutOfBoundsException} for - * backwards-compatibility reasons although it would more properly be {@link - * IndexOutOfBoundsException}. - * - * @param index index of byte - * @return the value - * @throws ArrayIndexOutOfBoundsException {@code index} is < 0 or >= size - */ - @Override - public byte byteAt(int index) { - // We must check the index ourselves as we cannot rely on Java array index - // checking for substrings. - checkIndex(index, size()); - return bytes[bytesOffset + index]; - } - - @Override - byte internalByteAt(int index) { - return bytes[bytesOffset + index]; - } - @Override - public int size() { - return bytesLength; - } - @Override - protected int getOffsetIntoBytes() { - return bytesOffset; - } - // ================================================================= - // ByteString -> byte[] - - @Override - protected void copyToInternal( - byte[] target, int sourceOffset, int targetOffset, int numberToCopy) { - System.arraycopy( - bytes, getOffsetIntoBytes() + sourceOffset, target, targetOffset, numberToCopy); - } - - // ================================================================= - // Serializable - - private static final long serialVersionUID = 1L; - - Object writeReplace() { - return ByteString.wrap(toByteArray()); - } - - private void readObject(@SuppressWarnings("unused") ObjectInputStream in) throws IOException { - throw new InvalidObjectException( - "BoundedByteStream instances are not to be serialized directly"); - } - } } diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/BoundedByteString.java b/protobuf-sdk/src/main/java/com/google/protobuf/BoundedByteString.java new file mode 100644 index 0000000..9da632d --- /dev/null +++ b/protobuf-sdk/src/main/java/com/google/protobuf/BoundedByteString.java @@ -0,0 +1,98 @@ +package com.google.protobuf; + +import java.io.IOException; +import java.io.InvalidObjectException; +import java.io.ObjectInputStream; + +import static com.google.protobuf.ByteString.checkIndex; +import static com.google.protobuf.ByteString.checkRange; + +/** + * This class is used to represent the substring of a {@link ByteString} over a single byte array. + * In terms of the public API of {@link ByteString}, you end up here by calling {@link + * ByteString#copyFrom(byte[])} followed by {@link ByteString#substring(int, int)}. + * + *

This class contains most of the overhead involved in creating a substring from a {@link + * LiteralByteString}. The overhead involves some range-checking and two extra fields. + * + * @author carlanton@google.com (Carl Haverl) + */ +// Keep this class private to avoid deadlocks in classloading across threads as ByteString's +// static initializer loads LiteralByteString and another thread loads BoundedByteString. +final class BoundedByteString extends LiteralByteString { + private final int bytesOffset; + private final int bytesLength; + + /** + * Creates a {@code BoundedByteString} backed by the sub-range of given array, without copying. + * + * @param bytes array to wrap + * @param offset index to first byte to use in bytes + * @param length number of bytes to use from bytes + * @throws IllegalArgumentException if {@code offset < 0}, {@code length < 0}, or if {@code + * offset + length > bytes.length}. + */ + BoundedByteString(byte[] bytes, int offset, int length) { + super(bytes); + checkRange(offset, offset + length, bytes.length); + + this.bytesOffset = offset; + this.bytesLength = length; + } + + /** + * Gets the byte at the given index. Throws {@link ArrayIndexOutOfBoundsException} for + * backwards-compatibility reasons although it would more properly be {@link + * IndexOutOfBoundsException}. + * + * @param index index of byte + * @return the value + * @throws ArrayIndexOutOfBoundsException {@code index} is < 0 or >= size + */ + @Override + public byte byteAt(int index) { + // We must check the index ourselves as we cannot rely on Java array index + // checking for substrings. + checkIndex(index, size()); + return bytes[bytesOffset + index]; + } + + @Override + byte internalByteAt(int index) { + return bytes[bytesOffset + index]; + } + + @Override + public int size() { + return bytesLength; + } + + @Override + protected int getOffsetIntoBytes() { + return bytesOffset; + } + + // ================================================================= + // ByteString -> byte[] + + @Override + protected void copyToInternal( + byte[] target, int sourceOffset, int targetOffset, int numberToCopy) { + System.arraycopy( + bytes, getOffsetIntoBytes() + sourceOffset, target, targetOffset, numberToCopy); + } + + // ================================================================= + // Serializable + + private static final long serialVersionUID = 1L; + + Object writeReplace() { + return ByteString.wrap(toByteArray()); + } + + private void readObject(@SuppressWarnings("unused") ObjectInputStream in) throws IOException { + throw new InvalidObjectException( + "BoundedByteStream instances are not to be serialized directly"); + } +} \ No newline at end of file diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/LeafByteString.java b/protobuf-sdk/src/main/java/com/google/protobuf/LeafByteString.java new file mode 100644 index 0000000..2f70f6e --- /dev/null +++ b/protobuf-sdk/src/main/java/com/google/protobuf/LeafByteString.java @@ -0,0 +1,34 @@ +package com.google.protobuf; + +import java.io.IOException; + +/** Base class for leaf {@link ByteString}s (i.e. non-ropes). */ +abstract class LeafByteString extends ByteString { + private static final long serialVersionUID = 1L; + + @Override + protected final int getTreeDepth() { + return 0; + } + + @Override + protected final boolean isBalanced() { + return true; + } + + @Override + void writeToReverse(ByteOutput byteOutput) throws IOException { + writeTo(byteOutput); + } + + /** + * Check equality of the substring of given length of this object starting at zero with another + * {@code ByteString} substring starting at offset. + * + * @param other what to compare a substring in + * @param offset offset into other + * @param length number of bytes to compare + * @return true for equality of substrings, else false. + */ + abstract boolean equalsRange(ByteString other, int offset, int length); +} \ No newline at end of file diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/LiteralByteString.java b/protobuf-sdk/src/main/java/com/google/protobuf/LiteralByteString.java new file mode 100644 index 0000000..5872e29 --- /dev/null +++ b/protobuf-sdk/src/main/java/com/google/protobuf/LiteralByteString.java @@ -0,0 +1,240 @@ +package com.google.protobuf; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.nio.ByteBuffer; +import java.nio.charset.Charset; +import java.util.Collections; +import java.util.List; + +/** + * This class implements a {@link com.google.protobuf.ByteString} backed by a single array of + * bytes, contiguous in memory. It supports substring by pointing to only a sub-range of the + * underlying byte array, meaning that a substring will reference the full byte-array of the + * string it's made from, exactly as with {@link String}. + * + * @author carlanton@google.com (Carl Haverl) + */ +// Keep this class private to avoid deadlocks in classloading across threads as ByteString's +// static initializer loads LiteralByteString and another thread loads LiteralByteString. +class LiteralByteString extends LeafByteString { + private static final long serialVersionUID = 1L; + + protected final byte[] bytes; + + /** + * Creates a {@code LiteralByteString} backed by the given array, without copying. + * + * @param bytes array to wrap + */ + LiteralByteString(byte[] bytes) { + if (bytes == null) { + throw new NullPointerException(); + } + this.bytes = bytes; + } + + @Override + public byte byteAt(int index) { + // Unlike most methods in this class, this one is a direct implementation + // ignoring the potential offset because we need to do range-checking in the + // substring case anyway. + return bytes[index]; + } + + @Override + byte internalByteAt(int index) { + return bytes[index]; + } + + @Override + public int size() { + return bytes.length; + } + + // ================================================================= + // ByteString -> substring + + @Override + public final ByteString substring(int beginIndex, int endIndex) { + final int length = checkRange(beginIndex, endIndex, size()); + + if (length == 0) { + return ByteString.EMPTY; + } + + return new BoundedByteString(bytes, getOffsetIntoBytes() + beginIndex, length); + } + + // ================================================================= + // ByteString -> byte[] + + @Override + protected void copyToInternal( + byte[] target, int sourceOffset, int targetOffset, int numberToCopy) { + // Optimized form, not for subclasses, since we don't call + // getOffsetIntoBytes() or check the 'numberToCopy' parameter. + // TODO: Is not calling getOffsetIntoBytes really saving that much? + System.arraycopy(bytes, sourceOffset, target, targetOffset, numberToCopy); + } + + @Override + public final void copyTo(ByteBuffer target) { + target.put(bytes, getOffsetIntoBytes(), size()); // Copies bytes + } + + @Override + public final ByteBuffer asReadOnlyByteBuffer() { + return ByteBuffer.wrap(bytes, getOffsetIntoBytes(), size()).asReadOnlyBuffer(); + } + + @Override + public final List asReadOnlyByteBufferList() { + return Collections.singletonList(asReadOnlyByteBuffer()); + } + + @Override + public final void writeTo(OutputStream outputStream) throws IOException { + outputStream.write(toByteArray()); + } + + @Override + final void writeToInternal(OutputStream outputStream, int sourceOffset, int numberToWrite) + throws IOException { + outputStream.write(bytes, getOffsetIntoBytes() + sourceOffset, numberToWrite); + } + + @Override + final void writeTo(ByteOutput output) throws IOException { + output.writeLazy(bytes, getOffsetIntoBytes(), size()); + } + + @Override + protected final String toStringInternal(Charset charset) { + return new String(bytes, getOffsetIntoBytes(), size(), charset); + } + + // ================================================================= + // UTF-8 decoding + + @Override + public final boolean isValidUtf8() { + int offset = getOffsetIntoBytes(); + return Utf8.isValidUtf8(bytes, offset, offset + size()); + } + + @Override + protected final int partialIsValidUtf8(int state, int offset, int length) { + int index = getOffsetIntoBytes() + offset; + return Utf8.partialIsValidUtf8(state, bytes, index, index + length); + } + + // ================================================================= + // equals() and hashCode() + + @Override + public final boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof ByteString)) { + return false; + } + + if (size() != ((ByteString) other).size()) { + return false; + } + if (size() == 0) { + return true; + } + + if (other instanceof LiteralByteString) { + LiteralByteString otherAsLiteral = (LiteralByteString) other; + // If we know the hash codes and they are not equal, we know the byte + // strings are not equal. + int thisHash = peekCachedHashCode(); + int thatHash = otherAsLiteral.peekCachedHashCode(); + if (thisHash != 0 && thatHash != 0 && thisHash != thatHash) { + return false; + } + + return equalsRange((LiteralByteString) other, 0, size()); + } else { + // RopeByteString and NioByteString. + return other.equals(this); + } + } + + /** + * Check equality of the substring of given length of this object starting at zero with another + * {@code LiteralByteString} substring starting at offset. + * + * @param other what to compare a substring in + * @param offset offset into other + * @param length number of bytes to compare + * @return true for equality of substrings, else false. + */ + @Override + final boolean equalsRange(ByteString other, int offset, int length) { + if (length > other.size()) { + throw new IllegalArgumentException("Length too large: " + length + size()); + } + if (offset + length > other.size()) { + throw new IllegalArgumentException( + "Ran off end of other: " + offset + ", " + length + ", " + other.size()); + } + + if (other instanceof LiteralByteString) { + LiteralByteString lbsOther = (LiteralByteString) other; + byte[] thisBytes = bytes; + byte[] otherBytes = lbsOther.bytes; + int thisLimit = getOffsetIntoBytes() + length; + for (int thisIndex = getOffsetIntoBytes(), + otherIndex = lbsOther.getOffsetIntoBytes() + offset; + (thisIndex < thisLimit); + ++thisIndex, ++otherIndex) { + if (thisBytes[thisIndex] != otherBytes[otherIndex]) { + return false; + } + } + return true; + } + + return other.substring(offset, offset + length).equals(substring(0, length)); + } + + @Override + protected final int partialHash(int h, int offset, int length) { + return Internal.partialHash(h, bytes, getOffsetIntoBytes() + offset, length); + } + + // ================================================================= + // Input stream + + @Override + public final InputStream newInput() { + return new ByteArrayInputStream(bytes, getOffsetIntoBytes(), size()); // No copy + } + + @Override + public final CodedInputStream newCodedInput() { + // We trust CodedInputStream not to modify the bytes, or to give anyone + // else access to them. + return CodedInputStream.newInstance( + bytes, getOffsetIntoBytes(), size(), /* bufferIsImmutable= */ true); + } + + // ================================================================= + // Internal methods + + /** + * Offset into {@code bytes[]} to use, non-zero for substrings. + * + * @return always 0 for this class + */ + protected int getOffsetIntoBytes() { + return 0; + } +} diff --git a/protobuf-api/src/main/java/com/google/protobuf/NioByteString.java b/protobuf-sdk/src/main/java/com/google/protobuf/NioByteString.java similarity index 99% rename from protobuf-api/src/main/java/com/google/protobuf/NioByteString.java rename to protobuf-sdk/src/main/java/com/google/protobuf/NioByteString.java index 56c0de9..110ed5f 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/NioByteString.java +++ b/protobuf-sdk/src/main/java/com/google/protobuf/NioByteString.java @@ -22,7 +22,7 @@ import java.util.List; /** A {@link ByteString} that wraps around a {@link ByteBuffer}. */ -final class NioByteString extends ByteString.LeafByteString { +final class NioByteString extends LeafByteString { private final ByteBuffer buffer; NioByteString(ByteBuffer buffer) { diff --git a/protobuf-api/src/main/java/com/google/protobuf/RopeByteString.java b/protobuf-sdk/src/main/java/com/google/protobuf/RopeByteString.java similarity index 100% rename from protobuf-api/src/main/java/com/google/protobuf/RopeByteString.java rename to protobuf-sdk/src/main/java/com/google/protobuf/RopeByteString.java diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/java_features.proto b/protobuf-sdk/src/main/java/com/google/protobuf/java_features.proto deleted file mode 100644 index d02d067..0000000 --- a/protobuf-sdk/src/main/java/com/google/protobuf/java_features.proto +++ /dev/null @@ -1,52 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google Inc. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -syntax = "proto2"; - -package pb; - -import "google/protobuf/descriptor.proto"; - -option java_package = "com.google.protobuf"; -option java_outer_classname = "JavaFeaturesProto"; - -extend google.protobuf.FeatureSet { - optional JavaFeatures java = 1001; -} - -message JavaFeatures { - // Whether or not to treat an enum field as closed. This option is only - // applicable to enum fields, and will be removed in the future. It is - // consistent with the legacy behavior of using proto3 enum types for proto2 - // fields. - optional bool legacy_closed_enum = 1 [ - retention = RETENTION_RUNTIME, - targets = TARGET_TYPE_FIELD, - targets = TARGET_TYPE_FILE, - edition_defaults = { edition: EDITION_PROTO2, value: "true" }, - edition_defaults = { edition: EDITION_PROTO3, value: "false" } - ]; - - // The UTF8 validation strategy to use. See go/editions-utf8-validation for - // more information on this feature. - enum Utf8Validation { - // Invalid default, which should never be used. - UTF8_VALIDATION_UNKNOWN = 0; - // Respect the UTF8 validation behavior specified by the global - // utf8_validation feature. - DEFAULT = 1; - // Verifies UTF8 validity overriding the global utf8_validation - // feature. This represents the legacy java_string_check_utf8 option. - VERIFY = 2; - } - optional Utf8Validation utf8_validation = 2 [ - retention = RETENTION_RUNTIME, - targets = TARGET_TYPE_FIELD, - targets = TARGET_TYPE_FILE, - edition_defaults = { edition: EDITION_PROTO2, value: "DEFAULT" } - ]; -} From 5ccdde0f97ef3cdca1c6ab1d36b0310ae0365a82 Mon Sep 17 00:00:00 2001 From: blakeli Date: Fri, 28 Mar 2025 21:07:32 -0400 Subject: [PATCH 07/42] Decouple WireFormat from CodedOutputStream --- .../google/protobuf/CodedOutputStream.java | 52 ++++++++++++------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/protobuf-api/src/main/java/com/google/protobuf/CodedOutputStream.java b/protobuf-api/src/main/java/com/google/protobuf/CodedOutputStream.java index 90ffcb5..3ef2b4c 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/CodedOutputStream.java +++ b/protobuf-api/src/main/java/com/google/protobuf/CodedOutputStream.java @@ -7,11 +7,6 @@ package com.google.protobuf; -import static com.google.protobuf.WireFormat.FIXED32_SIZE; -import static com.google.protobuf.WireFormat.FIXED64_SIZE; -import static com.google.protobuf.WireFormat.MAX_VARINT_SIZE; -import static java.lang.Math.max; - import com.google.protobuf.Utf8.UnpairedSurrogateException; import java.io.IOException; import java.io.OutputStream; @@ -44,6 +39,21 @@ public abstract class CodedOutputStream extends ByteOutput { /** Used to adapt to the experimental {@link Writer} interface. */ CodedOutputStreamWriter wrapper; + // Field numbers for fields in MessageSet wire format. + static final int MESSAGE_SET_ITEM = 1; + static final int MESSAGE_SET_TYPE_ID = 2; + static final int MESSAGE_SET_MESSAGE = 3; + + static final int TAG_TYPE_BITS = 3; + + static final int FIXED32_SIZE = 4; + static final int FIXED64_SIZE = 8; + static final int MAX_VARINT_SIZE = 10; + + public static final int WIRETYPE_START_GROUP = 3; + public static final int WIRETYPE_END_GROUP = 4; + + /** @deprecated Use {@link #computeFixed32SizeNoTag(int)} instead. */ @Deprecated public static final int LITTLE_ENDIAN_32_SIZE = FIXED32_SIZE; @@ -716,9 +726,9 @@ static int computeMessageSize( * stream. For historical reasons, the wire format differs from normal fields. */ public static int computeMessageSetExtensionSize(final int fieldNumber, final MessageLite value) { - return computeTagSize(WireFormat.MESSAGE_SET_ITEM) * 2 - + computeUInt32Size(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber) - + computeMessageSize(WireFormat.MESSAGE_SET_MESSAGE, value); + return computeTagSize(MESSAGE_SET_ITEM) * 2 + + computeUInt32Size(MESSAGE_SET_TYPE_ID, fieldNumber) + + computeMessageSize(MESSAGE_SET_MESSAGE, value); } /** @@ -727,9 +737,9 @@ public static int computeMessageSetExtensionSize(final int fieldNumber, final Me */ public static int computeRawMessageSetExtensionSize( final int fieldNumber, final ByteString value) { - return computeTagSize(WireFormat.MESSAGE_SET_ITEM) * 2 - + computeUInt32Size(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber) - + computeBytesSize(WireFormat.MESSAGE_SET_MESSAGE, value); + return computeTagSize(MESSAGE_SET_ITEM) * 2 + + computeUInt32Size(MESSAGE_SET_TYPE_ID, fieldNumber) + + computeBytesSize(MESSAGE_SET_MESSAGE, value); } /** @@ -739,16 +749,20 @@ public static int computeRawMessageSetExtensionSize( */ public static int computeLazyFieldMessageSetExtensionSize( final int fieldNumber, final LazyFieldLite value) { - return computeTagSize(WireFormat.MESSAGE_SET_ITEM) * 2 - + computeUInt32Size(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber) - + computeLazyFieldSize(WireFormat.MESSAGE_SET_MESSAGE, value); + return computeTagSize(MESSAGE_SET_ITEM) * 2 + + computeUInt32Size(MESSAGE_SET_TYPE_ID, fieldNumber) + + computeLazyFieldSize(MESSAGE_SET_MESSAGE, value); } // ----------------------------------------------------------------- /** Compute the number of bytes that would be needed to encode a tag. */ public static int computeTagSize(final int fieldNumber) { - return computeUInt32SizeNoTag(WireFormat.makeTag(fieldNumber, 0)); + return computeUInt32SizeNoTag(makeTag(fieldNumber, 0)); + } + + static int makeTag(final int fieldNumber, final int wireType) { + return (fieldNumber << TAG_TYPE_BITS) | wireType; } /** @@ -1049,9 +1063,9 @@ final void inefficientWriteStringNoTag(String value, UnpairedSurrogateException */ @Deprecated public final void writeGroup(final int fieldNumber, final MessageLite value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_START_GROUP); + writeTag(fieldNumber, WIRETYPE_START_GROUP); writeGroupNoTag(value); - writeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP); + writeTag(fieldNumber, WIRETYPE_END_GROUP); } /** @@ -1062,9 +1076,9 @@ public final void writeGroup(final int fieldNumber, final MessageLite value) thr @Deprecated final void writeGroup(final int fieldNumber, final MessageLite value, Schema schema) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_START_GROUP); + writeTag(fieldNumber, WIRETYPE_START_GROUP); writeGroupNoTag(value, schema); - writeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP); + writeTag(fieldNumber, WIRETYPE_END_GROUP); } /** From 07f9b9588f294a0de1296bc1f67bc785a3260d16 Mon Sep 17 00:00:00 2001 From: blakeli Date: Fri, 28 Mar 2025 22:31:39 -0400 Subject: [PATCH 08/42] Make all well known types extend from FlattenedGeneratedMessageV3 --- .../main/java/com/google/protobuf/Any.java | 34 +++++------ .../com/google/protobuf/AnyOrBuilder.java | 0 .../java/com/google/protobuf/AnyProto.java | 4 +- .../main/java/com/google/protobuf/Api.java | 50 ++++++++-------- .../com/google/protobuf/ApiOrBuilder.java | 0 .../java/com/google/protobuf/ApiProto.java | 12 ++-- .../java/com/google/protobuf/BoolValue.java | 26 ++++---- .../google/protobuf/BoolValueOrBuilder.java | 0 .../java/com/google/protobuf/BytesValue.java | 26 ++++---- .../google/protobuf/BytesValueOrBuilder.java | 0 .../java/com/google/protobuf/DoubleValue.java | 26 ++++---- .../google/protobuf/DoubleValueOrBuilder.java | 0 .../java/com/google/protobuf/Duration.java | 26 ++++---- .../google/protobuf/DurationOrBuilder.java | 0 .../com/google/protobuf/DurationProto.java | 4 +- .../main/java/com/google/protobuf/Empty.java | 26 ++++---- .../com/google/protobuf/EmptyOrBuilder.java | 0 .../java/com/google/protobuf/EmptyProto.java | 4 +- .../main/java/com/google/protobuf/Enum.java | 48 +++++++-------- .../com/google/protobuf/EnumOrBuilder.java | 0 .../java/com/google/protobuf/EnumValue.java | 36 +++++------ .../google/protobuf/EnumValueOrBuilder.java | 0 .../main/java/com/google/protobuf/Field.java | 60 +++++++++---------- .../java/com/google/protobuf/FieldMask.java | 28 ++++----- .../google/protobuf/FieldMaskOrBuilder.java | 0 .../com/google/protobuf/FieldMaskProto.java | 4 +- .../com/google/protobuf/FieldOrBuilder.java | 0 .../java/com/google/protobuf/FloatValue.java | 26 ++++---- .../google/protobuf/FloatValueOrBuilder.java | 0 .../java/com/google/protobuf/Int32Value.java | 26 ++++---- .../google/protobuf/Int32ValueOrBuilder.java | 0 .../java/com/google/protobuf/Int64Value.java | 26 ++++---- .../google/protobuf/Int64ValueOrBuilder.java | 0 .../google/protobuf/JavaFeaturesProto.java | 30 +++++----- .../java/com/google/protobuf/ListValue.java | 28 ++++----- .../google/protobuf/ListValueOrBuilder.java | 0 .../com/google/protobuf/MapFieldBuilder.java | 0 .../main/java/com/google/protobuf/Method.java | 52 ++++++++-------- .../com/google/protobuf/MethodOrBuilder.java | 0 .../main/java/com/google/protobuf/Mixin.java | 42 ++++++------- .../com/google/protobuf/MixinOrBuilder.java | 0 .../java/com/google/protobuf/NullValue.java | 0 .../main/java/com/google/protobuf/Option.java | 36 +++++------ .../com/google/protobuf/OptionOrBuilder.java | 0 .../com/google/protobuf/SourceContext.java | 34 +++++------ .../protobuf/SourceContextOrBuilder.java | 0 .../google/protobuf/SourceContextProto.java | 4 +- .../java/com/google/protobuf/StringValue.java | 34 +++++------ .../google/protobuf/StringValueOrBuilder.java | 0 .../main/java/com/google/protobuf/Struct.java | 28 ++++----- .../com/google/protobuf/StructOrBuilder.java | 0 .../java/com/google/protobuf/StructProto.java | 16 ++--- .../main/java/com/google/protobuf/Syntax.java | 0 .../java/com/google/protobuf/Timestamp.java | 26 ++++---- .../google/protobuf/TimestampOrBuilder.java | 0 .../com/google/protobuf/TimestampProto.java | 4 +- .../main/java/com/google/protobuf/Type.java | 50 ++++++++-------- .../com/google/protobuf/TypeOrBuilder.java | 0 .../java/com/google/protobuf/TypeProto.java | 20 +++---- .../java/com/google/protobuf/UInt32Value.java | 26 ++++---- .../google/protobuf/UInt32ValueOrBuilder.java | 0 .../java/com/google/protobuf/UInt64Value.java | 26 ++++---- .../google/protobuf/UInt64ValueOrBuilder.java | 0 .../main/java/com/google/protobuf/Value.java | 30 +++++----- .../com/google/protobuf/ValueOrBuilder.java | 0 .../com/google/protobuf/WrappersProto.java | 36 +++++------ 66 files changed, 507 insertions(+), 507 deletions(-) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/Any.java (96%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/AnyOrBuilder.java (100%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/AnyProto.java (92%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/Api.java (97%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/ApiOrBuilder.java (100%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/ApiProto.java (90%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/BoolValue.java (94%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/BoolValueOrBuilder.java (100%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/BytesValue.java (94%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/BytesValueOrBuilder.java (100%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/DoubleValue.java (94%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/DoubleValueOrBuilder.java (100%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/Duration.java (96%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/DurationOrBuilder.java (100%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/DurationProto.java (93%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/Empty.java (93%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/EmptyOrBuilder.java (100%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/EmptyProto.java (92%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/Enum.java (96%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/EnumOrBuilder.java (100%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/EnumValue.java (95%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/EnumValueOrBuilder.java (100%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/Field.java (96%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/FieldMask.java (96%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/FieldMaskOrBuilder.java (100%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/FieldMaskProto.java (92%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/FieldOrBuilder.java (100%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/FloatValue.java (94%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/FloatValueOrBuilder.java (100%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/Int32Value.java (94%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/Int32ValueOrBuilder.java (100%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/Int64Value.java (94%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/Int64ValueOrBuilder.java (100%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/JavaFeaturesProto.java (97%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/ListValue.java (96%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/ListValueOrBuilder.java (100%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/MapFieldBuilder.java (100%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/Method.java (95%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/MethodOrBuilder.java (100%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/Mixin.java (94%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/MixinOrBuilder.java (100%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/NullValue.java (100%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/Option.java (95%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/OptionOrBuilder.java (100%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/SourceContext.java (93%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/SourceContextOrBuilder.java (100%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/SourceContextProto.java (93%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/StringValue.java (93%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/StringValueOrBuilder.java (100%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/Struct.java (96%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/StructOrBuilder.java (100%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/StructProto.java (88%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/Syntax.java (100%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/Timestamp.java (96%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/TimestampOrBuilder.java (100%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/TimestampProto.java (93%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/Type.java (97%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/TypeOrBuilder.java (100%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/TypeProto.java (90%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/UInt32Value.java (94%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/UInt32ValueOrBuilder.java (100%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/UInt64Value.java (94%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/UInt64ValueOrBuilder.java (100%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/Value.java (97%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/ValueOrBuilder.java (100%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/WrappersProto.java (82%) diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/Any.java b/protobuf-api/src/main/java/com/google/protobuf/Any.java similarity index 96% rename from protobuf-sdk/src/main/java/com/google/protobuf/Any.java rename to protobuf-api/src/main/java/com/google/protobuf/Any.java index 74c8085..d950290 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/Any.java +++ b/protobuf-api/src/main/java/com/google/protobuf/Any.java @@ -96,12 +96,12 @@ * Protobuf type {@code google.protobuf.Any} */ public final class Any extends - com.google.protobuf.GeneratedMessageV3 implements + com.google.protobuf.FlattenedGeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:google.protobuf.Any) AnyOrBuilder { private static final long serialVersionUID = 0L; // Use Any.newBuilder() to construct. - private Any(com.google.protobuf.GeneratedMessageV3.Builder builder) { + private Any(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { super(builder); } private Any() { @@ -122,7 +122,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.AnyProto.internal_static_google_protobuf_Any_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -355,8 +355,8 @@ public final boolean isInitialized() { @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(typeUrl_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 1, typeUrl_); + if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(typeUrl_)) { + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 1, typeUrl_); } if (!value_.isEmpty()) { output.writeBytes(2, value_); @@ -370,8 +370,8 @@ public int getSerializedSize() { if (size != -1) return size; size = 0; - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(typeUrl_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, typeUrl_); + if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(typeUrl_)) { + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(1, typeUrl_); } if (!value_.isEmpty()) { size += com.google.protobuf.CodedOutputStream @@ -450,20 +450,20 @@ public static com.google.protobuf.Any parseFrom( } public static com.google.protobuf.Any parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.Any parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Any parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -471,20 +471,20 @@ public static com.google.protobuf.Any parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Any parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.Any parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -504,7 +504,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -600,7 +600,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.Any} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements + com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.Any) com.google.protobuf.AnyOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -609,7 +609,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.AnyProto.internal_static_google_protobuf_Any_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -622,7 +622,7 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); } diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/AnyOrBuilder.java b/protobuf-api/src/main/java/com/google/protobuf/AnyOrBuilder.java similarity index 100% rename from protobuf-sdk/src/main/java/com/google/protobuf/AnyOrBuilder.java rename to protobuf-api/src/main/java/com/google/protobuf/AnyOrBuilder.java diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/AnyProto.java b/protobuf-api/src/main/java/com/google/protobuf/AnyProto.java similarity index 92% rename from protobuf-sdk/src/main/java/com/google/protobuf/AnyProto.java rename to protobuf-api/src/main/java/com/google/protobuf/AnyProto.java index 2121cd2..e312d05 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/AnyProto.java +++ b/protobuf-api/src/main/java/com/google/protobuf/AnyProto.java @@ -18,7 +18,7 @@ public static void registerAllExtensions( static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_Any_descriptor; static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_Any_fieldAccessorTable; public static com.google.protobuf.Descriptors.FileDescriptor @@ -43,7 +43,7 @@ public static void registerAllExtensions( internal_static_google_protobuf_Any_descriptor = getDescriptor().getMessageTypes().get(0); internal_static_google_protobuf_Any_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_Any_descriptor, new java.lang.String[] { "TypeUrl", "Value", }); } diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/Api.java b/protobuf-api/src/main/java/com/google/protobuf/Api.java similarity index 97% rename from protobuf-sdk/src/main/java/com/google/protobuf/Api.java rename to protobuf-api/src/main/java/com/google/protobuf/Api.java index afd6947..22b8493 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/Api.java +++ b/protobuf-api/src/main/java/com/google/protobuf/Api.java @@ -20,12 +20,12 @@ * Protobuf type {@code google.protobuf.Api} */ public final class Api extends - com.google.protobuf.GeneratedMessageV3 implements + com.google.protobuf.FlattenedGeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:google.protobuf.Api) ApiOrBuilder { private static final long serialVersionUID = 0L; // Use Api.newBuilder() to construct. - private Api(com.google.protobuf.GeneratedMessageV3.Builder builder) { + private Api(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { super(builder); } private Api() { @@ -50,7 +50,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.ApiProto.internal_static_google_protobuf_Api_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -454,8 +454,8 @@ public final boolean isInitialized() { @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 1, name_); + if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(name_)) { + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 1, name_); } for (int i = 0; i < methods_.size(); i++) { output.writeMessage(2, methods_.get(i)); @@ -463,8 +463,8 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) for (int i = 0; i < options_.size(); i++) { output.writeMessage(3, options_.get(i)); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(version_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 4, version_); + if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(version_)) { + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 4, version_); } if (((bitField0_ & 0x00000001) != 0)) { output.writeMessage(5, getSourceContext()); @@ -484,8 +484,8 @@ public int getSerializedSize() { if (size != -1) return size; size = 0; - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, name_); + if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(name_)) { + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(1, name_); } for (int i = 0; i < methods_.size(); i++) { size += com.google.protobuf.CodedOutputStream @@ -495,8 +495,8 @@ public int getSerializedSize() { size += com.google.protobuf.CodedOutputStream .computeMessageSize(3, options_.get(i)); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(version_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(4, version_); + if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(version_)) { + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(4, version_); } if (((bitField0_ & 0x00000001) != 0)) { size += com.google.protobuf.CodedOutputStream @@ -613,20 +613,20 @@ public static com.google.protobuf.Api parseFrom( } public static com.google.protobuf.Api parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.Api parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Api parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -634,20 +634,20 @@ public static com.google.protobuf.Api parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Api parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.Api parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -667,7 +667,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -687,7 +687,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.Api} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements + com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.Api) com.google.protobuf.ApiOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -696,7 +696,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.ApiProto.internal_static_google_protobuf_Api_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -709,12 +709,12 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 + if (com.google.protobuf.FlattenedGeneratedMessageV3 .alwaysUseFieldBuilders) { getMethodsFieldBuilder(); getOptionsFieldBuilder(); @@ -906,7 +906,7 @@ public Builder mergeFrom(com.google.protobuf.Api other) { methods_ = other.methods_; bitField0_ = (bitField0_ & ~0x00000002); methodsBuilder_ = - com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? getMethodsFieldBuilder() : null; } else { methodsBuilder_.addAllMessages(other.methods_); @@ -932,7 +932,7 @@ public Builder mergeFrom(com.google.protobuf.Api other) { options_ = other.options_; bitField0_ = (bitField0_ & ~0x00000004); optionsBuilder_ = - com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? getOptionsFieldBuilder() : null; } else { optionsBuilder_.addAllMessages(other.options_); @@ -966,7 +966,7 @@ public Builder mergeFrom(com.google.protobuf.Api other) { mixins_ = other.mixins_; bitField0_ = (bitField0_ & ~0x00000020); mixinsBuilder_ = - com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? getMixinsFieldBuilder() : null; } else { mixinsBuilder_.addAllMessages(other.mixins_); diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/ApiOrBuilder.java b/protobuf-api/src/main/java/com/google/protobuf/ApiOrBuilder.java similarity index 100% rename from protobuf-sdk/src/main/java/com/google/protobuf/ApiOrBuilder.java rename to protobuf-api/src/main/java/com/google/protobuf/ApiOrBuilder.java diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/ApiProto.java b/protobuf-api/src/main/java/com/google/protobuf/ApiProto.java similarity index 90% rename from protobuf-sdk/src/main/java/com/google/protobuf/ApiProto.java rename to protobuf-api/src/main/java/com/google/protobuf/ApiProto.java index e96e7b2..e12d52e 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/ApiProto.java +++ b/protobuf-api/src/main/java/com/google/protobuf/ApiProto.java @@ -18,17 +18,17 @@ public static void registerAllExtensions( static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_Api_descriptor; static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_Api_fieldAccessorTable; static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_Method_descriptor; static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_Method_fieldAccessorTable; static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_Mixin_descriptor; static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_Mixin_fieldAccessorTable; public static com.google.protobuf.Descriptors.FileDescriptor @@ -68,19 +68,19 @@ public static void registerAllExtensions( internal_static_google_protobuf_Api_descriptor = getDescriptor().getMessageTypes().get(0); internal_static_google_protobuf_Api_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_Api_descriptor, new java.lang.String[] { "Name", "Methods", "Options", "Version", "SourceContext", "Mixins", "Syntax", }); internal_static_google_protobuf_Method_descriptor = getDescriptor().getMessageTypes().get(1); internal_static_google_protobuf_Method_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_Method_descriptor, new java.lang.String[] { "Name", "RequestTypeUrl", "RequestStreaming", "ResponseTypeUrl", "ResponseStreaming", "Options", "Syntax", }); internal_static_google_protobuf_Mixin_descriptor = getDescriptor().getMessageTypes().get(2); internal_static_google_protobuf_Mixin_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_Mixin_descriptor, new java.lang.String[] { "Name", "Root", }); com.google.protobuf.SourceContextProto.getDescriptor(); diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/BoolValue.java b/protobuf-api/src/main/java/com/google/protobuf/BoolValue.java similarity index 94% rename from protobuf-sdk/src/main/java/com/google/protobuf/BoolValue.java rename to protobuf-api/src/main/java/com/google/protobuf/BoolValue.java index a015e51..c3b51ee 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/BoolValue.java +++ b/protobuf-api/src/main/java/com/google/protobuf/BoolValue.java @@ -14,12 +14,12 @@ * Protobuf type {@code google.protobuf.BoolValue} */ public final class BoolValue extends - com.google.protobuf.GeneratedMessageV3 implements + com.google.protobuf.FlattenedGeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:google.protobuf.BoolValue) BoolValueOrBuilder { private static final long serialVersionUID = 0L; // Use BoolValue.newBuilder() to construct. - private BoolValue(com.google.protobuf.GeneratedMessageV3.Builder builder) { + private BoolValue(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { super(builder); } private BoolValue() { @@ -38,7 +38,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.WrappersProto.internal_static_google_protobuf_BoolValue_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -160,20 +160,20 @@ public static com.google.protobuf.BoolValue parseFrom( } public static com.google.protobuf.BoolValue parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.BoolValue parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.BoolValue parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -181,20 +181,20 @@ public static com.google.protobuf.BoolValue parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.BoolValue parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.BoolValue parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -214,7 +214,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -228,7 +228,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.BoolValue} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements + com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.BoolValue) com.google.protobuf.BoolValueOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -237,7 +237,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.WrappersProto.internal_static_google_protobuf_BoolValue_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -250,7 +250,7 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); } diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/BoolValueOrBuilder.java b/protobuf-api/src/main/java/com/google/protobuf/BoolValueOrBuilder.java similarity index 100% rename from protobuf-sdk/src/main/java/com/google/protobuf/BoolValueOrBuilder.java rename to protobuf-api/src/main/java/com/google/protobuf/BoolValueOrBuilder.java diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/BytesValue.java b/protobuf-api/src/main/java/com/google/protobuf/BytesValue.java similarity index 94% rename from protobuf-sdk/src/main/java/com/google/protobuf/BytesValue.java rename to protobuf-api/src/main/java/com/google/protobuf/BytesValue.java index 44eaefe..8b70f3e 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/BytesValue.java +++ b/protobuf-api/src/main/java/com/google/protobuf/BytesValue.java @@ -14,12 +14,12 @@ * Protobuf type {@code google.protobuf.BytesValue} */ public final class BytesValue extends - com.google.protobuf.GeneratedMessageV3 implements + com.google.protobuf.FlattenedGeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:google.protobuf.BytesValue) BytesValueOrBuilder { private static final long serialVersionUID = 0L; // Use BytesValue.newBuilder() to construct. - private BytesValue(com.google.protobuf.GeneratedMessageV3.Builder builder) { + private BytesValue(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { super(builder); } private BytesValue() { @@ -39,7 +39,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.WrappersProto.internal_static_google_protobuf_BytesValue_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -160,20 +160,20 @@ public static com.google.protobuf.BytesValue parseFrom( } public static com.google.protobuf.BytesValue parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.BytesValue parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.BytesValue parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -181,20 +181,20 @@ public static com.google.protobuf.BytesValue parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.BytesValue parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.BytesValue parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -214,7 +214,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -228,7 +228,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.BytesValue} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements + com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.BytesValue) com.google.protobuf.BytesValueOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -237,7 +237,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.WrappersProto.internal_static_google_protobuf_BytesValue_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -250,7 +250,7 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); } diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/BytesValueOrBuilder.java b/protobuf-api/src/main/java/com/google/protobuf/BytesValueOrBuilder.java similarity index 100% rename from protobuf-sdk/src/main/java/com/google/protobuf/BytesValueOrBuilder.java rename to protobuf-api/src/main/java/com/google/protobuf/BytesValueOrBuilder.java diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/DoubleValue.java b/protobuf-api/src/main/java/com/google/protobuf/DoubleValue.java similarity index 94% rename from protobuf-sdk/src/main/java/com/google/protobuf/DoubleValue.java rename to protobuf-api/src/main/java/com/google/protobuf/DoubleValue.java index 974047a..9a0b11f 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/DoubleValue.java +++ b/protobuf-api/src/main/java/com/google/protobuf/DoubleValue.java @@ -14,12 +14,12 @@ * Protobuf type {@code google.protobuf.DoubleValue} */ public final class DoubleValue extends - com.google.protobuf.GeneratedMessageV3 implements + com.google.protobuf.FlattenedGeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:google.protobuf.DoubleValue) DoubleValueOrBuilder { private static final long serialVersionUID = 0L; // Use DoubleValue.newBuilder() to construct. - private DoubleValue(com.google.protobuf.GeneratedMessageV3.Builder builder) { + private DoubleValue(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { super(builder); } private DoubleValue() { @@ -38,7 +38,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.WrappersProto.internal_static_google_protobuf_DoubleValue_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -161,20 +161,20 @@ public static com.google.protobuf.DoubleValue parseFrom( } public static com.google.protobuf.DoubleValue parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DoubleValue parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DoubleValue parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -182,20 +182,20 @@ public static com.google.protobuf.DoubleValue parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DoubleValue parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.DoubleValue parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -215,7 +215,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -229,7 +229,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.DoubleValue} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements + com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.DoubleValue) com.google.protobuf.DoubleValueOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -238,7 +238,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.WrappersProto.internal_static_google_protobuf_DoubleValue_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -251,7 +251,7 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); } diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/DoubleValueOrBuilder.java b/protobuf-api/src/main/java/com/google/protobuf/DoubleValueOrBuilder.java similarity index 100% rename from protobuf-sdk/src/main/java/com/google/protobuf/DoubleValueOrBuilder.java rename to protobuf-api/src/main/java/com/google/protobuf/DoubleValueOrBuilder.java diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/Duration.java b/protobuf-api/src/main/java/com/google/protobuf/Duration.java similarity index 96% rename from protobuf-sdk/src/main/java/com/google/protobuf/Duration.java rename to protobuf-api/src/main/java/com/google/protobuf/Duration.java index b0679c0..361ee3d 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/Duration.java +++ b/protobuf-api/src/main/java/com/google/protobuf/Duration.java @@ -69,12 +69,12 @@ * Protobuf type {@code google.protobuf.Duration} */ public final class Duration extends - com.google.protobuf.GeneratedMessageV3 implements + com.google.protobuf.FlattenedGeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:google.protobuf.Duration) DurationOrBuilder { private static final long serialVersionUID = 0L; // Use Duration.newBuilder() to construct. - private Duration(com.google.protobuf.GeneratedMessageV3.Builder builder) { + private Duration(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { super(builder); } private Duration() { @@ -93,7 +93,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DurationProto.internal_static_google_protobuf_Duration_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -248,20 +248,20 @@ public static com.google.protobuf.Duration parseFrom( } public static com.google.protobuf.Duration parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.Duration parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Duration parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -269,20 +269,20 @@ public static com.google.protobuf.Duration parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Duration parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.Duration parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -302,7 +302,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -371,7 +371,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.Duration} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements + com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.Duration) com.google.protobuf.DurationOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -380,7 +380,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DurationProto.internal_static_google_protobuf_Duration_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -393,7 +393,7 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); } diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/DurationOrBuilder.java b/protobuf-api/src/main/java/com/google/protobuf/DurationOrBuilder.java similarity index 100% rename from protobuf-sdk/src/main/java/com/google/protobuf/DurationOrBuilder.java rename to protobuf-api/src/main/java/com/google/protobuf/DurationOrBuilder.java diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/DurationProto.java b/protobuf-api/src/main/java/com/google/protobuf/DurationProto.java similarity index 93% rename from protobuf-sdk/src/main/java/com/google/protobuf/DurationProto.java rename to protobuf-api/src/main/java/com/google/protobuf/DurationProto.java index cd13d21..275746b 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/DurationProto.java +++ b/protobuf-api/src/main/java/com/google/protobuf/DurationProto.java @@ -18,7 +18,7 @@ public static void registerAllExtensions( static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_Duration_descriptor; static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_Duration_fieldAccessorTable; public static com.google.protobuf.Descriptors.FileDescriptor @@ -43,7 +43,7 @@ public static void registerAllExtensions( internal_static_google_protobuf_Duration_descriptor = getDescriptor().getMessageTypes().get(0); internal_static_google_protobuf_Duration_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_Duration_descriptor, new java.lang.String[] { "Seconds", "Nanos", }); } diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/Empty.java b/protobuf-api/src/main/java/com/google/protobuf/Empty.java similarity index 93% rename from protobuf-sdk/src/main/java/com/google/protobuf/Empty.java rename to protobuf-api/src/main/java/com/google/protobuf/Empty.java index 04437a3..38426dc 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/Empty.java +++ b/protobuf-api/src/main/java/com/google/protobuf/Empty.java @@ -18,12 +18,12 @@ * Protobuf type {@code google.protobuf.Empty} */ public final class Empty extends - com.google.protobuf.GeneratedMessageV3 implements + com.google.protobuf.FlattenedGeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:google.protobuf.Empty) EmptyOrBuilder { private static final long serialVersionUID = 0L; // Use Empty.newBuilder() to construct. - private Empty(com.google.protobuf.GeneratedMessageV3.Builder builder) { + private Empty(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { super(builder); } private Empty() { @@ -42,7 +42,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.EmptyProto.internal_static_google_protobuf_Empty_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -137,20 +137,20 @@ public static com.google.protobuf.Empty parseFrom( } public static com.google.protobuf.Empty parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.Empty parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Empty parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -158,20 +158,20 @@ public static com.google.protobuf.Empty parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Empty parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.Empty parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -191,7 +191,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -209,7 +209,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.Empty} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements + com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.Empty) com.google.protobuf.EmptyOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -218,7 +218,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.EmptyProto.internal_static_google_protobuf_Empty_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -231,7 +231,7 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); } diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/EmptyOrBuilder.java b/protobuf-api/src/main/java/com/google/protobuf/EmptyOrBuilder.java similarity index 100% rename from protobuf-sdk/src/main/java/com/google/protobuf/EmptyOrBuilder.java rename to protobuf-api/src/main/java/com/google/protobuf/EmptyOrBuilder.java diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/EmptyProto.java b/protobuf-api/src/main/java/com/google/protobuf/EmptyProto.java similarity index 92% rename from protobuf-sdk/src/main/java/com/google/protobuf/EmptyProto.java rename to protobuf-api/src/main/java/com/google/protobuf/EmptyProto.java index 666acb2..dd55151 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/EmptyProto.java +++ b/protobuf-api/src/main/java/com/google/protobuf/EmptyProto.java @@ -18,7 +18,7 @@ public static void registerAllExtensions( static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_Empty_descriptor; static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_Empty_fieldAccessorTable; public static com.google.protobuf.Descriptors.FileDescriptor @@ -42,7 +42,7 @@ public static void registerAllExtensions( internal_static_google_protobuf_Empty_descriptor = getDescriptor().getMessageTypes().get(0); internal_static_google_protobuf_Empty_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_Empty_descriptor, new java.lang.String[] { }); } diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/Enum.java b/protobuf-api/src/main/java/com/google/protobuf/Enum.java similarity index 96% rename from protobuf-sdk/src/main/java/com/google/protobuf/Enum.java rename to protobuf-api/src/main/java/com/google/protobuf/Enum.java index 17f3bf8..683b733 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/Enum.java +++ b/protobuf-api/src/main/java/com/google/protobuf/Enum.java @@ -12,12 +12,12 @@ * Protobuf type {@code google.protobuf.Enum} */ public final class Enum extends - com.google.protobuf.GeneratedMessageV3 implements + com.google.protobuf.FlattenedGeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:google.protobuf.Enum) EnumOrBuilder { private static final long serialVersionUID = 0L; // Use Enum.newBuilder() to construct. - private Enum(com.google.protobuf.GeneratedMessageV3.Builder builder) { + private Enum(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { super(builder); } private Enum() { @@ -41,7 +41,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.TypeProto.internal_static_google_protobuf_Enum_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -343,8 +343,8 @@ public final boolean isInitialized() { @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 1, name_); + if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(name_)) { + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 1, name_); } for (int i = 0; i < enumvalue_.size(); i++) { output.writeMessage(2, enumvalue_.get(i)); @@ -358,8 +358,8 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) if (syntax_ != com.google.protobuf.Syntax.SYNTAX_PROTO2.getNumber()) { output.writeEnum(5, syntax_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(edition_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 6, edition_); + if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(edition_)) { + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 6, edition_); } getUnknownFields().writeTo(output); } @@ -370,8 +370,8 @@ public int getSerializedSize() { if (size != -1) return size; size = 0; - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, name_); + if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(name_)) { + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(1, name_); } for (int i = 0; i < enumvalue_.size(); i++) { size += com.google.protobuf.CodedOutputStream @@ -389,8 +389,8 @@ public int getSerializedSize() { size += com.google.protobuf.CodedOutputStream .computeEnumSize(5, syntax_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(edition_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(6, edition_); + if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(edition_)) { + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(6, edition_); } size += getUnknownFields().getSerializedSize(); memoizedSize = size; @@ -489,20 +489,20 @@ public static com.google.protobuf.Enum parseFrom( } public static com.google.protobuf.Enum parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.Enum parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Enum parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -510,20 +510,20 @@ public static com.google.protobuf.Enum parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Enum parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.Enum parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -543,7 +543,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -555,7 +555,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.Enum} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements + com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.Enum) com.google.protobuf.EnumOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -564,7 +564,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.TypeProto.internal_static_google_protobuf_Enum_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -577,12 +577,12 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 + if (com.google.protobuf.FlattenedGeneratedMessageV3 .alwaysUseFieldBuilders) { getEnumvalueFieldBuilder(); getOptionsFieldBuilder(); @@ -757,7 +757,7 @@ public Builder mergeFrom(com.google.protobuf.Enum other) { enumvalue_ = other.enumvalue_; bitField0_ = (bitField0_ & ~0x00000002); enumvalueBuilder_ = - com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? getEnumvalueFieldBuilder() : null; } else { enumvalueBuilder_.addAllMessages(other.enumvalue_); @@ -783,7 +783,7 @@ public Builder mergeFrom(com.google.protobuf.Enum other) { options_ = other.options_; bitField0_ = (bitField0_ & ~0x00000004); optionsBuilder_ = - com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? getOptionsFieldBuilder() : null; } else { optionsBuilder_.addAllMessages(other.options_); diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/EnumOrBuilder.java b/protobuf-api/src/main/java/com/google/protobuf/EnumOrBuilder.java similarity index 100% rename from protobuf-sdk/src/main/java/com/google/protobuf/EnumOrBuilder.java rename to protobuf-api/src/main/java/com/google/protobuf/EnumOrBuilder.java diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/EnumValue.java b/protobuf-api/src/main/java/com/google/protobuf/EnumValue.java similarity index 95% rename from protobuf-sdk/src/main/java/com/google/protobuf/EnumValue.java rename to protobuf-api/src/main/java/com/google/protobuf/EnumValue.java index 62634f4..8d928d6 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/EnumValue.java +++ b/protobuf-api/src/main/java/com/google/protobuf/EnumValue.java @@ -12,12 +12,12 @@ * Protobuf type {@code google.protobuf.EnumValue} */ public final class EnumValue extends - com.google.protobuf.GeneratedMessageV3 implements + com.google.protobuf.FlattenedGeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:google.protobuf.EnumValue) EnumValueOrBuilder { private static final long serialVersionUID = 0L; // Use EnumValue.newBuilder() to construct. - private EnumValue(com.google.protobuf.GeneratedMessageV3.Builder builder) { + private EnumValue(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { super(builder); } private EnumValue() { @@ -38,7 +38,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.TypeProto.internal_static_google_protobuf_EnumValue_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -182,8 +182,8 @@ public final boolean isInitialized() { @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 1, name_); + if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(name_)) { + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 1, name_); } if (number_ != 0) { output.writeInt32(2, number_); @@ -200,8 +200,8 @@ public int getSerializedSize() { if (size != -1) return size; size = 0; - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, name_); + if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(name_)) { + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(1, name_); } if (number_ != 0) { size += com.google.protobuf.CodedOutputStream @@ -290,20 +290,20 @@ public static com.google.protobuf.EnumValue parseFrom( } public static com.google.protobuf.EnumValue parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.EnumValue parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.EnumValue parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -311,20 +311,20 @@ public static com.google.protobuf.EnumValue parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.EnumValue parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.EnumValue parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -344,7 +344,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -356,7 +356,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.EnumValue} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements + com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.EnumValue) com.google.protobuf.EnumValueOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -365,7 +365,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.TypeProto.internal_static_google_protobuf_EnumValue_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -378,7 +378,7 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); } @@ -520,7 +520,7 @@ public Builder mergeFrom(com.google.protobuf.EnumValue other) { options_ = other.options_; bitField0_ = (bitField0_ & ~0x00000004); optionsBuilder_ = - com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? getOptionsFieldBuilder() : null; } else { optionsBuilder_.addAllMessages(other.options_); diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/EnumValueOrBuilder.java b/protobuf-api/src/main/java/com/google/protobuf/EnumValueOrBuilder.java similarity index 100% rename from protobuf-sdk/src/main/java/com/google/protobuf/EnumValueOrBuilder.java rename to protobuf-api/src/main/java/com/google/protobuf/EnumValueOrBuilder.java diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/Field.java b/protobuf-api/src/main/java/com/google/protobuf/Field.java similarity index 96% rename from protobuf-sdk/src/main/java/com/google/protobuf/Field.java rename to protobuf-api/src/main/java/com/google/protobuf/Field.java index 0cd180b..0ca9ed0 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/Field.java +++ b/protobuf-api/src/main/java/com/google/protobuf/Field.java @@ -12,12 +12,12 @@ * Protobuf type {@code google.protobuf.Field} */ public final class Field extends - com.google.protobuf.GeneratedMessageV3 implements + com.google.protobuf.FlattenedGeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:google.protobuf.Field) FieldOrBuilder { private static final long serialVersionUID = 0L; // Use Field.newBuilder() to construct. - private Field(com.google.protobuf.GeneratedMessageV3.Builder builder) { + private Field(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { super(builder); } private Field() { @@ -43,7 +43,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.TypeProto.internal_static_google_protobuf_Field_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -1001,11 +1001,11 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) if (number_ != 0) { output.writeInt32(3, number_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 4, name_); + if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(name_)) { + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 4, name_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(typeUrl_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 6, typeUrl_); + if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(typeUrl_)) { + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 6, typeUrl_); } if (oneofIndex_ != 0) { output.writeInt32(7, oneofIndex_); @@ -1016,11 +1016,11 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) for (int i = 0; i < options_.size(); i++) { output.writeMessage(9, options_.get(i)); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(jsonName_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 10, jsonName_); + if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(jsonName_)) { + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 10, jsonName_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(defaultValue_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 11, defaultValue_); + if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(defaultValue_)) { + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 11, defaultValue_); } getUnknownFields().writeTo(output); } @@ -1043,11 +1043,11 @@ public int getSerializedSize() { size += com.google.protobuf.CodedOutputStream .computeInt32Size(3, number_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(4, name_); + if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(name_)) { + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(4, name_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(typeUrl_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(6, typeUrl_); + if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(typeUrl_)) { + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(6, typeUrl_); } if (oneofIndex_ != 0) { size += com.google.protobuf.CodedOutputStream @@ -1061,11 +1061,11 @@ public int getSerializedSize() { size += com.google.protobuf.CodedOutputStream .computeMessageSize(9, options_.get(i)); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(jsonName_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(10, jsonName_); + if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(jsonName_)) { + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(10, jsonName_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(defaultValue_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(11, defaultValue_); + if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(defaultValue_)) { + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(11, defaultValue_); } size += getUnknownFields().getSerializedSize(); memoizedSize = size; @@ -1173,20 +1173,20 @@ public static com.google.protobuf.Field parseFrom( } public static com.google.protobuf.Field parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.Field parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Field parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -1194,20 +1194,20 @@ public static com.google.protobuf.Field parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Field parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.Field parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -1227,7 +1227,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -1239,7 +1239,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.Field} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements + com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.Field) com.google.protobuf.FieldOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -1248,7 +1248,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.TypeProto.internal_static_google_protobuf_Field_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -1261,7 +1261,7 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); } @@ -1448,7 +1448,7 @@ public Builder mergeFrom(com.google.protobuf.Field other) { options_ = other.options_; bitField0_ = (bitField0_ & ~0x00000080); optionsBuilder_ = - com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? getOptionsFieldBuilder() : null; } else { optionsBuilder_.addAllMessages(other.options_); diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/FieldMask.java b/protobuf-api/src/main/java/com/google/protobuf/FieldMask.java similarity index 96% rename from protobuf-sdk/src/main/java/com/google/protobuf/FieldMask.java rename to protobuf-api/src/main/java/com/google/protobuf/FieldMask.java index 5aab429..c5fa321 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/FieldMask.java +++ b/protobuf-api/src/main/java/com/google/protobuf/FieldMask.java @@ -210,12 +210,12 @@ * Protobuf type {@code google.protobuf.FieldMask} */ public final class FieldMask extends - com.google.protobuf.GeneratedMessageV3 implements + com.google.protobuf.FlattenedGeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:google.protobuf.FieldMask) FieldMaskOrBuilder { private static final long serialVersionUID = 0L; // Use FieldMask.newBuilder() to construct. - private FieldMask(com.google.protobuf.GeneratedMessageV3.Builder builder) { + private FieldMask(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { super(builder); } private FieldMask() { @@ -236,7 +236,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.FieldMaskProto.internal_static_google_protobuf_FieldMask_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -311,7 +311,7 @@ public final boolean isInitialized() { public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { for (int i = 0; i < paths_.size(); i++) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 1, paths_.getRaw(i)); + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 1, paths_.getRaw(i)); } getUnknownFields().writeTo(output); } @@ -401,20 +401,20 @@ public static com.google.protobuf.FieldMask parseFrom( } public static com.google.protobuf.FieldMask parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.FieldMask parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.FieldMask parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -422,20 +422,20 @@ public static com.google.protobuf.FieldMask parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.FieldMask parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.FieldMask parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -455,7 +455,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -665,7 +665,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.FieldMask} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements + com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.FieldMask) com.google.protobuf.FieldMaskOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -674,7 +674,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.FieldMaskProto.internal_static_google_protobuf_FieldMask_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -687,7 +687,7 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); } diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/FieldMaskOrBuilder.java b/protobuf-api/src/main/java/com/google/protobuf/FieldMaskOrBuilder.java similarity index 100% rename from protobuf-sdk/src/main/java/com/google/protobuf/FieldMaskOrBuilder.java rename to protobuf-api/src/main/java/com/google/protobuf/FieldMaskOrBuilder.java diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/FieldMaskProto.java b/protobuf-api/src/main/java/com/google/protobuf/FieldMaskProto.java similarity index 92% rename from protobuf-sdk/src/main/java/com/google/protobuf/FieldMaskProto.java rename to protobuf-api/src/main/java/com/google/protobuf/FieldMaskProto.java index cfc5499..39d49ab 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/FieldMaskProto.java +++ b/protobuf-api/src/main/java/com/google/protobuf/FieldMaskProto.java @@ -18,7 +18,7 @@ public static void registerAllExtensions( static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_FieldMask_descriptor; static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_FieldMask_fieldAccessorTable; public static com.google.protobuf.Descriptors.FileDescriptor @@ -43,7 +43,7 @@ public static void registerAllExtensions( internal_static_google_protobuf_FieldMask_descriptor = getDescriptor().getMessageTypes().get(0); internal_static_google_protobuf_FieldMask_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_FieldMask_descriptor, new java.lang.String[] { "Paths", }); } diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/FieldOrBuilder.java b/protobuf-api/src/main/java/com/google/protobuf/FieldOrBuilder.java similarity index 100% rename from protobuf-sdk/src/main/java/com/google/protobuf/FieldOrBuilder.java rename to protobuf-api/src/main/java/com/google/protobuf/FieldOrBuilder.java diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/FloatValue.java b/protobuf-api/src/main/java/com/google/protobuf/FloatValue.java similarity index 94% rename from protobuf-sdk/src/main/java/com/google/protobuf/FloatValue.java rename to protobuf-api/src/main/java/com/google/protobuf/FloatValue.java index 4b4a8d4..07dc2da 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/FloatValue.java +++ b/protobuf-api/src/main/java/com/google/protobuf/FloatValue.java @@ -14,12 +14,12 @@ * Protobuf type {@code google.protobuf.FloatValue} */ public final class FloatValue extends - com.google.protobuf.GeneratedMessageV3 implements + com.google.protobuf.FlattenedGeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:google.protobuf.FloatValue) FloatValueOrBuilder { private static final long serialVersionUID = 0L; // Use FloatValue.newBuilder() to construct. - private FloatValue(com.google.protobuf.GeneratedMessageV3.Builder builder) { + private FloatValue(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { super(builder); } private FloatValue() { @@ -38,7 +38,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.WrappersProto.internal_static_google_protobuf_FloatValue_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -161,20 +161,20 @@ public static com.google.protobuf.FloatValue parseFrom( } public static com.google.protobuf.FloatValue parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.FloatValue parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.FloatValue parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -182,20 +182,20 @@ public static com.google.protobuf.FloatValue parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.FloatValue parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.FloatValue parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -215,7 +215,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -229,7 +229,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.FloatValue} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements + com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.FloatValue) com.google.protobuf.FloatValueOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -238,7 +238,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.WrappersProto.internal_static_google_protobuf_FloatValue_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -251,7 +251,7 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); } diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/FloatValueOrBuilder.java b/protobuf-api/src/main/java/com/google/protobuf/FloatValueOrBuilder.java similarity index 100% rename from protobuf-sdk/src/main/java/com/google/protobuf/FloatValueOrBuilder.java rename to protobuf-api/src/main/java/com/google/protobuf/FloatValueOrBuilder.java diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/Int32Value.java b/protobuf-api/src/main/java/com/google/protobuf/Int32Value.java similarity index 94% rename from protobuf-sdk/src/main/java/com/google/protobuf/Int32Value.java rename to protobuf-api/src/main/java/com/google/protobuf/Int32Value.java index e14fc28..b6ca2bb 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/Int32Value.java +++ b/protobuf-api/src/main/java/com/google/protobuf/Int32Value.java @@ -14,12 +14,12 @@ * Protobuf type {@code google.protobuf.Int32Value} */ public final class Int32Value extends - com.google.protobuf.GeneratedMessageV3 implements + com.google.protobuf.FlattenedGeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:google.protobuf.Int32Value) Int32ValueOrBuilder { private static final long serialVersionUID = 0L; // Use Int32Value.newBuilder() to construct. - private Int32Value(com.google.protobuf.GeneratedMessageV3.Builder builder) { + private Int32Value(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { super(builder); } private Int32Value() { @@ -38,7 +38,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.WrappersProto.internal_static_google_protobuf_Int32Value_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -159,20 +159,20 @@ public static com.google.protobuf.Int32Value parseFrom( } public static com.google.protobuf.Int32Value parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.Int32Value parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Int32Value parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -180,20 +180,20 @@ public static com.google.protobuf.Int32Value parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Int32Value parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.Int32Value parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -213,7 +213,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -227,7 +227,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.Int32Value} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements + com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.Int32Value) com.google.protobuf.Int32ValueOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -236,7 +236,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.WrappersProto.internal_static_google_protobuf_Int32Value_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -249,7 +249,7 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); } diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/Int32ValueOrBuilder.java b/protobuf-api/src/main/java/com/google/protobuf/Int32ValueOrBuilder.java similarity index 100% rename from protobuf-sdk/src/main/java/com/google/protobuf/Int32ValueOrBuilder.java rename to protobuf-api/src/main/java/com/google/protobuf/Int32ValueOrBuilder.java diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/Int64Value.java b/protobuf-api/src/main/java/com/google/protobuf/Int64Value.java similarity index 94% rename from protobuf-sdk/src/main/java/com/google/protobuf/Int64Value.java rename to protobuf-api/src/main/java/com/google/protobuf/Int64Value.java index 0d7c811..250d70d 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/Int64Value.java +++ b/protobuf-api/src/main/java/com/google/protobuf/Int64Value.java @@ -14,12 +14,12 @@ * Protobuf type {@code google.protobuf.Int64Value} */ public final class Int64Value extends - com.google.protobuf.GeneratedMessageV3 implements + com.google.protobuf.FlattenedGeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:google.protobuf.Int64Value) Int64ValueOrBuilder { private static final long serialVersionUID = 0L; // Use Int64Value.newBuilder() to construct. - private Int64Value(com.google.protobuf.GeneratedMessageV3.Builder builder) { + private Int64Value(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { super(builder); } private Int64Value() { @@ -38,7 +38,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.WrappersProto.internal_static_google_protobuf_Int64Value_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -160,20 +160,20 @@ public static com.google.protobuf.Int64Value parseFrom( } public static com.google.protobuf.Int64Value parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.Int64Value parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Int64Value parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -181,20 +181,20 @@ public static com.google.protobuf.Int64Value parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Int64Value parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.Int64Value parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -214,7 +214,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -228,7 +228,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.Int64Value} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements + com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.Int64Value) com.google.protobuf.Int64ValueOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -237,7 +237,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.WrappersProto.internal_static_google_protobuf_Int64Value_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -250,7 +250,7 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); } diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/Int64ValueOrBuilder.java b/protobuf-api/src/main/java/com/google/protobuf/Int64ValueOrBuilder.java similarity index 100% rename from protobuf-sdk/src/main/java/com/google/protobuf/Int64ValueOrBuilder.java rename to protobuf-api/src/main/java/com/google/protobuf/Int64ValueOrBuilder.java diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/JavaFeaturesProto.java b/protobuf-api/src/main/java/com/google/protobuf/JavaFeaturesProto.java similarity index 97% rename from protobuf-sdk/src/main/java/com/google/protobuf/JavaFeaturesProto.java rename to protobuf-api/src/main/java/com/google/protobuf/JavaFeaturesProto.java index 3b79d74..e6a0712 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/JavaFeaturesProto.java +++ b/protobuf-api/src/main/java/com/google/protobuf/JavaFeaturesProto.java @@ -89,12 +89,12 @@ public interface JavaFeaturesOrBuilder extends * Protobuf type {@code pb.JavaFeatures} */ public static final class JavaFeatures extends - com.google.protobuf.GeneratedMessageV3 implements + com.google.protobuf.FlattenedGeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:pb.JavaFeatures) JavaFeaturesOrBuilder { private static final long serialVersionUID = 0L; // Use JavaFeatures.newBuilder() to construct. - private JavaFeatures(com.google.protobuf.GeneratedMessageV3.Builder builder) { + private JavaFeatures(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { super(builder); } private JavaFeatures() { @@ -114,7 +114,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.JavaFeaturesProto.internal_static_pb_JavaFeatures_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -485,20 +485,20 @@ public static com.google.protobuf.JavaFeaturesProto.JavaFeatures parseFrom( } public static com.google.protobuf.JavaFeaturesProto.JavaFeatures parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.JavaFeaturesProto.JavaFeatures parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.JavaFeaturesProto.JavaFeatures parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -506,20 +506,20 @@ public static com.google.protobuf.JavaFeaturesProto.JavaFeatures parseDelimitedF java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.JavaFeaturesProto.JavaFeatures parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.JavaFeaturesProto.JavaFeatures parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -539,7 +539,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -547,7 +547,7 @@ protected Builder newBuilderForType( * Protobuf type {@code pb.JavaFeatures} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements + com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:pb.JavaFeatures) com.google.protobuf.JavaFeaturesProto.JavaFeaturesOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -556,7 +556,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.JavaFeaturesProto.internal_static_pb_JavaFeatures_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -569,7 +569,7 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); } @@ -1010,7 +1010,7 @@ public com.google.protobuf.JavaFeaturesProto.JavaFeatures getDefaultInstanceForT private static final com.google.protobuf.Descriptors.Descriptor internal_static_pb_JavaFeatures_descriptor; private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_pb_JavaFeatures_fieldAccessorTable; public static com.google.protobuf.Descriptors.FileDescriptor @@ -1053,7 +1053,7 @@ public com.google.protobuf.JavaFeaturesProto.JavaFeatures getDefaultInstanceForT internal_static_pb_JavaFeatures_descriptor = getDescriptor().getMessageTypes().get(0); internal_static_pb_JavaFeatures_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_pb_JavaFeatures_descriptor, new java.lang.String[] { "LegacyClosedEnum", "Utf8Validation", "UseOldOuterClassnameDefault", }); java.internalInit(descriptor.getExtensions().get(0)); diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/ListValue.java b/protobuf-api/src/main/java/com/google/protobuf/ListValue.java similarity index 96% rename from protobuf-sdk/src/main/java/com/google/protobuf/ListValue.java rename to protobuf-api/src/main/java/com/google/protobuf/ListValue.java index 8a2d1d8..e73789f 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/ListValue.java +++ b/protobuf-api/src/main/java/com/google/protobuf/ListValue.java @@ -14,12 +14,12 @@ * Protobuf type {@code google.protobuf.ListValue} */ public final class ListValue extends - com.google.protobuf.GeneratedMessageV3 implements + com.google.protobuf.FlattenedGeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:google.protobuf.ListValue) ListValueOrBuilder { private static final long serialVersionUID = 0L; // Use ListValue.newBuilder() to construct. - private ListValue(com.google.protobuf.GeneratedMessageV3.Builder builder) { + private ListValue(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { super(builder); } private ListValue() { @@ -39,7 +39,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.StructProto.internal_static_google_protobuf_ListValue_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -208,20 +208,20 @@ public static com.google.protobuf.ListValue parseFrom( } public static com.google.protobuf.ListValue parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.ListValue parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.ListValue parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -229,20 +229,20 @@ public static com.google.protobuf.ListValue parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.ListValue parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.ListValue parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -262,7 +262,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -276,7 +276,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.ListValue} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements + com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.ListValue) com.google.protobuf.ListValueOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -285,7 +285,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.StructProto.internal_static_google_protobuf_ListValue_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -298,7 +298,7 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); } @@ -424,7 +424,7 @@ public Builder mergeFrom(com.google.protobuf.ListValue other) { values_ = other.values_; bitField0_ = (bitField0_ & ~0x00000001); valuesBuilder_ = - com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? getValuesFieldBuilder() : null; } else { valuesBuilder_.addAllMessages(other.values_); diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/ListValueOrBuilder.java b/protobuf-api/src/main/java/com/google/protobuf/ListValueOrBuilder.java similarity index 100% rename from protobuf-sdk/src/main/java/com/google/protobuf/ListValueOrBuilder.java rename to protobuf-api/src/main/java/com/google/protobuf/ListValueOrBuilder.java diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/MapFieldBuilder.java b/protobuf-api/src/main/java/com/google/protobuf/MapFieldBuilder.java similarity index 100% rename from protobuf-sdk/src/main/java/com/google/protobuf/MapFieldBuilder.java rename to protobuf-api/src/main/java/com/google/protobuf/MapFieldBuilder.java diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/Method.java b/protobuf-api/src/main/java/com/google/protobuf/Method.java similarity index 95% rename from protobuf-sdk/src/main/java/com/google/protobuf/Method.java rename to protobuf-api/src/main/java/com/google/protobuf/Method.java index 541f0f1..9bddbbf 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/Method.java +++ b/protobuf-api/src/main/java/com/google/protobuf/Method.java @@ -12,12 +12,12 @@ * Protobuf type {@code google.protobuf.Method} */ public final class Method extends - com.google.protobuf.GeneratedMessageV3 implements + com.google.protobuf.FlattenedGeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:google.protobuf.Method) MethodOrBuilder { private static final long serialVersionUID = 0L; // Use Method.newBuilder() to construct. - private Method(com.google.protobuf.GeneratedMessageV3.Builder builder) { + private Method(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { super(builder); } private Method() { @@ -41,7 +41,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.ApiProto.internal_static_google_protobuf_Method_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -320,17 +320,17 @@ public final boolean isInitialized() { @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 1, name_); + if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(name_)) { + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 1, name_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(requestTypeUrl_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 2, requestTypeUrl_); + if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(requestTypeUrl_)) { + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 2, requestTypeUrl_); } if (requestStreaming_ != false) { output.writeBool(3, requestStreaming_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(responseTypeUrl_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 4, responseTypeUrl_); + if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(responseTypeUrl_)) { + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 4, responseTypeUrl_); } if (responseStreaming_ != false) { output.writeBool(5, responseStreaming_); @@ -350,18 +350,18 @@ public int getSerializedSize() { if (size != -1) return size; size = 0; - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, name_); + if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(name_)) { + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(1, name_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(requestTypeUrl_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, requestTypeUrl_); + if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(requestTypeUrl_)) { + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(2, requestTypeUrl_); } if (requestStreaming_ != false) { size += com.google.protobuf.CodedOutputStream .computeBoolSize(3, requestStreaming_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(responseTypeUrl_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(4, responseTypeUrl_); + if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(responseTypeUrl_)) { + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(4, responseTypeUrl_); } if (responseStreaming_ != false) { size += com.google.protobuf.CodedOutputStream @@ -471,20 +471,20 @@ public static com.google.protobuf.Method parseFrom( } public static com.google.protobuf.Method parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.Method parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Method parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -492,20 +492,20 @@ public static com.google.protobuf.Method parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Method parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.Method parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -525,7 +525,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -537,7 +537,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.Method} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements + com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.Method) com.google.protobuf.MethodOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -546,7 +546,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.ApiProto.internal_static_google_protobuf_Method_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -559,7 +559,7 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); } @@ -730,7 +730,7 @@ public Builder mergeFrom(com.google.protobuf.Method other) { options_ = other.options_; bitField0_ = (bitField0_ & ~0x00000020); optionsBuilder_ = - com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? getOptionsFieldBuilder() : null; } else { optionsBuilder_.addAllMessages(other.options_); diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/MethodOrBuilder.java b/protobuf-api/src/main/java/com/google/protobuf/MethodOrBuilder.java similarity index 100% rename from protobuf-sdk/src/main/java/com/google/protobuf/MethodOrBuilder.java rename to protobuf-api/src/main/java/com/google/protobuf/MethodOrBuilder.java diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/Mixin.java b/protobuf-api/src/main/java/com/google/protobuf/Mixin.java similarity index 94% rename from protobuf-sdk/src/main/java/com/google/protobuf/Mixin.java rename to protobuf-api/src/main/java/com/google/protobuf/Mixin.java index 56f92d0..3731fe4 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/Mixin.java +++ b/protobuf-api/src/main/java/com/google/protobuf/Mixin.java @@ -89,12 +89,12 @@ * Protobuf type {@code google.protobuf.Mixin} */ public final class Mixin extends - com.google.protobuf.GeneratedMessageV3 implements + com.google.protobuf.FlattenedGeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:google.protobuf.Mixin) MixinOrBuilder { private static final long serialVersionUID = 0L; // Use Mixin.newBuilder() to construct. - private Mixin(com.google.protobuf.GeneratedMessageV3.Builder builder) { + private Mixin(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { super(builder); } private Mixin() { @@ -115,7 +115,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.ApiProto.internal_static_google_protobuf_Mixin_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -232,11 +232,11 @@ public final boolean isInitialized() { @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 1, name_); + if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(name_)) { + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 1, name_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(root_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 2, root_); + if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(root_)) { + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 2, root_); } getUnknownFields().writeTo(output); } @@ -247,11 +247,11 @@ public int getSerializedSize() { if (size != -1) return size; size = 0; - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, name_); + if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(name_)) { + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(1, name_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(root_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, root_); + if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(root_)) { + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(2, root_); } size += getUnknownFields().getSerializedSize(); memoizedSize = size; @@ -326,20 +326,20 @@ public static com.google.protobuf.Mixin parseFrom( } public static com.google.protobuf.Mixin parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.Mixin parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Mixin parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -347,20 +347,20 @@ public static com.google.protobuf.Mixin parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Mixin parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.Mixin parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -380,7 +380,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -469,7 +469,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.Mixin} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements + com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.Mixin) com.google.protobuf.MixinOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -478,7 +478,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.ApiProto.internal_static_google_protobuf_Mixin_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -491,7 +491,7 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); } diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/MixinOrBuilder.java b/protobuf-api/src/main/java/com/google/protobuf/MixinOrBuilder.java similarity index 100% rename from protobuf-sdk/src/main/java/com/google/protobuf/MixinOrBuilder.java rename to protobuf-api/src/main/java/com/google/protobuf/MixinOrBuilder.java diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/NullValue.java b/protobuf-api/src/main/java/com/google/protobuf/NullValue.java similarity index 100% rename from protobuf-sdk/src/main/java/com/google/protobuf/NullValue.java rename to protobuf-api/src/main/java/com/google/protobuf/NullValue.java diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/Option.java b/protobuf-api/src/main/java/com/google/protobuf/Option.java similarity index 95% rename from protobuf-sdk/src/main/java/com/google/protobuf/Option.java rename to protobuf-api/src/main/java/com/google/protobuf/Option.java index 119fbaf..c4db5d4 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/Option.java +++ b/protobuf-api/src/main/java/com/google/protobuf/Option.java @@ -13,12 +13,12 @@ * Protobuf type {@code google.protobuf.Option} */ public final class Option extends - com.google.protobuf.GeneratedMessageV3 implements + com.google.protobuf.FlattenedGeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:google.protobuf.Option) OptionOrBuilder { private static final long serialVersionUID = 0L; // Use Option.newBuilder() to construct. - private Option(com.google.protobuf.GeneratedMessageV3.Builder builder) { + private Option(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { super(builder); } private Option() { @@ -38,7 +38,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.TypeProto.internal_static_google_protobuf_Option_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -160,8 +160,8 @@ public final boolean isInitialized() { @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 1, name_); + if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(name_)) { + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 1, name_); } if (((bitField0_ & 0x00000001) != 0)) { output.writeMessage(2, getValue()); @@ -175,8 +175,8 @@ public int getSerializedSize() { if (size != -1) return size; size = 0; - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, name_); + if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(name_)) { + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(1, name_); } if (((bitField0_ & 0x00000001) != 0)) { size += com.google.protobuf.CodedOutputStream @@ -260,20 +260,20 @@ public static com.google.protobuf.Option parseFrom( } public static com.google.protobuf.Option parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.Option parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Option parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -281,20 +281,20 @@ public static com.google.protobuf.Option parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Option parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.Option parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -314,7 +314,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -327,7 +327,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.Option} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements + com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.Option) com.google.protobuf.OptionOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -336,7 +336,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.TypeProto.internal_static_google_protobuf_Option_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -349,12 +349,12 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 + if (com.google.protobuf.FlattenedGeneratedMessageV3 .alwaysUseFieldBuilders) { getValueFieldBuilder(); } diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/OptionOrBuilder.java b/protobuf-api/src/main/java/com/google/protobuf/OptionOrBuilder.java similarity index 100% rename from protobuf-sdk/src/main/java/com/google/protobuf/OptionOrBuilder.java rename to protobuf-api/src/main/java/com/google/protobuf/OptionOrBuilder.java diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/SourceContext.java b/protobuf-api/src/main/java/com/google/protobuf/SourceContext.java similarity index 93% rename from protobuf-sdk/src/main/java/com/google/protobuf/SourceContext.java rename to protobuf-api/src/main/java/com/google/protobuf/SourceContext.java index 38c29b8..059b3ec 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/SourceContext.java +++ b/protobuf-api/src/main/java/com/google/protobuf/SourceContext.java @@ -13,12 +13,12 @@ * Protobuf type {@code google.protobuf.SourceContext} */ public final class SourceContext extends - com.google.protobuf.GeneratedMessageV3 implements + com.google.protobuf.FlattenedGeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:google.protobuf.SourceContext) SourceContextOrBuilder { private static final long serialVersionUID = 0L; // Use SourceContext.newBuilder() to construct. - private SourceContext(com.google.protobuf.GeneratedMessageV3.Builder builder) { + private SourceContext(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { super(builder); } private SourceContext() { @@ -38,7 +38,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.SourceContextProto.internal_static_google_protobuf_SourceContext_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -108,8 +108,8 @@ public final boolean isInitialized() { @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(fileName_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 1, fileName_); + if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(fileName_)) { + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 1, fileName_); } getUnknownFields().writeTo(output); } @@ -120,8 +120,8 @@ public int getSerializedSize() { if (size != -1) return size; size = 0; - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(fileName_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, fileName_); + if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(fileName_)) { + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(1, fileName_); } size += getUnknownFields().getSerializedSize(); memoizedSize = size; @@ -192,20 +192,20 @@ public static com.google.protobuf.SourceContext parseFrom( } public static com.google.protobuf.SourceContext parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.SourceContext parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.SourceContext parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -213,20 +213,20 @@ public static com.google.protobuf.SourceContext parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.SourceContext parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.SourceContext parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -246,7 +246,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -259,7 +259,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.SourceContext} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements + com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.SourceContext) com.google.protobuf.SourceContextOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -268,7 +268,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.SourceContextProto.internal_static_google_protobuf_SourceContext_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -281,7 +281,7 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); } diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/SourceContextOrBuilder.java b/protobuf-api/src/main/java/com/google/protobuf/SourceContextOrBuilder.java similarity index 100% rename from protobuf-sdk/src/main/java/com/google/protobuf/SourceContextOrBuilder.java rename to protobuf-api/src/main/java/com/google/protobuf/SourceContextOrBuilder.java diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/SourceContextProto.java b/protobuf-api/src/main/java/com/google/protobuf/SourceContextProto.java similarity index 93% rename from protobuf-sdk/src/main/java/com/google/protobuf/SourceContextProto.java rename to protobuf-api/src/main/java/com/google/protobuf/SourceContextProto.java index 0fdadc4..e8aa94d 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/SourceContextProto.java +++ b/protobuf-api/src/main/java/com/google/protobuf/SourceContextProto.java @@ -18,7 +18,7 @@ public static void registerAllExtensions( static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_SourceContext_descriptor; static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_SourceContext_fieldAccessorTable; public static com.google.protobuf.Descriptors.FileDescriptor @@ -43,7 +43,7 @@ public static void registerAllExtensions( internal_static_google_protobuf_SourceContext_descriptor = getDescriptor().getMessageTypes().get(0); internal_static_google_protobuf_SourceContext_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_SourceContext_descriptor, new java.lang.String[] { "FileName", }); } diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/StringValue.java b/protobuf-api/src/main/java/com/google/protobuf/StringValue.java similarity index 93% rename from protobuf-sdk/src/main/java/com/google/protobuf/StringValue.java rename to protobuf-api/src/main/java/com/google/protobuf/StringValue.java index c5ef53e..7943deb 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/StringValue.java +++ b/protobuf-api/src/main/java/com/google/protobuf/StringValue.java @@ -14,12 +14,12 @@ * Protobuf type {@code google.protobuf.StringValue} */ public final class StringValue extends - com.google.protobuf.GeneratedMessageV3 implements + com.google.protobuf.FlattenedGeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:google.protobuf.StringValue) StringValueOrBuilder { private static final long serialVersionUID = 0L; // Use StringValue.newBuilder() to construct. - private StringValue(com.google.protobuf.GeneratedMessageV3.Builder builder) { + private StringValue(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { super(builder); } private StringValue() { @@ -39,7 +39,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.WrappersProto.internal_static_google_protobuf_StringValue_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -107,8 +107,8 @@ public final boolean isInitialized() { @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(value_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 1, value_); + if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(value_)) { + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 1, value_); } getUnknownFields().writeTo(output); } @@ -119,8 +119,8 @@ public int getSerializedSize() { if (size != -1) return size; size = 0; - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(value_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, value_); + if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(value_)) { + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(1, value_); } size += getUnknownFields().getSerializedSize(); memoizedSize = size; @@ -191,20 +191,20 @@ public static com.google.protobuf.StringValue parseFrom( } public static com.google.protobuf.StringValue parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.StringValue parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.StringValue parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -212,20 +212,20 @@ public static com.google.protobuf.StringValue parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.StringValue parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.StringValue parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -245,7 +245,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -259,7 +259,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.StringValue} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements + com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.StringValue) com.google.protobuf.StringValueOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -268,7 +268,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.WrappersProto.internal_static_google_protobuf_StringValue_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -281,7 +281,7 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); } diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/StringValueOrBuilder.java b/protobuf-api/src/main/java/com/google/protobuf/StringValueOrBuilder.java similarity index 100% rename from protobuf-sdk/src/main/java/com/google/protobuf/StringValueOrBuilder.java rename to protobuf-api/src/main/java/com/google/protobuf/StringValueOrBuilder.java diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/Struct.java b/protobuf-api/src/main/java/com/google/protobuf/Struct.java similarity index 96% rename from protobuf-sdk/src/main/java/com/google/protobuf/Struct.java rename to protobuf-api/src/main/java/com/google/protobuf/Struct.java index 886142c..9ec8a2a 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/Struct.java +++ b/protobuf-api/src/main/java/com/google/protobuf/Struct.java @@ -19,12 +19,12 @@ * Protobuf type {@code google.protobuf.Struct} */ public final class Struct extends - com.google.protobuf.GeneratedMessageV3 implements + com.google.protobuf.FlattenedGeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:google.protobuf.Struct) StructOrBuilder { private static final long serialVersionUID = 0L; // Use Struct.newBuilder() to construct. - private Struct(com.google.protobuf.GeneratedMessageV3.Builder builder) { + private Struct(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { super(builder); } private Struct() { @@ -55,7 +55,7 @@ protected com.google.protobuf.MapFieldReflectionAccessor internalGetMapFieldRefl } } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.StructProto.internal_static_google_protobuf_Struct_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -171,7 +171,7 @@ public final boolean isInitialized() { @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - com.google.protobuf.GeneratedMessageV3 + com.google.protobuf.FlattenedGeneratedMessageV3 .serializeStringMapTo( output, internalGetFields(), @@ -267,20 +267,20 @@ public static com.google.protobuf.Struct parseFrom( } public static com.google.protobuf.Struct parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.Struct parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Struct parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -288,20 +288,20 @@ public static com.google.protobuf.Struct parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Struct parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.Struct parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -321,7 +321,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -340,7 +340,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.Struct} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements + com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.Struct) com.google.protobuf.StructOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -371,7 +371,7 @@ protected com.google.protobuf.MapFieldReflectionAccessor internalGetMutableMapFi } } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.StructProto.internal_static_google_protobuf_Struct_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -384,7 +384,7 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); } diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/StructOrBuilder.java b/protobuf-api/src/main/java/com/google/protobuf/StructOrBuilder.java similarity index 100% rename from protobuf-sdk/src/main/java/com/google/protobuf/StructOrBuilder.java rename to protobuf-api/src/main/java/com/google/protobuf/StructOrBuilder.java diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/StructProto.java b/protobuf-api/src/main/java/com/google/protobuf/StructProto.java similarity index 88% rename from protobuf-sdk/src/main/java/com/google/protobuf/StructProto.java rename to protobuf-api/src/main/java/com/google/protobuf/StructProto.java index 5f0050f..5bf2429 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/StructProto.java +++ b/protobuf-api/src/main/java/com/google/protobuf/StructProto.java @@ -18,22 +18,22 @@ public static void registerAllExtensions( static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_Struct_descriptor; static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_Struct_fieldAccessorTable; static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_Struct_FieldsEntry_descriptor; static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_Struct_FieldsEntry_fieldAccessorTable; static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_Value_descriptor; static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_Value_fieldAccessorTable; static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_ListValue_descriptor; static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_ListValue_fieldAccessorTable; public static com.google.protobuf.Descriptors.FileDescriptor @@ -68,25 +68,25 @@ public static void registerAllExtensions( internal_static_google_protobuf_Struct_descriptor = getDescriptor().getMessageTypes().get(0); internal_static_google_protobuf_Struct_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_Struct_descriptor, new java.lang.String[] { "Fields", }); internal_static_google_protobuf_Struct_FieldsEntry_descriptor = internal_static_google_protobuf_Struct_descriptor.getNestedTypes().get(0); internal_static_google_protobuf_Struct_FieldsEntry_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_Struct_FieldsEntry_descriptor, new java.lang.String[] { "Key", "Value", }); internal_static_google_protobuf_Value_descriptor = getDescriptor().getMessageTypes().get(1); internal_static_google_protobuf_Value_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_Value_descriptor, new java.lang.String[] { "NullValue", "NumberValue", "StringValue", "BoolValue", "StructValue", "ListValue", "Kind", }); internal_static_google_protobuf_ListValue_descriptor = getDescriptor().getMessageTypes().get(2); internal_static_google_protobuf_ListValue_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_ListValue_descriptor, new java.lang.String[] { "Values", }); } diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/Syntax.java b/protobuf-api/src/main/java/com/google/protobuf/Syntax.java similarity index 100% rename from protobuf-sdk/src/main/java/com/google/protobuf/Syntax.java rename to protobuf-api/src/main/java/com/google/protobuf/Syntax.java diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/Timestamp.java b/protobuf-api/src/main/java/com/google/protobuf/Timestamp.java similarity index 96% rename from protobuf-sdk/src/main/java/com/google/protobuf/Timestamp.java rename to protobuf-api/src/main/java/com/google/protobuf/Timestamp.java index a196076..b7eb723 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/Timestamp.java +++ b/protobuf-api/src/main/java/com/google/protobuf/Timestamp.java @@ -100,12 +100,12 @@ * Protobuf type {@code google.protobuf.Timestamp} */ public final class Timestamp extends - com.google.protobuf.GeneratedMessageV3 implements + com.google.protobuf.FlattenedGeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:google.protobuf.Timestamp) TimestampOrBuilder { private static final long serialVersionUID = 0L; // Use Timestamp.newBuilder() to construct. - private Timestamp(com.google.protobuf.GeneratedMessageV3.Builder builder) { + private Timestamp(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { super(builder); } private Timestamp() { @@ -124,7 +124,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.TimestampProto.internal_static_google_protobuf_Timestamp_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -277,20 +277,20 @@ public static com.google.protobuf.Timestamp parseFrom( } public static com.google.protobuf.Timestamp parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.Timestamp parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Timestamp parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -298,20 +298,20 @@ public static com.google.protobuf.Timestamp parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Timestamp parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.Timestamp parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -331,7 +331,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -431,7 +431,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.Timestamp} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements + com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.Timestamp) com.google.protobuf.TimestampOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -440,7 +440,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.TimestampProto.internal_static_google_protobuf_Timestamp_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -453,7 +453,7 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); } diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/TimestampOrBuilder.java b/protobuf-api/src/main/java/com/google/protobuf/TimestampOrBuilder.java similarity index 100% rename from protobuf-sdk/src/main/java/com/google/protobuf/TimestampOrBuilder.java rename to protobuf-api/src/main/java/com/google/protobuf/TimestampOrBuilder.java diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/TimestampProto.java b/protobuf-api/src/main/java/com/google/protobuf/TimestampProto.java similarity index 93% rename from protobuf-sdk/src/main/java/com/google/protobuf/TimestampProto.java rename to protobuf-api/src/main/java/com/google/protobuf/TimestampProto.java index 8cf5af4..9b784c2 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/TimestampProto.java +++ b/protobuf-api/src/main/java/com/google/protobuf/TimestampProto.java @@ -18,7 +18,7 @@ public static void registerAllExtensions( static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_Timestamp_descriptor; static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_Timestamp_fieldAccessorTable; public static com.google.protobuf.Descriptors.FileDescriptor @@ -43,7 +43,7 @@ public static void registerAllExtensions( internal_static_google_protobuf_Timestamp_descriptor = getDescriptor().getMessageTypes().get(0); internal_static_google_protobuf_Timestamp_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_Timestamp_descriptor, new java.lang.String[] { "Seconds", "Nanos", }); } diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/Type.java b/protobuf-api/src/main/java/com/google/protobuf/Type.java similarity index 97% rename from protobuf-sdk/src/main/java/com/google/protobuf/Type.java rename to protobuf-api/src/main/java/com/google/protobuf/Type.java index 88b3492..ebfb94c 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/Type.java +++ b/protobuf-api/src/main/java/com/google/protobuf/Type.java @@ -12,12 +12,12 @@ * Protobuf type {@code google.protobuf.Type} */ public final class Type extends - com.google.protobuf.GeneratedMessageV3 implements + com.google.protobuf.FlattenedGeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:google.protobuf.Type) TypeOrBuilder { private static final long serialVersionUID = 0L; // Use Type.newBuilder() to construct. - private Type(com.google.protobuf.GeneratedMessageV3.Builder builder) { + private Type(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { super(builder); } private Type() { @@ -43,7 +43,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.TypeProto.internal_static_google_protobuf_Type_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -398,14 +398,14 @@ public final boolean isInitialized() { @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 1, name_); + if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(name_)) { + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 1, name_); } for (int i = 0; i < fields_.size(); i++) { output.writeMessage(2, fields_.get(i)); } for (int i = 0; i < oneofs_.size(); i++) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 3, oneofs_.getRaw(i)); + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 3, oneofs_.getRaw(i)); } for (int i = 0; i < options_.size(); i++) { output.writeMessage(4, options_.get(i)); @@ -416,8 +416,8 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) if (syntax_ != com.google.protobuf.Syntax.SYNTAX_PROTO2.getNumber()) { output.writeEnum(6, syntax_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(edition_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 7, edition_); + if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(edition_)) { + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 7, edition_); } getUnknownFields().writeTo(output); } @@ -428,8 +428,8 @@ public int getSerializedSize() { if (size != -1) return size; size = 0; - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, name_); + if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(name_)) { + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(1, name_); } for (int i = 0; i < fields_.size(); i++) { size += com.google.protobuf.CodedOutputStream @@ -455,8 +455,8 @@ public int getSerializedSize() { size += com.google.protobuf.CodedOutputStream .computeEnumSize(6, syntax_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(edition_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(7, edition_); + if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(edition_)) { + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(7, edition_); } size += getUnknownFields().getSerializedSize(); memoizedSize = size; @@ -561,20 +561,20 @@ public static com.google.protobuf.Type parseFrom( } public static com.google.protobuf.Type parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.Type parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Type parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -582,20 +582,20 @@ public static com.google.protobuf.Type parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Type parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.Type parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -615,7 +615,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -627,7 +627,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.Type} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements + com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.Type) com.google.protobuf.TypeOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -636,7 +636,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.TypeProto.internal_static_google_protobuf_Type_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -649,12 +649,12 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 + if (com.google.protobuf.FlattenedGeneratedMessageV3 .alwaysUseFieldBuilders) { getFieldsFieldBuilder(); getOptionsFieldBuilder(); @@ -835,7 +835,7 @@ public Builder mergeFrom(com.google.protobuf.Type other) { fields_ = other.fields_; bitField0_ = (bitField0_ & ~0x00000002); fieldsBuilder_ = - com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? getFieldsFieldBuilder() : null; } else { fieldsBuilder_.addAllMessages(other.fields_); @@ -871,7 +871,7 @@ public Builder mergeFrom(com.google.protobuf.Type other) { options_ = other.options_; bitField0_ = (bitField0_ & ~0x00000008); optionsBuilder_ = - com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? getOptionsFieldBuilder() : null; } else { optionsBuilder_.addAllMessages(other.options_); diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/TypeOrBuilder.java b/protobuf-api/src/main/java/com/google/protobuf/TypeOrBuilder.java similarity index 100% rename from protobuf-sdk/src/main/java/com/google/protobuf/TypeOrBuilder.java rename to protobuf-api/src/main/java/com/google/protobuf/TypeOrBuilder.java diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/TypeProto.java b/protobuf-api/src/main/java/com/google/protobuf/TypeProto.java similarity index 90% rename from protobuf-sdk/src/main/java/com/google/protobuf/TypeProto.java rename to protobuf-api/src/main/java/com/google/protobuf/TypeProto.java index 1cc1248..b94a6aa 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/TypeProto.java +++ b/protobuf-api/src/main/java/com/google/protobuf/TypeProto.java @@ -18,27 +18,27 @@ public static void registerAllExtensions( static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_Type_descriptor; static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_Type_fieldAccessorTable; static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_Field_descriptor; static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_Field_fieldAccessorTable; static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_Enum_descriptor; static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_Enum_fieldAccessorTable; static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_EnumValue_descriptor; static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_EnumValue_fieldAccessorTable; static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_Option_descriptor; static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_Option_fieldAccessorTable; public static com.google.protobuf.Descriptors.FileDescriptor @@ -101,31 +101,31 @@ public static void registerAllExtensions( internal_static_google_protobuf_Type_descriptor = getDescriptor().getMessageTypes().get(0); internal_static_google_protobuf_Type_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_Type_descriptor, new java.lang.String[] { "Name", "Fields", "Oneofs", "Options", "SourceContext", "Syntax", "Edition", }); internal_static_google_protobuf_Field_descriptor = getDescriptor().getMessageTypes().get(1); internal_static_google_protobuf_Field_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_Field_descriptor, new java.lang.String[] { "Kind", "Cardinality", "Number", "Name", "TypeUrl", "OneofIndex", "Packed", "Options", "JsonName", "DefaultValue", }); internal_static_google_protobuf_Enum_descriptor = getDescriptor().getMessageTypes().get(2); internal_static_google_protobuf_Enum_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_Enum_descriptor, new java.lang.String[] { "Name", "Enumvalue", "Options", "SourceContext", "Syntax", "Edition", }); internal_static_google_protobuf_EnumValue_descriptor = getDescriptor().getMessageTypes().get(3); internal_static_google_protobuf_EnumValue_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_EnumValue_descriptor, new java.lang.String[] { "Name", "Number", "Options", }); internal_static_google_protobuf_Option_descriptor = getDescriptor().getMessageTypes().get(4); internal_static_google_protobuf_Option_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_Option_descriptor, new java.lang.String[] { "Name", "Value", }); com.google.protobuf.AnyProto.getDescriptor(); diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/UInt32Value.java b/protobuf-api/src/main/java/com/google/protobuf/UInt32Value.java similarity index 94% rename from protobuf-sdk/src/main/java/com/google/protobuf/UInt32Value.java rename to protobuf-api/src/main/java/com/google/protobuf/UInt32Value.java index b8e69f0..885b63d 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/UInt32Value.java +++ b/protobuf-api/src/main/java/com/google/protobuf/UInt32Value.java @@ -14,12 +14,12 @@ * Protobuf type {@code google.protobuf.UInt32Value} */ public final class UInt32Value extends - com.google.protobuf.GeneratedMessageV3 implements + com.google.protobuf.FlattenedGeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:google.protobuf.UInt32Value) UInt32ValueOrBuilder { private static final long serialVersionUID = 0L; // Use UInt32Value.newBuilder() to construct. - private UInt32Value(com.google.protobuf.GeneratedMessageV3.Builder builder) { + private UInt32Value(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { super(builder); } private UInt32Value() { @@ -38,7 +38,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.WrappersProto.internal_static_google_protobuf_UInt32Value_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -159,20 +159,20 @@ public static com.google.protobuf.UInt32Value parseFrom( } public static com.google.protobuf.UInt32Value parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.UInt32Value parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.UInt32Value parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -180,20 +180,20 @@ public static com.google.protobuf.UInt32Value parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.UInt32Value parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.UInt32Value parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -213,7 +213,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -227,7 +227,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.UInt32Value} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements + com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.UInt32Value) com.google.protobuf.UInt32ValueOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -236,7 +236,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.WrappersProto.internal_static_google_protobuf_UInt32Value_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -249,7 +249,7 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); } diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/UInt32ValueOrBuilder.java b/protobuf-api/src/main/java/com/google/protobuf/UInt32ValueOrBuilder.java similarity index 100% rename from protobuf-sdk/src/main/java/com/google/protobuf/UInt32ValueOrBuilder.java rename to protobuf-api/src/main/java/com/google/protobuf/UInt32ValueOrBuilder.java diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/UInt64Value.java b/protobuf-api/src/main/java/com/google/protobuf/UInt64Value.java similarity index 94% rename from protobuf-sdk/src/main/java/com/google/protobuf/UInt64Value.java rename to protobuf-api/src/main/java/com/google/protobuf/UInt64Value.java index eabc937..b0db2f5 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/UInt64Value.java +++ b/protobuf-api/src/main/java/com/google/protobuf/UInt64Value.java @@ -14,12 +14,12 @@ * Protobuf type {@code google.protobuf.UInt64Value} */ public final class UInt64Value extends - com.google.protobuf.GeneratedMessageV3 implements + com.google.protobuf.FlattenedGeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:google.protobuf.UInt64Value) UInt64ValueOrBuilder { private static final long serialVersionUID = 0L; // Use UInt64Value.newBuilder() to construct. - private UInt64Value(com.google.protobuf.GeneratedMessageV3.Builder builder) { + private UInt64Value(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { super(builder); } private UInt64Value() { @@ -38,7 +38,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.WrappersProto.internal_static_google_protobuf_UInt64Value_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -160,20 +160,20 @@ public static com.google.protobuf.UInt64Value parseFrom( } public static com.google.protobuf.UInt64Value parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.UInt64Value parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.UInt64Value parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -181,20 +181,20 @@ public static com.google.protobuf.UInt64Value parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.UInt64Value parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.UInt64Value parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -214,7 +214,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -228,7 +228,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.UInt64Value} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements + com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.UInt64Value) com.google.protobuf.UInt64ValueOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -237,7 +237,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.WrappersProto.internal_static_google_protobuf_UInt64Value_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -250,7 +250,7 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); } diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/UInt64ValueOrBuilder.java b/protobuf-api/src/main/java/com/google/protobuf/UInt64ValueOrBuilder.java similarity index 100% rename from protobuf-sdk/src/main/java/com/google/protobuf/UInt64ValueOrBuilder.java rename to protobuf-api/src/main/java/com/google/protobuf/UInt64ValueOrBuilder.java diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/Value.java b/protobuf-api/src/main/java/com/google/protobuf/Value.java similarity index 97% rename from protobuf-sdk/src/main/java/com/google/protobuf/Value.java rename to protobuf-api/src/main/java/com/google/protobuf/Value.java index 97dab1a..649a80b 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/Value.java +++ b/protobuf-api/src/main/java/com/google/protobuf/Value.java @@ -17,12 +17,12 @@ * Protobuf type {@code google.protobuf.Value} */ public final class Value extends - com.google.protobuf.GeneratedMessageV3 implements + com.google.protobuf.FlattenedGeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:google.protobuf.Value) ValueOrBuilder { private static final long serialVersionUID = 0L; // Use Value.newBuilder() to construct. - private Value(com.google.protobuf.GeneratedMessageV3.Builder builder) { + private Value(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { super(builder); } private Value() { @@ -41,7 +41,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.StructProto.internal_static_google_protobuf_Value_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -371,7 +371,7 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) 2, (double)((java.lang.Double) kind_)); } if (kindCase_ == 3) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 3, kind_); + com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 3, kind_); } if (kindCase_ == 4) { output.writeBool( @@ -402,7 +402,7 @@ public int getSerializedSize() { 2, (double)((java.lang.Double) kind_)); } if (kindCase_ == 3) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(3, kind_); + size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(3, kind_); } if (kindCase_ == 4) { size += com.google.protobuf.CodedOutputStream @@ -542,20 +542,20 @@ public static com.google.protobuf.Value parseFrom( } public static com.google.protobuf.Value parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.Value parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Value parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } @@ -563,20 +563,20 @@ public static com.google.protobuf.Value parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Value parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.google.protobuf.Value parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.FlattenedGeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } @@ -596,7 +596,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -613,7 +613,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.Value} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements + com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.Value) com.google.protobuf.ValueOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -622,7 +622,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.StructProto.internal_static_google_protobuf_Value_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -635,7 +635,7 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { super(parent); } diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/ValueOrBuilder.java b/protobuf-api/src/main/java/com/google/protobuf/ValueOrBuilder.java similarity index 100% rename from protobuf-sdk/src/main/java/com/google/protobuf/ValueOrBuilder.java rename to protobuf-api/src/main/java/com/google/protobuf/ValueOrBuilder.java diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/WrappersProto.java b/protobuf-api/src/main/java/com/google/protobuf/WrappersProto.java similarity index 82% rename from protobuf-sdk/src/main/java/com/google/protobuf/WrappersProto.java rename to protobuf-api/src/main/java/com/google/protobuf/WrappersProto.java index a83a961..1d2e0cb 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/WrappersProto.java +++ b/protobuf-api/src/main/java/com/google/protobuf/WrappersProto.java @@ -18,47 +18,47 @@ public static void registerAllExtensions( static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_DoubleValue_descriptor; static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_DoubleValue_fieldAccessorTable; static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_FloatValue_descriptor; static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_FloatValue_fieldAccessorTable; static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_Int64Value_descriptor; static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_Int64Value_fieldAccessorTable; static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_UInt64Value_descriptor; static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_UInt64Value_fieldAccessorTable; static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_Int32Value_descriptor; static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_Int32Value_fieldAccessorTable; static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_UInt32Value_descriptor; static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_UInt32Value_fieldAccessorTable; static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_BoolValue_descriptor; static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_BoolValue_fieldAccessorTable; static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_StringValue_descriptor; static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_StringValue_fieldAccessorTable; static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_BytesValue_descriptor; static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable internal_static_google_protobuf_BytesValue_fieldAccessorTable; public static com.google.protobuf.Descriptors.FileDescriptor @@ -89,55 +89,55 @@ public static void registerAllExtensions( internal_static_google_protobuf_DoubleValue_descriptor = getDescriptor().getMessageTypes().get(0); internal_static_google_protobuf_DoubleValue_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_DoubleValue_descriptor, new java.lang.String[] { "Value", }); internal_static_google_protobuf_FloatValue_descriptor = getDescriptor().getMessageTypes().get(1); internal_static_google_protobuf_FloatValue_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_FloatValue_descriptor, new java.lang.String[] { "Value", }); internal_static_google_protobuf_Int64Value_descriptor = getDescriptor().getMessageTypes().get(2); internal_static_google_protobuf_Int64Value_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_Int64Value_descriptor, new java.lang.String[] { "Value", }); internal_static_google_protobuf_UInt64Value_descriptor = getDescriptor().getMessageTypes().get(3); internal_static_google_protobuf_UInt64Value_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_UInt64Value_descriptor, new java.lang.String[] { "Value", }); internal_static_google_protobuf_Int32Value_descriptor = getDescriptor().getMessageTypes().get(4); internal_static_google_protobuf_Int32Value_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_Int32Value_descriptor, new java.lang.String[] { "Value", }); internal_static_google_protobuf_UInt32Value_descriptor = getDescriptor().getMessageTypes().get(5); internal_static_google_protobuf_UInt32Value_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_UInt32Value_descriptor, new java.lang.String[] { "Value", }); internal_static_google_protobuf_BoolValue_descriptor = getDescriptor().getMessageTypes().get(6); internal_static_google_protobuf_BoolValue_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_BoolValue_descriptor, new java.lang.String[] { "Value", }); internal_static_google_protobuf_StringValue_descriptor = getDescriptor().getMessageTypes().get(7); internal_static_google_protobuf_StringValue_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_StringValue_descriptor, new java.lang.String[] { "Value", }); internal_static_google_protobuf_BytesValue_descriptor = getDescriptor().getMessageTypes().get(8); internal_static_google_protobuf_BytesValue_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( internal_static_google_protobuf_BytesValue_descriptor, new java.lang.String[] { "Value", }); } From ed32977e4efe70cdd949c7eeb8d7dcb1d2e6696b Mon Sep 17 00:00:00 2001 From: blakeli Date: Mon, 31 Mar 2025 13:21:16 -0600 Subject: [PATCH 09/42] Move JavaFeaturesProto back to SDK package. --- .../google/protobuf/JavaFeaturesProto.java | 36 ++++++++----------- 1 file changed, 15 insertions(+), 21 deletions(-) rename {protobuf-api => protobuf-sdk}/src/main/java/com/google/protobuf/JavaFeaturesProto.java (96%) diff --git a/protobuf-api/src/main/java/com/google/protobuf/JavaFeaturesProto.java b/protobuf-sdk/src/main/java/com/google/protobuf/JavaFeaturesProto.java similarity index 96% rename from protobuf-api/src/main/java/com/google/protobuf/JavaFeaturesProto.java rename to protobuf-sdk/src/main/java/com/google/protobuf/JavaFeaturesProto.java index e6a0712..e5b8ac2 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/JavaFeaturesProto.java +++ b/protobuf-sdk/src/main/java/com/google/protobuf/JavaFeaturesProto.java @@ -89,12 +89,12 @@ public interface JavaFeaturesOrBuilder extends * Protobuf type {@code pb.JavaFeatures} */ public static final class JavaFeatures extends - com.google.protobuf.FlattenedGeneratedMessageV3 implements + com.google.protobuf.GeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:pb.JavaFeatures) JavaFeaturesOrBuilder { private static final long serialVersionUID = 0L; // Use JavaFeatures.newBuilder() to construct. - private JavaFeatures(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { + private JavaFeatures(com.google.protobuf.GeneratedMessageV3.Builder builder) { super(builder); } private JavaFeatures() { @@ -114,7 +114,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.JavaFeaturesProto.internal_static_pb_JavaFeatures_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -485,42 +485,36 @@ public static com.google.protobuf.JavaFeaturesProto.JavaFeatures parseFrom( } public static com.google.protobuf.JavaFeaturesProto.JavaFeatures parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 - .parseWithIOException(PARSER, input); + return parseWithIOException(PARSER, input); } public static com.google.protobuf.JavaFeaturesProto.JavaFeatures parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); + return parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.JavaFeaturesProto.JavaFeatures parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input); + return parseDelimitedWithIOException(PARSER, input); } public static com.google.protobuf.JavaFeaturesProto.JavaFeatures parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); + return parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.JavaFeaturesProto.JavaFeatures parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 - .parseWithIOException(PARSER, input); + return parseWithIOException(PARSER, input); } public static com.google.protobuf.JavaFeaturesProto.JavaFeatures parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); + return parseWithIOException(PARSER, input, extensionRegistry); } @java.lang.Override @@ -539,7 +533,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -547,7 +541,7 @@ protected Builder newBuilderForType( * Protobuf type {@code pb.JavaFeatures} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements + com.google.protobuf.GeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:pb.JavaFeatures) com.google.protobuf.JavaFeaturesProto.JavaFeaturesOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -556,7 +550,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.JavaFeaturesProto.internal_static_pb_JavaFeatures_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -569,7 +563,7 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { super(parent); } @@ -1010,7 +1004,7 @@ public com.google.protobuf.JavaFeaturesProto.JavaFeatures getDefaultInstanceForT private static final com.google.protobuf.Descriptors.Descriptor internal_static_pb_JavaFeatures_descriptor; private static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable internal_static_pb_JavaFeatures_fieldAccessorTable; public static com.google.protobuf.Descriptors.FileDescriptor @@ -1053,7 +1047,7 @@ public com.google.protobuf.JavaFeaturesProto.JavaFeatures getDefaultInstanceForT internal_static_pb_JavaFeatures_descriptor = getDescriptor().getMessageTypes().get(0); internal_static_pb_JavaFeatures_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_pb_JavaFeatures_descriptor, new java.lang.String[] { "LegacyClosedEnum", "Utf8Validation", "UseOldOuterClassnameDefault", }); java.internalInit(descriptor.getExtensions().get(0)); From 7d9f8af42e2872245829c2b26c93d71625c38599 Mon Sep 17 00:00:00 2001 From: blakeli Date: Thu, 3 Apr 2025 22:59:54 -0600 Subject: [PATCH 10/42] Decouple ExtensionRegistryLite from GeneratedMessageLite.GeneratedExtension. --- .../com/google/protobuf/ArrayDecoders.java | 2 +- .../protobuf/ExtensionRegistryLite.java | 27 ++++++++++--------- .../google/protobuf/GeneratedMessageLite.java | 4 +-- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/protobuf-api/src/main/java/com/google/protobuf/ArrayDecoders.java b/protobuf-api/src/main/java/com/google/protobuf/ArrayDecoders.java index bf5f922..331806b 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/ArrayDecoders.java +++ b/protobuf-api/src/main/java/com/google/protobuf/ArrayDecoders.java @@ -765,7 +765,7 @@ static int decodeExtensionOrUnknownField( throws IOException { final int number = tag >>> 3; GeneratedMessageLite.GeneratedExtension extension = - registers.extensionRegistry.findLiteExtensionByNumber(defaultInstance, number); + (GeneratedMessageLite.GeneratedExtension) registers.extensionRegistry.findLiteExtensionByNumber(defaultInstance, number); if (extension == null) { return decodeUnknownField( tag, data, position, limit, getMutableUnknownFields(message), registers); diff --git a/protobuf-api/src/main/java/com/google/protobuf/ExtensionRegistryLite.java b/protobuf-api/src/main/java/com/google/protobuf/ExtensionRegistryLite.java index 18d14bf..769bffd 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/ExtensionRegistryLite.java +++ b/protobuf-api/src/main/java/com/google/protobuf/ExtensionRegistryLite.java @@ -127,27 +127,30 @@ public ExtensionRegistryLite getUnmodifiable() { */ @SuppressWarnings("unchecked") public - GeneratedMessageLite.GeneratedExtension findLiteExtensionByNumber( + ExtensionLite findLiteExtensionByNumber( final ContainingType containingTypeDefaultInstance, final int fieldNumber) { - return (GeneratedMessageLite.GeneratedExtension) + return (ExtensionLite) extensionsByNumber.get(new ObjectIntPair(containingTypeDefaultInstance, fieldNumber)); } /** Add an extension from a lite generated file to the registry. */ - public final void add(final GeneratedMessageLite.GeneratedExtension extension) { - extensionsByNumber.put( - new ObjectIntPair(extension.getContainingTypeDefaultInstance(), extension.getNumber()), - extension); - } +// public final void add(final ExtensionLite extension) { +// extensionsByNumber.put( +// new ObjectIntPair(extension, extension.getNumber()), +// extension); +// } /** * Add an extension from a lite generated file to the registry only if it is a non-lite extension * i.e. {@link GeneratedMessageLite.GeneratedExtension}. */ public final void add(ExtensionLite extension) { - if (GeneratedMessageLite.GeneratedExtension.class.isAssignableFrom(extension.getClass())) { - add((GeneratedMessageLite.GeneratedExtension) extension); - } + extensionsByNumber.put( + new ObjectIntPair(extension, extension.getNumber()), + extension); +// if (GeneratedMessageLite.GeneratedExtension.class.isAssignableFrom(extension.getClass())) { +// add((GeneratedMessageLite.GeneratedExtension) extension); +// } if (doFullRuntimeInheritanceCheck && ExtensionRegistryFactory.isFullRegistry(this)) { try { this.getClass().getMethod("add", ExtensionClassHolder.INSTANCE).invoke(this, extension); @@ -166,7 +169,7 @@ public final void add(ExtensionLite extension) { ExtensionRegistryLite() { this.extensionsByNumber = - new HashMap>(); + new HashMap>(); } static final ExtensionRegistryLite EMPTY_REGISTRY_LITE = new ExtensionRegistryLite(true); @@ -179,7 +182,7 @@ public final void add(ExtensionLite extension) { } } - private final Map> + private final Map> extensionsByNumber; ExtensionRegistryLite(boolean empty) { diff --git a/protobuf-api/src/main/java/com/google/protobuf/GeneratedMessageLite.java b/protobuf-api/src/main/java/com/google/protobuf/GeneratedMessageLite.java index c153960..8dfc01a 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/GeneratedMessageLite.java +++ b/protobuf-api/src/main/java/com/google/protobuf/GeneratedMessageLite.java @@ -623,7 +623,7 @@ protected boolean parseUnknownField( // TODO: How much bytecode would be saved by not requiring the generated code to // provide the default instance? GeneratedExtension extension = - extensionRegistry.findLiteExtensionByNumber(defaultInstance, fieldNumber); + (GeneratedExtension) extensionRegistry.findLiteExtensionByNumber(defaultInstance, fieldNumber); return parseExtension(input, extensionRegistry, extension, tag, fieldNumber); } @@ -808,7 +808,7 @@ private void mergeMessageSetExtensionFromCoded if (tag == WireFormat.MESSAGE_SET_TYPE_ID_TAG) { typeId = input.readUInt32(); if (typeId != 0) { - extension = extensionRegistry.findLiteExtensionByNumber(defaultInstance, typeId); + extension = (GeneratedExtension) extensionRegistry.findLiteExtensionByNumber(defaultInstance, typeId); } } else if (tag == WireFormat.MESSAGE_SET_MESSAGE_TAG) { From 3a6427d5f16a74d08f4c228f4b929e3b17a6c495 Mon Sep 17 00:00:00 2001 From: blakeli Date: Thu, 3 Apr 2025 23:01:01 -0600 Subject: [PATCH 11/42] Decouple CodedOutputStream from AbstractMessageLite. --- .../com/google/protobuf/CodedOutputStream.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/protobuf-api/src/main/java/com/google/protobuf/CodedOutputStream.java b/protobuf-api/src/main/java/com/google/protobuf/CodedOutputStream.java index 3ef2b4c..66d928e 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/CodedOutputStream.java +++ b/protobuf-api/src/main/java/com/google/protobuf/CodedOutputStream.java @@ -934,7 +934,7 @@ public static int computeMessageSizeNoTag(final MessageLite value) { /** Compute the number of bytes that would be needed to encode an embedded message field. */ static int computeMessageSizeNoTag(final MessageLite value, final Schema schema) { - return computeLengthDelimitedFieldSize(((AbstractMessageLite) value).getSerializedSize(schema)); + return computeLengthDelimitedFieldSize(getSerializedSize(value, schema)); } static int computeLengthDelimitedFieldSize(int fieldLength) { @@ -1130,10 +1130,24 @@ public static int computeGroupSizeNoTag(final MessageLite value) { return value.getSerializedSize(); } + private static final Class ABSTRACT_MESSAGE_LITE = getClassForName("com.google.protobuf.AbstractMessageLite"); + /** Compute the number of bytes that would be needed to encode a {@code group} field. */ @Deprecated static int computeGroupSizeNoTag(final MessageLite value, Schema schema) { - return ((AbstractMessageLite) value).getSerializedSize(schema); + return getSerializedSize(value, schema); + } + + private static int getSerializedSize(MessageLite value, Schema schema) { + try { + return (int) ABSTRACT_MESSAGE_LITE.getMethod("getSerializedSize", Schema.class).invoke(value, schema); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } catch (InvocationTargetException e) { + throw new RuntimeException(e); + } catch (NoSuchMethodException e) { + throw new RuntimeException(e); + } } /** From c5bc454b21b6c0097f713f121ab5c104cbccf970 Mon Sep 17 00:00:00 2001 From: blakeli Date: Thu, 3 Apr 2025 23:18:55 -0600 Subject: [PATCH 12/42] Get GeneratedMessageLite$GeneratedExtension using reflection. --- .../protobuf/ExtensionRegistryLite.java | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/protobuf-api/src/main/java/com/google/protobuf/ExtensionRegistryLite.java b/protobuf-api/src/main/java/com/google/protobuf/ExtensionRegistryLite.java index 769bffd..03a2761 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/ExtensionRegistryLite.java +++ b/protobuf-api/src/main/java/com/google/protobuf/ExtensionRegistryLite.java @@ -7,6 +7,7 @@ package com.google.protobuf; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -72,6 +73,19 @@ static Class resolveExtensionClass() { } } } + private static final Class GENERATED_EXTENSION = getGeneratedExtensionClass(); + + private static Class getGeneratedExtensionClass() { + try { + Class generatedMessageLiteClass = Class.forName("com.google.protobuf.GeneratedMessageLite"); + return Arrays.stream(generatedMessageLiteClass.getClasses()) + .filter(innerClass -> innerClass.getName().equals("com.google.protobuf.GeneratedMessageLite$GeneratedExtension")) + .findFirst() + .get(); + } catch (Throwable e) { + return null; + } + } public static boolean isEagerlyParseMessageSets() { return eagerlyParseMessageSets; @@ -145,12 +159,11 @@ public ExtensionRegistryLite getUnmodifiable() { * i.e. {@link GeneratedMessageLite.GeneratedExtension}. */ public final void add(ExtensionLite extension) { - extensionsByNumber.put( - new ObjectIntPair(extension, extension.getNumber()), - extension); -// if (GeneratedMessageLite.GeneratedExtension.class.isAssignableFrom(extension.getClass())) { -// add((GeneratedMessageLite.GeneratedExtension) extension); -// } + if (GENERATED_EXTENSION.isAssignableFrom(extension.getClass())) { + extensionsByNumber.put( + new ObjectIntPair(extension, extension.getNumber()), + extension); + } if (doFullRuntimeInheritanceCheck && ExtensionRegistryFactory.isFullRegistry(this)) { try { this.getClass().getMethod("add", ExtensionClassHolder.INSTANCE).invoke(this, extension); From 613f7cf675e3e8ccbf9c85e58dc64c2f5d6fc0b3 Mon Sep 17 00:00:00 2001 From: blakeli Date: Mon, 7 Apr 2025 17:41:13 -0400 Subject: [PATCH 13/42] Move GeneratedMessageLite.SerializedForm and AbstractMessageLite.Builder.LimitedInputStream to their own package private classes. --- .../google/protobuf/AbstractMessageLite.java | 56 ------------ .../com/google/protobuf/AbstractParser.java | 1 - .../protobuf/FlattenedAbstractMessage.java | 2 +- .../protobuf/FlattenedGeneratedMessageV3.java | 4 +- .../com/google/protobuf/GeneratedMessage.java | 2 +- .../google/protobuf/GeneratedMessageLite.java | 88 ------------------ .../google/protobuf/LimitedInputStream.java | 61 +++++++++++++ .../java/com/google/protobuf/MapEntry.java | 58 +----------- .../com/google/protobuf/SerializedForm.java | 91 +++++++++++++++++++ .../com/google/protobuf/UnknownFieldSet.java | 1 - .../google/protobuf/GeneratedMessageV3.java | 2 +- 11 files changed, 158 insertions(+), 208 deletions(-) create mode 100644 protobuf-api/src/main/java/com/google/protobuf/LimitedInputStream.java create mode 100644 protobuf-api/src/main/java/com/google/protobuf/SerializedForm.java diff --git a/protobuf-api/src/main/java/com/google/protobuf/AbstractMessageLite.java b/protobuf-api/src/main/java/com/google/protobuf/AbstractMessageLite.java index 6a9d7ba..4e3f68f 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/AbstractMessageLite.java +++ b/protobuf-api/src/main/java/com/google/protobuf/AbstractMessageLite.java @@ -248,62 +248,6 @@ public BuilderType mergeFrom( return (BuilderType) this; } - /** - * An InputStream implementations which reads from some other InputStream but is limited to a - * particular number of bytes. Used by mergeDelimitedFrom(). This is intentionally - * package-private so that UnknownFieldSet can share it. - */ - static final class LimitedInputStream extends FilterInputStream { - private int limit; - - LimitedInputStream(InputStream in, int limit) { - super(in); - this.limit = limit; - } - - @Override - public int available() throws IOException { - return Math.min(super.available(), limit); - } - - @Override - public int read() throws IOException { - if (limit <= 0) { - return -1; - } - final int result = super.read(); - if (result >= 0) { - --limit; - } - return result; - } - - @Override - public int read(final byte[] b, final int off, int len) throws IOException { - if (limit <= 0) { - return -1; - } - len = Math.min(len, limit); - final int result = super.read(b, off, len); - if (result >= 0) { - limit -= result; - } - return result; - } - - @Override - public long skip(final long n) throws IOException { - // because we take the minimum of an int and a long, result is guaranteed to be - // less than or equal to Integer.MAX_INT so this cast is safe - int result = (int) super.skip(Math.min(n, limit)); - if (result >= 0) { - // if the superclass adheres to the contract for skip, this condition is always true - limit -= result; - } - return result; - } - } - @Override public boolean mergeDelimitedFrom( final InputStream input, final ExtensionRegistryLite extensionRegistry) throws IOException { diff --git a/protobuf-api/src/main/java/com/google/protobuf/AbstractParser.java b/protobuf-api/src/main/java/com/google/protobuf/AbstractParser.java index a1cfc61..8cbe6fa 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/AbstractParser.java +++ b/protobuf-api/src/main/java/com/google/protobuf/AbstractParser.java @@ -7,7 +7,6 @@ package com.google.protobuf; -import com.google.protobuf.AbstractMessageLite.Builder.LimitedInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; diff --git a/protobuf-api/src/main/java/com/google/protobuf/FlattenedAbstractMessage.java b/protobuf-api/src/main/java/com/google/protobuf/FlattenedAbstractMessage.java index 68d8da9..0fcf537 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/FlattenedAbstractMessage.java +++ b/protobuf-api/src/main/java/com/google/protobuf/FlattenedAbstractMessage.java @@ -441,7 +441,7 @@ public boolean mergeDelimitedFrom( return false; } final int size = CodedInputStream.readRawVarint32(firstByte, input); - final InputStream limitedInput = new AbstractMessageLite.Builder.LimitedInputStream(input, size); + final InputStream limitedInput = new LimitedInputStream(input, size); mergeFrom(limitedInput, extensionRegistry); return true; } diff --git a/protobuf-api/src/main/java/com/google/protobuf/FlattenedGeneratedMessageV3.java b/protobuf-api/src/main/java/com/google/protobuf/FlattenedGeneratedMessageV3.java index 6b1933a..96243f8 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/FlattenedGeneratedMessageV3.java +++ b/protobuf-api/src/main/java/com/google/protobuf/FlattenedGeneratedMessageV3.java @@ -901,7 +901,7 @@ public boolean mergeDelimitedFrom( return false; } final int size = CodedInputStream.readRawVarint32(firstByte, input); - final InputStream limitedInput = new AbstractMessageLite.Builder.LimitedInputStream(input, size); + final InputStream limitedInput = new LimitedInputStream(input, size); mergeFrom(limitedInput, extensionRegistry); return true; } @@ -4128,7 +4128,7 @@ public Message.Builder getRepeatedBuilder( * @return a SerializedForm of this message */ protected Object writeReplace() throws ObjectStreamException { - return new GeneratedMessageLite.SerializedForm(this); + return new SerializedForm(this); } /** diff --git a/protobuf-api/src/main/java/com/google/protobuf/GeneratedMessage.java b/protobuf-api/src/main/java/com/google/protobuf/GeneratedMessage.java index d3ff341..8120ed5 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/GeneratedMessage.java +++ b/protobuf-api/src/main/java/com/google/protobuf/GeneratedMessage.java @@ -2925,7 +2925,7 @@ public Message.Builder getRepeatedBuilder( * @return a SerializedForm of this message */ protected Object writeReplace() throws ObjectStreamException { - return new GeneratedMessageLite.SerializedForm(this); + return new SerializedForm(this); } /** diff --git a/protobuf-api/src/main/java/com/google/protobuf/GeneratedMessageLite.java b/protobuf-api/src/main/java/com/google/protobuf/GeneratedMessageLite.java index c153960..021a7cc 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/GeneratedMessageLite.java +++ b/protobuf-api/src/main/java/com/google/protobuf/GeneratedMessageLite.java @@ -7,7 +7,6 @@ package com.google.protobuf; -import com.google.protobuf.AbstractMessageLite.Builder.LimitedInputStream; import com.google.protobuf.Internal.BooleanList; import com.google.protobuf.Internal.DoubleList; import com.google.protobuf.Internal.FloatList; @@ -1395,93 +1394,6 @@ public Type getDefaultValue() { } } - /** - * A serialized (serializable) form of the generated message. Stores the message as a class name - * and a byte array. - */ - protected static final class SerializedForm implements Serializable { - - public static SerializedForm of(MessageLite message) { - return new SerializedForm(message); - } - - private static final long serialVersionUID = 0L; - - // since v3.6.1 - private final Class messageClass; - private final String messageClassName; - private final byte[] asBytes; - - /** - * Creates the serialized form by calling {@link com.google.protobuf.MessageLite#toByteArray}. - * - * @param regularForm the message to serialize - */ - SerializedForm(MessageLite regularForm) { - messageClass = regularForm.getClass(); - messageClassName = regularForm.getClass().getName(); - asBytes = regularForm.toByteArray(); - } - - /** - * When read from an ObjectInputStream, this method converts this object back to the regular - * form. Part of Java's serialization magic. - * - * @return a GeneratedMessage of the type that was serialized - */ - protected Object readResolve() throws ObjectStreamException { - try { - Class messageClass = resolveMessageClass(); - java.lang.reflect.Field defaultInstanceField = - messageClass.getDeclaredField("DEFAULT_INSTANCE"); - defaultInstanceField.setAccessible(true); - MessageLite defaultInstance = (MessageLite) defaultInstanceField.get(null); - return defaultInstance.newBuilderForType().mergeFrom(asBytes).buildPartial(); - } catch (ClassNotFoundException e) { - throw new RuntimeException("Unable to find proto buffer class: " + messageClassName, e); - } catch (NoSuchFieldException e) { - return readResolveFallback(); - } catch (SecurityException e) { - throw new RuntimeException("Unable to call DEFAULT_INSTANCE in " + messageClassName, e); - } catch (IllegalAccessException e) { - throw new RuntimeException("Unable to call parsePartialFrom", e); - } catch (InvalidProtocolBufferException e) { - throw new RuntimeException("Unable to understand proto buffer", e); - } - } - - /** - * @deprecated from v3.0.0-beta-3+, for compatibility with v2.5.0 and v2.6.1 generated code. - */ - @Deprecated - private Object readResolveFallback() throws ObjectStreamException { - try { - Class messageClass = resolveMessageClass(); - java.lang.reflect.Field defaultInstanceField = - messageClass.getDeclaredField("defaultInstance"); - defaultInstanceField.setAccessible(true); - MessageLite defaultInstance = (MessageLite) defaultInstanceField.get(null); - return defaultInstance.newBuilderForType() - .mergeFrom(asBytes) - .buildPartial(); - } catch (ClassNotFoundException e) { - throw new RuntimeException("Unable to find proto buffer class: " + messageClassName, e); - } catch (NoSuchFieldException e) { - throw new RuntimeException("Unable to find defaultInstance in " + messageClassName, e); - } catch (SecurityException e) { - throw new RuntimeException("Unable to call defaultInstance in " + messageClassName, e); - } catch (IllegalAccessException e) { - throw new RuntimeException("Unable to call parsePartialFrom", e); - } catch (InvalidProtocolBufferException e) { - throw new RuntimeException("Unable to understand proto buffer", e); - } - } - - private Class resolveMessageClass() throws ClassNotFoundException { - return messageClass != null ? messageClass : Class.forName(messageClassName); - } - } - /** Checks that the {@link Extension} is Lite and returns it as a {@link GeneratedExtension}. */ private static < MessageType extends ExtendableMessage, diff --git a/protobuf-api/src/main/java/com/google/protobuf/LimitedInputStream.java b/protobuf-api/src/main/java/com/google/protobuf/LimitedInputStream.java new file mode 100644 index 0000000..f6eaad7 --- /dev/null +++ b/protobuf-api/src/main/java/com/google/protobuf/LimitedInputStream.java @@ -0,0 +1,61 @@ +package com.google.protobuf; + +import java.io.FilterInputStream; +import java.io.IOException; +import java.io.InputStream; + +/** + * An InputStream implementations which reads from some other InputStream but is limited to a + * particular number of bytes. Used by mergeDelimitedFrom(). This is intentionally + * package-private so that UnknownFieldSet can share it. + */ +final class LimitedInputStream extends FilterInputStream { + private int limit; + + LimitedInputStream(InputStream in, int limit) { + super(in); + this.limit = limit; + } + + @Override + public int available() throws IOException { + return Math.min(super.available(), limit); + } + + @Override + public int read() throws IOException { + if (limit <= 0) { + return -1; + } + final int result = super.read(); + if (result >= 0) { + --limit; + } + return result; + } + + @Override + public int read(final byte[] b, final int off, int len) throws IOException { + if (limit <= 0) { + return -1; + } + len = Math.min(len, limit); + final int result = super.read(b, off, len); + if (result >= 0) { + limit -= result; + } + return result; + } + + @Override + public long skip(final long n) throws IOException { + // because we take the minimum of an int and a long, result is guaranteed to be + // less than or equal to Integer.MAX_INT so this cast is safe + int result = (int) super.skip(Math.min(n, limit)); + if (result >= 0) { + // if the superclass adheres to the contract for skip, this condition is always true + limit -= result; + } + return result; + } +} \ No newline at end of file diff --git a/protobuf-api/src/main/java/com/google/protobuf/MapEntry.java b/protobuf-api/src/main/java/com/google/protobuf/MapEntry.java index 8cd34ee..30b55ef 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/MapEntry.java +++ b/protobuf-api/src/main/java/com/google/protobuf/MapEntry.java @@ -744,62 +744,6 @@ public Builder clone() { return new Builder<>(metadata, key, value, hasKey, hasValue); } - /** - * An InputStream implementations which reads from some other InputStream but is limited to a - * particular number of bytes. Used by mergeDelimitedFrom(). This is intentionally - * package-private so that UnknownFieldSet can share it. - */ - static final class LimitedInputStream extends FilterInputStream { - private int limit; - - LimitedInputStream(InputStream in, int limit) { - super(in); - this.limit = limit; - } - - @Override - public int available() throws IOException { - return Math.min(super.available(), limit); - } - - @Override - public int read() throws IOException { - if (limit <= 0) { - return -1; - } - final int result = super.read(); - if (result >= 0) { - --limit; - } - return result; - } - - @Override - public int read(final byte[] b, final int off, int len) throws IOException { - if (limit <= 0) { - return -1; - } - len = Math.min(len, limit); - final int result = super.read(b, off, len); - if (result >= 0) { - limit -= result; - } - return result; - } - - @Override - public long skip(final long n) throws IOException { - // because we take the minimum of an int and a long, result is guaranteed to be - // less than or equal to Integer.MAX_INT so this cast is safe - int result = (int) super.skip(Math.min(n, limit)); - if (result >= 0) { - // if the superclass adheres to the contract for skip, this condition is always true - limit -= result; - } - return result; - } - } - @Override public boolean mergeDelimitedFrom( final InputStream input, final ExtensionRegistryLite extensionRegistry) throws IOException { @@ -808,7 +752,7 @@ public boolean mergeDelimitedFrom( return false; } final int size = CodedInputStream.readRawVarint32(firstByte, input); - final InputStream limitedInput = new AbstractMessageLite.Builder.LimitedInputStream(input, size); + final InputStream limitedInput = new LimitedInputStream(input, size); mergeFrom(limitedInput, extensionRegistry); return true; } diff --git a/protobuf-api/src/main/java/com/google/protobuf/SerializedForm.java b/protobuf-api/src/main/java/com/google/protobuf/SerializedForm.java new file mode 100644 index 0000000..78b40de --- /dev/null +++ b/protobuf-api/src/main/java/com/google/protobuf/SerializedForm.java @@ -0,0 +1,91 @@ +package com.google.protobuf; + +import java.io.ObjectStreamException; +import java.io.Serializable; + +/** + * A serialized (serializable) form of the generated message. Stores the message as a class name + * and a byte array. + */ +final class SerializedForm implements Serializable { + + public static SerializedForm of(MessageLite message) { + return new SerializedForm(message); + } + + private static final long serialVersionUID = 0L; + + // since v3.6.1 + private final Class messageClass; + private final String messageClassName; + private final byte[] asBytes; + + /** + * Creates the serialized form by calling {@link com.google.protobuf.MessageLite#toByteArray}. + * + * @param regularForm the message to serialize + */ + SerializedForm(MessageLite regularForm) { + messageClass = regularForm.getClass(); + messageClassName = regularForm.getClass().getName(); + asBytes = regularForm.toByteArray(); + } + + /** + * When read from an ObjectInputStream, this method converts this object back to the regular + * form. Part of Java's serialization magic. + * + * @return a GeneratedMessage of the type that was serialized + */ + protected Object readResolve() throws ObjectStreamException { + try { + Class messageClass = resolveMessageClass(); + java.lang.reflect.Field defaultInstanceField = + messageClass.getDeclaredField("DEFAULT_INSTANCE"); + defaultInstanceField.setAccessible(true); + MessageLite defaultInstance = (MessageLite) defaultInstanceField.get(null); + return defaultInstance.newBuilderForType().mergeFrom(asBytes).buildPartial(); + } catch (ClassNotFoundException e) { + throw new RuntimeException("Unable to find proto buffer class: " + messageClassName, e); + } catch (NoSuchFieldException e) { + return readResolveFallback(); + } catch (SecurityException e) { + throw new RuntimeException("Unable to call DEFAULT_INSTANCE in " + messageClassName, e); + } catch (IllegalAccessException e) { + throw new RuntimeException("Unable to call parsePartialFrom", e); + } catch (InvalidProtocolBufferException e) { + throw new RuntimeException("Unable to understand proto buffer", e); + } + } + + /** + * @deprecated from v3.0.0-beta-3+, for compatibility with v2.5.0 and v2.6.1 generated code. + */ + @Deprecated + private Object readResolveFallback() throws ObjectStreamException { + try { + Class messageClass = resolveMessageClass(); + java.lang.reflect.Field defaultInstanceField = + messageClass.getDeclaredField("defaultInstance"); + defaultInstanceField.setAccessible(true); + MessageLite defaultInstance = (MessageLite) defaultInstanceField.get(null); + return defaultInstance.newBuilderForType() + .mergeFrom(asBytes) + .buildPartial(); + } catch (ClassNotFoundException e) { + throw new RuntimeException("Unable to find proto buffer class: " + messageClassName, e); + } catch (NoSuchFieldException e) { + throw new RuntimeException("Unable to find defaultInstance in " + messageClassName, e); + } catch (SecurityException e) { + throw new RuntimeException("Unable to call defaultInstance in " + messageClassName, e); + } catch (IllegalAccessException e) { + throw new RuntimeException("Unable to call parsePartialFrom", e); + } catch (InvalidProtocolBufferException e) { + throw new RuntimeException("Unable to understand proto buffer", e); + } + } + + private Class resolveMessageClass() throws ClassNotFoundException { + return messageClass != null ? messageClass : Class.forName(messageClassName); + } +} \ No newline at end of file diff --git a/protobuf-api/src/main/java/com/google/protobuf/UnknownFieldSet.java b/protobuf-api/src/main/java/com/google/protobuf/UnknownFieldSet.java index 10fd7a7..725051c 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/UnknownFieldSet.java +++ b/protobuf-api/src/main/java/com/google/protobuf/UnknownFieldSet.java @@ -7,7 +7,6 @@ package com.google.protobuf; -import com.google.protobuf.AbstractMessageLite.Builder.LimitedInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/GeneratedMessageV3.java b/protobuf-sdk/src/main/java/com/google/protobuf/GeneratedMessageV3.java index 9c4980f..10642ca 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/GeneratedMessageV3.java +++ b/protobuf-sdk/src/main/java/com/google/protobuf/GeneratedMessageV3.java @@ -3251,7 +3251,7 @@ public Message.Builder getRepeatedBuilder( * @return a SerializedForm of this message */ protected Object writeReplace() throws ObjectStreamException { - return new GeneratedMessageLite.SerializedForm(this); + return new SerializedForm(this); } /** From fa86af5ff5ad17483b73938f8e413c2cd5aee0c9 Mon Sep 17 00:00:00 2001 From: blakeli Date: Mon, 7 Apr 2025 19:36:52 -0400 Subject: [PATCH 14/42] Decouple MessageReflection from GeneratedMessage --- .../com/google/protobuf/MessageReflection.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/protobuf-api/src/main/java/com/google/protobuf/MessageReflection.java b/protobuf-api/src/main/java/com/google/protobuf/MessageReflection.java index e33cc45..bb5871e 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/MessageReflection.java +++ b/protobuf-api/src/main/java/com/google/protobuf/MessageReflection.java @@ -11,6 +11,7 @@ import com.google.protobuf.Descriptors.FieldDescriptor; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.TreeMap; @@ -638,7 +639,7 @@ public WireFormat.Utf8Validation getUtf8Validation(Descriptors.FieldDescriptor d return WireFormat.Utf8Validation.STRICT; } // TODO: support lazy strings for repeated fields. - if (!descriptor.isRepeated() && builder instanceof GeneratedMessage.Builder) { + if (!descriptor.isRepeated() && GENERATED_MESSAGE_BUILDER.isInstance(builder)) { return WireFormat.Utf8Validation.LAZY; } return WireFormat.Utf8Validation.LOOSE; @@ -650,6 +651,20 @@ public Object finish() { } } + private static final Class GENERATED_MESSAGE_BUILDER = getGeneratedMessageBuilder(); + + private static Class getGeneratedMessageBuilder() { + try { + Class generatedMessageLiteClass = Class.forName("com.google.protobuf.GeneratedMessage"); + return Arrays.stream(generatedMessageLiteClass.getClasses()) + .filter(innerClass -> innerClass.getName().equals("com.google.protobuf.GeneratedMessage$Builder")) + .findFirst() + .get(); + } catch (Throwable e) { + return null; + } + } + static class ExtensionAdapter implements MergeTarget { private final FieldSet extensions; From d785096a2c7f8fda2dadf0f664791c1188a94b19 Mon Sep 17 00:00:00 2001 From: blakeli Date: Mon, 7 Apr 2025 19:47:21 -0400 Subject: [PATCH 15/42] Decouple ExtensionRegistry from GeneratedMessage --- .../main/java/com/google/protobuf/ExtensionRegistry.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/protobuf-api/src/main/java/com/google/protobuf/ExtensionRegistry.java b/protobuf-api/src/main/java/com/google/protobuf/ExtensionRegistry.java index 39babd3..665eee4 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/ExtensionRegistry.java +++ b/protobuf-api/src/main/java/com/google/protobuf/ExtensionRegistry.java @@ -200,10 +200,11 @@ public void add(final Extension extension) { add(newExtensionInfo(extension), extension.getExtensionType()); } - /** Add an extension from a generated file to the registry. */ - public void add(final GeneratedMessage.GeneratedExtension extension) { - add((Extension) extension); - } + //This method should be deprecated and then removed. +// /** Add an extension from a generated file to the registry. */ +// public void add(final GeneratedMessage.GeneratedExtension extension) { +// add((Extension) extension); +// } static ExtensionInfo newExtensionInfo(final Extension extension) { if (extension.getDescriptor().getJavaType() == FieldDescriptor.JavaType.MESSAGE) { From d4d6a2c523ddb409951ab46e4887a4c7a18f5b93 Mon Sep 17 00:00:00 2001 From: blakeli Date: Tue, 8 Apr 2025 10:48:22 -0400 Subject: [PATCH 16/42] Decouple DescriptorProtos from AbstractMessageLite. Use the util method from FlattenedGeneratedMessageV3 instead. --- .../com/google/protobuf/DescriptorProtos.java | 78 +++++++++---------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/protobuf-api/src/main/java/com/google/protobuf/DescriptorProtos.java b/protobuf-api/src/main/java/com/google/protobuf/DescriptorProtos.java index 28e300d..23ba571 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/DescriptorProtos.java +++ b/protobuf-api/src/main/java/com/google/protobuf/DescriptorProtos.java @@ -958,7 +958,7 @@ public Builder addAllFile( java.lang.Iterable values) { if (fileBuilder_ == null) { ensureFileIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( + com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( values, file_); onChanged(); } else { @@ -3516,7 +3516,7 @@ public Builder addDependency( public Builder addAllDependency( java.lang.Iterable values) { ensureDependencyIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( + com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( values, dependency_); bitField0_ |= 0x00000004; onChanged(); @@ -3647,7 +3647,7 @@ public Builder addPublicDependency(int value) { public Builder addAllPublicDependency( java.lang.Iterable values) { ensurePublicDependencyIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( + com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( values, publicDependency_); bitField0_ |= 0x00000008; onChanged(); @@ -3765,7 +3765,7 @@ public Builder addWeakDependency(int value) { public Builder addAllWeakDependency( java.lang.Iterable values) { ensureWeakDependencyIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( + com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( values, weakDependency_); bitField0_ |= 0x00000010; onChanged(); @@ -3968,7 +3968,7 @@ public Builder addAllMessageType( java.lang.Iterable values) { if (messageTypeBuilder_ == null) { ensureMessageTypeIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( + com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( values, messageType_); onChanged(); } else { @@ -4240,7 +4240,7 @@ public Builder addAllEnumType( java.lang.Iterable values) { if (enumTypeBuilder_ == null) { ensureEnumTypeIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( + com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( values, enumType_); onChanged(); } else { @@ -4480,7 +4480,7 @@ public Builder addAllService( java.lang.Iterable values) { if (serviceBuilder_ == null) { ensureServiceIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( + com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( values, service_); onChanged(); } else { @@ -4720,7 +4720,7 @@ public Builder addAllExtension( java.lang.Iterable values) { if (extensionBuilder_ == null) { ensureExtensionIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( + com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( values, extension_); onChanged(); } else { @@ -8886,7 +8886,7 @@ public Builder addAllField( java.lang.Iterable values) { if (fieldBuilder_ == null) { ensureFieldIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( + com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( values, field_); onChanged(); } else { @@ -9126,7 +9126,7 @@ public Builder addAllExtension( java.lang.Iterable values) { if (extensionBuilder_ == null) { ensureExtensionIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( + com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( values, extension_); onChanged(); } else { @@ -9366,7 +9366,7 @@ public Builder addAllNestedType( java.lang.Iterable values) { if (nestedTypeBuilder_ == null) { ensureNestedTypeIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( + com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( values, nestedType_); onChanged(); } else { @@ -9606,7 +9606,7 @@ public Builder addAllEnumType( java.lang.Iterable values) { if (enumTypeBuilder_ == null) { ensureEnumTypeIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( + com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( values, enumType_); onChanged(); } else { @@ -9846,7 +9846,7 @@ public Builder addAllExtensionRange( java.lang.Iterable values) { if (extensionRangeBuilder_ == null) { ensureExtensionRangeIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( + com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( values, extensionRange_); onChanged(); } else { @@ -10086,7 +10086,7 @@ public Builder addAllOneofDecl( java.lang.Iterable values) { if (oneofDeclBuilder_ == null) { ensureOneofDeclIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( + com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( values, oneofDecl_); onChanged(); } else { @@ -10447,7 +10447,7 @@ public Builder addAllReservedRange( java.lang.Iterable values) { if (reservedRangeBuilder_ == null) { ensureReservedRangeIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( + com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( values, reservedRange_); onChanged(); } else { @@ -10659,7 +10659,7 @@ public Builder addReservedName( public Builder addAllReservedName( java.lang.Iterable values) { ensureReservedNameIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( + com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( values, reservedName_); bitField0_ |= 0x00000200; onChanged(); @@ -13348,7 +13348,7 @@ public Builder addAllUninterpretedOption( java.lang.Iterable values) { if (uninterpretedOptionBuilder_ == null) { ensureUninterpretedOptionIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( + com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( values, uninterpretedOption_); onChanged(); } else { @@ -13680,7 +13680,7 @@ public Builder addAllDeclaration( java.lang.Iterable values) { if (declarationBuilder_ == null) { ensureDeclarationIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( + com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( values, declaration_); onChanged(); } else { @@ -19928,7 +19928,7 @@ public Builder addAllValue( java.lang.Iterable values) { if (valueBuilder_ == null) { ensureValueIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( + com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( values, value_); onChanged(); } else { @@ -20349,7 +20349,7 @@ public Builder addAllReservedRange( java.lang.Iterable values) { if (reservedRangeBuilder_ == null) { ensureReservedRangeIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( + com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( values, reservedRange_); onChanged(); } else { @@ -20609,7 +20609,7 @@ public Builder addReservedName( public Builder addAllReservedName( java.lang.Iterable values) { ensureReservedNameIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( + com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( values, reservedName_); bitField0_ |= 0x00000010; onChanged(); @@ -22536,7 +22536,7 @@ public Builder addAllMethod( java.lang.Iterable values) { if (methodBuilder_ == null) { ensureMethodIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( + com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( values, method_); onChanged(); } else { @@ -29386,7 +29386,7 @@ public Builder addAllUninterpretedOption( java.lang.Iterable values) { if (uninterpretedOptionBuilder_ == null) { ensureUninterpretedOptionIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( + com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( values, uninterpretedOption_); onChanged(); } else { @@ -31754,7 +31754,7 @@ public Builder addAllUninterpretedOption( java.lang.Iterable values) { if (uninterpretedOptionBuilder_ == null) { ensureUninterpretedOptionIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( + com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( values, uninterpretedOption_); onChanged(); } else { @@ -37186,7 +37186,7 @@ public Builder addAllEditionDefaults( java.lang.Iterable values) { if (editionDefaultsBuilder_ == null) { ensureEditionDefaultsIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( + com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( values, editionDefaults_); onChanged(); } else { @@ -37771,7 +37771,7 @@ public Builder addAllUninterpretedOption( java.lang.Iterable values) { if (uninterpretedOptionBuilder_ == null) { ensureUninterpretedOptionIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( + com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( values, uninterpretedOption_); onChanged(); } else { @@ -39047,7 +39047,7 @@ public Builder addAllUninterpretedOption( java.lang.Iterable values) { if (uninterpretedOptionBuilder_ == null) { ensureUninterpretedOptionIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( + com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( values, uninterpretedOption_); onChanged(); } else { @@ -40807,7 +40807,7 @@ public Builder addAllUninterpretedOption( java.lang.Iterable values) { if (uninterpretedOptionBuilder_ == null) { ensureUninterpretedOptionIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( + com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( values, uninterpretedOption_); onChanged(); } else { @@ -42647,7 +42647,7 @@ public Builder addAllUninterpretedOption( java.lang.Iterable values) { if (uninterpretedOptionBuilder_ == null) { ensureUninterpretedOptionIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( + com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( values, uninterpretedOption_); onChanged(); } else { @@ -44079,7 +44079,7 @@ public Builder addAllUninterpretedOption( java.lang.Iterable values) { if (uninterpretedOptionBuilder_ == null) { ensureUninterpretedOptionIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( + com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( values, uninterpretedOption_); onChanged(); } else { @@ -45745,7 +45745,7 @@ public Builder addAllUninterpretedOption( java.lang.Iterable values) { if (uninterpretedOptionBuilder_ == null) { ensureUninterpretedOptionIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( + com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( values, uninterpretedOption_); onChanged(); } else { @@ -47770,7 +47770,7 @@ public Builder addAllName( java.lang.Iterable values) { if (nameBuilder_ == null) { ensureNameIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( + com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( values, name_); onChanged(); } else { @@ -51927,7 +51927,7 @@ public Builder addAllDefaults( java.lang.Iterable values) { if (defaultsBuilder_ == null) { ensureDefaultsIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( + com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( values, defaults_); onChanged(); } else { @@ -54097,7 +54097,7 @@ public Builder addPath(int value) { public Builder addAllPath( java.lang.Iterable values) { ensurePathIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( + com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( values, path_); bitField0_ |= 0x00000001; onChanged(); @@ -54255,7 +54255,7 @@ public Builder addSpan(int value) { public Builder addAllSpan( java.lang.Iterable values) { ensureSpanIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( + com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( values, span_); bitField0_ |= 0x00000002; onChanged(); @@ -54818,7 +54818,7 @@ public Builder addLeadingDetachedComments( public Builder addAllLeadingDetachedComments( java.lang.Iterable values) { ensureLeadingDetachedCommentsIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( + com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( values, leadingDetachedComments_); bitField0_ |= 0x00000010; onChanged(); @@ -56208,7 +56208,7 @@ public Builder addAllLocation( java.lang.Iterable values) { if (locationBuilder_ == null) { ensureLocationIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( + com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( values, location_); onChanged(); } else { @@ -57894,7 +57894,7 @@ public Builder addPath(int value) { public Builder addAllPath( java.lang.Iterable values) { ensurePathIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( + com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( values, path_); bitField0_ |= 0x00000001; onChanged(); @@ -58886,7 +58886,7 @@ public Builder addAllAnnotation( java.lang.Iterable values) { if (annotationBuilder_ == null) { ensureAnnotationIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( + com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( values, annotation_); onChanged(); } else { From abcdf6e807693e815ad04fddc57d137fbd79a761 Mon Sep 17 00:00:00 2001 From: blakeli Date: Tue, 8 Apr 2025 11:16:09 -0400 Subject: [PATCH 17/42] Move GeneratedMessage to SDK package. --- .../src/main/java/com/google/protobuf/GeneratedMessage.java | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {protobuf-api => protobuf-sdk}/src/main/java/com/google/protobuf/GeneratedMessage.java (100%) diff --git a/protobuf-api/src/main/java/com/google/protobuf/GeneratedMessage.java b/protobuf-sdk/src/main/java/com/google/protobuf/GeneratedMessage.java similarity index 100% rename from protobuf-api/src/main/java/com/google/protobuf/GeneratedMessage.java rename to protobuf-sdk/src/main/java/com/google/protobuf/GeneratedMessage.java From 3cd6099b49d32f3158e8c4c3cb9acf8a9ae317d3 Mon Sep 17 00:00:00 2001 From: blakeli Date: Tue, 8 Apr 2025 13:52:13 -0400 Subject: [PATCH 18/42] Use FlattenedAbstractMessage instead of AbstractMessage in DynamicMessage and Value --- .../src/main/java/com/google/protobuf/DynamicMessage.java | 4 ++-- protobuf-sdk/src/main/java/com/google/protobuf/Value.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/protobuf-api/src/main/java/com/google/protobuf/DynamicMessage.java b/protobuf-api/src/main/java/com/google/protobuf/DynamicMessage.java index de98df0..578e362 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/DynamicMessage.java +++ b/protobuf-api/src/main/java/com/google/protobuf/DynamicMessage.java @@ -26,7 +26,7 @@ * * @author kenton@google.com Kenton Varda */ -public final class DynamicMessage extends AbstractMessage { +public final class DynamicMessage extends FlattenedAbstractMessage { private final Descriptor type; private final FieldSet fields; private final FieldDescriptor[] oneofCases; @@ -293,7 +293,7 @@ private void verifyOneofContainingType(OneofDescriptor oneof) { // ================================================================= /** Builder for {@link DynamicMessage}s. */ - public static final class Builder extends AbstractMessage.Builder { + public static final class Builder extends FlattenedAbstractMessage.Builder { private final Descriptor type; private FieldSet.Builder fields; private final FieldDescriptor[] oneofCases; diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/Value.java b/protobuf-sdk/src/main/java/com/google/protobuf/Value.java index 97dab1a..a74c041 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/Value.java +++ b/protobuf-sdk/src/main/java/com/google/protobuf/Value.java @@ -53,7 +53,7 @@ protected java.lang.Object newInstance( private java.lang.Object kind_; public enum KindCase implements com.google.protobuf.Internal.EnumLite, - com.google.protobuf.AbstractMessage.InternalOneOfEnum { + com.google.protobuf.FlattenedGeneratedMessageV3.InternalOneOfEnum { NULL_VALUE(1), NUMBER_VALUE(2), STRING_VALUE(3), From a3a9ddd21e4c08bac4d16ae4f663e71e21839876 Mon Sep 17 00:00:00 2001 From: blakeli Date: Tue, 8 Apr 2025 14:13:16 -0400 Subject: [PATCH 19/42] Move AbstractMessage to SDK package. --- .../src/main/java/com/google/protobuf/AbstractMessage.java | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {protobuf-api => protobuf-sdk}/src/main/java/com/google/protobuf/AbstractMessage.java (100%) diff --git a/protobuf-api/src/main/java/com/google/protobuf/AbstractMessage.java b/protobuf-sdk/src/main/java/com/google/protobuf/AbstractMessage.java similarity index 100% rename from protobuf-api/src/main/java/com/google/protobuf/AbstractMessage.java rename to protobuf-sdk/src/main/java/com/google/protobuf/AbstractMessage.java From e381ef332aa46b88ae3d3ecad167dfc8e136c964 Mon Sep 17 00:00:00 2001 From: blakeli Date: Mon, 14 Apr 2025 14:36:11 -0400 Subject: [PATCH 20/42] Remove unnecessary cast. --- .../src/main/java/com/google/protobuf/ArrayEncoder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/ArrayEncoder.java b/protobuf-sdk/src/main/java/com/google/protobuf/ArrayEncoder.java index efd2860..dfb943f 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/ArrayEncoder.java +++ b/protobuf-sdk/src/main/java/com/google/protobuf/ArrayEncoder.java @@ -163,7 +163,7 @@ public final void writeRawMessageSetExtension(final int fieldNumber, final ByteS @Override public final void writeMessageNoTag(final MessageLite value) throws IOException { writeUInt32NoTag(value.getSerializedSize()); - ((AbstractMessageLite) value).writeTo(this); + value.writeTo(this); } @Override From 29d4e3d7e37ee1b54a920eabec741aafd4a91a8d Mon Sep 17 00:00:00 2001 From: blakeli Date: Mon, 14 Apr 2025 18:07:41 -0400 Subject: [PATCH 21/42] Make GeneratedMessageLite and AbstractMessageLite package private. Extract AbstractMessageLite.addAll method to Internal so that PluginProtos does not have to be dependent on AbstractMessageLite --- .../google/protobuf/AbstractMessageLite.java | 2 +- .../google/protobuf/GeneratedMessageLite.java | 2 +- .../java/com/google/protobuf/Internal.java | 63 +++++++++++++++++++ .../protobuf/compiler/PluginProtos.java | 8 +-- 4 files changed, 69 insertions(+), 6 deletions(-) diff --git a/protobuf-api/src/main/java/com/google/protobuf/AbstractMessageLite.java b/protobuf-api/src/main/java/com/google/protobuf/AbstractMessageLite.java index 6a9d7ba..838579c 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/AbstractMessageLite.java +++ b/protobuf-api/src/main/java/com/google/protobuf/AbstractMessageLite.java @@ -23,7 +23,7 @@ * * @author kenton@google.com Kenton Varda */ -public abstract class AbstractMessageLite< +abstract class AbstractMessageLite< MessageType extends AbstractMessageLite, BuilderType extends AbstractMessageLite.Builder> implements MessageLite { diff --git a/protobuf-api/src/main/java/com/google/protobuf/GeneratedMessageLite.java b/protobuf-api/src/main/java/com/google/protobuf/GeneratedMessageLite.java index c153960..76fbcaa 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/GeneratedMessageLite.java +++ b/protobuf-api/src/main/java/com/google/protobuf/GeneratedMessageLite.java @@ -34,7 +34,7 @@ * * @author kenton@google.com Kenton Varda */ -public abstract class GeneratedMessageLite< +abstract class GeneratedMessageLite< MessageType extends GeneratedMessageLite, BuilderType extends GeneratedMessageLite.Builder> extends AbstractMessageLite { diff --git a/protobuf-api/src/main/java/com/google/protobuf/Internal.java b/protobuf-api/src/main/java/com/google/protobuf/Internal.java index 3024aa9..52da3c2 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/Internal.java +++ b/protobuf-api/src/main/java/com/google/protobuf/Internal.java @@ -14,7 +14,9 @@ import java.util.AbstractList; import java.util.AbstractMap; import java.util.AbstractSet; +import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -126,6 +128,67 @@ public static ByteBuffer copyByteBuffer(ByteBuffer source) { return result; } + /** + * Adds the {@code values} to the {@code list}. This is a helper method used by generated code. + * Users should ignore it. + * + * @throws NullPointerException if {@code values} or any of the elements of {@code values} is + * null. + */ + public static void addAll(final Iterable values, final List list) { + checkNotNull(values); + if (values instanceof LazyStringList) { + // For StringOrByteStringLists, check the underlying elements to avoid + // forcing conversions of ByteStrings to Strings. + // TODO: Could we just prohibit nulls in all protobuf lists and get rid of this? Is + // if even possible to hit this condition as all protobuf methods check for null first, + // right? + List lazyValues = ((LazyStringList) values).getUnderlyingElements(); + LazyStringList lazyList = (LazyStringList) list; + int begin = list.size(); + for (Object value : lazyValues) { + if (value == null) { + // encountered a null value so we must undo our modifications prior to throwing + String message = "Element at index " + (lazyList.size() - begin) + " is null."; + for (int i = lazyList.size() - 1; i >= begin; i--) { + lazyList.remove(i); + } + throw new NullPointerException(message); + } + if (value instanceof ByteString) { + lazyList.add((ByteString) value); + } else { + lazyList.add((String) value); + } + } + } else { + if (values instanceof PrimitiveNonBoxingCollection) { + list.addAll((Collection) values); + } else { + addAllCheckingNulls(values, list); + } + } + } + + // We check nulls as we iterate to avoid iterating over values twice. + private static void addAllCheckingNulls(Iterable values, List list) { + if (list instanceof ArrayList && values instanceof Collection) { + ((ArrayList) list).ensureCapacity(list.size() + ((Collection) values).size()); + } + int begin = list.size(); + for (T value : values) { + if (value == null) { + // encountered a null value so we must undo our modifications prior to throwing + String message = "Element at index " + (list.size() - begin) + " is null."; + for (int i = list.size() - 1; i >= begin; i--) { + list.remove(i); + } + throw new NullPointerException(message); + } + list.add(value); + } + } + /** * Helper called by generated code to determine if a byte array is a valid UTF-8 encoded string * such that the original bytes can be converted to a String object and then back to a byte array diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/compiler/PluginProtos.java b/protobuf-sdk/src/main/java/com/google/protobuf/compiler/PluginProtos.java index 501218a..a9fb84e 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/compiler/PluginProtos.java +++ b/protobuf-sdk/src/main/java/com/google/protobuf/compiler/PluginProtos.java @@ -2392,7 +2392,7 @@ public Builder addFileToGenerate( public Builder addAllFileToGenerate( java.lang.Iterable values) { ensureFileToGenerateIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( + com.google.protobuf.Internal.addAll( values, fileToGenerate_); bitField0_ |= 0x00000001; onChanged(); @@ -2901,7 +2901,7 @@ public Builder addAllProtoFile( java.lang.Iterable values) { if (protoFileBuilder_ == null) { ensureProtoFileIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( + com.google.protobuf.Internal.addAll( values, protoFile_); onChanged(); } else { @@ -3377,7 +3377,7 @@ public Builder addAllSourceFileDescriptors( java.lang.Iterable values) { if (sourceFileDescriptorsBuilder_ == null) { ensureSourceFileDescriptorsIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( + com.google.protobuf.Internal.addAll( values, sourceFileDescriptors_); onChanged(); } else { @@ -7180,7 +7180,7 @@ public Builder addAllFile( java.lang.Iterable values) { if (fileBuilder_ == null) { ensureFileIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( + com.google.protobuf.Internal.addAll( values, file_); onChanged(); } else { From 5e6e93baec5e5b4792817250128753c94566e322 Mon Sep 17 00:00:00 2001 From: blakeli Date: Tue, 15 Apr 2025 00:11:25 -0400 Subject: [PATCH 22/42] Move TextFormat to SDK package.Introducing a new TextFormatInternal. Move functionality required by the API package to TextFormatInternal or TextFormatEscaper --- .../java/com/google/protobuf/Descriptors.java | 12 +- .../protobuf/FlattenedAbstractMessage.java | 4 +- .../protobuf/FlattenedGeneratedMessageV3.java | 2 +- .../java/com/google/protobuf/MapEntry.java | 4 +- .../google/protobuf/TextFormatEscaper.java | 212 +++++ .../google/protobuf/TextFormatInternal.java | 732 ++++++++++++++++++ .../com/google/protobuf/UnknownFieldSet.java | 4 +- .../com/google/protobuf/AbstractMessage.java | 4 +- .../java/com/google/protobuf/TextFormat.java | 299 +------ 9 files changed, 965 insertions(+), 308 deletions(-) create mode 100644 protobuf-api/src/main/java/com/google/protobuf/TextFormatInternal.java rename {protobuf-api => protobuf-sdk}/src/main/java/com/google/protobuf/TextFormat.java (88%) diff --git a/protobuf-api/src/main/java/com/google/protobuf/Descriptors.java b/protobuf-api/src/main/java/com/google/protobuf/Descriptors.java index fb9b661..23d43aa 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/Descriptors.java +++ b/protobuf-api/src/main/java/com/google/protobuf/Descriptors.java @@ -1649,20 +1649,20 @@ private void crossLink() throws DescriptorValidationException { case INT32: case SINT32: case SFIXED32: - defaultValue = TextFormat.parseInt32(proto.getDefaultValue()); + defaultValue = TextFormatInternal.parseInt32(proto.getDefaultValue()); break; case UINT32: case FIXED32: - defaultValue = TextFormat.parseUInt32(proto.getDefaultValue()); + defaultValue = TextFormatInternal.parseUInt32(proto.getDefaultValue()); break; case INT64: case SINT64: case SFIXED64: - defaultValue = TextFormat.parseInt64(proto.getDefaultValue()); + defaultValue = TextFormatInternal.parseInt64(proto.getDefaultValue()); break; case UINT64: case FIXED64: - defaultValue = TextFormat.parseUInt64(proto.getDefaultValue()); + defaultValue = TextFormatInternal.parseUInt64(proto.getDefaultValue()); break; case FLOAT: if (proto.getDefaultValue().equals("inf")) { @@ -1694,8 +1694,8 @@ private void crossLink() throws DescriptorValidationException { break; case BYTES: try { - defaultValue = TextFormat.unescapeBytes(proto.getDefaultValue()); - } catch (TextFormat.InvalidEscapeSequenceException e) { + defaultValue = TextFormatEscaper.unescapeBytes(proto.getDefaultValue()); + } catch (Exception e) { throw new DescriptorValidationException( this, "Couldn't parse default value: " + e.getMessage(), e); } diff --git a/protobuf-api/src/main/java/com/google/protobuf/FlattenedAbstractMessage.java b/protobuf-api/src/main/java/com/google/protobuf/FlattenedAbstractMessage.java index 0fcf537..df84945 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/FlattenedAbstractMessage.java +++ b/protobuf-api/src/main/java/com/google/protobuf/FlattenedAbstractMessage.java @@ -171,7 +171,7 @@ public FieldDescriptor getOneofFieldDescriptor(OneofDescriptor oneof) { @Override public final String toString() { - return TextFormat.printer().printToString(this); + return TextFormatInternal.printer().printToString(this); } @Override @@ -686,7 +686,7 @@ public Message.Builder getRepeatedFieldBuilder(final FieldDescriptor field, int @Override public String toString() { - return TextFormat.printer().printToString(this); + return TextFormatInternal.printer().printToString(this); } /** Construct an UninitializedMessageException reporting missing fields in the given message. */ diff --git a/protobuf-api/src/main/java/com/google/protobuf/FlattenedGeneratedMessageV3.java b/protobuf-api/src/main/java/com/google/protobuf/FlattenedGeneratedMessageV3.java index 96243f8..d51c6c6 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/FlattenedGeneratedMessageV3.java +++ b/protobuf-api/src/main/java/com/google/protobuf/FlattenedGeneratedMessageV3.java @@ -1085,7 +1085,7 @@ public BuilderT mergeFrom( @Override public String toString() { - return TextFormat.printer().printToString(this); + return TextFormatInternal.printer().printToString(this); } /** Construct an UninitializedMessageException reporting missing fields in the given message. */ diff --git a/protobuf-api/src/main/java/com/google/protobuf/MapEntry.java b/protobuf-api/src/main/java/com/google/protobuf/MapEntry.java index 30b55ef..8cc3622 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/MapEntry.java +++ b/protobuf-api/src/main/java/com/google/protobuf/MapEntry.java @@ -357,7 +357,7 @@ public FieldDescriptor getOneofFieldDescriptor(Descriptors.OneofDescriptor oneof @Override public final String toString() { - return TextFormat.printer().printToString(this); + return TextFormatInternal.printer().printToString(this); } protected int memoizedSize = -1; @@ -989,7 +989,7 @@ public MapEntry.Builder getRepeatedFieldBuilder(final FieldDescriptor field @Override public String toString() { - return TextFormat.printer().printToString(this); + return TextFormatInternal.printer().printToString(this); } /** Construct an UninitializedMessageException reporting missing fields in the given message. */ diff --git a/protobuf-api/src/main/java/com/google/protobuf/TextFormatEscaper.java b/protobuf-api/src/main/java/com/google/protobuf/TextFormatEscaper.java index 8e43fb0..c141961 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/TextFormatEscaper.java +++ b/protobuf-api/src/main/java/com/google/protobuf/TextFormatEscaper.java @@ -7,6 +7,8 @@ package com.google.protobuf; +import java.io.IOException; + /** * Provide text format escaping of proto instances. These ASCII characters are escaped: * @@ -134,4 +136,214 @@ static String escapeText(String input) { static String escapeDoubleQuotesAndBackslashes(String input) { return input.replace("\\", "\\\\").replace("\"", "\\\""); } + + /** Is this an octal digit? */ + private static boolean isOctal(final byte c) { + return '0' <= c && c <= '7'; + } + + /** Is this a hex digit? */ + private static boolean isHex(final byte c) { + return ('0' <= c && c <= '9') || ('a' <= c && c <= 'f') || ('A' <= c && c <= 'F'); + } + + /** + * Interpret a character as a digit (in any base up to 36) and return the numeric value. This is + * like {@code Character.digit()} but we don't accept non-ASCII digits. + */ + private static int digitValue(final byte c) { + if ('0' <= c && c <= '9') { + return c - '0'; + } else if ('a' <= c && c <= 'z') { + return c - 'a' + 10; + } else { + return c - 'A' + 10; + } + } + + /** + * Thrown by {@link TextFormat#unescapeBytes} and {@link TextFormat#unescapeText} when an invalid + * escape sequence is seen. + */ + static class InvalidEscapeSequenceException extends IOException { + private static final long serialVersionUID = -8164033650142593305L; + + InvalidEscapeSequenceException(final String description) { + super(description); + } + } + + static ByteString unescapeBytes(CharSequence charString) + throws TextFormatEscaper.InvalidEscapeSequenceException { + // First convert the Java character sequence to UTF-8 bytes. + ByteString input = ByteString.copyFromUtf8(charString.toString()); + // Then unescape certain byte sequences introduced by ASCII '\\'. The valid + // escapes can all be expressed with ASCII characters, so it is safe to + // operate on bytes here. + // + // Unescaping the input byte array will result in a byte sequence that's no + // longer than the input. That's because each escape sequence is between + // two and four bytes long and stands for a single byte. + final byte[] result = new byte[input.size()]; + int pos = 0; + for (int i = 0; i < input.size(); i++) { + byte c = input.byteAt(i); + if (c == '\\') { + if (i + 1 < input.size()) { + ++i; + c = input.byteAt(i); + if (isOctal(c)) { + // Octal escape. + int code = digitValue(c); + if (i + 1 < input.size() && isOctal(input.byteAt(i + 1))) { + ++i; + code = code * 8 + digitValue(input.byteAt(i)); + } + if (i + 1 < input.size() && isOctal(input.byteAt(i + 1))) { + ++i; + code = code * 8 + digitValue(input.byteAt(i)); + } + // TODO: Check that 0 <= code && code <= 0xFF. + result[pos++] = (byte) code; + } else { + switch (c) { + case 'a': + result[pos++] = 0x07; + break; + case 'b': + result[pos++] = '\b'; + break; + case 'f': + result[pos++] = '\f'; + break; + case 'n': + result[pos++] = '\n'; + break; + case 'r': + result[pos++] = '\r'; + break; + case 't': + result[pos++] = '\t'; + break; + case 'v': + result[pos++] = 0x0b; + break; + case '\\': + result[pos++] = '\\'; + break; + case '\'': + result[pos++] = '\''; + break; + case '"': + result[pos++] = '\"'; + break; + case '?': + result[pos++] = '?'; + break; + + case 'x': + // hex escape + int code = 0; + if (i + 1 < input.size() && isHex(input.byteAt(i + 1))) { + ++i; + code = digitValue(input.byteAt(i)); + } else { + throw new TextFormatEscaper.InvalidEscapeSequenceException( + "Invalid escape sequence: '\\x' with no digits"); + } + if (i + 1 < input.size() && isHex(input.byteAt(i + 1))) { + ++i; + code = code * 16 + digitValue(input.byteAt(i)); + } + result[pos++] = (byte) code; + break; + + case 'u': + // Unicode escape + ++i; + if (i + 3 < input.size() + && isHex(input.byteAt(i)) + && isHex(input.byteAt(i + 1)) + && isHex(input.byteAt(i + 2)) + && isHex(input.byteAt(i + 3))) { + char ch = + (char) + (digitValue(input.byteAt(i)) << 12 + | digitValue(input.byteAt(i + 1)) << 8 + | digitValue(input.byteAt(i + 2)) << 4 + | digitValue(input.byteAt(i + 3))); + + if (ch >= Character.MIN_SURROGATE && ch <= Character.MAX_SURROGATE) { + throw new TextFormatEscaper.InvalidEscapeSequenceException( + "Invalid escape sequence: '\\u' refers to a surrogate"); + } + byte[] chUtf8 = Character.toString(ch).getBytes(Internal.UTF_8); + System.arraycopy(chUtf8, 0, result, pos, chUtf8.length); + pos += chUtf8.length; + i += 3; + } else { + throw new TextFormatEscaper.InvalidEscapeSequenceException( + "Invalid escape sequence: '\\u' with too few hex chars"); + } + break; + + case 'U': + // Unicode escape + ++i; + if (i + 7 >= input.size()) { + throw new TextFormatEscaper.InvalidEscapeSequenceException( + "Invalid escape sequence: '\\U' with too few hex chars"); + } + int codepoint = 0; + for (int offset = i; offset < i + 8; offset++) { + byte b = input.byteAt(offset); + if (!isHex(b)) { + throw new TextFormatEscaper.InvalidEscapeSequenceException( + "Invalid escape sequence: '\\U' with too few hex chars"); + } + codepoint = (codepoint << 4) | digitValue(b); + } + if (!Character.isValidCodePoint(codepoint)) { + throw new TextFormatEscaper.InvalidEscapeSequenceException( + "Invalid escape sequence: '\\U" + + input.substring(i, i + 8).toStringUtf8() + + "' is not a valid code point value"); + } + Character.UnicodeBlock unicodeBlock = Character.UnicodeBlock.of(codepoint); + if (unicodeBlock != null + && (unicodeBlock.equals(Character.UnicodeBlock.LOW_SURROGATES) + || unicodeBlock.equals(Character.UnicodeBlock.HIGH_SURROGATES) + || unicodeBlock.equals( + Character.UnicodeBlock.HIGH_PRIVATE_USE_SURROGATES))) { + throw new TextFormatEscaper.InvalidEscapeSequenceException( + "Invalid escape sequence: '\\U" + + input.substring(i, i + 8).toStringUtf8() + + "' refers to a surrogate code unit"); + } + int[] codepoints = new int[1]; + codepoints[0] = codepoint; + byte[] chUtf8 = new String(codepoints, 0, 1).getBytes(Internal.UTF_8); + System.arraycopy(chUtf8, 0, result, pos, chUtf8.length); + pos += chUtf8.length; + i += 7; + break; + + default: + throw new TextFormatEscaper.InvalidEscapeSequenceException( + "Invalid escape sequence: '\\" + (char) c + '\''); + } + } + } else { + throw new TextFormatEscaper.InvalidEscapeSequenceException( + "Invalid escape sequence: '\\' at end of string."); + } + } else { + result[pos++] = c; + } + } + + return result.length == pos + ? ByteString.wrap(result) // This reference has not been out of our control. + : ByteString.copyFrom(result, 0, pos); + } } diff --git a/protobuf-api/src/main/java/com/google/protobuf/TextFormatInternal.java b/protobuf-api/src/main/java/com/google/protobuf/TextFormatInternal.java new file mode 100644 index 0000000..0355aa5 --- /dev/null +++ b/protobuf-api/src/main/java/com/google/protobuf/TextFormatInternal.java @@ -0,0 +1,732 @@ +package com.google.protobuf; + +import java.io.IOException; +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Locale; +import java.util.Map; + +class TextFormatInternal { + /** + * Parse a 32-bit signed integer from the text. Unlike the Java standard {@code + * Integer.parseInt()}, this function recognizes the prefixes "0x" and "0" to signify hexadecimal + * and octal numbers, respectively. + */ + static int parseInt32(final String text) throws NumberFormatException { + return (int) parseInteger(text, true, false); + } + + /** + * Parse a 32-bit unsigned integer from the text. Unlike the Java standard {@code + * Integer.parseInt()}, this function recognizes the prefixes "0x" and "0" to signify hexadecimal + * and octal numbers, respectively. The result is coerced to a (signed) {@code int} when returned + * since Java has no unsigned integer type. + */ + static int parseUInt32(final String text) throws NumberFormatException { + return (int) parseInteger(text, false, false); + } + + /** + * Parse a 64-bit signed integer from the text. Unlike the Java standard {@code + * Integer.parseInt()}, this function recognizes the prefixes "0x" and "0" to signify hexadecimal + * and octal numbers, respectively. + */ + static long parseInt64(final String text) throws NumberFormatException { + return parseInteger(text, true, true); + } + + /** + * Parse a 64-bit unsigned integer from the text. Unlike the Java standard {@code + * Integer.parseInt()}, this function recognizes the prefixes "0x" and "0" to signify hexadecimal + * and octal numbers, respectively. The result is coerced to a (signed) {@code long} when returned + * since Java has no unsigned long type. + */ + static long parseUInt64(final String text) throws NumberFormatException { + return parseInteger(text, false, true); + } + + private static long parseInteger(final String text, final boolean isSigned, final boolean isLong) + throws NumberFormatException { + int pos = 0; + + boolean negative = false; + if (text.startsWith("-", pos)) { + if (!isSigned) { + throw new NumberFormatException("Number must be positive: " + text); + } + ++pos; + negative = true; + } + + int radix = 10; + if (text.startsWith("0x", pos)) { + pos += 2; + radix = 16; + } else if (text.startsWith("0", pos)) { + radix = 8; + } + + final String numberText = text.substring(pos); + + long result = 0; + if (numberText.length() < 16) { + // Can safely assume no overflow. + result = Long.parseLong(numberText, radix); + if (negative) { + result = -result; + } + + // Check bounds. + // No need to check for 64-bit numbers since they'd have to be 16 chars + // or longer to overflow. + if (!isLong) { + if (isSigned) { + if (result > Integer.MAX_VALUE || result < Integer.MIN_VALUE) { + throw new NumberFormatException( + "Number out of range for 32-bit signed integer: " + text); + } + } else { + if (result >= (1L << 32) || result < 0) { + throw new NumberFormatException( + "Number out of range for 32-bit unsigned integer: " + text); + } + } + } + } else { + BigInteger bigValue = new BigInteger(numberText, radix); + if (negative) { + bigValue = bigValue.negate(); + } + + // Check bounds. + if (!isLong) { + if (isSigned) { + if (bigValue.bitLength() > 31) { + throw new NumberFormatException( + "Number out of range for 32-bit signed integer: " + text); + } + } else { + if (bigValue.bitLength() > 32) { + throw new NumberFormatException( + "Number out of range for 32-bit unsigned integer: " + text); + } + } + } else { + if (isSigned) { + if (bigValue.bitLength() > 63) { + throw new NumberFormatException( + "Number out of range for 64-bit signed integer: " + text); + } + } else { + if (bigValue.bitLength() > 64) { + throw new NumberFormatException( + "Number out of range for 64-bit unsigned integer: " + text); + } + } + } + + result = bigValue.longValue(); + } + + return result; + } + + /** Printer instance which escapes non-ASCII characters. */ + public static TextFormatInternal.Printer printer() { + return TextFormatInternal.Printer.DEFAULT; + } + + /** Helper class for converting protobufs to text. */ + public static final class Printer { + + // Printer instance which escapes non-ASCII characters. + private static final TextFormatInternal.Printer DEFAULT = new TextFormatInternal.Printer(true, TypeRegistry.getEmptyTypeRegistry()); + + /** Whether to escape non ASCII characters with backslash and octal. */ + private final boolean escapeNonAscii; + + private final TypeRegistry typeRegistry; + + private Printer(boolean escapeNonAscii, TypeRegistry typeRegistry) { + this.escapeNonAscii = escapeNonAscii; + this.typeRegistry = typeRegistry; + } + + /** + * Return a new Printer instance with the specified escape mode. + * + * @param escapeNonAscii If true, the new Printer will escape non-ASCII characters (this is the + * default behavior. If false, the new Printer will print non-ASCII characters as is. In + * either case, the new Printer still escapes newlines and quotes in strings. + * @return a new Printer that clones all other configurations from the current {@link TextFormatInternal.Printer}, + * with the escape mode set to the given parameter. + */ + public TextFormatInternal.Printer escapingNonAscii(boolean escapeNonAscii) { + return new TextFormatInternal.Printer(escapeNonAscii, typeRegistry); + } + + /** + * Creates a new {@link TextFormatInternal.Printer} using the given typeRegistry. The new Printer clones all other + * configurations from the current {@link TextFormatInternal.Printer}. + * + * @throws IllegalArgumentException if a registry is already set. + */ + public TextFormatInternal.Printer usingTypeRegistry(TypeRegistry typeRegistry) { + if (this.typeRegistry != TypeRegistry.getEmptyTypeRegistry()) { + throw new IllegalArgumentException("Only one typeRegistry is allowed."); + } + return new TextFormatInternal.Printer(escapeNonAscii, typeRegistry); + } + + /** + * Outputs a textual representation of the Protocol Message supplied into the parameter output. + * (This representation is the new version of the classic "ProtocolPrinter" output from the + * original Protocol Buffer system) + */ + public void print(final MessageOrBuilder message, final Appendable output) throws IOException { + print(message, multiLineOutput(output)); + } + + /** Outputs a textual representation of {@code fields} to {@code output}. */ + public void print(final UnknownFieldSet fields, final Appendable output) throws IOException { + printUnknownFields(fields, multiLineOutput(output)); + } + + private void print(final MessageOrBuilder message, final TextFormatInternal.TextGenerator generator) + throws IOException { + if (message.getDescriptorForType().getFullName().equals("google.protobuf.Any") + && printAny(message, generator)) { + return; + } + printMessage(message, generator); + } + + /** + * Attempt to print the 'google.protobuf.Any' message in a human-friendly format. Returns false + * if the message isn't a valid 'google.protobuf.Any' message (in which case the message should + * be rendered just like a regular message to help debugging). + */ + private boolean printAny(final MessageOrBuilder message, final TextFormatInternal.TextGenerator generator) + throws IOException { + Descriptors.Descriptor messageType = message.getDescriptorForType(); + Descriptors.FieldDescriptor typeUrlField = messageType.findFieldByNumber(1); + Descriptors.FieldDescriptor valueField = messageType.findFieldByNumber(2); + if (typeUrlField == null + || typeUrlField.getType() != Descriptors.FieldDescriptor.Type.STRING + || valueField == null + || valueField.getType() != Descriptors.FieldDescriptor.Type.BYTES) { + // The message may look like an Any but isn't actually an Any message (might happen if the + // user tries to use DynamicMessage to construct an Any from incomplete Descriptor). + return false; + } + String typeUrl = (String) message.getField(typeUrlField); + // If type_url is not set, we will not be able to decode the content of the value, so just + // print out the Any like a regular message. + if (typeUrl.isEmpty()) { + return false; + } + Object value = message.getField(valueField); + + Message.Builder contentBuilder = null; + try { + Descriptors.Descriptor contentType = typeRegistry.getDescriptorForTypeUrl(typeUrl); + if (contentType == null) { + return false; + } + contentBuilder = DynamicMessage.getDefaultInstance(contentType).newBuilderForType(); + contentBuilder.mergeFrom((ByteString) value); + } catch (InvalidProtocolBufferException e) { + // The value of Any is malformed. We cannot print it out nicely, so fallback to printing out + // the type_url and value as bytes. Note that we fail open here to be consistent with + // text_format.cc, and also to allow a way for users to inspect the content of the broken + // message. + return false; + } + generator.print("["); + generator.print(typeUrl); + generator.print("] {"); + generator.eol(); + generator.indent(); + print(contentBuilder, generator); + generator.outdent(); + generator.print("}"); + generator.eol(); + return true; + } + + public String printFieldToString(final Descriptors.FieldDescriptor field, final Object value) { + try { + final StringBuilder text = new StringBuilder(); + printField(field, value, text); + return text.toString(); + } catch (IOException e) { + throw new IllegalStateException(e); + } + } + + public void printField(final Descriptors.FieldDescriptor field, final Object value, final Appendable output) + throws IOException { + printField(field, value, multiLineOutput(output)); + } + + private void printField( + final Descriptors.FieldDescriptor field, final Object value, final TextFormatInternal.TextGenerator generator) + throws IOException { + // Sort map field entries by key + if (field.isMapField()) { + List adapters = new ArrayList<>(); + for (Object entry : (List) value) { + adapters.add(new TextFormatInternal.Printer.MapEntryAdapter(entry, field)); + } + Collections.sort(adapters); + for (TextFormatInternal.Printer.MapEntryAdapter adapter : adapters) { + printSingleField(field, adapter.getEntry(), generator); + } + } else if (field.isRepeated()) { + // Repeated field. Print each element. + for (Object element : (List) value) { + printSingleField(field, element, generator); + } + } else { + printSingleField(field, value, generator); + } + } + + /** An adapter class that can take a {@link MapEntry} and returns its key and entry. */ + private static class MapEntryAdapter implements Comparable { + private Object entry; + + @SuppressWarnings({"rawtypes"}) + private MapEntry mapEntry; + + private final Descriptors.FieldDescriptor.JavaType fieldType; + + MapEntryAdapter(Object entry, Descriptors.FieldDescriptor fieldDescriptor) { + if (entry instanceof MapEntry) { + this.mapEntry = (MapEntry) entry; + } else { + this.entry = entry; + } + this.fieldType = extractFieldType(fieldDescriptor); + } + + private static Descriptors.FieldDescriptor.JavaType extractFieldType(Descriptors.FieldDescriptor fieldDescriptor) { + return fieldDescriptor.getMessageType().getFields().get(0).getJavaType(); + } + + Object getKey() { + if (mapEntry != null) { + return mapEntry.getKey(); + } + return null; + } + + Object getEntry() { + if (mapEntry != null) { + return mapEntry; + } + return entry; + } + + @Override + public int compareTo(TextFormatInternal.Printer.MapEntryAdapter b) { + if (getKey() == null || b.getKey() == null) { +// logger.info("Invalid key for map field."); + return -1; + } + switch (fieldType) { + case BOOLEAN: + return Boolean.valueOf((boolean) getKey()).compareTo((boolean) b.getKey()); + case LONG: + return Long.valueOf((long) getKey()).compareTo((long) b.getKey()); + case INT: + return Integer.valueOf((int) getKey()).compareTo((int) b.getKey()); + case STRING: + String aString = (String) getKey(); + String bString = (String) b.getKey(); + if (aString == null && bString == null) { + return 0; + } else if (aString == null && bString != null) { + return -1; + } else if (aString != null && bString == null) { + return 1; + } else { + return aString.compareTo(bString); + } + default: + return 0; + } + } + } + + /** + * Outputs a textual representation of the value of given field value. + * + * @param field the descriptor of the field + * @param value the value of the field + * @param output the output to which to append the formatted value + * @throws ClassCastException if the value is not appropriate for the given field descriptor + * @throws IOException if there is an exception writing to the output + */ + public void printFieldValue( + final Descriptors.FieldDescriptor field, final Object value, final Appendable output) + throws IOException { + printFieldValue(field, value, multiLineOutput(output)); + } + + private void printFieldValue( + final Descriptors.FieldDescriptor field, final Object value, final TextFormatInternal.TextGenerator generator) + throws IOException { + switch (field.getType()) { + case INT32: + case SINT32: + case SFIXED32: + generator.print(((Integer) value).toString()); + break; + + case INT64: + case SINT64: + case SFIXED64: + generator.print(((Long) value).toString()); + break; + + case BOOL: + generator.print(((Boolean) value).toString()); + break; + + case FLOAT: + generator.print(((Float) value).toString()); + break; + + case DOUBLE: + generator.print(((Double) value).toString()); + break; + + case UINT32: + case FIXED32: + generator.print(unsignedToString((Integer) value)); + break; + + case UINT64: + case FIXED64: + generator.print(unsignedToString((Long) value)); + break; + + case STRING: + generator.print("\""); + generator.print( + escapeNonAscii + ? TextFormatEscaper.escapeText((String) value) + : escapeDoubleQuotesAndBackslashes((String) value).replace("\n", "\\n")); + generator.print("\""); + break; + + case BYTES: + generator.print("\""); + if (value instanceof ByteString) { + generator.print(escapeBytes((ByteString) value)); + } else { + generator.print(escapeBytes((byte[]) value)); + } + generator.print("\""); + break; + + case ENUM: + generator.print(((Descriptors.EnumValueDescriptor) value).getName()); + break; + + case MESSAGE: + case GROUP: + print((MessageOrBuilder) value, generator); + break; + } + } + + /** Like {@code print()}, but writes directly to a {@code String} and returns it. */ + public String printToString(final MessageOrBuilder message) { + try { + final StringBuilder text = new StringBuilder(); + print(message, text); + return text.toString(); + } catch (IOException e) { + throw new IllegalStateException(e); + } + } + /** Like {@code print()}, but writes directly to a {@code String} and returns it. */ + public String printToString(final UnknownFieldSet fields) { + try { + final StringBuilder text = new StringBuilder(); + print(fields, text); + return text.toString(); + } catch (IOException e) { + throw new IllegalStateException(e); + } + } + + /** + * Generates a human readable form of this message, useful for debugging and other purposes, + * with no newline characters. + */ + public String shortDebugString(final MessageOrBuilder message) { + try { + final StringBuilder text = new StringBuilder(); + print(message, singleLineOutput(text)); + return text.toString(); + } catch (IOException e) { + throw new IllegalStateException(e); + } + } + + /** + * Generates a human readable form of the field, useful for debugging and other purposes, with + * no newline characters. + */ + public String shortDebugString(final Descriptors.FieldDescriptor field, final Object value) { + try { + final StringBuilder text = new StringBuilder(); + printField(field, value, singleLineOutput(text)); + return text.toString(); + } catch (IOException e) { + throw new IllegalStateException(e); + } + } + + /** + * Generates a human readable form of the unknown fields, useful for debugging and other + * purposes, with no newline characters. + */ + public String shortDebugString(final UnknownFieldSet fields) { + try { + final StringBuilder text = new StringBuilder(); + printUnknownFields(fields, singleLineOutput(text)); + return text.toString(); + } catch (IOException e) { + throw new IllegalStateException(e); + } + } + + private static void printUnknownFieldValue( + final int tag, final Object value, final TextFormatInternal.TextGenerator generator) throws IOException { + switch (WireFormat.getTagWireType(tag)) { + case WireFormat.WIRETYPE_VARINT: + generator.print(unsignedToString((Long) value)); + break; + case WireFormat.WIRETYPE_FIXED32: + generator.print(String.format((Locale) null, "0x%08x", (Integer) value)); + break; + case WireFormat.WIRETYPE_FIXED64: + generator.print(String.format((Locale) null, "0x%016x", (Long) value)); + break; + case WireFormat.WIRETYPE_LENGTH_DELIMITED: + try { + // Try to parse and print the field as an embedded message + UnknownFieldSet message = UnknownFieldSet.parseFrom((ByteString) value); + generator.print("{"); + generator.eol(); + generator.indent(); + printUnknownFields(message, generator); + generator.outdent(); + generator.print("}"); + } catch (InvalidProtocolBufferException e) { + // If not parseable as a message, print as a String + generator.print("\""); + generator.print(escapeBytes((ByteString) value)); + generator.print("\""); + } + break; + case WireFormat.WIRETYPE_START_GROUP: + printUnknownFields((UnknownFieldSet) value, generator); + break; + default: + throw new IllegalArgumentException("Bad tag: " + tag); + } + } + + private void printMessage(final MessageOrBuilder message, final TextFormatInternal.TextGenerator generator) + throws IOException { + for (Map.Entry field : message.getAllFields().entrySet()) { + printField(field.getKey(), field.getValue(), generator); + } + printUnknownFields(message.getUnknownFields(), generator); + } + + private void printSingleField( + final Descriptors.FieldDescriptor field, final Object value, final TextFormatInternal.TextGenerator generator) + throws IOException { + if (field.isExtension()) { + generator.print("["); + // We special-case MessageSet elements for compatibility with proto1. + if (field.getContainingType().getOptions().getMessageSetWireFormat() + && (field.getType() == Descriptors.FieldDescriptor.Type.MESSAGE) + && (field.isOptional()) + // object equality + && (field.getExtensionScope() == field.getMessageType())) { + generator.print(field.getMessageType().getFullName()); + } else { + generator.print(field.getFullName()); + } + generator.print("]"); + } else { + if (field.getType() == Descriptors.FieldDescriptor.Type.GROUP) { + // Groups must be serialized with their original capitalization. + generator.print(field.getMessageType().getName()); + } else { + generator.print(field.getName()); + } + } + + if (field.getJavaType() == Descriptors.FieldDescriptor.JavaType.MESSAGE) { + generator.print(" {"); + generator.eol(); + generator.indent(); + } else { + generator.print(": "); + } + + printFieldValue(field, value, generator); + + if (field.getJavaType() == Descriptors.FieldDescriptor.JavaType.MESSAGE) { + generator.outdent(); + generator.print("}"); + } + generator.eol(); + } + + private static void printUnknownFields( + final UnknownFieldSet unknownFields, final TextFormatInternal.TextGenerator generator) throws IOException { + for (Map.Entry entry : unknownFields.asMap().entrySet()) { + final int number = entry.getKey(); + final UnknownFieldSet.Field field = entry.getValue(); + printUnknownField(number, WireFormat.WIRETYPE_VARINT, field.getVarintList(), generator); + printUnknownField(number, WireFormat.WIRETYPE_FIXED32, field.getFixed32List(), generator); + printUnknownField(number, WireFormat.WIRETYPE_FIXED64, field.getFixed64List(), generator); + printUnknownField( + number, + WireFormat.WIRETYPE_LENGTH_DELIMITED, + field.getLengthDelimitedList(), + generator); + for (final UnknownFieldSet value : field.getGroupList()) { + generator.print(entry.getKey().toString()); + generator.print(" {"); + generator.eol(); + generator.indent(); + printUnknownFields(value, generator); + generator.outdent(); + generator.print("}"); + generator.eol(); + } + } + } + + private static void printUnknownField( + final int number, final int wireType, final List values, final TextFormatInternal.TextGenerator generator) + throws IOException { + for (final Object value : values) { + generator.print(String.valueOf(number)); + generator.print(": "); + printUnknownFieldValue(wireType, value, generator); + generator.eol(); + } + } + } + + /** Convert an unsigned 32-bit integer to a string. */ + public static String unsignedToString(final int value) { + if (value >= 0) { + return Integer.toString(value); + } else { + return Long.toString(value & 0x00000000FFFFFFFFL); + } + } + + /** Convert an unsigned 64-bit integer to a string. */ + public static String unsignedToString(final long value) { + if (value >= 0) { + return Long.toString(value); + } else { + // Pull off the most-significant bit so that BigInteger doesn't think + // the number is negative, then set it again using setBit(). + return BigInteger.valueOf(value & 0x7FFFFFFFFFFFFFFFL).setBit(63).toString(); + } + } + + private static TextFormatInternal.TextGenerator multiLineOutput(Appendable output) { + return new TextFormatInternal.TextGenerator(output, false); + } + + private static TextFormatInternal.TextGenerator singleLineOutput(Appendable output) { + return new TextFormatInternal.TextGenerator(output, true); + } + + private static String escapeBytes(ByteString input) { + return TextFormatEscaper.escapeBytes(input); + } + + public static String escapeBytes(byte[] input) { + return TextFormatEscaper.escapeBytes(input); + } + + public static String escapeDoubleQuotesAndBackslashes(final String input) { + return TextFormatEscaper.escapeDoubleQuotesAndBackslashes(input); + } + + /** An inner class for writing text to the output stream. */ + private static final class TextGenerator { + private final Appendable output; + private final StringBuilder indent = new StringBuilder(); + private final boolean singleLineMode; + // While technically we are "at the start of a line" at the very beginning of the output, all + // we would do in response to this is emit the (zero length) indentation, so it has no effect. + // Setting it false here does however suppress an unwanted leading space in single-line mode. + private boolean atStartOfLine = false; + + private TextGenerator(final Appendable output, boolean singleLineMode) { + this.output = output; + this.singleLineMode = singleLineMode; + } + + /** + * Indent text by two spaces. After calling Indent(), two spaces will be inserted at the + * beginning of each line of text. Indent() may be called multiple times to produce deeper + * indents. + */ + public void indent() { + indent.append(" "); + } + + /** Reduces the current indent level by two spaces, or crashes if the indent level is zero. */ + public void outdent() { + final int length = indent.length(); + if (length == 0) { + throw new IllegalArgumentException(" Outdent() without matching Indent()."); + } + indent.setLength(length - 2); + } + + /** + * Print text to the output stream. Bare newlines are never expected to be passed to this + * method; to indicate the end of a line, call "eol()". + */ + public void print(final CharSequence text) throws IOException { + if (atStartOfLine) { + atStartOfLine = false; + output.append(singleLineMode ? " " : indent); + } + output.append(text); + } + + /** + * Signifies reaching the "end of the current line" in the output. In single-line mode, this + * does not result in a newline being emitted, but ensures that a separating space is written + * before the next output. + */ + public void eol() throws IOException { + if (!singleLineMode) { + output.append("\n"); + } + atStartOfLine = true; + } + } +} diff --git a/protobuf-api/src/main/java/com/google/protobuf/UnknownFieldSet.java b/protobuf-api/src/main/java/com/google/protobuf/UnknownFieldSet.java index 725051c..d87ad2b 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/UnknownFieldSet.java +++ b/protobuf-api/src/main/java/com/google/protobuf/UnknownFieldSet.java @@ -109,11 +109,11 @@ public void writeTo(CodedOutputStream output) throws IOException { /** * Converts the set to a string in protocol buffer text format. This is just a trivial wrapper - * around {@link TextFormat.Printer#printToString(UnknownFieldSet)}. + * around {@link TextFormatInternal.printer#printToString(UnknownFieldSet)}. */ @Override public String toString() { - return TextFormat.printer().printToString(this); + return TextFormatInternal.printer().printToString(this); } /** diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/AbstractMessage.java b/protobuf-sdk/src/main/java/com/google/protobuf/AbstractMessage.java index 9c6e207..7b94d47 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/AbstractMessage.java +++ b/protobuf-sdk/src/main/java/com/google/protobuf/AbstractMessage.java @@ -84,7 +84,7 @@ public FieldDescriptor getOneofFieldDescriptor(OneofDescriptor oneof) { @Override public final String toString() { - return TextFormat.printer().printToString(this); + return TextFormatInternal.printer().printToString(this); } @Override @@ -437,7 +437,7 @@ public Message.Builder getRepeatedFieldBuilder(final FieldDescriptor field, int @Override public String toString() { - return TextFormat.printer().printToString(this); + return TextFormatInternal.printer().printToString(this); } /** Construct an UninitializedMessageException reporting missing fields in the given message. */ diff --git a/protobuf-api/src/main/java/com/google/protobuf/TextFormat.java b/protobuf-sdk/src/main/java/com/google/protobuf/TextFormat.java similarity index 88% rename from protobuf-api/src/main/java/com/google/protobuf/TextFormat.java rename to protobuf-sdk/src/main/java/com/google/protobuf/TextFormat.java index a49919e..e0bfdd2 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/TextFormat.java +++ b/protobuf-sdk/src/main/java/com/google/protobuf/TextFormat.java @@ -24,6 +24,8 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import static com.google.protobuf.TextFormatInternal.*; + /** * Provide text parsing and formatting support for proto2 instances. The implementation largely * follows text_format.cc. @@ -2396,176 +2398,11 @@ public static String escapeBytes(byte[] input) { */ public static ByteString unescapeBytes(CharSequence charString) throws InvalidEscapeSequenceException { - // First convert the Java character sequence to UTF-8 bytes. - ByteString input = ByteString.copyFromUtf8(charString.toString()); - // Then unescape certain byte sequences introduced by ASCII '\\'. The valid - // escapes can all be expressed with ASCII characters, so it is safe to - // operate on bytes here. - // - // Unescaping the input byte array will result in a byte sequence that's no - // longer than the input. That's because each escape sequence is between - // two and four bytes long and stands for a single byte. - final byte[] result = new byte[input.size()]; - int pos = 0; - for (int i = 0; i < input.size(); i++) { - byte c = input.byteAt(i); - if (c == '\\') { - if (i + 1 < input.size()) { - ++i; - c = input.byteAt(i); - if (isOctal(c)) { - // Octal escape. - int code = digitValue(c); - if (i + 1 < input.size() && isOctal(input.byteAt(i + 1))) { - ++i; - code = code * 8 + digitValue(input.byteAt(i)); - } - if (i + 1 < input.size() && isOctal(input.byteAt(i + 1))) { - ++i; - code = code * 8 + digitValue(input.byteAt(i)); - } - // TODO: Check that 0 <= code && code <= 0xFF. - result[pos++] = (byte) code; - } else { - switch (c) { - case 'a': - result[pos++] = 0x07; - break; - case 'b': - result[pos++] = '\b'; - break; - case 'f': - result[pos++] = '\f'; - break; - case 'n': - result[pos++] = '\n'; - break; - case 'r': - result[pos++] = '\r'; - break; - case 't': - result[pos++] = '\t'; - break; - case 'v': - result[pos++] = 0x0b; - break; - case '\\': - result[pos++] = '\\'; - break; - case '\'': - result[pos++] = '\''; - break; - case '"': - result[pos++] = '\"'; - break; - case '?': - result[pos++] = '?'; - break; - - case 'x': - // hex escape - int code = 0; - if (i + 1 < input.size() && isHex(input.byteAt(i + 1))) { - ++i; - code = digitValue(input.byteAt(i)); - } else { - throw new InvalidEscapeSequenceException( - "Invalid escape sequence: '\\x' with no digits"); - } - if (i + 1 < input.size() && isHex(input.byteAt(i + 1))) { - ++i; - code = code * 16 + digitValue(input.byteAt(i)); - } - result[pos++] = (byte) code; - break; - - case 'u': - // Unicode escape - ++i; - if (i + 3 < input.size() - && isHex(input.byteAt(i)) - && isHex(input.byteAt(i + 1)) - && isHex(input.byteAt(i + 2)) - && isHex(input.byteAt(i + 3))) { - char ch = - (char) - (digitValue(input.byteAt(i)) << 12 - | digitValue(input.byteAt(i + 1)) << 8 - | digitValue(input.byteAt(i + 2)) << 4 - | digitValue(input.byteAt(i + 3))); - - if (ch >= Character.MIN_SURROGATE && ch <= Character.MAX_SURROGATE) { - throw new InvalidEscapeSequenceException( - "Invalid escape sequence: '\\u' refers to a surrogate"); - } - byte[] chUtf8 = Character.toString(ch).getBytes(Internal.UTF_8); - System.arraycopy(chUtf8, 0, result, pos, chUtf8.length); - pos += chUtf8.length; - i += 3; - } else { - throw new InvalidEscapeSequenceException( - "Invalid escape sequence: '\\u' with too few hex chars"); - } - break; - - case 'U': - // Unicode escape - ++i; - if (i + 7 >= input.size()) { - throw new InvalidEscapeSequenceException( - "Invalid escape sequence: '\\U' with too few hex chars"); - } - int codepoint = 0; - for (int offset = i; offset < i + 8; offset++) { - byte b = input.byteAt(offset); - if (!isHex(b)) { - throw new InvalidEscapeSequenceException( - "Invalid escape sequence: '\\U' with too few hex chars"); - } - codepoint = (codepoint << 4) | digitValue(b); - } - if (!Character.isValidCodePoint(codepoint)) { - throw new InvalidEscapeSequenceException( - "Invalid escape sequence: '\\U" - + input.substring(i, i + 8).toStringUtf8() - + "' is not a valid code point value"); - } - Character.UnicodeBlock unicodeBlock = Character.UnicodeBlock.of(codepoint); - if (unicodeBlock != null - && (unicodeBlock.equals(Character.UnicodeBlock.LOW_SURROGATES) - || unicodeBlock.equals(Character.UnicodeBlock.HIGH_SURROGATES) - || unicodeBlock.equals( - Character.UnicodeBlock.HIGH_PRIVATE_USE_SURROGATES))) { - throw new InvalidEscapeSequenceException( - "Invalid escape sequence: '\\U" - + input.substring(i, i + 8).toStringUtf8() - + "' refers to a surrogate code unit"); - } - int[] codepoints = new int[1]; - codepoints[0] = codepoint; - byte[] chUtf8 = new String(codepoints, 0, 1).getBytes(Internal.UTF_8); - System.arraycopy(chUtf8, 0, result, pos, chUtf8.length); - pos += chUtf8.length; - i += 7; - break; - - default: - throw new InvalidEscapeSequenceException( - "Invalid escape sequence: '\\" + (char) c + '\''); - } - } - } else { - throw new InvalidEscapeSequenceException( - "Invalid escape sequence: '\\' at end of string."); - } - } else { - result[pos++] = c; + try { + return TextFormatEscaper.unescapeBytes(charString); + } catch (TextFormatEscaper.InvalidEscapeSequenceException e) { + throw new TextFormat.InvalidEscapeSequenceException(e.getMessage()); } - } - - return result.length == pos - ? ByteString.wrap(result) // This reference has not been out of our control. - : ByteString.copyFrom(result, 0, pos); } /** @@ -2625,128 +2462,4 @@ private static int digitValue(final byte c) { return c - 'A' + 10; } } - - /** - * Parse a 32-bit signed integer from the text. Unlike the Java standard {@code - * Integer.parseInt()}, this function recognizes the prefixes "0x" and "0" to signify hexadecimal - * and octal numbers, respectively. - */ - static int parseInt32(final String text) throws NumberFormatException { - return (int) parseInteger(text, true, false); - } - - /** - * Parse a 32-bit unsigned integer from the text. Unlike the Java standard {@code - * Integer.parseInt()}, this function recognizes the prefixes "0x" and "0" to signify hexadecimal - * and octal numbers, respectively. The result is coerced to a (signed) {@code int} when returned - * since Java has no unsigned integer type. - */ - static int parseUInt32(final String text) throws NumberFormatException { - return (int) parseInteger(text, false, false); - } - - /** - * Parse a 64-bit signed integer from the text. Unlike the Java standard {@code - * Integer.parseInt()}, this function recognizes the prefixes "0x" and "0" to signify hexadecimal - * and octal numbers, respectively. - */ - static long parseInt64(final String text) throws NumberFormatException { - return parseInteger(text, true, true); - } - - /** - * Parse a 64-bit unsigned integer from the text. Unlike the Java standard {@code - * Integer.parseInt()}, this function recognizes the prefixes "0x" and "0" to signify hexadecimal - * and octal numbers, respectively. The result is coerced to a (signed) {@code long} when returned - * since Java has no unsigned long type. - */ - static long parseUInt64(final String text) throws NumberFormatException { - return parseInteger(text, false, true); - } - - private static long parseInteger(final String text, final boolean isSigned, final boolean isLong) - throws NumberFormatException { - int pos = 0; - - boolean negative = false; - if (text.startsWith("-", pos)) { - if (!isSigned) { - throw new NumberFormatException("Number must be positive: " + text); - } - ++pos; - negative = true; - } - - int radix = 10; - if (text.startsWith("0x", pos)) { - pos += 2; - radix = 16; - } else if (text.startsWith("0", pos)) { - radix = 8; - } - - final String numberText = text.substring(pos); - - long result = 0; - if (numberText.length() < 16) { - // Can safely assume no overflow. - result = Long.parseLong(numberText, radix); - if (negative) { - result = -result; - } - - // Check bounds. - // No need to check for 64-bit numbers since they'd have to be 16 chars - // or longer to overflow. - if (!isLong) { - if (isSigned) { - if (result > Integer.MAX_VALUE || result < Integer.MIN_VALUE) { - throw new NumberFormatException( - "Number out of range for 32-bit signed integer: " + text); - } - } else { - if (result >= (1L << 32) || result < 0) { - throw new NumberFormatException( - "Number out of range for 32-bit unsigned integer: " + text); - } - } - } - } else { - BigInteger bigValue = new BigInteger(numberText, radix); - if (negative) { - bigValue = bigValue.negate(); - } - - // Check bounds. - if (!isLong) { - if (isSigned) { - if (bigValue.bitLength() > 31) { - throw new NumberFormatException( - "Number out of range for 32-bit signed integer: " + text); - } - } else { - if (bigValue.bitLength() > 32) { - throw new NumberFormatException( - "Number out of range for 32-bit unsigned integer: " + text); - } - } - } else { - if (isSigned) { - if (bigValue.bitLength() > 63) { - throw new NumberFormatException( - "Number out of range for 64-bit signed integer: " + text); - } - } else { - if (bigValue.bitLength() > 64) { - throw new NumberFormatException( - "Number out of range for 64-bit unsigned integer: " + text); - } - } - } - - result = bigValue.longValue(); - } - - return result; - } } From ea4b11fba6ff820cc86b718a5a8245501d855805 Mon Sep 17 00:00:00 2001 From: blakeli Date: Tue, 15 Apr 2025 00:15:51 -0400 Subject: [PATCH 23/42] Move TextFormatParseInfoTree.java and TextFormatParseLocation.java to SDK. --- .../main/java/com/google/protobuf/TextFormatParseInfoTree.java | 0 .../main/java/com/google/protobuf/TextFormatParseLocation.java | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename {protobuf-api => protobuf-sdk}/src/main/java/com/google/protobuf/TextFormatParseInfoTree.java (100%) rename {protobuf-api => protobuf-sdk}/src/main/java/com/google/protobuf/TextFormatParseLocation.java (100%) diff --git a/protobuf-api/src/main/java/com/google/protobuf/TextFormatParseInfoTree.java b/protobuf-sdk/src/main/java/com/google/protobuf/TextFormatParseInfoTree.java similarity index 100% rename from protobuf-api/src/main/java/com/google/protobuf/TextFormatParseInfoTree.java rename to protobuf-sdk/src/main/java/com/google/protobuf/TextFormatParseInfoTree.java diff --git a/protobuf-api/src/main/java/com/google/protobuf/TextFormatParseLocation.java b/protobuf-sdk/src/main/java/com/google/protobuf/TextFormatParseLocation.java similarity index 100% rename from protobuf-api/src/main/java/com/google/protobuf/TextFormatParseLocation.java rename to protobuf-sdk/src/main/java/com/google/protobuf/TextFormatParseLocation.java From 86077063374b769866fbee1862470b64493e97b1 Mon Sep 17 00:00:00 2001 From: blakeli Date: Tue, 15 Apr 2025 13:56:56 -0400 Subject: [PATCH 24/42] Revert AbstractMessageLite to public since gencode from a different package would not be able to access it. --- .../src/main/java/com/google/protobuf/AbstractMessageLite.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protobuf-api/src/main/java/com/google/protobuf/AbstractMessageLite.java b/protobuf-api/src/main/java/com/google/protobuf/AbstractMessageLite.java index 838579c..6a9d7ba 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/AbstractMessageLite.java +++ b/protobuf-api/src/main/java/com/google/protobuf/AbstractMessageLite.java @@ -23,7 +23,7 @@ * * @author kenton@google.com Kenton Varda */ -abstract class AbstractMessageLite< +public abstract class AbstractMessageLite< MessageType extends AbstractMessageLite, BuilderType extends AbstractMessageLite.Builder> implements MessageLite { From 83f51287c7a1416e00acc9dc41d9a8b0b6fd898b Mon Sep 17 00:00:00 2001 From: blakeli Date: Fri, 18 Apr 2025 15:06:28 -0400 Subject: [PATCH 25/42] Move classes only used by lite gen code to package private. --- .../src/main/java/com/google/protobuf/GeneratedMessageLite.java | 2 +- .../src/main/java/com/google/protobuf/LazyFieldLite.java | 2 +- .../src/main/java/com/google/protobuf/MapEntryLite.java | 2 +- .../src/main/java/com/google/protobuf/MapFieldLite.java | 2 +- .../src/main/java/com/google/protobuf/UnknownFieldSetLite.java | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/protobuf-api/src/main/java/com/google/protobuf/GeneratedMessageLite.java b/protobuf-api/src/main/java/com/google/protobuf/GeneratedMessageLite.java index c153960..76fbcaa 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/GeneratedMessageLite.java +++ b/protobuf-api/src/main/java/com/google/protobuf/GeneratedMessageLite.java @@ -34,7 +34,7 @@ * * @author kenton@google.com Kenton Varda */ -public abstract class GeneratedMessageLite< +abstract class GeneratedMessageLite< MessageType extends GeneratedMessageLite, BuilderType extends GeneratedMessageLite.Builder> extends AbstractMessageLite { diff --git a/protobuf-api/src/main/java/com/google/protobuf/LazyFieldLite.java b/protobuf-api/src/main/java/com/google/protobuf/LazyFieldLite.java index d5579fe..0ff6398 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/LazyFieldLite.java +++ b/protobuf-api/src/main/java/com/google/protobuf/LazyFieldLite.java @@ -30,7 +30,7 @@ * * @author xiangl@google.com (Xiang Li) */ -public class LazyFieldLite { +class LazyFieldLite { private static final ExtensionRegistryLite EMPTY_REGISTRY = ExtensionRegistryLite.getEmptyRegistry(); diff --git a/protobuf-api/src/main/java/com/google/protobuf/MapEntryLite.java b/protobuf-api/src/main/java/com/google/protobuf/MapEntryLite.java index 99f3460..61b1f65 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/MapEntryLite.java +++ b/protobuf-api/src/main/java/com/google/protobuf/MapEntryLite.java @@ -19,7 +19,7 @@ * *

Protobuf internal. Users shouldn't use. */ -public class MapEntryLite { +class MapEntryLite { static class Metadata { public final WireFormat.FieldType keyType; diff --git a/protobuf-api/src/main/java/com/google/protobuf/MapFieldLite.java b/protobuf-api/src/main/java/com/google/protobuf/MapFieldLite.java index bc5704b..a94825c 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/MapFieldLite.java +++ b/protobuf-api/src/main/java/com/google/protobuf/MapFieldLite.java @@ -21,7 +21,7 @@ * *

This class is a protobuf implementation detail. Users shouldn't use this class directly. */ -public final class MapFieldLite extends LinkedHashMap { +final class MapFieldLite extends LinkedHashMap { private boolean isMutable; diff --git a/protobuf-api/src/main/java/com/google/protobuf/UnknownFieldSetLite.java b/protobuf-api/src/main/java/com/google/protobuf/UnknownFieldSetLite.java index 36c9481..809ac95 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/UnknownFieldSetLite.java +++ b/protobuf-api/src/main/java/com/google/protobuf/UnknownFieldSetLite.java @@ -20,7 +20,7 @@ * * @author dweis@google.com (Daniel Weis) */ -public final class UnknownFieldSetLite { +final class UnknownFieldSetLite { // Arbitrarily chosen. // TODO: Tune this number? From 9aeeb34eae60db4b15d7959f4ea8617107d82f41 Mon Sep 17 00:00:00 2001 From: blakeli Date: Fri, 18 Apr 2025 15:35:17 -0400 Subject: [PATCH 26/42] Make LazyField package private. --- protobuf-api/src/main/java/com/google/protobuf/LazyField.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protobuf-api/src/main/java/com/google/protobuf/LazyField.java b/protobuf-api/src/main/java/com/google/protobuf/LazyField.java index d7dddd9..1ef780c 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/LazyField.java +++ b/protobuf-api/src/main/java/com/google/protobuf/LazyField.java @@ -20,7 +20,7 @@ * * @author xiangl@google.com (Xiang Li) */ -public class LazyField extends LazyFieldLite { +class LazyField extends LazyFieldLite { /** * Carry a message's default instance which is used by {@code hashCode()}, {@code equals()}, and From 081ab2ea9de121b5a70767a52d99fee8bc9e2f1f Mon Sep 17 00:00:00 2001 From: blakeli Date: Fri, 18 Apr 2025 18:09:40 -0400 Subject: [PATCH 27/42] Revert "Move implementation of ByteString to SDK package." This reverts commit be61c929b778c6b58d8c64ac33517a1a263f911b. --- .../java/com/google/protobuf/ByteString.java | 441 +++++++++++++++--- .../com/google/protobuf/NioByteString.java | 2 +- .../com/google/protobuf/RopeByteString.java | 0 .../google/protobuf/BoundedByteString.java | 98 ---- .../com/google/protobuf/LeafByteString.java | 34 -- .../google/protobuf/LiteralByteString.java | 240 ---------- .../com/google/protobuf/java_features.proto | 52 +++ 7 files changed, 420 insertions(+), 447 deletions(-) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/NioByteString.java (99%) rename {protobuf-sdk => protobuf-api}/src/main/java/com/google/protobuf/RopeByteString.java (100%) delete mode 100644 protobuf-sdk/src/main/java/com/google/protobuf/BoundedByteString.java delete mode 100644 protobuf-sdk/src/main/java/com/google/protobuf/LeafByteString.java delete mode 100644 protobuf-sdk/src/main/java/com/google/protobuf/LiteralByteString.java create mode 100644 protobuf-sdk/src/main/java/com/google/protobuf/java_features.proto diff --git a/protobuf-api/src/main/java/com/google/protobuf/ByteString.java b/protobuf-api/src/main/java/com/google/protobuf/ByteString.java index 99823f5..8ba729c 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/ByteString.java +++ b/protobuf-api/src/main/java/com/google/protobuf/ByteString.java @@ -11,21 +11,22 @@ import static java.lang.Integer.toHexString; import static java.lang.System.identityHashCode; +import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; +import java.io.InvalidObjectException; +import java.io.ObjectInputStream; import java.io.OutputStream; import java.io.Serializable; import java.io.UnsupportedEncodingException; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.nio.ByteBuffer; import java.nio.charset.Charset; import java.nio.charset.UnsupportedCharsetException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.Comparator; import java.util.Iterator; import java.util.List; @@ -68,22 +69,8 @@ public abstract class ByteString implements Iterable, Serializable { static final int MAX_READ_FROM_CHUNK_SIZE = 0x2000; // 8k - private static final Class LITERAL_BYTE_STRING = getClassForName("com.google.protobuf.LiteralByteString"); - private static final Class LEAF_BYTE_STRING = getClassForName("com.google.protobuf.LeafByteString"); - private static final Class NIO_BYTE_STRING = getClassForName("com.google.protobuf.NioByteString"); - private static final Class ROPE_BYTE_STRING = getClassForName("com.google.protobuf.RopeByteString"); - private static final Class BOUNDED_BYTE_STRING = getClassForName("com.google.protobuf.BoundedByteString"); - - private static Class getClassForName(String name) { - try { - return (Class) Class.forName(name); - } catch (Throwable e) { - return null; - } - } - /** Empty {@code ByteString}. */ - public static final ByteString EMPTY = newLiteralByteString(Internal.EMPTY_BYTE_ARRAY); + public static final ByteString EMPTY = new LiteralByteString(Internal.EMPTY_BYTE_ARRAY); /** * An interface to efficiently copy {@code byte[]}. @@ -392,21 +379,7 @@ public static ByteString fromHex(@CompileTimeConstant String hexString) { int d2 = extractHexDigit(hexString, 2 * i + 1); bytes[i] = (byte) (d1 << 4 | d2); } - - return newLiteralByteString(bytes); - } - - private static ByteString newLiteralByteString(byte[] bytes) { - try { - Constructor constructor = LITERAL_BYTE_STRING.getDeclaredConstructors()[0]; - return (ByteString) constructor.newInstance(bytes); - } catch (InstantiationException e) { - throw new RuntimeException(e); - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } catch (InvocationTargetException e) { - throw new RuntimeException(e); - } + return new LiteralByteString(bytes); } // ================================================================= @@ -423,7 +396,7 @@ private static ByteString newLiteralByteString(byte[] bytes) { */ public static ByteString copyFrom(byte[] bytes, int offset, int size) { checkRange(offset, offset + size, bytes.length); - return newLiteralByteString(byteArrayCopier.copyFrom(bytes, offset, size)); + return new LiteralByteString(byteArrayCopier.copyFrom(bytes, offset, size)); } /** @@ -445,16 +418,7 @@ static ByteString wrap(ByteBuffer buffer) { final int offset = buffer.arrayOffset(); return ByteString.wrap(buffer.array(), offset + buffer.position(), buffer.remaining()); } else { - try { - Constructor constructor = NIO_BYTE_STRING.getDeclaredConstructors()[0]; - return (ByteString) constructor.newInstance(buffer); - } catch (InstantiationException e) { - throw new RuntimeException(e); - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } catch (InvocationTargetException e) { - throw new RuntimeException(e); - } + return new NioByteString(buffer); } } @@ -464,7 +428,7 @@ static ByteString wrap(ByteBuffer buffer) { */ static ByteString wrap(byte[] bytes) { // TODO: Return EMPTY when bytes are empty to reduce allocations? - return newLiteralByteString(bytes); + return new LiteralByteString(bytes); } /** @@ -472,16 +436,7 @@ static ByteString wrap(byte[] bytes) { * to force a classload of ByteString before BoundedByteString and LiteralByteString. */ static ByteString wrap(byte[] bytes, int offset, int length) { - try { - Constructor constructor = BOUNDED_BYTE_STRING.getDeclaredConstructors()[0]; - return (ByteString) constructor.newInstance(bytes, offset, length); - } catch (InstantiationException e) { - throw new RuntimeException(e); - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } catch (InvocationTargetException e) { - throw new RuntimeException(e); - } + return new BoundedByteString(bytes, offset, length); } /** @@ -497,8 +452,7 @@ public static ByteString copyFrom(ByteBuffer bytes, int size) { checkRange(0, size, bytes.remaining()); byte[] copy = new byte[size]; bytes.get(copy); - return newLiteralByteString(copy); - + return new LiteralByteString(copy); } /** @@ -522,7 +476,7 @@ public static ByteString copyFrom(ByteBuffer bytes) { */ public static ByteString copyFrom(String text, String charsetName) throws UnsupportedEncodingException { - return newLiteralByteString(text.getBytes(charsetName)); + return new LiteralByteString(text.getBytes(charsetName)); } /** @@ -534,7 +488,7 @@ public static ByteString copyFrom(String text, String charsetName) * @return new {@code ByteString} */ public static ByteString copyFrom(String text, Charset charset) { - return newLiteralByteString(text.getBytes(charset)); + return new LiteralByteString(text.getBytes(charset)); } /** @@ -545,7 +499,7 @@ public static ByteString copyFrom(String text, Charset charset) { * @return new {@code ByteString} */ public static ByteString copyFromUtf8(String text) { - return newLiteralByteString(text.getBytes(Internal.UTF_8)); + return new LiteralByteString(text.getBytes(Internal.UTF_8)); } // ================================================================= @@ -669,16 +623,8 @@ public final ByteString concat(ByteString other) { throw new IllegalArgumentException( "ByteString would be too long: " + size() + "+" + other.size()); } - try { - Method concatenateMethod = ROPE_BYTE_STRING.getMethod("concatenate", ByteString.class, ByteString.class); - return (ByteString) concatenateMethod.invoke(null, this, other); - } catch (NoSuchMethodException e) { - throw new RuntimeException(e); - } catch (InvocationTargetException e) { - throw new RuntimeException(e); - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } + + return RopeByteString.concatenate(this, other); } /** @@ -978,6 +924,37 @@ public final String toStringUtf8() { @Override public abstract boolean equals(Object o); + /** Base class for leaf {@link ByteString}s (i.e. non-ropes). */ + abstract static class LeafByteString extends ByteString { + private static final long serialVersionUID = 1L; + + @Override + protected final int getTreeDepth() { + return 0; + } + + @Override + protected final boolean isBalanced() { + return true; + } + + @Override + void writeToReverse(ByteOutput byteOutput) throws IOException { + writeTo(byteOutput); + } + + /** + * Check equality of the substring of given length of this object starting at zero with another + * {@code ByteString} substring starting at offset. + * + * @param other what to compare a substring in + * @param offset offset into other + * @param length number of bytes to compare + * @return true for equality of substrings, else false. + */ + abstract boolean equalsRange(ByteString other, int offset, int length); + } + /** * Compute the hashCode using the traditional algorithm from {@link ByteString}. * @@ -1191,7 +1168,7 @@ public String toString() { * buffer whose size is at least the specified minimum size. */ private void flushFullBuffer(int minSize) { - flushedBuffers.add(newLiteralByteString(buffer)); + flushedBuffers.add(new LiteralByteString(buffer)); flushedBuffersTotalBytes += buffer.length; // We want to increase our total capacity by 50%, but as a minimum, // the new buffer should also at least be >= minSize and @@ -1209,12 +1186,12 @@ private void flushLastBuffer() { if (bufferPos < buffer.length) { if (bufferPos > 0) { byte[] bufferCopy = Arrays.copyOf(buffer, bufferPos); - flushedBuffers.add(newLiteralByteString(bufferCopy)); + flushedBuffers.add(new LiteralByteString(bufferCopy)); } // We reuse this buffer for further writes. } else { // Buffer is completely full. Huzzah. - flushedBuffers.add(newLiteralByteString(buffer)); + flushedBuffers.add(new LiteralByteString(buffer)); // 99% of the time, we're not going to use this OutputStream again. // We set buffer to an empty byte stream so that we're handling this // case without wasting space. In the rare case that more writes @@ -1259,7 +1236,7 @@ public ByteString build() { // We can be confident that the CodedOutputStream will not modify the // underlying bytes anymore because it already wrote all of them. So, // no need to make a copy. - return newLiteralByteString(buffer); + return new LiteralByteString(buffer); } public CodedOutputStream getCodedOutput() { @@ -1366,7 +1343,323 @@ private String truncateAndEscapeForDisplay() { return size() <= limit ? escapeBytes(this) : escapeBytes(substring(0, limit - 3)) + "..."; } + /** + * This class implements a {@link com.google.protobuf.ByteString} backed by a single array of + * bytes, contiguous in memory. It supports substring by pointing to only a sub-range of the + * underlying byte array, meaning that a substring will reference the full byte-array of the + * string it's made from, exactly as with {@link String}. + * + * @author carlanton@google.com (Carl Haverl) + */ + // Keep this class private to avoid deadlocks in classloading across threads as ByteString's + // static initializer loads LiteralByteString and another thread loads LiteralByteString. + private static class LiteralByteString extends ByteString.LeafByteString { + private static final long serialVersionUID = 1L; + + protected final byte[] bytes; + + /** + * Creates a {@code LiteralByteString} backed by the given array, without copying. + * + * @param bytes array to wrap + */ + LiteralByteString(byte[] bytes) { + if (bytes == null) { + throw new NullPointerException(); + } + this.bytes = bytes; + } + + @Override + public byte byteAt(int index) { + // Unlike most methods in this class, this one is a direct implementation + // ignoring the potential offset because we need to do range-checking in the + // substring case anyway. + return bytes[index]; + } + + @Override + byte internalByteAt(int index) { + return bytes[index]; + } + + @Override + public int size() { + return bytes.length; + } + + // ================================================================= + // ByteString -> substring + + @Override + public final ByteString substring(int beginIndex, int endIndex) { + final int length = checkRange(beginIndex, endIndex, size()); + + if (length == 0) { + return ByteString.EMPTY; + } + + return new BoundedByteString(bytes, getOffsetIntoBytes() + beginIndex, length); + } + + // ================================================================= + // ByteString -> byte[] + + @Override + protected void copyToInternal( + byte[] target, int sourceOffset, int targetOffset, int numberToCopy) { + // Optimized form, not for subclasses, since we don't call + // getOffsetIntoBytes() or check the 'numberToCopy' parameter. + // TODO: Is not calling getOffsetIntoBytes really saving that much? + System.arraycopy(bytes, sourceOffset, target, targetOffset, numberToCopy); + } + + @Override + public final void copyTo(ByteBuffer target) { + target.put(bytes, getOffsetIntoBytes(), size()); // Copies bytes + } + + @Override + public final ByteBuffer asReadOnlyByteBuffer() { + return ByteBuffer.wrap(bytes, getOffsetIntoBytes(), size()).asReadOnlyBuffer(); + } + + @Override + public final List asReadOnlyByteBufferList() { + return Collections.singletonList(asReadOnlyByteBuffer()); + } + + @Override + public final void writeTo(OutputStream outputStream) throws IOException { + outputStream.write(toByteArray()); + } + + @Override + final void writeToInternal(OutputStream outputStream, int sourceOffset, int numberToWrite) + throws IOException { + outputStream.write(bytes, getOffsetIntoBytes() + sourceOffset, numberToWrite); + } + + @Override + final void writeTo(ByteOutput output) throws IOException { + output.writeLazy(bytes, getOffsetIntoBytes(), size()); + } + + @Override + protected final String toStringInternal(Charset charset) { + return new String(bytes, getOffsetIntoBytes(), size(), charset); + } + + // ================================================================= + // UTF-8 decoding + + @Override + public final boolean isValidUtf8() { + int offset = getOffsetIntoBytes(); + return Utf8.isValidUtf8(bytes, offset, offset + size()); + } + + @Override + protected final int partialIsValidUtf8(int state, int offset, int length) { + int index = getOffsetIntoBytes() + offset; + return Utf8.partialIsValidUtf8(state, bytes, index, index + length); + } + + // ================================================================= + // equals() and hashCode() + + @Override + public final boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof ByteString)) { + return false; + } + + if (size() != ((ByteString) other).size()) { + return false; + } + if (size() == 0) { + return true; + } + + if (other instanceof LiteralByteString) { + LiteralByteString otherAsLiteral = (LiteralByteString) other; + // If we know the hash codes and they are not equal, we know the byte + // strings are not equal. + int thisHash = peekCachedHashCode(); + int thatHash = otherAsLiteral.peekCachedHashCode(); + if (thisHash != 0 && thatHash != 0 && thisHash != thatHash) { + return false; + } + + return equalsRange((LiteralByteString) other, 0, size()); + } else { + // RopeByteString and NioByteString. + return other.equals(this); + } + } + + /** + * Check equality of the substring of given length of this object starting at zero with another + * {@code LiteralByteString} substring starting at offset. + * + * @param other what to compare a substring in + * @param offset offset into other + * @param length number of bytes to compare + * @return true for equality of substrings, else false. + */ + @Override + final boolean equalsRange(ByteString other, int offset, int length) { + if (length > other.size()) { + throw new IllegalArgumentException("Length too large: " + length + size()); + } + if (offset + length > other.size()) { + throw new IllegalArgumentException( + "Ran off end of other: " + offset + ", " + length + ", " + other.size()); + } + + if (other instanceof LiteralByteString) { + LiteralByteString lbsOther = (LiteralByteString) other; + byte[] thisBytes = bytes; + byte[] otherBytes = lbsOther.bytes; + int thisLimit = getOffsetIntoBytes() + length; + for (int thisIndex = getOffsetIntoBytes(), + otherIndex = lbsOther.getOffsetIntoBytes() + offset; + (thisIndex < thisLimit); + ++thisIndex, ++otherIndex) { + if (thisBytes[thisIndex] != otherBytes[otherIndex]) { + return false; + } + } + return true; + } + + return other.substring(offset, offset + length).equals(substring(0, length)); + } + + @Override + protected final int partialHash(int h, int offset, int length) { + return Internal.partialHash(h, bytes, getOffsetIntoBytes() + offset, length); + } + + // ================================================================= + // Input stream + + @Override + public final InputStream newInput() { + return new ByteArrayInputStream(bytes, getOffsetIntoBytes(), size()); // No copy + } + + @Override + public final CodedInputStream newCodedInput() { + // We trust CodedInputStream not to modify the bytes, or to give anyone + // else access to them. + return CodedInputStream.newInstance( + bytes, getOffsetIntoBytes(), size(), /* bufferIsImmutable= */ true); + } + + // ================================================================= + // Internal methods + + /** + * Offset into {@code bytes[]} to use, non-zero for substrings. + * + * @return always 0 for this class + */ + protected int getOffsetIntoBytes() { + return 0; + } + } + + /** + * This class is used to represent the substring of a {@link ByteString} over a single byte array. + * In terms of the public API of {@link ByteString}, you end up here by calling {@link + * ByteString#copyFrom(byte[])} followed by {@link ByteString#substring(int, int)}. + * + *

This class contains most of the overhead involved in creating a substring from a {@link + * LiteralByteString}. The overhead involves some range-checking and two extra fields. + * + * @author carlanton@google.com (Carl Haverl) + */ + // Keep this class private to avoid deadlocks in classloading across threads as ByteString's + // static initializer loads LiteralByteString and another thread loads BoundedByteString. + private static final class BoundedByteString extends LiteralByteString { + private final int bytesOffset; + private final int bytesLength; + + /** + * Creates a {@code BoundedByteString} backed by the sub-range of given array, without copying. + * + * @param bytes array to wrap + * @param offset index to first byte to use in bytes + * @param length number of bytes to use from bytes + * @throws IllegalArgumentException if {@code offset < 0}, {@code length < 0}, or if {@code + * offset + length > bytes.length}. + */ + BoundedByteString(byte[] bytes, int offset, int length) { + super(bytes); + checkRange(offset, offset + length, bytes.length); + + this.bytesOffset = offset; + this.bytesLength = length; + } + + /** + * Gets the byte at the given index. Throws {@link ArrayIndexOutOfBoundsException} for + * backwards-compatibility reasons although it would more properly be {@link + * IndexOutOfBoundsException}. + * + * @param index index of byte + * @return the value + * @throws ArrayIndexOutOfBoundsException {@code index} is < 0 or >= size + */ + @Override + public byte byteAt(int index) { + // We must check the index ourselves as we cannot rely on Java array index + // checking for substrings. + checkIndex(index, size()); + return bytes[bytesOffset + index]; + } + + @Override + byte internalByteAt(int index) { + return bytes[bytesOffset + index]; + } + @Override + public int size() { + return bytesLength; + } + @Override + protected int getOffsetIntoBytes() { + return bytesOffset; + } + // ================================================================= + // ByteString -> byte[] + + @Override + protected void copyToInternal( + byte[] target, int sourceOffset, int targetOffset, int numberToCopy) { + System.arraycopy( + bytes, getOffsetIntoBytes() + sourceOffset, target, targetOffset, numberToCopy); + } + + // ================================================================= + // Serializable + + private static final long serialVersionUID = 1L; + + Object writeReplace() { + return ByteString.wrap(toByteArray()); + } + + private void readObject(@SuppressWarnings("unused") ObjectInputStream in) throws IOException { + throw new InvalidObjectException( + "BoundedByteStream instances are not to be serialized directly"); + } + } } diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/NioByteString.java b/protobuf-api/src/main/java/com/google/protobuf/NioByteString.java similarity index 99% rename from protobuf-sdk/src/main/java/com/google/protobuf/NioByteString.java rename to protobuf-api/src/main/java/com/google/protobuf/NioByteString.java index 110ed5f..56c0de9 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/NioByteString.java +++ b/protobuf-api/src/main/java/com/google/protobuf/NioByteString.java @@ -22,7 +22,7 @@ import java.util.List; /** A {@link ByteString} that wraps around a {@link ByteBuffer}. */ -final class NioByteString extends LeafByteString { +final class NioByteString extends ByteString.LeafByteString { private final ByteBuffer buffer; NioByteString(ByteBuffer buffer) { diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/RopeByteString.java b/protobuf-api/src/main/java/com/google/protobuf/RopeByteString.java similarity index 100% rename from protobuf-sdk/src/main/java/com/google/protobuf/RopeByteString.java rename to protobuf-api/src/main/java/com/google/protobuf/RopeByteString.java diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/BoundedByteString.java b/protobuf-sdk/src/main/java/com/google/protobuf/BoundedByteString.java deleted file mode 100644 index 9da632d..0000000 --- a/protobuf-sdk/src/main/java/com/google/protobuf/BoundedByteString.java +++ /dev/null @@ -1,98 +0,0 @@ -package com.google.protobuf; - -import java.io.IOException; -import java.io.InvalidObjectException; -import java.io.ObjectInputStream; - -import static com.google.protobuf.ByteString.checkIndex; -import static com.google.protobuf.ByteString.checkRange; - -/** - * This class is used to represent the substring of a {@link ByteString} over a single byte array. - * In terms of the public API of {@link ByteString}, you end up here by calling {@link - * ByteString#copyFrom(byte[])} followed by {@link ByteString#substring(int, int)}. - * - *

This class contains most of the overhead involved in creating a substring from a {@link - * LiteralByteString}. The overhead involves some range-checking and two extra fields. - * - * @author carlanton@google.com (Carl Haverl) - */ -// Keep this class private to avoid deadlocks in classloading across threads as ByteString's -// static initializer loads LiteralByteString and another thread loads BoundedByteString. -final class BoundedByteString extends LiteralByteString { - private final int bytesOffset; - private final int bytesLength; - - /** - * Creates a {@code BoundedByteString} backed by the sub-range of given array, without copying. - * - * @param bytes array to wrap - * @param offset index to first byte to use in bytes - * @param length number of bytes to use from bytes - * @throws IllegalArgumentException if {@code offset < 0}, {@code length < 0}, or if {@code - * offset + length > bytes.length}. - */ - BoundedByteString(byte[] bytes, int offset, int length) { - super(bytes); - checkRange(offset, offset + length, bytes.length); - - this.bytesOffset = offset; - this.bytesLength = length; - } - - /** - * Gets the byte at the given index. Throws {@link ArrayIndexOutOfBoundsException} for - * backwards-compatibility reasons although it would more properly be {@link - * IndexOutOfBoundsException}. - * - * @param index index of byte - * @return the value - * @throws ArrayIndexOutOfBoundsException {@code index} is < 0 or >= size - */ - @Override - public byte byteAt(int index) { - // We must check the index ourselves as we cannot rely on Java array index - // checking for substrings. - checkIndex(index, size()); - return bytes[bytesOffset + index]; - } - - @Override - byte internalByteAt(int index) { - return bytes[bytesOffset + index]; - } - - @Override - public int size() { - return bytesLength; - } - - @Override - protected int getOffsetIntoBytes() { - return bytesOffset; - } - - // ================================================================= - // ByteString -> byte[] - - @Override - protected void copyToInternal( - byte[] target, int sourceOffset, int targetOffset, int numberToCopy) { - System.arraycopy( - bytes, getOffsetIntoBytes() + sourceOffset, target, targetOffset, numberToCopy); - } - - // ================================================================= - // Serializable - - private static final long serialVersionUID = 1L; - - Object writeReplace() { - return ByteString.wrap(toByteArray()); - } - - private void readObject(@SuppressWarnings("unused") ObjectInputStream in) throws IOException { - throw new InvalidObjectException( - "BoundedByteStream instances are not to be serialized directly"); - } -} \ No newline at end of file diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/LeafByteString.java b/protobuf-sdk/src/main/java/com/google/protobuf/LeafByteString.java deleted file mode 100644 index 2f70f6e..0000000 --- a/protobuf-sdk/src/main/java/com/google/protobuf/LeafByteString.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.google.protobuf; - -import java.io.IOException; - -/** Base class for leaf {@link ByteString}s (i.e. non-ropes). */ -abstract class LeafByteString extends ByteString { - private static final long serialVersionUID = 1L; - - @Override - protected final int getTreeDepth() { - return 0; - } - - @Override - protected final boolean isBalanced() { - return true; - } - - @Override - void writeToReverse(ByteOutput byteOutput) throws IOException { - writeTo(byteOutput); - } - - /** - * Check equality of the substring of given length of this object starting at zero with another - * {@code ByteString} substring starting at offset. - * - * @param other what to compare a substring in - * @param offset offset into other - * @param length number of bytes to compare - * @return true for equality of substrings, else false. - */ - abstract boolean equalsRange(ByteString other, int offset, int length); -} \ No newline at end of file diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/LiteralByteString.java b/protobuf-sdk/src/main/java/com/google/protobuf/LiteralByteString.java deleted file mode 100644 index 5872e29..0000000 --- a/protobuf-sdk/src/main/java/com/google/protobuf/LiteralByteString.java +++ /dev/null @@ -1,240 +0,0 @@ -package com.google.protobuf; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.nio.ByteBuffer; -import java.nio.charset.Charset; -import java.util.Collections; -import java.util.List; - -/** - * This class implements a {@link com.google.protobuf.ByteString} backed by a single array of - * bytes, contiguous in memory. It supports substring by pointing to only a sub-range of the - * underlying byte array, meaning that a substring will reference the full byte-array of the - * string it's made from, exactly as with {@link String}. - * - * @author carlanton@google.com (Carl Haverl) - */ -// Keep this class private to avoid deadlocks in classloading across threads as ByteString's -// static initializer loads LiteralByteString and another thread loads LiteralByteString. -class LiteralByteString extends LeafByteString { - private static final long serialVersionUID = 1L; - - protected final byte[] bytes; - - /** - * Creates a {@code LiteralByteString} backed by the given array, without copying. - * - * @param bytes array to wrap - */ - LiteralByteString(byte[] bytes) { - if (bytes == null) { - throw new NullPointerException(); - } - this.bytes = bytes; - } - - @Override - public byte byteAt(int index) { - // Unlike most methods in this class, this one is a direct implementation - // ignoring the potential offset because we need to do range-checking in the - // substring case anyway. - return bytes[index]; - } - - @Override - byte internalByteAt(int index) { - return bytes[index]; - } - - @Override - public int size() { - return bytes.length; - } - - // ================================================================= - // ByteString -> substring - - @Override - public final ByteString substring(int beginIndex, int endIndex) { - final int length = checkRange(beginIndex, endIndex, size()); - - if (length == 0) { - return ByteString.EMPTY; - } - - return new BoundedByteString(bytes, getOffsetIntoBytes() + beginIndex, length); - } - - // ================================================================= - // ByteString -> byte[] - - @Override - protected void copyToInternal( - byte[] target, int sourceOffset, int targetOffset, int numberToCopy) { - // Optimized form, not for subclasses, since we don't call - // getOffsetIntoBytes() or check the 'numberToCopy' parameter. - // TODO: Is not calling getOffsetIntoBytes really saving that much? - System.arraycopy(bytes, sourceOffset, target, targetOffset, numberToCopy); - } - - @Override - public final void copyTo(ByteBuffer target) { - target.put(bytes, getOffsetIntoBytes(), size()); // Copies bytes - } - - @Override - public final ByteBuffer asReadOnlyByteBuffer() { - return ByteBuffer.wrap(bytes, getOffsetIntoBytes(), size()).asReadOnlyBuffer(); - } - - @Override - public final List asReadOnlyByteBufferList() { - return Collections.singletonList(asReadOnlyByteBuffer()); - } - - @Override - public final void writeTo(OutputStream outputStream) throws IOException { - outputStream.write(toByteArray()); - } - - @Override - final void writeToInternal(OutputStream outputStream, int sourceOffset, int numberToWrite) - throws IOException { - outputStream.write(bytes, getOffsetIntoBytes() + sourceOffset, numberToWrite); - } - - @Override - final void writeTo(ByteOutput output) throws IOException { - output.writeLazy(bytes, getOffsetIntoBytes(), size()); - } - - @Override - protected final String toStringInternal(Charset charset) { - return new String(bytes, getOffsetIntoBytes(), size(), charset); - } - - // ================================================================= - // UTF-8 decoding - - @Override - public final boolean isValidUtf8() { - int offset = getOffsetIntoBytes(); - return Utf8.isValidUtf8(bytes, offset, offset + size()); - } - - @Override - protected final int partialIsValidUtf8(int state, int offset, int length) { - int index = getOffsetIntoBytes() + offset; - return Utf8.partialIsValidUtf8(state, bytes, index, index + length); - } - - // ================================================================= - // equals() and hashCode() - - @Override - public final boolean equals(Object other) { - if (other == this) { - return true; - } - if (!(other instanceof ByteString)) { - return false; - } - - if (size() != ((ByteString) other).size()) { - return false; - } - if (size() == 0) { - return true; - } - - if (other instanceof LiteralByteString) { - LiteralByteString otherAsLiteral = (LiteralByteString) other; - // If we know the hash codes and they are not equal, we know the byte - // strings are not equal. - int thisHash = peekCachedHashCode(); - int thatHash = otherAsLiteral.peekCachedHashCode(); - if (thisHash != 0 && thatHash != 0 && thisHash != thatHash) { - return false; - } - - return equalsRange((LiteralByteString) other, 0, size()); - } else { - // RopeByteString and NioByteString. - return other.equals(this); - } - } - - /** - * Check equality of the substring of given length of this object starting at zero with another - * {@code LiteralByteString} substring starting at offset. - * - * @param other what to compare a substring in - * @param offset offset into other - * @param length number of bytes to compare - * @return true for equality of substrings, else false. - */ - @Override - final boolean equalsRange(ByteString other, int offset, int length) { - if (length > other.size()) { - throw new IllegalArgumentException("Length too large: " + length + size()); - } - if (offset + length > other.size()) { - throw new IllegalArgumentException( - "Ran off end of other: " + offset + ", " + length + ", " + other.size()); - } - - if (other instanceof LiteralByteString) { - LiteralByteString lbsOther = (LiteralByteString) other; - byte[] thisBytes = bytes; - byte[] otherBytes = lbsOther.bytes; - int thisLimit = getOffsetIntoBytes() + length; - for (int thisIndex = getOffsetIntoBytes(), - otherIndex = lbsOther.getOffsetIntoBytes() + offset; - (thisIndex < thisLimit); - ++thisIndex, ++otherIndex) { - if (thisBytes[thisIndex] != otherBytes[otherIndex]) { - return false; - } - } - return true; - } - - return other.substring(offset, offset + length).equals(substring(0, length)); - } - - @Override - protected final int partialHash(int h, int offset, int length) { - return Internal.partialHash(h, bytes, getOffsetIntoBytes() + offset, length); - } - - // ================================================================= - // Input stream - - @Override - public final InputStream newInput() { - return new ByteArrayInputStream(bytes, getOffsetIntoBytes(), size()); // No copy - } - - @Override - public final CodedInputStream newCodedInput() { - // We trust CodedInputStream not to modify the bytes, or to give anyone - // else access to them. - return CodedInputStream.newInstance( - bytes, getOffsetIntoBytes(), size(), /* bufferIsImmutable= */ true); - } - - // ================================================================= - // Internal methods - - /** - * Offset into {@code bytes[]} to use, non-zero for substrings. - * - * @return always 0 for this class - */ - protected int getOffsetIntoBytes() { - return 0; - } -} diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/java_features.proto b/protobuf-sdk/src/main/java/com/google/protobuf/java_features.proto new file mode 100644 index 0000000..d02d067 --- /dev/null +++ b/protobuf-sdk/src/main/java/com/google/protobuf/java_features.proto @@ -0,0 +1,52 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2023 Google Inc. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd + +syntax = "proto2"; + +package pb; + +import "google/protobuf/descriptor.proto"; + +option java_package = "com.google.protobuf"; +option java_outer_classname = "JavaFeaturesProto"; + +extend google.protobuf.FeatureSet { + optional JavaFeatures java = 1001; +} + +message JavaFeatures { + // Whether or not to treat an enum field as closed. This option is only + // applicable to enum fields, and will be removed in the future. It is + // consistent with the legacy behavior of using proto3 enum types for proto2 + // fields. + optional bool legacy_closed_enum = 1 [ + retention = RETENTION_RUNTIME, + targets = TARGET_TYPE_FIELD, + targets = TARGET_TYPE_FILE, + edition_defaults = { edition: EDITION_PROTO2, value: "true" }, + edition_defaults = { edition: EDITION_PROTO3, value: "false" } + ]; + + // The UTF8 validation strategy to use. See go/editions-utf8-validation for + // more information on this feature. + enum Utf8Validation { + // Invalid default, which should never be used. + UTF8_VALIDATION_UNKNOWN = 0; + // Respect the UTF8 validation behavior specified by the global + // utf8_validation feature. + DEFAULT = 1; + // Verifies UTF8 validity overriding the global utf8_validation + // feature. This represents the legacy java_string_check_utf8 option. + VERIFY = 2; + } + optional Utf8Validation utf8_validation = 2 [ + retention = RETENTION_RUNTIME, + targets = TARGET_TYPE_FIELD, + targets = TARGET_TYPE_FILE, + edition_defaults = { edition: EDITION_PROTO2, value: "DEFAULT" } + ]; +} From 3b35f92357fe4a3496856f1c5c0fe6da536f6c1b Mon Sep 17 00:00:00 2001 From: blakeli Date: Fri, 18 Apr 2025 18:18:42 -0400 Subject: [PATCH 28/42] Revert "Move implementation of CodedInputStream to SDK package." This reverts commit bef8090fa53a265d41a329a23627aea2277a9c6c. --- .../com/google/protobuf/CodedInputStream.java | 3388 ++++++++++++++++- .../google/protobuf/CodedOutputStream.java | 1 + .../com/google/protobuf/ArrayDecoder.java | 672 ---- .../IterableDirectByteBufferDecoder.java | 835 ---- .../com/google/protobuf/StreamDecoder.java | 1106 ------ .../protobuf/UnsafeDirectNioDecoder.java | 737 ---- 6 files changed, 3327 insertions(+), 3412 deletions(-) delete mode 100644 protobuf-sdk/src/main/java/com/google/protobuf/ArrayDecoder.java delete mode 100644 protobuf-sdk/src/main/java/com/google/protobuf/IterableDirectByteBufferDecoder.java delete mode 100644 protobuf-sdk/src/main/java/com/google/protobuf/StreamDecoder.java delete mode 100644 protobuf-sdk/src/main/java/com/google/protobuf/UnsafeDirectNioDecoder.java diff --git a/protobuf-api/src/main/java/com/google/protobuf/CodedInputStream.java b/protobuf-api/src/main/java/com/google/protobuf/CodedInputStream.java index ae4ad1c..fd29913 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/CodedInputStream.java +++ b/protobuf-api/src/main/java/com/google/protobuf/CodedInputStream.java @@ -8,13 +8,22 @@ package com.google.protobuf; import static com.google.protobuf.Internal.EMPTY_BYTE_ARRAY; +import static com.google.protobuf.Internal.EMPTY_BYTE_BUFFER; +import static com.google.protobuf.Internal.UTF_8; import static com.google.protobuf.Internal.checkNotNull; +import static com.google.protobuf.WireFormat.FIXED32_SIZE; +import static com.google.protobuf.WireFormat.FIXED64_SIZE; +import static com.google.protobuf.WireFormat.MAX_VARINT_SIZE; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; +import java.nio.Buffer; import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; /** * Reads and decodes protocol message fields. @@ -28,24 +37,11 @@ * @author kenton@google.com Kenton Varda */ public abstract class CodedInputStream { - static final int DEFAULT_BUFFER_SIZE = 4096; + private static final int DEFAULT_BUFFER_SIZE = 4096; // Integer.MAX_VALUE == 0x7FFFFFF == INT_MAX from limits.h private static final int DEFAULT_SIZE_LIMIT = Integer.MAX_VALUE; private static volatile int defaultRecursionLimit = 100; - private static final Class ARRAY_DECODER = getClassForName("com.google.protobuf.ArrayDecoder"); - private static final Class ITERABLE_DIRECT_BYTE_BUFFER_DECODER = getClassForName("com.google.protobuf.IterableDirectByteBufferDecoder"); - private static final Class STREAM_DECODER = getClassForName("com.google.protobuf.StreamDecoder"); - private static final Class UNSAFE_DIRECT_NIO_DECODER = getClassForName("com.google.protobuf.UnsafeDirectNioDecoder"); - - private static Class getClassForName(String name) { - try { - return (Class) Class.forName(name); - } catch (Throwable e) { - return null; - } - } - /** Visible for subclasses. See setRecursionLimit() */ int recursionDepth; @@ -71,21 +67,12 @@ public static CodedInputStream newInstance(final InputStream input, int bufferSi // Ideally we would throw here. This is done for backward compatibility. return newInstance(EMPTY_BYTE_ARRAY); } - try { - Constructor constructor = STREAM_DECODER.getDeclaredConstructors()[0]; - return (CodedInputStream) constructor.newInstance(input, bufferSize); - } catch (InstantiationException e) { - throw new RuntimeException(e); - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } catch (InvocationTargetException e) { - throw new RuntimeException(e); - } + return new StreamDecoder(input, bufferSize); } /** Create a new CodedInputStream wrapping the given {@code Iterable }. */ public static CodedInputStream newInstance(final Iterable input) { - if (!UnsafeUtil.hasUnsafeByteBufferOperations()) { + if (!UnsafeDirectNioDecoder.isSupported()) { return newInstance(new IterableByteBufferInputStream(input)); } return newInstance(input, false); @@ -113,16 +100,7 @@ static CodedInputStream newInstance( } } if (flag == 2) { - try { - Constructor constructor = ITERABLE_DIRECT_BYTE_BUFFER_DECODER.getDeclaredConstructors()[0]; - return (CodedInputStream) constructor.newInstance(bufs, totalSize, bufferIsImmutable); - } catch (InstantiationException e) { - throw new RuntimeException(e); - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } catch (InvocationTargetException e) { - throw new RuntimeException(e); - } + return new IterableDirectByteBufferDecoder(bufs, totalSize, bufferIsImmutable); } else { // TODO: add another decoders to deal case 1 and 3. return newInstance(new IterableByteBufferInputStream(bufs)); @@ -142,24 +120,14 @@ public static CodedInputStream newInstance(final byte[] buf, final int off, fina /** Create a new CodedInputStream wrapping the given byte array slice. */ static CodedInputStream newInstance( final byte[] buf, final int off, final int len, final boolean bufferIsImmutable) { - CodedInputStream arrayDecoder; - try { - Constructor constructor = ARRAY_DECODER.getDeclaredConstructors()[0]; - arrayDecoder = (CodedInputStream) constructor.newInstance(buf, off, len, bufferIsImmutable); - } catch (InstantiationException e) { - throw new RuntimeException(e); - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } catch (InvocationTargetException e) { - throw new RuntimeException(e); - } + ArrayDecoder result = new ArrayDecoder(buf, off, len, bufferIsImmutable); try { // Some uses of CodedInputStream can be more efficient if they know // exactly how many bytes are available. By pushing the end point of the // buffer as a limit, we allow them to get this information via // getBytesUntilLimit(). Pushing a limit that we know is at the end of // the stream can never hurt, since we can never past that point anyway. - arrayDecoder.pushLimit(len); + result.pushLimit(len); } catch (InvalidProtocolBufferException ex) { // The only reason pushLimit() might throw an exception here is if len // is negative. Normally pushLimit()'s parameter comes directly off the @@ -170,7 +138,7 @@ static CodedInputStream newInstance( // appropriate. throw new IllegalArgumentException(ex); } - return arrayDecoder; + return result; } /** @@ -192,17 +160,8 @@ static CodedInputStream newInstance(ByteBuffer buf, boolean bufferIsImmutable) { buf.array(), buf.arrayOffset() + buf.position(), buf.remaining(), bufferIsImmutable); } - if (buf.isDirect() && UnsafeUtil.hasUnsafeByteBufferOperations()) { - try { - Constructor constructor = UNSAFE_DIRECT_NIO_DECODER.getDeclaredConstructors()[0]; - return (CodedInputStream) constructor.newInstance(buf, bufferIsImmutable); - } catch (InstantiationException e) { - throw new RuntimeException(e); - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } catch (InvocationTargetException e) { - throw new RuntimeException(e); - } + if (buf.isDirect() && UnsafeDirectNioDecoder.isSupported()) { + return new UnsafeDirectNioDecoder(buf, bufferIsImmutable); } // The buffer is non-direct and does not expose the underlying array. Using the ByteBuffer API @@ -219,7 +178,7 @@ public void checkRecursionLimit() throws InvalidProtocolBufferException { } } /** Disable construction/inheritance outside of this class. */ - CodedInputStream() {} + private CodedInputStream() {} // ----------------------------------------------------------------- @@ -639,4 +598,3309 @@ static int readRawVarint32(final InputStream input) throws IOException { } return readRawVarint32(firstByte, input); } + + /** A {@link CodedInputStream} implementation that uses a backing array as the input. */ + private static final class ArrayDecoder extends CodedInputStream { + private final byte[] buffer; + private final boolean immutable; + private int limit; + private int bufferSizeAfterLimit; + private int pos; + private int startPos; + private int lastTag; + private boolean enableAliasing; + + /** The absolute position of the end of the current message. */ + private int currentLimit = Integer.MAX_VALUE; + + private ArrayDecoder(final byte[] buffer, final int offset, final int len, boolean immutable) { + this.buffer = buffer; + limit = offset + len; + pos = offset; + startPos = pos; + this.immutable = immutable; + } + + @Override + public int readTag() throws IOException { + if (isAtEnd()) { + lastTag = 0; + return 0; + } + + lastTag = readRawVarint32(); + if (WireFormat.getTagFieldNumber(lastTag) == 0) { + // If we actually read zero (or any tag number corresponding to field + // number zero), that's not a valid tag. + throw InvalidProtocolBufferException.invalidTag(); + } + return lastTag; + } + + @Override + public void checkLastTagWas(final int value) throws InvalidProtocolBufferException { + if (lastTag != value) { + throw InvalidProtocolBufferException.invalidEndTag(); + } + } + + @Override + public int getLastTag() { + return lastTag; + } + + @Override + public boolean skipField(final int tag) throws IOException { + switch (WireFormat.getTagWireType(tag)) { + case WireFormat.WIRETYPE_VARINT: + skipRawVarint(); + return true; + case WireFormat.WIRETYPE_FIXED64: + skipRawBytes(FIXED64_SIZE); + return true; + case WireFormat.WIRETYPE_LENGTH_DELIMITED: + skipRawBytes(readRawVarint32()); + return true; + case WireFormat.WIRETYPE_START_GROUP: + skipMessage(); + checkLastTagWas( + WireFormat.makeTag(WireFormat.getTagFieldNumber(tag), WireFormat.WIRETYPE_END_GROUP)); + return true; + case WireFormat.WIRETYPE_END_GROUP: + return false; + case WireFormat.WIRETYPE_FIXED32: + skipRawBytes(FIXED32_SIZE); + return true; + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + + @Override + public boolean skipField(final int tag, final CodedOutputStream output) throws IOException { + switch (WireFormat.getTagWireType(tag)) { + case WireFormat.WIRETYPE_VARINT: + { + long value = readInt64(); + output.writeUInt32NoTag(tag); + output.writeUInt64NoTag(value); + return true; + } + case WireFormat.WIRETYPE_FIXED64: + { + long value = readRawLittleEndian64(); + output.writeUInt32NoTag(tag); + output.writeFixed64NoTag(value); + return true; + } + case WireFormat.WIRETYPE_LENGTH_DELIMITED: + { + ByteString value = readBytes(); + output.writeUInt32NoTag(tag); + output.writeBytesNoTag(value); + return true; + } + case WireFormat.WIRETYPE_START_GROUP: + { + output.writeUInt32NoTag(tag); + skipMessage(output); + int endtag = + WireFormat.makeTag( + WireFormat.getTagFieldNumber(tag), WireFormat.WIRETYPE_END_GROUP); + checkLastTagWas(endtag); + output.writeUInt32NoTag(endtag); + return true; + } + case WireFormat.WIRETYPE_END_GROUP: + { + return false; + } + case WireFormat.WIRETYPE_FIXED32: + { + int value = readRawLittleEndian32(); + output.writeUInt32NoTag(tag); + output.writeFixed32NoTag(value); + return true; + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + + // ----------------------------------------------------------------- + + @Override + public double readDouble() throws IOException { + return Double.longBitsToDouble(readRawLittleEndian64()); + } + + @Override + public float readFloat() throws IOException { + return Float.intBitsToFloat(readRawLittleEndian32()); + } + + @Override + public long readUInt64() throws IOException { + return readRawVarint64(); + } + + @Override + public long readInt64() throws IOException { + return readRawVarint64(); + } + + @Override + public int readInt32() throws IOException { + return readRawVarint32(); + } + + @Override + public long readFixed64() throws IOException { + return readRawLittleEndian64(); + } + + @Override + public int readFixed32() throws IOException { + return readRawLittleEndian32(); + } + + @Override + public boolean readBool() throws IOException { + return readRawVarint64() != 0; + } + + @Override + public String readString() throws IOException { + final int size = readRawVarint32(); + if (size > 0 && size <= (limit - pos)) { + // Fast path: We already have the bytes in a contiguous buffer, so + // just copy directly from it. + final String result = new String(buffer, pos, size, UTF_8); + pos += size; + return result; + } + + if (size == 0) { + return ""; + } + if (size < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + throw InvalidProtocolBufferException.truncatedMessage(); + } + + @Override + public String readStringRequireUtf8() throws IOException { + final int size = readRawVarint32(); + if (size > 0 && size <= (limit - pos)) { + String result = Utf8.decodeUtf8(buffer, pos, size); + pos += size; + return result; + } + + if (size == 0) { + return ""; + } + if (size <= 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + throw InvalidProtocolBufferException.truncatedMessage(); + } + + @Override + public void readGroup( + final int fieldNumber, + final MessageLite.Builder builder, + final ExtensionRegistryLite extensionRegistry) + throws IOException { + checkRecursionLimit(); + ++recursionDepth; + builder.mergeFrom(this, extensionRegistry); + checkLastTagWas(WireFormat.makeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP)); + --recursionDepth; + } + + @Override + public T readGroup( + final int fieldNumber, + final Parser parser, + final ExtensionRegistryLite extensionRegistry) + throws IOException { + checkRecursionLimit(); + ++recursionDepth; + T result = parser.parsePartialFrom(this, extensionRegistry); + checkLastTagWas(WireFormat.makeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP)); + --recursionDepth; + return result; + } + + @Deprecated + @Override + public void readUnknownGroup(final int fieldNumber, final MessageLite.Builder builder) + throws IOException { + readGroup(fieldNumber, builder, ExtensionRegistryLite.getEmptyRegistry()); + } + + @Override + public void readMessage( + final MessageLite.Builder builder, final ExtensionRegistryLite extensionRegistry) + throws IOException { + final int length = readRawVarint32(); + checkRecursionLimit(); + final int oldLimit = pushLimit(length); + ++recursionDepth; + builder.mergeFrom(this, extensionRegistry); + checkLastTagWas(0); + --recursionDepth; + if (getBytesUntilLimit() != 0) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + popLimit(oldLimit); + } + + @Override + public T readMessage( + final Parser parser, final ExtensionRegistryLite extensionRegistry) throws IOException { + int length = readRawVarint32(); + checkRecursionLimit(); + final int oldLimit = pushLimit(length); + ++recursionDepth; + T result = parser.parsePartialFrom(this, extensionRegistry); + checkLastTagWas(0); + --recursionDepth; + if (getBytesUntilLimit() != 0) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + popLimit(oldLimit); + return result; + } + + @Override + public ByteString readBytes() throws IOException { + final int size = readRawVarint32(); + if (size > 0 && size <= (limit - pos)) { + // Fast path: We already have the bytes in a contiguous buffer, so + // just copy directly from it. + final ByteString result = + immutable && enableAliasing + ? ByteString.wrap(buffer, pos, size) + : ByteString.copyFrom(buffer, pos, size); + pos += size; + return result; + } + if (size == 0) { + return ByteString.EMPTY; + } + // Slow path: Build a byte array first then copy it. + return ByteString.wrap(readRawBytes(size)); + } + + @Override + public byte[] readByteArray() throws IOException { + final int size = readRawVarint32(); + return readRawBytes(size); + } + + @Override + public ByteBuffer readByteBuffer() throws IOException { + final int size = readRawVarint32(); + if (size > 0 && size <= (limit - pos)) { + // Fast path: We already have the bytes in a contiguous buffer. + // When aliasing is enabled, we can return a ByteBuffer pointing directly + // into the underlying byte array without copy if the CodedInputStream is + // constructed from a byte array. If aliasing is disabled or the input is + // from an InputStream or ByteString, we have to make a copy of the bytes. + ByteBuffer result = + !immutable && enableAliasing + ? ByteBuffer.wrap(buffer, pos, size).slice() + : ByteBuffer.wrap(Arrays.copyOfRange(buffer, pos, pos + size)); + pos += size; + // TODO: Investigate making the ByteBuffer be made read-only + return result; + } + + if (size == 0) { + return EMPTY_BYTE_BUFFER; + } + if (size < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + throw InvalidProtocolBufferException.truncatedMessage(); + } + + @Override + public int readUInt32() throws IOException { + return readRawVarint32(); + } + + @Override + public int readEnum() throws IOException { + return readRawVarint32(); + } + + @Override + public int readSFixed32() throws IOException { + return readRawLittleEndian32(); + } + + @Override + public long readSFixed64() throws IOException { + return readRawLittleEndian64(); + } + + @Override + public int readSInt32() throws IOException { + return decodeZigZag32(readRawVarint32()); + } + + @Override + public long readSInt64() throws IOException { + return decodeZigZag64(readRawVarint64()); + } + + // ================================================================= + + @Override + public int readRawVarint32() throws IOException { + // See implementation notes for readRawVarint64 + fastpath: + { + int tempPos = pos; + + if (limit == tempPos) { + break fastpath; + } + + final byte[] buffer = this.buffer; + int x; + if ((x = buffer[tempPos++]) >= 0) { + pos = tempPos; + return x; + } else if (limit - tempPos < 9) { + break fastpath; + } else if ((x ^= (buffer[tempPos++] << 7)) < 0) { + x ^= (~0 << 7); + } else if ((x ^= (buffer[tempPos++] << 14)) >= 0) { + x ^= (~0 << 7) ^ (~0 << 14); + } else if ((x ^= (buffer[tempPos++] << 21)) < 0) { + x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21); + } else { + int y = buffer[tempPos++]; + x ^= y << 28; + x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21) ^ (~0 << 28); + if (y < 0 + && buffer[tempPos++] < 0 + && buffer[tempPos++] < 0 + && buffer[tempPos++] < 0 + && buffer[tempPos++] < 0 + && buffer[tempPos++] < 0) { + break fastpath; // Will throw malformedVarint() + } + } + pos = tempPos; + return x; + } + return (int) readRawVarint64SlowPath(); + } + + private void skipRawVarint() throws IOException { + if (limit - pos >= MAX_VARINT_SIZE) { + skipRawVarintFastPath(); + } else { + skipRawVarintSlowPath(); + } + } + + private void skipRawVarintFastPath() throws IOException { + for (int i = 0; i < MAX_VARINT_SIZE; i++) { + if (buffer[pos++] >= 0) { + return; + } + } + throw InvalidProtocolBufferException.malformedVarint(); + } + + private void skipRawVarintSlowPath() throws IOException { + for (int i = 0; i < MAX_VARINT_SIZE; i++) { + if (readRawByte() >= 0) { + return; + } + } + throw InvalidProtocolBufferException.malformedVarint(); + } + + @Override + public long readRawVarint64() throws IOException { + // Implementation notes: + // + // Optimized for one-byte values, expected to be common. + // The particular code below was selected from various candidates + // empirically, by winning VarintBenchmark. + // + // Sign extension of (signed) Java bytes is usually a nuisance, but + // we exploit it here to more easily obtain the sign of bytes read. + // Instead of cleaning up the sign extension bits by masking eagerly, + // we delay until we find the final (positive) byte, when we clear all + // accumulated bits with one xor. We depend on javac to constant fold. + fastpath: + { + int tempPos = pos; + + if (limit == tempPos) { + break fastpath; + } + + final byte[] buffer = this.buffer; + long x; + int y; + if ((y = buffer[tempPos++]) >= 0) { + pos = tempPos; + return y; + } else if (limit - tempPos < 9) { + break fastpath; + } else if ((y ^= (buffer[tempPos++] << 7)) < 0) { + x = y ^ (~0 << 7); + } else if ((y ^= (buffer[tempPos++] << 14)) >= 0) { + x = y ^ ((~0 << 7) ^ (~0 << 14)); + } else if ((y ^= (buffer[tempPos++] << 21)) < 0) { + x = y ^ ((~0 << 7) ^ (~0 << 14) ^ (~0 << 21)); + } else if ((x = y ^ ((long) buffer[tempPos++] << 28)) >= 0L) { + x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28); + } else if ((x ^= ((long) buffer[tempPos++] << 35)) < 0L) { + x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35); + } else if ((x ^= ((long) buffer[tempPos++] << 42)) >= 0L) { + x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35) ^ (~0L << 42); + } else if ((x ^= ((long) buffer[tempPos++] << 49)) < 0L) { + x ^= + (~0L << 7) + ^ (~0L << 14) + ^ (~0L << 21) + ^ (~0L << 28) + ^ (~0L << 35) + ^ (~0L << 42) + ^ (~0L << 49); + } else { + x ^= ((long) buffer[tempPos++] << 56); + x ^= + (~0L << 7) + ^ (~0L << 14) + ^ (~0L << 21) + ^ (~0L << 28) + ^ (~0L << 35) + ^ (~0L << 42) + ^ (~0L << 49) + ^ (~0L << 56); + if (x < 0L) { + if (buffer[tempPos++] < 0L) { + break fastpath; // Will throw malformedVarint() + } + } + } + pos = tempPos; + return x; + } + return readRawVarint64SlowPath(); + } + + @Override + long readRawVarint64SlowPath() throws IOException { + long result = 0; + for (int shift = 0; shift < 64; shift += 7) { + final byte b = readRawByte(); + result |= (long) (b & 0x7F) << shift; + if ((b & 0x80) == 0) { + return result; + } + } + throw InvalidProtocolBufferException.malformedVarint(); + } + + @Override + public int readRawLittleEndian32() throws IOException { + int tempPos = pos; + + if (limit - tempPos < FIXED32_SIZE) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + + final byte[] buffer = this.buffer; + pos = tempPos + FIXED32_SIZE; + return ((buffer[tempPos] & 0xff) + | ((buffer[tempPos + 1] & 0xff) << 8) + | ((buffer[tempPos + 2] & 0xff) << 16) + | ((buffer[tempPos + 3] & 0xff) << 24)); + } + + @Override + public long readRawLittleEndian64() throws IOException { + int tempPos = pos; + + if (limit - tempPos < FIXED64_SIZE) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + + final byte[] buffer = this.buffer; + pos = tempPos + FIXED64_SIZE; + return ((buffer[tempPos] & 0xffL) + | ((buffer[tempPos + 1] & 0xffL) << 8) + | ((buffer[tempPos + 2] & 0xffL) << 16) + | ((buffer[tempPos + 3] & 0xffL) << 24) + | ((buffer[tempPos + 4] & 0xffL) << 32) + | ((buffer[tempPos + 5] & 0xffL) << 40) + | ((buffer[tempPos + 6] & 0xffL) << 48) + | ((buffer[tempPos + 7] & 0xffL) << 56)); + } + + @Override + public void enableAliasing(boolean enabled) { + this.enableAliasing = enabled; + } + + @Override + public void resetSizeCounter() { + startPos = pos; + } + + @Override + public int pushLimit(int byteLimit) throws InvalidProtocolBufferException { + if (byteLimit < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + byteLimit += getTotalBytesRead(); + if (byteLimit < 0) { + throw InvalidProtocolBufferException.parseFailure(); + } + final int oldLimit = currentLimit; + if (byteLimit > oldLimit) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + currentLimit = byteLimit; + + recomputeBufferSizeAfterLimit(); + + return oldLimit; + } + + private void recomputeBufferSizeAfterLimit() { + limit += bufferSizeAfterLimit; + final int bufferEnd = limit - startPos; + if (bufferEnd > currentLimit) { + // Limit is in current buffer. + bufferSizeAfterLimit = bufferEnd - currentLimit; + limit -= bufferSizeAfterLimit; + } else { + bufferSizeAfterLimit = 0; + } + } + + @Override + public void popLimit(final int oldLimit) { + currentLimit = oldLimit; + recomputeBufferSizeAfterLimit(); + } + + @Override + public int getBytesUntilLimit() { + if (currentLimit == Integer.MAX_VALUE) { + return -1; + } + + return currentLimit - getTotalBytesRead(); + } + + @Override + public boolean isAtEnd() throws IOException { + return pos == limit; + } + + @Override + public int getTotalBytesRead() { + return pos - startPos; + } + + @Override + public byte readRawByte() throws IOException { + if (pos == limit) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + return buffer[pos++]; + } + + @Override + public byte[] readRawBytes(final int length) throws IOException { + if (length > 0 && length <= (limit - pos)) { + final int tempPos = pos; + pos += length; + return Arrays.copyOfRange(buffer, tempPos, pos); + } + + if (length <= 0) { + if (length == 0) { + return Internal.EMPTY_BYTE_ARRAY; + } else { + throw InvalidProtocolBufferException.negativeSize(); + } + } + throw InvalidProtocolBufferException.truncatedMessage(); + } + + @Override + public void skipRawBytes(final int length) throws IOException { + if (length >= 0 && length <= (limit - pos)) { + // We have all the bytes we need already. + pos += length; + return; + } + + if (length < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + throw InvalidProtocolBufferException.truncatedMessage(); + } + } + + /** + * A {@link CodedInputStream} implementation that uses a backing direct ByteBuffer as the input. + * Requires the use of {@code sun.misc.Unsafe} to perform fast reads on the buffer. + */ + private static final class UnsafeDirectNioDecoder extends CodedInputStream { + /** The direct buffer that is backing this stream. */ + private final ByteBuffer buffer; + + /** + * If {@code true}, indicates that the buffer is backing a {@link ByteString} and is therefore + * considered to be an immutable input source. + */ + private final boolean immutable; + + /** The unsafe address of the content of {@link #buffer}. */ + private final long address; + + /** The unsafe address of the current read limit of the buffer. */ + private long limit; + + /** The unsafe address of the current read position of the buffer. */ + private long pos; + + /** The unsafe address of the starting read position. */ + private long startPos; + + /** The amount of available data in the buffer beyond {@link #limit}. */ + private int bufferSizeAfterLimit; + + /** The last tag that was read from this stream. */ + private int lastTag; + + /** + * If {@code true}, indicates that calls to read {@link ByteString} or {@code byte[]} + * may return slices of the underlying buffer, rather than copies. + */ + private boolean enableAliasing; + + /** The absolute position of the end of the current message. */ + private int currentLimit = Integer.MAX_VALUE; + + static boolean isSupported() { + return UnsafeUtil.hasUnsafeByteBufferOperations(); + } + + private UnsafeDirectNioDecoder(ByteBuffer buffer, boolean immutable) { + this.buffer = buffer; + address = UnsafeUtil.addressOffset(buffer); + limit = address + buffer.limit(); + pos = address + buffer.position(); + startPos = pos; + this.immutable = immutable; + } + + @Override + public int readTag() throws IOException { + if (isAtEnd()) { + lastTag = 0; + return 0; + } + + lastTag = readRawVarint32(); + if (WireFormat.getTagFieldNumber(lastTag) == 0) { + // If we actually read zero (or any tag number corresponding to field + // number zero), that's not a valid tag. + throw InvalidProtocolBufferException.invalidTag(); + } + return lastTag; + } + + @Override + public void checkLastTagWas(final int value) throws InvalidProtocolBufferException { + if (lastTag != value) { + throw InvalidProtocolBufferException.invalidEndTag(); + } + } + + @Override + public int getLastTag() { + return lastTag; + } + + @Override + public boolean skipField(final int tag) throws IOException { + switch (WireFormat.getTagWireType(tag)) { + case WireFormat.WIRETYPE_VARINT: + skipRawVarint(); + return true; + case WireFormat.WIRETYPE_FIXED64: + skipRawBytes(FIXED64_SIZE); + return true; + case WireFormat.WIRETYPE_LENGTH_DELIMITED: + skipRawBytes(readRawVarint32()); + return true; + case WireFormat.WIRETYPE_START_GROUP: + skipMessage(); + checkLastTagWas( + WireFormat.makeTag(WireFormat.getTagFieldNumber(tag), WireFormat.WIRETYPE_END_GROUP)); + return true; + case WireFormat.WIRETYPE_END_GROUP: + return false; + case WireFormat.WIRETYPE_FIXED32: + skipRawBytes(FIXED32_SIZE); + return true; + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + + @Override + public boolean skipField(final int tag, final CodedOutputStream output) throws IOException { + switch (WireFormat.getTagWireType(tag)) { + case WireFormat.WIRETYPE_VARINT: + { + long value = readInt64(); + output.writeUInt32NoTag(tag); + output.writeUInt64NoTag(value); + return true; + } + case WireFormat.WIRETYPE_FIXED64: + { + long value = readRawLittleEndian64(); + output.writeUInt32NoTag(tag); + output.writeFixed64NoTag(value); + return true; + } + case WireFormat.WIRETYPE_LENGTH_DELIMITED: + { + ByteString value = readBytes(); + output.writeUInt32NoTag(tag); + output.writeBytesNoTag(value); + return true; + } + case WireFormat.WIRETYPE_START_GROUP: + { + output.writeUInt32NoTag(tag); + skipMessage(output); + int endtag = + WireFormat.makeTag( + WireFormat.getTagFieldNumber(tag), WireFormat.WIRETYPE_END_GROUP); + checkLastTagWas(endtag); + output.writeUInt32NoTag(endtag); + return true; + } + case WireFormat.WIRETYPE_END_GROUP: + { + return false; + } + case WireFormat.WIRETYPE_FIXED32: + { + int value = readRawLittleEndian32(); + output.writeUInt32NoTag(tag); + output.writeFixed32NoTag(value); + return true; + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + + // ----------------------------------------------------------------- + + @Override + public double readDouble() throws IOException { + return Double.longBitsToDouble(readRawLittleEndian64()); + } + + @Override + public float readFloat() throws IOException { + return Float.intBitsToFloat(readRawLittleEndian32()); + } + + @Override + public long readUInt64() throws IOException { + return readRawVarint64(); + } + + @Override + public long readInt64() throws IOException { + return readRawVarint64(); + } + + @Override + public int readInt32() throws IOException { + return readRawVarint32(); + } + + @Override + public long readFixed64() throws IOException { + return readRawLittleEndian64(); + } + + @Override + public int readFixed32() throws IOException { + return readRawLittleEndian32(); + } + + @Override + public boolean readBool() throws IOException { + return readRawVarint64() != 0; + } + + @Override + public String readString() throws IOException { + final int size = readRawVarint32(); + if (size > 0 && size <= remaining()) { + // TODO: Is there a way to avoid this copy? + // TODO: It might be possible to share the optimized loop with + // readStringRequireUtf8 by implementing Java replacement logic there. + // The same as readBytes' logic + byte[] bytes = new byte[size]; + UnsafeUtil.copyMemory(pos, bytes, 0, size); + String result = new String(bytes, UTF_8); + pos += size; + return result; + } + + if (size == 0) { + return ""; + } + if (size < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + throw InvalidProtocolBufferException.truncatedMessage(); + } + + @Override + public String readStringRequireUtf8() throws IOException { + final int size = readRawVarint32(); + if (size > 0 && size <= remaining()) { + final int bufferPos = bufferPos(pos); + String result = Utf8.decodeUtf8(buffer, bufferPos, size); + pos += size; + return result; + } + + if (size == 0) { + return ""; + } + if (size <= 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + throw InvalidProtocolBufferException.truncatedMessage(); + } + + @Override + public void readGroup( + final int fieldNumber, + final MessageLite.Builder builder, + final ExtensionRegistryLite extensionRegistry) + throws IOException { + checkRecursionLimit(); + ++recursionDepth; + builder.mergeFrom(this, extensionRegistry); + checkLastTagWas(WireFormat.makeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP)); + --recursionDepth; + } + + @Override + public T readGroup( + final int fieldNumber, + final Parser parser, + final ExtensionRegistryLite extensionRegistry) + throws IOException { + checkRecursionLimit(); + ++recursionDepth; + T result = parser.parsePartialFrom(this, extensionRegistry); + checkLastTagWas(WireFormat.makeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP)); + --recursionDepth; + return result; + } + + @Deprecated + @Override + public void readUnknownGroup(final int fieldNumber, final MessageLite.Builder builder) + throws IOException { + readGroup(fieldNumber, builder, ExtensionRegistryLite.getEmptyRegistry()); + } + + @Override + public void readMessage( + final MessageLite.Builder builder, final ExtensionRegistryLite extensionRegistry) + throws IOException { + final int length = readRawVarint32(); + checkRecursionLimit(); + final int oldLimit = pushLimit(length); + ++recursionDepth; + builder.mergeFrom(this, extensionRegistry); + checkLastTagWas(0); + --recursionDepth; + if (getBytesUntilLimit() != 0) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + popLimit(oldLimit); + } + + @Override + public T readMessage( + final Parser parser, final ExtensionRegistryLite extensionRegistry) throws IOException { + int length = readRawVarint32(); + checkRecursionLimit(); + final int oldLimit = pushLimit(length); + ++recursionDepth; + T result = parser.parsePartialFrom(this, extensionRegistry); + checkLastTagWas(0); + --recursionDepth; + if (getBytesUntilLimit() != 0) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + popLimit(oldLimit); + return result; + } + + @Override + public ByteString readBytes() throws IOException { + final int size = readRawVarint32(); + if (size > 0 && size <= remaining()) { + if (immutable && enableAliasing) { + final ByteBuffer result = slice(pos, pos + size); + pos += size; + return ByteString.wrap(result); + } else { + // Use UnsafeUtil to copy the memory to bytes instead of using ByteBuffer ways. + byte[] bytes = new byte[size]; + UnsafeUtil.copyMemory(pos, bytes, 0, size); + pos += size; + return ByteString.wrap(bytes); + } + } + + if (size == 0) { + return ByteString.EMPTY; + } + if (size < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + throw InvalidProtocolBufferException.truncatedMessage(); + } + + @Override + public byte[] readByteArray() throws IOException { + return readRawBytes(readRawVarint32()); + } + + @Override + public ByteBuffer readByteBuffer() throws IOException { + final int size = readRawVarint32(); + if (size > 0 && size <= remaining()) { + // "Immutable" implies that buffer is backing a ByteString. + // Disallow slicing in this case to prevent the caller from modifying the contents + // of the ByteString. + if (!immutable && enableAliasing) { + final ByteBuffer result = slice(pos, pos + size); + pos += size; + return result; + } else { + // The same as readBytes' logic + byte[] bytes = new byte[size]; + UnsafeUtil.copyMemory(pos, bytes, 0, size); + pos += size; + return ByteBuffer.wrap(bytes); + } + // TODO: Investigate making the ByteBuffer be made read-only + } + + if (size == 0) { + return EMPTY_BYTE_BUFFER; + } + if (size < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + throw InvalidProtocolBufferException.truncatedMessage(); + } + + @Override + public int readUInt32() throws IOException { + return readRawVarint32(); + } + + @Override + public int readEnum() throws IOException { + return readRawVarint32(); + } + + @Override + public int readSFixed32() throws IOException { + return readRawLittleEndian32(); + } + + @Override + public long readSFixed64() throws IOException { + return readRawLittleEndian64(); + } + + @Override + public int readSInt32() throws IOException { + return decodeZigZag32(readRawVarint32()); + } + + @Override + public long readSInt64() throws IOException { + return decodeZigZag64(readRawVarint64()); + } + + // ================================================================= + + @Override + public int readRawVarint32() throws IOException { + // See implementation notes for readRawVarint64 + fastpath: + { + long tempPos = pos; + + if (limit == tempPos) { + break fastpath; + } + + int x; + if ((x = UnsafeUtil.getByte(tempPos++)) >= 0) { + pos = tempPos; + return x; + } else if (limit - tempPos < 9) { + break fastpath; + } else if ((x ^= (UnsafeUtil.getByte(tempPos++) << 7)) < 0) { + x ^= (~0 << 7); + } else if ((x ^= (UnsafeUtil.getByte(tempPos++) << 14)) >= 0) { + x ^= (~0 << 7) ^ (~0 << 14); + } else if ((x ^= (UnsafeUtil.getByte(tempPos++) << 21)) < 0) { + x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21); + } else { + int y = UnsafeUtil.getByte(tempPos++); + x ^= y << 28; + x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21) ^ (~0 << 28); + if (y < 0 + && UnsafeUtil.getByte(tempPos++) < 0 + && UnsafeUtil.getByte(tempPos++) < 0 + && UnsafeUtil.getByte(tempPos++) < 0 + && UnsafeUtil.getByte(tempPos++) < 0 + && UnsafeUtil.getByte(tempPos++) < 0) { + break fastpath; // Will throw malformedVarint() + } + } + pos = tempPos; + return x; + } + return (int) readRawVarint64SlowPath(); + } + + private void skipRawVarint() throws IOException { + if (remaining() >= MAX_VARINT_SIZE) { + skipRawVarintFastPath(); + } else { + skipRawVarintSlowPath(); + } + } + + private void skipRawVarintFastPath() throws IOException { + for (int i = 0; i < MAX_VARINT_SIZE; i++) { + if (UnsafeUtil.getByte(pos++) >= 0) { + return; + } + } + throw InvalidProtocolBufferException.malformedVarint(); + } + + private void skipRawVarintSlowPath() throws IOException { + for (int i = 0; i < MAX_VARINT_SIZE; i++) { + if (readRawByte() >= 0) { + return; + } + } + throw InvalidProtocolBufferException.malformedVarint(); + } + + @Override + public long readRawVarint64() throws IOException { + // Implementation notes: + // + // Optimized for one-byte values, expected to be common. + // The particular code below was selected from various candidates + // empirically, by winning VarintBenchmark. + // + // Sign extension of (signed) Java bytes is usually a nuisance, but + // we exploit it here to more easily obtain the sign of bytes read. + // Instead of cleaning up the sign extension bits by masking eagerly, + // we delay until we find the final (positive) byte, when we clear all + // accumulated bits with one xor. We depend on javac to constant fold. + fastpath: + { + long tempPos = pos; + + if (limit == tempPos) { + break fastpath; + } + + long x; + int y; + if ((y = UnsafeUtil.getByte(tempPos++)) >= 0) { + pos = tempPos; + return y; + } else if (limit - tempPos < 9) { + break fastpath; + } else if ((y ^= (UnsafeUtil.getByte(tempPos++) << 7)) < 0) { + x = y ^ (~0 << 7); + } else if ((y ^= (UnsafeUtil.getByte(tempPos++) << 14)) >= 0) { + x = y ^ ((~0 << 7) ^ (~0 << 14)); + } else if ((y ^= (UnsafeUtil.getByte(tempPos++) << 21)) < 0) { + x = y ^ ((~0 << 7) ^ (~0 << 14) ^ (~0 << 21)); + } else if ((x = y ^ ((long) UnsafeUtil.getByte(tempPos++) << 28)) >= 0L) { + x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28); + } else if ((x ^= ((long) UnsafeUtil.getByte(tempPos++) << 35)) < 0L) { + x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35); + } else if ((x ^= ((long) UnsafeUtil.getByte(tempPos++) << 42)) >= 0L) { + x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35) ^ (~0L << 42); + } else if ((x ^= ((long) UnsafeUtil.getByte(tempPos++) << 49)) < 0L) { + x ^= + (~0L << 7) + ^ (~0L << 14) + ^ (~0L << 21) + ^ (~0L << 28) + ^ (~0L << 35) + ^ (~0L << 42) + ^ (~0L << 49); + } else { + x ^= ((long) UnsafeUtil.getByte(tempPos++) << 56); + x ^= + (~0L << 7) + ^ (~0L << 14) + ^ (~0L << 21) + ^ (~0L << 28) + ^ (~0L << 35) + ^ (~0L << 42) + ^ (~0L << 49) + ^ (~0L << 56); + if (x < 0L) { + if (UnsafeUtil.getByte(tempPos++) < 0L) { + break fastpath; // Will throw malformedVarint() + } + } + } + pos = tempPos; + return x; + } + return readRawVarint64SlowPath(); + } + + @Override + long readRawVarint64SlowPath() throws IOException { + long result = 0; + for (int shift = 0; shift < 64; shift += 7) { + final byte b = readRawByte(); + result |= (long) (b & 0x7F) << shift; + if ((b & 0x80) == 0) { + return result; + } + } + throw InvalidProtocolBufferException.malformedVarint(); + } + + @Override + public int readRawLittleEndian32() throws IOException { + long tempPos = pos; + + if (limit - tempPos < FIXED32_SIZE) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + + pos = tempPos + FIXED32_SIZE; + return ((UnsafeUtil.getByte(tempPos) & 0xff) + | ((UnsafeUtil.getByte(tempPos + 1) & 0xff) << 8) + | ((UnsafeUtil.getByte(tempPos + 2) & 0xff) << 16) + | ((UnsafeUtil.getByte(tempPos + 3) & 0xff) << 24)); + } + + @Override + public long readRawLittleEndian64() throws IOException { + long tempPos = pos; + + if (limit - tempPos < FIXED64_SIZE) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + + pos = tempPos + FIXED64_SIZE; + return ((UnsafeUtil.getByte(tempPos) & 0xffL) + | ((UnsafeUtil.getByte(tempPos + 1) & 0xffL) << 8) + | ((UnsafeUtil.getByte(tempPos + 2) & 0xffL) << 16) + | ((UnsafeUtil.getByte(tempPos + 3) & 0xffL) << 24) + | ((UnsafeUtil.getByte(tempPos + 4) & 0xffL) << 32) + | ((UnsafeUtil.getByte(tempPos + 5) & 0xffL) << 40) + | ((UnsafeUtil.getByte(tempPos + 6) & 0xffL) << 48) + | ((UnsafeUtil.getByte(tempPos + 7) & 0xffL) << 56)); + } + + @Override + public void enableAliasing(boolean enabled) { + this.enableAliasing = enabled; + } + + @Override + public void resetSizeCounter() { + startPos = pos; + } + + @Override + public int pushLimit(int byteLimit) throws InvalidProtocolBufferException { + if (byteLimit < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + byteLimit += getTotalBytesRead(); + final int oldLimit = currentLimit; + if (byteLimit > oldLimit) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + currentLimit = byteLimit; + + recomputeBufferSizeAfterLimit(); + + return oldLimit; + } + + @Override + public void popLimit(final int oldLimit) { + currentLimit = oldLimit; + recomputeBufferSizeAfterLimit(); + } + + @Override + public int getBytesUntilLimit() { + if (currentLimit == Integer.MAX_VALUE) { + return -1; + } + + return currentLimit - getTotalBytesRead(); + } + + @Override + public boolean isAtEnd() throws IOException { + return pos == limit; + } + + @Override + public int getTotalBytesRead() { + return (int) (pos - startPos); + } + + @Override + public byte readRawByte() throws IOException { + if (pos == limit) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + return UnsafeUtil.getByte(pos++); + } + + @Override + public byte[] readRawBytes(final int length) throws IOException { + if (length >= 0 && length <= remaining()) { + byte[] bytes = new byte[length]; + slice(pos, pos + length).get(bytes); + pos += length; + return bytes; + } + + if (length <= 0) { + if (length == 0) { + return EMPTY_BYTE_ARRAY; + } else { + throw InvalidProtocolBufferException.negativeSize(); + } + } + + throw InvalidProtocolBufferException.truncatedMessage(); + } + + @Override + public void skipRawBytes(final int length) throws IOException { + if (length >= 0 && length <= remaining()) { + // We have all the bytes we need already. + pos += length; + return; + } + + if (length < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + throw InvalidProtocolBufferException.truncatedMessage(); + } + + private void recomputeBufferSizeAfterLimit() { + limit += bufferSizeAfterLimit; + final int bufferEnd = (int) (limit - startPos); + if (bufferEnd > currentLimit) { + // Limit is in current buffer. + bufferSizeAfterLimit = bufferEnd - currentLimit; + limit -= bufferSizeAfterLimit; + } else { + bufferSizeAfterLimit = 0; + } + } + + private int remaining() { + return (int) (limit - pos); + } + + private int bufferPos(long pos) { + return (int) (pos - address); + } + + private ByteBuffer slice(long begin, long end) throws IOException { + int prevPos = buffer.position(); + int prevLimit = buffer.limit(); + // View ByteBuffer as Buffer to avoid cross-Java version issues. + // See https://issues.apache.org/jira/browse/MRESOLVER-85 + Buffer asBuffer = buffer; + try { + asBuffer.position(bufferPos(begin)); + asBuffer.limit(bufferPos(end)); + return buffer.slice(); + } catch (IllegalArgumentException e) { + InvalidProtocolBufferException ex = InvalidProtocolBufferException.truncatedMessage(); + ex.initCause(e); + throw ex; + } finally { + asBuffer.position(prevPos); + asBuffer.limit(prevLimit); + } + } + } + + /** + * Implementation of {@link CodedInputStream} that uses an {@link InputStream} as the data source. + */ + private static final class StreamDecoder extends CodedInputStream { + private final InputStream input; + private final byte[] buffer; + /** bufferSize represents how many bytes are currently filled in the buffer */ + private int bufferSize; + + private int bufferSizeAfterLimit; + private int pos; + private int lastTag; + + /** + * The total number of bytes read before the current buffer. The total bytes read up to the + * current position can be computed as {@code totalBytesRetired + pos}. This value may be + * negative if reading started in the middle of the current buffer (e.g. if the constructor that + * takes a byte array and an offset was used). + */ + private int totalBytesRetired; + + /** The absolute position of the end of the current message. */ + private int currentLimit = Integer.MAX_VALUE; + + private StreamDecoder(final InputStream input, int bufferSize) { + checkNotNull(input, "input"); + this.input = input; + this.buffer = new byte[bufferSize]; + this.bufferSize = 0; + pos = 0; + totalBytesRetired = 0; + } + + /* + * The following wrapper methods exist so that InvalidProtocolBufferExceptions thrown by the + * InputStream can be differentiated from ones thrown by CodedInputStream itself. Each call to + * an InputStream method that can throw IOException must be wrapped like this. We do this + * because we sometimes need to modify IPBE instances after they are thrown far away from where + * they are thrown (ex. to add unfinished messages) and we use this signal elsewhere in the + * exception catch chain to know when to perform these operations directly or to wrap the + * exception in their own IPBE so the extra information can be communicated without trampling + * downstream information. + */ + private static int read(InputStream input, byte[] data, int offset, int length) + throws IOException { + try { + return input.read(data, offset, length); + } catch (InvalidProtocolBufferException e) { + e.setThrownFromInputStream(); + throw e; + } + } + + private static long skip(InputStream input, long length) throws IOException { + try { + return input.skip(length); + } catch (InvalidProtocolBufferException e) { + e.setThrownFromInputStream(); + throw e; + } + } + + private static int available(InputStream input) throws IOException { + try { + return input.available(); + } catch (InvalidProtocolBufferException e) { + e.setThrownFromInputStream(); + throw e; + } + } + + @Override + public int readTag() throws IOException { + if (isAtEnd()) { + lastTag = 0; + return 0; + } + + lastTag = readRawVarint32(); + if (WireFormat.getTagFieldNumber(lastTag) == 0) { + // If we actually read zero (or any tag number corresponding to field + // number zero), that's not a valid tag. + throw InvalidProtocolBufferException.invalidTag(); + } + return lastTag; + } + + @Override + public void checkLastTagWas(final int value) throws InvalidProtocolBufferException { + if (lastTag != value) { + throw InvalidProtocolBufferException.invalidEndTag(); + } + } + + @Override + public int getLastTag() { + return lastTag; + } + + @Override + public boolean skipField(final int tag) throws IOException { + switch (WireFormat.getTagWireType(tag)) { + case WireFormat.WIRETYPE_VARINT: + skipRawVarint(); + return true; + case WireFormat.WIRETYPE_FIXED64: + skipRawBytes(FIXED64_SIZE); + return true; + case WireFormat.WIRETYPE_LENGTH_DELIMITED: + skipRawBytes(readRawVarint32()); + return true; + case WireFormat.WIRETYPE_START_GROUP: + skipMessage(); + checkLastTagWas( + WireFormat.makeTag(WireFormat.getTagFieldNumber(tag), WireFormat.WIRETYPE_END_GROUP)); + return true; + case WireFormat.WIRETYPE_END_GROUP: + return false; + case WireFormat.WIRETYPE_FIXED32: + skipRawBytes(FIXED32_SIZE); + return true; + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + + @Override + public boolean skipField(final int tag, final CodedOutputStream output) throws IOException { + switch (WireFormat.getTagWireType(tag)) { + case WireFormat.WIRETYPE_VARINT: + { + long value = readInt64(); + output.writeUInt32NoTag(tag); + output.writeUInt64NoTag(value); + return true; + } + case WireFormat.WIRETYPE_FIXED64: + { + long value = readRawLittleEndian64(); + output.writeUInt32NoTag(tag); + output.writeFixed64NoTag(value); + return true; + } + case WireFormat.WIRETYPE_LENGTH_DELIMITED: + { + ByteString value = readBytes(); + output.writeUInt32NoTag(tag); + output.writeBytesNoTag(value); + return true; + } + case WireFormat.WIRETYPE_START_GROUP: + { + output.writeUInt32NoTag(tag); + skipMessage(output); + int endtag = + WireFormat.makeTag( + WireFormat.getTagFieldNumber(tag), WireFormat.WIRETYPE_END_GROUP); + checkLastTagWas(endtag); + output.writeUInt32NoTag(endtag); + return true; + } + case WireFormat.WIRETYPE_END_GROUP: + { + return false; + } + case WireFormat.WIRETYPE_FIXED32: + { + int value = readRawLittleEndian32(); + output.writeUInt32NoTag(tag); + output.writeFixed32NoTag(value); + return true; + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + + /** Collects the bytes skipped and returns the data in a ByteBuffer. */ + private class SkippedDataSink implements RefillCallback { + private int lastPos = pos; + private ByteArrayOutputStream byteArrayStream; + + @Override + public void onRefill() { + if (byteArrayStream == null) { + byteArrayStream = new ByteArrayOutputStream(); + } + byteArrayStream.write(buffer, lastPos, pos - lastPos); + lastPos = 0; + } + + /** Gets skipped data in a ByteBuffer. This method should only be called once. */ + ByteBuffer getSkippedData() { + if (byteArrayStream == null) { + return ByteBuffer.wrap(buffer, lastPos, pos - lastPos); + } else { + byteArrayStream.write(buffer, lastPos, pos); + return ByteBuffer.wrap(byteArrayStream.toByteArray()); + } + } + } + + // ----------------------------------------------------------------- + + @Override + public double readDouble() throws IOException { + return Double.longBitsToDouble(readRawLittleEndian64()); + } + + @Override + public float readFloat() throws IOException { + return Float.intBitsToFloat(readRawLittleEndian32()); + } + + @Override + public long readUInt64() throws IOException { + return readRawVarint64(); + } + + @Override + public long readInt64() throws IOException { + return readRawVarint64(); + } + + @Override + public int readInt32() throws IOException { + return readRawVarint32(); + } + + @Override + public long readFixed64() throws IOException { + return readRawLittleEndian64(); + } + + @Override + public int readFixed32() throws IOException { + return readRawLittleEndian32(); + } + + @Override + public boolean readBool() throws IOException { + return readRawVarint64() != 0; + } + + @Override + public String readString() throws IOException { + final int size = readRawVarint32(); + if (size > 0 && size <= (bufferSize - pos)) { + // Fast path: We already have the bytes in a contiguous buffer, so + // just copy directly from it. + final String result = new String(buffer, pos, size, UTF_8); + pos += size; + return result; + } + if (size == 0) { + return ""; + } + if (size < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + if (size <= bufferSize) { + refillBuffer(size); + String result = new String(buffer, pos, size, UTF_8); + pos += size; + return result; + } + // Slow path: Build a byte array first then copy it. + return new String(readRawBytesSlowPath(size, /* ensureNoLeakedReferences= */ false), UTF_8); + } + + @Override + public String readStringRequireUtf8() throws IOException { + final int size = readRawVarint32(); + final byte[] bytes; + final int oldPos = pos; + final int tempPos; + if (size <= (bufferSize - oldPos) && size > 0) { + // Fast path: We already have the bytes in a contiguous buffer, so + // just copy directly from it. + bytes = buffer; + pos = oldPos + size; + tempPos = oldPos; + } else if (size == 0) { + return ""; + } else if (size < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } else if (size <= bufferSize) { + refillBuffer(size); + bytes = buffer; + tempPos = 0; + pos = tempPos + size; + } else { + // Slow path: Build a byte array first then copy it. + bytes = readRawBytesSlowPath(size, /* ensureNoLeakedReferences= */ false); + tempPos = 0; + } + return Utf8.decodeUtf8(bytes, tempPos, size); + } + + @Override + public void readGroup( + final int fieldNumber, + final MessageLite.Builder builder, + final ExtensionRegistryLite extensionRegistry) + throws IOException { + checkRecursionLimit(); + ++recursionDepth; + builder.mergeFrom(this, extensionRegistry); + checkLastTagWas(WireFormat.makeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP)); + --recursionDepth; + } + + @Override + public T readGroup( + final int fieldNumber, + final Parser parser, + final ExtensionRegistryLite extensionRegistry) + throws IOException { + checkRecursionLimit(); + ++recursionDepth; + T result = parser.parsePartialFrom(this, extensionRegistry); + checkLastTagWas(WireFormat.makeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP)); + --recursionDepth; + return result; + } + + @Deprecated + @Override + public void readUnknownGroup(final int fieldNumber, final MessageLite.Builder builder) + throws IOException { + readGroup(fieldNumber, builder, ExtensionRegistryLite.getEmptyRegistry()); + } + + @Override + public void readMessage( + final MessageLite.Builder builder, final ExtensionRegistryLite extensionRegistry) + throws IOException { + final int length = readRawVarint32(); + checkRecursionLimit(); + final int oldLimit = pushLimit(length); + ++recursionDepth; + builder.mergeFrom(this, extensionRegistry); + checkLastTagWas(0); + --recursionDepth; + if (getBytesUntilLimit() != 0) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + popLimit(oldLimit); + } + + @Override + public T readMessage( + final Parser parser, final ExtensionRegistryLite extensionRegistry) throws IOException { + int length = readRawVarint32(); + checkRecursionLimit(); + final int oldLimit = pushLimit(length); + ++recursionDepth; + T result = parser.parsePartialFrom(this, extensionRegistry); + checkLastTagWas(0); + --recursionDepth; + if (getBytesUntilLimit() != 0) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + popLimit(oldLimit); + return result; + } + + @Override + public ByteString readBytes() throws IOException { + final int size = readRawVarint32(); + if (size <= (bufferSize - pos) && size > 0) { + // Fast path: We already have the bytes in a contiguous buffer, so + // just copy directly from it. + final ByteString result = ByteString.copyFrom(buffer, pos, size); + pos += size; + return result; + } + if (size == 0) { + return ByteString.EMPTY; + } + if (size < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + return readBytesSlowPath(size); + } + + @Override + public byte[] readByteArray() throws IOException { + final int size = readRawVarint32(); + if (size <= (bufferSize - pos) && size > 0) { + // Fast path: We already have the bytes in a contiguous buffer, so + // just copy directly from it. + final byte[] result = Arrays.copyOfRange(buffer, pos, pos + size); + pos += size; + return result; + } else if (size < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } else { + // Slow path: Build a byte array first then copy it. + // TODO: Do we want to protect from malicious input streams here? + return readRawBytesSlowPath(size, /* ensureNoLeakedReferences= */ false); + } + } + + @Override + public ByteBuffer readByteBuffer() throws IOException { + final int size = readRawVarint32(); + if (size <= (bufferSize - pos) && size > 0) { + // Fast path: We already have the bytes in a contiguous buffer. + ByteBuffer result = ByteBuffer.wrap(Arrays.copyOfRange(buffer, pos, pos + size)); + pos += size; + return result; + } + if (size == 0) { + return Internal.EMPTY_BYTE_BUFFER; + } + if (size < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + // Slow path: Build a byte array first then copy it. + + // We must copy as the byte array was handed off to the InputStream and a malicious + // implementation could retain a reference. + return ByteBuffer.wrap(readRawBytesSlowPath(size, /* ensureNoLeakedReferences= */ true)); + } + + @Override + public int readUInt32() throws IOException { + return readRawVarint32(); + } + + @Override + public int readEnum() throws IOException { + return readRawVarint32(); + } + + @Override + public int readSFixed32() throws IOException { + return readRawLittleEndian32(); + } + + @Override + public long readSFixed64() throws IOException { + return readRawLittleEndian64(); + } + + @Override + public int readSInt32() throws IOException { + return decodeZigZag32(readRawVarint32()); + } + + @Override + public long readSInt64() throws IOException { + return decodeZigZag64(readRawVarint64()); + } + + // ================================================================= + + @Override + public int readRawVarint32() throws IOException { + // See implementation notes for readRawVarint64 + fastpath: + { + int tempPos = pos; + + if (bufferSize == tempPos) { + break fastpath; + } + + final byte[] buffer = this.buffer; + int x; + if ((x = buffer[tempPos++]) >= 0) { + pos = tempPos; + return x; + } else if (bufferSize - tempPos < 9) { + break fastpath; + } else if ((x ^= (buffer[tempPos++] << 7)) < 0) { + x ^= (~0 << 7); + } else if ((x ^= (buffer[tempPos++] << 14)) >= 0) { + x ^= (~0 << 7) ^ (~0 << 14); + } else if ((x ^= (buffer[tempPos++] << 21)) < 0) { + x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21); + } else { + int y = buffer[tempPos++]; + x ^= y << 28; + x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21) ^ (~0 << 28); + if (y < 0 + && buffer[tempPos++] < 0 + && buffer[tempPos++] < 0 + && buffer[tempPos++] < 0 + && buffer[tempPos++] < 0 + && buffer[tempPos++] < 0) { + break fastpath; // Will throw malformedVarint() + } + } + pos = tempPos; + return x; + } + return (int) readRawVarint64SlowPath(); + } + + private void skipRawVarint() throws IOException { + if (bufferSize - pos >= MAX_VARINT_SIZE) { + skipRawVarintFastPath(); + } else { + skipRawVarintSlowPath(); + } + } + + private void skipRawVarintFastPath() throws IOException { + for (int i = 0; i < MAX_VARINT_SIZE; i++) { + if (buffer[pos++] >= 0) { + return; + } + } + throw InvalidProtocolBufferException.malformedVarint(); + } + + private void skipRawVarintSlowPath() throws IOException { + for (int i = 0; i < MAX_VARINT_SIZE; i++) { + if (readRawByte() >= 0) { + return; + } + } + throw InvalidProtocolBufferException.malformedVarint(); + } + + @Override + public long readRawVarint64() throws IOException { + // Implementation notes: + // + // Optimized for one-byte values, expected to be common. + // The particular code below was selected from various candidates + // empirically, by winning VarintBenchmark. + // + // Sign extension of (signed) Java bytes is usually a nuisance, but + // we exploit it here to more easily obtain the sign of bytes read. + // Instead of cleaning up the sign extension bits by masking eagerly, + // we delay until we find the final (positive) byte, when we clear all + // accumulated bits with one xor. We depend on javac to constant fold. + fastpath: + { + int tempPos = pos; + + if (bufferSize == tempPos) { + break fastpath; + } + + final byte[] buffer = this.buffer; + long x; + int y; + if ((y = buffer[tempPos++]) >= 0) { + pos = tempPos; + return y; + } else if (bufferSize - tempPos < 9) { + break fastpath; + } else if ((y ^= (buffer[tempPos++] << 7)) < 0) { + x = y ^ (~0 << 7); + } else if ((y ^= (buffer[tempPos++] << 14)) >= 0) { + x = y ^ ((~0 << 7) ^ (~0 << 14)); + } else if ((y ^= (buffer[tempPos++] << 21)) < 0) { + x = y ^ ((~0 << 7) ^ (~0 << 14) ^ (~0 << 21)); + } else if ((x = y ^ ((long) buffer[tempPos++] << 28)) >= 0L) { + x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28); + } else if ((x ^= ((long) buffer[tempPos++] << 35)) < 0L) { + x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35); + } else if ((x ^= ((long) buffer[tempPos++] << 42)) >= 0L) { + x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35) ^ (~0L << 42); + } else if ((x ^= ((long) buffer[tempPos++] << 49)) < 0L) { + x ^= + (~0L << 7) + ^ (~0L << 14) + ^ (~0L << 21) + ^ (~0L << 28) + ^ (~0L << 35) + ^ (~0L << 42) + ^ (~0L << 49); + } else { + x ^= ((long) buffer[tempPos++] << 56); + x ^= + (~0L << 7) + ^ (~0L << 14) + ^ (~0L << 21) + ^ (~0L << 28) + ^ (~0L << 35) + ^ (~0L << 42) + ^ (~0L << 49) + ^ (~0L << 56); + if (x < 0L) { + if (buffer[tempPos++] < 0L) { + break fastpath; // Will throw malformedVarint() + } + } + } + pos = tempPos; + return x; + } + return readRawVarint64SlowPath(); + } + + @Override + long readRawVarint64SlowPath() throws IOException { + long result = 0; + for (int shift = 0; shift < 64; shift += 7) { + final byte b = readRawByte(); + result |= (long) (b & 0x7F) << shift; + if ((b & 0x80) == 0) { + return result; + } + } + throw InvalidProtocolBufferException.malformedVarint(); + } + + @Override + public int readRawLittleEndian32() throws IOException { + int tempPos = pos; + + if (bufferSize - tempPos < FIXED32_SIZE) { + refillBuffer(FIXED32_SIZE); + tempPos = pos; + } + + final byte[] buffer = this.buffer; + pos = tempPos + FIXED32_SIZE; + return ((buffer[tempPos] & 0xff) + | ((buffer[tempPos + 1] & 0xff) << 8) + | ((buffer[tempPos + 2] & 0xff) << 16) + | ((buffer[tempPos + 3] & 0xff) << 24)); + } + + @Override + public long readRawLittleEndian64() throws IOException { + int tempPos = pos; + + if (bufferSize - tempPos < FIXED64_SIZE) { + refillBuffer(FIXED64_SIZE); + tempPos = pos; + } + + final byte[] buffer = this.buffer; + pos = tempPos + FIXED64_SIZE; + return (((buffer[tempPos] & 0xffL)) + | ((buffer[tempPos + 1] & 0xffL) << 8) + | ((buffer[tempPos + 2] & 0xffL) << 16) + | ((buffer[tempPos + 3] & 0xffL) << 24) + | ((buffer[tempPos + 4] & 0xffL) << 32) + | ((buffer[tempPos + 5] & 0xffL) << 40) + | ((buffer[tempPos + 6] & 0xffL) << 48) + | ((buffer[tempPos + 7] & 0xffL) << 56)); + } + + // ----------------------------------------------------------------- + + @Override + public void enableAliasing(boolean enabled) { + // TODO: Ideally we should throw here. Do nothing for backward compatibility. + } + + @Override + public void resetSizeCounter() { + totalBytesRetired = -pos; + } + + @Override + public int pushLimit(int byteLimit) throws InvalidProtocolBufferException { + if (byteLimit < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + byteLimit += totalBytesRetired + pos; + final int oldLimit = currentLimit; + if (byteLimit > oldLimit) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + currentLimit = byteLimit; + + recomputeBufferSizeAfterLimit(); + + return oldLimit; + } + + private void recomputeBufferSizeAfterLimit() { + bufferSize += bufferSizeAfterLimit; + final int bufferEnd = totalBytesRetired + bufferSize; + if (bufferEnd > currentLimit) { + // Limit is in current buffer. + bufferSizeAfterLimit = bufferEnd - currentLimit; + bufferSize -= bufferSizeAfterLimit; + } else { + bufferSizeAfterLimit = 0; + } + } + + @Override + public void popLimit(final int oldLimit) { + currentLimit = oldLimit; + recomputeBufferSizeAfterLimit(); + } + + @Override + public int getBytesUntilLimit() { + if (currentLimit == Integer.MAX_VALUE) { + return -1; + } + + final int currentAbsolutePosition = totalBytesRetired + pos; + return currentLimit - currentAbsolutePosition; + } + + @Override + public boolean isAtEnd() throws IOException { + return pos == bufferSize && !tryRefillBuffer(1); + } + + @Override + public int getTotalBytesRead() { + return totalBytesRetired + pos; + } + + private interface RefillCallback { + void onRefill(); + } + + private RefillCallback refillCallback = null; + + /** + * Reads more bytes from the input, making at least {@code n} bytes available in the buffer. + * Caller must ensure that the requested space is not yet available, and that the requested + * space is less than BUFFER_SIZE. + * + * @throws InvalidProtocolBufferException The end of the stream or the current limit was + * reached. + */ + private void refillBuffer(int n) throws IOException { + if (!tryRefillBuffer(n)) { + // We have to distinguish the exception between sizeLimitExceeded and truncatedMessage. So + // we just throw an sizeLimitExceeded exception here if it exceeds the sizeLimit + if (n > sizeLimit - totalBytesRetired - pos) { + throw InvalidProtocolBufferException.sizeLimitExceeded(); + } else { + throw InvalidProtocolBufferException.truncatedMessage(); + } + } + } + + /** + * Tries to read more bytes from the input, making at least {@code n} bytes available in the + * buffer. Caller must ensure that the requested space is not yet available, and that the + * requested space is less than BUFFER_SIZE. + * + * @return {@code true} If the bytes could be made available; {@code false} 1. Current at the + * end of the stream 2. The current limit was reached 3. The total size limit was reached + */ + private boolean tryRefillBuffer(int n) throws IOException { + if (pos + n <= bufferSize) { + throw new IllegalStateException( + "refillBuffer() called when " + n + " bytes were already available in buffer"); + } + + // Check whether the size of total message needs to read is bigger than the size limit. + // We shouldn't throw an exception here as isAtEnd() function needs to get this function's + // return as the result. + if (n > sizeLimit - totalBytesRetired - pos) { + return false; + } + + // Shouldn't throw the exception here either. + if (totalBytesRetired + pos + n > currentLimit) { + // Oops, we hit a limit. + return false; + } + + if (refillCallback != null) { + refillCallback.onRefill(); + } + + int tempPos = pos; + if (tempPos > 0) { + if (bufferSize > tempPos) { + System.arraycopy(buffer, tempPos, buffer, 0, bufferSize - tempPos); + } + totalBytesRetired += tempPos; + bufferSize -= tempPos; + pos = 0; + } + + // Here we should refill the buffer as many bytes as possible. + int bytesRead = + read( + input, + buffer, + bufferSize, + Math.min( + // the size of allocated but unused bytes in the buffer + buffer.length - bufferSize, + // do not exceed the total bytes limit + sizeLimit - totalBytesRetired - bufferSize)); + if (bytesRead == 0 || bytesRead < -1 || bytesRead > buffer.length) { + throw new IllegalStateException( + input.getClass() + + "#read(byte[]) returned invalid result: " + + bytesRead + + "\nThe InputStream implementation is buggy."); + } + if (bytesRead > 0) { + bufferSize += bytesRead; + recomputeBufferSizeAfterLimit(); + return (bufferSize >= n) ? true : tryRefillBuffer(n); + } + + return false; + } + + @Override + public byte readRawByte() throws IOException { + if (pos == bufferSize) { + refillBuffer(1); + } + return buffer[pos++]; + } + + @Override + public byte[] readRawBytes(final int size) throws IOException { + final int tempPos = pos; + if (size <= (bufferSize - tempPos) && size > 0) { + pos = tempPos + size; + return Arrays.copyOfRange(buffer, tempPos, tempPos + size); + } else { + // TODO: Do we want to protect from malicious input streams here? + return readRawBytesSlowPath(size, /* ensureNoLeakedReferences= */ false); + } + } + + /** + * Exactly like readRawBytes, but caller must have already checked the fast path: (size <= + * (bufferSize - pos) && size > 0) + * + * If ensureNoLeakedReferences is true, the value is guaranteed to have not escaped to + * untrusted code. + */ + private byte[] readRawBytesSlowPath( + final int size, boolean ensureNoLeakedReferences) throws IOException { + // Attempt to read the data in one byte array when it's safe to do. + byte[] result = readRawBytesSlowPathOneChunk(size); + if (result != null) { + return ensureNoLeakedReferences ? result.clone() : result; + } + + final int originalBufferPos = pos; + final int bufferedBytes = bufferSize - pos; + + // Mark the current buffer consumed. + totalBytesRetired += bufferSize; + pos = 0; + bufferSize = 0; + + // Determine the number of bytes we need to read from the input stream. + int sizeLeft = size - bufferedBytes; + + // The size is very large. For security reasons we read them in small + // chunks. + List chunks = readRawBytesSlowPathRemainingChunks(sizeLeft); + + // OK, got everything. Now concatenate it all into one buffer. + final byte[] bytes = new byte[size]; + + // Start by copying the leftover bytes from this.buffer. + System.arraycopy(buffer, originalBufferPos, bytes, 0, bufferedBytes); + + // And now all the chunks. + int tempPos = bufferedBytes; + for (final byte[] chunk : chunks) { + System.arraycopy(chunk, 0, bytes, tempPos, chunk.length); + tempPos += chunk.length; + } + + // Done. + return bytes; + } + + /** + * Attempts to read the data in one byte array when it's safe to do. Returns null if the size to + * read is too large and needs to be allocated in smaller chunks for security reasons. + * + *

Returns a byte[] that may have escaped to user code via InputStream APIs. + */ + private byte[] readRawBytesSlowPathOneChunk(final int size) throws IOException { + if (size == 0) { + return Internal.EMPTY_BYTE_ARRAY; + } + if (size < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + + // Integer-overflow-conscious check that the message size so far has not exceeded sizeLimit. + int currentMessageSize = totalBytesRetired + pos + size; + if (currentMessageSize - sizeLimit > 0) { + throw InvalidProtocolBufferException.sizeLimitExceeded(); + } + + // Verify that the message size so far has not exceeded currentLimit. + if (currentMessageSize > currentLimit) { + // Read to the end of the stream anyway. + skipRawBytes(currentLimit - totalBytesRetired - pos); + throw InvalidProtocolBufferException.truncatedMessage(); + } + + final int bufferedBytes = bufferSize - pos; + // Determine the number of bytes we need to read from the input stream. + int sizeLeft = size - bufferedBytes; + // TODO: Consider using a value larger than DEFAULT_BUFFER_SIZE. + if (sizeLeft < DEFAULT_BUFFER_SIZE || sizeLeft <= available(input)) { + // Either the bytes we need are known to be available, or the required buffer is + // within an allowed threshold - go ahead and allocate the buffer now. + final byte[] bytes = new byte[size]; + + // Copy all of the buffered bytes to the result buffer. + System.arraycopy(buffer, pos, bytes, 0, bufferedBytes); + totalBytesRetired += bufferSize; + pos = 0; + bufferSize = 0; + + // Fill the remaining bytes from the input stream. + int tempPos = bufferedBytes; + while (tempPos < bytes.length) { + int n = read(input, bytes, tempPos, size - tempPos); + if (n == -1) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + totalBytesRetired += n; + tempPos += n; + } + + return bytes; + } + + return null; + } + + /** + * Reads the remaining data in small chunks from the input stream. + * + * Returns a byte[] that may have escaped to user code via InputStream APIs. + */ + private List readRawBytesSlowPathRemainingChunks(int sizeLeft) throws IOException { + // The size is very large. For security reasons, we can't allocate the + // entire byte array yet. The size comes directly from the input, so a + // maliciously-crafted message could provide a bogus very large size in + // order to trick the app into allocating a lot of memory. We avoid this + // by allocating and reading only a small chunk at a time, so that the + // malicious message must actually *be* extremely large to cause + // problems. Meanwhile, we limit the allowed size of a message elsewhere. + final List chunks = new ArrayList<>(); + + while (sizeLeft > 0) { + // TODO: Consider using a value larger than DEFAULT_BUFFER_SIZE. + final byte[] chunk = new byte[Math.min(sizeLeft, DEFAULT_BUFFER_SIZE)]; + int tempPos = 0; + while (tempPos < chunk.length) { + final int n = input.read(chunk, tempPos, chunk.length - tempPos); + if (n == -1) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + totalBytesRetired += n; + tempPos += n; + } + sizeLeft -= chunk.length; + chunks.add(chunk); + } + + return chunks; + } + + /** + * Like readBytes, but caller must have already checked the fast path: (size <= (bufferSize - + * pos) && size > 0 || size == 0) + */ + private ByteString readBytesSlowPath(final int size) throws IOException { + final byte[] result = readRawBytesSlowPathOneChunk(size); + if (result != null) { + // We must copy as the byte array was handed off to the InputStream and a malicious + // implementation could retain a reference. + return ByteString.copyFrom(result); + } + + final int originalBufferPos = pos; + final int bufferedBytes = bufferSize - pos; + + // Mark the current buffer consumed. + totalBytesRetired += bufferSize; + pos = 0; + bufferSize = 0; + + // Determine the number of bytes we need to read from the input stream. + int sizeLeft = size - bufferedBytes; + + // The size is very large. For security reasons we read them in small + // chunks. + List chunks = readRawBytesSlowPathRemainingChunks(sizeLeft); + + // OK, got everything. Now concatenate it all into one buffer. + final byte[] bytes = new byte[size]; + + // Start by copying the leftover bytes from this.buffer. + System.arraycopy(buffer, originalBufferPos, bytes, 0, bufferedBytes); + + // And now all the chunks. + int tempPos = bufferedBytes; + for (final byte[] chunk : chunks) { + System.arraycopy(chunk, 0, bytes, tempPos, chunk.length); + tempPos += chunk.length; + } + + return ByteString.wrap(bytes); + } + + @Override + public void skipRawBytes(final int size) throws IOException { + if (size <= (bufferSize - pos) && size >= 0) { + // We have all the bytes we need already. + pos += size; + } else { + skipRawBytesSlowPath(size); + } + } + + /** + * Exactly like skipRawBytes, but caller must have already checked the fast path: (size <= + * (bufferSize - pos) && size >= 0) + */ + private void skipRawBytesSlowPath(final int size) throws IOException { + if (size < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + + if (totalBytesRetired + pos + size > currentLimit) { + // Read to the end of the stream anyway. + skipRawBytes(currentLimit - totalBytesRetired - pos); + // Then fail. + throw InvalidProtocolBufferException.truncatedMessage(); + } + + int totalSkipped = 0; + if (refillCallback == null) { + // Skipping more bytes than are in the buffer. First skip what we have. + totalBytesRetired += pos; + totalSkipped = bufferSize - pos; + bufferSize = 0; + pos = 0; + + try { + while (totalSkipped < size) { + int toSkip = size - totalSkipped; + long skipped = skip(input, toSkip); + if (skipped < 0 || skipped > toSkip) { + throw new IllegalStateException( + input.getClass() + + "#skip returned invalid result: " + + skipped + + "\nThe InputStream implementation is buggy."); + } else if (skipped == 0) { + // The API contract of skip() permits an inputstream to skip zero bytes for any reason + // it wants. In particular, ByteArrayInputStream will just return zero over and over + // when it's at the end of its input. In order to actually confirm that we've hit the + // end of input, we need to issue a read call via the other path. + break; + } + totalSkipped += (int) skipped; + } + } finally { + totalBytesRetired += totalSkipped; + recomputeBufferSizeAfterLimit(); + } + } + if (totalSkipped < size) { + // Skipping more bytes than are in the buffer. First skip what we have. + int tempPos = bufferSize - pos; + pos = bufferSize; + + // Keep refilling the buffer until we get to the point we wanted to skip to. + // This has the side effect of ensuring the limits are updated correctly. + refillBuffer(1); + while (size - tempPos > bufferSize) { + tempPos += bufferSize; + pos = bufferSize; + refillBuffer(1); + } + + pos = size - tempPos; + } + } + } + + /** + * Implementation of {@link CodedInputStream} that uses an {@link Iterable } as the + * data source. Requires the use of {@code sun.misc.Unsafe} to perform fast reads on the buffer. + */ + private static final class IterableDirectByteBufferDecoder extends CodedInputStream { + /** The object that need to decode. */ + private final Iterable input; + /** The {@link Iterator} with type {@link ByteBuffer} of {@code input} */ + private final Iterator iterator; + /** The current ByteBuffer; */ + private ByteBuffer currentByteBuffer; + /** + * If {@code true}, indicates that all the buffers are backing a {@link ByteString} and are + * therefore considered to be an immutable input source. + */ + private final boolean immutable; + /** + * If {@code true}, indicates that calls to read {@link ByteString} or {@code byte[]} + * may return slices of the underlying buffer, rather than copies. + */ + private boolean enableAliasing; + /** The global total message length limit */ + private int totalBufferSize; + /** The amount of available data in the input beyond {@link #currentLimit}. */ + private int bufferSizeAfterCurrentLimit; + /** The absolute position of the end of the current message. */ + private int currentLimit = Integer.MAX_VALUE; + /** The last tag that was read from this stream. */ + private int lastTag; + /** Total Bytes have been Read from the {@link Iterable} {@link ByteBuffer} */ + private int totalBytesRead; + /** The start position offset of the whole message, used as to reset the totalBytesRead */ + private int startOffset; + /** The current position for current ByteBuffer */ + private long currentByteBufferPos; + + private long currentByteBufferStartPos; + /** + * If the current ByteBuffer is unsafe-direct based, currentAddress is the start address of this + * ByteBuffer; otherwise should be zero. + */ + private long currentAddress; + /** The limit position for current ByteBuffer */ + private long currentByteBufferLimit; + + /** + * The constructor of {@code Iterable} decoder. + * + * @param inputBufs The input data. + * @param size The total size of the input data. + * @param immutableFlag whether the input data is immutable. + */ + private IterableDirectByteBufferDecoder( + Iterable inputBufs, int size, boolean immutableFlag) { + totalBufferSize = size; + input = inputBufs; + iterator = input.iterator(); + immutable = immutableFlag; + startOffset = totalBytesRead = 0; + if (size == 0) { + currentByteBuffer = EMPTY_BYTE_BUFFER; + currentByteBufferPos = 0; + currentByteBufferStartPos = 0; + currentByteBufferLimit = 0; + currentAddress = 0; + } else { + tryGetNextByteBuffer(); + } + } + + /** To get the next ByteBuffer from {@code input}, and then update the parameters */ + private void getNextByteBuffer() throws InvalidProtocolBufferException { + if (!iterator.hasNext()) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + tryGetNextByteBuffer(); + } + + private void tryGetNextByteBuffer() { + currentByteBuffer = iterator.next(); + totalBytesRead += (int) (currentByteBufferPos - currentByteBufferStartPos); + currentByteBufferPos = currentByteBuffer.position(); + currentByteBufferStartPos = currentByteBufferPos; + currentByteBufferLimit = currentByteBuffer.limit(); + currentAddress = UnsafeUtil.addressOffset(currentByteBuffer); + currentByteBufferPos += currentAddress; + currentByteBufferStartPos += currentAddress; + currentByteBufferLimit += currentAddress; + } + + @Override + public int readTag() throws IOException { + if (isAtEnd()) { + lastTag = 0; + return 0; + } + + lastTag = readRawVarint32(); + if (WireFormat.getTagFieldNumber(lastTag) == 0) { + // If we actually read zero (or any tag number corresponding to field + // number zero), that's not a valid tag. + throw InvalidProtocolBufferException.invalidTag(); + } + return lastTag; + } + + @Override + public void checkLastTagWas(final int value) throws InvalidProtocolBufferException { + if (lastTag != value) { + throw InvalidProtocolBufferException.invalidEndTag(); + } + } + + @Override + public int getLastTag() { + return lastTag; + } + + @Override + public boolean skipField(final int tag) throws IOException { + switch (WireFormat.getTagWireType(tag)) { + case WireFormat.WIRETYPE_VARINT: + skipRawVarint(); + return true; + case WireFormat.WIRETYPE_FIXED64: + skipRawBytes(FIXED64_SIZE); + return true; + case WireFormat.WIRETYPE_LENGTH_DELIMITED: + skipRawBytes(readRawVarint32()); + return true; + case WireFormat.WIRETYPE_START_GROUP: + skipMessage(); + checkLastTagWas( + WireFormat.makeTag(WireFormat.getTagFieldNumber(tag), WireFormat.WIRETYPE_END_GROUP)); + return true; + case WireFormat.WIRETYPE_END_GROUP: + return false; + case WireFormat.WIRETYPE_FIXED32: + skipRawBytes(FIXED32_SIZE); + return true; + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + + @Override + public boolean skipField(final int tag, final CodedOutputStream output) throws IOException { + switch (WireFormat.getTagWireType(tag)) { + case WireFormat.WIRETYPE_VARINT: + { + long value = readInt64(); + output.writeUInt32NoTag(tag); + output.writeUInt64NoTag(value); + return true; + } + case WireFormat.WIRETYPE_FIXED64: + { + long value = readRawLittleEndian64(); + output.writeUInt32NoTag(tag); + output.writeFixed64NoTag(value); + return true; + } + case WireFormat.WIRETYPE_LENGTH_DELIMITED: + { + ByteString value = readBytes(); + output.writeUInt32NoTag(tag); + output.writeBytesNoTag(value); + return true; + } + case WireFormat.WIRETYPE_START_GROUP: + { + output.writeUInt32NoTag(tag); + skipMessage(output); + int endtag = + WireFormat.makeTag( + WireFormat.getTagFieldNumber(tag), WireFormat.WIRETYPE_END_GROUP); + checkLastTagWas(endtag); + output.writeUInt32NoTag(endtag); + return true; + } + case WireFormat.WIRETYPE_END_GROUP: + { + return false; + } + case WireFormat.WIRETYPE_FIXED32: + { + int value = readRawLittleEndian32(); + output.writeUInt32NoTag(tag); + output.writeFixed32NoTag(value); + return true; + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + + // ----------------------------------------------------------------- + + @Override + public double readDouble() throws IOException { + return Double.longBitsToDouble(readRawLittleEndian64()); + } + + @Override + public float readFloat() throws IOException { + return Float.intBitsToFloat(readRawLittleEndian32()); + } + + @Override + public long readUInt64() throws IOException { + return readRawVarint64(); + } + + @Override + public long readInt64() throws IOException { + return readRawVarint64(); + } + + @Override + public int readInt32() throws IOException { + return readRawVarint32(); + } + + @Override + public long readFixed64() throws IOException { + return readRawLittleEndian64(); + } + + @Override + public int readFixed32() throws IOException { + return readRawLittleEndian32(); + } + + @Override + public boolean readBool() throws IOException { + return readRawVarint64() != 0; + } + + @Override + public String readString() throws IOException { + final int size = readRawVarint32(); + if (size > 0 && size <= currentByteBufferLimit - currentByteBufferPos) { + byte[] bytes = new byte[size]; + UnsafeUtil.copyMemory(currentByteBufferPos, bytes, 0, size); + String result = new String(bytes, UTF_8); + currentByteBufferPos += size; + return result; + } else if (size > 0 && size <= remaining()) { + // TODO: To use an underlying bytes[] instead of allocating a new bytes[] + byte[] bytes = new byte[size]; + readRawBytesTo(bytes, 0, size); + String result = new String(bytes, UTF_8); + return result; + } + + if (size == 0) { + return ""; + } + if (size < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + throw InvalidProtocolBufferException.truncatedMessage(); + } + + @Override + public String readStringRequireUtf8() throws IOException { + final int size = readRawVarint32(); + if (size > 0 && size <= currentByteBufferLimit - currentByteBufferPos) { + final int bufferPos = (int) (currentByteBufferPos - currentByteBufferStartPos); + String result = Utf8.decodeUtf8(currentByteBuffer, bufferPos, size); + currentByteBufferPos += size; + return result; + } + if (size >= 0 && size <= remaining()) { + byte[] bytes = new byte[size]; + readRawBytesTo(bytes, 0, size); + return Utf8.decodeUtf8(bytes, 0, size); + } + + if (size == 0) { + return ""; + } + if (size <= 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + throw InvalidProtocolBufferException.truncatedMessage(); + } + + @Override + public void readGroup( + final int fieldNumber, + final MessageLite.Builder builder, + final ExtensionRegistryLite extensionRegistry) + throws IOException { + checkRecursionLimit(); + ++recursionDepth; + builder.mergeFrom(this, extensionRegistry); + checkLastTagWas(WireFormat.makeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP)); + --recursionDepth; + } + + @Override + public T readGroup( + final int fieldNumber, + final Parser parser, + final ExtensionRegistryLite extensionRegistry) + throws IOException { + checkRecursionLimit(); + ++recursionDepth; + T result = parser.parsePartialFrom(this, extensionRegistry); + checkLastTagWas(WireFormat.makeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP)); + --recursionDepth; + return result; + } + + @Deprecated + @Override + public void readUnknownGroup(final int fieldNumber, final MessageLite.Builder builder) + throws IOException { + readGroup(fieldNumber, builder, ExtensionRegistryLite.getEmptyRegistry()); + } + + @Override + public void readMessage( + final MessageLite.Builder builder, final ExtensionRegistryLite extensionRegistry) + throws IOException { + final int length = readRawVarint32(); + checkRecursionLimit(); + final int oldLimit = pushLimit(length); + ++recursionDepth; + builder.mergeFrom(this, extensionRegistry); + checkLastTagWas(0); + --recursionDepth; + if (getBytesUntilLimit() != 0) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + popLimit(oldLimit); + } + + @Override + public T readMessage( + final Parser parser, final ExtensionRegistryLite extensionRegistry) throws IOException { + int length = readRawVarint32(); + checkRecursionLimit(); + final int oldLimit = pushLimit(length); + ++recursionDepth; + T result = parser.parsePartialFrom(this, extensionRegistry); + checkLastTagWas(0); + --recursionDepth; + if (getBytesUntilLimit() != 0) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + popLimit(oldLimit); + return result; + } + + @Override + public ByteString readBytes() throws IOException { + final int size = readRawVarint32(); + if (size > 0 && size <= currentByteBufferLimit - currentByteBufferPos) { + if (immutable && enableAliasing) { + final int idx = (int) (currentByteBufferPos - currentAddress); + final ByteString result = ByteString.wrap(slice(idx, idx + size)); + currentByteBufferPos += size; + return result; + } else { + byte[] bytes = new byte[size]; + UnsafeUtil.copyMemory(currentByteBufferPos, bytes, 0, size); + currentByteBufferPos += size; + return ByteString.wrap(bytes); + } + } else if (size > 0 && size <= remaining()) { + if (immutable && enableAliasing) { + ArrayList byteStrings = new ArrayList<>(); + int l = size; + while (l > 0) { + if (currentRemaining() == 0) { + getNextByteBuffer(); + } + int bytesToCopy = Math.min(l, (int) currentRemaining()); + int idx = (int) (currentByteBufferPos - currentAddress); + byteStrings.add(ByteString.wrap(slice(idx, idx + bytesToCopy))); + l -= bytesToCopy; + currentByteBufferPos += bytesToCopy; + } + return ByteString.copyFrom(byteStrings); + } else { + byte[] temp = new byte[size]; + readRawBytesTo(temp, 0, size); + return ByteString.wrap(temp); + } + } + + if (size == 0) { + return ByteString.EMPTY; + } + if (size < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + throw InvalidProtocolBufferException.truncatedMessage(); + } + + @Override + public byte[] readByteArray() throws IOException { + return readRawBytes(readRawVarint32()); + } + + @Override + public ByteBuffer readByteBuffer() throws IOException { + final int size = readRawVarint32(); + if (size > 0 && size <= currentRemaining()) { + if (!immutable && enableAliasing) { + currentByteBufferPos += size; + return slice( + (int) (currentByteBufferPos - currentAddress - size), + (int) (currentByteBufferPos - currentAddress)); + } else { + byte[] bytes = new byte[size]; + UnsafeUtil.copyMemory(currentByteBufferPos, bytes, 0, size); + currentByteBufferPos += size; + return ByteBuffer.wrap(bytes); + } + } else if (size > 0 && size <= remaining()) { + byte[] temp = new byte[size]; + readRawBytesTo(temp, 0, size); + return ByteBuffer.wrap(temp); + } + + if (size == 0) { + return EMPTY_BYTE_BUFFER; + } + if (size < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + throw InvalidProtocolBufferException.truncatedMessage(); + } + + @Override + public int readUInt32() throws IOException { + return readRawVarint32(); + } + + @Override + public int readEnum() throws IOException { + return readRawVarint32(); + } + + @Override + public int readSFixed32() throws IOException { + return readRawLittleEndian32(); + } + + @Override + public long readSFixed64() throws IOException { + return readRawLittleEndian64(); + } + + @Override + public int readSInt32() throws IOException { + return decodeZigZag32(readRawVarint32()); + } + + @Override + public long readSInt64() throws IOException { + return decodeZigZag64(readRawVarint64()); + } + + @Override + public int readRawVarint32() throws IOException { + fastpath: + { + long tempPos = currentByteBufferPos; + + if (currentByteBufferLimit == currentByteBufferPos) { + break fastpath; + } + + int x; + if ((x = UnsafeUtil.getByte(tempPos++)) >= 0) { + currentByteBufferPos++; + return x; + } else if (currentByteBufferLimit - currentByteBufferPos < 10) { + break fastpath; + } else if ((x ^= (UnsafeUtil.getByte(tempPos++) << 7)) < 0) { + x ^= (~0 << 7); + } else if ((x ^= (UnsafeUtil.getByte(tempPos++) << 14)) >= 0) { + x ^= (~0 << 7) ^ (~0 << 14); + } else if ((x ^= (UnsafeUtil.getByte(tempPos++) << 21)) < 0) { + x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21); + } else { + int y = UnsafeUtil.getByte(tempPos++); + x ^= y << 28; + x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21) ^ (~0 << 28); + if (y < 0 + && UnsafeUtil.getByte(tempPos++) < 0 + && UnsafeUtil.getByte(tempPos++) < 0 + && UnsafeUtil.getByte(tempPos++) < 0 + && UnsafeUtil.getByte(tempPos++) < 0 + && UnsafeUtil.getByte(tempPos++) < 0) { + break fastpath; // Will throw malformedVarint() + } + } + currentByteBufferPos = tempPos; + return x; + } + return (int) readRawVarint64SlowPath(); + } + + @Override + public long readRawVarint64() throws IOException { + fastpath: + { + long tempPos = currentByteBufferPos; + + if (currentByteBufferLimit == currentByteBufferPos) { + break fastpath; + } + + long x; + int y; + if ((y = UnsafeUtil.getByte(tempPos++)) >= 0) { + currentByteBufferPos++; + return y; + } else if (currentByteBufferLimit - currentByteBufferPos < 10) { + break fastpath; + } else if ((y ^= (UnsafeUtil.getByte(tempPos++) << 7)) < 0) { + x = y ^ (~0 << 7); + } else if ((y ^= (UnsafeUtil.getByte(tempPos++) << 14)) >= 0) { + x = y ^ ((~0 << 7) ^ (~0 << 14)); + } else if ((y ^= (UnsafeUtil.getByte(tempPos++) << 21)) < 0) { + x = y ^ ((~0 << 7) ^ (~0 << 14) ^ (~0 << 21)); + } else if ((x = y ^ ((long) UnsafeUtil.getByte(tempPos++) << 28)) >= 0L) { + x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28); + } else if ((x ^= ((long) UnsafeUtil.getByte(tempPos++) << 35)) < 0L) { + x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35); + } else if ((x ^= ((long) UnsafeUtil.getByte(tempPos++) << 42)) >= 0L) { + x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35) ^ (~0L << 42); + } else if ((x ^= ((long) UnsafeUtil.getByte(tempPos++) << 49)) < 0L) { + x ^= + (~0L << 7) + ^ (~0L << 14) + ^ (~0L << 21) + ^ (~0L << 28) + ^ (~0L << 35) + ^ (~0L << 42) + ^ (~0L << 49); + } else { + x ^= ((long) UnsafeUtil.getByte(tempPos++) << 56); + x ^= + (~0L << 7) + ^ (~0L << 14) + ^ (~0L << 21) + ^ (~0L << 28) + ^ (~0L << 35) + ^ (~0L << 42) + ^ (~0L << 49) + ^ (~0L << 56); + if (x < 0L) { + if (UnsafeUtil.getByte(tempPos++) < 0L) { + break fastpath; // Will throw malformedVarint() + } + } + } + currentByteBufferPos = tempPos; + return x; + } + return readRawVarint64SlowPath(); + } + + @Override + long readRawVarint64SlowPath() throws IOException { + long result = 0; + for (int shift = 0; shift < 64; shift += 7) { + final byte b = readRawByte(); + result |= (long) (b & 0x7F) << shift; + if ((b & 0x80) == 0) { + return result; + } + } + throw InvalidProtocolBufferException.malformedVarint(); + } + + @Override + public int readRawLittleEndian32() throws IOException { + if (currentRemaining() >= FIXED32_SIZE) { + long tempPos = currentByteBufferPos; + currentByteBufferPos += FIXED32_SIZE; + return ((UnsafeUtil.getByte(tempPos) & 0xff) + | ((UnsafeUtil.getByte(tempPos + 1) & 0xff) << 8) + | ((UnsafeUtil.getByte(tempPos + 2) & 0xff) << 16) + | ((UnsafeUtil.getByte(tempPos + 3) & 0xff) << 24)); + } + return ((readRawByte() & 0xff) + | ((readRawByte() & 0xff) << 8) + | ((readRawByte() & 0xff) << 16) + | ((readRawByte() & 0xff) << 24)); + } + + @Override + public long readRawLittleEndian64() throws IOException { + if (currentRemaining() >= FIXED64_SIZE) { + long tempPos = currentByteBufferPos; + currentByteBufferPos += FIXED64_SIZE; + return ((UnsafeUtil.getByte(tempPos) & 0xffL) + | ((UnsafeUtil.getByte(tempPos + 1) & 0xffL) << 8) + | ((UnsafeUtil.getByte(tempPos + 2) & 0xffL) << 16) + | ((UnsafeUtil.getByte(tempPos + 3) & 0xffL) << 24) + | ((UnsafeUtil.getByte(tempPos + 4) & 0xffL) << 32) + | ((UnsafeUtil.getByte(tempPos + 5) & 0xffL) << 40) + | ((UnsafeUtil.getByte(tempPos + 6) & 0xffL) << 48) + | ((UnsafeUtil.getByte(tempPos + 7) & 0xffL) << 56)); + } + return ((readRawByte() & 0xffL) + | ((readRawByte() & 0xffL) << 8) + | ((readRawByte() & 0xffL) << 16) + | ((readRawByte() & 0xffL) << 24) + | ((readRawByte() & 0xffL) << 32) + | ((readRawByte() & 0xffL) << 40) + | ((readRawByte() & 0xffL) << 48) + | ((readRawByte() & 0xffL) << 56)); + } + + @Override + public void enableAliasing(boolean enabled) { + this.enableAliasing = enabled; + } + + @Override + public void resetSizeCounter() { + startOffset = (int) (totalBytesRead + currentByteBufferPos - currentByteBufferStartPos); + } + + @Override + public int pushLimit(int byteLimit) throws InvalidProtocolBufferException { + if (byteLimit < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + byteLimit += getTotalBytesRead(); + final int oldLimit = currentLimit; + if (byteLimit > oldLimit) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + currentLimit = byteLimit; + + recomputeBufferSizeAfterLimit(); + + return oldLimit; + } + + private void recomputeBufferSizeAfterLimit() { + totalBufferSize += bufferSizeAfterCurrentLimit; + final int bufferEnd = totalBufferSize - startOffset; + if (bufferEnd > currentLimit) { + // Limit is in current buffer. + bufferSizeAfterCurrentLimit = bufferEnd - currentLimit; + totalBufferSize -= bufferSizeAfterCurrentLimit; + } else { + bufferSizeAfterCurrentLimit = 0; + } + } + + @Override + public void popLimit(final int oldLimit) { + currentLimit = oldLimit; + recomputeBufferSizeAfterLimit(); + } + + @Override + public int getBytesUntilLimit() { + if (currentLimit == Integer.MAX_VALUE) { + return -1; + } + + return currentLimit - getTotalBytesRead(); + } + + @Override + public boolean isAtEnd() throws IOException { + return totalBytesRead + currentByteBufferPos - currentByteBufferStartPos == totalBufferSize; + } + + @Override + public int getTotalBytesRead() { + return (int) + (totalBytesRead - startOffset + currentByteBufferPos - currentByteBufferStartPos); + } + + @Override + public byte readRawByte() throws IOException { + if (currentRemaining() == 0) { + getNextByteBuffer(); + } + return UnsafeUtil.getByte(currentByteBufferPos++); + } + + @Override + public byte[] readRawBytes(final int length) throws IOException { + if (length >= 0 && length <= currentRemaining()) { + byte[] bytes = new byte[length]; + UnsafeUtil.copyMemory(currentByteBufferPos, bytes, 0, length); + currentByteBufferPos += length; + return bytes; + } + if (length >= 0 && length <= remaining()) { + byte[] bytes = new byte[length]; + readRawBytesTo(bytes, 0, length); + return bytes; + } + + if (length <= 0) { + if (length == 0) { + return EMPTY_BYTE_ARRAY; + } else { + throw InvalidProtocolBufferException.negativeSize(); + } + } + + throw InvalidProtocolBufferException.truncatedMessage(); + } + + /** + * Try to get raw bytes from {@code input} with the size of {@code length} and copy to {@code + * bytes} array. If the size is bigger than the number of remaining bytes in the input, then + * throw {@code truncatedMessage} exception. + */ + private void readRawBytesTo(byte[] bytes, int offset, final int length) throws IOException { + if (length >= 0 && length <= remaining()) { + int l = length; + while (l > 0) { + if (currentRemaining() == 0) { + getNextByteBuffer(); + } + int bytesToCopy = Math.min(l, (int) currentRemaining()); + UnsafeUtil.copyMemory(currentByteBufferPos, bytes, length - l + offset, bytesToCopy); + l -= bytesToCopy; + currentByteBufferPos += bytesToCopy; + } + return; + } + + if (length <= 0) { + if (length == 0) { + return; + } else { + throw InvalidProtocolBufferException.negativeSize(); + } + } + throw InvalidProtocolBufferException.truncatedMessage(); + } + + @Override + public void skipRawBytes(final int length) throws IOException { + if (length >= 0 + && length + <= (totalBufferSize + - totalBytesRead + - currentByteBufferPos + + currentByteBufferStartPos)) { + // We have all the bytes we need already. + int l = length; + while (l > 0) { + if (currentRemaining() == 0) { + getNextByteBuffer(); + } + int rl = Math.min(l, (int) currentRemaining()); + l -= rl; + currentByteBufferPos += rl; + } + return; + } + + if (length < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + throw InvalidProtocolBufferException.truncatedMessage(); + } + + // TODO: optimize to fastpath + private void skipRawVarint() throws IOException { + for (int i = 0; i < MAX_VARINT_SIZE; i++) { + if (readRawByte() >= 0) { + return; + } + } + throw InvalidProtocolBufferException.malformedVarint(); + } + + /** + * Try to get the number of remaining bytes in {@code input}. + * + * @return the number of remaining bytes in {@code input}. + */ + private int remaining() { + return (int) + (totalBufferSize - totalBytesRead - currentByteBufferPos + currentByteBufferStartPos); + } + + /** + * Try to get the number of remaining bytes in {@code currentByteBuffer}. + * + * @return the number of remaining bytes in {@code currentByteBuffer} + */ + private long currentRemaining() { + return (currentByteBufferLimit - currentByteBufferPos); + } + + private ByteBuffer slice(int begin, int end) throws IOException { + int prevPos = currentByteBuffer.position(); + int prevLimit = currentByteBuffer.limit(); + // View ByteBuffer as Buffer to avoid cross-Java version issues. + // See https://issues.apache.org/jira/browse/MRESOLVER-85 + Buffer asBuffer = currentByteBuffer; + try { + asBuffer.position(begin); + asBuffer.limit(end); + return currentByteBuffer.slice(); + } catch (IllegalArgumentException e) { + throw InvalidProtocolBufferException.truncatedMessage(); + } finally { + asBuffer.position(prevPos); + asBuffer.limit(prevLimit); + } + } + } } diff --git a/protobuf-api/src/main/java/com/google/protobuf/CodedOutputStream.java b/protobuf-api/src/main/java/com/google/protobuf/CodedOutputStream.java index 66d928e..eb97e57 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/CodedOutputStream.java +++ b/protobuf-api/src/main/java/com/google/protobuf/CodedOutputStream.java @@ -31,6 +31,7 @@ public abstract class CodedOutputStream extends ByteOutput { private static final Logger logger = Logger.getLogger(CodedOutputStream.class.getName()); static final boolean HAS_UNSAFE_ARRAY_OPERATIONS = UnsafeUtil.hasUnsafeArrayOperations(); private static final Class ARRAY_ENCODER = getClassForName("com.google.protobuf.ArrayEncoder"); + private static final Class ABSTRACT_BUFFERED_ENCODER = getClassForName("com.google.protobuf.AbstractBufferedEncoder"); private static final Class BYTE_OUTPUT_ENCODER = getClassForName("com.google.protobuf.ByteOutputEncoder"); private static final Class HEAP_NIO_ENCODER = getClassForName("com.google.protobuf.HeapNioEncoder"); private static final Class OUTPUT_STREAM_ENCODER = getClassForName("com.google.protobuf.OutputStreamEncoder"); diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/ArrayDecoder.java b/protobuf-sdk/src/main/java/com/google/protobuf/ArrayDecoder.java deleted file mode 100644 index f61f939..0000000 --- a/protobuf-sdk/src/main/java/com/google/protobuf/ArrayDecoder.java +++ /dev/null @@ -1,672 +0,0 @@ -package com.google.protobuf; - -import java.io.IOException; -import java.nio.ByteBuffer; -import java.util.Arrays; - -import static com.google.protobuf.Internal.EMPTY_BYTE_BUFFER; -import static com.google.protobuf.Internal.UTF_8; -import static com.google.protobuf.WireFormat.*; -import static com.google.protobuf.WireFormat.FIXED64_SIZE; - - -/** A {@link CodedInputStream} implementation that uses a backing array as the input. */ -final class ArrayDecoder extends CodedInputStream { - private final byte[] buffer; - private final boolean immutable; - private int limit; - private int bufferSizeAfterLimit; - private int pos; - private int startPos; - private int lastTag; - private boolean enableAliasing; - - /** The absolute position of the end of the current message. */ - private int currentLimit = Integer.MAX_VALUE; - - ArrayDecoder(final byte[] buffer, final int offset, final int len, boolean immutable) { - super(); - this.buffer = buffer; - limit = offset + len; - pos = offset; - startPos = pos; - this.immutable = immutable; - } - - @Override - public int readTag() throws IOException { - if (isAtEnd()) { - lastTag = 0; - return 0; - } - - lastTag = readRawVarint32(); - if (WireFormat.getTagFieldNumber(lastTag) == 0) { - // If we actually read zero (or any tag number corresponding to field - // number zero), that's not a valid tag. - throw InvalidProtocolBufferException.invalidTag(); - } - return lastTag; - } - - @Override - public void checkLastTagWas(final int value) throws InvalidProtocolBufferException { - if (lastTag != value) { - throw InvalidProtocolBufferException.invalidEndTag(); - } - } - - @Override - public int getLastTag() { - return lastTag; - } - - @Override - public boolean skipField(final int tag) throws IOException { - switch (WireFormat.getTagWireType(tag)) { - case WireFormat.WIRETYPE_VARINT: - skipRawVarint(); - return true; - case WireFormat.WIRETYPE_FIXED64: - skipRawBytes(FIXED64_SIZE); - return true; - case WireFormat.WIRETYPE_LENGTH_DELIMITED: - skipRawBytes(readRawVarint32()); - return true; - case WireFormat.WIRETYPE_START_GROUP: - skipMessage(); - checkLastTagWas( - WireFormat.makeTag(WireFormat.getTagFieldNumber(tag), WireFormat.WIRETYPE_END_GROUP)); - return true; - case WireFormat.WIRETYPE_END_GROUP: - return false; - case WireFormat.WIRETYPE_FIXED32: - skipRawBytes(FIXED32_SIZE); - return true; - default: - throw InvalidProtocolBufferException.invalidWireType(); - } - } - - @Override - public boolean skipField(final int tag, final CodedOutputStream output) throws IOException { - switch (WireFormat.getTagWireType(tag)) { - case WireFormat.WIRETYPE_VARINT: - { - long value = readInt64(); - output.writeUInt32NoTag(tag); - output.writeUInt64NoTag(value); - return true; - } - case WireFormat.WIRETYPE_FIXED64: - { - long value = readRawLittleEndian64(); - output.writeUInt32NoTag(tag); - output.writeFixed64NoTag(value); - return true; - } - case WireFormat.WIRETYPE_LENGTH_DELIMITED: - { - ByteString value = readBytes(); - output.writeUInt32NoTag(tag); - output.writeBytesNoTag(value); - return true; - } - case WireFormat.WIRETYPE_START_GROUP: - { - output.writeUInt32NoTag(tag); - skipMessage(output); - int endtag = - WireFormat.makeTag( - WireFormat.getTagFieldNumber(tag), WireFormat.WIRETYPE_END_GROUP); - checkLastTagWas(endtag); - output.writeUInt32NoTag(endtag); - return true; - } - case WireFormat.WIRETYPE_END_GROUP: - { - return false; - } - case WireFormat.WIRETYPE_FIXED32: - { - int value = readRawLittleEndian32(); - output.writeUInt32NoTag(tag); - output.writeFixed32NoTag(value); - return true; - } - default: - throw InvalidProtocolBufferException.invalidWireType(); - } - } - - // ----------------------------------------------------------------- - - @Override - public double readDouble() throws IOException { - return Double.longBitsToDouble(readRawLittleEndian64()); - } - - @Override - public float readFloat() throws IOException { - return Float.intBitsToFloat(readRawLittleEndian32()); - } - - @Override - public long readUInt64() throws IOException { - return readRawVarint64(); - } - - @Override - public long readInt64() throws IOException { - return readRawVarint64(); - } - - @Override - public int readInt32() throws IOException { - return readRawVarint32(); - } - - @Override - public long readFixed64() throws IOException { - return readRawLittleEndian64(); - } - - @Override - public int readFixed32() throws IOException { - return readRawLittleEndian32(); - } - - @Override - public boolean readBool() throws IOException { - return readRawVarint64() != 0; - } - - @Override - public String readString() throws IOException { - final int size = readRawVarint32(); - if (size > 0 && size <= (limit - pos)) { - // Fast path: We already have the bytes in a contiguous buffer, so - // just copy directly from it. - final String result = new String(buffer, pos, size, UTF_8); - pos += size; - return result; - } - - if (size == 0) { - return ""; - } - if (size < 0) { - throw InvalidProtocolBufferException.negativeSize(); - } - throw InvalidProtocolBufferException.truncatedMessage(); - } - - @Override - public String readStringRequireUtf8() throws IOException { - final int size = readRawVarint32(); - if (size > 0 && size <= (limit - pos)) { - String result = Utf8.decodeUtf8(buffer, pos, size); - pos += size; - return result; - } - - if (size == 0) { - return ""; - } - if (size <= 0) { - throw InvalidProtocolBufferException.negativeSize(); - } - throw InvalidProtocolBufferException.truncatedMessage(); - } - - @Override - public void readGroup( - final int fieldNumber, - final MessageLite.Builder builder, - final ExtensionRegistryLite extensionRegistry) - throws IOException { - checkRecursionLimit(); - ++recursionDepth; - builder.mergeFrom(this, extensionRegistry); - checkLastTagWas(WireFormat.makeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP)); - --recursionDepth; - } - - @Override - public T readGroup( - final int fieldNumber, - final Parser parser, - final ExtensionRegistryLite extensionRegistry) - throws IOException { - checkRecursionLimit(); - ++recursionDepth; - T result = parser.parsePartialFrom(this, extensionRegistry); - checkLastTagWas(WireFormat.makeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP)); - --recursionDepth; - return result; - } - - @Deprecated - @Override - public void readUnknownGroup(final int fieldNumber, final MessageLite.Builder builder) - throws IOException { - readGroup(fieldNumber, builder, ExtensionRegistryLite.getEmptyRegistry()); - } - - @Override - public void readMessage( - final MessageLite.Builder builder, final ExtensionRegistryLite extensionRegistry) - throws IOException { - final int length = readRawVarint32(); - checkRecursionLimit(); - final int oldLimit = pushLimit(length); - ++recursionDepth; - builder.mergeFrom(this, extensionRegistry); - checkLastTagWas(0); - --recursionDepth; - if (getBytesUntilLimit() != 0) { - throw InvalidProtocolBufferException.truncatedMessage(); - } - popLimit(oldLimit); - } - - @Override - public T readMessage( - final Parser parser, final ExtensionRegistryLite extensionRegistry) throws IOException { - int length = readRawVarint32(); - checkRecursionLimit(); - final int oldLimit = pushLimit(length); - ++recursionDepth; - T result = parser.parsePartialFrom(this, extensionRegistry); - checkLastTagWas(0); - --recursionDepth; - if (getBytesUntilLimit() != 0) { - throw InvalidProtocolBufferException.truncatedMessage(); - } - popLimit(oldLimit); - return result; - } - - @Override - public ByteString readBytes() throws IOException { - final int size = readRawVarint32(); - if (size > 0 && size <= (limit - pos)) { - // Fast path: We already have the bytes in a contiguous buffer, so - // just copy directly from it. - final ByteString result = - immutable && enableAliasing - ? ByteString.wrap(buffer, pos, size) - : ByteString.copyFrom(buffer, pos, size); - pos += size; - return result; - } - if (size == 0) { - return ByteString.EMPTY; - } - // Slow path: Build a byte array first then copy it. - return ByteString.wrap(readRawBytes(size)); - } - - @Override - public byte[] readByteArray() throws IOException { - final int size = readRawVarint32(); - return readRawBytes(size); - } - - @Override - public ByteBuffer readByteBuffer() throws IOException { - final int size = readRawVarint32(); - if (size > 0 && size <= (limit - pos)) { - // Fast path: We already have the bytes in a contiguous buffer. - // When aliasing is enabled, we can return a ByteBuffer pointing directly - // into the underlying byte array without copy if the CodedInputStream is - // constructed from a byte array. If aliasing is disabled or the input is - // from an InputStream or ByteString, we have to make a copy of the bytes. - ByteBuffer result = - !immutable && enableAliasing - ? ByteBuffer.wrap(buffer, pos, size).slice() - : ByteBuffer.wrap(Arrays.copyOfRange(buffer, pos, pos + size)); - pos += size; - // TODO: Investigate making the ByteBuffer be made read-only - return result; - } - - if (size == 0) { - return EMPTY_BYTE_BUFFER; - } - if (size < 0) { - throw InvalidProtocolBufferException.negativeSize(); - } - throw InvalidProtocolBufferException.truncatedMessage(); - } - - @Override - public int readUInt32() throws IOException { - return readRawVarint32(); - } - - @Override - public int readEnum() throws IOException { - return readRawVarint32(); - } - - @Override - public int readSFixed32() throws IOException { - return readRawLittleEndian32(); - } - - @Override - public long readSFixed64() throws IOException { - return readRawLittleEndian64(); - } - - @Override - public int readSInt32() throws IOException { - return decodeZigZag32(readRawVarint32()); - } - - @Override - public long readSInt64() throws IOException { - return decodeZigZag64(readRawVarint64()); - } - - // ================================================================= - - @Override - public int readRawVarint32() throws IOException { - // See implementation notes for readRawVarint64 - fastpath: - { - int tempPos = pos; - - if (limit == tempPos) { - break fastpath; - } - - final byte[] buffer = this.buffer; - int x; - if ((x = buffer[tempPos++]) >= 0) { - pos = tempPos; - return x; - } else if (limit - tempPos < 9) { - break fastpath; - } else if ((x ^= (buffer[tempPos++] << 7)) < 0) { - x ^= (~0 << 7); - } else if ((x ^= (buffer[tempPos++] << 14)) >= 0) { - x ^= (~0 << 7) ^ (~0 << 14); - } else if ((x ^= (buffer[tempPos++] << 21)) < 0) { - x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21); - } else { - int y = buffer[tempPos++]; - x ^= y << 28; - x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21) ^ (~0 << 28); - if (y < 0 - && buffer[tempPos++] < 0 - && buffer[tempPos++] < 0 - && buffer[tempPos++] < 0 - && buffer[tempPos++] < 0 - && buffer[tempPos++] < 0) { - break fastpath; // Will throw malformedVarint() - } - } - pos = tempPos; - return x; - } - return (int) readRawVarint64SlowPath(); - } - - private void skipRawVarint() throws IOException { - if (limit - pos >= MAX_VARINT_SIZE) { - skipRawVarintFastPath(); - } else { - skipRawVarintSlowPath(); - } - } - - private void skipRawVarintFastPath() throws IOException { - for (int i = 0; i < MAX_VARINT_SIZE; i++) { - if (buffer[pos++] >= 0) { - return; - } - } - throw InvalidProtocolBufferException.malformedVarint(); - } - - private void skipRawVarintSlowPath() throws IOException { - for (int i = 0; i < MAX_VARINT_SIZE; i++) { - if (readRawByte() >= 0) { - return; - } - } - throw InvalidProtocolBufferException.malformedVarint(); - } - - @Override - public long readRawVarint64() throws IOException { - // Implementation notes: - // - // Optimized for one-byte values, expected to be common. - // The particular code below was selected from various candidates - // empirically, by winning VarintBenchmark. - // - // Sign extension of (signed) Java bytes is usually a nuisance, but - // we exploit it here to more easily obtain the sign of bytes read. - // Instead of cleaning up the sign extension bits by masking eagerly, - // we delay until we find the final (positive) byte, when we clear all - // accumulated bits with one xor. We depend on javac to constant fold. - fastpath: - { - int tempPos = pos; - - if (limit == tempPos) { - break fastpath; - } - - final byte[] buffer = this.buffer; - long x; - int y; - if ((y = buffer[tempPos++]) >= 0) { - pos = tempPos; - return y; - } else if (limit - tempPos < 9) { - break fastpath; - } else if ((y ^= (buffer[tempPos++] << 7)) < 0) { - x = y ^ (~0 << 7); - } else if ((y ^= (buffer[tempPos++] << 14)) >= 0) { - x = y ^ ((~0 << 7) ^ (~0 << 14)); - } else if ((y ^= (buffer[tempPos++] << 21)) < 0) { - x = y ^ ((~0 << 7) ^ (~0 << 14) ^ (~0 << 21)); - } else if ((x = y ^ ((long) buffer[tempPos++] << 28)) >= 0L) { - x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28); - } else if ((x ^= ((long) buffer[tempPos++] << 35)) < 0L) { - x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35); - } else if ((x ^= ((long) buffer[tempPos++] << 42)) >= 0L) { - x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35) ^ (~0L << 42); - } else if ((x ^= ((long) buffer[tempPos++] << 49)) < 0L) { - x ^= - (~0L << 7) - ^ (~0L << 14) - ^ (~0L << 21) - ^ (~0L << 28) - ^ (~0L << 35) - ^ (~0L << 42) - ^ (~0L << 49); - } else { - x ^= ((long) buffer[tempPos++] << 56); - x ^= - (~0L << 7) - ^ (~0L << 14) - ^ (~0L << 21) - ^ (~0L << 28) - ^ (~0L << 35) - ^ (~0L << 42) - ^ (~0L << 49) - ^ (~0L << 56); - if (x < 0L) { - if (buffer[tempPos++] < 0L) { - break fastpath; // Will throw malformedVarint() - } - } - } - pos = tempPos; - return x; - } - return readRawVarint64SlowPath(); - } - - @Override - long readRawVarint64SlowPath() throws IOException { - long result = 0; - for (int shift = 0; shift < 64; shift += 7) { - final byte b = readRawByte(); - result |= (long) (b & 0x7F) << shift; - if ((b & 0x80) == 0) { - return result; - } - } - throw InvalidProtocolBufferException.malformedVarint(); - } - - @Override - public int readRawLittleEndian32() throws IOException { - int tempPos = pos; - - if (limit - tempPos < FIXED32_SIZE) { - throw InvalidProtocolBufferException.truncatedMessage(); - } - - final byte[] buffer = this.buffer; - pos = tempPos + FIXED32_SIZE; - return ((buffer[tempPos] & 0xff) - | ((buffer[tempPos + 1] & 0xff) << 8) - | ((buffer[tempPos + 2] & 0xff) << 16) - | ((buffer[tempPos + 3] & 0xff) << 24)); - } - - @Override - public long readRawLittleEndian64() throws IOException { - int tempPos = pos; - - if (limit - tempPos < FIXED64_SIZE) { - throw InvalidProtocolBufferException.truncatedMessage(); - } - - final byte[] buffer = this.buffer; - pos = tempPos + FIXED64_SIZE; - return ((buffer[tempPos] & 0xffL) - | ((buffer[tempPos + 1] & 0xffL) << 8) - | ((buffer[tempPos + 2] & 0xffL) << 16) - | ((buffer[tempPos + 3] & 0xffL) << 24) - | ((buffer[tempPos + 4] & 0xffL) << 32) - | ((buffer[tempPos + 5] & 0xffL) << 40) - | ((buffer[tempPos + 6] & 0xffL) << 48) - | ((buffer[tempPos + 7] & 0xffL) << 56)); - } - - @Override - public void enableAliasing(boolean enabled) { - this.enableAliasing = enabled; - } - - @Override - public void resetSizeCounter() { - startPos = pos; - } - - @Override - public int pushLimit(int byteLimit) throws InvalidProtocolBufferException { - if (byteLimit < 0) { - throw InvalidProtocolBufferException.negativeSize(); - } - byteLimit += getTotalBytesRead(); - if (byteLimit < 0) { - throw InvalidProtocolBufferException.parseFailure(); - } - final int oldLimit = currentLimit; - if (byteLimit > oldLimit) { - throw InvalidProtocolBufferException.truncatedMessage(); - } - currentLimit = byteLimit; - - recomputeBufferSizeAfterLimit(); - - return oldLimit; - } - - private void recomputeBufferSizeAfterLimit() { - limit += bufferSizeAfterLimit; - final int bufferEnd = limit - startPos; - if (bufferEnd > currentLimit) { - // Limit is in current buffer. - bufferSizeAfterLimit = bufferEnd - currentLimit; - limit -= bufferSizeAfterLimit; - } else { - bufferSizeAfterLimit = 0; - } - } - - @Override - public void popLimit(final int oldLimit) { - currentLimit = oldLimit; - recomputeBufferSizeAfterLimit(); - } - - @Override - public int getBytesUntilLimit() { - if (currentLimit == Integer.MAX_VALUE) { - return -1; - } - - return currentLimit - getTotalBytesRead(); - } - - @Override - public boolean isAtEnd() throws IOException { - return pos == limit; - } - - @Override - public int getTotalBytesRead() { - return pos - startPos; - } - - @Override - public byte readRawByte() throws IOException { - if (pos == limit) { - throw InvalidProtocolBufferException.truncatedMessage(); - } - return buffer[pos++]; - } - - @Override - public byte[] readRawBytes(final int length) throws IOException { - if (length > 0 && length <= (limit - pos)) { - final int tempPos = pos; - pos += length; - return Arrays.copyOfRange(buffer, tempPos, pos); - } - - if (length <= 0) { - if (length == 0) { - return Internal.EMPTY_BYTE_ARRAY; - } else { - throw InvalidProtocolBufferException.negativeSize(); - } - } - throw InvalidProtocolBufferException.truncatedMessage(); - } - - @Override - public void skipRawBytes(final int length) throws IOException { - if (length >= 0 && length <= (limit - pos)) { - // We have all the bytes we need already. - pos += length; - return; - } - - if (length < 0) { - throw InvalidProtocolBufferException.negativeSize(); - } - throw InvalidProtocolBufferException.truncatedMessage(); - } -} \ No newline at end of file diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/IterableDirectByteBufferDecoder.java b/protobuf-sdk/src/main/java/com/google/protobuf/IterableDirectByteBufferDecoder.java deleted file mode 100644 index af8e6d9..0000000 --- a/protobuf-sdk/src/main/java/com/google/protobuf/IterableDirectByteBufferDecoder.java +++ /dev/null @@ -1,835 +0,0 @@ -package com.google.protobuf; - -import java.io.IOException; -import java.nio.Buffer; -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.Iterator; - -import static com.google.protobuf.Internal.*; -import static com.google.protobuf.WireFormat.*; - -/** - * Implementation of {@link CodedInputStream} that uses an {@link Iterable } as the - * data source. Requires the use of {@code sun.misc.Unsafe} to perform fast reads on the buffer. - */ -final class IterableDirectByteBufferDecoder extends CodedInputStream { - /** The object that need to decode. */ - private final Iterable input; - /** The {@link Iterator} with type {@link ByteBuffer} of {@code input} */ - private final Iterator iterator; - /** The current ByteBuffer; */ - private ByteBuffer currentByteBuffer; - /** - * If {@code true}, indicates that all the buffers are backing a {@link ByteString} and are - * therefore considered to be an immutable input source. - */ - private final boolean immutable; - /** - * If {@code true}, indicates that calls to read {@link ByteString} or {@code byte[]} - * may return slices of the underlying buffer, rather than copies. - */ - private boolean enableAliasing; - /** The global total message length limit */ - private int totalBufferSize; - /** The amount of available data in the input beyond {@link #currentLimit}. */ - private int bufferSizeAfterCurrentLimit; - /** The absolute position of the end of the current message. */ - private int currentLimit = Integer.MAX_VALUE; - /** The last tag that was read from this stream. */ - private int lastTag; - /** Total Bytes have been Read from the {@link Iterable} {@link ByteBuffer} */ - private int totalBytesRead; - /** The start position offset of the whole message, used as to reset the totalBytesRead */ - private int startOffset; - /** The current position for current ByteBuffer */ - private long currentByteBufferPos; - - private long currentByteBufferStartPos; - /** - * If the current ByteBuffer is unsafe-direct based, currentAddress is the start address of this - * ByteBuffer; otherwise should be zero. - */ - private long currentAddress; - /** The limit position for current ByteBuffer */ - private long currentByteBufferLimit; - - /** - * The constructor of {@code Iterable} decoder. - * - * @param inputBufs The input data. - * @param size The total size of the input data. - * @param immutableFlag whether the input data is immutable. - */ - IterableDirectByteBufferDecoder( - Iterable inputBufs, int size, boolean immutableFlag) { - totalBufferSize = size; - input = inputBufs; - iterator = input.iterator(); - immutable = immutableFlag; - startOffset = totalBytesRead = 0; - if (size == 0) { - currentByteBuffer = EMPTY_BYTE_BUFFER; - currentByteBufferPos = 0; - currentByteBufferStartPos = 0; - currentByteBufferLimit = 0; - currentAddress = 0; - } else { - tryGetNextByteBuffer(); - } - } - - /** To get the next ByteBuffer from {@code input}, and then update the parameters */ - private void getNextByteBuffer() throws InvalidProtocolBufferException { - if (!iterator.hasNext()) { - throw InvalidProtocolBufferException.truncatedMessage(); - } - tryGetNextByteBuffer(); - } - - private void tryGetNextByteBuffer() { - currentByteBuffer = iterator.next(); - totalBytesRead += (int) (currentByteBufferPos - currentByteBufferStartPos); - currentByteBufferPos = currentByteBuffer.position(); - currentByteBufferStartPos = currentByteBufferPos; - currentByteBufferLimit = currentByteBuffer.limit(); - currentAddress = UnsafeUtil.addressOffset(currentByteBuffer); - currentByteBufferPos += currentAddress; - currentByteBufferStartPos += currentAddress; - currentByteBufferLimit += currentAddress; - } - - @Override - public int readTag() throws IOException { - if (isAtEnd()) { - lastTag = 0; - return 0; - } - - lastTag = readRawVarint32(); - if (WireFormat.getTagFieldNumber(lastTag) == 0) { - // If we actually read zero (or any tag number corresponding to field - // number zero), that's not a valid tag. - throw InvalidProtocolBufferException.invalidTag(); - } - return lastTag; - } - - @Override - public void checkLastTagWas(final int value) throws InvalidProtocolBufferException { - if (lastTag != value) { - throw InvalidProtocolBufferException.invalidEndTag(); - } - } - - @Override - public int getLastTag() { - return lastTag; - } - - @Override - public boolean skipField(final int tag) throws IOException { - switch (WireFormat.getTagWireType(tag)) { - case WireFormat.WIRETYPE_VARINT: - skipRawVarint(); - return true; - case WireFormat.WIRETYPE_FIXED64: - skipRawBytes(FIXED64_SIZE); - return true; - case WireFormat.WIRETYPE_LENGTH_DELIMITED: - skipRawBytes(readRawVarint32()); - return true; - case WireFormat.WIRETYPE_START_GROUP: - skipMessage(); - checkLastTagWas( - WireFormat.makeTag(WireFormat.getTagFieldNumber(tag), WireFormat.WIRETYPE_END_GROUP)); - return true; - case WireFormat.WIRETYPE_END_GROUP: - return false; - case WireFormat.WIRETYPE_FIXED32: - skipRawBytes(FIXED32_SIZE); - return true; - default: - throw InvalidProtocolBufferException.invalidWireType(); - } - } - - @Override - public boolean skipField(final int tag, final CodedOutputStream output) throws IOException { - switch (WireFormat.getTagWireType(tag)) { - case WireFormat.WIRETYPE_VARINT: - { - long value = readInt64(); - output.writeUInt32NoTag(tag); - output.writeUInt64NoTag(value); - return true; - } - case WireFormat.WIRETYPE_FIXED64: - { - long value = readRawLittleEndian64(); - output.writeUInt32NoTag(tag); - output.writeFixed64NoTag(value); - return true; - } - case WireFormat.WIRETYPE_LENGTH_DELIMITED: - { - ByteString value = readBytes(); - output.writeUInt32NoTag(tag); - output.writeBytesNoTag(value); - return true; - } - case WireFormat.WIRETYPE_START_GROUP: - { - output.writeUInt32NoTag(tag); - skipMessage(output); - int endtag = - WireFormat.makeTag( - WireFormat.getTagFieldNumber(tag), WireFormat.WIRETYPE_END_GROUP); - checkLastTagWas(endtag); - output.writeUInt32NoTag(endtag); - return true; - } - case WireFormat.WIRETYPE_END_GROUP: - { - return false; - } - case WireFormat.WIRETYPE_FIXED32: - { - int value = readRawLittleEndian32(); - output.writeUInt32NoTag(tag); - output.writeFixed32NoTag(value); - return true; - } - default: - throw InvalidProtocolBufferException.invalidWireType(); - } - } - - // ----------------------------------------------------------------- - - @Override - public double readDouble() throws IOException { - return Double.longBitsToDouble(readRawLittleEndian64()); - } - - @Override - public float readFloat() throws IOException { - return Float.intBitsToFloat(readRawLittleEndian32()); - } - - @Override - public long readUInt64() throws IOException { - return readRawVarint64(); - } - - @Override - public long readInt64() throws IOException { - return readRawVarint64(); - } - - @Override - public int readInt32() throws IOException { - return readRawVarint32(); - } - - @Override - public long readFixed64() throws IOException { - return readRawLittleEndian64(); - } - - @Override - public int readFixed32() throws IOException { - return readRawLittleEndian32(); - } - - @Override - public boolean readBool() throws IOException { - return readRawVarint64() != 0; - } - - @Override - public String readString() throws IOException { - final int size = readRawVarint32(); - if (size > 0 && size <= currentByteBufferLimit - currentByteBufferPos) { - byte[] bytes = new byte[size]; - UnsafeUtil.copyMemory(currentByteBufferPos, bytes, 0, size); - String result = new String(bytes, UTF_8); - currentByteBufferPos += size; - return result; - } else if (size > 0 && size <= remaining()) { - // TODO: To use an underlying bytes[] instead of allocating a new bytes[] - byte[] bytes = new byte[size]; - readRawBytesTo(bytes, 0, size); - String result = new String(bytes, UTF_8); - return result; - } - - if (size == 0) { - return ""; - } - if (size < 0) { - throw InvalidProtocolBufferException.negativeSize(); - } - throw InvalidProtocolBufferException.truncatedMessage(); - } - - @Override - public String readStringRequireUtf8() throws IOException { - final int size = readRawVarint32(); - if (size > 0 && size <= currentByteBufferLimit - currentByteBufferPos) { - final int bufferPos = (int) (currentByteBufferPos - currentByteBufferStartPos); - String result = Utf8.decodeUtf8(currentByteBuffer, bufferPos, size); - currentByteBufferPos += size; - return result; - } - if (size >= 0 && size <= remaining()) { - byte[] bytes = new byte[size]; - readRawBytesTo(bytes, 0, size); - return Utf8.decodeUtf8(bytes, 0, size); - } - - if (size == 0) { - return ""; - } - if (size <= 0) { - throw InvalidProtocolBufferException.negativeSize(); - } - throw InvalidProtocolBufferException.truncatedMessage(); - } - - @Override - public void readGroup( - final int fieldNumber, - final MessageLite.Builder builder, - final ExtensionRegistryLite extensionRegistry) - throws IOException { - checkRecursionLimit(); - ++recursionDepth; - builder.mergeFrom(this, extensionRegistry); - checkLastTagWas(WireFormat.makeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP)); - --recursionDepth; - } - - @Override - public T readGroup( - final int fieldNumber, - final Parser parser, - final ExtensionRegistryLite extensionRegistry) - throws IOException { - checkRecursionLimit(); - ++recursionDepth; - T result = parser.parsePartialFrom(this, extensionRegistry); - checkLastTagWas(WireFormat.makeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP)); - --recursionDepth; - return result; - } - - @Deprecated - @Override - public void readUnknownGroup(final int fieldNumber, final MessageLite.Builder builder) - throws IOException { - readGroup(fieldNumber, builder, ExtensionRegistryLite.getEmptyRegistry()); - } - - @Override - public void readMessage( - final MessageLite.Builder builder, final ExtensionRegistryLite extensionRegistry) - throws IOException { - final int length = readRawVarint32(); - checkRecursionLimit(); - final int oldLimit = pushLimit(length); - ++recursionDepth; - builder.mergeFrom(this, extensionRegistry); - checkLastTagWas(0); - --recursionDepth; - if (getBytesUntilLimit() != 0) { - throw InvalidProtocolBufferException.truncatedMessage(); - } - popLimit(oldLimit); - } - - @Override - public T readMessage( - final Parser parser, final ExtensionRegistryLite extensionRegistry) throws IOException { - int length = readRawVarint32(); - checkRecursionLimit(); - final int oldLimit = pushLimit(length); - ++recursionDepth; - T result = parser.parsePartialFrom(this, extensionRegistry); - checkLastTagWas(0); - --recursionDepth; - if (getBytesUntilLimit() != 0) { - throw InvalidProtocolBufferException.truncatedMessage(); - } - popLimit(oldLimit); - return result; - } - - @Override - public ByteString readBytes() throws IOException { - final int size = readRawVarint32(); - if (size > 0 && size <= currentByteBufferLimit - currentByteBufferPos) { - if (immutable && enableAliasing) { - final int idx = (int) (currentByteBufferPos - currentAddress); - final ByteString result = ByteString.wrap(slice(idx, idx + size)); - currentByteBufferPos += size; - return result; - } else { - byte[] bytes = new byte[size]; - UnsafeUtil.copyMemory(currentByteBufferPos, bytes, 0, size); - currentByteBufferPos += size; - return ByteString.wrap(bytes); - } - } else if (size > 0 && size <= remaining()) { - if (immutable && enableAliasing) { - ArrayList byteStrings = new ArrayList<>(); - int l = size; - while (l > 0) { - if (currentRemaining() == 0) { - getNextByteBuffer(); - } - int bytesToCopy = Math.min(l, (int) currentRemaining()); - int idx = (int) (currentByteBufferPos - currentAddress); - byteStrings.add(ByteString.wrap(slice(idx, idx + bytesToCopy))); - l -= bytesToCopy; - currentByteBufferPos += bytesToCopy; - } - return ByteString.copyFrom(byteStrings); - } else { - byte[] temp = new byte[size]; - readRawBytesTo(temp, 0, size); - return ByteString.wrap(temp); - } - } - - if (size == 0) { - return ByteString.EMPTY; - } - if (size < 0) { - throw InvalidProtocolBufferException.negativeSize(); - } - throw InvalidProtocolBufferException.truncatedMessage(); - } - - @Override - public byte[] readByteArray() throws IOException { - return readRawBytes(readRawVarint32()); - } - - @Override - public ByteBuffer readByteBuffer() throws IOException { - final int size = readRawVarint32(); - if (size > 0 && size <= currentRemaining()) { - if (!immutable && enableAliasing) { - currentByteBufferPos += size; - return slice( - (int) (currentByteBufferPos - currentAddress - size), - (int) (currentByteBufferPos - currentAddress)); - } else { - byte[] bytes = new byte[size]; - UnsafeUtil.copyMemory(currentByteBufferPos, bytes, 0, size); - currentByteBufferPos += size; - return ByteBuffer.wrap(bytes); - } - } else if (size > 0 && size <= remaining()) { - byte[] temp = new byte[size]; - readRawBytesTo(temp, 0, size); - return ByteBuffer.wrap(temp); - } - - if (size == 0) { - return EMPTY_BYTE_BUFFER; - } - if (size < 0) { - throw InvalidProtocolBufferException.negativeSize(); - } - throw InvalidProtocolBufferException.truncatedMessage(); - } - - @Override - public int readUInt32() throws IOException { - return readRawVarint32(); - } - - @Override - public int readEnum() throws IOException { - return readRawVarint32(); - } - - @Override - public int readSFixed32() throws IOException { - return readRawLittleEndian32(); - } - - @Override - public long readSFixed64() throws IOException { - return readRawLittleEndian64(); - } - - @Override - public int readSInt32() throws IOException { - return decodeZigZag32(readRawVarint32()); - } - - @Override - public long readSInt64() throws IOException { - return decodeZigZag64(readRawVarint64()); - } - - @Override - public int readRawVarint32() throws IOException { - fastpath: - { - long tempPos = currentByteBufferPos; - - if (currentByteBufferLimit == currentByteBufferPos) { - break fastpath; - } - - int x; - if ((x = UnsafeUtil.getByte(tempPos++)) >= 0) { - currentByteBufferPos++; - return x; - } else if (currentByteBufferLimit - currentByteBufferPos < 10) { - break fastpath; - } else if ((x ^= (UnsafeUtil.getByte(tempPos++) << 7)) < 0) { - x ^= (~0 << 7); - } else if ((x ^= (UnsafeUtil.getByte(tempPos++) << 14)) >= 0) { - x ^= (~0 << 7) ^ (~0 << 14); - } else if ((x ^= (UnsafeUtil.getByte(tempPos++) << 21)) < 0) { - x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21); - } else { - int y = UnsafeUtil.getByte(tempPos++); - x ^= y << 28; - x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21) ^ (~0 << 28); - if (y < 0 - && UnsafeUtil.getByte(tempPos++) < 0 - && UnsafeUtil.getByte(tempPos++) < 0 - && UnsafeUtil.getByte(tempPos++) < 0 - && UnsafeUtil.getByte(tempPos++) < 0 - && UnsafeUtil.getByte(tempPos++) < 0) { - break fastpath; // Will throw malformedVarint() - } - } - currentByteBufferPos = tempPos; - return x; - } - return (int) readRawVarint64SlowPath(); - } - - @Override - public long readRawVarint64() throws IOException { - fastpath: - { - long tempPos = currentByteBufferPos; - - if (currentByteBufferLimit == currentByteBufferPos) { - break fastpath; - } - - long x; - int y; - if ((y = UnsafeUtil.getByte(tempPos++)) >= 0) { - currentByteBufferPos++; - return y; - } else if (currentByteBufferLimit - currentByteBufferPos < 10) { - break fastpath; - } else if ((y ^= (UnsafeUtil.getByte(tempPos++) << 7)) < 0) { - x = y ^ (~0 << 7); - } else if ((y ^= (UnsafeUtil.getByte(tempPos++) << 14)) >= 0) { - x = y ^ ((~0 << 7) ^ (~0 << 14)); - } else if ((y ^= (UnsafeUtil.getByte(tempPos++) << 21)) < 0) { - x = y ^ ((~0 << 7) ^ (~0 << 14) ^ (~0 << 21)); - } else if ((x = y ^ ((long) UnsafeUtil.getByte(tempPos++) << 28)) >= 0L) { - x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28); - } else if ((x ^= ((long) UnsafeUtil.getByte(tempPos++) << 35)) < 0L) { - x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35); - } else if ((x ^= ((long) UnsafeUtil.getByte(tempPos++) << 42)) >= 0L) { - x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35) ^ (~0L << 42); - } else if ((x ^= ((long) UnsafeUtil.getByte(tempPos++) << 49)) < 0L) { - x ^= - (~0L << 7) - ^ (~0L << 14) - ^ (~0L << 21) - ^ (~0L << 28) - ^ (~0L << 35) - ^ (~0L << 42) - ^ (~0L << 49); - } else { - x ^= ((long) UnsafeUtil.getByte(tempPos++) << 56); - x ^= - (~0L << 7) - ^ (~0L << 14) - ^ (~0L << 21) - ^ (~0L << 28) - ^ (~0L << 35) - ^ (~0L << 42) - ^ (~0L << 49) - ^ (~0L << 56); - if (x < 0L) { - if (UnsafeUtil.getByte(tempPos++) < 0L) { - break fastpath; // Will throw malformedVarint() - } - } - } - currentByteBufferPos = tempPos; - return x; - } - return readRawVarint64SlowPath(); - } - - @Override - long readRawVarint64SlowPath() throws IOException { - long result = 0; - for (int shift = 0; shift < 64; shift += 7) { - final byte b = readRawByte(); - result |= (long) (b & 0x7F) << shift; - if ((b & 0x80) == 0) { - return result; - } - } - throw InvalidProtocolBufferException.malformedVarint(); - } - - @Override - public int readRawLittleEndian32() throws IOException { - if (currentRemaining() >= FIXED32_SIZE) { - long tempPos = currentByteBufferPos; - currentByteBufferPos += FIXED32_SIZE; - return ((UnsafeUtil.getByte(tempPos) & 0xff) - | ((UnsafeUtil.getByte(tempPos + 1) & 0xff) << 8) - | ((UnsafeUtil.getByte(tempPos + 2) & 0xff) << 16) - | ((UnsafeUtil.getByte(tempPos + 3) & 0xff) << 24)); - } - return ((readRawByte() & 0xff) - | ((readRawByte() & 0xff) << 8) - | ((readRawByte() & 0xff) << 16) - | ((readRawByte() & 0xff) << 24)); - } - - @Override - public long readRawLittleEndian64() throws IOException { - if (currentRemaining() >= FIXED64_SIZE) { - long tempPos = currentByteBufferPos; - currentByteBufferPos += FIXED64_SIZE; - return ((UnsafeUtil.getByte(tempPos) & 0xffL) - | ((UnsafeUtil.getByte(tempPos + 1) & 0xffL) << 8) - | ((UnsafeUtil.getByte(tempPos + 2) & 0xffL) << 16) - | ((UnsafeUtil.getByte(tempPos + 3) & 0xffL) << 24) - | ((UnsafeUtil.getByte(tempPos + 4) & 0xffL) << 32) - | ((UnsafeUtil.getByte(tempPos + 5) & 0xffL) << 40) - | ((UnsafeUtil.getByte(tempPos + 6) & 0xffL) << 48) - | ((UnsafeUtil.getByte(tempPos + 7) & 0xffL) << 56)); - } - return ((readRawByte() & 0xffL) - | ((readRawByte() & 0xffL) << 8) - | ((readRawByte() & 0xffL) << 16) - | ((readRawByte() & 0xffL) << 24) - | ((readRawByte() & 0xffL) << 32) - | ((readRawByte() & 0xffL) << 40) - | ((readRawByte() & 0xffL) << 48) - | ((readRawByte() & 0xffL) << 56)); - } - - @Override - public void enableAliasing(boolean enabled) { - this.enableAliasing = enabled; - } - - @Override - public void resetSizeCounter() { - startOffset = (int) (totalBytesRead + currentByteBufferPos - currentByteBufferStartPos); - } - - @Override - public int pushLimit(int byteLimit) throws InvalidProtocolBufferException { - if (byteLimit < 0) { - throw InvalidProtocolBufferException.negativeSize(); - } - byteLimit += getTotalBytesRead(); - final int oldLimit = currentLimit; - if (byteLimit > oldLimit) { - throw InvalidProtocolBufferException.truncatedMessage(); - } - currentLimit = byteLimit; - - recomputeBufferSizeAfterLimit(); - - return oldLimit; - } - - private void recomputeBufferSizeAfterLimit() { - totalBufferSize += bufferSizeAfterCurrentLimit; - final int bufferEnd = totalBufferSize - startOffset; - if (bufferEnd > currentLimit) { - // Limit is in current buffer. - bufferSizeAfterCurrentLimit = bufferEnd - currentLimit; - totalBufferSize -= bufferSizeAfterCurrentLimit; - } else { - bufferSizeAfterCurrentLimit = 0; - } - } - - @Override - public void popLimit(final int oldLimit) { - currentLimit = oldLimit; - recomputeBufferSizeAfterLimit(); - } - - @Override - public int getBytesUntilLimit() { - if (currentLimit == Integer.MAX_VALUE) { - return -1; - } - - return currentLimit - getTotalBytesRead(); - } - - @Override - public boolean isAtEnd() throws IOException { - return totalBytesRead + currentByteBufferPos - currentByteBufferStartPos == totalBufferSize; - } - - @Override - public int getTotalBytesRead() { - return (int) - (totalBytesRead - startOffset + currentByteBufferPos - currentByteBufferStartPos); - } - - @Override - public byte readRawByte() throws IOException { - if (currentRemaining() == 0) { - getNextByteBuffer(); - } - return UnsafeUtil.getByte(currentByteBufferPos++); - } - - @Override - public byte[] readRawBytes(final int length) throws IOException { - if (length >= 0 && length <= currentRemaining()) { - byte[] bytes = new byte[length]; - UnsafeUtil.copyMemory(currentByteBufferPos, bytes, 0, length); - currentByteBufferPos += length; - return bytes; - } - if (length >= 0 && length <= remaining()) { - byte[] bytes = new byte[length]; - readRawBytesTo(bytes, 0, length); - return bytes; - } - - if (length <= 0) { - if (length == 0) { - return EMPTY_BYTE_ARRAY; - } else { - throw InvalidProtocolBufferException.negativeSize(); - } - } - - throw InvalidProtocolBufferException.truncatedMessage(); - } - - /** - * Try to get raw bytes from {@code input} with the size of {@code length} and copy to {@code - * bytes} array. If the size is bigger than the number of remaining bytes in the input, then - * throw {@code truncatedMessage} exception. - */ - private void readRawBytesTo(byte[] bytes, int offset, final int length) throws IOException { - if (length >= 0 && length <= remaining()) { - int l = length; - while (l > 0) { - if (currentRemaining() == 0) { - getNextByteBuffer(); - } - int bytesToCopy = Math.min(l, (int) currentRemaining()); - UnsafeUtil.copyMemory(currentByteBufferPos, bytes, length - l + offset, bytesToCopy); - l -= bytesToCopy; - currentByteBufferPos += bytesToCopy; - } - return; - } - - if (length <= 0) { - if (length == 0) { - return; - } else { - throw InvalidProtocolBufferException.negativeSize(); - } - } - throw InvalidProtocolBufferException.truncatedMessage(); - } - - @Override - public void skipRawBytes(final int length) throws IOException { - if (length >= 0 - && length - <= (totalBufferSize - - totalBytesRead - - currentByteBufferPos - + currentByteBufferStartPos)) { - // We have all the bytes we need already. - int l = length; - while (l > 0) { - if (currentRemaining() == 0) { - getNextByteBuffer(); - } - int rl = Math.min(l, (int) currentRemaining()); - l -= rl; - currentByteBufferPos += rl; - } - return; - } - - if (length < 0) { - throw InvalidProtocolBufferException.negativeSize(); - } - throw InvalidProtocolBufferException.truncatedMessage(); - } - - // TODO: optimize to fastpath - private void skipRawVarint() throws IOException { - for (int i = 0; i < MAX_VARINT_SIZE; i++) { - if (readRawByte() >= 0) { - return; - } - } - throw InvalidProtocolBufferException.malformedVarint(); - } - - /** - * Try to get the number of remaining bytes in {@code input}. - * - * @return the number of remaining bytes in {@code input}. - */ - private int remaining() { - return (int) - (totalBufferSize - totalBytesRead - currentByteBufferPos + currentByteBufferStartPos); - } - - /** - * Try to get the number of remaining bytes in {@code currentByteBuffer}. - * - * @return the number of remaining bytes in {@code currentByteBuffer} - */ - private long currentRemaining() { - return (currentByteBufferLimit - currentByteBufferPos); - } - - private ByteBuffer slice(int begin, int end) throws IOException { - int prevPos = currentByteBuffer.position(); - int prevLimit = currentByteBuffer.limit(); - // View ByteBuffer as Buffer to avoid cross-Java version issues. - // See https://issues.apache.org/jira/browse/MRESOLVER-85 - Buffer asBuffer = currentByteBuffer; - try { - asBuffer.position(begin); - asBuffer.limit(end); - return currentByteBuffer.slice(); - } catch (IllegalArgumentException e) { - throw InvalidProtocolBufferException.truncatedMessage(); - } finally { - asBuffer.position(prevPos); - asBuffer.limit(prevLimit); - } - } -} \ No newline at end of file diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/StreamDecoder.java b/protobuf-sdk/src/main/java/com/google/protobuf/StreamDecoder.java deleted file mode 100644 index 9ce5786..0000000 --- a/protobuf-sdk/src/main/java/com/google/protobuf/StreamDecoder.java +++ /dev/null @@ -1,1106 +0,0 @@ -package com.google.protobuf; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import static com.google.protobuf.Internal.UTF_8; -import static com.google.protobuf.Internal.checkNotNull; -import static com.google.protobuf.WireFormat.*; -import static com.google.protobuf.WireFormat.FIXED64_SIZE; - -/** - * Implementation of {@link CodedInputStream} that uses an {@link InputStream} as the data source. - */ -final class StreamDecoder extends CodedInputStream { - private final InputStream input; - private final byte[] buffer; - /** bufferSize represents how many bytes are currently filled in the buffer */ - private int bufferSize; - - private int bufferSizeAfterLimit; - private int pos; - private int lastTag; - - /** - * The total number of bytes read before the current buffer. The total bytes read up to the - * current position can be computed as {@code totalBytesRetired + pos}. This value may be - * negative if reading started in the middle of the current buffer (e.g. if the constructor that - * takes a byte array and an offset was used). - */ - private int totalBytesRetired; - - /** The absolute position of the end of the current message. */ - private int currentLimit = Integer.MAX_VALUE; - - StreamDecoder(final InputStream input, int bufferSize) { - checkNotNull(input, "input"); - this.input = input; - this.buffer = new byte[bufferSize]; - this.bufferSize = 0; - pos = 0; - totalBytesRetired = 0; - } - - /* - * The following wrapper methods exist so that InvalidProtocolBufferExceptions thrown by the - * InputStream can be differentiated from ones thrown by CodedInputStream itself. Each call to - * an InputStream method that can throw IOException must be wrapped like this. We do this - * because we sometimes need to modify IPBE instances after they are thrown far away from where - * they are thrown (ex. to add unfinished messages) and we use this signal elsewhere in the - * exception catch chain to know when to perform these operations directly or to wrap the - * exception in their own IPBE so the extra information can be communicated without trampling - * downstream information. - */ - private static int read(InputStream input, byte[] data, int offset, int length) - throws IOException { - try { - return input.read(data, offset, length); - } catch (InvalidProtocolBufferException e) { - e.setThrownFromInputStream(); - throw e; - } - } - - private static long skip(InputStream input, long length) throws IOException { - try { - return input.skip(length); - } catch (InvalidProtocolBufferException e) { - e.setThrownFromInputStream(); - throw e; - } - } - - private static int available(InputStream input) throws IOException { - try { - return input.available(); - } catch (InvalidProtocolBufferException e) { - e.setThrownFromInputStream(); - throw e; - } - } - - @Override - public int readTag() throws IOException { - if (isAtEnd()) { - lastTag = 0; - return 0; - } - - lastTag = readRawVarint32(); - if (WireFormat.getTagFieldNumber(lastTag) == 0) { - // If we actually read zero (or any tag number corresponding to field - // number zero), that's not a valid tag. - throw InvalidProtocolBufferException.invalidTag(); - } - return lastTag; - } - - @Override - public void checkLastTagWas(final int value) throws InvalidProtocolBufferException { - if (lastTag != value) { - throw InvalidProtocolBufferException.invalidEndTag(); - } - } - - @Override - public int getLastTag() { - return lastTag; - } - - @Override - public boolean skipField(final int tag) throws IOException { - switch (WireFormat.getTagWireType(tag)) { - case WireFormat.WIRETYPE_VARINT: - skipRawVarint(); - return true; - case WireFormat.WIRETYPE_FIXED64: - skipRawBytes(FIXED64_SIZE); - return true; - case WireFormat.WIRETYPE_LENGTH_DELIMITED: - skipRawBytes(readRawVarint32()); - return true; - case WireFormat.WIRETYPE_START_GROUP: - skipMessage(); - checkLastTagWas( - WireFormat.makeTag(WireFormat.getTagFieldNumber(tag), WireFormat.WIRETYPE_END_GROUP)); - return true; - case WireFormat.WIRETYPE_END_GROUP: - return false; - case WireFormat.WIRETYPE_FIXED32: - skipRawBytes(FIXED32_SIZE); - return true; - default: - throw InvalidProtocolBufferException.invalidWireType(); - } - } - - @Override - public boolean skipField(final int tag, final CodedOutputStream output) throws IOException { - switch (WireFormat.getTagWireType(tag)) { - case WireFormat.WIRETYPE_VARINT: - { - long value = readInt64(); - output.writeUInt32NoTag(tag); - output.writeUInt64NoTag(value); - return true; - } - case WireFormat.WIRETYPE_FIXED64: - { - long value = readRawLittleEndian64(); - output.writeUInt32NoTag(tag); - output.writeFixed64NoTag(value); - return true; - } - case WireFormat.WIRETYPE_LENGTH_DELIMITED: - { - ByteString value = readBytes(); - output.writeUInt32NoTag(tag); - output.writeBytesNoTag(value); - return true; - } - case WireFormat.WIRETYPE_START_GROUP: - { - output.writeUInt32NoTag(tag); - skipMessage(output); - int endtag = - WireFormat.makeTag( - WireFormat.getTagFieldNumber(tag), WireFormat.WIRETYPE_END_GROUP); - checkLastTagWas(endtag); - output.writeUInt32NoTag(endtag); - return true; - } - case WireFormat.WIRETYPE_END_GROUP: - { - return false; - } - case WireFormat.WIRETYPE_FIXED32: - { - int value = readRawLittleEndian32(); - output.writeUInt32NoTag(tag); - output.writeFixed32NoTag(value); - return true; - } - default: - throw InvalidProtocolBufferException.invalidWireType(); - } - } - - /** Collects the bytes skipped and returns the data in a ByteBuffer. */ - private class SkippedDataSink implements RefillCallback { - private int lastPos = pos; - private ByteArrayOutputStream byteArrayStream; - - @Override - public void onRefill() { - if (byteArrayStream == null) { - byteArrayStream = new ByteArrayOutputStream(); - } - byteArrayStream.write(buffer, lastPos, pos - lastPos); - lastPos = 0; - } - - /** Gets skipped data in a ByteBuffer. This method should only be called once. */ - ByteBuffer getSkippedData() { - if (byteArrayStream == null) { - return ByteBuffer.wrap(buffer, lastPos, pos - lastPos); - } else { - byteArrayStream.write(buffer, lastPos, pos); - return ByteBuffer.wrap(byteArrayStream.toByteArray()); - } - } - } - - // ----------------------------------------------------------------- - - @Override - public double readDouble() throws IOException { - return Double.longBitsToDouble(readRawLittleEndian64()); - } - - @Override - public float readFloat() throws IOException { - return Float.intBitsToFloat(readRawLittleEndian32()); - } - - @Override - public long readUInt64() throws IOException { - return readRawVarint64(); - } - - @Override - public long readInt64() throws IOException { - return readRawVarint64(); - } - - @Override - public int readInt32() throws IOException { - return readRawVarint32(); - } - - @Override - public long readFixed64() throws IOException { - return readRawLittleEndian64(); - } - - @Override - public int readFixed32() throws IOException { - return readRawLittleEndian32(); - } - - @Override - public boolean readBool() throws IOException { - return readRawVarint64() != 0; - } - - @Override - public String readString() throws IOException { - final int size = readRawVarint32(); - if (size > 0 && size <= (bufferSize - pos)) { - // Fast path: We already have the bytes in a contiguous buffer, so - // just copy directly from it. - final String result = new String(buffer, pos, size, UTF_8); - pos += size; - return result; - } - if (size == 0) { - return ""; - } - if (size < 0) { - throw InvalidProtocolBufferException.negativeSize(); - } - if (size <= bufferSize) { - refillBuffer(size); - String result = new String(buffer, pos, size, UTF_8); - pos += size; - return result; - } - // Slow path: Build a byte array first then copy it. - return new String(readRawBytesSlowPath(size, /* ensureNoLeakedReferences= */ false), UTF_8); - } - - @Override - public String readStringRequireUtf8() throws IOException { - final int size = readRawVarint32(); - final byte[] bytes; - final int oldPos = pos; - final int tempPos; - if (size <= (bufferSize - oldPos) && size > 0) { - // Fast path: We already have the bytes in a contiguous buffer, so - // just copy directly from it. - bytes = buffer; - pos = oldPos + size; - tempPos = oldPos; - } else if (size == 0) { - return ""; - } else if (size < 0) { - throw InvalidProtocolBufferException.negativeSize(); - } else if (size <= bufferSize) { - refillBuffer(size); - bytes = buffer; - tempPos = 0; - pos = tempPos + size; - } else { - // Slow path: Build a byte array first then copy it. - bytes = readRawBytesSlowPath(size, /* ensureNoLeakedReferences= */ false); - tempPos = 0; - } - return Utf8.decodeUtf8(bytes, tempPos, size); - } - - @Override - public void readGroup( - final int fieldNumber, - final MessageLite.Builder builder, - final ExtensionRegistryLite extensionRegistry) - throws IOException { - checkRecursionLimit(); - ++recursionDepth; - builder.mergeFrom(this, extensionRegistry); - checkLastTagWas(WireFormat.makeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP)); - --recursionDepth; - } - - @Override - public T readGroup( - final int fieldNumber, - final Parser parser, - final ExtensionRegistryLite extensionRegistry) - throws IOException { - checkRecursionLimit(); - ++recursionDepth; - T result = parser.parsePartialFrom(this, extensionRegistry); - checkLastTagWas(WireFormat.makeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP)); - --recursionDepth; - return result; - } - - @Deprecated - @Override - public void readUnknownGroup(final int fieldNumber, final MessageLite.Builder builder) - throws IOException { - readGroup(fieldNumber, builder, ExtensionRegistryLite.getEmptyRegistry()); - } - - @Override - public void readMessage( - final MessageLite.Builder builder, final ExtensionRegistryLite extensionRegistry) - throws IOException { - final int length = readRawVarint32(); - checkRecursionLimit(); - final int oldLimit = pushLimit(length); - ++recursionDepth; - builder.mergeFrom(this, extensionRegistry); - checkLastTagWas(0); - --recursionDepth; - if (getBytesUntilLimit() != 0) { - throw InvalidProtocolBufferException.truncatedMessage(); - } - popLimit(oldLimit); - } - - @Override - public T readMessage( - final Parser parser, final ExtensionRegistryLite extensionRegistry) throws IOException { - int length = readRawVarint32(); - checkRecursionLimit(); - final int oldLimit = pushLimit(length); - ++recursionDepth; - T result = parser.parsePartialFrom(this, extensionRegistry); - checkLastTagWas(0); - --recursionDepth; - if (getBytesUntilLimit() != 0) { - throw InvalidProtocolBufferException.truncatedMessage(); - } - popLimit(oldLimit); - return result; - } - - @Override - public ByteString readBytes() throws IOException { - final int size = readRawVarint32(); - if (size <= (bufferSize - pos) && size > 0) { - // Fast path: We already have the bytes in a contiguous buffer, so - // just copy directly from it. - final ByteString result = ByteString.copyFrom(buffer, pos, size); - pos += size; - return result; - } - if (size == 0) { - return ByteString.EMPTY; - } - if (size < 0) { - throw InvalidProtocolBufferException.negativeSize(); - } - return readBytesSlowPath(size); - } - - @Override - public byte[] readByteArray() throws IOException { - final int size = readRawVarint32(); - if (size <= (bufferSize - pos) && size > 0) { - // Fast path: We already have the bytes in a contiguous buffer, so - // just copy directly from it. - final byte[] result = Arrays.copyOfRange(buffer, pos, pos + size); - pos += size; - return result; - } else if (size < 0) { - throw InvalidProtocolBufferException.negativeSize(); - } else { - // Slow path: Build a byte array first then copy it. - // TODO: Do we want to protect from malicious input streams here? - return readRawBytesSlowPath(size, /* ensureNoLeakedReferences= */ false); - } - } - - @Override - public ByteBuffer readByteBuffer() throws IOException { - final int size = readRawVarint32(); - if (size <= (bufferSize - pos) && size > 0) { - // Fast path: We already have the bytes in a contiguous buffer. - ByteBuffer result = ByteBuffer.wrap(Arrays.copyOfRange(buffer, pos, pos + size)); - pos += size; - return result; - } - if (size == 0) { - return Internal.EMPTY_BYTE_BUFFER; - } - if (size < 0) { - throw InvalidProtocolBufferException.negativeSize(); - } - // Slow path: Build a byte array first then copy it. - - // We must copy as the byte array was handed off to the InputStream and a malicious - // implementation could retain a reference. - return ByteBuffer.wrap(readRawBytesSlowPath(size, /* ensureNoLeakedReferences= */ true)); - } - - @Override - public int readUInt32() throws IOException { - return readRawVarint32(); - } - - @Override - public int readEnum() throws IOException { - return readRawVarint32(); - } - - @Override - public int readSFixed32() throws IOException { - return readRawLittleEndian32(); - } - - @Override - public long readSFixed64() throws IOException { - return readRawLittleEndian64(); - } - - @Override - public int readSInt32() throws IOException { - return decodeZigZag32(readRawVarint32()); - } - - @Override - public long readSInt64() throws IOException { - return decodeZigZag64(readRawVarint64()); - } - - // ================================================================= - - @Override - public int readRawVarint32() throws IOException { - // See implementation notes for readRawVarint64 - fastpath: - { - int tempPos = pos; - - if (bufferSize == tempPos) { - break fastpath; - } - - final byte[] buffer = this.buffer; - int x; - if ((x = buffer[tempPos++]) >= 0) { - pos = tempPos; - return x; - } else if (bufferSize - tempPos < 9) { - break fastpath; - } else if ((x ^= (buffer[tempPos++] << 7)) < 0) { - x ^= (~0 << 7); - } else if ((x ^= (buffer[tempPos++] << 14)) >= 0) { - x ^= (~0 << 7) ^ (~0 << 14); - } else if ((x ^= (buffer[tempPos++] << 21)) < 0) { - x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21); - } else { - int y = buffer[tempPos++]; - x ^= y << 28; - x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21) ^ (~0 << 28); - if (y < 0 - && buffer[tempPos++] < 0 - && buffer[tempPos++] < 0 - && buffer[tempPos++] < 0 - && buffer[tempPos++] < 0 - && buffer[tempPos++] < 0) { - break fastpath; // Will throw malformedVarint() - } - } - pos = tempPos; - return x; - } - return (int) readRawVarint64SlowPath(); - } - - private void skipRawVarint() throws IOException { - if (bufferSize - pos >= MAX_VARINT_SIZE) { - skipRawVarintFastPath(); - } else { - skipRawVarintSlowPath(); - } - } - - private void skipRawVarintFastPath() throws IOException { - for (int i = 0; i < MAX_VARINT_SIZE; i++) { - if (buffer[pos++] >= 0) { - return; - } - } - throw InvalidProtocolBufferException.malformedVarint(); - } - - private void skipRawVarintSlowPath() throws IOException { - for (int i = 0; i < MAX_VARINT_SIZE; i++) { - if (readRawByte() >= 0) { - return; - } - } - throw InvalidProtocolBufferException.malformedVarint(); - } - - @Override - public long readRawVarint64() throws IOException { - // Implementation notes: - // - // Optimized for one-byte values, expected to be common. - // The particular code below was selected from various candidates - // empirically, by winning VarintBenchmark. - // - // Sign extension of (signed) Java bytes is usually a nuisance, but - // we exploit it here to more easily obtain the sign of bytes read. - // Instead of cleaning up the sign extension bits by masking eagerly, - // we delay until we find the final (positive) byte, when we clear all - // accumulated bits with one xor. We depend on javac to constant fold. - fastpath: - { - int tempPos = pos; - - if (bufferSize == tempPos) { - break fastpath; - } - - final byte[] buffer = this.buffer; - long x; - int y; - if ((y = buffer[tempPos++]) >= 0) { - pos = tempPos; - return y; - } else if (bufferSize - tempPos < 9) { - break fastpath; - } else if ((y ^= (buffer[tempPos++] << 7)) < 0) { - x = y ^ (~0 << 7); - } else if ((y ^= (buffer[tempPos++] << 14)) >= 0) { - x = y ^ ((~0 << 7) ^ (~0 << 14)); - } else if ((y ^= (buffer[tempPos++] << 21)) < 0) { - x = y ^ ((~0 << 7) ^ (~0 << 14) ^ (~0 << 21)); - } else if ((x = y ^ ((long) buffer[tempPos++] << 28)) >= 0L) { - x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28); - } else if ((x ^= ((long) buffer[tempPos++] << 35)) < 0L) { - x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35); - } else if ((x ^= ((long) buffer[tempPos++] << 42)) >= 0L) { - x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35) ^ (~0L << 42); - } else if ((x ^= ((long) buffer[tempPos++] << 49)) < 0L) { - x ^= - (~0L << 7) - ^ (~0L << 14) - ^ (~0L << 21) - ^ (~0L << 28) - ^ (~0L << 35) - ^ (~0L << 42) - ^ (~0L << 49); - } else { - x ^= ((long) buffer[tempPos++] << 56); - x ^= - (~0L << 7) - ^ (~0L << 14) - ^ (~0L << 21) - ^ (~0L << 28) - ^ (~0L << 35) - ^ (~0L << 42) - ^ (~0L << 49) - ^ (~0L << 56); - if (x < 0L) { - if (buffer[tempPos++] < 0L) { - break fastpath; // Will throw malformedVarint() - } - } - } - pos = tempPos; - return x; - } - return readRawVarint64SlowPath(); - } - - @Override - long readRawVarint64SlowPath() throws IOException { - long result = 0; - for (int shift = 0; shift < 64; shift += 7) { - final byte b = readRawByte(); - result |= (long) (b & 0x7F) << shift; - if ((b & 0x80) == 0) { - return result; - } - } - throw InvalidProtocolBufferException.malformedVarint(); - } - - @Override - public int readRawLittleEndian32() throws IOException { - int tempPos = pos; - - if (bufferSize - tempPos < FIXED32_SIZE) { - refillBuffer(FIXED32_SIZE); - tempPos = pos; - } - - final byte[] buffer = this.buffer; - pos = tempPos + FIXED32_SIZE; - return ((buffer[tempPos] & 0xff) - | ((buffer[tempPos + 1] & 0xff) << 8) - | ((buffer[tempPos + 2] & 0xff) << 16) - | ((buffer[tempPos + 3] & 0xff) << 24)); - } - - @Override - public long readRawLittleEndian64() throws IOException { - int tempPos = pos; - - if (bufferSize - tempPos < FIXED64_SIZE) { - refillBuffer(FIXED64_SIZE); - tempPos = pos; - } - - final byte[] buffer = this.buffer; - pos = tempPos + FIXED64_SIZE; - return (((buffer[tempPos] & 0xffL)) - | ((buffer[tempPos + 1] & 0xffL) << 8) - | ((buffer[tempPos + 2] & 0xffL) << 16) - | ((buffer[tempPos + 3] & 0xffL) << 24) - | ((buffer[tempPos + 4] & 0xffL) << 32) - | ((buffer[tempPos + 5] & 0xffL) << 40) - | ((buffer[tempPos + 6] & 0xffL) << 48) - | ((buffer[tempPos + 7] & 0xffL) << 56)); - } - - // ----------------------------------------------------------------- - - @Override - public void enableAliasing(boolean enabled) { - // TODO: Ideally we should throw here. Do nothing for backward compatibility. - } - - @Override - public void resetSizeCounter() { - totalBytesRetired = -pos; - } - - @Override - public int pushLimit(int byteLimit) throws InvalidProtocolBufferException { - if (byteLimit < 0) { - throw InvalidProtocolBufferException.negativeSize(); - } - byteLimit += totalBytesRetired + pos; - final int oldLimit = currentLimit; - if (byteLimit > oldLimit) { - throw InvalidProtocolBufferException.truncatedMessage(); - } - currentLimit = byteLimit; - - recomputeBufferSizeAfterLimit(); - - return oldLimit; - } - - private void recomputeBufferSizeAfterLimit() { - bufferSize += bufferSizeAfterLimit; - final int bufferEnd = totalBytesRetired + bufferSize; - if (bufferEnd > currentLimit) { - // Limit is in current buffer. - bufferSizeAfterLimit = bufferEnd - currentLimit; - bufferSize -= bufferSizeAfterLimit; - } else { - bufferSizeAfterLimit = 0; - } - } - - @Override - public void popLimit(final int oldLimit) { - currentLimit = oldLimit; - recomputeBufferSizeAfterLimit(); - } - - @Override - public int getBytesUntilLimit() { - if (currentLimit == Integer.MAX_VALUE) { - return -1; - } - - final int currentAbsolutePosition = totalBytesRetired + pos; - return currentLimit - currentAbsolutePosition; - } - - @Override - public boolean isAtEnd() throws IOException { - return pos == bufferSize && !tryRefillBuffer(1); - } - - @Override - public int getTotalBytesRead() { - return totalBytesRetired + pos; - } - - private interface RefillCallback { - void onRefill(); - } - - private RefillCallback refillCallback = null; - - /** - * Reads more bytes from the input, making at least {@code n} bytes available in the buffer. - * Caller must ensure that the requested space is not yet available, and that the requested - * space is less than BUFFER_SIZE. - * - * @throws InvalidProtocolBufferException The end of the stream or the current limit was - * reached. - */ - private void refillBuffer(int n) throws IOException { - if (!tryRefillBuffer(n)) { - // We have to distinguish the exception between sizeLimitExceeded and truncatedMessage. So - // we just throw an sizeLimitExceeded exception here if it exceeds the sizeLimit - if (n > sizeLimit - totalBytesRetired - pos) { - throw InvalidProtocolBufferException.sizeLimitExceeded(); - } else { - throw InvalidProtocolBufferException.truncatedMessage(); - } - } - } - - /** - * Tries to read more bytes from the input, making at least {@code n} bytes available in the - * buffer. Caller must ensure that the requested space is not yet available, and that the - * requested space is less than BUFFER_SIZE. - * - * @return {@code true} If the bytes could be made available; {@code false} 1. Current at the - * end of the stream 2. The current limit was reached 3. The total size limit was reached - */ - private boolean tryRefillBuffer(int n) throws IOException { - if (pos + n <= bufferSize) { - throw new IllegalStateException( - "refillBuffer() called when " + n + " bytes were already available in buffer"); - } - - // Check whether the size of total message needs to read is bigger than the size limit. - // We shouldn't throw an exception here as isAtEnd() function needs to get this function's - // return as the result. - if (n > sizeLimit - totalBytesRetired - pos) { - return false; - } - - // Shouldn't throw the exception here either. - if (totalBytesRetired + pos + n > currentLimit) { - // Oops, we hit a limit. - return false; - } - - if (refillCallback != null) { - refillCallback.onRefill(); - } - - int tempPos = pos; - if (tempPos > 0) { - if (bufferSize > tempPos) { - System.arraycopy(buffer, tempPos, buffer, 0, bufferSize - tempPos); - } - totalBytesRetired += tempPos; - bufferSize -= tempPos; - pos = 0; - } - - // Here we should refill the buffer as many bytes as possible. - int bytesRead = - read( - input, - buffer, - bufferSize, - Math.min( - // the size of allocated but unused bytes in the buffer - buffer.length - bufferSize, - // do not exceed the total bytes limit - sizeLimit - totalBytesRetired - bufferSize)); - if (bytesRead == 0 || bytesRead < -1 || bytesRead > buffer.length) { - throw new IllegalStateException( - input.getClass() - + "#read(byte[]) returned invalid result: " - + bytesRead - + "\nThe InputStream implementation is buggy."); - } - if (bytesRead > 0) { - bufferSize += bytesRead; - recomputeBufferSizeAfterLimit(); - return (bufferSize >= n) ? true : tryRefillBuffer(n); - } - - return false; - } - - @Override - public byte readRawByte() throws IOException { - if (pos == bufferSize) { - refillBuffer(1); - } - return buffer[pos++]; - } - - @Override - public byte[] readRawBytes(final int size) throws IOException { - final int tempPos = pos; - if (size <= (bufferSize - tempPos) && size > 0) { - pos = tempPos + size; - return Arrays.copyOfRange(buffer, tempPos, tempPos + size); - } else { - // TODO: Do we want to protect from malicious input streams here? - return readRawBytesSlowPath(size, /* ensureNoLeakedReferences= */ false); - } - } - - /** - * Exactly like readRawBytes, but caller must have already checked the fast path: (size <= - * (bufferSize - pos) && size > 0) - * - * If ensureNoLeakedReferences is true, the value is guaranteed to have not escaped to - * untrusted code. - */ - private byte[] readRawBytesSlowPath( - final int size, boolean ensureNoLeakedReferences) throws IOException { - // Attempt to read the data in one byte array when it's safe to do. - byte[] result = readRawBytesSlowPathOneChunk(size); - if (result != null) { - return ensureNoLeakedReferences ? result.clone() : result; - } - - final int originalBufferPos = pos; - final int bufferedBytes = bufferSize - pos; - - // Mark the current buffer consumed. - totalBytesRetired += bufferSize; - pos = 0; - bufferSize = 0; - - // Determine the number of bytes we need to read from the input stream. - int sizeLeft = size - bufferedBytes; - - // The size is very large. For security reasons we read them in small - // chunks. - List chunks = readRawBytesSlowPathRemainingChunks(sizeLeft); - - // OK, got everything. Now concatenate it all into one buffer. - final byte[] bytes = new byte[size]; - - // Start by copying the leftover bytes from this.buffer. - System.arraycopy(buffer, originalBufferPos, bytes, 0, bufferedBytes); - - // And now all the chunks. - int tempPos = bufferedBytes; - for (final byte[] chunk : chunks) { - System.arraycopy(chunk, 0, bytes, tempPos, chunk.length); - tempPos += chunk.length; - } - - // Done. - return bytes; - } - - /** - * Attempts to read the data in one byte array when it's safe to do. Returns null if the size to - * read is too large and needs to be allocated in smaller chunks for security reasons. - * - *

Returns a byte[] that may have escaped to user code via InputStream APIs. - */ - private byte[] readRawBytesSlowPathOneChunk(final int size) throws IOException { - if (size == 0) { - return Internal.EMPTY_BYTE_ARRAY; - } - if (size < 0) { - throw InvalidProtocolBufferException.negativeSize(); - } - - // Integer-overflow-conscious check that the message size so far has not exceeded sizeLimit. - int currentMessageSize = totalBytesRetired + pos + size; - if (currentMessageSize - sizeLimit > 0) { - throw InvalidProtocolBufferException.sizeLimitExceeded(); - } - - // Verify that the message size so far has not exceeded currentLimit. - if (currentMessageSize > currentLimit) { - // Read to the end of the stream anyway. - skipRawBytes(currentLimit - totalBytesRetired - pos); - throw InvalidProtocolBufferException.truncatedMessage(); - } - - final int bufferedBytes = bufferSize - pos; - // Determine the number of bytes we need to read from the input stream. - int sizeLeft = size - bufferedBytes; - // TODO: Consider using a value larger than DEFAULT_BUFFER_SIZE. - if (sizeLeft < DEFAULT_BUFFER_SIZE || sizeLeft <= available(input)) { - // Either the bytes we need are known to be available, or the required buffer is - // within an allowed threshold - go ahead and allocate the buffer now. - final byte[] bytes = new byte[size]; - - // Copy all of the buffered bytes to the result buffer. - System.arraycopy(buffer, pos, bytes, 0, bufferedBytes); - totalBytesRetired += bufferSize; - pos = 0; - bufferSize = 0; - - // Fill the remaining bytes from the input stream. - int tempPos = bufferedBytes; - while (tempPos < bytes.length) { - int n = read(input, bytes, tempPos, size - tempPos); - if (n == -1) { - throw InvalidProtocolBufferException.truncatedMessage(); - } - totalBytesRetired += n; - tempPos += n; - } - - return bytes; - } - - return null; - } - - /** - * Reads the remaining data in small chunks from the input stream. - * - * Returns a byte[] that may have escaped to user code via InputStream APIs. - */ - private List readRawBytesSlowPathRemainingChunks(int sizeLeft) throws IOException { - // The size is very large. For security reasons, we can't allocate the - // entire byte array yet. The size comes directly from the input, so a - // maliciously-crafted message could provide a bogus very large size in - // order to trick the app into allocating a lot of memory. We avoid this - // by allocating and reading only a small chunk at a time, so that the - // malicious message must actually *be* extremely large to cause - // problems. Meanwhile, we limit the allowed size of a message elsewhere. - final List chunks = new ArrayList<>(); - - while (sizeLeft > 0) { - // TODO: Consider using a value larger than DEFAULT_BUFFER_SIZE. - final byte[] chunk = new byte[Math.min(sizeLeft, DEFAULT_BUFFER_SIZE)]; - int tempPos = 0; - while (tempPos < chunk.length) { - final int n = input.read(chunk, tempPos, chunk.length - tempPos); - if (n == -1) { - throw InvalidProtocolBufferException.truncatedMessage(); - } - totalBytesRetired += n; - tempPos += n; - } - sizeLeft -= chunk.length; - chunks.add(chunk); - } - - return chunks; - } - - /** - * Like readBytes, but caller must have already checked the fast path: (size <= (bufferSize - - * pos) && size > 0 || size == 0) - */ - private ByteString readBytesSlowPath(final int size) throws IOException { - final byte[] result = readRawBytesSlowPathOneChunk(size); - if (result != null) { - // We must copy as the byte array was handed off to the InputStream and a malicious - // implementation could retain a reference. - return ByteString.copyFrom(result); - } - - final int originalBufferPos = pos; - final int bufferedBytes = bufferSize - pos; - - // Mark the current buffer consumed. - totalBytesRetired += bufferSize; - pos = 0; - bufferSize = 0; - - // Determine the number of bytes we need to read from the input stream. - int sizeLeft = size - bufferedBytes; - - // The size is very large. For security reasons we read them in small - // chunks. - List chunks = readRawBytesSlowPathRemainingChunks(sizeLeft); - - // OK, got everything. Now concatenate it all into one buffer. - final byte[] bytes = new byte[size]; - - // Start by copying the leftover bytes from this.buffer. - System.arraycopy(buffer, originalBufferPos, bytes, 0, bufferedBytes); - - // And now all the chunks. - int tempPos = bufferedBytes; - for (final byte[] chunk : chunks) { - System.arraycopy(chunk, 0, bytes, tempPos, chunk.length); - tempPos += chunk.length; - } - - return ByteString.wrap(bytes); - } - - @Override - public void skipRawBytes(final int size) throws IOException { - if (size <= (bufferSize - pos) && size >= 0) { - // We have all the bytes we need already. - pos += size; - } else { - skipRawBytesSlowPath(size); - } - } - - /** - * Exactly like skipRawBytes, but caller must have already checked the fast path: (size <= - * (bufferSize - pos) && size >= 0) - */ - private void skipRawBytesSlowPath(final int size) throws IOException { - if (size < 0) { - throw InvalidProtocolBufferException.negativeSize(); - } - - if (totalBytesRetired + pos + size > currentLimit) { - // Read to the end of the stream anyway. - skipRawBytes(currentLimit - totalBytesRetired - pos); - // Then fail. - throw InvalidProtocolBufferException.truncatedMessage(); - } - - int totalSkipped = 0; - if (refillCallback == null) { - // Skipping more bytes than are in the buffer. First skip what we have. - totalBytesRetired += pos; - totalSkipped = bufferSize - pos; - bufferSize = 0; - pos = 0; - - try { - while (totalSkipped < size) { - int toSkip = size - totalSkipped; - long skipped = skip(input, toSkip); - if (skipped < 0 || skipped > toSkip) { - throw new IllegalStateException( - input.getClass() - + "#skip returned invalid result: " - + skipped - + "\nThe InputStream implementation is buggy."); - } else if (skipped == 0) { - // The API contract of skip() permits an inputstream to skip zero bytes for any reason - // it wants. In particular, ByteArrayInputStream will just return zero over and over - // when it's at the end of its input. In order to actually confirm that we've hit the - // end of input, we need to issue a read call via the other path. - break; - } - totalSkipped += (int) skipped; - } - } finally { - totalBytesRetired += totalSkipped; - recomputeBufferSizeAfterLimit(); - } - } - if (totalSkipped < size) { - // Skipping more bytes than are in the buffer. First skip what we have. - int tempPos = bufferSize - pos; - pos = bufferSize; - - // Keep refilling the buffer until we get to the point we wanted to skip to. - // This has the side effect of ensuring the limits are updated correctly. - refillBuffer(1); - while (size - tempPos > bufferSize) { - tempPos += bufferSize; - pos = bufferSize; - refillBuffer(1); - } - - pos = size - tempPos; - } - } -} \ No newline at end of file diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/UnsafeDirectNioDecoder.java b/protobuf-sdk/src/main/java/com/google/protobuf/UnsafeDirectNioDecoder.java deleted file mode 100644 index 5f14d17..0000000 --- a/protobuf-sdk/src/main/java/com/google/protobuf/UnsafeDirectNioDecoder.java +++ /dev/null @@ -1,737 +0,0 @@ -package com.google.protobuf; - -import java.io.IOException; -import java.nio.Buffer; -import java.nio.ByteBuffer; - -import static com.google.protobuf.Internal.*; -import static com.google.protobuf.WireFormat.*; -import static com.google.protobuf.WireFormat.FIXED64_SIZE; - -/** - * A {@link CodedInputStream} implementation that uses a backing direct ByteBuffer as the input. - * Requires the use of {@code sun.misc.Unsafe} to perform fast reads on the buffer. - */ -final class UnsafeDirectNioDecoder extends CodedInputStream { - /** The direct buffer that is backing this stream. */ - private final ByteBuffer buffer; - - /** - * If {@code true}, indicates that the buffer is backing a {@link ByteString} and is therefore - * considered to be an immutable input source. - */ - private final boolean immutable; - - /** The unsafe address of the content of {@link #buffer}. */ - private final long address; - - /** The unsafe address of the current read limit of the buffer. */ - private long limit; - - /** The unsafe address of the current read position of the buffer. */ - private long pos; - - /** The unsafe address of the starting read position. */ - private long startPos; - - /** The amount of available data in the buffer beyond {@link #limit}. */ - private int bufferSizeAfterLimit; - - /** The last tag that was read from this stream. */ - private int lastTag; - - /** - * If {@code true}, indicates that calls to read {@link ByteString} or {@code byte[]} - * may return slices of the underlying buffer, rather than copies. - */ - private boolean enableAliasing; - - /** The absolute position of the end of the current message. */ - private int currentLimit = Integer.MAX_VALUE; - - static boolean isSupported() { - return UnsafeUtil.hasUnsafeByteBufferOperations(); - } - - UnsafeDirectNioDecoder(ByteBuffer buffer, boolean immutable) { - this.buffer = buffer; - address = UnsafeUtil.addressOffset(buffer); - limit = address + buffer.limit(); - pos = address + buffer.position(); - startPos = pos; - this.immutable = immutable; - } - - @Override - public int readTag() throws IOException { - if (isAtEnd()) { - lastTag = 0; - return 0; - } - - lastTag = readRawVarint32(); - if (WireFormat.getTagFieldNumber(lastTag) == 0) { - // If we actually read zero (or any tag number corresponding to field - // number zero), that's not a valid tag. - throw InvalidProtocolBufferException.invalidTag(); - } - return lastTag; - } - - @Override - public void checkLastTagWas(final int value) throws InvalidProtocolBufferException { - if (lastTag != value) { - throw InvalidProtocolBufferException.invalidEndTag(); - } - } - - @Override - public int getLastTag() { - return lastTag; - } - - @Override - public boolean skipField(final int tag) throws IOException { - switch (WireFormat.getTagWireType(tag)) { - case WireFormat.WIRETYPE_VARINT: - skipRawVarint(); - return true; - case WireFormat.WIRETYPE_FIXED64: - skipRawBytes(FIXED64_SIZE); - return true; - case WireFormat.WIRETYPE_LENGTH_DELIMITED: - skipRawBytes(readRawVarint32()); - return true; - case WireFormat.WIRETYPE_START_GROUP: - skipMessage(); - checkLastTagWas( - WireFormat.makeTag(WireFormat.getTagFieldNumber(tag), WireFormat.WIRETYPE_END_GROUP)); - return true; - case WireFormat.WIRETYPE_END_GROUP: - return false; - case WireFormat.WIRETYPE_FIXED32: - skipRawBytes(FIXED32_SIZE); - return true; - default: - throw InvalidProtocolBufferException.invalidWireType(); - } - } - - @Override - public boolean skipField(final int tag, final CodedOutputStream output) throws IOException { - switch (WireFormat.getTagWireType(tag)) { - case WireFormat.WIRETYPE_VARINT: - { - long value = readInt64(); - output.writeUInt32NoTag(tag); - output.writeUInt64NoTag(value); - return true; - } - case WireFormat.WIRETYPE_FIXED64: - { - long value = readRawLittleEndian64(); - output.writeUInt32NoTag(tag); - output.writeFixed64NoTag(value); - return true; - } - case WireFormat.WIRETYPE_LENGTH_DELIMITED: - { - ByteString value = readBytes(); - output.writeUInt32NoTag(tag); - output.writeBytesNoTag(value); - return true; - } - case WireFormat.WIRETYPE_START_GROUP: - { - output.writeUInt32NoTag(tag); - skipMessage(output); - int endtag = - WireFormat.makeTag( - WireFormat.getTagFieldNumber(tag), WireFormat.WIRETYPE_END_GROUP); - checkLastTagWas(endtag); - output.writeUInt32NoTag(endtag); - return true; - } - case WireFormat.WIRETYPE_END_GROUP: - { - return false; - } - case WireFormat.WIRETYPE_FIXED32: - { - int value = readRawLittleEndian32(); - output.writeUInt32NoTag(tag); - output.writeFixed32NoTag(value); - return true; - } - default: - throw InvalidProtocolBufferException.invalidWireType(); - } - } - - // ----------------------------------------------------------------- - - @Override - public double readDouble() throws IOException { - return Double.longBitsToDouble(readRawLittleEndian64()); - } - - @Override - public float readFloat() throws IOException { - return Float.intBitsToFloat(readRawLittleEndian32()); - } - - @Override - public long readUInt64() throws IOException { - return readRawVarint64(); - } - - @Override - public long readInt64() throws IOException { - return readRawVarint64(); - } - - @Override - public int readInt32() throws IOException { - return readRawVarint32(); - } - - @Override - public long readFixed64() throws IOException { - return readRawLittleEndian64(); - } - - @Override - public int readFixed32() throws IOException { - return readRawLittleEndian32(); - } - - @Override - public boolean readBool() throws IOException { - return readRawVarint64() != 0; - } - - @Override - public String readString() throws IOException { - final int size = readRawVarint32(); - if (size > 0 && size <= remaining()) { - // TODO: Is there a way to avoid this copy? - // TODO: It might be possible to share the optimized loop with - // readStringRequireUtf8 by implementing Java replacement logic there. - // The same as readBytes' logic - byte[] bytes = new byte[size]; - UnsafeUtil.copyMemory(pos, bytes, 0, size); - String result = new String(bytes, UTF_8); - pos += size; - return result; - } - - if (size == 0) { - return ""; - } - if (size < 0) { - throw InvalidProtocolBufferException.negativeSize(); - } - throw InvalidProtocolBufferException.truncatedMessage(); - } - - @Override - public String readStringRequireUtf8() throws IOException { - final int size = readRawVarint32(); - if (size > 0 && size <= remaining()) { - final int bufferPos = bufferPos(pos); - String result = Utf8.decodeUtf8(buffer, bufferPos, size); - pos += size; - return result; - } - - if (size == 0) { - return ""; - } - if (size <= 0) { - throw InvalidProtocolBufferException.negativeSize(); - } - throw InvalidProtocolBufferException.truncatedMessage(); - } - - @Override - public void readGroup( - final int fieldNumber, - final MessageLite.Builder builder, - final ExtensionRegistryLite extensionRegistry) - throws IOException { - checkRecursionLimit(); - ++recursionDepth; - builder.mergeFrom(this, extensionRegistry); - checkLastTagWas(WireFormat.makeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP)); - --recursionDepth; - } - - @Override - public T readGroup( - final int fieldNumber, - final Parser parser, - final ExtensionRegistryLite extensionRegistry) - throws IOException { - checkRecursionLimit(); - ++recursionDepth; - T result = parser.parsePartialFrom(this, extensionRegistry); - checkLastTagWas(WireFormat.makeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP)); - --recursionDepth; - return result; - } - - @Deprecated - @Override - public void readUnknownGroup(final int fieldNumber, final MessageLite.Builder builder) - throws IOException { - readGroup(fieldNumber, builder, ExtensionRegistryLite.getEmptyRegistry()); - } - - @Override - public void readMessage( - final MessageLite.Builder builder, final ExtensionRegistryLite extensionRegistry) - throws IOException { - final int length = readRawVarint32(); - checkRecursionLimit(); - final int oldLimit = pushLimit(length); - ++recursionDepth; - builder.mergeFrom(this, extensionRegistry); - checkLastTagWas(0); - --recursionDepth; - if (getBytesUntilLimit() != 0) { - throw InvalidProtocolBufferException.truncatedMessage(); - } - popLimit(oldLimit); - } - - @Override - public T readMessage( - final Parser parser, final ExtensionRegistryLite extensionRegistry) throws IOException { - int length = readRawVarint32(); - checkRecursionLimit(); - final int oldLimit = pushLimit(length); - ++recursionDepth; - T result = parser.parsePartialFrom(this, extensionRegistry); - checkLastTagWas(0); - --recursionDepth; - if (getBytesUntilLimit() != 0) { - throw InvalidProtocolBufferException.truncatedMessage(); - } - popLimit(oldLimit); - return result; - } - - @Override - public ByteString readBytes() throws IOException { - final int size = readRawVarint32(); - if (size > 0 && size <= remaining()) { - if (immutable && enableAliasing) { - final ByteBuffer result = slice(pos, pos + size); - pos += size; - return ByteString.wrap(result); - } else { - // Use UnsafeUtil to copy the memory to bytes instead of using ByteBuffer ways. - byte[] bytes = new byte[size]; - UnsafeUtil.copyMemory(pos, bytes, 0, size); - pos += size; - return ByteString.wrap(bytes); - } - } - - if (size == 0) { - return ByteString.EMPTY; - } - if (size < 0) { - throw InvalidProtocolBufferException.negativeSize(); - } - throw InvalidProtocolBufferException.truncatedMessage(); - } - - @Override - public byte[] readByteArray() throws IOException { - return readRawBytes(readRawVarint32()); - } - - @Override - public ByteBuffer readByteBuffer() throws IOException { - final int size = readRawVarint32(); - if (size > 0 && size <= remaining()) { - // "Immutable" implies that buffer is backing a ByteString. - // Disallow slicing in this case to prevent the caller from modifying the contents - // of the ByteString. - if (!immutable && enableAliasing) { - final ByteBuffer result = slice(pos, pos + size); - pos += size; - return result; - } else { - // The same as readBytes' logic - byte[] bytes = new byte[size]; - UnsafeUtil.copyMemory(pos, bytes, 0, size); - pos += size; - return ByteBuffer.wrap(bytes); - } - // TODO: Investigate making the ByteBuffer be made read-only - } - - if (size == 0) { - return EMPTY_BYTE_BUFFER; - } - if (size < 0) { - throw InvalidProtocolBufferException.negativeSize(); - } - throw InvalidProtocolBufferException.truncatedMessage(); - } - - @Override - public int readUInt32() throws IOException { - return readRawVarint32(); - } - - @Override - public int readEnum() throws IOException { - return readRawVarint32(); - } - - @Override - public int readSFixed32() throws IOException { - return readRawLittleEndian32(); - } - - @Override - public long readSFixed64() throws IOException { - return readRawLittleEndian64(); - } - - @Override - public int readSInt32() throws IOException { - return decodeZigZag32(readRawVarint32()); - } - - @Override - public long readSInt64() throws IOException { - return decodeZigZag64(readRawVarint64()); - } - - // ================================================================= - - @Override - public int readRawVarint32() throws IOException { - // See implementation notes for readRawVarint64 - fastpath: - { - long tempPos = pos; - - if (limit == tempPos) { - break fastpath; - } - - int x; - if ((x = UnsafeUtil.getByte(tempPos++)) >= 0) { - pos = tempPos; - return x; - } else if (limit - tempPos < 9) { - break fastpath; - } else if ((x ^= (UnsafeUtil.getByte(tempPos++) << 7)) < 0) { - x ^= (~0 << 7); - } else if ((x ^= (UnsafeUtil.getByte(tempPos++) << 14)) >= 0) { - x ^= (~0 << 7) ^ (~0 << 14); - } else if ((x ^= (UnsafeUtil.getByte(tempPos++) << 21)) < 0) { - x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21); - } else { - int y = UnsafeUtil.getByte(tempPos++); - x ^= y << 28; - x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21) ^ (~0 << 28); - if (y < 0 - && UnsafeUtil.getByte(tempPos++) < 0 - && UnsafeUtil.getByte(tempPos++) < 0 - && UnsafeUtil.getByte(tempPos++) < 0 - && UnsafeUtil.getByte(tempPos++) < 0 - && UnsafeUtil.getByte(tempPos++) < 0) { - break fastpath; // Will throw malformedVarint() - } - } - pos = tempPos; - return x; - } - return (int) readRawVarint64SlowPath(); - } - - private void skipRawVarint() throws IOException { - if (remaining() >= MAX_VARINT_SIZE) { - skipRawVarintFastPath(); - } else { - skipRawVarintSlowPath(); - } - } - - private void skipRawVarintFastPath() throws IOException { - for (int i = 0; i < MAX_VARINT_SIZE; i++) { - if (UnsafeUtil.getByte(pos++) >= 0) { - return; - } - } - throw InvalidProtocolBufferException.malformedVarint(); - } - - private void skipRawVarintSlowPath() throws IOException { - for (int i = 0; i < MAX_VARINT_SIZE; i++) { - if (readRawByte() >= 0) { - return; - } - } - throw InvalidProtocolBufferException.malformedVarint(); - } - - @Override - public long readRawVarint64() throws IOException { - // Implementation notes: - // - // Optimized for one-byte values, expected to be common. - // The particular code below was selected from various candidates - // empirically, by winning VarintBenchmark. - // - // Sign extension of (signed) Java bytes is usually a nuisance, but - // we exploit it here to more easily obtain the sign of bytes read. - // Instead of cleaning up the sign extension bits by masking eagerly, - // we delay until we find the final (positive) byte, when we clear all - // accumulated bits with one xor. We depend on javac to constant fold. - fastpath: - { - long tempPos = pos; - - if (limit == tempPos) { - break fastpath; - } - - long x; - int y; - if ((y = UnsafeUtil.getByte(tempPos++)) >= 0) { - pos = tempPos; - return y; - } else if (limit - tempPos < 9) { - break fastpath; - } else if ((y ^= (UnsafeUtil.getByte(tempPos++) << 7)) < 0) { - x = y ^ (~0 << 7); - } else if ((y ^= (UnsafeUtil.getByte(tempPos++) << 14)) >= 0) { - x = y ^ ((~0 << 7) ^ (~0 << 14)); - } else if ((y ^= (UnsafeUtil.getByte(tempPos++) << 21)) < 0) { - x = y ^ ((~0 << 7) ^ (~0 << 14) ^ (~0 << 21)); - } else if ((x = y ^ ((long) UnsafeUtil.getByte(tempPos++) << 28)) >= 0L) { - x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28); - } else if ((x ^= ((long) UnsafeUtil.getByte(tempPos++) << 35)) < 0L) { - x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35); - } else if ((x ^= ((long) UnsafeUtil.getByte(tempPos++) << 42)) >= 0L) { - x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35) ^ (~0L << 42); - } else if ((x ^= ((long) UnsafeUtil.getByte(tempPos++) << 49)) < 0L) { - x ^= - (~0L << 7) - ^ (~0L << 14) - ^ (~0L << 21) - ^ (~0L << 28) - ^ (~0L << 35) - ^ (~0L << 42) - ^ (~0L << 49); - } else { - x ^= ((long) UnsafeUtil.getByte(tempPos++) << 56); - x ^= - (~0L << 7) - ^ (~0L << 14) - ^ (~0L << 21) - ^ (~0L << 28) - ^ (~0L << 35) - ^ (~0L << 42) - ^ (~0L << 49) - ^ (~0L << 56); - if (x < 0L) { - if (UnsafeUtil.getByte(tempPos++) < 0L) { - break fastpath; // Will throw malformedVarint() - } - } - } - pos = tempPos; - return x; - } - return readRawVarint64SlowPath(); - } - - @Override - long readRawVarint64SlowPath() throws IOException { - long result = 0; - for (int shift = 0; shift < 64; shift += 7) { - final byte b = readRawByte(); - result |= (long) (b & 0x7F) << shift; - if ((b & 0x80) == 0) { - return result; - } - } - throw InvalidProtocolBufferException.malformedVarint(); - } - - @Override - public int readRawLittleEndian32() throws IOException { - long tempPos = pos; - - if (limit - tempPos < FIXED32_SIZE) { - throw InvalidProtocolBufferException.truncatedMessage(); - } - - pos = tempPos + FIXED32_SIZE; - return ((UnsafeUtil.getByte(tempPos) & 0xff) - | ((UnsafeUtil.getByte(tempPos + 1) & 0xff) << 8) - | ((UnsafeUtil.getByte(tempPos + 2) & 0xff) << 16) - | ((UnsafeUtil.getByte(tempPos + 3) & 0xff) << 24)); - } - - @Override - public long readRawLittleEndian64() throws IOException { - long tempPos = pos; - - if (limit - tempPos < FIXED64_SIZE) { - throw InvalidProtocolBufferException.truncatedMessage(); - } - - pos = tempPos + FIXED64_SIZE; - return ((UnsafeUtil.getByte(tempPos) & 0xffL) - | ((UnsafeUtil.getByte(tempPos + 1) & 0xffL) << 8) - | ((UnsafeUtil.getByte(tempPos + 2) & 0xffL) << 16) - | ((UnsafeUtil.getByte(tempPos + 3) & 0xffL) << 24) - | ((UnsafeUtil.getByte(tempPos + 4) & 0xffL) << 32) - | ((UnsafeUtil.getByte(tempPos + 5) & 0xffL) << 40) - | ((UnsafeUtil.getByte(tempPos + 6) & 0xffL) << 48) - | ((UnsafeUtil.getByte(tempPos + 7) & 0xffL) << 56)); - } - - @Override - public void enableAliasing(boolean enabled) { - this.enableAliasing = enabled; - } - - @Override - public void resetSizeCounter() { - startPos = pos; - } - - @Override - public int pushLimit(int byteLimit) throws InvalidProtocolBufferException { - if (byteLimit < 0) { - throw InvalidProtocolBufferException.negativeSize(); - } - byteLimit += getTotalBytesRead(); - final int oldLimit = currentLimit; - if (byteLimit > oldLimit) { - throw InvalidProtocolBufferException.truncatedMessage(); - } - currentLimit = byteLimit; - - recomputeBufferSizeAfterLimit(); - - return oldLimit; - } - - @Override - public void popLimit(final int oldLimit) { - currentLimit = oldLimit; - recomputeBufferSizeAfterLimit(); - } - - @Override - public int getBytesUntilLimit() { - if (currentLimit == Integer.MAX_VALUE) { - return -1; - } - - return currentLimit - getTotalBytesRead(); - } - - @Override - public boolean isAtEnd() throws IOException { - return pos == limit; - } - - @Override - public int getTotalBytesRead() { - return (int) (pos - startPos); - } - - @Override - public byte readRawByte() throws IOException { - if (pos == limit) { - throw InvalidProtocolBufferException.truncatedMessage(); - } - return UnsafeUtil.getByte(pos++); - } - - @Override - public byte[] readRawBytes(final int length) throws IOException { - if (length >= 0 && length <= remaining()) { - byte[] bytes = new byte[length]; - slice(pos, pos + length).get(bytes); - pos += length; - return bytes; - } - - if (length <= 0) { - if (length == 0) { - return EMPTY_BYTE_ARRAY; - } else { - throw InvalidProtocolBufferException.negativeSize(); - } - } - - throw InvalidProtocolBufferException.truncatedMessage(); - } - - @Override - public void skipRawBytes(final int length) throws IOException { - if (length >= 0 && length <= remaining()) { - // We have all the bytes we need already. - pos += length; - return; - } - - if (length < 0) { - throw InvalidProtocolBufferException.negativeSize(); - } - throw InvalidProtocolBufferException.truncatedMessage(); - } - - private void recomputeBufferSizeAfterLimit() { - limit += bufferSizeAfterLimit; - final int bufferEnd = (int) (limit - startPos); - if (bufferEnd > currentLimit) { - // Limit is in current buffer. - bufferSizeAfterLimit = bufferEnd - currentLimit; - limit -= bufferSizeAfterLimit; - } else { - bufferSizeAfterLimit = 0; - } - } - - private int remaining() { - return (int) (limit - pos); - } - - private int bufferPos(long pos) { - return (int) (pos - address); - } - - private ByteBuffer slice(long begin, long end) throws IOException { - int prevPos = buffer.position(); - int prevLimit = buffer.limit(); - // View ByteBuffer as Buffer to avoid cross-Java version issues. - // See https://issues.apache.org/jira/browse/MRESOLVER-85 - Buffer asBuffer = buffer; - try { - asBuffer.position(bufferPos(begin)); - asBuffer.limit(bufferPos(end)); - return buffer.slice(); - } catch (IllegalArgumentException e) { - InvalidProtocolBufferException ex = InvalidProtocolBufferException.truncatedMessage(); - ex.initCause(e); - throw ex; - } finally { - asBuffer.position(prevPos); - asBuffer.limit(prevLimit); - } - } -} \ No newline at end of file From d174dc5f59f8eb118bc197b61328421d15a64f4e Mon Sep 17 00:00:00 2001 From: blakeli Date: Fri, 18 Apr 2025 18:19:12 -0400 Subject: [PATCH 29/42] Revert "Use getDeclaredConstructors" This reverts commit 2e042b3a21ebb39dbc89a3629112a84ecaaeb468. --- .../java/com/google/protobuf/CodedOutputStream.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/protobuf-api/src/main/java/com/google/protobuf/CodedOutputStream.java b/protobuf-api/src/main/java/com/google/protobuf/CodedOutputStream.java index eb97e57..21ae9d0 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/CodedOutputStream.java +++ b/protobuf-api/src/main/java/com/google/protobuf/CodedOutputStream.java @@ -102,7 +102,7 @@ public static CodedOutputStream newInstance(final OutputStream output) { */ public static CodedOutputStream newInstance(final OutputStream output, final int bufferSize) { try { - Constructor constructor = OUTPUT_STREAM_ENCODER.getDeclaredConstructors()[0]; + Constructor constructor = OUTPUT_STREAM_ENCODER.getConstructors()[0]; return (CodedOutputStream)constructor.newInstance(output, bufferSize); } catch (InstantiationException e) { throw new RuntimeException(e); @@ -132,7 +132,7 @@ public static CodedOutputStream newInstance(final byte[] flatArray) { public static CodedOutputStream newInstance( final byte[] flatArray, final int offset, final int length) { try { - Constructor constructor = ARRAY_ENCODER.getDeclaredConstructors()[0]; + Constructor constructor = ARRAY_ENCODER.getConstructors()[0]; return (CodedOutputStream)constructor.newInstance(flatArray, offset, length); } catch (InstantiationException e) { throw new RuntimeException(e); @@ -147,7 +147,7 @@ public static CodedOutputStream newInstance( public static CodedOutputStream newInstance(ByteBuffer buffer) { if (buffer.hasArray()) { try { - Constructor constructor = HEAP_NIO_ENCODER.getDeclaredConstructors()[0]; + Constructor constructor = HEAP_NIO_ENCODER.getConstructors()[0]; return (CodedOutputStream)constructor.newInstance(buffer); } catch (InstantiationException e) { throw new RuntimeException(e); @@ -168,7 +168,7 @@ public static CodedOutputStream newInstance(ByteBuffer buffer) { /** For testing purposes only. */ static CodedOutputStream newUnsafeInstance(ByteBuffer buffer) { try { - Constructor constructor = UNSAFE_DIRECT_NIO_ENCODER.getDeclaredConstructors()[0]; + Constructor constructor = UNSAFE_DIRECT_NIO_ENCODER.getConstructors()[0]; return (CodedOutputStream)constructor.newInstance(buffer); } catch (InstantiationException e) { throw new RuntimeException(e); @@ -182,7 +182,7 @@ static CodedOutputStream newUnsafeInstance(ByteBuffer buffer) { /** For testing purposes only. */ static CodedOutputStream newSafeInstance(ByteBuffer buffer) { try { - Constructor constructor = SAFE_DIRECT_NIO_ENCODER.getDeclaredConstructors()[0]; + Constructor constructor = SAFE_DIRECT_NIO_ENCODER.getConstructors()[0]; return (CodedOutputStream)constructor.newInstance(buffer); } catch (InstantiationException e) { throw new RuntimeException(e); @@ -261,7 +261,7 @@ static CodedOutputStream newInstance(ByteOutput byteOutput, int bufferSize) { throw new IllegalArgumentException("bufferSize must be positive"); } try { - Constructor constructor = BYTE_OUTPUT_ENCODER.getDeclaredConstructors()[0]; + Constructor constructor = BYTE_OUTPUT_ENCODER.getConstructors()[0]; return (CodedOutputStream)constructor.newInstance(byteOutput, bufferSize); } catch (InstantiationException e) { throw new RuntimeException(e); From b8e6fcd25d1a264787ead16a47e14644905ae482 Mon Sep 17 00:00:00 2001 From: blakeli Date: Fri, 18 Apr 2025 18:21:13 -0400 Subject: [PATCH 30/42] Revert "Move implementations of CodedOutputStream to SDK package." This reverts commit 0ca49b545a48ad9db5ab5ba9609500812738f7bc. --- .../google/protobuf/CodedOutputStream.java | 2052 ++++++++++++++++- .../protobuf/AbstractBufferedEncoder.java | 160 -- .../com/google/protobuf/ArrayEncoder.java | 354 --- .../google/protobuf/ByteOutputEncoder.java | 322 --- .../com/google/protobuf/HeapNioEncoder.java | 27 - .../google/protobuf/OutputStreamEncoder.java | 371 --- .../google/protobuf/SafeDirectNioEncoder.java | 328 --- .../protobuf/UnsafeDirectNioEncoder.java | 369 --- 8 files changed, 1924 insertions(+), 2059 deletions(-) delete mode 100644 protobuf-sdk/src/main/java/com/google/protobuf/AbstractBufferedEncoder.java delete mode 100644 protobuf-sdk/src/main/java/com/google/protobuf/ArrayEncoder.java delete mode 100644 protobuf-sdk/src/main/java/com/google/protobuf/ByteOutputEncoder.java delete mode 100644 protobuf-sdk/src/main/java/com/google/protobuf/HeapNioEncoder.java delete mode 100644 protobuf-sdk/src/main/java/com/google/protobuf/OutputStreamEncoder.java delete mode 100644 protobuf-sdk/src/main/java/com/google/protobuf/SafeDirectNioEncoder.java delete mode 100644 protobuf-sdk/src/main/java/com/google/protobuf/UnsafeDirectNioEncoder.java diff --git a/protobuf-api/src/main/java/com/google/protobuf/CodedOutputStream.java b/protobuf-api/src/main/java/com/google/protobuf/CodedOutputStream.java index 21ae9d0..37bb44a 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/CodedOutputStream.java +++ b/protobuf-api/src/main/java/com/google/protobuf/CodedOutputStream.java @@ -7,12 +7,18 @@ package com.google.protobuf; +import static com.google.protobuf.WireFormat.FIXED32_SIZE; +import static com.google.protobuf.WireFormat.FIXED64_SIZE; +import static com.google.protobuf.WireFormat.MAX_VARINT32_SIZE; +import static com.google.protobuf.WireFormat.MAX_VARINT_SIZE; +import static java.lang.Math.max; + import com.google.protobuf.Utf8.UnpairedSurrogateException; import java.io.IOException; import java.io.OutputStream; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; +import java.nio.BufferOverflowException; import java.nio.ByteBuffer; +import java.nio.ByteOrder; import java.util.logging.Level; import java.util.logging.Logger; @@ -29,45 +35,17 @@ */ public abstract class CodedOutputStream extends ByteOutput { private static final Logger logger = Logger.getLogger(CodedOutputStream.class.getName()); - static final boolean HAS_UNSAFE_ARRAY_OPERATIONS = UnsafeUtil.hasUnsafeArrayOperations(); - private static final Class ARRAY_ENCODER = getClassForName("com.google.protobuf.ArrayEncoder"); - private static final Class ABSTRACT_BUFFERED_ENCODER = getClassForName("com.google.protobuf.AbstractBufferedEncoder"); - private static final Class BYTE_OUTPUT_ENCODER = getClassForName("com.google.protobuf.ByteOutputEncoder"); - private static final Class HEAP_NIO_ENCODER = getClassForName("com.google.protobuf.HeapNioEncoder"); - private static final Class OUTPUT_STREAM_ENCODER = getClassForName("com.google.protobuf.OutputStreamEncoder"); - private static final Class SAFE_DIRECT_NIO_ENCODER = getClassForName("com.google.protobuf.SafeDirectNioEncoder"); - private static final Class UNSAFE_DIRECT_NIO_ENCODER = getClassForName("com.google.protobuf.UnsafeDirectNioEncoder"); + private static final boolean HAS_UNSAFE_ARRAY_OPERATIONS = UnsafeUtil.hasUnsafeArrayOperations(); + /** Used to adapt to the experimental {@link Writer} interface. */ CodedOutputStreamWriter wrapper; - // Field numbers for fields in MessageSet wire format. - static final int MESSAGE_SET_ITEM = 1; - static final int MESSAGE_SET_TYPE_ID = 2; - static final int MESSAGE_SET_MESSAGE = 3; - - static final int TAG_TYPE_BITS = 3; - - static final int FIXED32_SIZE = 4; - static final int FIXED64_SIZE = 8; - static final int MAX_VARINT_SIZE = 10; - - public static final int WIRETYPE_START_GROUP = 3; - public static final int WIRETYPE_END_GROUP = 4; - - /** @deprecated Use {@link #computeFixed32SizeNoTag(int)} instead. */ @Deprecated public static final int LITTLE_ENDIAN_32_SIZE = FIXED32_SIZE; /** The buffer size used in {@link #newInstance(OutputStream)}. */ public static final int DEFAULT_BUFFER_SIZE = 4096; - private static Class getClassForName(String name) { - try { - return (Class) Class.forName(name); - } catch (Throwable e) { - return null; - } - } /** * Returns the buffer size to efficiently write dataLength bytes to this CodedOutputStream. Used * by AbstractMessageLite. @@ -101,16 +79,7 @@ public static CodedOutputStream newInstance(final OutputStream output) { * debug. */ public static CodedOutputStream newInstance(final OutputStream output, final int bufferSize) { - try { - Constructor constructor = OUTPUT_STREAM_ENCODER.getConstructors()[0]; - return (CodedOutputStream)constructor.newInstance(output, bufferSize); - } catch (InstantiationException e) { - throw new RuntimeException(e); - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } catch (InvocationTargetException e) { - throw new RuntimeException(e); - } + return new OutputStreamEncoder(output, bufferSize); } /** @@ -131,34 +100,16 @@ public static CodedOutputStream newInstance(final byte[] flatArray) { */ public static CodedOutputStream newInstance( final byte[] flatArray, final int offset, final int length) { - try { - Constructor constructor = ARRAY_ENCODER.getConstructors()[0]; - return (CodedOutputStream)constructor.newInstance(flatArray, offset, length); - } catch (InstantiationException e) { - throw new RuntimeException(e); - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } catch (InvocationTargetException e) { - throw new RuntimeException(e); - } + return new ArrayEncoder(flatArray, offset, length); } /** Create a new {@code CodedOutputStream} that writes to the given {@link ByteBuffer}. */ public static CodedOutputStream newInstance(ByteBuffer buffer) { if (buffer.hasArray()) { - try { - Constructor constructor = HEAP_NIO_ENCODER.getConstructors()[0]; - return (CodedOutputStream)constructor.newInstance(buffer); - } catch (InstantiationException e) { - throw new RuntimeException(e); - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } catch (InvocationTargetException e) { - throw new RuntimeException(e); - } + return new HeapNioEncoder(buffer); } if (buffer.isDirect() && !buffer.isReadOnly()) { - return UnsafeUtil.hasUnsafeByteBufferOperations() + return UnsafeDirectNioEncoder.isSupported() ? newUnsafeInstance(buffer) : newSafeInstance(buffer); } @@ -167,30 +118,12 @@ public static CodedOutputStream newInstance(ByteBuffer buffer) { /** For testing purposes only. */ static CodedOutputStream newUnsafeInstance(ByteBuffer buffer) { - try { - Constructor constructor = UNSAFE_DIRECT_NIO_ENCODER.getConstructors()[0]; - return (CodedOutputStream)constructor.newInstance(buffer); - } catch (InstantiationException e) { - throw new RuntimeException(e); - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } catch (InvocationTargetException e) { - throw new RuntimeException(e); - } + return new UnsafeDirectNioEncoder(buffer); } /** For testing purposes only. */ static CodedOutputStream newSafeInstance(ByteBuffer buffer) { - try { - Constructor constructor = SAFE_DIRECT_NIO_ENCODER.getConstructors()[0]; - return (CodedOutputStream)constructor.newInstance(buffer); - } catch (InstantiationException e) { - throw new RuntimeException(e); - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } catch (InvocationTargetException e) { - throw new RuntimeException(e); - } + return new SafeDirectNioEncoder(buffer); } /** @@ -260,20 +193,12 @@ static CodedOutputStream newInstance(ByteOutput byteOutput, int bufferSize) { if (bufferSize < 0) { throw new IllegalArgumentException("bufferSize must be positive"); } - try { - Constructor constructor = BYTE_OUTPUT_ENCODER.getConstructors()[0]; - return (CodedOutputStream)constructor.newInstance(byteOutput, bufferSize); - } catch (InstantiationException e) { - throw new RuntimeException(e); - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } catch (InvocationTargetException e) { - throw new RuntimeException(e); - } + + return new ByteOutputEncoder(byteOutput, bufferSize); } // Disallow construction outside of this class. - CodedOutputStream() {} + private CodedOutputStream() {} // ----------------------------------------------------------------- @@ -727,9 +652,9 @@ static int computeMessageSize( * stream. For historical reasons, the wire format differs from normal fields. */ public static int computeMessageSetExtensionSize(final int fieldNumber, final MessageLite value) { - return computeTagSize(MESSAGE_SET_ITEM) * 2 - + computeUInt32Size(MESSAGE_SET_TYPE_ID, fieldNumber) - + computeMessageSize(MESSAGE_SET_MESSAGE, value); + return computeTagSize(WireFormat.MESSAGE_SET_ITEM) * 2 + + computeUInt32Size(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber) + + computeMessageSize(WireFormat.MESSAGE_SET_MESSAGE, value); } /** @@ -738,9 +663,9 @@ public static int computeMessageSetExtensionSize(final int fieldNumber, final Me */ public static int computeRawMessageSetExtensionSize( final int fieldNumber, final ByteString value) { - return computeTagSize(MESSAGE_SET_ITEM) * 2 - + computeUInt32Size(MESSAGE_SET_TYPE_ID, fieldNumber) - + computeBytesSize(MESSAGE_SET_MESSAGE, value); + return computeTagSize(WireFormat.MESSAGE_SET_ITEM) * 2 + + computeUInt32Size(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber) + + computeBytesSize(WireFormat.MESSAGE_SET_MESSAGE, value); } /** @@ -750,20 +675,16 @@ public static int computeRawMessageSetExtensionSize( */ public static int computeLazyFieldMessageSetExtensionSize( final int fieldNumber, final LazyFieldLite value) { - return computeTagSize(MESSAGE_SET_ITEM) * 2 - + computeUInt32Size(MESSAGE_SET_TYPE_ID, fieldNumber) - + computeLazyFieldSize(MESSAGE_SET_MESSAGE, value); + return computeTagSize(WireFormat.MESSAGE_SET_ITEM) * 2 + + computeUInt32Size(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber) + + computeLazyFieldSize(WireFormat.MESSAGE_SET_MESSAGE, value); } // ----------------------------------------------------------------- /** Compute the number of bytes that would be needed to encode a tag. */ public static int computeTagSize(final int fieldNumber) { - return computeUInt32SizeNoTag(makeTag(fieldNumber, 0)); - } - - static int makeTag(final int fieldNumber, final int wireType) { - return (fieldNumber << TAG_TYPE_BITS) | wireType; + return computeUInt32SizeNoTag(WireFormat.makeTag(fieldNumber, 0)); } /** @@ -935,7 +856,7 @@ public static int computeMessageSizeNoTag(final MessageLite value) { /** Compute the number of bytes that would be needed to encode an embedded message field. */ static int computeMessageSizeNoTag(final MessageLite value, final Schema schema) { - return computeLengthDelimitedFieldSize(getSerializedSize(value, schema)); + return computeLengthDelimitedFieldSize(((AbstractMessageLite) value).getSerializedSize(schema)); } static int computeLengthDelimitedFieldSize(int fieldLength) { @@ -1064,9 +985,9 @@ final void inefficientWriteStringNoTag(String value, UnpairedSurrogateException */ @Deprecated public final void writeGroup(final int fieldNumber, final MessageLite value) throws IOException { - writeTag(fieldNumber, WIRETYPE_START_GROUP); + writeTag(fieldNumber, WireFormat.WIRETYPE_START_GROUP); writeGroupNoTag(value); - writeTag(fieldNumber, WIRETYPE_END_GROUP); + writeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP); } /** @@ -1077,9 +998,9 @@ public final void writeGroup(final int fieldNumber, final MessageLite value) thr @Deprecated final void writeGroup(final int fieldNumber, final MessageLite value, Schema schema) throws IOException { - writeTag(fieldNumber, WIRETYPE_START_GROUP); + writeTag(fieldNumber, WireFormat.WIRETYPE_START_GROUP); writeGroupNoTag(value, schema); - writeTag(fieldNumber, WIRETYPE_END_GROUP); + writeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP); } /** @@ -1131,24 +1052,10 @@ public static int computeGroupSizeNoTag(final MessageLite value) { return value.getSerializedSize(); } - private static final Class ABSTRACT_MESSAGE_LITE = getClassForName("com.google.protobuf.AbstractMessageLite"); - /** Compute the number of bytes that would be needed to encode a {@code group} field. */ @Deprecated static int computeGroupSizeNoTag(final MessageLite value, Schema schema) { - return getSerializedSize(value, schema); - } - - private static int getSerializedSize(MessageLite value, Schema schema) { - try { - return (int) ABSTRACT_MESSAGE_LITE.getMethod("getSerializedSize", Schema.class).invoke(value, schema); - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } catch (InvocationTargetException e) { - throw new RuntimeException(e); - } catch (NoSuchMethodException e) { - throw new RuntimeException(e); - } + return ((AbstractMessageLite) value).getSerializedSize(schema); } /** @@ -1223,4 +1130,1893 @@ public final void writeRawLittleEndian64(final long value) throws IOException { writeFixed64NoTag(value); } + // ================================================================= + + /** A {@link CodedOutputStream} that writes directly to a byte array. */ + private static class ArrayEncoder extends CodedOutputStream { + private final byte[] buffer; + private final int offset; + private final int limit; + private int position; + + ArrayEncoder(byte[] buffer, int offset, int length) { + if (buffer == null) { + throw new NullPointerException("buffer"); + } + if ((offset | length | (buffer.length - (offset + length))) < 0) { + throw new IllegalArgumentException( + String.format( + "Array range is invalid. Buffer.length=%d, offset=%d, length=%d", + buffer.length, offset, length)); + } + this.buffer = buffer; + this.offset = offset; + position = offset; + limit = offset + length; + } + + @Override + public final void writeTag(final int fieldNumber, final int wireType) throws IOException { + writeUInt32NoTag(WireFormat.makeTag(fieldNumber, wireType)); + } + + @Override + public final void writeInt32(final int fieldNumber, final int value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); + writeInt32NoTag(value); + } + + @Override + public final void writeUInt32(final int fieldNumber, final int value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); + writeUInt32NoTag(value); + } + + @Override + public final void writeFixed32(final int fieldNumber, final int value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED32); + writeFixed32NoTag(value); + } + + @Override + public final void writeUInt64(final int fieldNumber, final long value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); + writeUInt64NoTag(value); + } + + @Override + public final void writeFixed64(final int fieldNumber, final long value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED64); + writeFixed64NoTag(value); + } + + @Override + public final void writeBool(final int fieldNumber, final boolean value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); + write((byte) (value ? 1 : 0)); + } + + @Override + public final void writeString(final int fieldNumber, final String value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeStringNoTag(value); + } + + @Override + public final void writeBytes(final int fieldNumber, final ByteString value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeBytesNoTag(value); + } + + @Override + public final void writeByteArray(final int fieldNumber, final byte[] value) throws IOException { + writeByteArray(fieldNumber, value, 0, value.length); + } + + @Override + public final void writeByteArray( + final int fieldNumber, final byte[] value, final int offset, final int length) + throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeByteArrayNoTag(value, offset, length); + } + + @Override + public final void writeByteBuffer(final int fieldNumber, final ByteBuffer value) + throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeUInt32NoTag(value.capacity()); + writeRawBytes(value); + } + + @Override + public final void writeBytesNoTag(final ByteString value) throws IOException { + writeUInt32NoTag(value.size()); + value.writeTo(this); + } + + @Override + public final void writeByteArrayNoTag(final byte[] value, int offset, int length) + throws IOException { + writeUInt32NoTag(length); + write(value, offset, length); + } + + @Override + public final void writeRawBytes(final ByteBuffer value) throws IOException { + if (value.hasArray()) { + write(value.array(), value.arrayOffset(), value.capacity()); + } else { + ByteBuffer duplicated = value.duplicate(); + Java8Compatibility.clear(duplicated); + write(duplicated); + } + } + + @Override + public final void writeMessage(final int fieldNumber, final MessageLite value) + throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeMessageNoTag(value); + } + + @Override + final void writeMessage(final int fieldNumber, final MessageLite value, Schema schema) + throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeUInt32NoTag(((AbstractMessageLite) value).getSerializedSize(schema)); + schema.writeTo(value, wrapper); + } + + @Override + public final void writeMessageSetExtension(final int fieldNumber, final MessageLite value) + throws IOException { + writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_START_GROUP); + writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber); + writeMessage(WireFormat.MESSAGE_SET_MESSAGE, value); + writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP); + } + + @Override + public final void writeRawMessageSetExtension(final int fieldNumber, final ByteString value) + throws IOException { + writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_START_GROUP); + writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber); + writeBytes(WireFormat.MESSAGE_SET_MESSAGE, value); + writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP); + } + + @Override + public final void writeMessageNoTag(final MessageLite value) throws IOException { + writeUInt32NoTag(value.getSerializedSize()); + value.writeTo(this); + } + + @Override + final void writeMessageNoTag(final MessageLite value, Schema schema) throws IOException { + writeUInt32NoTag(((AbstractMessageLite) value).getSerializedSize(schema)); + schema.writeTo(value, wrapper); + } + + @Override + public final void write(byte value) throws IOException { + try { + buffer[position++] = value; + } catch (IndexOutOfBoundsException e) { + throw new OutOfSpaceException( + String.format("Pos: %d, limit: %d, len: %d", position, limit, 1), e); + } + } + + @Override + public final void writeInt32NoTag(int value) throws IOException { + if (value >= 0) { + writeUInt32NoTag(value); + } else { + // Must sign-extend. + writeUInt64NoTag(value); + } + } + + @Override + public final void writeUInt32NoTag(int value) throws IOException { + try { + while (true) { + if ((value & ~0x7F) == 0) { + buffer[position++] = (byte) value; + return; + } else { + buffer[position++] = (byte) ((value & 0x7F) | 0x80); + value >>>= 7; + } + } + } catch (IndexOutOfBoundsException e) { + throw new OutOfSpaceException( + String.format("Pos: %d, limit: %d, len: %d", position, limit, 1), e); + } + } + + @Override + public final void writeFixed32NoTag(int value) throws IOException { + try { + buffer[position++] = (byte) (value & 0xFF); + buffer[position++] = (byte) ((value >> 8) & 0xFF); + buffer[position++] = (byte) ((value >> 16) & 0xFF); + buffer[position++] = (byte) ((value >> 24) & 0xFF); + } catch (IndexOutOfBoundsException e) { + throw new OutOfSpaceException( + String.format("Pos: %d, limit: %d, len: %d", position, limit, 1), e); + } + } + + @Override + public final void writeUInt64NoTag(long value) throws IOException { + if (HAS_UNSAFE_ARRAY_OPERATIONS && spaceLeft() >= MAX_VARINT_SIZE) { + while (true) { + if ((value & ~0x7FL) == 0) { + UnsafeUtil.putByte(buffer, position++, (byte) value); + return; + } else { + UnsafeUtil.putByte(buffer, position++, (byte) (((int) value & 0x7F) | 0x80)); + value >>>= 7; + } + } + } else { + try { + while (true) { + if ((value & ~0x7FL) == 0) { + buffer[position++] = (byte) value; + return; + } else { + buffer[position++] = (byte) (((int) value & 0x7F) | 0x80); + value >>>= 7; + } + } + } catch (IndexOutOfBoundsException e) { + throw new OutOfSpaceException( + String.format("Pos: %d, limit: %d, len: %d", position, limit, 1), e); + } + } + } + + @Override + public final void writeFixed64NoTag(long value) throws IOException { + try { + buffer[position++] = (byte) ((int) (value) & 0xFF); + buffer[position++] = (byte) ((int) (value >> 8) & 0xFF); + buffer[position++] = (byte) ((int) (value >> 16) & 0xFF); + buffer[position++] = (byte) ((int) (value >> 24) & 0xFF); + buffer[position++] = (byte) ((int) (value >> 32) & 0xFF); + buffer[position++] = (byte) ((int) (value >> 40) & 0xFF); + buffer[position++] = (byte) ((int) (value >> 48) & 0xFF); + buffer[position++] = (byte) ((int) (value >> 56) & 0xFF); + } catch (IndexOutOfBoundsException e) { + throw new OutOfSpaceException( + String.format("Pos: %d, limit: %d, len: %d", position, limit, 1), e); + } + } + + @Override + public final void write(byte[] value, int offset, int length) throws IOException { + try { + System.arraycopy(value, offset, buffer, position, length); + position += length; + } catch (IndexOutOfBoundsException e) { + throw new OutOfSpaceException( + String.format("Pos: %d, limit: %d, len: %d", position, limit, length), e); + } + } + + @Override + public final void writeLazy(byte[] value, int offset, int length) throws IOException { + write(value, offset, length); + } + + @Override + public final void write(ByteBuffer value) throws IOException { + final int length = value.remaining(); + try { + value.get(buffer, position, length); + position += length; + } catch (IndexOutOfBoundsException e) { + throw new OutOfSpaceException( + String.format("Pos: %d, limit: %d, len: %d", position, limit, length), e); + } + } + + @Override + public final void writeLazy(ByteBuffer value) throws IOException { + write(value); + } + + @Override + public final void writeStringNoTag(String value) throws IOException { + final int oldPosition = position; + try { + // UTF-8 byte length of the string is at least its UTF-16 code unit length (value.length()), + // and at most 3 times of it. We take advantage of this in both branches below. + final int maxLength = value.length() * Utf8.MAX_BYTES_PER_CHAR; + final int maxLengthVarIntSize = computeUInt32SizeNoTag(maxLength); + final int minLengthVarIntSize = computeUInt32SizeNoTag(value.length()); + if (minLengthVarIntSize == maxLengthVarIntSize) { + position = oldPosition + minLengthVarIntSize; + int newPosition = Utf8.encode(value, buffer, position, spaceLeft()); + // Since this class is stateful and tracks the position, we rewind and store the state, + // prepend the length, then reset it back to the end of the string. + position = oldPosition; + int length = newPosition - oldPosition - minLengthVarIntSize; + writeUInt32NoTag(length); + position = newPosition; + } else { + int length = Utf8.encodedLength(value); + writeUInt32NoTag(length); + position = Utf8.encode(value, buffer, position, spaceLeft()); + } + } catch (UnpairedSurrogateException e) { + // Roll back the change - we fall back to inefficient path. + position = oldPosition; + + // TODO: We should throw an IOException here instead. + inefficientWriteStringNoTag(value, e); + } catch (IndexOutOfBoundsException e) { + throw new OutOfSpaceException(e); + } + } + + @Override + public void flush() { + // Do nothing. + } + + @Override + public final int spaceLeft() { + return limit - position; + } + + @Override + public final int getTotalBytesWritten() { + return position - offset; + } + } + + /** + * A {@link CodedOutputStream} that writes directly to a heap {@link ByteBuffer}. Writes are done + * directly to the underlying array. The buffer position is only updated after a flush. + */ + private static final class HeapNioEncoder extends ArrayEncoder { + private final ByteBuffer byteBuffer; + private int initialPosition; + + HeapNioEncoder(ByteBuffer byteBuffer) { + super( + byteBuffer.array(), + byteBuffer.arrayOffset() + byteBuffer.position(), + byteBuffer.remaining()); + this.byteBuffer = byteBuffer; + this.initialPosition = byteBuffer.position(); + } + + @Override + public void flush() { + // Update the position on the buffer. + Java8Compatibility.position(byteBuffer, initialPosition + getTotalBytesWritten()); + } + } + + /** + * A {@link CodedOutputStream} that writes directly to a direct {@link ByteBuffer}, using only + * safe operations.. + */ + private static final class SafeDirectNioEncoder extends CodedOutputStream { + private final ByteBuffer originalBuffer; + private final ByteBuffer buffer; + private final int initialPosition; + + SafeDirectNioEncoder(ByteBuffer buffer) { + this.originalBuffer = buffer; + this.buffer = buffer.duplicate().order(ByteOrder.LITTLE_ENDIAN); + initialPosition = buffer.position(); + } + + @Override + public void writeTag(final int fieldNumber, final int wireType) throws IOException { + writeUInt32NoTag(WireFormat.makeTag(fieldNumber, wireType)); + } + + @Override + public void writeInt32(final int fieldNumber, final int value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); + writeInt32NoTag(value); + } + + @Override + public void writeUInt32(final int fieldNumber, final int value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); + writeUInt32NoTag(value); + } + + @Override + public void writeFixed32(final int fieldNumber, final int value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED32); + writeFixed32NoTag(value); + } + + @Override + public void writeUInt64(final int fieldNumber, final long value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); + writeUInt64NoTag(value); + } + + @Override + public void writeFixed64(final int fieldNumber, final long value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED64); + writeFixed64NoTag(value); + } + + @Override + public void writeBool(final int fieldNumber, final boolean value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); + write((byte) (value ? 1 : 0)); + } + + @Override + public void writeString(final int fieldNumber, final String value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeStringNoTag(value); + } + + @Override + public void writeBytes(final int fieldNumber, final ByteString value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeBytesNoTag(value); + } + + @Override + public void writeByteArray(final int fieldNumber, final byte[] value) throws IOException { + writeByteArray(fieldNumber, value, 0, value.length); + } + + @Override + public void writeByteArray( + final int fieldNumber, final byte[] value, final int offset, final int length) + throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeByteArrayNoTag(value, offset, length); + } + + @Override + public void writeByteBuffer(final int fieldNumber, final ByteBuffer value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeUInt32NoTag(value.capacity()); + writeRawBytes(value); + } + + @Override + public void writeMessage(final int fieldNumber, final MessageLite value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeMessageNoTag(value); + } + + @Override + void writeMessage(final int fieldNumber, final MessageLite value, Schema schema) + throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeMessageNoTag(value, schema); + } + + @Override + public void writeMessageSetExtension(final int fieldNumber, final MessageLite value) + throws IOException { + writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_START_GROUP); + writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber); + writeMessage(WireFormat.MESSAGE_SET_MESSAGE, value); + writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP); + } + + @Override + public void writeRawMessageSetExtension(final int fieldNumber, final ByteString value) + throws IOException { + writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_START_GROUP); + writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber); + writeBytes(WireFormat.MESSAGE_SET_MESSAGE, value); + writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP); + } + + @Override + public void writeMessageNoTag(final MessageLite value) throws IOException { + writeUInt32NoTag(value.getSerializedSize()); + value.writeTo(this); + } + + @Override + void writeMessageNoTag(final MessageLite value, Schema schema) throws IOException { + writeUInt32NoTag(((AbstractMessageLite) value).getSerializedSize(schema)); + schema.writeTo(value, wrapper); + } + + @Override + public void write(byte value) throws IOException { + try { + buffer.put(value); + } catch (BufferOverflowException e) { + throw new OutOfSpaceException(e); + } + } + + @Override + public void writeBytesNoTag(final ByteString value) throws IOException { + writeUInt32NoTag(value.size()); + value.writeTo(this); + } + + @Override + public void writeByteArrayNoTag(final byte[] value, int offset, int length) throws IOException { + writeUInt32NoTag(length); + write(value, offset, length); + } + + @Override + public void writeRawBytes(final ByteBuffer value) throws IOException { + if (value.hasArray()) { + write(value.array(), value.arrayOffset(), value.capacity()); + } else { + ByteBuffer duplicated = value.duplicate(); + Java8Compatibility.clear(duplicated); + write(duplicated); + } + } + + @Override + public void writeInt32NoTag(int value) throws IOException { + if (value >= 0) { + writeUInt32NoTag(value); + } else { + // Must sign-extend. + writeUInt64NoTag(value); + } + } + + @Override + public void writeUInt32NoTag(int value) throws IOException { + try { + while (true) { + if ((value & ~0x7F) == 0) { + buffer.put((byte) value); + return; + } else { + buffer.put((byte) ((value & 0x7F) | 0x80)); + value >>>= 7; + } + } + } catch (BufferOverflowException e) { + throw new OutOfSpaceException(e); + } + } + + @Override + public void writeFixed32NoTag(int value) throws IOException { + try { + buffer.putInt(value); + } catch (BufferOverflowException e) { + throw new OutOfSpaceException(e); + } + } + + @Override + public void writeUInt64NoTag(long value) throws IOException { + try { + while (true) { + if ((value & ~0x7FL) == 0) { + buffer.put((byte) value); + return; + } else { + buffer.put((byte) (((int) value & 0x7F) | 0x80)); + value >>>= 7; + } + } + } catch (BufferOverflowException e) { + throw new OutOfSpaceException(e); + } + } + + @Override + public void writeFixed64NoTag(long value) throws IOException { + try { + buffer.putLong(value); + } catch (BufferOverflowException e) { + throw new OutOfSpaceException(e); + } + } + + @Override + public void write(byte[] value, int offset, int length) throws IOException { + try { + buffer.put(value, offset, length); + } catch (IndexOutOfBoundsException e) { + throw new OutOfSpaceException(e); + } catch (BufferOverflowException e) { + throw new OutOfSpaceException(e); + } + } + + @Override + public void writeLazy(byte[] value, int offset, int length) throws IOException { + write(value, offset, length); + } + + @Override + public void write(ByteBuffer value) throws IOException { + try { + buffer.put(value); + } catch (BufferOverflowException e) { + throw new OutOfSpaceException(e); + } + } + + @Override + public void writeLazy(ByteBuffer value) throws IOException { + write(value); + } + + @Override + public void writeStringNoTag(String value) throws IOException { + final int startPos = buffer.position(); + try { + // UTF-8 byte length of the string is at least its UTF-16 code unit length (value.length()), + // and at most 3 times of it. We take advantage of this in both branches below. + final int maxEncodedSize = value.length() * Utf8.MAX_BYTES_PER_CHAR; + final int maxLengthVarIntSize = computeUInt32SizeNoTag(maxEncodedSize); + final int minLengthVarIntSize = computeUInt32SizeNoTag(value.length()); + if (minLengthVarIntSize == maxLengthVarIntSize) { + // Save the current position and increment past the length field. We'll come back + // and write the length field after the encoding is complete. + final int startOfBytes = buffer.position() + minLengthVarIntSize; + Java8Compatibility.position(buffer, startOfBytes); + + // Encode the string. + encode(value); + + // Now go back to the beginning and write the length. + int endOfBytes = buffer.position(); + Java8Compatibility.position(buffer, startPos); + writeUInt32NoTag(endOfBytes - startOfBytes); + + // Reposition the buffer past the written data. + Java8Compatibility.position(buffer, endOfBytes); + } else { + final int length = Utf8.encodedLength(value); + writeUInt32NoTag(length); + encode(value); + } + } catch (UnpairedSurrogateException e) { + // Roll back the change and convert to an IOException. + Java8Compatibility.position(buffer, startPos); + + // TODO: We should throw an IOException here instead. + inefficientWriteStringNoTag(value, e); + } catch (IllegalArgumentException e) { + // Thrown by buffer.position() if out of range. + throw new OutOfSpaceException(e); + } + } + + @Override + public void flush() { + // Update the position of the original buffer. + Java8Compatibility.position(originalBuffer, buffer.position()); + } + + @Override + public int spaceLeft() { + return buffer.remaining(); + } + + @Override + public int getTotalBytesWritten() { + return buffer.position() - initialPosition; + } + + private void encode(String value) throws IOException { + try { + Utf8.encodeUtf8(value, buffer); + } catch (IndexOutOfBoundsException e) { + throw new OutOfSpaceException(e); + } + } + } + + /** + * A {@link CodedOutputStream} that writes directly to a direct {@link ByteBuffer} using {@code + * sun.misc.Unsafe}. + */ + private static final class UnsafeDirectNioEncoder extends CodedOutputStream { + private final ByteBuffer originalBuffer; + private final ByteBuffer buffer; + private final long address; + private final long initialPosition; + private final long limit; + private final long oneVarintLimit; + private long position; + + UnsafeDirectNioEncoder(ByteBuffer buffer) { + this.originalBuffer = buffer; + this.buffer = buffer.duplicate().order(ByteOrder.LITTLE_ENDIAN); + address = UnsafeUtil.addressOffset(buffer); + initialPosition = address + buffer.position(); + limit = address + buffer.limit(); + oneVarintLimit = limit - MAX_VARINT_SIZE; + position = initialPosition; + } + + static boolean isSupported() { + return UnsafeUtil.hasUnsafeByteBufferOperations(); + } + + @Override + public void writeTag(int fieldNumber, int wireType) throws IOException { + writeUInt32NoTag(WireFormat.makeTag(fieldNumber, wireType)); + } + + @Override + public void writeInt32(int fieldNumber, int value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); + writeInt32NoTag(value); + } + + @Override + public void writeUInt32(int fieldNumber, int value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); + writeUInt32NoTag(value); + } + + @Override + public void writeFixed32(int fieldNumber, int value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED32); + writeFixed32NoTag(value); + } + + @Override + public void writeUInt64(int fieldNumber, long value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); + writeUInt64NoTag(value); + } + + @Override + public void writeFixed64(int fieldNumber, long value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED64); + writeFixed64NoTag(value); + } + + @Override + public void writeBool(int fieldNumber, boolean value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); + write((byte) (value ? 1 : 0)); + } + + @Override + public void writeString(int fieldNumber, String value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeStringNoTag(value); + } + + @Override + public void writeBytes(int fieldNumber, ByteString value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeBytesNoTag(value); + } + + @Override + public void writeByteArray(int fieldNumber, byte[] value) throws IOException { + writeByteArray(fieldNumber, value, 0, value.length); + } + + @Override + public void writeByteArray(int fieldNumber, byte[] value, int offset, int length) + throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeByteArrayNoTag(value, offset, length); + } + + @Override + public void writeByteBuffer(int fieldNumber, ByteBuffer value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeUInt32NoTag(value.capacity()); + writeRawBytes(value); + } + + @Override + public void writeMessage(int fieldNumber, MessageLite value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeMessageNoTag(value); + } + + @Override + void writeMessage(int fieldNumber, MessageLite value, Schema schema) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeMessageNoTag(value, schema); + } + + @Override + public void writeMessageSetExtension(int fieldNumber, MessageLite value) throws IOException { + writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_START_GROUP); + writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber); + writeMessage(WireFormat.MESSAGE_SET_MESSAGE, value); + writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP); + } + + @Override + public void writeRawMessageSetExtension(int fieldNumber, ByteString value) throws IOException { + writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_START_GROUP); + writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber); + writeBytes(WireFormat.MESSAGE_SET_MESSAGE, value); + writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP); + } + + @Override + public void writeMessageNoTag(MessageLite value) throws IOException { + writeUInt32NoTag(value.getSerializedSize()); + value.writeTo(this); + } + + @Override + void writeMessageNoTag(MessageLite value, Schema schema) throws IOException { + writeUInt32NoTag(((AbstractMessageLite) value).getSerializedSize(schema)); + schema.writeTo(value, wrapper); + } + + @Override + public void write(byte value) throws IOException { + if (position >= limit) { + throw new OutOfSpaceException( + String.format("Pos: %d, limit: %d, len: %d", position, limit, 1)); + } + UnsafeUtil.putByte(position++, value); + } + + @Override + public void writeBytesNoTag(ByteString value) throws IOException { + writeUInt32NoTag(value.size()); + value.writeTo(this); + } + + @Override + public void writeByteArrayNoTag(byte[] value, int offset, int length) throws IOException { + writeUInt32NoTag(length); + write(value, offset, length); + } + + @Override + public void writeRawBytes(ByteBuffer value) throws IOException { + if (value.hasArray()) { + write(value.array(), value.arrayOffset(), value.capacity()); + } else { + ByteBuffer duplicated = value.duplicate(); + Java8Compatibility.clear(duplicated); + write(duplicated); + } + } + + @Override + public void writeInt32NoTag(int value) throws IOException { + if (value >= 0) { + writeUInt32NoTag(value); + } else { + // Must sign-extend. + writeUInt64NoTag(value); + } + } + + @Override + public void writeUInt32NoTag(int value) throws IOException { + if (position <= oneVarintLimit) { + // Optimization to avoid bounds checks on each iteration. + while (true) { + if ((value & ~0x7F) == 0) { + UnsafeUtil.putByte(position++, (byte) value); + return; + } else { + UnsafeUtil.putByte(position++, (byte) ((value & 0x7F) | 0x80)); + value >>>= 7; + } + } + } else { + while (position < limit) { + if ((value & ~0x7F) == 0) { + UnsafeUtil.putByte(position++, (byte) value); + return; + } else { + UnsafeUtil.putByte(position++, (byte) ((value & 0x7F) | 0x80)); + value >>>= 7; + } + } + throw new OutOfSpaceException( + String.format("Pos: %d, limit: %d, len: %d", position, limit, 1)); + } + } + + @Override + public void writeFixed32NoTag(int value) throws IOException { + buffer.putInt(bufferPos(position), value); + position += FIXED32_SIZE; + } + + @Override + public void writeUInt64NoTag(long value) throws IOException { + if (position <= oneVarintLimit) { + // Optimization to avoid bounds checks on each iteration. + while (true) { + if ((value & ~0x7FL) == 0) { + UnsafeUtil.putByte(position++, (byte) value); + return; + } else { + UnsafeUtil.putByte(position++, (byte) (((int) value & 0x7F) | 0x80)); + value >>>= 7; + } + } + } else { + while (position < limit) { + if ((value & ~0x7FL) == 0) { + UnsafeUtil.putByte(position++, (byte) value); + return; + } else { + UnsafeUtil.putByte(position++, (byte) (((int) value & 0x7F) | 0x80)); + value >>>= 7; + } + } + throw new OutOfSpaceException( + String.format("Pos: %d, limit: %d, len: %d", position, limit, 1)); + } + } + + @Override + public void writeFixed64NoTag(long value) throws IOException { + buffer.putLong(bufferPos(position), value); + position += FIXED64_SIZE; + } + + @Override + public void write(byte[] value, int offset, int length) throws IOException { + if (value == null + || offset < 0 + || length < 0 + || (value.length - length) < offset + || (limit - length) < position) { + if (value == null) { + throw new NullPointerException("value"); + } + throw new OutOfSpaceException( + String.format("Pos: %d, limit: %d, len: %d", position, limit, length)); + } + + UnsafeUtil.copyMemory(value, offset, position, length); + position += length; + } + + @Override + public void writeLazy(byte[] value, int offset, int length) throws IOException { + write(value, offset, length); + } + + @Override + public void write(ByteBuffer value) throws IOException { + try { + int length = value.remaining(); + repositionBuffer(position); + buffer.put(value); + position += length; + } catch (BufferOverflowException e) { + throw new OutOfSpaceException(e); + } + } + + @Override + public void writeLazy(ByteBuffer value) throws IOException { + write(value); + } + + @Override + public void writeStringNoTag(String value) throws IOException { + long prevPos = position; + try { + // UTF-8 byte length of the string is at least its UTF-16 code unit length (value.length()), + // and at most 3 times of it. We take advantage of this in both branches below. + int maxEncodedSize = value.length() * Utf8.MAX_BYTES_PER_CHAR; + int maxLengthVarIntSize = computeUInt32SizeNoTag(maxEncodedSize); + int minLengthVarIntSize = computeUInt32SizeNoTag(value.length()); + if (minLengthVarIntSize == maxLengthVarIntSize) { + // Save the current position and increment past the length field. We'll come back + // and write the length field after the encoding is complete. + int stringStart = bufferPos(position) + minLengthVarIntSize; + Java8Compatibility.position(buffer, stringStart); + + // Encode the string. + Utf8.encodeUtf8(value, buffer); + + // Write the length and advance the position. + int length = buffer.position() - stringStart; + writeUInt32NoTag(length); + position += length; + } else { + // Calculate and write the encoded length. + int length = Utf8.encodedLength(value); + writeUInt32NoTag(length); + + // Write the string and advance the position. + repositionBuffer(position); + Utf8.encodeUtf8(value, buffer); + position += length; + } + } catch (UnpairedSurrogateException e) { + // Roll back the change and convert to an IOException. + position = prevPos; + repositionBuffer(position); + + // TODO: We should throw an IOException here instead. + inefficientWriteStringNoTag(value, e); + } catch (IllegalArgumentException e) { + // Thrown by buffer.position() if out of range. + throw new OutOfSpaceException(e); + } catch (IndexOutOfBoundsException e) { + throw new OutOfSpaceException(e); + } + } + + @Override + public void flush() { + // Update the position of the original buffer. + Java8Compatibility.position(originalBuffer, bufferPos(position)); + } + + @Override + public int spaceLeft() { + return (int) (limit - position); + } + + @Override + public int getTotalBytesWritten() { + return (int) (position - initialPosition); + } + + private void repositionBuffer(long pos) { + Java8Compatibility.position(buffer, bufferPos(pos)); + } + + private int bufferPos(long pos) { + return (int) (pos - address); + } + } + + /** Abstract base class for buffered encoders. */ + private abstract static class AbstractBufferedEncoder extends CodedOutputStream { + final byte[] buffer; + final int limit; + int position; + int totalBytesWritten; + + AbstractBufferedEncoder(int bufferSize) { + if (bufferSize < 0) { + throw new IllegalArgumentException("bufferSize must be >= 0"); + } + // As an optimization, we require that the buffer be able to store at least 2 + // varints so that we can buffer any integer write (tag + value). This reduces the + // number of range checks for a single write to 1 (i.e. if there is not enough space + // to buffer the tag+value, flush and then buffer it). + this.buffer = new byte[max(bufferSize, MAX_VARINT_SIZE * 2)]; + this.limit = buffer.length; + } + + @Override + public final int spaceLeft() { + throw new UnsupportedOperationException( + "spaceLeft() can only be called on CodedOutputStreams that are " + + "writing to a flat array or ByteBuffer."); + } + + @Override + public final int getTotalBytesWritten() { + return totalBytesWritten; + } + + /** + * This method does not perform bounds checking on the array. Checking array bounds is the + * responsibility of the caller. + */ + final void buffer(byte value) { + buffer[position++] = value; + totalBytesWritten++; + } + + /** + * This method does not perform bounds checking on the array. Checking array bounds is the + * responsibility of the caller. + */ + final void bufferTag(final int fieldNumber, final int wireType) { + bufferUInt32NoTag(WireFormat.makeTag(fieldNumber, wireType)); + } + + /** + * This method does not perform bounds checking on the array. Checking array bounds is the + * responsibility of the caller. + */ + final void bufferInt32NoTag(final int value) { + if (value >= 0) { + bufferUInt32NoTag(value); + } else { + // Must sign-extend. + bufferUInt64NoTag(value); + } + } + + /** + * This method does not perform bounds checking on the array. Checking array bounds is the + * responsibility of the caller. + */ + final void bufferUInt32NoTag(int value) { + if (HAS_UNSAFE_ARRAY_OPERATIONS) { + final long originalPos = position; + while (true) { + if ((value & ~0x7F) == 0) { + UnsafeUtil.putByte(buffer, position++, (byte) value); + break; + } else { + UnsafeUtil.putByte(buffer, position++, (byte) ((value & 0x7F) | 0x80)); + value >>>= 7; + } + } + int delta = (int) (position - originalPos); + totalBytesWritten += delta; + } else { + while (true) { + if ((value & ~0x7F) == 0) { + buffer[position++] = (byte) value; + totalBytesWritten++; + return; + } else { + buffer[position++] = (byte) ((value & 0x7F) | 0x80); + totalBytesWritten++; + value >>>= 7; + } + } + } + } + + /** + * This method does not perform bounds checking on the array. Checking array bounds is the + * responsibility of the caller. + */ + final void bufferUInt64NoTag(long value) { + if (HAS_UNSAFE_ARRAY_OPERATIONS) { + final long originalPos = position; + while (true) { + if ((value & ~0x7FL) == 0) { + UnsafeUtil.putByte(buffer, position++, (byte) value); + break; + } else { + UnsafeUtil.putByte(buffer, position++, (byte) (((int) value & 0x7F) | 0x80)); + value >>>= 7; + } + } + int delta = (int) (position - originalPos); + totalBytesWritten += delta; + } else { + while (true) { + if ((value & ~0x7FL) == 0) { + buffer[position++] = (byte) value; + totalBytesWritten++; + return; + } else { + buffer[position++] = (byte) (((int) value & 0x7F) | 0x80); + totalBytesWritten++; + value >>>= 7; + } + } + } + } + + /** + * This method does not perform bounds checking on the array. Checking array bounds is the + * responsibility of the caller. + */ + final void bufferFixed32NoTag(int value) { + buffer[position++] = (byte) (value & 0xFF); + buffer[position++] = (byte) ((value >> 8) & 0xFF); + buffer[position++] = (byte) ((value >> 16) & 0xFF); + buffer[position++] = (byte) ((value >> 24) & 0xFF); + totalBytesWritten += FIXED32_SIZE; + } + + /** + * This method does not perform bounds checking on the array. Checking array bounds is the + * responsibility of the caller. + */ + final void bufferFixed64NoTag(long value) { + buffer[position++] = (byte) (value & 0xFF); + buffer[position++] = (byte) ((value >> 8) & 0xFF); + buffer[position++] = (byte) ((value >> 16) & 0xFF); + buffer[position++] = (byte) ((value >> 24) & 0xFF); + buffer[position++] = (byte) ((int) (value >> 32) & 0xFF); + buffer[position++] = (byte) ((int) (value >> 40) & 0xFF); + buffer[position++] = (byte) ((int) (value >> 48) & 0xFF); + buffer[position++] = (byte) ((int) (value >> 56) & 0xFF); + totalBytesWritten += FIXED64_SIZE; + } + } + + /** + * A {@link CodedOutputStream} that decorates a {@link ByteOutput}. It internal buffer only to + * support string encoding operations. All other writes are just passed through to the {@link + * ByteOutput}. + */ + private static final class ByteOutputEncoder extends AbstractBufferedEncoder { + private final ByteOutput out; + + ByteOutputEncoder(ByteOutput out, int bufferSize) { + super(bufferSize); + if (out == null) { + throw new NullPointerException("out"); + } + this.out = out; + } + + @Override + public void writeTag(final int fieldNumber, final int wireType) throws IOException { + writeUInt32NoTag(WireFormat.makeTag(fieldNumber, wireType)); + } + + @Override + public void writeInt32(final int fieldNumber, final int value) throws IOException { + flushIfNotAvailable(MAX_VARINT_SIZE * 2); + bufferTag(fieldNumber, WireFormat.WIRETYPE_VARINT); + bufferInt32NoTag(value); + } + + @Override + public void writeUInt32(final int fieldNumber, final int value) throws IOException { + flushIfNotAvailable(MAX_VARINT_SIZE * 2); + bufferTag(fieldNumber, WireFormat.WIRETYPE_VARINT); + bufferUInt32NoTag(value); + } + + @Override + public void writeFixed32(final int fieldNumber, final int value) throws IOException { + flushIfNotAvailable(MAX_VARINT_SIZE + FIXED32_SIZE); + bufferTag(fieldNumber, WireFormat.WIRETYPE_FIXED32); + bufferFixed32NoTag(value); + } + + @Override + public void writeUInt64(final int fieldNumber, final long value) throws IOException { + flushIfNotAvailable(MAX_VARINT_SIZE * 2); + bufferTag(fieldNumber, WireFormat.WIRETYPE_VARINT); + bufferUInt64NoTag(value); + } + + @Override + public void writeFixed64(final int fieldNumber, final long value) throws IOException { + flushIfNotAvailable(MAX_VARINT_SIZE + FIXED64_SIZE); + bufferTag(fieldNumber, WireFormat.WIRETYPE_FIXED64); + bufferFixed64NoTag(value); + } + + @Override + public void writeBool(final int fieldNumber, final boolean value) throws IOException { + flushIfNotAvailable(MAX_VARINT_SIZE + 1); + bufferTag(fieldNumber, WireFormat.WIRETYPE_VARINT); + buffer((byte) (value ? 1 : 0)); + } + + @Override + public void writeString(final int fieldNumber, final String value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeStringNoTag(value); + } + + @Override + public void writeBytes(final int fieldNumber, final ByteString value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeBytesNoTag(value); + } + + @Override + public void writeByteArray(final int fieldNumber, final byte[] value) throws IOException { + writeByteArray(fieldNumber, value, 0, value.length); + } + + @Override + public void writeByteArray( + final int fieldNumber, final byte[] value, final int offset, final int length) + throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeByteArrayNoTag(value, offset, length); + } + + @Override + public void writeByteBuffer(final int fieldNumber, final ByteBuffer value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeUInt32NoTag(value.capacity()); + writeRawBytes(value); + } + + @Override + public void writeBytesNoTag(final ByteString value) throws IOException { + writeUInt32NoTag(value.size()); + value.writeTo(this); + } + + @Override + public void writeByteArrayNoTag(final byte[] value, int offset, int length) throws IOException { + writeUInt32NoTag(length); + write(value, offset, length); + } + + @Override + public void writeRawBytes(final ByteBuffer value) throws IOException { + if (value.hasArray()) { + write(value.array(), value.arrayOffset(), value.capacity()); + } else { + ByteBuffer duplicated = value.duplicate(); + Java8Compatibility.clear(duplicated); + write(duplicated); + } + } + + @Override + public void writeMessage(final int fieldNumber, final MessageLite value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeMessageNoTag(value); + } + + @Override + void writeMessage(final int fieldNumber, final MessageLite value, Schema schema) + throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeMessageNoTag(value, schema); + } + + @Override + public void writeMessageSetExtension(final int fieldNumber, final MessageLite value) + throws IOException { + writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_START_GROUP); + writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber); + writeMessage(WireFormat.MESSAGE_SET_MESSAGE, value); + writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP); + } + + @Override + public void writeRawMessageSetExtension(final int fieldNumber, final ByteString value) + throws IOException { + writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_START_GROUP); + writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber); + writeBytes(WireFormat.MESSAGE_SET_MESSAGE, value); + writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP); + } + + @Override + public void writeMessageNoTag(final MessageLite value) throws IOException { + writeUInt32NoTag(value.getSerializedSize()); + value.writeTo(this); + } + + @Override + void writeMessageNoTag(final MessageLite value, Schema schema) throws IOException { + writeUInt32NoTag(((AbstractMessageLite) value).getSerializedSize(schema)); + schema.writeTo(value, wrapper); + } + + @Override + public void write(byte value) throws IOException { + if (position == limit) { + doFlush(); + } + + buffer(value); + } + + @Override + public void writeInt32NoTag(int value) throws IOException { + if (value >= 0) { + writeUInt32NoTag(value); + } else { + // Must sign-extend. + writeUInt64NoTag(value); + } + } + + @Override + public void writeUInt32NoTag(int value) throws IOException { + flushIfNotAvailable(MAX_VARINT32_SIZE); + bufferUInt32NoTag(value); + } + + @Override + public void writeFixed32NoTag(final int value) throws IOException { + flushIfNotAvailable(FIXED32_SIZE); + bufferFixed32NoTag(value); + } + + @Override + public void writeUInt64NoTag(long value) throws IOException { + flushIfNotAvailable(MAX_VARINT_SIZE); + bufferUInt64NoTag(value); + } + + @Override + public void writeFixed64NoTag(final long value) throws IOException { + flushIfNotAvailable(FIXED64_SIZE); + bufferFixed64NoTag(value); + } + + @Override + public void writeStringNoTag(String value) throws IOException { + // UTF-8 byte length of the string is at least its UTF-16 code unit length (value.length()), + // and at most 3 times of it. We take advantage of this in both branches below. + final int maxLength = value.length() * Utf8.MAX_BYTES_PER_CHAR; + final int maxLengthVarIntSize = computeUInt32SizeNoTag(maxLength); + + // If we are streaming and the potential length is too big to fit in our buffer, we take the + // slower path. + if (maxLengthVarIntSize + maxLength > limit) { + // Allocate a byte[] that we know can fit the string and encode into it. String.getBytes() + // does the same internally and then does *another copy* to return a byte[] of exactly the + // right size. We can skip that copy and just writeRawBytes up to the actualLength of the + // UTF-8 encoded bytes. + final byte[] encodedBytes = new byte[maxLength]; + int actualLength = Utf8.encode(value, encodedBytes, 0, maxLength); + writeUInt32NoTag(actualLength); + writeLazy(encodedBytes, 0, actualLength); + return; + } + + // Fast path: we have enough space available in our buffer for the string... + if (maxLengthVarIntSize + maxLength > limit - position) { + // Flush to free up space. + doFlush(); + } + + final int oldPosition = position; + try { + // Optimize for the case where we know this length results in a constant varint length as + // this saves a pass for measuring the length of the string. + final int minLengthVarIntSize = computeUInt32SizeNoTag(value.length()); + + if (minLengthVarIntSize == maxLengthVarIntSize) { + position = oldPosition + minLengthVarIntSize; + int newPosition = Utf8.encode(value, buffer, position, limit - position); + // Since this class is stateful and tracks the position, we rewind and store the state, + // prepend the length, then reset it back to the end of the string. + position = oldPosition; + int length = newPosition - oldPosition - minLengthVarIntSize; + bufferUInt32NoTag(length); + position = newPosition; + totalBytesWritten += length; + } else { + int length = Utf8.encodedLength(value); + bufferUInt32NoTag(length); + position = Utf8.encode(value, buffer, position, length); + totalBytesWritten += length; + } + } catch (UnpairedSurrogateException e) { + // Roll back the change and convert to an IOException. + totalBytesWritten -= position - oldPosition; + position = oldPosition; + + // TODO: We should throw an IOException here instead. + inefficientWriteStringNoTag(value, e); + } catch (IndexOutOfBoundsException e) { + throw new OutOfSpaceException(e); + } + } + + @Override + public void flush() throws IOException { + if (position > 0) { + // Flush the buffer. + doFlush(); + } + } + + @Override + public void write(byte[] value, int offset, int length) throws IOException { + flush(); + out.write(value, offset, length); + totalBytesWritten += length; + } + + @Override + public void writeLazy(byte[] value, int offset, int length) throws IOException { + flush(); + out.writeLazy(value, offset, length); + totalBytesWritten += length; + } + + @Override + public void write(ByteBuffer value) throws IOException { + flush(); + int length = value.remaining(); + out.write(value); + totalBytesWritten += length; + } + + @Override + public void writeLazy(ByteBuffer value) throws IOException { + flush(); + int length = value.remaining(); + out.writeLazy(value); + totalBytesWritten += length; + } + + private void flushIfNotAvailable(int requiredSize) throws IOException { + if (limit - position < requiredSize) { + doFlush(); + } + } + + private void doFlush() throws IOException { + out.write(buffer, 0, position); + position = 0; + } + } + + /** + * An {@link CodedOutputStream} that decorates an {@link OutputStream}. It performs internal + * buffering to optimize writes to the {@link OutputStream}. + */ + private static final class OutputStreamEncoder extends AbstractBufferedEncoder { + private final OutputStream out; + + OutputStreamEncoder(OutputStream out, int bufferSize) { + super(bufferSize); + if (out == null) { + throw new NullPointerException("out"); + } + this.out = out; + } + + @Override + public void writeTag(final int fieldNumber, final int wireType) throws IOException { + writeUInt32NoTag(WireFormat.makeTag(fieldNumber, wireType)); + } + + @Override + public void writeInt32(final int fieldNumber, final int value) throws IOException { + flushIfNotAvailable(MAX_VARINT_SIZE * 2); + bufferTag(fieldNumber, WireFormat.WIRETYPE_VARINT); + bufferInt32NoTag(value); + } + + @Override + public void writeUInt32(final int fieldNumber, final int value) throws IOException { + flushIfNotAvailable(MAX_VARINT_SIZE * 2); + bufferTag(fieldNumber, WireFormat.WIRETYPE_VARINT); + bufferUInt32NoTag(value); + } + + @Override + public void writeFixed32(final int fieldNumber, final int value) throws IOException { + flushIfNotAvailable(MAX_VARINT_SIZE + FIXED32_SIZE); + bufferTag(fieldNumber, WireFormat.WIRETYPE_FIXED32); + bufferFixed32NoTag(value); + } + + @Override + public void writeUInt64(final int fieldNumber, final long value) throws IOException { + flushIfNotAvailable(MAX_VARINT_SIZE * 2); + bufferTag(fieldNumber, WireFormat.WIRETYPE_VARINT); + bufferUInt64NoTag(value); + } + + @Override + public void writeFixed64(final int fieldNumber, final long value) throws IOException { + flushIfNotAvailable(MAX_VARINT_SIZE + FIXED64_SIZE); + bufferTag(fieldNumber, WireFormat.WIRETYPE_FIXED64); + bufferFixed64NoTag(value); + } + + @Override + public void writeBool(final int fieldNumber, final boolean value) throws IOException { + flushIfNotAvailable(MAX_VARINT_SIZE + 1); + bufferTag(fieldNumber, WireFormat.WIRETYPE_VARINT); + buffer((byte) (value ? 1 : 0)); + } + + @Override + public void writeString(final int fieldNumber, final String value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeStringNoTag(value); + } + + @Override + public void writeBytes(final int fieldNumber, final ByteString value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeBytesNoTag(value); + } + + @Override + public void writeByteArray(final int fieldNumber, final byte[] value) throws IOException { + writeByteArray(fieldNumber, value, 0, value.length); + } + + @Override + public void writeByteArray( + final int fieldNumber, final byte[] value, final int offset, final int length) + throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeByteArrayNoTag(value, offset, length); + } + + @Override + public void writeByteBuffer(final int fieldNumber, final ByteBuffer value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeUInt32NoTag(value.capacity()); + writeRawBytes(value); + } + + @Override + public void writeBytesNoTag(final ByteString value) throws IOException { + writeUInt32NoTag(value.size()); + value.writeTo(this); + } + + @Override + public void writeByteArrayNoTag(final byte[] value, int offset, int length) throws IOException { + writeUInt32NoTag(length); + write(value, offset, length); + } + + @Override + public void writeRawBytes(final ByteBuffer value) throws IOException { + if (value.hasArray()) { + write(value.array(), value.arrayOffset(), value.capacity()); + } else { + ByteBuffer duplicated = value.duplicate(); + Java8Compatibility.clear(duplicated); + write(duplicated); + } + } + + @Override + public void writeMessage(final int fieldNumber, final MessageLite value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeMessageNoTag(value); + } + + @Override + void writeMessage(final int fieldNumber, final MessageLite value, Schema schema) + throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeMessageNoTag(value, schema); + } + + @Override + public void writeMessageSetExtension(final int fieldNumber, final MessageLite value) + throws IOException { + writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_START_GROUP); + writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber); + writeMessage(WireFormat.MESSAGE_SET_MESSAGE, value); + writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP); + } + + @Override + public void writeRawMessageSetExtension(final int fieldNumber, final ByteString value) + throws IOException { + writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_START_GROUP); + writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber); + writeBytes(WireFormat.MESSAGE_SET_MESSAGE, value); + writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP); + } + + @Override + public void writeMessageNoTag(final MessageLite value) throws IOException { + writeUInt32NoTag(value.getSerializedSize()); + value.writeTo(this); + } + + @Override + void writeMessageNoTag(final MessageLite value, Schema schema) throws IOException { + writeUInt32NoTag(((AbstractMessageLite) value).getSerializedSize(schema)); + schema.writeTo(value, wrapper); + } + + @Override + public void write(byte value) throws IOException { + if (position == limit) { + doFlush(); + } + + buffer(value); + } + + @Override + public void writeInt32NoTag(int value) throws IOException { + if (value >= 0) { + writeUInt32NoTag(value); + } else { + // Must sign-extend. + writeUInt64NoTag(value); + } + } + + @Override + public void writeUInt32NoTag(int value) throws IOException { + flushIfNotAvailable(MAX_VARINT32_SIZE); + bufferUInt32NoTag(value); + } + + @Override + public void writeFixed32NoTag(final int value) throws IOException { + flushIfNotAvailable(FIXED32_SIZE); + bufferFixed32NoTag(value); + } + + @Override + public void writeUInt64NoTag(long value) throws IOException { + flushIfNotAvailable(MAX_VARINT_SIZE); + bufferUInt64NoTag(value); + } + + @Override + public void writeFixed64NoTag(final long value) throws IOException { + flushIfNotAvailable(FIXED64_SIZE); + bufferFixed64NoTag(value); + } + + @Override + public void writeStringNoTag(String value) throws IOException { + try { + // UTF-8 byte length of the string is at least its UTF-16 code unit length (value.length()), + // and at most 3 times of it. We take advantage of this in both branches below. + final int maxLength = value.length() * Utf8.MAX_BYTES_PER_CHAR; + final int maxLengthVarIntSize = computeUInt32SizeNoTag(maxLength); + + // If we are streaming and the potential length is too big to fit in our buffer, we take the + // slower path. + if (maxLengthVarIntSize + maxLength > limit) { + // Allocate a byte[] that we know can fit the string and encode into it. String.getBytes() + // does the same internally and then does *another copy* to return a byte[] of exactly the + // right size. We can skip that copy and just writeRawBytes up to the actualLength of the + // UTF-8 encoded bytes. + final byte[] encodedBytes = new byte[maxLength]; + int actualLength = Utf8.encode(value, encodedBytes, 0, maxLength); + writeUInt32NoTag(actualLength); + writeLazy(encodedBytes, 0, actualLength); + return; + } + + // Fast path: we have enough space available in our buffer for the string... + if (maxLengthVarIntSize + maxLength > limit - position) { + // Flush to free up space. + doFlush(); + } + + // Optimize for the case where we know this length results in a constant varint length as + // this saves a pass for measuring the length of the string. + final int minLengthVarIntSize = computeUInt32SizeNoTag(value.length()); + int oldPosition = position; + final int length; + try { + if (minLengthVarIntSize == maxLengthVarIntSize) { + position = oldPosition + minLengthVarIntSize; + int newPosition = Utf8.encode(value, buffer, position, limit - position); + // Since this class is stateful and tracks the position, we rewind and store the + // state, prepend the length, then reset it back to the end of the string. + position = oldPosition; + length = newPosition - oldPosition - minLengthVarIntSize; + bufferUInt32NoTag(length); + position = newPosition; + } else { + length = Utf8.encodedLength(value); + bufferUInt32NoTag(length); + position = Utf8.encode(value, buffer, position, length); + } + totalBytesWritten += length; + } catch (UnpairedSurrogateException e) { + // Be extra careful and restore the original position for retrying the write with the + // less efficient path. + totalBytesWritten -= position - oldPosition; + position = oldPosition; + throw e; + } catch (ArrayIndexOutOfBoundsException e) { + throw new OutOfSpaceException(e); + } + } catch (UnpairedSurrogateException e) { + inefficientWriteStringNoTag(value, e); + } + } + + @Override + public void flush() throws IOException { + if (position > 0) { + // Flush the buffer. + doFlush(); + } + } + + @Override + public void write(byte[] value, int offset, int length) throws IOException { + if (limit - position >= length) { + // We have room in the current buffer. + System.arraycopy(value, offset, buffer, position, length); + position += length; + totalBytesWritten += length; + } else { + // Write extends past current buffer. Fill the rest of this buffer and + // flush. + final int bytesWritten = limit - position; + System.arraycopy(value, offset, buffer, position, bytesWritten); + offset += bytesWritten; + length -= bytesWritten; + position = limit; + totalBytesWritten += bytesWritten; + doFlush(); + + // Now deal with the rest. + // Since we have an output stream, this is our buffer + // and buffer offset == 0 + if (length <= limit) { + // Fits in new buffer. + System.arraycopy(value, offset, buffer, 0, length); + position = length; + } else { + // Write is very big. Let's do it all at once. + out.write(value, offset, length); + } + totalBytesWritten += length; + } + } + + @Override + public void writeLazy(byte[] value, int offset, int length) throws IOException { + write(value, offset, length); + } + + @Override + public void write(ByteBuffer value) throws IOException { + int length = value.remaining(); + if (limit - position >= length) { + // We have room in the current buffer. + value.get(buffer, position, length); + position += length; + totalBytesWritten += length; + } else { + // Write extends past current buffer. Fill the rest of this buffer and + // flush. + final int bytesWritten = limit - position; + value.get(buffer, position, bytesWritten); + length -= bytesWritten; + position = limit; + totalBytesWritten += bytesWritten; + doFlush(); + + // Now deal with the rest. + // Since we have an output stream, this is our buffer + // and buffer offset == 0 + while (length > limit) { + // Copy data into the buffer before writing it to OutputStream. + value.get(buffer, 0, limit); + out.write(buffer, 0, limit); + length -= limit; + totalBytesWritten += limit; + } + value.get(buffer, 0, length); + position = length; + totalBytesWritten += length; + } + } + + @Override + public void writeLazy(ByteBuffer value) throws IOException { + write(value); + } + + private void flushIfNotAvailable(int requiredSize) throws IOException { + if (limit - position < requiredSize) { + doFlush(); + } + } + + private void doFlush() throws IOException { + out.write(buffer, 0, position); + position = 0; + } + } } diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/AbstractBufferedEncoder.java b/protobuf-sdk/src/main/java/com/google/protobuf/AbstractBufferedEncoder.java deleted file mode 100644 index cafbf01..0000000 --- a/protobuf-sdk/src/main/java/com/google/protobuf/AbstractBufferedEncoder.java +++ /dev/null @@ -1,160 +0,0 @@ -package com.google.protobuf; - -import static com.google.protobuf.WireFormat.*; -import static java.lang.Math.max; - -/** Abstract base class for buffered encoders. */ -abstract class AbstractBufferedEncoder extends CodedOutputStream { - final byte[] buffer; - final int limit; - int position; - int totalBytesWritten; - - AbstractBufferedEncoder(int bufferSize) { - if (bufferSize < 0) { - throw new IllegalArgumentException("bufferSize must be >= 0"); - } - // As an optimization, we require that the buffer be able to store at least 2 - // varints so that we can buffer any integer write (tag + value). This reduces the - // number of range checks for a single write to 1 (i.e. if there is not enough space - // to buffer the tag+value, flush and then buffer it). - this.buffer = new byte[max(bufferSize, MAX_VARINT_SIZE * 2)]; - this.limit = buffer.length; - } - - @Override - public final int spaceLeft() { - throw new UnsupportedOperationException( - "spaceLeft() can only be called on CodedOutputStreams that are " - + "writing to a flat array or ByteBuffer."); - } - - @Override - public final int getTotalBytesWritten() { - return totalBytesWritten; - } - - /** - * This method does not perform bounds checking on the array. Checking array bounds is the - * responsibility of the caller. - */ - final void buffer(byte value) { - buffer[position++] = value; - totalBytesWritten++; - } - - /** - * This method does not perform bounds checking on the array. Checking array bounds is the - * responsibility of the caller. - */ - final void bufferTag(final int fieldNumber, final int wireType) { - bufferUInt32NoTag(WireFormat.makeTag(fieldNumber, wireType)); - } - - /** - * This method does not perform bounds checking on the array. Checking array bounds is the - * responsibility of the caller. - */ - final void bufferInt32NoTag(final int value) { - if (value >= 0) { - bufferUInt32NoTag(value); - } else { - // Must sign-extend. - bufferUInt64NoTag(value); - } - } - - /** - * This method does not perform bounds checking on the array. Checking array bounds is the - * responsibility of the caller. - */ - final void bufferUInt32NoTag(int value) { - if (HAS_UNSAFE_ARRAY_OPERATIONS) { - final long originalPos = position; - while (true) { - if ((value & ~0x7F) == 0) { - UnsafeUtil.putByte(buffer, position++, (byte) value); - break; - } else { - UnsafeUtil.putByte(buffer, position++, (byte) ((value & 0x7F) | 0x80)); - value >>>= 7; - } - } - int delta = (int) (position - originalPos); - totalBytesWritten += delta; - } else { - while (true) { - if ((value & ~0x7F) == 0) { - buffer[position++] = (byte) value; - totalBytesWritten++; - return; - } else { - buffer[position++] = (byte) ((value & 0x7F) | 0x80); - totalBytesWritten++; - value >>>= 7; - } - } - } - } - - /** - * This method does not perform bounds checking on the array. Checking array bounds is the - * responsibility of the caller. - */ - final void bufferUInt64NoTag(long value) { - if (HAS_UNSAFE_ARRAY_OPERATIONS) { - final long originalPos = position; - while (true) { - if ((value & ~0x7FL) == 0) { - UnsafeUtil.putByte(buffer, position++, (byte) value); - break; - } else { - UnsafeUtil.putByte(buffer, position++, (byte) (((int) value & 0x7F) | 0x80)); - value >>>= 7; - } - } - int delta = (int) (position - originalPos); - totalBytesWritten += delta; - } else { - while (true) { - if ((value & ~0x7FL) == 0) { - buffer[position++] = (byte) value; - totalBytesWritten++; - return; - } else { - buffer[position++] = (byte) (((int) value & 0x7F) | 0x80); - totalBytesWritten++; - value >>>= 7; - } - } - } - } - - /** - * This method does not perform bounds checking on the array. Checking array bounds is the - * responsibility of the caller. - */ - final void bufferFixed32NoTag(int value) { - buffer[position++] = (byte) (value & 0xFF); - buffer[position++] = (byte) ((value >> 8) & 0xFF); - buffer[position++] = (byte) ((value >> 16) & 0xFF); - buffer[position++] = (byte) ((value >> 24) & 0xFF); - totalBytesWritten += FIXED32_SIZE; - } - - /** - * This method does not perform bounds checking on the array. Checking array bounds is the - * responsibility of the caller. - */ - final void bufferFixed64NoTag(long value) { - buffer[position++] = (byte) (value & 0xFF); - buffer[position++] = (byte) ((value >> 8) & 0xFF); - buffer[position++] = (byte) ((value >> 16) & 0xFF); - buffer[position++] = (byte) ((value >> 24) & 0xFF); - buffer[position++] = (byte) ((int) (value >> 32) & 0xFF); - buffer[position++] = (byte) ((int) (value >> 40) & 0xFF); - buffer[position++] = (byte) ((int) (value >> 48) & 0xFF); - buffer[position++] = (byte) ((int) (value >> 56) & 0xFF); - totalBytesWritten += FIXED64_SIZE; - } -} \ No newline at end of file diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/ArrayEncoder.java b/protobuf-sdk/src/main/java/com/google/protobuf/ArrayEncoder.java deleted file mode 100644 index dfb943f..0000000 --- a/protobuf-sdk/src/main/java/com/google/protobuf/ArrayEncoder.java +++ /dev/null @@ -1,354 +0,0 @@ -package com.google.protobuf; - -import java.io.IOException; -import java.nio.ByteBuffer; - -import static com.google.protobuf.WireFormat.MAX_VARINT_SIZE; - -/** A {@link CodedOutputStream} that writes directly to a byte array. */ -class ArrayEncoder extends CodedOutputStream { - private final byte[] buffer; - private final int offset; - private final int limit; - private int position; - - ArrayEncoder(byte[] buffer, int offset, int length) { - super(); - if (buffer == null) { - throw new NullPointerException("buffer"); - } - if ((offset | length | (buffer.length - (offset + length))) < 0) { - throw new IllegalArgumentException( - String.format( - "Array range is invalid. Buffer.length=%d, offset=%d, length=%d", - buffer.length, offset, length)); - } - this.buffer = buffer; - this.offset = offset; - position = offset; - limit = offset + length; - } - - @Override - public final void writeTag(final int fieldNumber, final int wireType) throws IOException { - writeUInt32NoTag(WireFormat.makeTag(fieldNumber, wireType)); - } - - @Override - public final void writeInt32(final int fieldNumber, final int value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); - writeInt32NoTag(value); - } - - @Override - public final void writeUInt32(final int fieldNumber, final int value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); - writeUInt32NoTag(value); - } - - @Override - public final void writeFixed32(final int fieldNumber, final int value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED32); - writeFixed32NoTag(value); - } - - @Override - public final void writeUInt64(final int fieldNumber, final long value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); - writeUInt64NoTag(value); - } - - @Override - public final void writeFixed64(final int fieldNumber, final long value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED64); - writeFixed64NoTag(value); - } - - @Override - public final void writeBool(final int fieldNumber, final boolean value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); - write((byte) (value ? 1 : 0)); - } - - @Override - public final void writeString(final int fieldNumber, final String value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeStringNoTag(value); - } - - @Override - public final void writeBytes(final int fieldNumber, final ByteString value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeBytesNoTag(value); - } - - @Override - public final void writeByteArray(final int fieldNumber, final byte[] value) throws IOException { - writeByteArray(fieldNumber, value, 0, value.length); - } - - @Override - public final void writeByteArray( - final int fieldNumber, final byte[] value, final int offset, final int length) - throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeByteArrayNoTag(value, offset, length); - } - - @Override - public final void writeByteBuffer(final int fieldNumber, final ByteBuffer value) - throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeUInt32NoTag(value.capacity()); - writeRawBytes(value); - } - - @Override - public final void writeBytesNoTag(final ByteString value) throws IOException { - writeUInt32NoTag(value.size()); - value.writeTo(this); - } - - @Override - public final void writeByteArrayNoTag(final byte[] value, int offset, int length) - throws IOException { - writeUInt32NoTag(length); - write(value, offset, length); - } - - @Override - public final void writeRawBytes(final ByteBuffer value) throws IOException { - if (value.hasArray()) { - write(value.array(), value.arrayOffset(), value.capacity()); - } else { - ByteBuffer duplicated = value.duplicate(); - Java8Compatibility.clear(duplicated); - write(duplicated); - } - } - - @Override - public final void writeMessage(final int fieldNumber, final MessageLite value) - throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeMessageNoTag(value); - } - - @Override - final void writeMessage(final int fieldNumber, final MessageLite value, Schema schema) - throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeUInt32NoTag(((AbstractMessageLite) value).getSerializedSize(schema)); - schema.writeTo(value, wrapper); - } - - @Override - public final void writeMessageSetExtension(final int fieldNumber, final MessageLite value) - throws IOException { - writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_START_GROUP); - writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber); - writeMessage(WireFormat.MESSAGE_SET_MESSAGE, value); - writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP); - } - - @Override - public final void writeRawMessageSetExtension(final int fieldNumber, final ByteString value) - throws IOException { - writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_START_GROUP); - writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber); - writeBytes(WireFormat.MESSAGE_SET_MESSAGE, value); - writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP); - } - - @Override - public final void writeMessageNoTag(final MessageLite value) throws IOException { - writeUInt32NoTag(value.getSerializedSize()); - value.writeTo(this); - } - - @Override - final void writeMessageNoTag(final MessageLite value, Schema schema) throws IOException { - writeUInt32NoTag(((AbstractMessageLite) value).getSerializedSize(schema)); - schema.writeTo(value, wrapper); - } - - @Override - public final void write(byte value) throws IOException { - try { - buffer[position++] = value; - } catch (IndexOutOfBoundsException e) { - throw new OutOfSpaceException( - String.format("Pos: %d, limit: %d, len: %d", position, limit, 1), e); - } - } - - @Override - public final void writeInt32NoTag(int value) throws IOException { - if (value >= 0) { - writeUInt32NoTag(value); - } else { - // Must sign-extend. - writeUInt64NoTag(value); - } - } - - @Override - public final void writeUInt32NoTag(int value) throws IOException { - try { - while (true) { - if ((value & ~0x7F) == 0) { - buffer[position++] = (byte) value; - return; - } else { - buffer[position++] = (byte) ((value & 0x7F) | 0x80); - value >>>= 7; - } - } - } catch (IndexOutOfBoundsException e) { - throw new OutOfSpaceException( - String.format("Pos: %d, limit: %d, len: %d", position, limit, 1), e); - } - } - - @Override - public final void writeFixed32NoTag(int value) throws IOException { - try { - buffer[position++] = (byte) (value & 0xFF); - buffer[position++] = (byte) ((value >> 8) & 0xFF); - buffer[position++] = (byte) ((value >> 16) & 0xFF); - buffer[position++] = (byte) ((value >> 24) & 0xFF); - } catch (IndexOutOfBoundsException e) { - throw new OutOfSpaceException( - String.format("Pos: %d, limit: %d, len: %d", position, limit, 1), e); - } - } - - @Override - public final void writeUInt64NoTag(long value) throws IOException { - if (HAS_UNSAFE_ARRAY_OPERATIONS && spaceLeft() >= MAX_VARINT_SIZE) { - while (true) { - if ((value & ~0x7FL) == 0) { - UnsafeUtil.putByte(buffer, position++, (byte) value); - return; - } else { - UnsafeUtil.putByte(buffer, position++, (byte) (((int) value & 0x7F) | 0x80)); - value >>>= 7; - } - } - } else { - try { - while (true) { - if ((value & ~0x7FL) == 0) { - buffer[position++] = (byte) value; - return; - } else { - buffer[position++] = (byte) (((int) value & 0x7F) | 0x80); - value >>>= 7; - } - } - } catch (IndexOutOfBoundsException e) { - throw new OutOfSpaceException( - String.format("Pos: %d, limit: %d, len: %d", position, limit, 1), e); - } - } - } - - @Override - public final void writeFixed64NoTag(long value) throws IOException { - try { - buffer[position++] = (byte) ((int) (value) & 0xFF); - buffer[position++] = (byte) ((int) (value >> 8) & 0xFF); - buffer[position++] = (byte) ((int) (value >> 16) & 0xFF); - buffer[position++] = (byte) ((int) (value >> 24) & 0xFF); - buffer[position++] = (byte) ((int) (value >> 32) & 0xFF); - buffer[position++] = (byte) ((int) (value >> 40) & 0xFF); - buffer[position++] = (byte) ((int) (value >> 48) & 0xFF); - buffer[position++] = (byte) ((int) (value >> 56) & 0xFF); - } catch (IndexOutOfBoundsException e) { - throw new OutOfSpaceException( - String.format("Pos: %d, limit: %d, len: %d", position, limit, 1), e); - } - } - - @Override - public final void write(byte[] value, int offset, int length) throws IOException { - try { - System.arraycopy(value, offset, buffer, position, length); - position += length; - } catch (IndexOutOfBoundsException e) { - throw new OutOfSpaceException( - String.format("Pos: %d, limit: %d, len: %d", position, limit, length), e); - } - } - - @Override - public final void writeLazy(byte[] value, int offset, int length) throws IOException { - write(value, offset, length); - } - - @Override - public final void write(ByteBuffer value) throws IOException { - final int length = value.remaining(); - try { - value.get(buffer, position, length); - position += length; - } catch (IndexOutOfBoundsException e) { - throw new OutOfSpaceException( - String.format("Pos: %d, limit: %d, len: %d", position, limit, length), e); - } - } - - @Override - public final void writeLazy(ByteBuffer value) throws IOException { - write(value); - } - - @Override - public final void writeStringNoTag(String value) throws IOException { - final int oldPosition = position; - try { - // UTF-8 byte length of the string is at least its UTF-16 code unit length (value.length()), - // and at most 3 times of it. We take advantage of this in both branches below. - final int maxLength = value.length() * Utf8.MAX_BYTES_PER_CHAR; - final int maxLengthVarIntSize = computeUInt32SizeNoTag(maxLength); - final int minLengthVarIntSize = computeUInt32SizeNoTag(value.length()); - if (minLengthVarIntSize == maxLengthVarIntSize) { - position = oldPosition + minLengthVarIntSize; - int newPosition = Utf8.encode(value, buffer, position, spaceLeft()); - // Since this class is stateful and tracks the position, we rewind and store the state, - // prepend the length, then reset it back to the end of the string. - position = oldPosition; - int length = newPosition - oldPosition - minLengthVarIntSize; - writeUInt32NoTag(length); - position = newPosition; - } else { - int length = Utf8.encodedLength(value); - writeUInt32NoTag(length); - position = Utf8.encode(value, buffer, position, spaceLeft()); - } - } catch (Utf8.UnpairedSurrogateException e) { - // Roll back the change - we fall back to inefficient path. - position = oldPosition; - - // TODO: We should throw an IOException here instead. - inefficientWriteStringNoTag(value, e); - } catch (IndexOutOfBoundsException e) { - throw new OutOfSpaceException(e); - } - } - - @Override - public void flush() { - // Do nothing. - } - - @Override - public final int spaceLeft() { - return limit - position; - } - - @Override - public final int getTotalBytesWritten() { - return position - offset; - } -} \ No newline at end of file diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/ByteOutputEncoder.java b/protobuf-sdk/src/main/java/com/google/protobuf/ByteOutputEncoder.java deleted file mode 100644 index 060d095..0000000 --- a/protobuf-sdk/src/main/java/com/google/protobuf/ByteOutputEncoder.java +++ /dev/null @@ -1,322 +0,0 @@ -package com.google.protobuf; - -import java.io.IOException; -import java.nio.ByteBuffer; - -import static com.google.protobuf.WireFormat.*; -import static com.google.protobuf.WireFormat.FIXED64_SIZE; - -/** - * A {@link CodedOutputStream} that decorates a {@link ByteOutput}. It internal buffer only to - * support string encoding operations. All other writes are just passed through to the {@link - * ByteOutput}. - */ -final class ByteOutputEncoder extends AbstractBufferedEncoder { - private final ByteOutput out; - - ByteOutputEncoder(ByteOutput out, int bufferSize) { - super(bufferSize); - if (out == null) { - throw new NullPointerException("out"); - } - this.out = out; - } - - @Override - public void writeTag(final int fieldNumber, final int wireType) throws IOException { - writeUInt32NoTag(WireFormat.makeTag(fieldNumber, wireType)); - } - - @Override - public void writeInt32(final int fieldNumber, final int value) throws IOException { - flushIfNotAvailable(MAX_VARINT_SIZE * 2); - bufferTag(fieldNumber, WireFormat.WIRETYPE_VARINT); - bufferInt32NoTag(value); - } - - @Override - public void writeUInt32(final int fieldNumber, final int value) throws IOException { - flushIfNotAvailable(MAX_VARINT_SIZE * 2); - bufferTag(fieldNumber, WireFormat.WIRETYPE_VARINT); - bufferUInt32NoTag(value); - } - - @Override - public void writeFixed32(final int fieldNumber, final int value) throws IOException { - flushIfNotAvailable(MAX_VARINT_SIZE + FIXED32_SIZE); - bufferTag(fieldNumber, WireFormat.WIRETYPE_FIXED32); - bufferFixed32NoTag(value); - } - - @Override - public void writeUInt64(final int fieldNumber, final long value) throws IOException { - flushIfNotAvailable(MAX_VARINT_SIZE * 2); - bufferTag(fieldNumber, WireFormat.WIRETYPE_VARINT); - bufferUInt64NoTag(value); - } - - @Override - public void writeFixed64(final int fieldNumber, final long value) throws IOException { - flushIfNotAvailable(MAX_VARINT_SIZE + FIXED64_SIZE); - bufferTag(fieldNumber, WireFormat.WIRETYPE_FIXED64); - bufferFixed64NoTag(value); - } - - @Override - public void writeBool(final int fieldNumber, final boolean value) throws IOException { - flushIfNotAvailable(MAX_VARINT_SIZE + 1); - bufferTag(fieldNumber, WireFormat.WIRETYPE_VARINT); - buffer((byte) (value ? 1 : 0)); - } - - @Override - public void writeString(final int fieldNumber, final String value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeStringNoTag(value); - } - - @Override - public void writeBytes(final int fieldNumber, final ByteString value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeBytesNoTag(value); - } - - @Override - public void writeByteArray(final int fieldNumber, final byte[] value) throws IOException { - writeByteArray(fieldNumber, value, 0, value.length); - } - - @Override - public void writeByteArray( - final int fieldNumber, final byte[] value, final int offset, final int length) - throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeByteArrayNoTag(value, offset, length); - } - - @Override - public void writeByteBuffer(final int fieldNumber, final ByteBuffer value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeUInt32NoTag(value.capacity()); - writeRawBytes(value); - } - - @Override - public void writeBytesNoTag(final ByteString value) throws IOException { - writeUInt32NoTag(value.size()); - value.writeTo(this); - } - - @Override - public void writeByteArrayNoTag(final byte[] value, int offset, int length) throws IOException { - writeUInt32NoTag(length); - write(value, offset, length); - } - - @Override - public void writeRawBytes(final ByteBuffer value) throws IOException { - if (value.hasArray()) { - write(value.array(), value.arrayOffset(), value.capacity()); - } else { - ByteBuffer duplicated = value.duplicate(); - Java8Compatibility.clear(duplicated); - write(duplicated); - } - } - - @Override - public void writeMessage(final int fieldNumber, final MessageLite value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeMessageNoTag(value); - } - - @Override - void writeMessage(final int fieldNumber, final MessageLite value, Schema schema) - throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeMessageNoTag(value, schema); - } - - @Override - public void writeMessageSetExtension(final int fieldNumber, final MessageLite value) - throws IOException { - writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_START_GROUP); - writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber); - writeMessage(WireFormat.MESSAGE_SET_MESSAGE, value); - writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP); - } - - @Override - public void writeRawMessageSetExtension(final int fieldNumber, final ByteString value) - throws IOException { - writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_START_GROUP); - writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber); - writeBytes(WireFormat.MESSAGE_SET_MESSAGE, value); - writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP); - } - - @Override - public void writeMessageNoTag(final MessageLite value) throws IOException { - writeUInt32NoTag(value.getSerializedSize()); - value.writeTo(this); - } - - @Override - void writeMessageNoTag(final MessageLite value, Schema schema) throws IOException { - writeUInt32NoTag(((AbstractMessageLite) value).getSerializedSize(schema)); - schema.writeTo(value, wrapper); - } - - @Override - public void write(byte value) throws IOException { - if (position == limit) { - doFlush(); - } - - buffer(value); - } - - @Override - public void writeInt32NoTag(int value) throws IOException { - if (value >= 0) { - writeUInt32NoTag(value); - } else { - // Must sign-extend. - writeUInt64NoTag(value); - } - } - - @Override - public void writeUInt32NoTag(int value) throws IOException { - flushIfNotAvailable(MAX_VARINT32_SIZE); - bufferUInt32NoTag(value); - } - - @Override - public void writeFixed32NoTag(final int value) throws IOException { - flushIfNotAvailable(FIXED32_SIZE); - bufferFixed32NoTag(value); - } - - @Override - public void writeUInt64NoTag(long value) throws IOException { - flushIfNotAvailable(MAX_VARINT_SIZE); - bufferUInt64NoTag(value); - } - - @Override - public void writeFixed64NoTag(final long value) throws IOException { - flushIfNotAvailable(FIXED64_SIZE); - bufferFixed64NoTag(value); - } - - @Override - public void writeStringNoTag(String value) throws IOException { - // UTF-8 byte length of the string is at least its UTF-16 code unit length (value.length()), - // and at most 3 times of it. We take advantage of this in both branches below. - final int maxLength = value.length() * Utf8.MAX_BYTES_PER_CHAR; - final int maxLengthVarIntSize = computeUInt32SizeNoTag(maxLength); - - // If we are streaming and the potential length is too big to fit in our buffer, we take the - // slower path. - if (maxLengthVarIntSize + maxLength > limit) { - // Allocate a byte[] that we know can fit the string and encode into it. String.getBytes() - // does the same internally and then does *another copy* to return a byte[] of exactly the - // right size. We can skip that copy and just writeRawBytes up to the actualLength of the - // UTF-8 encoded bytes. - final byte[] encodedBytes = new byte[maxLength]; - int actualLength = Utf8.encode(value, encodedBytes, 0, maxLength); - writeUInt32NoTag(actualLength); - writeLazy(encodedBytes, 0, actualLength); - return; - } - - // Fast path: we have enough space available in our buffer for the string... - if (maxLengthVarIntSize + maxLength > limit - position) { - // Flush to free up space. - doFlush(); - } - - final int oldPosition = position; - try { - // Optimize for the case where we know this length results in a constant varint length as - // this saves a pass for measuring the length of the string. - final int minLengthVarIntSize = computeUInt32SizeNoTag(value.length()); - - if (minLengthVarIntSize == maxLengthVarIntSize) { - position = oldPosition + minLengthVarIntSize; - int newPosition = Utf8.encode(value, buffer, position, limit - position); - // Since this class is stateful and tracks the position, we rewind and store the state, - // prepend the length, then reset it back to the end of the string. - position = oldPosition; - int length = newPosition - oldPosition - minLengthVarIntSize; - bufferUInt32NoTag(length); - position = newPosition; - totalBytesWritten += length; - } else { - int length = Utf8.encodedLength(value); - bufferUInt32NoTag(length); - position = Utf8.encode(value, buffer, position, length); - totalBytesWritten += length; - } - } catch (Utf8.UnpairedSurrogateException e) { - // Roll back the change and convert to an IOException. - totalBytesWritten -= position - oldPosition; - position = oldPosition; - - // TODO: We should throw an IOException here instead. - inefficientWriteStringNoTag(value, e); - } catch (IndexOutOfBoundsException e) { - throw new OutOfSpaceException(e); - } - } - - @Override - public void flush() throws IOException { - if (position > 0) { - // Flush the buffer. - doFlush(); - } - } - - @Override - public void write(byte[] value, int offset, int length) throws IOException { - flush(); - out.write(value, offset, length); - totalBytesWritten += length; - } - - @Override - public void writeLazy(byte[] value, int offset, int length) throws IOException { - flush(); - out.writeLazy(value, offset, length); - totalBytesWritten += length; - } - - @Override - public void write(ByteBuffer value) throws IOException { - flush(); - int length = value.remaining(); - out.write(value); - totalBytesWritten += length; - } - - @Override - public void writeLazy(ByteBuffer value) throws IOException { - flush(); - int length = value.remaining(); - out.writeLazy(value); - totalBytesWritten += length; - } - - private void flushIfNotAvailable(int requiredSize) throws IOException { - if (limit - position < requiredSize) { - doFlush(); - } - } - - private void doFlush() throws IOException { - out.write(buffer, 0, position); - position = 0; - } -} \ No newline at end of file diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/HeapNioEncoder.java b/protobuf-sdk/src/main/java/com/google/protobuf/HeapNioEncoder.java deleted file mode 100644 index 0c0bdd0..0000000 --- a/protobuf-sdk/src/main/java/com/google/protobuf/HeapNioEncoder.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.google.protobuf; - -import java.nio.ByteBuffer; - -/** - * A {@link CodedOutputStream} that writes directly to a heap {@link ByteBuffer}. Writes are done - * directly to the underlying array. The buffer position is only updated after a flush. - */ -final class HeapNioEncoder extends ArrayEncoder { - private final ByteBuffer byteBuffer; - private int initialPosition; - - HeapNioEncoder(ByteBuffer byteBuffer) { - super( - byteBuffer.array(), - byteBuffer.arrayOffset() + byteBuffer.position(), - byteBuffer.remaining()); - this.byteBuffer = byteBuffer; - this.initialPosition = byteBuffer.position(); - } - - @Override - public void flush() { - // Update the position on the buffer. - Java8Compatibility.position(byteBuffer, initialPosition + getTotalBytesWritten()); - } -} \ No newline at end of file diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/OutputStreamEncoder.java b/protobuf-sdk/src/main/java/com/google/protobuf/OutputStreamEncoder.java deleted file mode 100644 index 04e6c04..0000000 --- a/protobuf-sdk/src/main/java/com/google/protobuf/OutputStreamEncoder.java +++ /dev/null @@ -1,371 +0,0 @@ -package com.google.protobuf; - -import java.io.IOException; -import java.io.OutputStream; -import java.nio.ByteBuffer; - -import static com.google.protobuf.WireFormat.*; -import static com.google.protobuf.WireFormat.FIXED64_SIZE; - -/** - * An {@link CodedOutputStream} that decorates an {@link OutputStream}. It performs internal - * buffering to optimize writes to the {@link OutputStream}. - */ -final class OutputStreamEncoder extends AbstractBufferedEncoder { - private final OutputStream out; - - OutputStreamEncoder(OutputStream out, int bufferSize) { - super(bufferSize); - if (out == null) { - throw new NullPointerException("out"); - } - this.out = out; - } - - @Override - public void writeTag(final int fieldNumber, final int wireType) throws IOException { - writeUInt32NoTag(WireFormat.makeTag(fieldNumber, wireType)); - } - - @Override - public void writeInt32(final int fieldNumber, final int value) throws IOException { - flushIfNotAvailable(MAX_VARINT_SIZE * 2); - bufferTag(fieldNumber, WireFormat.WIRETYPE_VARINT); - bufferInt32NoTag(value); - } - - @Override - public void writeUInt32(final int fieldNumber, final int value) throws IOException { - flushIfNotAvailable(MAX_VARINT_SIZE * 2); - bufferTag(fieldNumber, WireFormat.WIRETYPE_VARINT); - bufferUInt32NoTag(value); - } - - @Override - public void writeFixed32(final int fieldNumber, final int value) throws IOException { - flushIfNotAvailable(MAX_VARINT_SIZE + FIXED32_SIZE); - bufferTag(fieldNumber, WireFormat.WIRETYPE_FIXED32); - bufferFixed32NoTag(value); - } - - @Override - public void writeUInt64(final int fieldNumber, final long value) throws IOException { - flushIfNotAvailable(MAX_VARINT_SIZE * 2); - bufferTag(fieldNumber, WireFormat.WIRETYPE_VARINT); - bufferUInt64NoTag(value); - } - - @Override - public void writeFixed64(final int fieldNumber, final long value) throws IOException { - flushIfNotAvailable(MAX_VARINT_SIZE + FIXED64_SIZE); - bufferTag(fieldNumber, WireFormat.WIRETYPE_FIXED64); - bufferFixed64NoTag(value); - } - - @Override - public void writeBool(final int fieldNumber, final boolean value) throws IOException { - flushIfNotAvailable(MAX_VARINT_SIZE + 1); - bufferTag(fieldNumber, WireFormat.WIRETYPE_VARINT); - buffer((byte) (value ? 1 : 0)); - } - - @Override - public void writeString(final int fieldNumber, final String value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeStringNoTag(value); - } - - @Override - public void writeBytes(final int fieldNumber, final ByteString value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeBytesNoTag(value); - } - - @Override - public void writeByteArray(final int fieldNumber, final byte[] value) throws IOException { - writeByteArray(fieldNumber, value, 0, value.length); - } - - @Override - public void writeByteArray( - final int fieldNumber, final byte[] value, final int offset, final int length) - throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeByteArrayNoTag(value, offset, length); - } - - @Override - public void writeByteBuffer(final int fieldNumber, final ByteBuffer value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeUInt32NoTag(value.capacity()); - writeRawBytes(value); - } - - @Override - public void writeBytesNoTag(final ByteString value) throws IOException { - writeUInt32NoTag(value.size()); - value.writeTo(this); - } - - @Override - public void writeByteArrayNoTag(final byte[] value, int offset, int length) throws IOException { - writeUInt32NoTag(length); - write(value, offset, length); - } - - @Override - public void writeRawBytes(final ByteBuffer value) throws IOException { - if (value.hasArray()) { - write(value.array(), value.arrayOffset(), value.capacity()); - } else { - ByteBuffer duplicated = value.duplicate(); - Java8Compatibility.clear(duplicated); - write(duplicated); - } - } - - @Override - public void writeMessage(final int fieldNumber, final MessageLite value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeMessageNoTag(value); - } - - @Override - void writeMessage(final int fieldNumber, final MessageLite value, Schema schema) - throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeMessageNoTag(value, schema); - } - - @Override - public void writeMessageSetExtension(final int fieldNumber, final MessageLite value) - throws IOException { - writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_START_GROUP); - writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber); - writeMessage(WireFormat.MESSAGE_SET_MESSAGE, value); - writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP); - } - - @Override - public void writeRawMessageSetExtension(final int fieldNumber, final ByteString value) - throws IOException { - writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_START_GROUP); - writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber); - writeBytes(WireFormat.MESSAGE_SET_MESSAGE, value); - writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP); - } - - @Override - public void writeMessageNoTag(final MessageLite value) throws IOException { - writeUInt32NoTag(value.getSerializedSize()); - value.writeTo(this); - } - - @Override - void writeMessageNoTag(final MessageLite value, Schema schema) throws IOException { - writeUInt32NoTag(((AbstractMessageLite) value).getSerializedSize(schema)); - schema.writeTo(value, wrapper); - } - - @Override - public void write(byte value) throws IOException { - if (position == limit) { - doFlush(); - } - - buffer(value); - } - - @Override - public void writeInt32NoTag(int value) throws IOException { - if (value >= 0) { - writeUInt32NoTag(value); - } else { - // Must sign-extend. - writeUInt64NoTag(value); - } - } - - @Override - public void writeUInt32NoTag(int value) throws IOException { - flushIfNotAvailable(MAX_VARINT32_SIZE); - bufferUInt32NoTag(value); - } - - @Override - public void writeFixed32NoTag(final int value) throws IOException { - flushIfNotAvailable(FIXED32_SIZE); - bufferFixed32NoTag(value); - } - - @Override - public void writeUInt64NoTag(long value) throws IOException { - flushIfNotAvailable(MAX_VARINT_SIZE); - bufferUInt64NoTag(value); - } - - @Override - public void writeFixed64NoTag(final long value) throws IOException { - flushIfNotAvailable(FIXED64_SIZE); - bufferFixed64NoTag(value); - } - - @Override - public void writeStringNoTag(String value) throws IOException { - try { - // UTF-8 byte length of the string is at least its UTF-16 code unit length (value.length()), - // and at most 3 times of it. We take advantage of this in both branches below. - final int maxLength = value.length() * Utf8.MAX_BYTES_PER_CHAR; - final int maxLengthVarIntSize = computeUInt32SizeNoTag(maxLength); - - // If we are streaming and the potential length is too big to fit in our buffer, we take the - // slower path. - if (maxLengthVarIntSize + maxLength > limit) { - // Allocate a byte[] that we know can fit the string and encode into it. String.getBytes() - // does the same internally and then does *another copy* to return a byte[] of exactly the - // right size. We can skip that copy and just writeRawBytes up to the actualLength of the - // UTF-8 encoded bytes. - final byte[] encodedBytes = new byte[maxLength]; - int actualLength = Utf8.encode(value, encodedBytes, 0, maxLength); - writeUInt32NoTag(actualLength); - writeLazy(encodedBytes, 0, actualLength); - return; - } - - // Fast path: we have enough space available in our buffer for the string... - if (maxLengthVarIntSize + maxLength > limit - position) { - // Flush to free up space. - doFlush(); - } - - // Optimize for the case where we know this length results in a constant varint length as - // this saves a pass for measuring the length of the string. - final int minLengthVarIntSize = computeUInt32SizeNoTag(value.length()); - int oldPosition = position; - final int length; - try { - if (minLengthVarIntSize == maxLengthVarIntSize) { - position = oldPosition + minLengthVarIntSize; - int newPosition = Utf8.encode(value, buffer, position, limit - position); - // Since this class is stateful and tracks the position, we rewind and store the - // state, prepend the length, then reset it back to the end of the string. - position = oldPosition; - length = newPosition - oldPosition - minLengthVarIntSize; - bufferUInt32NoTag(length); - position = newPosition; - } else { - length = Utf8.encodedLength(value); - bufferUInt32NoTag(length); - position = Utf8.encode(value, buffer, position, length); - } - totalBytesWritten += length; - } catch (Utf8.UnpairedSurrogateException e) { - // Be extra careful and restore the original position for retrying the write with the - // less efficient path. - totalBytesWritten -= position - oldPosition; - position = oldPosition; - throw e; - } catch (ArrayIndexOutOfBoundsException e) { - throw new OutOfSpaceException(e); - } - } catch (Utf8.UnpairedSurrogateException e) { - inefficientWriteStringNoTag(value, e); - } - } - - @Override - public void flush() throws IOException { - if (position > 0) { - // Flush the buffer. - doFlush(); - } - } - - @Override - public void write(byte[] value, int offset, int length) throws IOException { - if (limit - position >= length) { - // We have room in the current buffer. - System.arraycopy(value, offset, buffer, position, length); - position += length; - totalBytesWritten += length; - } else { - // Write extends past current buffer. Fill the rest of this buffer and - // flush. - final int bytesWritten = limit - position; - System.arraycopy(value, offset, buffer, position, bytesWritten); - offset += bytesWritten; - length -= bytesWritten; - position = limit; - totalBytesWritten += bytesWritten; - doFlush(); - - // Now deal with the rest. - // Since we have an output stream, this is our buffer - // and buffer offset == 0 - if (length <= limit) { - // Fits in new buffer. - System.arraycopy(value, offset, buffer, 0, length); - position = length; - } else { - // Write is very big. Let's do it all at once. - out.write(value, offset, length); - } - totalBytesWritten += length; - } - } - - @Override - public void writeLazy(byte[] value, int offset, int length) throws IOException { - write(value, offset, length); - } - - @Override - public void write(ByteBuffer value) throws IOException { - int length = value.remaining(); - if (limit - position >= length) { - // We have room in the current buffer. - value.get(buffer, position, length); - position += length; - totalBytesWritten += length; - } else { - // Write extends past current buffer. Fill the rest of this buffer and - // flush. - final int bytesWritten = limit - position; - value.get(buffer, position, bytesWritten); - length -= bytesWritten; - position = limit; - totalBytesWritten += bytesWritten; - doFlush(); - - // Now deal with the rest. - // Since we have an output stream, this is our buffer - // and buffer offset == 0 - while (length > limit) { - // Copy data into the buffer before writing it to OutputStream. - value.get(buffer, 0, limit); - out.write(buffer, 0, limit); - length -= limit; - totalBytesWritten += limit; - } - value.get(buffer, 0, length); - position = length; - totalBytesWritten += length; - } - } - - @Override - public void writeLazy(ByteBuffer value) throws IOException { - write(value); - } - - private void flushIfNotAvailable(int requiredSize) throws IOException { - if (limit - position < requiredSize) { - doFlush(); - } - } - - private void doFlush() throws IOException { - out.write(buffer, 0, position); - position = 0; - } -} \ No newline at end of file diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/SafeDirectNioEncoder.java b/protobuf-sdk/src/main/java/com/google/protobuf/SafeDirectNioEncoder.java deleted file mode 100644 index 3b879d0..0000000 --- a/protobuf-sdk/src/main/java/com/google/protobuf/SafeDirectNioEncoder.java +++ /dev/null @@ -1,328 +0,0 @@ -package com.google.protobuf; - -import java.io.IOException; -import java.nio.BufferOverflowException; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; - -/** - * A {@link CodedOutputStream} that writes directly to a direct {@link ByteBuffer}, using only - * safe operations.. - */ -final class SafeDirectNioEncoder extends CodedOutputStream { - private final ByteBuffer originalBuffer; - private final ByteBuffer buffer; - private final int initialPosition; - - SafeDirectNioEncoder(ByteBuffer buffer) { - this.originalBuffer = buffer; - this.buffer = buffer.duplicate().order(ByteOrder.LITTLE_ENDIAN); - initialPosition = buffer.position(); - } - - @Override - public void writeTag(final int fieldNumber, final int wireType) throws IOException { - writeUInt32NoTag(WireFormat.makeTag(fieldNumber, wireType)); - } - - @Override - public void writeInt32(final int fieldNumber, final int value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); - writeInt32NoTag(value); - } - - @Override - public void writeUInt32(final int fieldNumber, final int value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); - writeUInt32NoTag(value); - } - - @Override - public void writeFixed32(final int fieldNumber, final int value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED32); - writeFixed32NoTag(value); - } - - @Override - public void writeUInt64(final int fieldNumber, final long value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); - writeUInt64NoTag(value); - } - - @Override - public void writeFixed64(final int fieldNumber, final long value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED64); - writeFixed64NoTag(value); - } - - @Override - public void writeBool(final int fieldNumber, final boolean value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); - write((byte) (value ? 1 : 0)); - } - - @Override - public void writeString(final int fieldNumber, final String value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeStringNoTag(value); - } - - @Override - public void writeBytes(final int fieldNumber, final ByteString value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeBytesNoTag(value); - } - - @Override - public void writeByteArray(final int fieldNumber, final byte[] value) throws IOException { - writeByteArray(fieldNumber, value, 0, value.length); - } - - @Override - public void writeByteArray( - final int fieldNumber, final byte[] value, final int offset, final int length) - throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeByteArrayNoTag(value, offset, length); - } - - @Override - public void writeByteBuffer(final int fieldNumber, final ByteBuffer value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeUInt32NoTag(value.capacity()); - writeRawBytes(value); - } - - @Override - public void writeMessage(final int fieldNumber, final MessageLite value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeMessageNoTag(value); - } - - @Override - void writeMessage(final int fieldNumber, final MessageLite value, Schema schema) - throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeMessageNoTag(value, schema); - } - - @Override - public void writeMessageSetExtension(final int fieldNumber, final MessageLite value) - throws IOException { - writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_START_GROUP); - writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber); - writeMessage(WireFormat.MESSAGE_SET_MESSAGE, value); - writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP); - } - - @Override - public void writeRawMessageSetExtension(final int fieldNumber, final ByteString value) - throws IOException { - writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_START_GROUP); - writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber); - writeBytes(WireFormat.MESSAGE_SET_MESSAGE, value); - writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP); - } - - @Override - public void writeMessageNoTag(final MessageLite value) throws IOException { - writeUInt32NoTag(value.getSerializedSize()); - value.writeTo(this); - } - - @Override - void writeMessageNoTag(final MessageLite value, Schema schema) throws IOException { - writeUInt32NoTag(((AbstractMessageLite) value).getSerializedSize(schema)); - schema.writeTo(value, wrapper); - } - - @Override - public void write(byte value) throws IOException { - try { - buffer.put(value); - } catch (BufferOverflowException e) { - throw new OutOfSpaceException(e); - } - } - - @Override - public void writeBytesNoTag(final ByteString value) throws IOException { - writeUInt32NoTag(value.size()); - value.writeTo(this); - } - - @Override - public void writeByteArrayNoTag(final byte[] value, int offset, int length) throws IOException { - writeUInt32NoTag(length); - write(value, offset, length); - } - - @Override - public void writeRawBytes(final ByteBuffer value) throws IOException { - if (value.hasArray()) { - write(value.array(), value.arrayOffset(), value.capacity()); - } else { - ByteBuffer duplicated = value.duplicate(); - Java8Compatibility.clear(duplicated); - write(duplicated); - } - } - - @Override - public void writeInt32NoTag(int value) throws IOException { - if (value >= 0) { - writeUInt32NoTag(value); - } else { - // Must sign-extend. - writeUInt64NoTag(value); - } - } - - @Override - public void writeUInt32NoTag(int value) throws IOException { - try { - while (true) { - if ((value & ~0x7F) == 0) { - buffer.put((byte) value); - return; - } else { - buffer.put((byte) ((value & 0x7F) | 0x80)); - value >>>= 7; - } - } - } catch (BufferOverflowException e) { - throw new OutOfSpaceException(e); - } - } - - @Override - public void writeFixed32NoTag(int value) throws IOException { - try { - buffer.putInt(value); - } catch (BufferOverflowException e) { - throw new OutOfSpaceException(e); - } - } - - @Override - public void writeUInt64NoTag(long value) throws IOException { - try { - while (true) { - if ((value & ~0x7FL) == 0) { - buffer.put((byte) value); - return; - } else { - buffer.put((byte) (((int) value & 0x7F) | 0x80)); - value >>>= 7; - } - } - } catch (BufferOverflowException e) { - throw new OutOfSpaceException(e); - } - } - - @Override - public void writeFixed64NoTag(long value) throws IOException { - try { - buffer.putLong(value); - } catch (BufferOverflowException e) { - throw new OutOfSpaceException(e); - } - } - - @Override - public void write(byte[] value, int offset, int length) throws IOException { - try { - buffer.put(value, offset, length); - } catch (IndexOutOfBoundsException e) { - throw new OutOfSpaceException(e); - } catch (BufferOverflowException e) { - throw new OutOfSpaceException(e); - } - } - - @Override - public void writeLazy(byte[] value, int offset, int length) throws IOException { - write(value, offset, length); - } - - @Override - public void write(ByteBuffer value) throws IOException { - try { - buffer.put(value); - } catch (BufferOverflowException e) { - throw new OutOfSpaceException(e); - } - } - - @Override - public void writeLazy(ByteBuffer value) throws IOException { - write(value); - } - - @Override - public void writeStringNoTag(String value) throws IOException { - final int startPos = buffer.position(); - try { - // UTF-8 byte length of the string is at least its UTF-16 code unit length (value.length()), - // and at most 3 times of it. We take advantage of this in both branches below. - final int maxEncodedSize = value.length() * Utf8.MAX_BYTES_PER_CHAR; - final int maxLengthVarIntSize = computeUInt32SizeNoTag(maxEncodedSize); - final int minLengthVarIntSize = computeUInt32SizeNoTag(value.length()); - if (minLengthVarIntSize == maxLengthVarIntSize) { - // Save the current position and increment past the length field. We'll come back - // and write the length field after the encoding is complete. - final int startOfBytes = buffer.position() + minLengthVarIntSize; - Java8Compatibility.position(buffer, startOfBytes); - - // Encode the string. - encode(value); - - // Now go back to the beginning and write the length. - int endOfBytes = buffer.position(); - Java8Compatibility.position(buffer, startPos); - writeUInt32NoTag(endOfBytes - startOfBytes); - - // Reposition the buffer past the written data. - Java8Compatibility.position(buffer, endOfBytes); - } else { - final int length = Utf8.encodedLength(value); - writeUInt32NoTag(length); - encode(value); - } - } catch (Utf8.UnpairedSurrogateException e) { - // Roll back the change and convert to an IOException. - Java8Compatibility.position(buffer, startPos); - - // TODO: We should throw an IOException here instead. - inefficientWriteStringNoTag(value, e); - } catch (IllegalArgumentException e) { - // Thrown by buffer.position() if out of range. - throw new OutOfSpaceException(e); - } - } - - @Override - public void flush() { - // Update the position of the original buffer. - Java8Compatibility.position(originalBuffer, buffer.position()); - } - - @Override - public int spaceLeft() { - return buffer.remaining(); - } - - @Override - public int getTotalBytesWritten() { - return buffer.position() - initialPosition; - } - - private void encode(String value) throws IOException { - try { - Utf8.encodeUtf8(value, buffer); - } catch (IndexOutOfBoundsException e) { - throw new OutOfSpaceException(e); - } - } -} \ No newline at end of file diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/UnsafeDirectNioEncoder.java b/protobuf-sdk/src/main/java/com/google/protobuf/UnsafeDirectNioEncoder.java deleted file mode 100644 index 07ef277..0000000 --- a/protobuf-sdk/src/main/java/com/google/protobuf/UnsafeDirectNioEncoder.java +++ /dev/null @@ -1,369 +0,0 @@ -package com.google.protobuf; - -import java.io.IOException; -import java.nio.BufferOverflowException; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; - -import static com.google.protobuf.WireFormat.*; - -/** - * A {@link CodedOutputStream} that writes directly to a direct {@link ByteBuffer} using {@code - * sun.misc.Unsafe}. - */ -final class UnsafeDirectNioEncoder extends CodedOutputStream { - private final ByteBuffer originalBuffer; - private final ByteBuffer buffer; - private final long address; - private final long initialPosition; - private final long limit; - private final long oneVarintLimit; - private long position; - - UnsafeDirectNioEncoder(ByteBuffer buffer) { - this.originalBuffer = buffer; - this.buffer = buffer.duplicate().order(ByteOrder.LITTLE_ENDIAN); - address = UnsafeUtil.addressOffset(buffer); - initialPosition = address + buffer.position(); - limit = address + buffer.limit(); - oneVarintLimit = limit - MAX_VARINT_SIZE; - position = initialPosition; - } - - static boolean isSupported() { - return UnsafeUtil.hasUnsafeByteBufferOperations(); - } - - @Override - public void writeTag(int fieldNumber, int wireType) throws IOException { - writeUInt32NoTag(WireFormat.makeTag(fieldNumber, wireType)); - } - - @Override - public void writeInt32(int fieldNumber, int value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); - writeInt32NoTag(value); - } - - @Override - public void writeUInt32(int fieldNumber, int value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); - writeUInt32NoTag(value); - } - - @Override - public void writeFixed32(int fieldNumber, int value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED32); - writeFixed32NoTag(value); - } - - @Override - public void writeUInt64(int fieldNumber, long value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); - writeUInt64NoTag(value); - } - - @Override - public void writeFixed64(int fieldNumber, long value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED64); - writeFixed64NoTag(value); - } - - @Override - public void writeBool(int fieldNumber, boolean value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); - write((byte) (value ? 1 : 0)); - } - - @Override - public void writeString(int fieldNumber, String value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeStringNoTag(value); - } - - @Override - public void writeBytes(int fieldNumber, ByteString value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeBytesNoTag(value); - } - - @Override - public void writeByteArray(int fieldNumber, byte[] value) throws IOException { - writeByteArray(fieldNumber, value, 0, value.length); - } - - @Override - public void writeByteArray(int fieldNumber, byte[] value, int offset, int length) - throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeByteArrayNoTag(value, offset, length); - } - - @Override - public void writeByteBuffer(int fieldNumber, ByteBuffer value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeUInt32NoTag(value.capacity()); - writeRawBytes(value); - } - - @Override - public void writeMessage(int fieldNumber, MessageLite value) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeMessageNoTag(value); - } - - @Override - void writeMessage(int fieldNumber, MessageLite value, Schema schema) throws IOException { - writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); - writeMessageNoTag(value, schema); - } - - @Override - public void writeMessageSetExtension(int fieldNumber, MessageLite value) throws IOException { - writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_START_GROUP); - writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber); - writeMessage(WireFormat.MESSAGE_SET_MESSAGE, value); - writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP); - } - - @Override - public void writeRawMessageSetExtension(int fieldNumber, ByteString value) throws IOException { - writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_START_GROUP); - writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber); - writeBytes(WireFormat.MESSAGE_SET_MESSAGE, value); - writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP); - } - - @Override - public void writeMessageNoTag(MessageLite value) throws IOException { - writeUInt32NoTag(value.getSerializedSize()); - value.writeTo(this); - } - - @Override - void writeMessageNoTag(MessageLite value, Schema schema) throws IOException { - writeUInt32NoTag(((AbstractMessageLite) value).getSerializedSize(schema)); - schema.writeTo(value, wrapper); - } - - @Override - public void write(byte value) throws IOException { - if (position >= limit) { - throw new OutOfSpaceException( - String.format("Pos: %d, limit: %d, len: %d", position, limit, 1)); - } - UnsafeUtil.putByte(position++, value); - } - - @Override - public void writeBytesNoTag(ByteString value) throws IOException { - writeUInt32NoTag(value.size()); - value.writeTo(this); - } - - @Override - public void writeByteArrayNoTag(byte[] value, int offset, int length) throws IOException { - writeUInt32NoTag(length); - write(value, offset, length); - } - - @Override - public void writeRawBytes(ByteBuffer value) throws IOException { - if (value.hasArray()) { - write(value.array(), value.arrayOffset(), value.capacity()); - } else { - ByteBuffer duplicated = value.duplicate(); - Java8Compatibility.clear(duplicated); - write(duplicated); - } - } - - @Override - public void writeInt32NoTag(int value) throws IOException { - if (value >= 0) { - writeUInt32NoTag(value); - } else { - // Must sign-extend. - writeUInt64NoTag(value); - } - } - - @Override - public void writeUInt32NoTag(int value) throws IOException { - if (position <= oneVarintLimit) { - // Optimization to avoid bounds checks on each iteration. - while (true) { - if ((value & ~0x7F) == 0) { - UnsafeUtil.putByte(position++, (byte) value); - return; - } else { - UnsafeUtil.putByte(position++, (byte) ((value & 0x7F) | 0x80)); - value >>>= 7; - } - } - } else { - while (position < limit) { - if ((value & ~0x7F) == 0) { - UnsafeUtil.putByte(position++, (byte) value); - return; - } else { - UnsafeUtil.putByte(position++, (byte) ((value & 0x7F) | 0x80)); - value >>>= 7; - } - } - throw new OutOfSpaceException( - String.format("Pos: %d, limit: %d, len: %d", position, limit, 1)); - } - } - - @Override - public void writeFixed32NoTag(int value) throws IOException { - buffer.putInt(bufferPos(position), value); - position += FIXED32_SIZE; - } - - @Override - public void writeUInt64NoTag(long value) throws IOException { - if (position <= oneVarintLimit) { - // Optimization to avoid bounds checks on each iteration. - while (true) { - if ((value & ~0x7FL) == 0) { - UnsafeUtil.putByte(position++, (byte) value); - return; - } else { - UnsafeUtil.putByte(position++, (byte) (((int) value & 0x7F) | 0x80)); - value >>>= 7; - } - } - } else { - while (position < limit) { - if ((value & ~0x7FL) == 0) { - UnsafeUtil.putByte(position++, (byte) value); - return; - } else { - UnsafeUtil.putByte(position++, (byte) (((int) value & 0x7F) | 0x80)); - value >>>= 7; - } - } - throw new OutOfSpaceException( - String.format("Pos: %d, limit: %d, len: %d", position, limit, 1)); - } - } - - @Override - public void writeFixed64NoTag(long value) throws IOException { - buffer.putLong(bufferPos(position), value); - position += FIXED64_SIZE; - } - - @Override - public void write(byte[] value, int offset, int length) throws IOException { - if (value == null - || offset < 0 - || length < 0 - || (value.length - length) < offset - || (limit - length) < position) { - if (value == null) { - throw new NullPointerException("value"); - } - throw new OutOfSpaceException( - String.format("Pos: %d, limit: %d, len: %d", position, limit, length)); - } - - UnsafeUtil.copyMemory(value, offset, position, length); - position += length; - } - - @Override - public void writeLazy(byte[] value, int offset, int length) throws IOException { - write(value, offset, length); - } - - @Override - public void write(ByteBuffer value) throws IOException { - try { - int length = value.remaining(); - repositionBuffer(position); - buffer.put(value); - position += length; - } catch (BufferOverflowException e) { - throw new OutOfSpaceException(e); - } - } - - @Override - public void writeLazy(ByteBuffer value) throws IOException { - write(value); - } - - @Override - public void writeStringNoTag(String value) throws IOException { - long prevPos = position; - try { - // UTF-8 byte length of the string is at least its UTF-16 code unit length (value.length()), - // and at most 3 times of it. We take advantage of this in both branches below. - int maxEncodedSize = value.length() * Utf8.MAX_BYTES_PER_CHAR; - int maxLengthVarIntSize = computeUInt32SizeNoTag(maxEncodedSize); - int minLengthVarIntSize = computeUInt32SizeNoTag(value.length()); - if (minLengthVarIntSize == maxLengthVarIntSize) { - // Save the current position and increment past the length field. We'll come back - // and write the length field after the encoding is complete. - int stringStart = bufferPos(position) + minLengthVarIntSize; - Java8Compatibility.position(buffer, stringStart); - - // Encode the string. - Utf8.encodeUtf8(value, buffer); - - // Write the length and advance the position. - int length = buffer.position() - stringStart; - writeUInt32NoTag(length); - position += length; - } else { - // Calculate and write the encoded length. - int length = Utf8.encodedLength(value); - writeUInt32NoTag(length); - - // Write the string and advance the position. - repositionBuffer(position); - Utf8.encodeUtf8(value, buffer); - position += length; - } - } catch (Utf8.UnpairedSurrogateException e) { - // Roll back the change and convert to an IOException. - position = prevPos; - repositionBuffer(position); - - // TODO: We should throw an IOException here instead. - inefficientWriteStringNoTag(value, e); - } catch (IllegalArgumentException e) { - // Thrown by buffer.position() if out of range. - throw new OutOfSpaceException(e); - } catch (IndexOutOfBoundsException e) { - throw new OutOfSpaceException(e); - } - } - - @Override - public void flush() { - // Update the position of the original buffer. - Java8Compatibility.position(originalBuffer, bufferPos(position)); - } - - @Override - public int spaceLeft() { - return (int) (limit - position); - } - - @Override - public int getTotalBytesWritten() { - return (int) (position - initialPosition); - } - - private void repositionBuffer(long pos) { - Java8Compatibility.position(buffer, bufferPos(pos)); - } - - private int bufferPos(long pos) { - return (int) (pos - address); - } -} \ No newline at end of file From 333878cd0035f9b28629f4efe5eff150f271f71b Mon Sep 17 00:00:00 2001 From: blakeli Date: Fri, 18 Apr 2025 18:29:34 -0400 Subject: [PATCH 31/42] Make LazyFieldLite public again because it is on the surface of CodedOutputStream. --- .../src/main/java/com/google/protobuf/LazyFieldLite.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protobuf-api/src/main/java/com/google/protobuf/LazyFieldLite.java b/protobuf-api/src/main/java/com/google/protobuf/LazyFieldLite.java index 0ff6398..d5579fe 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/LazyFieldLite.java +++ b/protobuf-api/src/main/java/com/google/protobuf/LazyFieldLite.java @@ -30,7 +30,7 @@ * * @author xiangl@google.com (Xiang Li) */ -class LazyFieldLite { +public class LazyFieldLite { private static final ExtensionRegistryLite EMPTY_REGISTRY = ExtensionRegistryLite.getEmptyRegistry(); From 526599268f21912ef603d41625c862e1a135dcda Mon Sep 17 00:00:00 2001 From: blakeli Date: Mon, 28 Apr 2025 16:24:58 -0400 Subject: [PATCH 32/42] Use TextFormat instead of TextFormatInternal in AbstractMessage. --- .../src/main/java/com/google/protobuf/AbstractMessage.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/AbstractMessage.java b/protobuf-sdk/src/main/java/com/google/protobuf/AbstractMessage.java index 7b94d47..9c6e207 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/AbstractMessage.java +++ b/protobuf-sdk/src/main/java/com/google/protobuf/AbstractMessage.java @@ -84,7 +84,7 @@ public FieldDescriptor getOneofFieldDescriptor(OneofDescriptor oneof) { @Override public final String toString() { - return TextFormatInternal.printer().printToString(this); + return TextFormat.printer().printToString(this); } @Override @@ -437,7 +437,7 @@ public Message.Builder getRepeatedFieldBuilder(final FieldDescriptor field, int @Override public String toString() { - return TextFormatInternal.printer().printToString(this); + return TextFormat.printer().printToString(this); } /** Construct an UninitializedMessageException reporting missing fields in the given message. */ From 057f4cc95a6fc3842ab4e6b8d2bd5ebc15c43056 Mon Sep 17 00:00:00 2001 From: blakeli Date: Tue, 27 May 2025 12:49:29 -0400 Subject: [PATCH 33/42] Make isSerializationDeterministic public since it used by GeneratedMessageV3. --- .../src/main/java/com/google/protobuf/CodedOutputStream.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protobuf-api/src/main/java/com/google/protobuf/CodedOutputStream.java b/protobuf-api/src/main/java/com/google/protobuf/CodedOutputStream.java index 37bb44a..5131299 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/CodedOutputStream.java +++ b/protobuf-api/src/main/java/com/google/protobuf/CodedOutputStream.java @@ -159,7 +159,7 @@ public void useDeterministicSerialization() { serializationDeterministic = true; } - boolean isSerializationDeterministic() { + public boolean isSerializationDeterministic() { return serializationDeterministic; } From c79e60c7fbb2b31e59e8585c658e00ffd185473e Mon Sep 17 00:00:00 2001 From: blakeli Date: Tue, 27 May 2025 12:50:54 -0400 Subject: [PATCH 34/42] Make TextFormatEscaper and TextFormatInternal public since it used by TextFormat. --- .../src/main/java/com/google/protobuf/TextFormatEscaper.java | 2 +- .../src/main/java/com/google/protobuf/TextFormatInternal.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/protobuf-api/src/main/java/com/google/protobuf/TextFormatEscaper.java b/protobuf-api/src/main/java/com/google/protobuf/TextFormatEscaper.java index c141961..e315e1b 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/TextFormatEscaper.java +++ b/protobuf-api/src/main/java/com/google/protobuf/TextFormatEscaper.java @@ -27,7 +27,7 @@ * Other ASCII characters less than 32 and all Unicode characters 128 or greater are * first encoded as UTF-8, then each byte is escaped individually as a 3-digit octal escape. */ -final class TextFormatEscaper { +public final class TextFormatEscaper { private TextFormatEscaper() {} private interface ByteSequence { diff --git a/protobuf-api/src/main/java/com/google/protobuf/TextFormatInternal.java b/protobuf-api/src/main/java/com/google/protobuf/TextFormatInternal.java index 0355aa5..e5b08de 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/TextFormatInternal.java +++ b/protobuf-api/src/main/java/com/google/protobuf/TextFormatInternal.java @@ -8,7 +8,7 @@ import java.util.Locale; import java.util.Map; -class TextFormatInternal { +public class TextFormatInternal { /** * Parse a 32-bit signed integer from the text. Unlike the Java standard {@code * Integer.parseInt()}, this function recognizes the prefixes "0x" and "0" to signify hexadecimal From 9ee5b3ba0226d7c61ac33d82d724773bae676719 Mon Sep 17 00:00:00 2001 From: blakeli Date: Tue, 27 May 2025 16:34:41 -0400 Subject: [PATCH 35/42] Make package privates methods in TextFormatEscaper public since it used by TextFormat. --- .../java/com/google/protobuf/TextFormatEscaper.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/protobuf-api/src/main/java/com/google/protobuf/TextFormatEscaper.java b/protobuf-api/src/main/java/com/google/protobuf/TextFormatEscaper.java index e315e1b..772700c 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/TextFormatEscaper.java +++ b/protobuf-api/src/main/java/com/google/protobuf/TextFormatEscaper.java @@ -39,7 +39,7 @@ private interface ByteSequence { /** * Backslash escapes bytes in the format used in protocol buffer text format. */ - static String escapeBytes(ByteSequence input) { + public static String escapeBytes(ByteSequence input) { final StringBuilder builder = new StringBuilder(input.size()); for (int i = 0; i < input.size(); i++) { byte b = input.byteAt(i); @@ -128,12 +128,12 @@ public byte byteAt(int offset) { /** * Like {@link #escapeBytes(ByteString)}, but escapes a text string. */ - static String escapeText(String input) { + public static String escapeText(String input) { return escapeBytes(ByteString.copyFromUtf8(input)); } /** Escape double quotes and backslashes in a String for unicode output of a message. */ - static String escapeDoubleQuotesAndBackslashes(String input) { + public static String escapeDoubleQuotesAndBackslashes(String input) { return input.replace("\\", "\\\\").replace("\"", "\\\""); } @@ -165,7 +165,7 @@ private static int digitValue(final byte c) { * Thrown by {@link TextFormat#unescapeBytes} and {@link TextFormat#unescapeText} when an invalid * escape sequence is seen. */ - static class InvalidEscapeSequenceException extends IOException { + public static class InvalidEscapeSequenceException extends IOException { private static final long serialVersionUID = -8164033650142593305L; InvalidEscapeSequenceException(final String description) { @@ -173,7 +173,7 @@ static class InvalidEscapeSequenceException extends IOException { } } - static ByteString unescapeBytes(CharSequence charString) + public static ByteString unescapeBytes(CharSequence charString) throws TextFormatEscaper.InvalidEscapeSequenceException { // First convert the Java character sequence to UTF-8 bytes. ByteString input = ByteString.copyFromUtf8(charString.toString()); From 129e312163a8823756b6c34de8596b45c1dea9c6 Mon Sep 17 00:00:00 2001 From: blakeli Date: Wed, 28 May 2025 18:20:36 -0400 Subject: [PATCH 36/42] Introduce RepeatedFieldBuilderV3Internal and SingleFieldBuilderV3Internal for well-known types and PluginProtos. Move RepeatedFieldBuilderV3 and SingleFieldBuilderV3 to SDK package and restore the binary incompatibility, by change the constructor type from Message back to AbstractMessage. --- .../main/java/com/google/protobuf/Api.java | 48 +- .../com/google/protobuf/DescriptorProtos.java | 636 ++++++++--------- .../main/java/com/google/protobuf/Enum.java | 36 +- .../java/com/google/protobuf/EnumValue.java | 12 +- .../main/java/com/google/protobuf/Field.java | 12 +- .../java/com/google/protobuf/ListValue.java | 12 +- .../main/java/com/google/protobuf/Method.java | 12 +- .../main/java/com/google/protobuf/Option.java | 12 +- .../RepeatedFieldBuilderV3Internal.java | 647 +++++++++++++++++ .../SingleFieldBuilderV3Internal.java | 217 ++++++ .../main/java/com/google/protobuf/Type.java | 36 +- .../main/java/com/google/protobuf/Value.java | 24 +- .../protobuf/RepeatedFieldBuilderV3.java | 31 +- .../google/protobuf/SingleFieldBuilderV3.java | 27 +- .../protobuf/compiler/PluginProtos.java | 32 +- .../RepeatedFieldBuilderV3Internal.java | 656 ++++++++++++++++++ .../SingleFieldBuilderV3Internal.java | 219 ++++++ 17 files changed, 2210 insertions(+), 459 deletions(-) create mode 100644 protobuf-api/src/main/java/com/google/protobuf/RepeatedFieldBuilderV3Internal.java create mode 100644 protobuf-api/src/main/java/com/google/protobuf/SingleFieldBuilderV3Internal.java rename {protobuf-api => protobuf-sdk}/src/main/java/com/google/protobuf/RepeatedFieldBuilderV3.java (97%) rename {protobuf-api => protobuf-sdk}/src/main/java/com/google/protobuf/SingleFieldBuilderV3.java (92%) create mode 100644 protobuf-sdk/src/main/java/com/google/protobuf/compiler/RepeatedFieldBuilderV3Internal.java create mode 100644 protobuf-sdk/src/main/java/com/google/protobuf/compiler/SingleFieldBuilderV3Internal.java diff --git a/protobuf-api/src/main/java/com/google/protobuf/Api.java b/protobuf-api/src/main/java/com/google/protobuf/Api.java index 22b8493..a04ebcc 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/Api.java +++ b/protobuf-api/src/main/java/com/google/protobuf/Api.java @@ -1186,8 +1186,8 @@ private void ensureMethodsIsMutable() { } } - private com.google.protobuf.RepeatedFieldBuilderV3< - com.google.protobuf.Method, com.google.protobuf.Method.Builder, com.google.protobuf.MethodOrBuilder> methodsBuilder_; + private RepeatedFieldBuilderV3Internal< + Method, Method.Builder, MethodOrBuilder> methodsBuilder_; /** *

@@ -1474,12 +1474,12 @@ public com.google.protobuf.Method.Builder addMethodsBuilder(
          getMethodsBuilderList() {
       return getMethodsFieldBuilder().getBuilderList();
     }
-    private com.google.protobuf.RepeatedFieldBuilderV3<
-        com.google.protobuf.Method, com.google.protobuf.Method.Builder, com.google.protobuf.MethodOrBuilder> 
+    private RepeatedFieldBuilderV3Internal<
+            Method, Method.Builder, MethodOrBuilder>
         getMethodsFieldBuilder() {
       if (methodsBuilder_ == null) {
-        methodsBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
-            com.google.protobuf.Method, com.google.protobuf.Method.Builder, com.google.protobuf.MethodOrBuilder>(
+        methodsBuilder_ = new RepeatedFieldBuilderV3Internal<
+                    Method, Method.Builder, MethodOrBuilder>(
                 methods_,
                 ((bitField0_ & 0x00000002) != 0),
                 getParentForChildren(),
@@ -1498,8 +1498,8 @@ private void ensureOptionsIsMutable() {
        }
     }
 
-    private com.google.protobuf.RepeatedFieldBuilderV3<
-        com.google.protobuf.Option, com.google.protobuf.Option.Builder, com.google.protobuf.OptionOrBuilder> optionsBuilder_;
+    private RepeatedFieldBuilderV3Internal<
+            Option, Option.Builder, OptionOrBuilder> optionsBuilder_;
 
     /**
      * 
@@ -1786,12 +1786,12 @@ public com.google.protobuf.Option.Builder addOptionsBuilder(
          getOptionsBuilderList() {
       return getOptionsFieldBuilder().getBuilderList();
     }
-    private com.google.protobuf.RepeatedFieldBuilderV3<
-        com.google.protobuf.Option, com.google.protobuf.Option.Builder, com.google.protobuf.OptionOrBuilder> 
+    private RepeatedFieldBuilderV3Internal<
+            Option, Option.Builder, OptionOrBuilder>
         getOptionsFieldBuilder() {
       if (optionsBuilder_ == null) {
-        optionsBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
-            com.google.protobuf.Option, com.google.protobuf.Option.Builder, com.google.protobuf.OptionOrBuilder>(
+        optionsBuilder_ = new RepeatedFieldBuilderV3Internal<
+                    Option, Option.Builder, OptionOrBuilder>(
                 options_,
                 ((bitField0_ & 0x00000004) != 0),
                 getParentForChildren(),
@@ -1984,8 +1984,8 @@ public Builder setVersionBytes(
     }
 
     private com.google.protobuf.SourceContext sourceContext_;
-    private com.google.protobuf.SingleFieldBuilderV3<
-        com.google.protobuf.SourceContext, com.google.protobuf.SourceContext.Builder, com.google.protobuf.SourceContextOrBuilder> sourceContextBuilder_;
+    private SingleFieldBuilderV3Internal<
+            SourceContext, SourceContext.Builder, SourceContextOrBuilder> sourceContextBuilder_;
     /**
      * 
      * Source context for the protocol buffer service represented by this
@@ -2135,12 +2135,12 @@ public com.google.protobuf.SourceContextOrBuilder getSourceContextOrBuilder() {
      *
      * .google.protobuf.SourceContext source_context = 5;
      */
-    private com.google.protobuf.SingleFieldBuilderV3<
-        com.google.protobuf.SourceContext, com.google.protobuf.SourceContext.Builder, com.google.protobuf.SourceContextOrBuilder> 
+    private SingleFieldBuilderV3Internal<
+            SourceContext, SourceContext.Builder, SourceContextOrBuilder>
         getSourceContextFieldBuilder() {
       if (sourceContextBuilder_ == null) {
-        sourceContextBuilder_ = new com.google.protobuf.SingleFieldBuilderV3<
-            com.google.protobuf.SourceContext, com.google.protobuf.SourceContext.Builder, com.google.protobuf.SourceContextOrBuilder>(
+        sourceContextBuilder_ = new SingleFieldBuilderV3Internal<
+                    SourceContext, SourceContext.Builder, SourceContextOrBuilder>(
                 getSourceContext(),
                 getParentForChildren(),
                 isClean());
@@ -2158,8 +2158,8 @@ private void ensureMixinsIsMutable() {
        }
     }
 
-    private com.google.protobuf.RepeatedFieldBuilderV3<
-        com.google.protobuf.Mixin, com.google.protobuf.Mixin.Builder, com.google.protobuf.MixinOrBuilder> mixinsBuilder_;
+    private RepeatedFieldBuilderV3Internal<
+            Mixin, Mixin.Builder, MixinOrBuilder> mixinsBuilder_;
 
     /**
      * 
@@ -2446,12 +2446,12 @@ public com.google.protobuf.Mixin.Builder addMixinsBuilder(
          getMixinsBuilderList() {
       return getMixinsFieldBuilder().getBuilderList();
     }
-    private com.google.protobuf.RepeatedFieldBuilderV3<
-        com.google.protobuf.Mixin, com.google.protobuf.Mixin.Builder, com.google.protobuf.MixinOrBuilder> 
+    private RepeatedFieldBuilderV3Internal<
+            Mixin, Mixin.Builder, MixinOrBuilder>
         getMixinsFieldBuilder() {
       if (mixinsBuilder_ == null) {
-        mixinsBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
-            com.google.protobuf.Mixin, com.google.protobuf.Mixin.Builder, com.google.protobuf.MixinOrBuilder>(
+        mixinsBuilder_ = new RepeatedFieldBuilderV3Internal<
+                    Mixin, Mixin.Builder, MixinOrBuilder>(
                 mixins_,
                 ((bitField0_ & 0x00000020) != 0),
                 getParentForChildren(),
diff --git a/protobuf-api/src/main/java/com/google/protobuf/DescriptorProtos.java b/protobuf-api/src/main/java/com/google/protobuf/DescriptorProtos.java
index 23ba571..8c8fa7e 100644
--- a/protobuf-api/src/main/java/com/google/protobuf/DescriptorProtos.java
+++ b/protobuf-api/src/main/java/com/google/protobuf/DescriptorProtos.java
@@ -826,8 +826,8 @@ private void ensureFileIsMutable() {
          }
       }
 
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.FileDescriptorProto, com.google.protobuf.DescriptorProtos.FileDescriptorProto.Builder, com.google.protobuf.DescriptorProtos.FileDescriptorProtoOrBuilder> fileBuilder_;
+      private RepeatedFieldBuilderV3Internal<
+                FileDescriptorProto, FileDescriptorProto.Builder, FileDescriptorProtoOrBuilder> fileBuilder_;
 
       /**
        * repeated .google.protobuf.FileDescriptorProto file = 1;
@@ -1042,12 +1042,12 @@ public com.google.protobuf.DescriptorProtos.FileDescriptorProto.Builder addFileB
            getFileBuilderList() {
         return getFileFieldBuilder().getBuilderList();
       }
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.FileDescriptorProto, com.google.protobuf.DescriptorProtos.FileDescriptorProto.Builder, com.google.protobuf.DescriptorProtos.FileDescriptorProtoOrBuilder> 
+      private RepeatedFieldBuilderV3Internal<
+                FileDescriptorProto, FileDescriptorProto.Builder, FileDescriptorProtoOrBuilder>
           getFileFieldBuilder() {
         if (fileBuilder_ == null) {
-          fileBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.FileDescriptorProto, com.google.protobuf.DescriptorProtos.FileDescriptorProto.Builder, com.google.protobuf.DescriptorProtos.FileDescriptorProtoOrBuilder>(
+          fileBuilder_ = new RepeatedFieldBuilderV3Internal<
+                        FileDescriptorProto, FileDescriptorProto.Builder, FileDescriptorProtoOrBuilder>(
                   file_,
                   ((bitField0_ & 0x00000001) != 0),
                   getParentForChildren(),
@@ -3796,8 +3796,8 @@ private void ensureMessageTypeIsMutable() {
          }
       }
 
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.DescriptorProto, com.google.protobuf.DescriptorProtos.DescriptorProto.Builder, com.google.protobuf.DescriptorProtos.DescriptorProtoOrBuilder> messageTypeBuilder_;
+      private RepeatedFieldBuilderV3Internal<
+                DescriptorProto, DescriptorProto.Builder, DescriptorProtoOrBuilder> messageTypeBuilder_;
 
       /**
        * 
@@ -4084,12 +4084,12 @@ public com.google.protobuf.DescriptorProtos.DescriptorProto.Builder addMessageTy
            getMessageTypeBuilderList() {
         return getMessageTypeFieldBuilder().getBuilderList();
       }
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.DescriptorProto, com.google.protobuf.DescriptorProtos.DescriptorProto.Builder, com.google.protobuf.DescriptorProtos.DescriptorProtoOrBuilder> 
+      private RepeatedFieldBuilderV3Internal<
+                DescriptorProto, DescriptorProto.Builder, DescriptorProtoOrBuilder>
           getMessageTypeFieldBuilder() {
         if (messageTypeBuilder_ == null) {
-          messageTypeBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.DescriptorProto, com.google.protobuf.DescriptorProtos.DescriptorProto.Builder, com.google.protobuf.DescriptorProtos.DescriptorProtoOrBuilder>(
+          messageTypeBuilder_ = new RepeatedFieldBuilderV3Internal<
+                        DescriptorProto, DescriptorProto.Builder, DescriptorProtoOrBuilder>(
                   messageType_,
                   ((bitField0_ & 0x00000020) != 0),
                   getParentForChildren(),
@@ -4108,8 +4108,8 @@ private void ensureEnumTypeIsMutable() {
          }
       }
 
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.EnumDescriptorProto, com.google.protobuf.DescriptorProtos.EnumDescriptorProto.Builder, com.google.protobuf.DescriptorProtos.EnumDescriptorProtoOrBuilder> enumTypeBuilder_;
+      private RepeatedFieldBuilderV3Internal<
+                EnumDescriptorProto, EnumDescriptorProto.Builder, EnumDescriptorProtoOrBuilder> enumTypeBuilder_;
 
       /**
        * repeated .google.protobuf.EnumDescriptorProto enum_type = 5;
@@ -4324,12 +4324,12 @@ public com.google.protobuf.DescriptorProtos.EnumDescriptorProto.Builder addEnumT
            getEnumTypeBuilderList() {
         return getEnumTypeFieldBuilder().getBuilderList();
       }
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.EnumDescriptorProto, com.google.protobuf.DescriptorProtos.EnumDescriptorProto.Builder, com.google.protobuf.DescriptorProtos.EnumDescriptorProtoOrBuilder> 
+      private RepeatedFieldBuilderV3Internal<
+                EnumDescriptorProto, EnumDescriptorProto.Builder, EnumDescriptorProtoOrBuilder>
           getEnumTypeFieldBuilder() {
         if (enumTypeBuilder_ == null) {
-          enumTypeBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.EnumDescriptorProto, com.google.protobuf.DescriptorProtos.EnumDescriptorProto.Builder, com.google.protobuf.DescriptorProtos.EnumDescriptorProtoOrBuilder>(
+          enumTypeBuilder_ = new RepeatedFieldBuilderV3Internal<
+                        EnumDescriptorProto, EnumDescriptorProto.Builder, EnumDescriptorProtoOrBuilder>(
                   enumType_,
                   ((bitField0_ & 0x00000040) != 0),
                   getParentForChildren(),
@@ -4348,8 +4348,8 @@ private void ensureServiceIsMutable() {
          }
       }
 
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.ServiceDescriptorProto, com.google.protobuf.DescriptorProtos.ServiceDescriptorProto.Builder, com.google.protobuf.DescriptorProtos.ServiceDescriptorProtoOrBuilder> serviceBuilder_;
+      private RepeatedFieldBuilderV3Internal<
+                ServiceDescriptorProto, ServiceDescriptorProto.Builder, ServiceDescriptorProtoOrBuilder> serviceBuilder_;
 
       /**
        * repeated .google.protobuf.ServiceDescriptorProto service = 6;
@@ -4564,12 +4564,12 @@ public com.google.protobuf.DescriptorProtos.ServiceDescriptorProto.Builder addSe
            getServiceBuilderList() {
         return getServiceFieldBuilder().getBuilderList();
       }
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.ServiceDescriptorProto, com.google.protobuf.DescriptorProtos.ServiceDescriptorProto.Builder, com.google.protobuf.DescriptorProtos.ServiceDescriptorProtoOrBuilder> 
+      private RepeatedFieldBuilderV3Internal<
+                ServiceDescriptorProto, ServiceDescriptorProto.Builder, ServiceDescriptorProtoOrBuilder>
           getServiceFieldBuilder() {
         if (serviceBuilder_ == null) {
-          serviceBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.ServiceDescriptorProto, com.google.protobuf.DescriptorProtos.ServiceDescriptorProto.Builder, com.google.protobuf.DescriptorProtos.ServiceDescriptorProtoOrBuilder>(
+          serviceBuilder_ = new RepeatedFieldBuilderV3Internal<
+                        ServiceDescriptorProto, ServiceDescriptorProto.Builder, ServiceDescriptorProtoOrBuilder>(
                   service_,
                   ((bitField0_ & 0x00000080) != 0),
                   getParentForChildren(),
@@ -4588,8 +4588,8 @@ private void ensureExtensionIsMutable() {
          }
       }
 
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.FieldDescriptorProto, com.google.protobuf.DescriptorProtos.FieldDescriptorProto.Builder, com.google.protobuf.DescriptorProtos.FieldDescriptorProtoOrBuilder> extensionBuilder_;
+      private RepeatedFieldBuilderV3Internal<
+                FieldDescriptorProto, FieldDescriptorProto.Builder, FieldDescriptorProtoOrBuilder> extensionBuilder_;
 
       /**
        * repeated .google.protobuf.FieldDescriptorProto extension = 7;
@@ -4804,12 +4804,12 @@ public com.google.protobuf.DescriptorProtos.FieldDescriptorProto.Builder addExte
            getExtensionBuilderList() {
         return getExtensionFieldBuilder().getBuilderList();
       }
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.FieldDescriptorProto, com.google.protobuf.DescriptorProtos.FieldDescriptorProto.Builder, com.google.protobuf.DescriptorProtos.FieldDescriptorProtoOrBuilder> 
+      private RepeatedFieldBuilderV3Internal<
+                FieldDescriptorProto, FieldDescriptorProto.Builder, FieldDescriptorProtoOrBuilder>
           getExtensionFieldBuilder() {
         if (extensionBuilder_ == null) {
-          extensionBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.FieldDescriptorProto, com.google.protobuf.DescriptorProtos.FieldDescriptorProto.Builder, com.google.protobuf.DescriptorProtos.FieldDescriptorProtoOrBuilder>(
+          extensionBuilder_ = new RepeatedFieldBuilderV3Internal<
+                        FieldDescriptorProto, FieldDescriptorProto.Builder, FieldDescriptorProtoOrBuilder>(
                   extension_,
                   ((bitField0_ & 0x00000100) != 0),
                   getParentForChildren(),
@@ -4820,8 +4820,8 @@ public com.google.protobuf.DescriptorProtos.FieldDescriptorProto.Builder addExte
       }
 
       private com.google.protobuf.DescriptorProtos.FileOptions options_;
-      private com.google.protobuf.SingleFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.FileOptions, com.google.protobuf.DescriptorProtos.FileOptions.Builder, com.google.protobuf.DescriptorProtos.FileOptionsOrBuilder> optionsBuilder_;
+      private SingleFieldBuilderV3Internal<
+                FileOptions, FileOptions.Builder, FileOptionsOrBuilder> optionsBuilder_;
       /**
        * optional .google.protobuf.FileOptions options = 8;
        * @return Whether the options field is set.
@@ -4926,12 +4926,12 @@ public com.google.protobuf.DescriptorProtos.FileOptionsOrBuilder getOptionsOrBui
       /**
        * optional .google.protobuf.FileOptions options = 8;
        */
-      private com.google.protobuf.SingleFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.FileOptions, com.google.protobuf.DescriptorProtos.FileOptions.Builder, com.google.protobuf.DescriptorProtos.FileOptionsOrBuilder> 
+      private SingleFieldBuilderV3Internal<
+                FileOptions, FileOptions.Builder, FileOptionsOrBuilder>
           getOptionsFieldBuilder() {
         if (optionsBuilder_ == null) {
-          optionsBuilder_ = new com.google.protobuf.SingleFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.FileOptions, com.google.protobuf.DescriptorProtos.FileOptions.Builder, com.google.protobuf.DescriptorProtos.FileOptionsOrBuilder>(
+          optionsBuilder_ = new SingleFieldBuilderV3Internal<
+                        FileOptions, FileOptions.Builder, FileOptionsOrBuilder>(
                   getOptions(),
                   getParentForChildren(),
                   isClean());
@@ -4941,8 +4941,8 @@ public com.google.protobuf.DescriptorProtos.FileOptionsOrBuilder getOptionsOrBui
       }
 
       private com.google.protobuf.DescriptorProtos.SourceCodeInfo sourceCodeInfo_;
-      private com.google.protobuf.SingleFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.SourceCodeInfo, com.google.protobuf.DescriptorProtos.SourceCodeInfo.Builder, com.google.protobuf.DescriptorProtos.SourceCodeInfoOrBuilder> sourceCodeInfoBuilder_;
+      private SingleFieldBuilderV3Internal<
+                SourceCodeInfo, SourceCodeInfo.Builder, SourceCodeInfoOrBuilder> sourceCodeInfoBuilder_;
       /**
        * 
        * This field contains optional information about the original source code.
@@ -5110,12 +5110,12 @@ public com.google.protobuf.DescriptorProtos.SourceCodeInfoOrBuilder getSourceCod
        *
        * optional .google.protobuf.SourceCodeInfo source_code_info = 9;
        */
-      private com.google.protobuf.SingleFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.SourceCodeInfo, com.google.protobuf.DescriptorProtos.SourceCodeInfo.Builder, com.google.protobuf.DescriptorProtos.SourceCodeInfoOrBuilder> 
+      private SingleFieldBuilderV3Internal<
+                SourceCodeInfo, SourceCodeInfo.Builder, SourceCodeInfoOrBuilder>
           getSourceCodeInfoFieldBuilder() {
         if (sourceCodeInfoBuilder_ == null) {
-          sourceCodeInfoBuilder_ = new com.google.protobuf.SingleFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.SourceCodeInfo, com.google.protobuf.DescriptorProtos.SourceCodeInfo.Builder, com.google.protobuf.DescriptorProtos.SourceCodeInfoOrBuilder>(
+          sourceCodeInfoBuilder_ = new SingleFieldBuilderV3Internal<
+                        SourceCodeInfo, SourceCodeInfo.Builder, SourceCodeInfoOrBuilder>(
                   getSourceCodeInfo(),
                   getParentForChildren(),
                   isClean());
@@ -6397,8 +6397,8 @@ public Builder clearEnd() {
         }
 
         private com.google.protobuf.DescriptorProtos.ExtensionRangeOptions options_;
-        private com.google.protobuf.SingleFieldBuilderV3<
-            com.google.protobuf.DescriptorProtos.ExtensionRangeOptions, com.google.protobuf.DescriptorProtos.ExtensionRangeOptions.Builder, com.google.protobuf.DescriptorProtos.ExtensionRangeOptionsOrBuilder> optionsBuilder_;
+        private SingleFieldBuilderV3Internal<
+                    ExtensionRangeOptions, ExtensionRangeOptions.Builder, ExtensionRangeOptionsOrBuilder> optionsBuilder_;
         /**
          * optional .google.protobuf.ExtensionRangeOptions options = 3;
          * @return Whether the options field is set.
@@ -6503,12 +6503,12 @@ public com.google.protobuf.DescriptorProtos.ExtensionRangeOptionsOrBuilder getOp
         /**
          * optional .google.protobuf.ExtensionRangeOptions options = 3;
          */
-        private com.google.protobuf.SingleFieldBuilderV3<
-            com.google.protobuf.DescriptorProtos.ExtensionRangeOptions, com.google.protobuf.DescriptorProtos.ExtensionRangeOptions.Builder, com.google.protobuf.DescriptorProtos.ExtensionRangeOptionsOrBuilder> 
+        private SingleFieldBuilderV3Internal<
+                    ExtensionRangeOptions, ExtensionRangeOptions.Builder, ExtensionRangeOptionsOrBuilder>
             getOptionsFieldBuilder() {
           if (optionsBuilder_ == null) {
-            optionsBuilder_ = new com.google.protobuf.SingleFieldBuilderV3<
-                com.google.protobuf.DescriptorProtos.ExtensionRangeOptions, com.google.protobuf.DescriptorProtos.ExtensionRangeOptions.Builder, com.google.protobuf.DescriptorProtos.ExtensionRangeOptionsOrBuilder>(
+            optionsBuilder_ = new SingleFieldBuilderV3Internal<
+                            ExtensionRangeOptions, ExtensionRangeOptions.Builder, ExtensionRangeOptionsOrBuilder>(
                     getOptions(),
                     getParentForChildren(),
                     isClean());
@@ -8754,8 +8754,8 @@ private void ensureFieldIsMutable() {
          }
       }
 
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.FieldDescriptorProto, com.google.protobuf.DescriptorProtos.FieldDescriptorProto.Builder, com.google.protobuf.DescriptorProtos.FieldDescriptorProtoOrBuilder> fieldBuilder_;
+      private RepeatedFieldBuilderV3Internal<
+                FieldDescriptorProto, FieldDescriptorProto.Builder, FieldDescriptorProtoOrBuilder> fieldBuilder_;
 
       /**
        * repeated .google.protobuf.FieldDescriptorProto field = 2;
@@ -8970,12 +8970,12 @@ public com.google.protobuf.DescriptorProtos.FieldDescriptorProto.Builder addFiel
            getFieldBuilderList() {
         return getFieldFieldBuilder().getBuilderList();
       }
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.FieldDescriptorProto, com.google.protobuf.DescriptorProtos.FieldDescriptorProto.Builder, com.google.protobuf.DescriptorProtos.FieldDescriptorProtoOrBuilder> 
+      private RepeatedFieldBuilderV3Internal<
+                FieldDescriptorProto, FieldDescriptorProto.Builder, FieldDescriptorProtoOrBuilder>
           getFieldFieldBuilder() {
         if (fieldBuilder_ == null) {
-          fieldBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.FieldDescriptorProto, com.google.protobuf.DescriptorProtos.FieldDescriptorProto.Builder, com.google.protobuf.DescriptorProtos.FieldDescriptorProtoOrBuilder>(
+          fieldBuilder_ = new RepeatedFieldBuilderV3Internal<
+                        FieldDescriptorProto, FieldDescriptorProto.Builder, FieldDescriptorProtoOrBuilder>(
                   field_,
                   ((bitField0_ & 0x00000002) != 0),
                   getParentForChildren(),
@@ -8994,8 +8994,8 @@ private void ensureExtensionIsMutable() {
          }
       }
 
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.FieldDescriptorProto, com.google.protobuf.DescriptorProtos.FieldDescriptorProto.Builder, com.google.protobuf.DescriptorProtos.FieldDescriptorProtoOrBuilder> extensionBuilder_;
+      private RepeatedFieldBuilderV3Internal<
+                FieldDescriptorProto, FieldDescriptorProto.Builder, FieldDescriptorProtoOrBuilder> extensionBuilder_;
 
       /**
        * repeated .google.protobuf.FieldDescriptorProto extension = 6;
@@ -9210,12 +9210,12 @@ public com.google.protobuf.DescriptorProtos.FieldDescriptorProto.Builder addExte
            getExtensionBuilderList() {
         return getExtensionFieldBuilder().getBuilderList();
       }
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.FieldDescriptorProto, com.google.protobuf.DescriptorProtos.FieldDescriptorProto.Builder, com.google.protobuf.DescriptorProtos.FieldDescriptorProtoOrBuilder> 
+      private RepeatedFieldBuilderV3Internal<
+                FieldDescriptorProto, FieldDescriptorProto.Builder, FieldDescriptorProtoOrBuilder>
           getExtensionFieldBuilder() {
         if (extensionBuilder_ == null) {
-          extensionBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.FieldDescriptorProto, com.google.protobuf.DescriptorProtos.FieldDescriptorProto.Builder, com.google.protobuf.DescriptorProtos.FieldDescriptorProtoOrBuilder>(
+          extensionBuilder_ = new RepeatedFieldBuilderV3Internal<
+                        FieldDescriptorProto, FieldDescriptorProto.Builder, FieldDescriptorProtoOrBuilder>(
                   extension_,
                   ((bitField0_ & 0x00000004) != 0),
                   getParentForChildren(),
@@ -9234,8 +9234,8 @@ private void ensureNestedTypeIsMutable() {
          }
       }
 
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.DescriptorProto, com.google.protobuf.DescriptorProtos.DescriptorProto.Builder, com.google.protobuf.DescriptorProtos.DescriptorProtoOrBuilder> nestedTypeBuilder_;
+      private RepeatedFieldBuilderV3Internal<
+                DescriptorProto, Builder, DescriptorProtoOrBuilder> nestedTypeBuilder_;
 
       /**
        * repeated .google.protobuf.DescriptorProto nested_type = 3;
@@ -9450,12 +9450,12 @@ public com.google.protobuf.DescriptorProtos.DescriptorProto.Builder addNestedTyp
            getNestedTypeBuilderList() {
         return getNestedTypeFieldBuilder().getBuilderList();
       }
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.DescriptorProto, com.google.protobuf.DescriptorProtos.DescriptorProto.Builder, com.google.protobuf.DescriptorProtos.DescriptorProtoOrBuilder> 
+      private RepeatedFieldBuilderV3Internal<
+                DescriptorProto, Builder, DescriptorProtoOrBuilder>
           getNestedTypeFieldBuilder() {
         if (nestedTypeBuilder_ == null) {
-          nestedTypeBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.DescriptorProto, com.google.protobuf.DescriptorProtos.DescriptorProto.Builder, com.google.protobuf.DescriptorProtos.DescriptorProtoOrBuilder>(
+          nestedTypeBuilder_ = new RepeatedFieldBuilderV3Internal<
+                        DescriptorProto, Builder, DescriptorProtoOrBuilder>(
                   nestedType_,
                   ((bitField0_ & 0x00000008) != 0),
                   getParentForChildren(),
@@ -9474,8 +9474,8 @@ private void ensureEnumTypeIsMutable() {
          }
       }
 
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.EnumDescriptorProto, com.google.protobuf.DescriptorProtos.EnumDescriptorProto.Builder, com.google.protobuf.DescriptorProtos.EnumDescriptorProtoOrBuilder> enumTypeBuilder_;
+      private RepeatedFieldBuilderV3Internal<
+                EnumDescriptorProto, EnumDescriptorProto.Builder, EnumDescriptorProtoOrBuilder> enumTypeBuilder_;
 
       /**
        * repeated .google.protobuf.EnumDescriptorProto enum_type = 4;
@@ -9690,12 +9690,12 @@ public com.google.protobuf.DescriptorProtos.EnumDescriptorProto.Builder addEnumT
            getEnumTypeBuilderList() {
         return getEnumTypeFieldBuilder().getBuilderList();
       }
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.EnumDescriptorProto, com.google.protobuf.DescriptorProtos.EnumDescriptorProto.Builder, com.google.protobuf.DescriptorProtos.EnumDescriptorProtoOrBuilder> 
+      private RepeatedFieldBuilderV3Internal<
+                EnumDescriptorProto, EnumDescriptorProto.Builder, EnumDescriptorProtoOrBuilder>
           getEnumTypeFieldBuilder() {
         if (enumTypeBuilder_ == null) {
-          enumTypeBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.EnumDescriptorProto, com.google.protobuf.DescriptorProtos.EnumDescriptorProto.Builder, com.google.protobuf.DescriptorProtos.EnumDescriptorProtoOrBuilder>(
+          enumTypeBuilder_ = new RepeatedFieldBuilderV3Internal<
+                        EnumDescriptorProto, EnumDescriptorProto.Builder, EnumDescriptorProtoOrBuilder>(
                   enumType_,
                   ((bitField0_ & 0x00000010) != 0),
                   getParentForChildren(),
@@ -9714,8 +9714,8 @@ private void ensureExtensionRangeIsMutable() {
          }
       }
 
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange, com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange.Builder, com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRangeOrBuilder> extensionRangeBuilder_;
+      private RepeatedFieldBuilderV3Internal<
+                ExtensionRange, ExtensionRange.Builder, ExtensionRangeOrBuilder> extensionRangeBuilder_;
 
       /**
        * repeated .google.protobuf.DescriptorProto.ExtensionRange extension_range = 5;
@@ -9930,12 +9930,12 @@ public com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange.Build
            getExtensionRangeBuilderList() {
         return getExtensionRangeFieldBuilder().getBuilderList();
       }
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange, com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange.Builder, com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRangeOrBuilder> 
+      private RepeatedFieldBuilderV3Internal<
+                ExtensionRange, ExtensionRange.Builder, ExtensionRangeOrBuilder>
           getExtensionRangeFieldBuilder() {
         if (extensionRangeBuilder_ == null) {
-          extensionRangeBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange, com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange.Builder, com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRangeOrBuilder>(
+          extensionRangeBuilder_ = new RepeatedFieldBuilderV3Internal<
+                        ExtensionRange, ExtensionRange.Builder, ExtensionRangeOrBuilder>(
                   extensionRange_,
                   ((bitField0_ & 0x00000020) != 0),
                   getParentForChildren(),
@@ -9954,8 +9954,8 @@ private void ensureOneofDeclIsMutable() {
          }
       }
 
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.OneofDescriptorProto, com.google.protobuf.DescriptorProtos.OneofDescriptorProto.Builder, com.google.protobuf.DescriptorProtos.OneofDescriptorProtoOrBuilder> oneofDeclBuilder_;
+      private RepeatedFieldBuilderV3Internal<
+                OneofDescriptorProto, OneofDescriptorProto.Builder, OneofDescriptorProtoOrBuilder> oneofDeclBuilder_;
 
       /**
        * repeated .google.protobuf.OneofDescriptorProto oneof_decl = 8;
@@ -10170,12 +10170,12 @@ public com.google.protobuf.DescriptorProtos.OneofDescriptorProto.Builder addOneo
            getOneofDeclBuilderList() {
         return getOneofDeclFieldBuilder().getBuilderList();
       }
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.OneofDescriptorProto, com.google.protobuf.DescriptorProtos.OneofDescriptorProto.Builder, com.google.protobuf.DescriptorProtos.OneofDescriptorProtoOrBuilder> 
+      private RepeatedFieldBuilderV3Internal<
+                OneofDescriptorProto, OneofDescriptorProto.Builder, OneofDescriptorProtoOrBuilder>
           getOneofDeclFieldBuilder() {
         if (oneofDeclBuilder_ == null) {
-          oneofDeclBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.OneofDescriptorProto, com.google.protobuf.DescriptorProtos.OneofDescriptorProto.Builder, com.google.protobuf.DescriptorProtos.OneofDescriptorProtoOrBuilder>(
+          oneofDeclBuilder_ = new RepeatedFieldBuilderV3Internal<
+                        OneofDescriptorProto, OneofDescriptorProto.Builder, OneofDescriptorProtoOrBuilder>(
                   oneofDecl_,
                   ((bitField0_ & 0x00000040) != 0),
                   getParentForChildren(),
@@ -10186,8 +10186,8 @@ public com.google.protobuf.DescriptorProtos.OneofDescriptorProto.Builder addOneo
       }
 
       private com.google.protobuf.DescriptorProtos.MessageOptions options_;
-      private com.google.protobuf.SingleFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.MessageOptions, com.google.protobuf.DescriptorProtos.MessageOptions.Builder, com.google.protobuf.DescriptorProtos.MessageOptionsOrBuilder> optionsBuilder_;
+      private SingleFieldBuilderV3Internal<
+                MessageOptions, MessageOptions.Builder, MessageOptionsOrBuilder> optionsBuilder_;
       /**
        * optional .google.protobuf.MessageOptions options = 7;
        * @return Whether the options field is set.
@@ -10292,12 +10292,12 @@ public com.google.protobuf.DescriptorProtos.MessageOptionsOrBuilder getOptionsOr
       /**
        * optional .google.protobuf.MessageOptions options = 7;
        */
-      private com.google.protobuf.SingleFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.MessageOptions, com.google.protobuf.DescriptorProtos.MessageOptions.Builder, com.google.protobuf.DescriptorProtos.MessageOptionsOrBuilder> 
+      private SingleFieldBuilderV3Internal<
+                MessageOptions, MessageOptions.Builder, MessageOptionsOrBuilder>
           getOptionsFieldBuilder() {
         if (optionsBuilder_ == null) {
-          optionsBuilder_ = new com.google.protobuf.SingleFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.MessageOptions, com.google.protobuf.DescriptorProtos.MessageOptions.Builder, com.google.protobuf.DescriptorProtos.MessageOptionsOrBuilder>(
+          optionsBuilder_ = new SingleFieldBuilderV3Internal<
+                        MessageOptions, MessageOptions.Builder, MessageOptionsOrBuilder>(
                   getOptions(),
                   getParentForChildren(),
                   isClean());
@@ -10315,8 +10315,8 @@ private void ensureReservedRangeIsMutable() {
          }
       }
 
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.DescriptorProto.ReservedRange, com.google.protobuf.DescriptorProtos.DescriptorProto.ReservedRange.Builder, com.google.protobuf.DescriptorProtos.DescriptorProto.ReservedRangeOrBuilder> reservedRangeBuilder_;
+      private RepeatedFieldBuilderV3Internal<
+                ReservedRange, ReservedRange.Builder, ReservedRangeOrBuilder> reservedRangeBuilder_;
 
       /**
        * repeated .google.protobuf.DescriptorProto.ReservedRange reserved_range = 9;
@@ -10531,12 +10531,12 @@ public com.google.protobuf.DescriptorProtos.DescriptorProto.ReservedRange.Builde
            getReservedRangeBuilderList() {
         return getReservedRangeFieldBuilder().getBuilderList();
       }
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.DescriptorProto.ReservedRange, com.google.protobuf.DescriptorProtos.DescriptorProto.ReservedRange.Builder, com.google.protobuf.DescriptorProtos.DescriptorProto.ReservedRangeOrBuilder> 
+      private RepeatedFieldBuilderV3Internal<
+                ReservedRange, ReservedRange.Builder, ReservedRangeOrBuilder>
           getReservedRangeFieldBuilder() {
         if (reservedRangeBuilder_ == null) {
-          reservedRangeBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.DescriptorProto.ReservedRange, com.google.protobuf.DescriptorProtos.DescriptorProto.ReservedRange.Builder, com.google.protobuf.DescriptorProtos.DescriptorProto.ReservedRangeOrBuilder>(
+          reservedRangeBuilder_ = new RepeatedFieldBuilderV3Internal<
+                        ReservedRange, ReservedRange.Builder, ReservedRangeOrBuilder>(
                   reservedRange_,
                   ((bitField0_ & 0x00000100) != 0),
                   getParentForChildren(),
@@ -13176,8 +13176,8 @@ private void ensureUninterpretedOptionIsMutable() {
          }
       }
 
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.UninterpretedOption, com.google.protobuf.DescriptorProtos.UninterpretedOption.Builder, com.google.protobuf.DescriptorProtos.UninterpretedOptionOrBuilder> uninterpretedOptionBuilder_;
+      private RepeatedFieldBuilderV3Internal<
+                UninterpretedOption, UninterpretedOption.Builder, UninterpretedOptionOrBuilder> uninterpretedOptionBuilder_;
 
       /**
        * 
@@ -13464,12 +13464,12 @@ public com.google.protobuf.DescriptorProtos.UninterpretedOption.Builder addUnint
            getUninterpretedOptionBuilderList() {
         return getUninterpretedOptionFieldBuilder().getBuilderList();
       }
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.UninterpretedOption, com.google.protobuf.DescriptorProtos.UninterpretedOption.Builder, com.google.protobuf.DescriptorProtos.UninterpretedOptionOrBuilder> 
+      private RepeatedFieldBuilderV3Internal<
+                UninterpretedOption, UninterpretedOption.Builder, UninterpretedOptionOrBuilder>
           getUninterpretedOptionFieldBuilder() {
         if (uninterpretedOptionBuilder_ == null) {
-          uninterpretedOptionBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.UninterpretedOption, com.google.protobuf.DescriptorProtos.UninterpretedOption.Builder, com.google.protobuf.DescriptorProtos.UninterpretedOptionOrBuilder>(
+          uninterpretedOptionBuilder_ = new RepeatedFieldBuilderV3Internal<
+                        UninterpretedOption, UninterpretedOption.Builder, UninterpretedOptionOrBuilder>(
                   uninterpretedOption_,
                   ((bitField0_ & 0x00000001) != 0),
                   getParentForChildren(),
@@ -13488,8 +13488,8 @@ private void ensureDeclarationIsMutable() {
          }
       }
 
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.ExtensionRangeOptions.Declaration, com.google.protobuf.DescriptorProtos.ExtensionRangeOptions.Declaration.Builder, com.google.protobuf.DescriptorProtos.ExtensionRangeOptions.DeclarationOrBuilder> declarationBuilder_;
+      private RepeatedFieldBuilderV3Internal<
+                Declaration, Declaration.Builder, DeclarationOrBuilder> declarationBuilder_;
 
       /**
        * 
@@ -13812,12 +13812,12 @@ public com.google.protobuf.DescriptorProtos.ExtensionRangeOptions.Declaration.Bu
            getDeclarationBuilderList() {
         return getDeclarationFieldBuilder().getBuilderList();
       }
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.ExtensionRangeOptions.Declaration, com.google.protobuf.DescriptorProtos.ExtensionRangeOptions.Declaration.Builder, com.google.protobuf.DescriptorProtos.ExtensionRangeOptions.DeclarationOrBuilder> 
+      private RepeatedFieldBuilderV3Internal<
+                Declaration, Declaration.Builder, DeclarationOrBuilder>
           getDeclarationFieldBuilder() {
         if (declarationBuilder_ == null) {
-          declarationBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.ExtensionRangeOptions.Declaration, com.google.protobuf.DescriptorProtos.ExtensionRangeOptions.Declaration.Builder, com.google.protobuf.DescriptorProtos.ExtensionRangeOptions.DeclarationOrBuilder>(
+          declarationBuilder_ = new RepeatedFieldBuilderV3Internal<
+                        Declaration, Declaration.Builder, DeclarationOrBuilder>(
                   declaration_,
                   ((bitField0_ & 0x00000002) != 0),
                   getParentForChildren(),
@@ -13828,8 +13828,8 @@ public com.google.protobuf.DescriptorProtos.ExtensionRangeOptions.Declaration.Bu
       }
 
       private com.google.protobuf.DescriptorProtos.FeatureSet features_;
-      private com.google.protobuf.SingleFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.FeatureSet, com.google.protobuf.DescriptorProtos.FeatureSet.Builder, com.google.protobuf.DescriptorProtos.FeatureSetOrBuilder> featuresBuilder_;
+      private SingleFieldBuilderV3Internal<
+                FeatureSet, FeatureSet.Builder, FeatureSetOrBuilder> featuresBuilder_;
       /**
        * 
        * Any features defined in the specific edition.
@@ -13970,12 +13970,12 @@ public com.google.protobuf.DescriptorProtos.FeatureSetOrBuilder getFeaturesOrBui
        *
        * optional .google.protobuf.FeatureSet features = 50;
        */
-      private com.google.protobuf.SingleFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.FeatureSet, com.google.protobuf.DescriptorProtos.FeatureSet.Builder, com.google.protobuf.DescriptorProtos.FeatureSetOrBuilder> 
+      private SingleFieldBuilderV3Internal<
+                FeatureSet, FeatureSet.Builder, FeatureSetOrBuilder>
           getFeaturesFieldBuilder() {
         if (featuresBuilder_ == null) {
-          featuresBuilder_ = new com.google.protobuf.SingleFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.FeatureSet, com.google.protobuf.DescriptorProtos.FeatureSet.Builder, com.google.protobuf.DescriptorProtos.FeatureSetOrBuilder>(
+          featuresBuilder_ = new SingleFieldBuilderV3Internal<
+                        FeatureSet, FeatureSet.Builder, FeatureSetOrBuilder>(
                   getFeatures(),
                   getParentForChildren(),
                   isClean());
@@ -16861,8 +16861,8 @@ public Builder setJsonNameBytes(
       }
 
       private com.google.protobuf.DescriptorProtos.FieldOptions options_;
-      private com.google.protobuf.SingleFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.FieldOptions, com.google.protobuf.DescriptorProtos.FieldOptions.Builder, com.google.protobuf.DescriptorProtos.FieldOptionsOrBuilder> optionsBuilder_;
+      private SingleFieldBuilderV3Internal<
+                FieldOptions, FieldOptions.Builder, FieldOptionsOrBuilder> optionsBuilder_;
       /**
        * optional .google.protobuf.FieldOptions options = 8;
        * @return Whether the options field is set.
@@ -16967,12 +16967,12 @@ public com.google.protobuf.DescriptorProtos.FieldOptionsOrBuilder getOptionsOrBu
       /**
        * optional .google.protobuf.FieldOptions options = 8;
        */
-      private com.google.protobuf.SingleFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.FieldOptions, com.google.protobuf.DescriptorProtos.FieldOptions.Builder, com.google.protobuf.DescriptorProtos.FieldOptionsOrBuilder> 
+      private SingleFieldBuilderV3Internal<
+                FieldOptions, FieldOptions.Builder, FieldOptionsOrBuilder>
           getOptionsFieldBuilder() {
         if (optionsBuilder_ == null) {
-          optionsBuilder_ = new com.google.protobuf.SingleFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.FieldOptions, com.google.protobuf.DescriptorProtos.FieldOptions.Builder, com.google.protobuf.DescriptorProtos.FieldOptionsOrBuilder>(
+          optionsBuilder_ = new SingleFieldBuilderV3Internal<
+                        FieldOptions, FieldOptions.Builder, FieldOptionsOrBuilder>(
                   getOptions(),
                   getParentForChildren(),
                   isClean());
@@ -17805,8 +17805,8 @@ public Builder setNameBytes(
       }
 
       private com.google.protobuf.DescriptorProtos.OneofOptions options_;
-      private com.google.protobuf.SingleFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.OneofOptions, com.google.protobuf.DescriptorProtos.OneofOptions.Builder, com.google.protobuf.DescriptorProtos.OneofOptionsOrBuilder> optionsBuilder_;
+      private SingleFieldBuilderV3Internal<
+                OneofOptions, OneofOptions.Builder, OneofOptionsOrBuilder> optionsBuilder_;
       /**
        * optional .google.protobuf.OneofOptions options = 2;
        * @return Whether the options field is set.
@@ -17911,12 +17911,12 @@ public com.google.protobuf.DescriptorProtos.OneofOptionsOrBuilder getOptionsOrBu
       /**
        * optional .google.protobuf.OneofOptions options = 2;
        */
-      private com.google.protobuf.SingleFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.OneofOptions, com.google.protobuf.DescriptorProtos.OneofOptions.Builder, com.google.protobuf.DescriptorProtos.OneofOptionsOrBuilder> 
+      private SingleFieldBuilderV3Internal<
+                OneofOptions, OneofOptions.Builder, OneofOptionsOrBuilder>
           getOptionsFieldBuilder() {
         if (optionsBuilder_ == null) {
-          optionsBuilder_ = new com.google.protobuf.SingleFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.OneofOptions, com.google.protobuf.DescriptorProtos.OneofOptions.Builder, com.google.protobuf.DescriptorProtos.OneofOptionsOrBuilder>(
+          optionsBuilder_ = new SingleFieldBuilderV3Internal<
+                        OneofOptions, OneofOptions.Builder, OneofOptionsOrBuilder>(
                   getOptions(),
                   getParentForChildren(),
                   isClean());
@@ -19796,8 +19796,8 @@ private void ensureValueIsMutable() {
          }
       }
 
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.EnumValueDescriptorProto, com.google.protobuf.DescriptorProtos.EnumValueDescriptorProto.Builder, com.google.protobuf.DescriptorProtos.EnumValueDescriptorProtoOrBuilder> valueBuilder_;
+      private RepeatedFieldBuilderV3Internal<
+                EnumValueDescriptorProto, EnumValueDescriptorProto.Builder, EnumValueDescriptorProtoOrBuilder> valueBuilder_;
 
       /**
        * repeated .google.protobuf.EnumValueDescriptorProto value = 2;
@@ -20012,12 +20012,12 @@ public com.google.protobuf.DescriptorProtos.EnumValueDescriptorProto.Builder add
            getValueBuilderList() {
         return getValueFieldBuilder().getBuilderList();
       }
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.EnumValueDescriptorProto, com.google.protobuf.DescriptorProtos.EnumValueDescriptorProto.Builder, com.google.protobuf.DescriptorProtos.EnumValueDescriptorProtoOrBuilder> 
+      private RepeatedFieldBuilderV3Internal<
+                EnumValueDescriptorProto, EnumValueDescriptorProto.Builder, EnumValueDescriptorProtoOrBuilder>
           getValueFieldBuilder() {
         if (valueBuilder_ == null) {
-          valueBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.EnumValueDescriptorProto, com.google.protobuf.DescriptorProtos.EnumValueDescriptorProto.Builder, com.google.protobuf.DescriptorProtos.EnumValueDescriptorProtoOrBuilder>(
+          valueBuilder_ = new RepeatedFieldBuilderV3Internal<
+                        EnumValueDescriptorProto, EnumValueDescriptorProto.Builder, EnumValueDescriptorProtoOrBuilder>(
                   value_,
                   ((bitField0_ & 0x00000002) != 0),
                   getParentForChildren(),
@@ -20028,8 +20028,8 @@ public com.google.protobuf.DescriptorProtos.EnumValueDescriptorProto.Builder add
       }
 
       private com.google.protobuf.DescriptorProtos.EnumOptions options_;
-      private com.google.protobuf.SingleFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.EnumOptions, com.google.protobuf.DescriptorProtos.EnumOptions.Builder, com.google.protobuf.DescriptorProtos.EnumOptionsOrBuilder> optionsBuilder_;
+      private SingleFieldBuilderV3Internal<
+                EnumOptions, EnumOptions.Builder, EnumOptionsOrBuilder> optionsBuilder_;
       /**
        * optional .google.protobuf.EnumOptions options = 3;
        * @return Whether the options field is set.
@@ -20134,12 +20134,12 @@ public com.google.protobuf.DescriptorProtos.EnumOptionsOrBuilder getOptionsOrBui
       /**
        * optional .google.protobuf.EnumOptions options = 3;
        */
-      private com.google.protobuf.SingleFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.EnumOptions, com.google.protobuf.DescriptorProtos.EnumOptions.Builder, com.google.protobuf.DescriptorProtos.EnumOptionsOrBuilder> 
+      private SingleFieldBuilderV3Internal<
+                EnumOptions, EnumOptions.Builder, EnumOptionsOrBuilder>
           getOptionsFieldBuilder() {
         if (optionsBuilder_ == null) {
-          optionsBuilder_ = new com.google.protobuf.SingleFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.EnumOptions, com.google.protobuf.DescriptorProtos.EnumOptions.Builder, com.google.protobuf.DescriptorProtos.EnumOptionsOrBuilder>(
+          optionsBuilder_ = new SingleFieldBuilderV3Internal<
+                        EnumOptions, EnumOptions.Builder, EnumOptionsOrBuilder>(
                   getOptions(),
                   getParentForChildren(),
                   isClean());
@@ -20157,8 +20157,8 @@ private void ensureReservedRangeIsMutable() {
          }
       }
 
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.EnumDescriptorProto.EnumReservedRange, com.google.protobuf.DescriptorProtos.EnumDescriptorProto.EnumReservedRange.Builder, com.google.protobuf.DescriptorProtos.EnumDescriptorProto.EnumReservedRangeOrBuilder> reservedRangeBuilder_;
+      private RepeatedFieldBuilderV3Internal<
+                EnumReservedRange, EnumReservedRange.Builder, EnumReservedRangeOrBuilder> reservedRangeBuilder_;
 
       /**
        * 
@@ -20481,12 +20481,12 @@ public com.google.protobuf.DescriptorProtos.EnumDescriptorProto.EnumReservedRang
            getReservedRangeBuilderList() {
         return getReservedRangeFieldBuilder().getBuilderList();
       }
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.EnumDescriptorProto.EnumReservedRange, com.google.protobuf.DescriptorProtos.EnumDescriptorProto.EnumReservedRange.Builder, com.google.protobuf.DescriptorProtos.EnumDescriptorProto.EnumReservedRangeOrBuilder> 
+      private RepeatedFieldBuilderV3Internal<
+                EnumReservedRange, EnumReservedRange.Builder, EnumReservedRangeOrBuilder>
           getReservedRangeFieldBuilder() {
         if (reservedRangeBuilder_ == null) {
-          reservedRangeBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.EnumDescriptorProto.EnumReservedRange, com.google.protobuf.DescriptorProtos.EnumDescriptorProto.EnumReservedRange.Builder, com.google.protobuf.DescriptorProtos.EnumDescriptorProto.EnumReservedRangeOrBuilder>(
+          reservedRangeBuilder_ = new RepeatedFieldBuilderV3Internal<
+                        EnumReservedRange, EnumReservedRange.Builder, EnumReservedRangeOrBuilder>(
                   reservedRange_,
                   ((bitField0_ & 0x00000008) != 0),
                   getParentForChildren(),
@@ -21438,8 +21438,8 @@ public Builder clearNumber() {
       }
 
       private com.google.protobuf.DescriptorProtos.EnumValueOptions options_;
-      private com.google.protobuf.SingleFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.EnumValueOptions, com.google.protobuf.DescriptorProtos.EnumValueOptions.Builder, com.google.protobuf.DescriptorProtos.EnumValueOptionsOrBuilder> optionsBuilder_;
+      private SingleFieldBuilderV3Internal<
+                EnumValueOptions, EnumValueOptions.Builder, EnumValueOptionsOrBuilder> optionsBuilder_;
       /**
        * optional .google.protobuf.EnumValueOptions options = 3;
        * @return Whether the options field is set.
@@ -21544,12 +21544,12 @@ public com.google.protobuf.DescriptorProtos.EnumValueOptionsOrBuilder getOptions
       /**
        * optional .google.protobuf.EnumValueOptions options = 3;
        */
-      private com.google.protobuf.SingleFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.EnumValueOptions, com.google.protobuf.DescriptorProtos.EnumValueOptions.Builder, com.google.protobuf.DescriptorProtos.EnumValueOptionsOrBuilder> 
+      private SingleFieldBuilderV3Internal<
+                EnumValueOptions, EnumValueOptions.Builder, EnumValueOptionsOrBuilder>
           getOptionsFieldBuilder() {
         if (optionsBuilder_ == null) {
-          optionsBuilder_ = new com.google.protobuf.SingleFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.EnumValueOptions, com.google.protobuf.DescriptorProtos.EnumValueOptions.Builder, com.google.protobuf.DescriptorProtos.EnumValueOptionsOrBuilder>(
+          optionsBuilder_ = new SingleFieldBuilderV3Internal<
+                        EnumValueOptions, EnumValueOptions.Builder, EnumValueOptionsOrBuilder>(
                   getOptions(),
                   getParentForChildren(),
                   isClean());
@@ -22404,8 +22404,8 @@ private void ensureMethodIsMutable() {
          }
       }
 
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.MethodDescriptorProto, com.google.protobuf.DescriptorProtos.MethodDescriptorProto.Builder, com.google.protobuf.DescriptorProtos.MethodDescriptorProtoOrBuilder> methodBuilder_;
+      private RepeatedFieldBuilderV3Internal<
+                MethodDescriptorProto, MethodDescriptorProto.Builder, MethodDescriptorProtoOrBuilder> methodBuilder_;
 
       /**
        * repeated .google.protobuf.MethodDescriptorProto method = 2;
@@ -22620,12 +22620,12 @@ public com.google.protobuf.DescriptorProtos.MethodDescriptorProto.Builder addMet
            getMethodBuilderList() {
         return getMethodFieldBuilder().getBuilderList();
       }
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.MethodDescriptorProto, com.google.protobuf.DescriptorProtos.MethodDescriptorProto.Builder, com.google.protobuf.DescriptorProtos.MethodDescriptorProtoOrBuilder> 
+      private RepeatedFieldBuilderV3Internal<
+                MethodDescriptorProto, MethodDescriptorProto.Builder, MethodDescriptorProtoOrBuilder>
           getMethodFieldBuilder() {
         if (methodBuilder_ == null) {
-          methodBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.MethodDescriptorProto, com.google.protobuf.DescriptorProtos.MethodDescriptorProto.Builder, com.google.protobuf.DescriptorProtos.MethodDescriptorProtoOrBuilder>(
+          methodBuilder_ = new RepeatedFieldBuilderV3Internal<
+                        MethodDescriptorProto, MethodDescriptorProto.Builder, MethodDescriptorProtoOrBuilder>(
                   method_,
                   ((bitField0_ & 0x00000002) != 0),
                   getParentForChildren(),
@@ -22636,8 +22636,8 @@ public com.google.protobuf.DescriptorProtos.MethodDescriptorProto.Builder addMet
       }
 
       private com.google.protobuf.DescriptorProtos.ServiceOptions options_;
-      private com.google.protobuf.SingleFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.ServiceOptions, com.google.protobuf.DescriptorProtos.ServiceOptions.Builder, com.google.protobuf.DescriptorProtos.ServiceOptionsOrBuilder> optionsBuilder_;
+      private SingleFieldBuilderV3Internal<
+                ServiceOptions, ServiceOptions.Builder, ServiceOptionsOrBuilder> optionsBuilder_;
       /**
        * optional .google.protobuf.ServiceOptions options = 3;
        * @return Whether the options field is set.
@@ -22742,12 +22742,12 @@ public com.google.protobuf.DescriptorProtos.ServiceOptionsOrBuilder getOptionsOr
       /**
        * optional .google.protobuf.ServiceOptions options = 3;
        */
-      private com.google.protobuf.SingleFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.ServiceOptions, com.google.protobuf.DescriptorProtos.ServiceOptions.Builder, com.google.protobuf.DescriptorProtos.ServiceOptionsOrBuilder> 
+      private SingleFieldBuilderV3Internal<
+                ServiceOptions, ServiceOptions.Builder, ServiceOptionsOrBuilder>
           getOptionsFieldBuilder() {
         if (optionsBuilder_ == null) {
-          optionsBuilder_ = new com.google.protobuf.SingleFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.ServiceOptions, com.google.protobuf.DescriptorProtos.ServiceOptions.Builder, com.google.protobuf.DescriptorProtos.ServiceOptionsOrBuilder>(
+          optionsBuilder_ = new SingleFieldBuilderV3Internal<
+                        ServiceOptions, ServiceOptions.Builder, ServiceOptionsOrBuilder>(
                   getOptions(),
                   getParentForChildren(),
                   isClean());
@@ -24010,8 +24010,8 @@ public Builder setOutputTypeBytes(
       }
 
       private com.google.protobuf.DescriptorProtos.MethodOptions options_;
-      private com.google.protobuf.SingleFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.MethodOptions, com.google.protobuf.DescriptorProtos.MethodOptions.Builder, com.google.protobuf.DescriptorProtos.MethodOptionsOrBuilder> optionsBuilder_;
+      private SingleFieldBuilderV3Internal<
+                MethodOptions, MethodOptions.Builder, MethodOptionsOrBuilder> optionsBuilder_;
       /**
        * optional .google.protobuf.MethodOptions options = 4;
        * @return Whether the options field is set.
@@ -24116,12 +24116,12 @@ public com.google.protobuf.DescriptorProtos.MethodOptionsOrBuilder getOptionsOrB
       /**
        * optional .google.protobuf.MethodOptions options = 4;
        */
-      private com.google.protobuf.SingleFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.MethodOptions, com.google.protobuf.DescriptorProtos.MethodOptions.Builder, com.google.protobuf.DescriptorProtos.MethodOptionsOrBuilder> 
+      private SingleFieldBuilderV3Internal<
+                MethodOptions, MethodOptions.Builder, MethodOptionsOrBuilder>
           getOptionsFieldBuilder() {
         if (optionsBuilder_ == null) {
-          optionsBuilder_ = new com.google.protobuf.SingleFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.MethodOptions, com.google.protobuf.DescriptorProtos.MethodOptions.Builder, com.google.protobuf.DescriptorProtos.MethodOptionsOrBuilder>(
+          optionsBuilder_ = new SingleFieldBuilderV3Internal<
+                        MethodOptions, MethodOptions.Builder, MethodOptionsOrBuilder>(
                   getOptions(),
                   getParentForChildren(),
                   isClean());
@@ -29012,8 +29012,8 @@ public Builder setRubyPackageBytes(
       }
 
       private com.google.protobuf.DescriptorProtos.FeatureSet features_;
-      private com.google.protobuf.SingleFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.FeatureSet, com.google.protobuf.DescriptorProtos.FeatureSet.Builder, com.google.protobuf.DescriptorProtos.FeatureSetOrBuilder> featuresBuilder_;
+      private SingleFieldBuilderV3Internal<
+                FeatureSet, FeatureSet.Builder, FeatureSetOrBuilder> featuresBuilder_;
       /**
        * 
        * Any features defined in the specific edition.
@@ -29181,12 +29181,12 @@ public com.google.protobuf.DescriptorProtos.FeatureSetOrBuilder getFeaturesOrBui
        *
        * optional .google.protobuf.FeatureSet features = 50;
        */
-      private com.google.protobuf.SingleFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.FeatureSet, com.google.protobuf.DescriptorProtos.FeatureSet.Builder, com.google.protobuf.DescriptorProtos.FeatureSetOrBuilder> 
+      private SingleFieldBuilderV3Internal<
+                FeatureSet, FeatureSet.Builder, FeatureSetOrBuilder>
           getFeaturesFieldBuilder() {
         if (featuresBuilder_ == null) {
-          featuresBuilder_ = new com.google.protobuf.SingleFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.FeatureSet, com.google.protobuf.DescriptorProtos.FeatureSet.Builder, com.google.protobuf.DescriptorProtos.FeatureSetOrBuilder>(
+          featuresBuilder_ = new SingleFieldBuilderV3Internal<
+                        FeatureSet, FeatureSet.Builder, FeatureSetOrBuilder>(
                   getFeatures(),
                   getParentForChildren(),
                   isClean());
@@ -29204,8 +29204,8 @@ private void ensureUninterpretedOptionIsMutable() {
          }
       }
 
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.UninterpretedOption, com.google.protobuf.DescriptorProtos.UninterpretedOption.Builder, com.google.protobuf.DescriptorProtos.UninterpretedOptionOrBuilder> uninterpretedOptionBuilder_;
+      private RepeatedFieldBuilderV3Internal<
+                UninterpretedOption, UninterpretedOption.Builder, UninterpretedOptionOrBuilder> uninterpretedOptionBuilder_;
 
       /**
        * 
@@ -29510,12 +29510,12 @@ public com.google.protobuf.DescriptorProtos.UninterpretedOption.Builder addUnint
            getUninterpretedOptionBuilderList() {
         return getUninterpretedOptionFieldBuilder().getBuilderList();
       }
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.UninterpretedOption, com.google.protobuf.DescriptorProtos.UninterpretedOption.Builder, com.google.protobuf.DescriptorProtos.UninterpretedOptionOrBuilder> 
+      private RepeatedFieldBuilderV3Internal<
+                UninterpretedOption, UninterpretedOption.Builder, UninterpretedOptionOrBuilder>
           getUninterpretedOptionFieldBuilder() {
         if (uninterpretedOptionBuilder_ == null) {
-          uninterpretedOptionBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.UninterpretedOption, com.google.protobuf.DescriptorProtos.UninterpretedOption.Builder, com.google.protobuf.DescriptorProtos.UninterpretedOptionOrBuilder>(
+          uninterpretedOptionBuilder_ = new RepeatedFieldBuilderV3Internal<
+                        UninterpretedOption, UninterpretedOption.Builder, UninterpretedOptionOrBuilder>(
                   uninterpretedOption_,
                   ((bitField0_ & 0x00100000) != 0),
                   getParentForChildren(),
@@ -31390,8 +31390,8 @@ public Builder clearMapEntry() {
       }
 
       private com.google.protobuf.DescriptorProtos.FeatureSet features_;
-      private com.google.protobuf.SingleFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.FeatureSet, com.google.protobuf.DescriptorProtos.FeatureSet.Builder, com.google.protobuf.DescriptorProtos.FeatureSetOrBuilder> featuresBuilder_;
+      private SingleFieldBuilderV3Internal<
+                FeatureSet, FeatureSet.Builder, FeatureSetOrBuilder> featuresBuilder_;
       /**
        * 
        * Any features defined in the specific edition.
@@ -31559,12 +31559,12 @@ public com.google.protobuf.DescriptorProtos.FeatureSetOrBuilder getFeaturesOrBui
        *
        * optional .google.protobuf.FeatureSet features = 12;
        */
-      private com.google.protobuf.SingleFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.FeatureSet, com.google.protobuf.DescriptorProtos.FeatureSet.Builder, com.google.protobuf.DescriptorProtos.FeatureSetOrBuilder> 
+      private SingleFieldBuilderV3Internal<
+                FeatureSet, FeatureSet.Builder, FeatureSetOrBuilder>
           getFeaturesFieldBuilder() {
         if (featuresBuilder_ == null) {
-          featuresBuilder_ = new com.google.protobuf.SingleFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.FeatureSet, com.google.protobuf.DescriptorProtos.FeatureSet.Builder, com.google.protobuf.DescriptorProtos.FeatureSetOrBuilder>(
+          featuresBuilder_ = new SingleFieldBuilderV3Internal<
+                        FeatureSet, FeatureSet.Builder, FeatureSetOrBuilder>(
                   getFeatures(),
                   getParentForChildren(),
                   isClean());
@@ -31582,8 +31582,8 @@ private void ensureUninterpretedOptionIsMutable() {
          }
       }
 
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.UninterpretedOption, com.google.protobuf.DescriptorProtos.UninterpretedOption.Builder, com.google.protobuf.DescriptorProtos.UninterpretedOptionOrBuilder> uninterpretedOptionBuilder_;
+      private RepeatedFieldBuilderV3Internal<
+                UninterpretedOption, UninterpretedOption.Builder, UninterpretedOptionOrBuilder> uninterpretedOptionBuilder_;
 
       /**
        * 
@@ -31870,12 +31870,12 @@ public com.google.protobuf.DescriptorProtos.UninterpretedOption.Builder addUnint
            getUninterpretedOptionBuilderList() {
         return getUninterpretedOptionFieldBuilder().getBuilderList();
       }
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.UninterpretedOption, com.google.protobuf.DescriptorProtos.UninterpretedOption.Builder, com.google.protobuf.DescriptorProtos.UninterpretedOptionOrBuilder> 
+      private RepeatedFieldBuilderV3Internal<
+                UninterpretedOption, UninterpretedOption.Builder, UninterpretedOptionOrBuilder>
           getUninterpretedOptionFieldBuilder() {
         if (uninterpretedOptionBuilder_ == null) {
-          uninterpretedOptionBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.UninterpretedOption, com.google.protobuf.DescriptorProtos.UninterpretedOption.Builder, com.google.protobuf.DescriptorProtos.UninterpretedOptionOrBuilder>(
+          uninterpretedOptionBuilder_ = new RepeatedFieldBuilderV3Internal<
+                        UninterpretedOption, UninterpretedOption.Builder, UninterpretedOptionOrBuilder>(
                   uninterpretedOption_,
                   ((bitField0_ & 0x00000040) != 0),
                   getParentForChildren(),
@@ -37054,8 +37054,8 @@ private void ensureEditionDefaultsIsMutable() {
          }
       }
 
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.FieldOptions.EditionDefault, com.google.protobuf.DescriptorProtos.FieldOptions.EditionDefault.Builder, com.google.protobuf.DescriptorProtos.FieldOptions.EditionDefaultOrBuilder> editionDefaultsBuilder_;
+      private RepeatedFieldBuilderV3Internal<
+                EditionDefault, EditionDefault.Builder, EditionDefaultOrBuilder> editionDefaultsBuilder_;
 
       /**
        * repeated .google.protobuf.FieldOptions.EditionDefault edition_defaults = 20;
@@ -37270,12 +37270,12 @@ public com.google.protobuf.DescriptorProtos.FieldOptions.EditionDefault.Builder
            getEditionDefaultsBuilderList() {
         return getEditionDefaultsFieldBuilder().getBuilderList();
       }
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.FieldOptions.EditionDefault, com.google.protobuf.DescriptorProtos.FieldOptions.EditionDefault.Builder, com.google.protobuf.DescriptorProtos.FieldOptions.EditionDefaultOrBuilder> 
+      private RepeatedFieldBuilderV3Internal<
+                EditionDefault, EditionDefault.Builder, EditionDefaultOrBuilder>
           getEditionDefaultsFieldBuilder() {
         if (editionDefaultsBuilder_ == null) {
-          editionDefaultsBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.FieldOptions.EditionDefault, com.google.protobuf.DescriptorProtos.FieldOptions.EditionDefault.Builder, com.google.protobuf.DescriptorProtos.FieldOptions.EditionDefaultOrBuilder>(
+          editionDefaultsBuilder_ = new RepeatedFieldBuilderV3Internal<
+                        EditionDefault, EditionDefault.Builder, EditionDefaultOrBuilder>(
                   editionDefaults_,
                   ((bitField0_ & 0x00000400) != 0),
                   getParentForChildren(),
@@ -37286,8 +37286,8 @@ public com.google.protobuf.DescriptorProtos.FieldOptions.EditionDefault.Builder
       }
 
       private com.google.protobuf.DescriptorProtos.FeatureSet features_;
-      private com.google.protobuf.SingleFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.FeatureSet, com.google.protobuf.DescriptorProtos.FeatureSet.Builder, com.google.protobuf.DescriptorProtos.FeatureSetOrBuilder> featuresBuilder_;
+      private SingleFieldBuilderV3Internal<
+                FeatureSet, FeatureSet.Builder, FeatureSetOrBuilder> featuresBuilder_;
       /**
        * 
        * Any features defined in the specific edition.
@@ -37455,12 +37455,12 @@ public com.google.protobuf.DescriptorProtos.FeatureSetOrBuilder getFeaturesOrBui
        *
        * optional .google.protobuf.FeatureSet features = 21;
        */
-      private com.google.protobuf.SingleFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.FeatureSet, com.google.protobuf.DescriptorProtos.FeatureSet.Builder, com.google.protobuf.DescriptorProtos.FeatureSetOrBuilder> 
+      private SingleFieldBuilderV3Internal<
+                FeatureSet, FeatureSet.Builder, FeatureSetOrBuilder>
           getFeaturesFieldBuilder() {
         if (featuresBuilder_ == null) {
-          featuresBuilder_ = new com.google.protobuf.SingleFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.FeatureSet, com.google.protobuf.DescriptorProtos.FeatureSet.Builder, com.google.protobuf.DescriptorProtos.FeatureSetOrBuilder>(
+          featuresBuilder_ = new SingleFieldBuilderV3Internal<
+                        FeatureSet, FeatureSet.Builder, FeatureSetOrBuilder>(
                   getFeatures(),
                   getParentForChildren(),
                   isClean());
@@ -37470,8 +37470,8 @@ public com.google.protobuf.DescriptorProtos.FeatureSetOrBuilder getFeaturesOrBui
       }
 
       private com.google.protobuf.DescriptorProtos.FieldOptions.FeatureSupport featureSupport_;
-      private com.google.protobuf.SingleFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.FieldOptions.FeatureSupport, com.google.protobuf.DescriptorProtos.FieldOptions.FeatureSupport.Builder, com.google.protobuf.DescriptorProtos.FieldOptions.FeatureSupportOrBuilder> featureSupportBuilder_;
+      private SingleFieldBuilderV3Internal<
+                FeatureSupport, FeatureSupport.Builder, FeatureSupportOrBuilder> featureSupportBuilder_;
       /**
        * optional .google.protobuf.FieldOptions.FeatureSupport feature_support = 22;
        * @return Whether the featureSupport field is set.
@@ -37576,12 +37576,12 @@ public com.google.protobuf.DescriptorProtos.FieldOptions.FeatureSupportOrBuilder
       /**
        * optional .google.protobuf.FieldOptions.FeatureSupport feature_support = 22;
        */
-      private com.google.protobuf.SingleFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.FieldOptions.FeatureSupport, com.google.protobuf.DescriptorProtos.FieldOptions.FeatureSupport.Builder, com.google.protobuf.DescriptorProtos.FieldOptions.FeatureSupportOrBuilder> 
+      private SingleFieldBuilderV3Internal<
+                FeatureSupport, FeatureSupport.Builder, FeatureSupportOrBuilder>
           getFeatureSupportFieldBuilder() {
         if (featureSupportBuilder_ == null) {
-          featureSupportBuilder_ = new com.google.protobuf.SingleFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.FieldOptions.FeatureSupport, com.google.protobuf.DescriptorProtos.FieldOptions.FeatureSupport.Builder, com.google.protobuf.DescriptorProtos.FieldOptions.FeatureSupportOrBuilder>(
+          featureSupportBuilder_ = new SingleFieldBuilderV3Internal<
+                        FeatureSupport, FeatureSupport.Builder, FeatureSupportOrBuilder>(
                   getFeatureSupport(),
                   getParentForChildren(),
                   isClean());
@@ -37599,8 +37599,8 @@ private void ensureUninterpretedOptionIsMutable() {
          }
       }
 
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.UninterpretedOption, com.google.protobuf.DescriptorProtos.UninterpretedOption.Builder, com.google.protobuf.DescriptorProtos.UninterpretedOptionOrBuilder> uninterpretedOptionBuilder_;
+      private RepeatedFieldBuilderV3Internal<
+                UninterpretedOption, UninterpretedOption.Builder, UninterpretedOptionOrBuilder> uninterpretedOptionBuilder_;
 
       /**
        * 
@@ -37887,12 +37887,12 @@ public com.google.protobuf.DescriptorProtos.UninterpretedOption.Builder addUnint
            getUninterpretedOptionBuilderList() {
         return getUninterpretedOptionFieldBuilder().getBuilderList();
       }
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.UninterpretedOption, com.google.protobuf.DescriptorProtos.UninterpretedOption.Builder, com.google.protobuf.DescriptorProtos.UninterpretedOptionOrBuilder> 
+      private RepeatedFieldBuilderV3Internal<
+                UninterpretedOption, UninterpretedOption.Builder, UninterpretedOptionOrBuilder>
           getUninterpretedOptionFieldBuilder() {
         if (uninterpretedOptionBuilder_ == null) {
-          uninterpretedOptionBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.UninterpretedOption, com.google.protobuf.DescriptorProtos.UninterpretedOption.Builder, com.google.protobuf.DescriptorProtos.UninterpretedOptionOrBuilder>(
+          uninterpretedOptionBuilder_ = new RepeatedFieldBuilderV3Internal<
+                        UninterpretedOption, UninterpretedOption.Builder, UninterpretedOptionOrBuilder>(
                   uninterpretedOption_,
                   ((bitField0_ & 0x00002000) != 0),
                   getParentForChildren(),
@@ -38683,8 +38683,8 @@ public Builder mergeFrom(
       private int bitField0_;
 
       private com.google.protobuf.DescriptorProtos.FeatureSet features_;
-      private com.google.protobuf.SingleFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.FeatureSet, com.google.protobuf.DescriptorProtos.FeatureSet.Builder, com.google.protobuf.DescriptorProtos.FeatureSetOrBuilder> featuresBuilder_;
+      private SingleFieldBuilderV3Internal<
+                FeatureSet, FeatureSet.Builder, FeatureSetOrBuilder> featuresBuilder_;
       /**
        * 
        * Any features defined in the specific edition.
@@ -38852,12 +38852,12 @@ public com.google.protobuf.DescriptorProtos.FeatureSetOrBuilder getFeaturesOrBui
        *
        * optional .google.protobuf.FeatureSet features = 1;
        */
-      private com.google.protobuf.SingleFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.FeatureSet, com.google.protobuf.DescriptorProtos.FeatureSet.Builder, com.google.protobuf.DescriptorProtos.FeatureSetOrBuilder> 
+      private SingleFieldBuilderV3Internal<
+                FeatureSet, FeatureSet.Builder, FeatureSetOrBuilder>
           getFeaturesFieldBuilder() {
         if (featuresBuilder_ == null) {
-          featuresBuilder_ = new com.google.protobuf.SingleFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.FeatureSet, com.google.protobuf.DescriptorProtos.FeatureSet.Builder, com.google.protobuf.DescriptorProtos.FeatureSetOrBuilder>(
+          featuresBuilder_ = new SingleFieldBuilderV3Internal<
+                        FeatureSet, FeatureSet.Builder, FeatureSetOrBuilder>(
                   getFeatures(),
                   getParentForChildren(),
                   isClean());
@@ -38875,8 +38875,8 @@ private void ensureUninterpretedOptionIsMutable() {
          }
       }
 
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.UninterpretedOption, com.google.protobuf.DescriptorProtos.UninterpretedOption.Builder, com.google.protobuf.DescriptorProtos.UninterpretedOptionOrBuilder> uninterpretedOptionBuilder_;
+      private RepeatedFieldBuilderV3Internal<
+                UninterpretedOption, UninterpretedOption.Builder, UninterpretedOptionOrBuilder> uninterpretedOptionBuilder_;
 
       /**
        * 
@@ -39163,12 +39163,12 @@ public com.google.protobuf.DescriptorProtos.UninterpretedOption.Builder addUnint
            getUninterpretedOptionBuilderList() {
         return getUninterpretedOptionFieldBuilder().getBuilderList();
       }
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.UninterpretedOption, com.google.protobuf.DescriptorProtos.UninterpretedOption.Builder, com.google.protobuf.DescriptorProtos.UninterpretedOptionOrBuilder> 
+      private RepeatedFieldBuilderV3Internal<
+                UninterpretedOption, UninterpretedOption.Builder, UninterpretedOptionOrBuilder>
           getUninterpretedOptionFieldBuilder() {
         if (uninterpretedOptionBuilder_ == null) {
-          uninterpretedOptionBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.UninterpretedOption, com.google.protobuf.DescriptorProtos.UninterpretedOption.Builder, com.google.protobuf.DescriptorProtos.UninterpretedOptionOrBuilder>(
+          uninterpretedOptionBuilder_ = new RepeatedFieldBuilderV3Internal<
+                        UninterpretedOption, UninterpretedOption.Builder, UninterpretedOptionOrBuilder>(
                   uninterpretedOption_,
                   ((bitField0_ & 0x00000002) != 0),
                   getParentForChildren(),
@@ -40443,8 +40443,8 @@ public Builder clearDeprecated() {
       }
 
       private com.google.protobuf.DescriptorProtos.FeatureSet features_;
-      private com.google.protobuf.SingleFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.FeatureSet, com.google.protobuf.DescriptorProtos.FeatureSet.Builder, com.google.protobuf.DescriptorProtos.FeatureSetOrBuilder> featuresBuilder_;
+      private SingleFieldBuilderV3Internal<
+                FeatureSet, FeatureSet.Builder, FeatureSetOrBuilder> featuresBuilder_;
       /**
        * 
        * Any features defined in the specific edition.
@@ -40612,12 +40612,12 @@ public com.google.protobuf.DescriptorProtos.FeatureSetOrBuilder getFeaturesOrBui
        *
        * optional .google.protobuf.FeatureSet features = 7;
        */
-      private com.google.protobuf.SingleFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.FeatureSet, com.google.protobuf.DescriptorProtos.FeatureSet.Builder, com.google.protobuf.DescriptorProtos.FeatureSetOrBuilder> 
+      private SingleFieldBuilderV3Internal<
+                FeatureSet, FeatureSet.Builder, FeatureSetOrBuilder>
           getFeaturesFieldBuilder() {
         if (featuresBuilder_ == null) {
-          featuresBuilder_ = new com.google.protobuf.SingleFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.FeatureSet, com.google.protobuf.DescriptorProtos.FeatureSet.Builder, com.google.protobuf.DescriptorProtos.FeatureSetOrBuilder>(
+          featuresBuilder_ = new SingleFieldBuilderV3Internal<
+                        FeatureSet, FeatureSet.Builder, FeatureSetOrBuilder>(
                   getFeatures(),
                   getParentForChildren(),
                   isClean());
@@ -40635,8 +40635,8 @@ private void ensureUninterpretedOptionIsMutable() {
          }
       }
 
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.UninterpretedOption, com.google.protobuf.DescriptorProtos.UninterpretedOption.Builder, com.google.protobuf.DescriptorProtos.UninterpretedOptionOrBuilder> uninterpretedOptionBuilder_;
+      private RepeatedFieldBuilderV3Internal<
+                UninterpretedOption, UninterpretedOption.Builder, UninterpretedOptionOrBuilder> uninterpretedOptionBuilder_;
 
       /**
        * 
@@ -40923,12 +40923,12 @@ public com.google.protobuf.DescriptorProtos.UninterpretedOption.Builder addUnint
            getUninterpretedOptionBuilderList() {
         return getUninterpretedOptionFieldBuilder().getBuilderList();
       }
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.UninterpretedOption, com.google.protobuf.DescriptorProtos.UninterpretedOption.Builder, com.google.protobuf.DescriptorProtos.UninterpretedOptionOrBuilder> 
+      private RepeatedFieldBuilderV3Internal<
+                UninterpretedOption, UninterpretedOption.Builder, UninterpretedOptionOrBuilder>
           getUninterpretedOptionFieldBuilder() {
         if (uninterpretedOptionBuilder_ == null) {
-          uninterpretedOptionBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.UninterpretedOption, com.google.protobuf.DescriptorProtos.UninterpretedOption.Builder, com.google.protobuf.DescriptorProtos.UninterpretedOptionOrBuilder>(
+          uninterpretedOptionBuilder_ = new RepeatedFieldBuilderV3Internal<
+                        UninterpretedOption, UninterpretedOption.Builder, UninterpretedOptionOrBuilder>(
                   uninterpretedOption_,
                   ((bitField0_ & 0x00000010) != 0),
                   getParentForChildren(),
@@ -42062,8 +42062,8 @@ public Builder clearDeprecated() {
       }
 
       private com.google.protobuf.DescriptorProtos.FeatureSet features_;
-      private com.google.protobuf.SingleFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.FeatureSet, com.google.protobuf.DescriptorProtos.FeatureSet.Builder, com.google.protobuf.DescriptorProtos.FeatureSetOrBuilder> featuresBuilder_;
+      private SingleFieldBuilderV3Internal<
+                FeatureSet, FeatureSet.Builder, FeatureSetOrBuilder> featuresBuilder_;
       /**
        * 
        * Any features defined in the specific edition.
@@ -42231,12 +42231,12 @@ public com.google.protobuf.DescriptorProtos.FeatureSetOrBuilder getFeaturesOrBui
        *
        * optional .google.protobuf.FeatureSet features = 2;
        */
-      private com.google.protobuf.SingleFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.FeatureSet, com.google.protobuf.DescriptorProtos.FeatureSet.Builder, com.google.protobuf.DescriptorProtos.FeatureSetOrBuilder> 
+      private SingleFieldBuilderV3Internal<
+                FeatureSet, FeatureSet.Builder, FeatureSetOrBuilder>
           getFeaturesFieldBuilder() {
         if (featuresBuilder_ == null) {
-          featuresBuilder_ = new com.google.protobuf.SingleFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.FeatureSet, com.google.protobuf.DescriptorProtos.FeatureSet.Builder, com.google.protobuf.DescriptorProtos.FeatureSetOrBuilder>(
+          featuresBuilder_ = new SingleFieldBuilderV3Internal<
+                        FeatureSet, FeatureSet.Builder, FeatureSetOrBuilder>(
                   getFeatures(),
                   getParentForChildren(),
                   isClean());
@@ -42310,8 +42310,8 @@ public Builder clearDebugRedact() {
       }
 
       private com.google.protobuf.DescriptorProtos.FieldOptions.FeatureSupport featureSupport_;
-      private com.google.protobuf.SingleFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.FieldOptions.FeatureSupport, com.google.protobuf.DescriptorProtos.FieldOptions.FeatureSupport.Builder, com.google.protobuf.DescriptorProtos.FieldOptions.FeatureSupportOrBuilder> featureSupportBuilder_;
+      private SingleFieldBuilderV3Internal<
+                FieldOptions.FeatureSupport, FieldOptions.FeatureSupport.Builder, FieldOptions.FeatureSupportOrBuilder> featureSupportBuilder_;
       /**
        * 
        * Information about the support window of a feature value.
@@ -42452,12 +42452,12 @@ public com.google.protobuf.DescriptorProtos.FieldOptions.FeatureSupportOrBuilder
        *
        * optional .google.protobuf.FieldOptions.FeatureSupport feature_support = 4;
        */
-      private com.google.protobuf.SingleFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.FieldOptions.FeatureSupport, com.google.protobuf.DescriptorProtos.FieldOptions.FeatureSupport.Builder, com.google.protobuf.DescriptorProtos.FieldOptions.FeatureSupportOrBuilder> 
+      private SingleFieldBuilderV3Internal<
+                FieldOptions.FeatureSupport, FieldOptions.FeatureSupport.Builder, FieldOptions.FeatureSupportOrBuilder>
           getFeatureSupportFieldBuilder() {
         if (featureSupportBuilder_ == null) {
-          featureSupportBuilder_ = new com.google.protobuf.SingleFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.FieldOptions.FeatureSupport, com.google.protobuf.DescriptorProtos.FieldOptions.FeatureSupport.Builder, com.google.protobuf.DescriptorProtos.FieldOptions.FeatureSupportOrBuilder>(
+          featureSupportBuilder_ = new SingleFieldBuilderV3Internal<
+                        FieldOptions.FeatureSupport, FieldOptions.FeatureSupport.Builder, FieldOptions.FeatureSupportOrBuilder>(
                   getFeatureSupport(),
                   getParentForChildren(),
                   isClean());
@@ -42475,8 +42475,8 @@ private void ensureUninterpretedOptionIsMutable() {
          }
       }
 
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.UninterpretedOption, com.google.protobuf.DescriptorProtos.UninterpretedOption.Builder, com.google.protobuf.DescriptorProtos.UninterpretedOptionOrBuilder> uninterpretedOptionBuilder_;
+      private RepeatedFieldBuilderV3Internal<
+                UninterpretedOption, UninterpretedOption.Builder, UninterpretedOptionOrBuilder> uninterpretedOptionBuilder_;
 
       /**
        * 
@@ -42763,12 +42763,12 @@ public com.google.protobuf.DescriptorProtos.UninterpretedOption.Builder addUnint
            getUninterpretedOptionBuilderList() {
         return getUninterpretedOptionFieldBuilder().getBuilderList();
       }
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.UninterpretedOption, com.google.protobuf.DescriptorProtos.UninterpretedOption.Builder, com.google.protobuf.DescriptorProtos.UninterpretedOptionOrBuilder> 
+      private RepeatedFieldBuilderV3Internal<
+                UninterpretedOption, UninterpretedOption.Builder, UninterpretedOptionOrBuilder>
           getUninterpretedOptionFieldBuilder() {
         if (uninterpretedOptionBuilder_ == null) {
-          uninterpretedOptionBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.UninterpretedOption, com.google.protobuf.DescriptorProtos.UninterpretedOption.Builder, com.google.protobuf.DescriptorProtos.UninterpretedOptionOrBuilder>(
+          uninterpretedOptionBuilder_ = new RepeatedFieldBuilderV3Internal<
+                        UninterpretedOption, UninterpretedOption.Builder, UninterpretedOptionOrBuilder>(
                   uninterpretedOption_,
                   ((bitField0_ & 0x00000010) != 0),
                   getParentForChildren(),
@@ -43647,8 +43647,8 @@ public Builder mergeFrom(
       private int bitField0_;
 
       private com.google.protobuf.DescriptorProtos.FeatureSet features_;
-      private com.google.protobuf.SingleFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.FeatureSet, com.google.protobuf.DescriptorProtos.FeatureSet.Builder, com.google.protobuf.DescriptorProtos.FeatureSetOrBuilder> featuresBuilder_;
+      private SingleFieldBuilderV3Internal<
+                FeatureSet, FeatureSet.Builder, FeatureSetOrBuilder> featuresBuilder_;
       /**
        * 
        * Any features defined in the specific edition.
@@ -43816,12 +43816,12 @@ public com.google.protobuf.DescriptorProtos.FeatureSetOrBuilder getFeaturesOrBui
        *
        * optional .google.protobuf.FeatureSet features = 34;
        */
-      private com.google.protobuf.SingleFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.FeatureSet, com.google.protobuf.DescriptorProtos.FeatureSet.Builder, com.google.protobuf.DescriptorProtos.FeatureSetOrBuilder> 
+      private SingleFieldBuilderV3Internal<
+                FeatureSet, FeatureSet.Builder, FeatureSetOrBuilder>
           getFeaturesFieldBuilder() {
         if (featuresBuilder_ == null) {
-          featuresBuilder_ = new com.google.protobuf.SingleFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.FeatureSet, com.google.protobuf.DescriptorProtos.FeatureSet.Builder, com.google.protobuf.DescriptorProtos.FeatureSetOrBuilder>(
+          featuresBuilder_ = new SingleFieldBuilderV3Internal<
+                        FeatureSet, FeatureSet.Builder, FeatureSetOrBuilder>(
                   getFeatures(),
                   getParentForChildren(),
                   isClean());
@@ -43907,8 +43907,8 @@ private void ensureUninterpretedOptionIsMutable() {
          }
       }
 
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.UninterpretedOption, com.google.protobuf.DescriptorProtos.UninterpretedOption.Builder, com.google.protobuf.DescriptorProtos.UninterpretedOptionOrBuilder> uninterpretedOptionBuilder_;
+      private RepeatedFieldBuilderV3Internal<
+                UninterpretedOption, UninterpretedOption.Builder, UninterpretedOptionOrBuilder> uninterpretedOptionBuilder_;
 
       /**
        * 
@@ -44195,12 +44195,12 @@ public com.google.protobuf.DescriptorProtos.UninterpretedOption.Builder addUnint
            getUninterpretedOptionBuilderList() {
         return getUninterpretedOptionFieldBuilder().getBuilderList();
       }
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.UninterpretedOption, com.google.protobuf.DescriptorProtos.UninterpretedOption.Builder, com.google.protobuf.DescriptorProtos.UninterpretedOptionOrBuilder> 
+      private RepeatedFieldBuilderV3Internal<
+                UninterpretedOption, UninterpretedOption.Builder, UninterpretedOptionOrBuilder>
           getUninterpretedOptionFieldBuilder() {
         if (uninterpretedOptionBuilder_ == null) {
-          uninterpretedOptionBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.UninterpretedOption, com.google.protobuf.DescriptorProtos.UninterpretedOption.Builder, com.google.protobuf.DescriptorProtos.UninterpretedOptionOrBuilder>(
+          uninterpretedOptionBuilder_ = new RepeatedFieldBuilderV3Internal<
+                        UninterpretedOption, UninterpretedOption.Builder, UninterpretedOptionOrBuilder>(
                   uninterpretedOption_,
                   ((bitField0_ & 0x00000004) != 0),
                   getParentForChildren(),
@@ -45381,8 +45381,8 @@ public Builder clearIdempotencyLevel() {
       }
 
       private com.google.protobuf.DescriptorProtos.FeatureSet features_;
-      private com.google.protobuf.SingleFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.FeatureSet, com.google.protobuf.DescriptorProtos.FeatureSet.Builder, com.google.protobuf.DescriptorProtos.FeatureSetOrBuilder> featuresBuilder_;
+      private SingleFieldBuilderV3Internal<
+                FeatureSet, FeatureSet.Builder, FeatureSetOrBuilder> featuresBuilder_;
       /**
        * 
        * Any features defined in the specific edition.
@@ -45550,12 +45550,12 @@ public com.google.protobuf.DescriptorProtos.FeatureSetOrBuilder getFeaturesOrBui
        *
        * optional .google.protobuf.FeatureSet features = 35;
        */
-      private com.google.protobuf.SingleFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.FeatureSet, com.google.protobuf.DescriptorProtos.FeatureSet.Builder, com.google.protobuf.DescriptorProtos.FeatureSetOrBuilder> 
+      private SingleFieldBuilderV3Internal<
+                FeatureSet, FeatureSet.Builder, FeatureSetOrBuilder>
           getFeaturesFieldBuilder() {
         if (featuresBuilder_ == null) {
-          featuresBuilder_ = new com.google.protobuf.SingleFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.FeatureSet, com.google.protobuf.DescriptorProtos.FeatureSet.Builder, com.google.protobuf.DescriptorProtos.FeatureSetOrBuilder>(
+          featuresBuilder_ = new SingleFieldBuilderV3Internal<
+                        FeatureSet, FeatureSet.Builder, FeatureSetOrBuilder>(
                   getFeatures(),
                   getParentForChildren(),
                   isClean());
@@ -45573,8 +45573,8 @@ private void ensureUninterpretedOptionIsMutable() {
          }
       }
 
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.UninterpretedOption, com.google.protobuf.DescriptorProtos.UninterpretedOption.Builder, com.google.protobuf.DescriptorProtos.UninterpretedOptionOrBuilder> uninterpretedOptionBuilder_;
+      private RepeatedFieldBuilderV3Internal<
+                UninterpretedOption, UninterpretedOption.Builder, UninterpretedOptionOrBuilder> uninterpretedOptionBuilder_;
 
       /**
        * 
@@ -45861,12 +45861,12 @@ public com.google.protobuf.DescriptorProtos.UninterpretedOption.Builder addUnint
            getUninterpretedOptionBuilderList() {
         return getUninterpretedOptionFieldBuilder().getBuilderList();
       }
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.UninterpretedOption, com.google.protobuf.DescriptorProtos.UninterpretedOption.Builder, com.google.protobuf.DescriptorProtos.UninterpretedOptionOrBuilder> 
+      private RepeatedFieldBuilderV3Internal<
+                UninterpretedOption, UninterpretedOption.Builder, UninterpretedOptionOrBuilder>
           getUninterpretedOptionFieldBuilder() {
         if (uninterpretedOptionBuilder_ == null) {
-          uninterpretedOptionBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.UninterpretedOption, com.google.protobuf.DescriptorProtos.UninterpretedOption.Builder, com.google.protobuf.DescriptorProtos.UninterpretedOptionOrBuilder>(
+          uninterpretedOptionBuilder_ = new RepeatedFieldBuilderV3Internal<
+                        UninterpretedOption, UninterpretedOption.Builder, UninterpretedOptionOrBuilder>(
                   uninterpretedOption_,
                   ((bitField0_ & 0x00000008) != 0),
                   getParentForChildren(),
@@ -47638,8 +47638,8 @@ private void ensureNameIsMutable() {
          }
       }
 
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.UninterpretedOption.NamePart, com.google.protobuf.DescriptorProtos.UninterpretedOption.NamePart.Builder, com.google.protobuf.DescriptorProtos.UninterpretedOption.NamePartOrBuilder> nameBuilder_;
+      private RepeatedFieldBuilderV3Internal<
+                NamePart, NamePart.Builder, NamePartOrBuilder> nameBuilder_;
 
       /**
        * repeated .google.protobuf.UninterpretedOption.NamePart name = 2;
@@ -47854,12 +47854,12 @@ public com.google.protobuf.DescriptorProtos.UninterpretedOption.NamePart.Builder
            getNameBuilderList() {
         return getNameFieldBuilder().getBuilderList();
       }
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.UninterpretedOption.NamePart, com.google.protobuf.DescriptorProtos.UninterpretedOption.NamePart.Builder, com.google.protobuf.DescriptorProtos.UninterpretedOption.NamePartOrBuilder> 
+      private RepeatedFieldBuilderV3Internal<
+                NamePart, NamePart.Builder, NamePartOrBuilder>
           getNameFieldBuilder() {
         if (nameBuilder_ == null) {
-          nameBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.UninterpretedOption.NamePart, com.google.protobuf.DescriptorProtos.UninterpretedOption.NamePart.Builder, com.google.protobuf.DescriptorProtos.UninterpretedOption.NamePartOrBuilder>(
+          nameBuilder_ = new RepeatedFieldBuilderV3Internal<
+                        NamePart, NamePart.Builder, NamePartOrBuilder>(
                   name_,
                   ((bitField0_ & 0x00000001) != 0),
                   getParentForChildren(),
@@ -50848,8 +50848,8 @@ public Builder clearEdition() {
         }
 
         private com.google.protobuf.DescriptorProtos.FeatureSet overridableFeatures_;
-        private com.google.protobuf.SingleFieldBuilderV3<
-            com.google.protobuf.DescriptorProtos.FeatureSet, com.google.protobuf.DescriptorProtos.FeatureSet.Builder, com.google.protobuf.DescriptorProtos.FeatureSetOrBuilder> overridableFeaturesBuilder_;
+        private SingleFieldBuilderV3Internal<
+                    FeatureSet, FeatureSet.Builder, FeatureSetOrBuilder> overridableFeaturesBuilder_;
         /**
          * 
          * Defaults of features that can be overridden in this edition.
@@ -50990,12 +50990,12 @@ public com.google.protobuf.DescriptorProtos.FeatureSetOrBuilder getOverridableFe
          *
          * optional .google.protobuf.FeatureSet overridable_features = 4;
          */
-        private com.google.protobuf.SingleFieldBuilderV3<
-            com.google.protobuf.DescriptorProtos.FeatureSet, com.google.protobuf.DescriptorProtos.FeatureSet.Builder, com.google.protobuf.DescriptorProtos.FeatureSetOrBuilder> 
+        private SingleFieldBuilderV3Internal<
+                    FeatureSet, FeatureSet.Builder, FeatureSetOrBuilder>
             getOverridableFeaturesFieldBuilder() {
           if (overridableFeaturesBuilder_ == null) {
-            overridableFeaturesBuilder_ = new com.google.protobuf.SingleFieldBuilderV3<
-                com.google.protobuf.DescriptorProtos.FeatureSet, com.google.protobuf.DescriptorProtos.FeatureSet.Builder, com.google.protobuf.DescriptorProtos.FeatureSetOrBuilder>(
+            overridableFeaturesBuilder_ = new SingleFieldBuilderV3Internal<
+                            FeatureSet, FeatureSet.Builder, FeatureSetOrBuilder>(
                     getOverridableFeatures(),
                     getParentForChildren(),
                     isClean());
@@ -51005,8 +51005,8 @@ public com.google.protobuf.DescriptorProtos.FeatureSetOrBuilder getOverridableFe
         }
 
         private com.google.protobuf.DescriptorProtos.FeatureSet fixedFeatures_;
-        private com.google.protobuf.SingleFieldBuilderV3<
-            com.google.protobuf.DescriptorProtos.FeatureSet, com.google.protobuf.DescriptorProtos.FeatureSet.Builder, com.google.protobuf.DescriptorProtos.FeatureSetOrBuilder> fixedFeaturesBuilder_;
+        private SingleFieldBuilderV3Internal<
+                    FeatureSet, FeatureSet.Builder, FeatureSetOrBuilder> fixedFeaturesBuilder_;
         /**
          * 
          * Defaults of features that can't be overridden in this edition.
@@ -51147,12 +51147,12 @@ public com.google.protobuf.DescriptorProtos.FeatureSetOrBuilder getFixedFeatures
          *
          * optional .google.protobuf.FeatureSet fixed_features = 5;
          */
-        private com.google.protobuf.SingleFieldBuilderV3<
-            com.google.protobuf.DescriptorProtos.FeatureSet, com.google.protobuf.DescriptorProtos.FeatureSet.Builder, com.google.protobuf.DescriptorProtos.FeatureSetOrBuilder> 
+        private SingleFieldBuilderV3Internal<
+                    FeatureSet, FeatureSet.Builder, FeatureSetOrBuilder>
             getFixedFeaturesFieldBuilder() {
           if (fixedFeaturesBuilder_ == null) {
-            fixedFeaturesBuilder_ = new com.google.protobuf.SingleFieldBuilderV3<
-                com.google.protobuf.DescriptorProtos.FeatureSet, com.google.protobuf.DescriptorProtos.FeatureSet.Builder, com.google.protobuf.DescriptorProtos.FeatureSetOrBuilder>(
+            fixedFeaturesBuilder_ = new SingleFieldBuilderV3Internal<
+                            FeatureSet, FeatureSet.Builder, FeatureSetOrBuilder>(
                     getFixedFeatures(),
                     getParentForChildren(),
                     isClean());
@@ -51795,8 +51795,8 @@ private void ensureDefaultsIsMutable() {
          }
       }
 
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.FeatureSetDefaults.FeatureSetEditionDefault, com.google.protobuf.DescriptorProtos.FeatureSetDefaults.FeatureSetEditionDefault.Builder, com.google.protobuf.DescriptorProtos.FeatureSetDefaults.FeatureSetEditionDefaultOrBuilder> defaultsBuilder_;
+      private RepeatedFieldBuilderV3Internal<
+                FeatureSetEditionDefault, FeatureSetEditionDefault.Builder, FeatureSetEditionDefaultOrBuilder> defaultsBuilder_;
 
       /**
        * repeated .google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault defaults = 1;
@@ -52011,12 +52011,12 @@ public com.google.protobuf.DescriptorProtos.FeatureSetDefaults.FeatureSetEdition
            getDefaultsBuilderList() {
         return getDefaultsFieldBuilder().getBuilderList();
       }
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.FeatureSetDefaults.FeatureSetEditionDefault, com.google.protobuf.DescriptorProtos.FeatureSetDefaults.FeatureSetEditionDefault.Builder, com.google.protobuf.DescriptorProtos.FeatureSetDefaults.FeatureSetEditionDefaultOrBuilder> 
+      private RepeatedFieldBuilderV3Internal<
+                FeatureSetEditionDefault, FeatureSetEditionDefault.Builder, FeatureSetEditionDefaultOrBuilder>
           getDefaultsFieldBuilder() {
         if (defaultsBuilder_ == null) {
-          defaultsBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.FeatureSetDefaults.FeatureSetEditionDefault, com.google.protobuf.DescriptorProtos.FeatureSetDefaults.FeatureSetEditionDefault.Builder, com.google.protobuf.DescriptorProtos.FeatureSetDefaults.FeatureSetEditionDefaultOrBuilder>(
+          defaultsBuilder_ = new RepeatedFieldBuilderV3Internal<
+                        FeatureSetEditionDefault, FeatureSetEditionDefault.Builder, FeatureSetEditionDefaultOrBuilder>(
                   defaults_,
                   ((bitField0_ & 0x00000001) != 0),
                   getParentForChildren(),
@@ -55616,8 +55616,8 @@ private void ensureLocationIsMutable() {
          }
       }
 
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.SourceCodeInfo.Location, com.google.protobuf.DescriptorProtos.SourceCodeInfo.Location.Builder, com.google.protobuf.DescriptorProtos.SourceCodeInfo.LocationOrBuilder> locationBuilder_;
+      private RepeatedFieldBuilderV3Internal<
+                Location, Location.Builder, LocationOrBuilder> locationBuilder_;
 
       /**
        * 
@@ -56660,12 +56660,12 @@ public com.google.protobuf.DescriptorProtos.SourceCodeInfo.Location.Builder addL
            getLocationBuilderList() {
         return getLocationFieldBuilder().getBuilderList();
       }
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.SourceCodeInfo.Location, com.google.protobuf.DescriptorProtos.SourceCodeInfo.Location.Builder, com.google.protobuf.DescriptorProtos.SourceCodeInfo.LocationOrBuilder> 
+      private RepeatedFieldBuilderV3Internal<
+                Location, Location.Builder, LocationOrBuilder>
           getLocationFieldBuilder() {
         if (locationBuilder_ == null) {
-          locationBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.SourceCodeInfo.Location, com.google.protobuf.DescriptorProtos.SourceCodeInfo.Location.Builder, com.google.protobuf.DescriptorProtos.SourceCodeInfo.LocationOrBuilder>(
+          locationBuilder_ = new RepeatedFieldBuilderV3Internal<
+                        Location, Location.Builder, LocationOrBuilder>(
                   location_,
                   ((bitField0_ & 0x00000001) != 0),
                   getParentForChildren(),
@@ -58704,8 +58704,8 @@ private void ensureAnnotationIsMutable() {
          }
       }
 
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.GeneratedCodeInfo.Annotation, com.google.protobuf.DescriptorProtos.GeneratedCodeInfo.Annotation.Builder, com.google.protobuf.DescriptorProtos.GeneratedCodeInfo.AnnotationOrBuilder> annotationBuilder_;
+      private RepeatedFieldBuilderV3Internal<
+                Annotation, Annotation.Builder, AnnotationOrBuilder> annotationBuilder_;
 
       /**
        * 
@@ -59010,12 +59010,12 @@ public com.google.protobuf.DescriptorProtos.GeneratedCodeInfo.Annotation.Builder
            getAnnotationBuilderList() {
         return getAnnotationFieldBuilder().getBuilderList();
       }
-      private com.google.protobuf.RepeatedFieldBuilderV3<
-          com.google.protobuf.DescriptorProtos.GeneratedCodeInfo.Annotation, com.google.protobuf.DescriptorProtos.GeneratedCodeInfo.Annotation.Builder, com.google.protobuf.DescriptorProtos.GeneratedCodeInfo.AnnotationOrBuilder> 
+      private RepeatedFieldBuilderV3Internal<
+                Annotation, Annotation.Builder, AnnotationOrBuilder>
           getAnnotationFieldBuilder() {
         if (annotationBuilder_ == null) {
-          annotationBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
-              com.google.protobuf.DescriptorProtos.GeneratedCodeInfo.Annotation, com.google.protobuf.DescriptorProtos.GeneratedCodeInfo.Annotation.Builder, com.google.protobuf.DescriptorProtos.GeneratedCodeInfo.AnnotationOrBuilder>(
+          annotationBuilder_ = new RepeatedFieldBuilderV3Internal<
+                        Annotation, Annotation.Builder, AnnotationOrBuilder>(
                   annotation_,
                   ((bitField0_ & 0x00000001) != 0),
                   getParentForChildren(),
diff --git a/protobuf-api/src/main/java/com/google/protobuf/Enum.java b/protobuf-api/src/main/java/com/google/protobuf/Enum.java
index 683b733..f65cd39 100644
--- a/protobuf-api/src/main/java/com/google/protobuf/Enum.java
+++ b/protobuf-api/src/main/java/com/google/protobuf/Enum.java
@@ -993,8 +993,8 @@ private void ensureEnumvalueIsMutable() {
        }
     }
 
-    private com.google.protobuf.RepeatedFieldBuilderV3<
-        com.google.protobuf.EnumValue, com.google.protobuf.EnumValue.Builder, com.google.protobuf.EnumValueOrBuilder> enumvalueBuilder_;
+    private RepeatedFieldBuilderV3Internal<
+            EnumValue, EnumValue.Builder, EnumValueOrBuilder> enumvalueBuilder_;
 
     /**
      * 
@@ -1281,12 +1281,12 @@ public com.google.protobuf.EnumValue.Builder addEnumvalueBuilder(
          getEnumvalueBuilderList() {
       return getEnumvalueFieldBuilder().getBuilderList();
     }
-    private com.google.protobuf.RepeatedFieldBuilderV3<
-        com.google.protobuf.EnumValue, com.google.protobuf.EnumValue.Builder, com.google.protobuf.EnumValueOrBuilder> 
+    private RepeatedFieldBuilderV3Internal<
+            EnumValue, EnumValue.Builder, EnumValueOrBuilder>
         getEnumvalueFieldBuilder() {
       if (enumvalueBuilder_ == null) {
-        enumvalueBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
-            com.google.protobuf.EnumValue, com.google.protobuf.EnumValue.Builder, com.google.protobuf.EnumValueOrBuilder>(
+        enumvalueBuilder_ = new RepeatedFieldBuilderV3Internal<
+                    EnumValue, EnumValue.Builder, EnumValueOrBuilder>(
                 enumvalue_,
                 ((bitField0_ & 0x00000002) != 0),
                 getParentForChildren(),
@@ -1305,8 +1305,8 @@ private void ensureOptionsIsMutable() {
        }
     }
 
-    private com.google.protobuf.RepeatedFieldBuilderV3<
-        com.google.protobuf.Option, com.google.protobuf.Option.Builder, com.google.protobuf.OptionOrBuilder> optionsBuilder_;
+    private RepeatedFieldBuilderV3Internal<
+            Option, Option.Builder, OptionOrBuilder> optionsBuilder_;
 
     /**
      * 
@@ -1593,12 +1593,12 @@ public com.google.protobuf.Option.Builder addOptionsBuilder(
          getOptionsBuilderList() {
       return getOptionsFieldBuilder().getBuilderList();
     }
-    private com.google.protobuf.RepeatedFieldBuilderV3<
-        com.google.protobuf.Option, com.google.protobuf.Option.Builder, com.google.protobuf.OptionOrBuilder> 
+    private RepeatedFieldBuilderV3Internal<
+            Option, Option.Builder, OptionOrBuilder>
         getOptionsFieldBuilder() {
       if (optionsBuilder_ == null) {
-        optionsBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
-            com.google.protobuf.Option, com.google.protobuf.Option.Builder, com.google.protobuf.OptionOrBuilder>(
+        optionsBuilder_ = new RepeatedFieldBuilderV3Internal<
+                    Option, Option.Builder, OptionOrBuilder>(
                 options_,
                 ((bitField0_ & 0x00000004) != 0),
                 getParentForChildren(),
@@ -1609,8 +1609,8 @@ public com.google.protobuf.Option.Builder addOptionsBuilder(
     }
 
     private com.google.protobuf.SourceContext sourceContext_;
-    private com.google.protobuf.SingleFieldBuilderV3<
-        com.google.protobuf.SourceContext, com.google.protobuf.SourceContext.Builder, com.google.protobuf.SourceContextOrBuilder> sourceContextBuilder_;
+    private SingleFieldBuilderV3Internal<
+            SourceContext, SourceContext.Builder, SourceContextOrBuilder> sourceContextBuilder_;
     /**
      * 
      * The source context.
@@ -1751,12 +1751,12 @@ public com.google.protobuf.SourceContextOrBuilder getSourceContextOrBuilder() {
      *
      * .google.protobuf.SourceContext source_context = 4;
      */
-    private com.google.protobuf.SingleFieldBuilderV3<
-        com.google.protobuf.SourceContext, com.google.protobuf.SourceContext.Builder, com.google.protobuf.SourceContextOrBuilder> 
+    private SingleFieldBuilderV3Internal<
+            SourceContext, SourceContext.Builder, SourceContextOrBuilder>
         getSourceContextFieldBuilder() {
       if (sourceContextBuilder_ == null) {
-        sourceContextBuilder_ = new com.google.protobuf.SingleFieldBuilderV3<
-            com.google.protobuf.SourceContext, com.google.protobuf.SourceContext.Builder, com.google.protobuf.SourceContextOrBuilder>(
+        sourceContextBuilder_ = new SingleFieldBuilderV3Internal<
+                    SourceContext, SourceContext.Builder, SourceContextOrBuilder>(
                 getSourceContext(),
                 getParentForChildren(),
                 isClean());
diff --git a/protobuf-api/src/main/java/com/google/protobuf/EnumValue.java b/protobuf-api/src/main/java/com/google/protobuf/EnumValue.java
index 8d928d6..93c173b 100644
--- a/protobuf-api/src/main/java/com/google/protobuf/EnumValue.java
+++ b/protobuf-api/src/main/java/com/google/protobuf/EnumValue.java
@@ -738,8 +738,8 @@ private void ensureOptionsIsMutable() {
        }
     }
 
-    private com.google.protobuf.RepeatedFieldBuilderV3<
-        com.google.protobuf.Option, com.google.protobuf.Option.Builder, com.google.protobuf.OptionOrBuilder> optionsBuilder_;
+    private RepeatedFieldBuilderV3Internal<
+            Option, Option.Builder, OptionOrBuilder> optionsBuilder_;
 
     /**
      * 
@@ -1026,12 +1026,12 @@ public com.google.protobuf.Option.Builder addOptionsBuilder(
          getOptionsBuilderList() {
       return getOptionsFieldBuilder().getBuilderList();
     }
-    private com.google.protobuf.RepeatedFieldBuilderV3<
-        com.google.protobuf.Option, com.google.protobuf.Option.Builder, com.google.protobuf.OptionOrBuilder> 
+    private RepeatedFieldBuilderV3Internal<
+            Option, Option.Builder, OptionOrBuilder>
         getOptionsFieldBuilder() {
       if (optionsBuilder_ == null) {
-        optionsBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
-            com.google.protobuf.Option, com.google.protobuf.Option.Builder, com.google.protobuf.OptionOrBuilder>(
+        optionsBuilder_ = new RepeatedFieldBuilderV3Internal<
+                    Option, Option.Builder, OptionOrBuilder>(
                 options_,
                 ((bitField0_ & 0x00000004) != 0),
                 getParentForChildren(),
diff --git a/protobuf-api/src/main/java/com/google/protobuf/Field.java b/protobuf-api/src/main/java/com/google/protobuf/Field.java
index 0ca9ed0..3228d6e 100644
--- a/protobuf-api/src/main/java/com/google/protobuf/Field.java
+++ b/protobuf-api/src/main/java/com/google/protobuf/Field.java
@@ -2045,8 +2045,8 @@ private void ensureOptionsIsMutable() {
        }
     }
 
-    private com.google.protobuf.RepeatedFieldBuilderV3<
-        com.google.protobuf.Option, com.google.protobuf.Option.Builder, com.google.protobuf.OptionOrBuilder> optionsBuilder_;
+    private RepeatedFieldBuilderV3Internal<
+            Option, Option.Builder, OptionOrBuilder> optionsBuilder_;
 
     /**
      * 
@@ -2333,12 +2333,12 @@ public com.google.protobuf.Option.Builder addOptionsBuilder(
          getOptionsBuilderList() {
       return getOptionsFieldBuilder().getBuilderList();
     }
-    private com.google.protobuf.RepeatedFieldBuilderV3<
-        com.google.protobuf.Option, com.google.protobuf.Option.Builder, com.google.protobuf.OptionOrBuilder> 
+    private RepeatedFieldBuilderV3Internal<
+            Option, Option.Builder, OptionOrBuilder>
         getOptionsFieldBuilder() {
       if (optionsBuilder_ == null) {
-        optionsBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
-            com.google.protobuf.Option, com.google.protobuf.Option.Builder, com.google.protobuf.OptionOrBuilder>(
+        optionsBuilder_ = new RepeatedFieldBuilderV3Internal<
+                    Option, Option.Builder, OptionOrBuilder>(
                 options_,
                 ((bitField0_ & 0x00000080) != 0),
                 getParentForChildren(),
diff --git a/protobuf-api/src/main/java/com/google/protobuf/ListValue.java b/protobuf-api/src/main/java/com/google/protobuf/ListValue.java
index e73789f..05fbedc 100644
--- a/protobuf-api/src/main/java/com/google/protobuf/ListValue.java
+++ b/protobuf-api/src/main/java/com/google/protobuf/ListValue.java
@@ -496,8 +496,8 @@ private void ensureValuesIsMutable() {
        }
     }
 
-    private com.google.protobuf.RepeatedFieldBuilderV3<
-        com.google.protobuf.Value, com.google.protobuf.Value.Builder, com.google.protobuf.ValueOrBuilder> valuesBuilder_;
+    private RepeatedFieldBuilderV3Internal<
+            Value, Value.Builder, ValueOrBuilder> valuesBuilder_;
 
     /**
      * 
@@ -784,12 +784,12 @@ public com.google.protobuf.Value.Builder addValuesBuilder(
          getValuesBuilderList() {
       return getValuesFieldBuilder().getBuilderList();
     }
-    private com.google.protobuf.RepeatedFieldBuilderV3<
-        com.google.protobuf.Value, com.google.protobuf.Value.Builder, com.google.protobuf.ValueOrBuilder> 
+    private RepeatedFieldBuilderV3Internal<
+            Value, Value.Builder, ValueOrBuilder>
         getValuesFieldBuilder() {
       if (valuesBuilder_ == null) {
-        valuesBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
-            com.google.protobuf.Value, com.google.protobuf.Value.Builder, com.google.protobuf.ValueOrBuilder>(
+        valuesBuilder_ = new RepeatedFieldBuilderV3Internal<
+                    Value, Value.Builder, ValueOrBuilder>(
                 values_,
                 ((bitField0_ & 0x00000001) != 0),
                 getParentForChildren(),
diff --git a/protobuf-api/src/main/java/com/google/protobuf/Method.java b/protobuf-api/src/main/java/com/google/protobuf/Method.java
index 9bddbbf..208b8b9 100644
--- a/protobuf-api/src/main/java/com/google/protobuf/Method.java
+++ b/protobuf-api/src/main/java/com/google/protobuf/Method.java
@@ -1199,8 +1199,8 @@ private void ensureOptionsIsMutable() {
        }
     }
 
-    private com.google.protobuf.RepeatedFieldBuilderV3<
-        com.google.protobuf.Option, com.google.protobuf.Option.Builder, com.google.protobuf.OptionOrBuilder> optionsBuilder_;
+    private RepeatedFieldBuilderV3Internal<
+            Option, Option.Builder, OptionOrBuilder> optionsBuilder_;
 
     /**
      * 
@@ -1487,12 +1487,12 @@ public com.google.protobuf.Option.Builder addOptionsBuilder(
          getOptionsBuilderList() {
       return getOptionsFieldBuilder().getBuilderList();
     }
-    private com.google.protobuf.RepeatedFieldBuilderV3<
-        com.google.protobuf.Option, com.google.protobuf.Option.Builder, com.google.protobuf.OptionOrBuilder> 
+    private RepeatedFieldBuilderV3Internal<
+            Option, Option.Builder, OptionOrBuilder>
         getOptionsFieldBuilder() {
       if (optionsBuilder_ == null) {
-        optionsBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
-            com.google.protobuf.Option, com.google.protobuf.Option.Builder, com.google.protobuf.OptionOrBuilder>(
+        optionsBuilder_ = new RepeatedFieldBuilderV3Internal<
+                    Option, Option.Builder, OptionOrBuilder>(
                 options_,
                 ((bitField0_ & 0x00000020) != 0),
                 getParentForChildren(),
diff --git a/protobuf-api/src/main/java/com/google/protobuf/Option.java b/protobuf-api/src/main/java/com/google/protobuf/Option.java
index c4db5d4..dac0036 100644
--- a/protobuf-api/src/main/java/com/google/protobuf/Option.java
+++ b/protobuf-api/src/main/java/com/google/protobuf/Option.java
@@ -630,8 +630,8 @@ public Builder setNameBytes(
     }
 
     private com.google.protobuf.Any value_;
-    private com.google.protobuf.SingleFieldBuilderV3<
-        com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder> valueBuilder_;
+    private SingleFieldBuilderV3Internal<
+            Any, Any.Builder, AnyOrBuilder> valueBuilder_;
     /**
      * 
      * The option's value packed in an Any message. If the value is a primitive,
@@ -799,12 +799,12 @@ public com.google.protobuf.AnyOrBuilder getValueOrBuilder() {
      *
      * .google.protobuf.Any value = 2;
      */
-    private com.google.protobuf.SingleFieldBuilderV3<
-        com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder> 
+    private SingleFieldBuilderV3Internal<
+            Any, Any.Builder, AnyOrBuilder>
         getValueFieldBuilder() {
       if (valueBuilder_ == null) {
-        valueBuilder_ = new com.google.protobuf.SingleFieldBuilderV3<
-            com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder>(
+        valueBuilder_ = new SingleFieldBuilderV3Internal<
+                    Any, Any.Builder, AnyOrBuilder>(
                 getValue(),
                 getParentForChildren(),
                 isClean());
diff --git a/protobuf-api/src/main/java/com/google/protobuf/RepeatedFieldBuilderV3Internal.java b/protobuf-api/src/main/java/com/google/protobuf/RepeatedFieldBuilderV3Internal.java
new file mode 100644
index 0000000..016085a
--- /dev/null
+++ b/protobuf-api/src/main/java/com/google/protobuf/RepeatedFieldBuilderV3Internal.java
@@ -0,0 +1,647 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc.  All rights reserved.
+//
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file or at
+// https://developers.google.com/open-source/licenses/bsd
+
+package com.google.protobuf;
+
+import static com.google.protobuf.Internal.checkNotNull;
+
+import java.util.AbstractList;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.RandomAccess;
+
+/**
+ * {@code RepeatedFieldBuilderV3} implements a structure that a protocol message uses to hold a
+ * repeated field of other protocol messages. It supports the classical use case of adding immutable
+ * {@link Message}'s to the repeated field and is highly optimized around this (no extra memory
+ * allocations and sharing of immutable arrays). 
+ * It also supports the additional use case of adding a {@link Message.Builder} to the repeated + * field and deferring conversion of that {@code Builder} to an immutable {@code Message}. In this + * way, it's possible to maintain a tree of {@code Builder}'s that acts as a fully read/write data + * structure.
+ * Logically, one can think of a tree of builders as converting the entire tree to messages when + * build is called on the root or when any method is called that desires a Message instead of a + * Builder. In terms of the implementation, the {@code SingleFieldBuilderV3} and {@code + * RepeatedFieldBuilderV3} classes cache messages that were created so that messages only need to be + * created when some change occurred in its builder or a builder for one of its descendants. + * + * @param the type of message for the field + * @param the type of builder for the field + * @param the common interface for the message and the builder + * @author jonp@google.com (Jon Perlow) + */ +class RepeatedFieldBuilderV3Internal< + MType extends Message, + BType extends Message.Builder, + IType extends MessageOrBuilder> + implements Message.BuilderParent { + + // Parent to send changes to. + private Message.BuilderParent parent; + + // List of messages. Never null. It may be immutable, in which case + // isMessagesListMutable will be false. See note below. + private List messages; + + // Whether messages is an mutable array that can be modified. + private boolean isMessagesListMutable; + + // List of builders. May be null, in which case, no nested builders were + // created. If not null, entries represent the builder for that index. + private List> builders; + + // Here are the invariants for messages and builders: + // 1. messages is never null and its count corresponds to the number of items + // in the repeated field. + // 2. If builders is non-null, messages and builders MUST always + // contain the same number of items. + // 3. Entries in either array can be null, but for any index, there MUST be + // either a Message in messages or a builder in builders. + // 4. If the builder at an index is non-null, the builder is + // authoritative. This is the case where a Builder was set on the index. + // Any message in the messages array MUST be ignored. + // t. If the builder at an index is null, the message in the messages + // list is authoritative. This is the case where a Message (not a Builder) + // was set directly for an index. + + // Indicates that we've built a message and so we are now obligated + // to dispatch dirty invalidations. See AbstractMessage.BuilderListener. + private boolean isClean; + + // A view of this builder that exposes a List interface of messages. This is + // initialized on demand. This is fully backed by this object and all changes + // are reflected in it. Access to any item converts it to a message if it + // was a builder. + private MessageExternalList externalMessageList; + + // A view of this builder that exposes a List interface of builders. This is + // initialized on demand. This is fully backed by this object and all changes + // are reflected in it. Access to any item converts it to a builder if it + // was a message. + private BuilderExternalList externalBuilderList; + + // A view of this builder that exposes a List interface of the interface + // implemented by messages and builders. This is initialized on demand. This + // is fully backed by this object and all changes are reflected in it. + // Access to any item returns either a builder or message depending on + // what is most efficient. + private MessageOrBuilderExternalList externalMessageOrBuilderList; + + /** + * Constructs a new builder with an empty list of messages. + * + * @param messages the current list of messages + * @param isMessagesListMutable Whether the messages list is mutable + * @param parent a listener to notify of changes + * @param isClean whether the builder is initially marked clean + */ + public RepeatedFieldBuilderV3Internal( + List messages, + boolean isMessagesListMutable, + Message.BuilderParent parent, + boolean isClean) { + this.messages = messages; + this.isMessagesListMutable = isMessagesListMutable; + this.parent = parent; + this.isClean = isClean; + } + + public void dispose() { + // Null out parent so we stop sending it invalidations. + parent = null; + } + + /** + * Ensures that the list of messages is mutable so it can be updated. If it's immutable, a copy is + * made. + */ + private void ensureMutableMessageList() { + if (!isMessagesListMutable) { + messages = new ArrayList(messages); + isMessagesListMutable = true; + } + } + + /** + * Ensures that the list of builders is not null. If it's null, the list is created and + * initialized to be the same size as the messages list with null entries. + */ + private void ensureBuilders() { + if (this.builders == null) { + this.builders = new ArrayList>(messages.size()); + for (int i = 0; i < messages.size(); i++) { + builders.add(null); + } + } + } + + /** + * Gets the count of items in the list. + * + * @return the count of items in the list. + */ + public int getCount() { + return messages.size(); + } + + /** + * Gets whether the list is empty. + * + * @return whether the list is empty + */ + public boolean isEmpty() { + return messages.isEmpty(); + } + + /** + * Get the message at the specified index. If the message is currently stored as a {@code + * Builder}, it is converted to a {@code Message} by calling {@link Message.Builder#buildPartial} + * on it. + * + * @param index the index of the message to get + * @return the message for the specified index + */ + public MType getMessage(int index) { + return getMessage(index, false); + } + + /** + * Get the message at the specified index. If the message is currently stored as a {@code + * Builder}, it is converted to a {@code Message} by calling {@link Message.Builder#buildPartial} + * on it. + * + * @param index the index of the message to get + * @param forBuild this is being called for build so we want to make sure we + * SingleFieldBuilderV3.build to send dirty invalidations + * @return the message for the specified index + */ + private MType getMessage(int index, boolean forBuild) { + if (this.builders == null) { + // We don't have any builders -- return the current Message. + // This is the case where no builder was created, so we MUST have a + // Message. + return messages.get(index); + } + + SingleFieldBuilderV3Internal builder = builders.get(index); + if (builder == null) { + // We don't have a builder -- return the current message. + // This is the case where no builder was created for the entry at index, + // so we MUST have a message. + return messages.get(index); + + } else { + return forBuild ? builder.build() : builder.getMessage(); + } + } + + /** + * Gets a builder for the specified index. If no builder has been created for that index, a + * builder is created on demand by calling {@link Message#toBuilder}. + * + * @param index the index of the message to get + * @return The builder for that index + */ + public BType getBuilder(int index) { + ensureBuilders(); + SingleFieldBuilderV3Internal builder = builders.get(index); + if (builder == null) { + MType message = messages.get(index); + builder = new SingleFieldBuilderV3Internal(message, this, isClean); + builders.set(index, builder); + } + return builder.getBuilder(); + } + + /** + * Gets the base class interface for the specified index. This may either be a builder or a + * message. It will return whatever is more efficient. + * + * @param index the index of the message to get + * @return the message or builder for the index as the base class interface + */ + @SuppressWarnings("unchecked") + public IType getMessageOrBuilder(int index) { + if (this.builders == null) { + // We don't have any builders -- return the current Message. + // This is the case where no builder was created, so we MUST have a + // Message. + return (IType) messages.get(index); + } + + SingleFieldBuilderV3Internal builder = builders.get(index); + if (builder == null) { + // We don't have a builder -- return the current message. + // This is the case where no builder was created for the entry at index, + // so we MUST have a message. + return (IType) messages.get(index); + + } else { + return builder.getMessageOrBuilder(); + } + } + + /** + * Sets a message at the specified index replacing the existing item at that index. + * + * @param index the index to set. + * @param message the message to set + * @return the builder + */ + @CanIgnoreReturnValue + public RepeatedFieldBuilderV3Internal setMessage(int index, MType message) { + checkNotNull(message); + ensureMutableMessageList(); + messages.set(index, message); + if (builders != null) { + SingleFieldBuilderV3Internal entry = builders.set(index, null); + if (entry != null) { + entry.dispose(); + } + } + onChanged(); + incrementModCounts(); + return this; + } + + /** + * Appends the specified element to the end of this list. + * + * @param message the message to add + * @return the builder + */ + @CanIgnoreReturnValue + public RepeatedFieldBuilderV3Internal addMessage(MType message) { + checkNotNull(message); + ensureMutableMessageList(); + messages.add(message); + if (builders != null) { + builders.add(null); + } + onChanged(); + incrementModCounts(); + return this; + } + + /** + * Inserts the specified message at the specified position in this list. Shifts the element + * currently at that position (if any) and any subsequent elements to the right (adds one to their + * indices). + * + * @param index the index at which to insert the message + * @param message the message to add + * @return the builder + */ + @CanIgnoreReturnValue + public RepeatedFieldBuilderV3Internal addMessage(int index, MType message) { + checkNotNull(message); + ensureMutableMessageList(); + messages.add(index, message); + if (builders != null) { + builders.add(index, null); + } + onChanged(); + incrementModCounts(); + return this; + } + + /** + * Appends all of the messages in the specified collection to the end of this list, in the order + * that they are returned by the specified collection's iterator. + * + * @param values the messages to add + * @return the builder + */ + @CanIgnoreReturnValue + public RepeatedFieldBuilderV3Internal addAllMessages( + Iterable values) { + for (final MType value : values) { + checkNotNull(value); + } + + // If we can inspect the size, we can more efficiently add messages. + int size = -1; + if (values instanceof Collection) { + final Collection collection = (Collection) values; + if (collection.isEmpty()) { + return this; + } + size = collection.size(); + } + ensureMutableMessageList(); + + if (size >= 0 && messages instanceof ArrayList) { + ((ArrayList) messages).ensureCapacity(messages.size() + size); + } + + for (MType value : values) { + addMessage(value); + } + + onChanged(); + incrementModCounts(); + return this; + } + + /** + * Appends a new builder to the end of this list and returns the builder. + * + * @param message the message to add which is the basis of the builder + * @return the new builder + */ + public BType addBuilder(MType message) { + ensureMutableMessageList(); + ensureBuilders(); + SingleFieldBuilderV3Internal builder = + new SingleFieldBuilderV3Internal(message, this, isClean); + messages.add(null); + builders.add(builder); + onChanged(); + incrementModCounts(); + return builder.getBuilder(); + } + + /** + * Inserts a new builder at the specified position in this list. Shifts the element currently at + * that position (if any) and any subsequent elements to the right (adds one to their indices). + * + * @param index the index at which to insert the builder + * @param message the message to add which is the basis of the builder + * @return the builder + */ + public BType addBuilder(int index, MType message) { + ensureMutableMessageList(); + ensureBuilders(); + SingleFieldBuilderV3Internal builder = + new SingleFieldBuilderV3Internal(message, this, isClean); + messages.add(index, null); + builders.add(index, builder); + onChanged(); + incrementModCounts(); + return builder.getBuilder(); + } + + /** + * Removes the element at the specified position in this list. Shifts any subsequent elements to + * the left (subtracts one from their indices). + * + * @param index the index at which to remove the message + */ + public void remove(int index) { + ensureMutableMessageList(); + messages.remove(index); + if (builders != null) { + SingleFieldBuilderV3Internal entry = builders.remove(index); + if (entry != null) { + entry.dispose(); + } + } + onChanged(); + incrementModCounts(); + } + + /** Removes all of the elements from this list. The list will be empty after this call returns. */ + public void clear() { + messages = Collections.emptyList(); + isMessagesListMutable = false; + if (builders != null) { + for (SingleFieldBuilderV3Internal entry : builders) { + if (entry != null) { + entry.dispose(); + } + } + builders = null; + } + onChanged(); + incrementModCounts(); + } + + /** + * Builds the list of messages from the builder and returns them. + * + * @return an immutable list of messages + */ + public List build() { + // Now that build has been called, we are required to dispatch + // invalidations. + isClean = true; + + if (!isMessagesListMutable && builders == null) { + // We still have an immutable list and we never created a builder. + return messages; + } + + boolean allMessagesInSync = true; + if (!isMessagesListMutable) { + // We still have an immutable list. Let's see if any of them are out + // of sync with their builders. + for (int i = 0; i < messages.size(); i++) { + Message message = messages.get(i); + SingleFieldBuilderV3Internal builder = builders.get(i); + if (builder != null) { + if (builder.build() != message) { + allMessagesInSync = false; + break; + } + } + } + if (allMessagesInSync) { + // Immutable list is still in sync. + return messages; + } + } + + // Need to make sure messages is up to date + ensureMutableMessageList(); + for (int i = 0; i < messages.size(); i++) { + messages.set(i, getMessage(i, true)); + } + + // We're going to return our list as immutable so we mark that we can + // no longer update it. + messages = Collections.unmodifiableList(messages); + isMessagesListMutable = false; + return messages; + } + + /** + * Gets a view of the builder as a list of messages. The returned list is live and will reflect + * any changes to the underlying builder. + * + * @return the messages in the list + */ + public List getMessageList() { + if (externalMessageList == null) { + externalMessageList = new MessageExternalList(this); + } + return externalMessageList; + } + + /** + * Gets a view of the builder as a list of builders. This returned list is live and will reflect + * any changes to the underlying builder. + * + * @return the builders in the list + */ + public List getBuilderList() { + if (externalBuilderList == null) { + externalBuilderList = new BuilderExternalList(this); + } + return externalBuilderList; + } + + /** + * Gets a view of the builder as a list of MessageOrBuilders. This returned list is live and will + * reflect any changes to the underlying builder. + * + * @return the builders in the list + */ + public List getMessageOrBuilderList() { + if (externalMessageOrBuilderList == null) { + externalMessageOrBuilderList = new MessageOrBuilderExternalList(this); + } + return externalMessageOrBuilderList; + } + + /** + * Called when a the builder or one of its nested children has changed and any parent should be + * notified of its invalidation. + */ + private void onChanged() { + if (isClean && parent != null) { + parent.markDirty(); + + // Don't keep dispatching invalidations until build is called again. + isClean = false; + } + } + + @Override + public void markDirty() { + onChanged(); + } + + /** + * Increments the mod counts so that an ConcurrentModificationException can be thrown if calling + * code tries to modify the builder while its iterating the list. + */ + private void incrementModCounts() { + if (externalMessageList != null) { + externalMessageList.incrementModCount(); + } + if (externalBuilderList != null) { + externalBuilderList.incrementModCount(); + } + if (externalMessageOrBuilderList != null) { + externalMessageOrBuilderList.incrementModCount(); + } + } + + /** + * Provides a live view of the builder as a list of messages. + * + * @param the type of message for the field + * @param the type of builder for the field + * @param the common interface for the message and the builder + */ + private static class MessageExternalList< + MType extends Message, + BType extends Message.Builder, + IType extends MessageOrBuilder> + extends AbstractList implements List, RandomAccess { + + RepeatedFieldBuilderV3Internal builder; + + MessageExternalList(RepeatedFieldBuilderV3Internal builder) { + this.builder = builder; + } + + @Override + public int size() { + return this.builder.getCount(); + } + + @Override + public MType get(int index) { + return builder.getMessage(index); + } + + void incrementModCount() { + modCount++; + } + } + + /** + * Provides a live view of the builder as a list of builders. + * + * @param the type of message for the field + * @param the type of builder for the field + * @param the common interface for the message and the builder + */ + private static class BuilderExternalList< + MType extends Message, + BType extends Message.Builder, + IType extends MessageOrBuilder> + extends AbstractList implements List, RandomAccess { + + RepeatedFieldBuilderV3Internal builder; + + BuilderExternalList(RepeatedFieldBuilderV3Internal builder) { + this.builder = builder; + } + + @Override + public int size() { + return this.builder.getCount(); + } + + @Override + public BType get(int index) { + return builder.getBuilder(index); + } + + void incrementModCount() { + modCount++; + } + } + + /** + * Provides a live view of the builder as a list of builders. + * + * @param the type of message for the field + * @param the type of builder for the field + * @param the common interface for the message and the builder + */ + private static class MessageOrBuilderExternalList< + MType extends Message, + BType extends Message.Builder, + IType extends MessageOrBuilder> + extends AbstractList implements List, RandomAccess { + + RepeatedFieldBuilderV3Internal builder; + + MessageOrBuilderExternalList(RepeatedFieldBuilderV3Internal builder) { + this.builder = builder; + } + + @Override + public int size() { + return this.builder.getCount(); + } + + @Override + public IType get(int index) { + return builder.getMessageOrBuilder(index); + } + + void incrementModCount() { + modCount++; + } + } +} diff --git a/protobuf-api/src/main/java/com/google/protobuf/SingleFieldBuilderV3Internal.java b/protobuf-api/src/main/java/com/google/protobuf/SingleFieldBuilderV3Internal.java new file mode 100644 index 0000000..49a44f6 --- /dev/null +++ b/protobuf-api/src/main/java/com/google/protobuf/SingleFieldBuilderV3Internal.java @@ -0,0 +1,217 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd + +package com.google.protobuf; + +import static com.google.protobuf.Internal.checkNotNull; + +/** + * {@code SingleFieldBuilderV3} implements a structure that a protocol message uses to hold a single + * field of another protocol message. It supports the classical use case of setting an immutable + * {@link Message} as the value of the field and is highly optimized around this. + * + *

It also supports the additional use case of setting a {@link Message.Builder} as the field and + * deferring conversion of that {@code Builder} to an immutable {@code Message}. In this way, it's + * possible to maintain a tree of {@code Builder}'s that acts as a fully read/write data structure. + *
+ * Logically, one can think of a tree of builders as converting the entire tree to messages when + * build is called on the root or when any method is called that desires a Message instead of a + * Builder. In terms of the implementation, the {@code SingleFieldBuilderV3} and {@code + * RepeatedFieldBuilderV3} classes cache messages that were created so that messages only need to be + * created when some change occurred in its builder or a builder for one of its descendants. + * + * @param the type of message for the field + * @param the type of builder for the field + * @param the common interface for the message and the builder + * @author jonp@google.com (Jon Perlow) + */ +class SingleFieldBuilderV3Internal< + MType extends Message, + BType extends Message.Builder, + IType extends MessageOrBuilder> + implements Message.BuilderParent { + + // Parent to send changes to. + private Message.BuilderParent parent; + + // Invariant: one of builder or message fields must be non-null. + + // If set, this is the case where we are backed by a builder. In this case, + // message field represents a cached message for the builder (or null if + // there is no cached message). + private BType builder; + + // If builder is non-null, this represents a cached message from the builder. + // If builder is null, this is the authoritative message for the field. + private MType message; + + // Indicates that we've built a message and so we are now obligated + // to dispatch dirty invalidations. See AbstractMessage.BuilderListener. + private boolean isClean; + + public SingleFieldBuilderV3Internal(MType message, Message.BuilderParent parent, boolean isClean) { + this.message = checkNotNull(message); + this.parent = parent; + this.isClean = isClean; + } + + public void dispose() { + // Null out parent so we stop sending it invalidations. + parent = null; + } + + /** + * Get the message for the field. If the message is currently stored as a {@code Builder}, it is + * converted to a {@code Message} by calling {@link Message.Builder#buildPartial} on it. If no + * message has been set, returns the default instance of the message. + * + * @return the message for the field + */ + @SuppressWarnings("unchecked") + public MType getMessage() { + if (message == null) { + // If message is null, the invariant is that we must be have a builder. + message = (MType) builder.buildPartial(); + } + return message; + } + + /** + * Builds the message and returns it. + * + * @return the message + */ + public MType build() { + // Now that build has been called, we are required to dispatch + // invalidations. + isClean = true; + return getMessage(); + } + + /** + * Gets a builder for the field. If no builder has been created yet, a builder is created on + * demand by calling {@link Message#toBuilder}. + * + * @return The builder for the field + */ + @SuppressWarnings("unchecked") + public BType getBuilder() { + if (builder == null) { + // builder.mergeFrom() on a fresh builder + // does not create any sub-objects with independent clean/dirty states, + // therefore setting the builder itself to clean without actually calling + // build() cannot break any invariants. + builder = (BType) message.newBuilderForType(); + builder.mergeFrom(message); // no-op if message is the default message +// builder.markClean(); + } + return builder; + } + + /** + * Gets the base class interface for the field. This may either be a builder or a message. It will + * return whatever is more efficient. + * + * @return the message or builder for the field as the base class interface + */ + @SuppressWarnings("unchecked") + public IType getMessageOrBuilder() { + if (builder != null) { + return (IType) builder; + } else { + return (IType) message; + } + } + + /** + * Sets a message for the field replacing any existing value. + * + * @param message the message to set + * @return the builder + */ + @CanIgnoreReturnValue + public SingleFieldBuilderV3Internal setMessage(MType message) { + this.message = checkNotNull(message); + if (builder != null) { +// builder.dispose(); + builder = null; + } + onChanged(); + return this; + } + + /** + * Merges the field from another field. + * + * @param value the value to merge from + * @return the builder + */ + @CanIgnoreReturnValue + public SingleFieldBuilderV3Internal mergeFrom(MType value) { + if (builder == null && message == message.getDefaultInstanceForType()) { + message = value; + } else { + getBuilder().mergeFrom(value); + } + onChanged(); + return this; + } + + /** + * Clears the value of the field. + * + * @return the builder + */ + @SuppressWarnings("unchecked") + @CanIgnoreReturnValue + public SingleFieldBuilderV3Internal clear() { + message = + (MType) + (message != null + ? message.getDefaultInstanceForType() + : builder.getDefaultInstanceForType()); + if (builder != null) { +// builder.dispose(); + builder = null; + } + onChanged(); + // After clearing, parent is dirty, but this field builder is now clean and any changes should + // trickle up. + isClean = true; + return this; + } + + /** + * Called when a the builder or one of its nested children has changed and any parent should be + * notified of its invalidation. + */ + private void onChanged() { + // If builder is null, this is the case where onChanged is being called + // from setMessage or clear. + if (builder != null) { + message = null; + } + if (isClean && parent != null) { + parent.markDirty(); + + // Don't keep dispatching invalidations until build is called again. + isClean = false; + } + } + + static T checkNotNull(T obj) { + if (obj == null) { + throw new NullPointerException(); + } + return obj; + } + + @Override + public void markDirty() { + onChanged(); + } +} diff --git a/protobuf-api/src/main/java/com/google/protobuf/Type.java b/protobuf-api/src/main/java/com/google/protobuf/Type.java index ebfb94c..0b7261f 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/Type.java +++ b/protobuf-api/src/main/java/com/google/protobuf/Type.java @@ -1087,8 +1087,8 @@ private void ensureFieldsIsMutable() { } } - private com.google.protobuf.RepeatedFieldBuilderV3< - com.google.protobuf.Field, com.google.protobuf.Field.Builder, com.google.protobuf.FieldOrBuilder> fieldsBuilder_; + private RepeatedFieldBuilderV3Internal< + Field, Field.Builder, FieldOrBuilder> fieldsBuilder_; /** *

@@ -1375,12 +1375,12 @@ public com.google.protobuf.Field.Builder addFieldsBuilder(
          getFieldsBuilderList() {
       return getFieldsFieldBuilder().getBuilderList();
     }
-    private com.google.protobuf.RepeatedFieldBuilderV3<
-        com.google.protobuf.Field, com.google.protobuf.Field.Builder, com.google.protobuf.FieldOrBuilder> 
+    private RepeatedFieldBuilderV3Internal<
+            Field, Field.Builder, FieldOrBuilder>
         getFieldsFieldBuilder() {
       if (fieldsBuilder_ == null) {
-        fieldsBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
-            com.google.protobuf.Field, com.google.protobuf.Field.Builder, com.google.protobuf.FieldOrBuilder>(
+        fieldsBuilder_ = new RepeatedFieldBuilderV3Internal<
+                    Field, Field.Builder, FieldOrBuilder>(
                 fields_,
                 ((bitField0_ & 0x00000002) != 0),
                 getParentForChildren(),
@@ -1546,8 +1546,8 @@ private void ensureOptionsIsMutable() {
        }
     }
 
-    private com.google.protobuf.RepeatedFieldBuilderV3<
-        com.google.protobuf.Option, com.google.protobuf.Option.Builder, com.google.protobuf.OptionOrBuilder> optionsBuilder_;
+    private RepeatedFieldBuilderV3Internal<
+            Option, Option.Builder, OptionOrBuilder> optionsBuilder_;
 
     /**
      * 
@@ -1834,12 +1834,12 @@ public com.google.protobuf.Option.Builder addOptionsBuilder(
          getOptionsBuilderList() {
       return getOptionsFieldBuilder().getBuilderList();
     }
-    private com.google.protobuf.RepeatedFieldBuilderV3<
-        com.google.protobuf.Option, com.google.protobuf.Option.Builder, com.google.protobuf.OptionOrBuilder> 
+    private RepeatedFieldBuilderV3Internal<
+            Option, Option.Builder, OptionOrBuilder>
         getOptionsFieldBuilder() {
       if (optionsBuilder_ == null) {
-        optionsBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
-            com.google.protobuf.Option, com.google.protobuf.Option.Builder, com.google.protobuf.OptionOrBuilder>(
+        optionsBuilder_ = new RepeatedFieldBuilderV3Internal<
+                    Option, Option.Builder, OptionOrBuilder>(
                 options_,
                 ((bitField0_ & 0x00000008) != 0),
                 getParentForChildren(),
@@ -1850,8 +1850,8 @@ public com.google.protobuf.Option.Builder addOptionsBuilder(
     }
 
     private com.google.protobuf.SourceContext sourceContext_;
-    private com.google.protobuf.SingleFieldBuilderV3<
-        com.google.protobuf.SourceContext, com.google.protobuf.SourceContext.Builder, com.google.protobuf.SourceContextOrBuilder> sourceContextBuilder_;
+    private SingleFieldBuilderV3Internal<
+            SourceContext, SourceContext.Builder, SourceContextOrBuilder> sourceContextBuilder_;
     /**
      * 
      * The source context.
@@ -1992,12 +1992,12 @@ public com.google.protobuf.SourceContextOrBuilder getSourceContextOrBuilder() {
      *
      * .google.protobuf.SourceContext source_context = 5;
      */
-    private com.google.protobuf.SingleFieldBuilderV3<
-        com.google.protobuf.SourceContext, com.google.protobuf.SourceContext.Builder, com.google.protobuf.SourceContextOrBuilder> 
+    private SingleFieldBuilderV3Internal<
+            SourceContext, SourceContext.Builder, SourceContextOrBuilder>
         getSourceContextFieldBuilder() {
       if (sourceContextBuilder_ == null) {
-        sourceContextBuilder_ = new com.google.protobuf.SingleFieldBuilderV3<
-            com.google.protobuf.SourceContext, com.google.protobuf.SourceContext.Builder, com.google.protobuf.SourceContextOrBuilder>(
+        sourceContextBuilder_ = new SingleFieldBuilderV3Internal<
+                    SourceContext, SourceContext.Builder, SourceContextOrBuilder>(
                 getSourceContext(),
                 getParentForChildren(),
                 isClean());
diff --git a/protobuf-api/src/main/java/com/google/protobuf/Value.java b/protobuf-api/src/main/java/com/google/protobuf/Value.java
index 3d3c265..e59e991 100644
--- a/protobuf-api/src/main/java/com/google/protobuf/Value.java
+++ b/protobuf-api/src/main/java/com/google/protobuf/Value.java
@@ -1196,8 +1196,8 @@ public Builder clearBoolValue() {
       return this;
     }
 
-    private com.google.protobuf.SingleFieldBuilderV3<
-        com.google.protobuf.Struct, com.google.protobuf.Struct.Builder, com.google.protobuf.StructOrBuilder> structValueBuilder_;
+    private SingleFieldBuilderV3Internal<
+            Struct, Struct.Builder, StructOrBuilder> structValueBuilder_;
     /**
      * 
      * Represents a structured value.
@@ -1355,15 +1355,15 @@ public com.google.protobuf.StructOrBuilder getStructValueOrBuilder() {
      *
      * .google.protobuf.Struct struct_value = 5;
      */
-    private com.google.protobuf.SingleFieldBuilderV3<
-        com.google.protobuf.Struct, com.google.protobuf.Struct.Builder, com.google.protobuf.StructOrBuilder> 
+    private SingleFieldBuilderV3Internal<
+            Struct, Struct.Builder, StructOrBuilder>
         getStructValueFieldBuilder() {
       if (structValueBuilder_ == null) {
         if (!(kindCase_ == 5)) {
           kind_ = com.google.protobuf.Struct.getDefaultInstance();
         }
-        structValueBuilder_ = new com.google.protobuf.SingleFieldBuilderV3<
-            com.google.protobuf.Struct, com.google.protobuf.Struct.Builder, com.google.protobuf.StructOrBuilder>(
+        structValueBuilder_ = new SingleFieldBuilderV3Internal<
+                    Struct, Struct.Builder, StructOrBuilder>(
                 (com.google.protobuf.Struct) kind_,
                 getParentForChildren(),
                 isClean());
@@ -1374,8 +1374,8 @@ public com.google.protobuf.StructOrBuilder getStructValueOrBuilder() {
       return structValueBuilder_;
     }
 
-    private com.google.protobuf.SingleFieldBuilderV3<
-        com.google.protobuf.ListValue, com.google.protobuf.ListValue.Builder, com.google.protobuf.ListValueOrBuilder> listValueBuilder_;
+    private SingleFieldBuilderV3Internal<
+            ListValue, ListValue.Builder, ListValueOrBuilder> listValueBuilder_;
     /**
      * 
      * Represents a repeated `Value`.
@@ -1533,15 +1533,15 @@ public com.google.protobuf.ListValueOrBuilder getListValueOrBuilder() {
      *
      * .google.protobuf.ListValue list_value = 6;
      */
-    private com.google.protobuf.SingleFieldBuilderV3<
-        com.google.protobuf.ListValue, com.google.protobuf.ListValue.Builder, com.google.protobuf.ListValueOrBuilder> 
+    private SingleFieldBuilderV3Internal<
+            ListValue, ListValue.Builder, ListValueOrBuilder>
         getListValueFieldBuilder() {
       if (listValueBuilder_ == null) {
         if (!(kindCase_ == 6)) {
           kind_ = com.google.protobuf.ListValue.getDefaultInstance();
         }
-        listValueBuilder_ = new com.google.protobuf.SingleFieldBuilderV3<
-            com.google.protobuf.ListValue, com.google.protobuf.ListValue.Builder, com.google.protobuf.ListValueOrBuilder>(
+        listValueBuilder_ = new SingleFieldBuilderV3Internal<
+                    ListValue, ListValue.Builder, ListValueOrBuilder>(
                 (com.google.protobuf.ListValue) kind_,
                 getParentForChildren(),
                 isClean());
diff --git a/protobuf-api/src/main/java/com/google/protobuf/RepeatedFieldBuilderV3.java b/protobuf-sdk/src/main/java/com/google/protobuf/RepeatedFieldBuilderV3.java
similarity index 97%
rename from protobuf-api/src/main/java/com/google/protobuf/RepeatedFieldBuilderV3.java
rename to protobuf-sdk/src/main/java/com/google/protobuf/RepeatedFieldBuilderV3.java
index f418b3a..aeb2c09 100644
--- a/protobuf-api/src/main/java/com/google/protobuf/RepeatedFieldBuilderV3.java
+++ b/protobuf-sdk/src/main/java/com/google/protobuf/RepeatedFieldBuilderV3.java
@@ -7,8 +7,6 @@
 
 package com.google.protobuf;
 
-import static com.google.protobuf.Internal.checkNotNull;
-
 import java.util.AbstractList;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -37,13 +35,13 @@
  * @author jonp@google.com (Jon Perlow)
  */
 public class RepeatedFieldBuilderV3<
-        MType extends Message,
-        BType extends Message.Builder,
+        MType extends AbstractMessage,
+        BType extends AbstractMessage.Builder,
         IType extends MessageOrBuilder>
-    implements Message.BuilderParent {
+    implements AbstractMessage.BuilderParent {
 
   // Parent to send changes to.
-  private Message.BuilderParent parent;
+  private AbstractMessage.BuilderParent parent;
 
   // List of messages. Never null. It may be immutable, in which case
   // isMessagesListMutable will be false. See note below.
@@ -104,7 +102,7 @@ public class RepeatedFieldBuilderV3<
   public RepeatedFieldBuilderV3(
       List messages,
       boolean isMessagesListMutable,
-      Message.BuilderParent parent,
+      AbstractMessage.BuilderParent parent,
       boolean isClean) {
     this.messages = messages;
     this.isMessagesListMutable = isMessagesListMutable;
@@ -367,6 +365,13 @@ public BType addBuilder(MType message) {
     return builder.getBuilder();
   }
 
+  static  T checkNotNull(T obj) {
+    if (obj == null) {
+      throw new NullPointerException();
+    }
+    return obj;
+  }
+
   /**
    * Inserts a new builder at the specified position in this list. Shifts the element currently at
    * that position (if any) and any subsequent elements to the right (adds one to their indices).
@@ -551,8 +556,8 @@ private void incrementModCounts() {
    * @param  the common interface for the message and the builder
    */
   private static class MessageExternalList<
-          MType extends Message,
-          BType extends Message.Builder,
+          MType extends AbstractMessage,
+          BType extends AbstractMessage.Builder,
           IType extends MessageOrBuilder>
       extends AbstractList implements List, RandomAccess {
 
@@ -585,8 +590,8 @@ void incrementModCount() {
    * @param  the common interface for the message and the builder
    */
   private static class BuilderExternalList<
-          MType extends Message,
-          BType extends Message.Builder,
+          MType extends AbstractMessage,
+          BType extends AbstractMessage.Builder,
           IType extends MessageOrBuilder>
       extends AbstractList implements List, RandomAccess {
 
@@ -619,8 +624,8 @@ void incrementModCount() {
    * @param  the common interface for the message and the builder
    */
   private static class MessageOrBuilderExternalList<
-          MType extends Message,
-          BType extends Message.Builder,
+          MType extends AbstractMessage,
+          BType extends AbstractMessage.Builder,
           IType extends MessageOrBuilder>
       extends AbstractList implements List, RandomAccess {
 
diff --git a/protobuf-api/src/main/java/com/google/protobuf/SingleFieldBuilderV3.java b/protobuf-sdk/src/main/java/com/google/protobuf/SingleFieldBuilderV3.java
similarity index 92%
rename from protobuf-api/src/main/java/com/google/protobuf/SingleFieldBuilderV3.java
rename to protobuf-sdk/src/main/java/com/google/protobuf/SingleFieldBuilderV3.java
index cad278e..991404e 100644
--- a/protobuf-api/src/main/java/com/google/protobuf/SingleFieldBuilderV3.java
+++ b/protobuf-sdk/src/main/java/com/google/protobuf/SingleFieldBuilderV3.java
@@ -7,8 +7,6 @@
 
 package com.google.protobuf;
 
-import static com.google.protobuf.Internal.checkNotNull;
-
 /**
  * {@code SingleFieldBuilderV3} implements a structure that a protocol message uses to hold a single
  * field of another protocol message. It supports the classical use case of setting an immutable
@@ -30,13 +28,13 @@
  * @author jonp@google.com (Jon Perlow)
  */
 public class SingleFieldBuilderV3<
-        MType extends Message,
-        BType extends Message.Builder,
+        MType extends AbstractMessage,
+        BType extends AbstractMessage.Builder,
         IType extends MessageOrBuilder>
-    implements Message.BuilderParent {
+    implements AbstractMessage.BuilderParent {
 
   // Parent to send changes to.
-  private Message.BuilderParent parent;
+  private AbstractMessage.BuilderParent parent;
 
   // Invariant: one of builder or message fields must be non-null.
 
@@ -53,12 +51,19 @@ public class SingleFieldBuilderV3<
   // to dispatch dirty invalidations. See AbstractMessage.BuilderListener.
   private boolean isClean;
 
-  public SingleFieldBuilderV3(MType message, Message.BuilderParent parent, boolean isClean) {
+  public SingleFieldBuilderV3(MType message, AbstractMessage.BuilderParent parent, boolean isClean) {
     this.message = checkNotNull(message);
     this.parent = parent;
     this.isClean = isClean;
   }
 
+  static  T checkNotNull(T obj) {
+    if (obj == null) {
+      throw new NullPointerException();
+    }
+    return obj;
+  }
+
   public void dispose() {
     // Null out parent so we stop sending it invalidations.
     parent = null;
@@ -105,9 +110,9 @@ public BType getBuilder() {
       // does not create any sub-objects with independent clean/dirty states,
       // therefore setting the builder itself to clean without actually calling
       // build() cannot break any invariants.
-      builder = (BType) message.newBuilderForType();
+      builder = (BType) message.newBuilderForType(this);
       builder.mergeFrom(message); // no-op if message is the default message
-//      builder.markClean();
+      builder.markClean();
     }
     return builder;
   }
@@ -137,7 +142,7 @@ public IType getMessageOrBuilder() {
   public SingleFieldBuilderV3 setMessage(MType message) {
     this.message = checkNotNull(message);
     if (builder != null) {
-//      builder.dispose();
+      builder.dispose();
       builder = null;
     }
     onChanged();
@@ -175,7 +180,7 @@ public SingleFieldBuilderV3 clear() {
                 ? message.getDefaultInstanceForType()
                 : builder.getDefaultInstanceForType());
     if (builder != null) {
-//      builder.dispose();
+      builder.dispose();
       builder = null;
     }
     onChanged();
diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/compiler/PluginProtos.java b/protobuf-sdk/src/main/java/com/google/protobuf/compiler/PluginProtos.java
index a9fb84e..6f80eff 100644
--- a/protobuf-sdk/src/main/java/com/google/protobuf/compiler/PluginProtos.java
+++ b/protobuf-sdk/src/main/java/com/google/protobuf/compiler/PluginProtos.java
@@ -4,6 +4,8 @@
 // Protobuf Java Version: 3.25.5
 package com.google.protobuf.compiler;
 
+import java.util.Map;
+
 public final class PluginProtos {
   private PluginProtos() {}
   public static void registerAllExtensions(
@@ -2549,7 +2551,7 @@ private void ensureProtoFileIsMutable() {
          }
       }
 
-      private com.google.protobuf.RepeatedFieldBuilderV3<
+      private com.google.protobuf.compiler.RepeatedFieldBuilderV3Internal<
           com.google.protobuf.DescriptorProtos.FileDescriptorProto, com.google.protobuf.DescriptorProtos.FileDescriptorProto.Builder, com.google.protobuf.DescriptorProtos.FileDescriptorProtoOrBuilder> protoFileBuilder_;
 
       /**
@@ -3161,11 +3163,11 @@ public com.google.protobuf.DescriptorProtos.FileDescriptorProto.Builder addProto
            getProtoFileBuilderList() {
         return getProtoFileFieldBuilder().getBuilderList();
       }
-      private com.google.protobuf.RepeatedFieldBuilderV3<
+      private com.google.protobuf.compiler.RepeatedFieldBuilderV3Internal<
           com.google.protobuf.DescriptorProtos.FileDescriptorProto, com.google.protobuf.DescriptorProtos.FileDescriptorProto.Builder, com.google.protobuf.DescriptorProtos.FileDescriptorProtoOrBuilder> 
           getProtoFileFieldBuilder() {
         if (protoFileBuilder_ == null) {
-          protoFileBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
+          protoFileBuilder_ = new com.google.protobuf.compiler.RepeatedFieldBuilderV3Internal<
               com.google.protobuf.DescriptorProtos.FileDescriptorProto, com.google.protobuf.DescriptorProtos.FileDescriptorProto.Builder, com.google.protobuf.DescriptorProtos.FileDescriptorProtoOrBuilder>(
                   protoFile_,
                   ((bitField0_ & 0x00000004) != 0),
@@ -3185,7 +3187,7 @@ private void ensureSourceFileDescriptorsIsMutable() {
          }
       }
 
-      private com.google.protobuf.RepeatedFieldBuilderV3<
+      private com.google.protobuf.compiler.RepeatedFieldBuilderV3Internal<
           com.google.protobuf.DescriptorProtos.FileDescriptorProto, com.google.protobuf.DescriptorProtos.FileDescriptorProto.Builder, com.google.protobuf.DescriptorProtos.FileDescriptorProtoOrBuilder> sourceFileDescriptorsBuilder_;
 
       /**
@@ -3509,11 +3511,11 @@ public com.google.protobuf.DescriptorProtos.FileDescriptorProto.Builder addSourc
            getSourceFileDescriptorsBuilderList() {
         return getSourceFileDescriptorsFieldBuilder().getBuilderList();
       }
-      private com.google.protobuf.RepeatedFieldBuilderV3<
+      private com.google.protobuf.compiler.RepeatedFieldBuilderV3Internal<
           com.google.protobuf.DescriptorProtos.FileDescriptorProto, com.google.protobuf.DescriptorProtos.FileDescriptorProto.Builder, com.google.protobuf.DescriptorProtos.FileDescriptorProtoOrBuilder> 
           getSourceFileDescriptorsFieldBuilder() {
         if (sourceFileDescriptorsBuilder_ == null) {
-          sourceFileDescriptorsBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
+          sourceFileDescriptorsBuilder_ = new com.google.protobuf.compiler.RepeatedFieldBuilderV3Internal<
               com.google.protobuf.DescriptorProtos.FileDescriptorProto, com.google.protobuf.DescriptorProtos.FileDescriptorProto.Builder, com.google.protobuf.DescriptorProtos.FileDescriptorProtoOrBuilder>(
                   sourceFileDescriptors_,
                   ((bitField0_ & 0x00000008) != 0),
@@ -3525,7 +3527,7 @@ public com.google.protobuf.DescriptorProtos.FileDescriptorProto.Builder addSourc
       }
 
       private com.google.protobuf.compiler.PluginProtos.Version compilerVersion_;
-      private com.google.protobuf.SingleFieldBuilderV3<
+      private com.google.protobuf.compiler.SingleFieldBuilderV3Internal<
           com.google.protobuf.compiler.PluginProtos.Version, com.google.protobuf.compiler.PluginProtos.Version.Builder, com.google.protobuf.compiler.PluginProtos.VersionOrBuilder> compilerVersionBuilder_;
       /**
        * 
@@ -3667,11 +3669,11 @@ public com.google.protobuf.compiler.PluginProtos.VersionOrBuilder getCompilerVer
        *
        * optional .google.protobuf.compiler.Version compiler_version = 3;
        */
-      private com.google.protobuf.SingleFieldBuilderV3<
+      private com.google.protobuf.compiler.SingleFieldBuilderV3Internal<
           com.google.protobuf.compiler.PluginProtos.Version, com.google.protobuf.compiler.PluginProtos.Version.Builder, com.google.protobuf.compiler.PluginProtos.VersionOrBuilder> 
           getCompilerVersionFieldBuilder() {
         if (compilerVersionBuilder_ == null) {
-          compilerVersionBuilder_ = new com.google.protobuf.SingleFieldBuilderV3<
+          compilerVersionBuilder_ = new com.google.protobuf.compiler.SingleFieldBuilderV3Internal<
               com.google.protobuf.compiler.PluginProtos.Version, com.google.protobuf.compiler.PluginProtos.Version.Builder, com.google.protobuf.compiler.PluginProtos.VersionOrBuilder>(
                   getCompilerVersion(),
                   getParentForChildren(),
@@ -5743,7 +5745,7 @@ public Builder setContentBytes(
         }
 
         private com.google.protobuf.DescriptorProtos.GeneratedCodeInfo generatedCodeInfo_;
-        private com.google.protobuf.SingleFieldBuilderV3<
+        private com.google.protobuf.compiler.SingleFieldBuilderV3Internal<
             com.google.protobuf.DescriptorProtos.GeneratedCodeInfo, com.google.protobuf.DescriptorProtos.GeneratedCodeInfo.Builder, com.google.protobuf.DescriptorProtos.GeneratedCodeInfoOrBuilder> generatedCodeInfoBuilder_;
         /**
          * 
@@ -5903,11 +5905,11 @@ public com.google.protobuf.DescriptorProtos.GeneratedCodeInfoOrBuilder getGenera
          *
          * optional .google.protobuf.GeneratedCodeInfo generated_code_info = 16;
          */
-        private com.google.protobuf.SingleFieldBuilderV3<
+        private com.google.protobuf.compiler.SingleFieldBuilderV3Internal<
             com.google.protobuf.DescriptorProtos.GeneratedCodeInfo, com.google.protobuf.DescriptorProtos.GeneratedCodeInfo.Builder, com.google.protobuf.DescriptorProtos.GeneratedCodeInfoOrBuilder> 
             getGeneratedCodeInfoFieldBuilder() {
           if (generatedCodeInfoBuilder_ == null) {
-            generatedCodeInfoBuilder_ = new com.google.protobuf.SingleFieldBuilderV3<
+            generatedCodeInfoBuilder_ = new com.google.protobuf.compiler.SingleFieldBuilderV3Internal<
                 com.google.protobuf.DescriptorProtos.GeneratedCodeInfo, com.google.protobuf.DescriptorProtos.GeneratedCodeInfo.Builder, com.google.protobuf.DescriptorProtos.GeneratedCodeInfoOrBuilder>(
                     getGeneratedCodeInfo(),
                     getParentForChildren(),
@@ -7048,7 +7050,7 @@ private void ensureFileIsMutable() {
          }
       }
 
-      private com.google.protobuf.RepeatedFieldBuilderV3<
+      private com.google.protobuf.compiler.RepeatedFieldBuilderV3Internal<
           com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse.File, com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse.File.Builder, com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse.FileOrBuilder> fileBuilder_;
 
       /**
@@ -7264,11 +7266,11 @@ public com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse.File.Buil
            getFileBuilderList() {
         return getFileFieldBuilder().getBuilderList();
       }
-      private com.google.protobuf.RepeatedFieldBuilderV3<
+      private com.google.protobuf.compiler.RepeatedFieldBuilderV3Internal<
           com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse.File, com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse.File.Builder, com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse.FileOrBuilder> 
           getFileFieldBuilder() {
         if (fileBuilder_ == null) {
-          fileBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
+          fileBuilder_ = new com.google.protobuf.compiler.RepeatedFieldBuilderV3Internal<
               com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse.File, com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse.File.Builder, com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse.FileOrBuilder>(
                   file_,
                   ((bitField0_ & 0x00000010) != 0),
diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/compiler/RepeatedFieldBuilderV3Internal.java b/protobuf-sdk/src/main/java/com/google/protobuf/compiler/RepeatedFieldBuilderV3Internal.java
new file mode 100644
index 0000000..3390aa9
--- /dev/null
+++ b/protobuf-sdk/src/main/java/com/google/protobuf/compiler/RepeatedFieldBuilderV3Internal.java
@@ -0,0 +1,656 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc.  All rights reserved.
+//
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file or at
+// https://developers.google.com/open-source/licenses/bsd
+
+package com.google.protobuf.compiler;
+
+import com.google.protobuf.Message;
+import com.google.protobuf.MessageOrBuilder;
+
+import java.util.AbstractList;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.RandomAccess;
+
+
+/**
+ * {@code RepeatedFieldBuilderV3} implements a structure that a protocol message uses to hold a
+ * repeated field of other protocol messages. It supports the classical use case of adding immutable
+ * {@link Message}'s to the repeated field and is highly optimized around this (no extra memory
+ * allocations and sharing of immutable arrays). 
+ * It also supports the additional use case of adding a {@link Message.Builder} to the repeated + * field and deferring conversion of that {@code Builder} to an immutable {@code Message}. In this + * way, it's possible to maintain a tree of {@code Builder}'s that acts as a fully read/write data + * structure.
+ * Logically, one can think of a tree of builders as converting the entire tree to messages when + * build is called on the root or when any method is called that desires a Message instead of a + * Builder. In terms of the implementation, the {@code SingleFieldBuilderV3} and {@code + * RepeatedFieldBuilderV3} classes cache messages that were created so that messages only need to be + * created when some change occurred in its builder or a builder for one of its descendants. + * + * @param the type of message for the field + * @param the type of builder for the field + * @param the common interface for the message and the builder + * @author jonp@google.com (Jon Perlow) + */ +class RepeatedFieldBuilderV3Internal< + MType extends Message, + BType extends Message.Builder, + IType extends MessageOrBuilder> + implements Message.BuilderParent { + + // Parent to send changes to. + private Message.BuilderParent parent; + + // List of messages. Never null. It may be immutable, in which case + // isMessagesListMutable will be false. See note below. + private List messages; + + // Whether messages is an mutable array that can be modified. + private boolean isMessagesListMutable; + + // List of builders. May be null, in which case, no nested builders were + // created. If not null, entries represent the builder for that index. + private List> builders; + + // Here are the invariants for messages and builders: + // 1. messages is never null and its count corresponds to the number of items + // in the repeated field. + // 2. If builders is non-null, messages and builders MUST always + // contain the same number of items. + // 3. Entries in either array can be null, but for any index, there MUST be + // either a Message in messages or a builder in builders. + // 4. If the builder at an index is non-null, the builder is + // authoritative. This is the case where a Builder was set on the index. + // Any message in the messages array MUST be ignored. + // t. If the builder at an index is null, the message in the messages + // list is authoritative. This is the case where a Message (not a Builder) + // was set directly for an index. + + // Indicates that we've built a message and so we are now obligated + // to dispatch dirty invalidations. See AbstractMessage.BuilderListener. + private boolean isClean; + + // A view of this builder that exposes a List interface of messages. This is + // initialized on demand. This is fully backed by this object and all changes + // are reflected in it. Access to any item converts it to a message if it + // was a builder. + private MessageExternalList externalMessageList; + + // A view of this builder that exposes a List interface of builders. This is + // initialized on demand. This is fully backed by this object and all changes + // are reflected in it. Access to any item converts it to a builder if it + // was a message. + private BuilderExternalList externalBuilderList; + + // A view of this builder that exposes a List interface of the interface + // implemented by messages and builders. This is initialized on demand. This + // is fully backed by this object and all changes are reflected in it. + // Access to any item returns either a builder or message depending on + // what is most efficient. + private MessageOrBuilderExternalList externalMessageOrBuilderList; + + /** + * Constructs a new builder with an empty list of messages. + * + * @param messages the current list of messages + * @param isMessagesListMutable Whether the messages list is mutable + * @param parent a listener to notify of changes + * @param isClean whether the builder is initially marked clean + */ + public RepeatedFieldBuilderV3Internal( + List messages, + boolean isMessagesListMutable, + Message.BuilderParent parent, + boolean isClean) { + this.messages = messages; + this.isMessagesListMutable = isMessagesListMutable; + this.parent = parent; + this.isClean = isClean; + } + + public void dispose() { + // Null out parent so we stop sending it invalidations. + parent = null; + } + + /** + * Ensures that the list of messages is mutable so it can be updated. If it's immutable, a copy is + * made. + */ + private void ensureMutableMessageList() { + if (!isMessagesListMutable) { + messages = new ArrayList(messages); + isMessagesListMutable = true; + } + } + + /** + * Ensures that the list of builders is not null. If it's null, the list is created and + * initialized to be the same size as the messages list with null entries. + */ + private void ensureBuilders() { + if (this.builders == null) { + this.builders = new ArrayList>(messages.size()); + for (int i = 0; i < messages.size(); i++) { + builders.add(null); + } + } + } + + /** + * Gets the count of items in the list. + * + * @return the count of items in the list. + */ + public int getCount() { + return messages.size(); + } + + /** + * Gets whether the list is empty. + * + * @return whether the list is empty + */ + public boolean isEmpty() { + return messages.isEmpty(); + } + + /** + * Get the message at the specified index. If the message is currently stored as a {@code + * Builder}, it is converted to a {@code Message} by calling {@link Message.Builder#buildPartial} + * on it. + * + * @param index the index of the message to get + * @return the message for the specified index + */ + public MType getMessage(int index) { + return getMessage(index, false); + } + + /** + * Get the message at the specified index. If the message is currently stored as a {@code + * Builder}, it is converted to a {@code Message} by calling {@link Message.Builder#buildPartial} + * on it. + * + * @param index the index of the message to get + * @param forBuild this is being called for build so we want to make sure we + * SingleFieldBuilderV3.build to send dirty invalidations + * @return the message for the specified index + */ + private MType getMessage(int index, boolean forBuild) { + if (this.builders == null) { + // We don't have any builders -- return the current Message. + // This is the case where no builder was created, so we MUST have a + // Message. + return messages.get(index); + } + + SingleFieldBuilderV3Internal builder = builders.get(index); + if (builder == null) { + // We don't have a builder -- return the current message. + // This is the case where no builder was created for the entry at index, + // so we MUST have a message. + return messages.get(index); + + } else { + return forBuild ? builder.build() : builder.getMessage(); + } + } + + /** + * Gets a builder for the specified index. If no builder has been created for that index, a + * builder is created on demand by calling {@link Message#toBuilder}. + * + * @param index the index of the message to get + * @return The builder for that index + */ + public BType getBuilder(int index) { + ensureBuilders(); + SingleFieldBuilderV3Internal builder = builders.get(index); + if (builder == null) { + MType message = messages.get(index); + builder = new SingleFieldBuilderV3Internal(message, this, isClean); + builders.set(index, builder); + } + return builder.getBuilder(); + } + + /** + * Gets the base class interface for the specified index. This may either be a builder or a + * message. It will return whatever is more efficient. + * + * @param index the index of the message to get + * @return the message or builder for the index as the base class interface + */ + @SuppressWarnings("unchecked") + public IType getMessageOrBuilder(int index) { + if (this.builders == null) { + // We don't have any builders -- return the current Message. + // This is the case where no builder was created, so we MUST have a + // Message. + return (IType) messages.get(index); + } + + SingleFieldBuilderV3Internal builder = builders.get(index); + if (builder == null) { + // We don't have a builder -- return the current message. + // This is the case where no builder was created for the entry at index, + // so we MUST have a message. + return (IType) messages.get(index); + + } else { + return builder.getMessageOrBuilder(); + } + } + + static T checkNotNull(T obj) { + if (obj == null) { + throw new NullPointerException(); + } + return obj; + } + + /** + * Sets a message at the specified index replacing the existing item at that index. + * + * @param index the index to set. + * @param message the message to set + * @return the builder + */ +// @CanIgnoreReturnValue + public RepeatedFieldBuilderV3Internal setMessage(int index, MType message) { + checkNotNull(message); + ensureMutableMessageList(); + messages.set(index, message); + if (builders != null) { + SingleFieldBuilderV3Internal entry = builders.set(index, null); + if (entry != null) { + entry.dispose(); + } + } + onChanged(); + incrementModCounts(); + return this; + } + + /** + * Appends the specified element to the end of this list. + * + * @param message the message to add + * @return the builder + */ +// @CanIgnoreReturnValue + public RepeatedFieldBuilderV3Internal addMessage(MType message) { + checkNotNull(message); + ensureMutableMessageList(); + messages.add(message); + if (builders != null) { + builders.add(null); + } + onChanged(); + incrementModCounts(); + return this; + } + + /** + * Inserts the specified message at the specified position in this list. Shifts the element + * currently at that position (if any) and any subsequent elements to the right (adds one to their + * indices). + * + * @param index the index at which to insert the message + * @param message the message to add + * @return the builder + */ +// @CanIgnoreReturnValue + public RepeatedFieldBuilderV3Internal addMessage(int index, MType message) { + checkNotNull(message); + ensureMutableMessageList(); + messages.add(index, message); + if (builders != null) { + builders.add(index, null); + } + onChanged(); + incrementModCounts(); + return this; + } + + /** + * Appends all of the messages in the specified collection to the end of this list, in the order + * that they are returned by the specified collection's iterator. + * + * @param values the messages to add + * @return the builder + */ +// @CanIgnoreReturnValue + public RepeatedFieldBuilderV3Internal addAllMessages( + Iterable values) { + for (final MType value : values) { + checkNotNull(value); + } + + // If we can inspect the size, we can more efficiently add messages. + int size = -1; + if (values instanceof Collection) { + final Collection collection = (Collection) values; + if (collection.isEmpty()) { + return this; + } + size = collection.size(); + } + ensureMutableMessageList(); + + if (size >= 0 && messages instanceof ArrayList) { + ((ArrayList) messages).ensureCapacity(messages.size() + size); + } + + for (MType value : values) { + addMessage(value); + } + + onChanged(); + incrementModCounts(); + return this; + } + + /** + * Appends a new builder to the end of this list and returns the builder. + * + * @param message the message to add which is the basis of the builder + * @return the new builder + */ + public BType addBuilder(MType message) { + ensureMutableMessageList(); + ensureBuilders(); + SingleFieldBuilderV3Internal builder = + new SingleFieldBuilderV3Internal(message, this, isClean); + messages.add(null); + builders.add(builder); + onChanged(); + incrementModCounts(); + return builder.getBuilder(); + } + + /** + * Inserts a new builder at the specified position in this list. Shifts the element currently at + * that position (if any) and any subsequent elements to the right (adds one to their indices). + * + * @param index the index at which to insert the builder + * @param message the message to add which is the basis of the builder + * @return the builder + */ + public BType addBuilder(int index, MType message) { + ensureMutableMessageList(); + ensureBuilders(); + SingleFieldBuilderV3Internal builder = + new SingleFieldBuilderV3Internal(message, this, isClean); + messages.add(index, null); + builders.add(index, builder); + onChanged(); + incrementModCounts(); + return builder.getBuilder(); + } + + /** + * Removes the element at the specified position in this list. Shifts any subsequent elements to + * the left (subtracts one from their indices). + * + * @param index the index at which to remove the message + */ + public void remove(int index) { + ensureMutableMessageList(); + messages.remove(index); + if (builders != null) { + SingleFieldBuilderV3Internal entry = builders.remove(index); + if (entry != null) { + entry.dispose(); + } + } + onChanged(); + incrementModCounts(); + } + + /** Removes all of the elements from this list. The list will be empty after this call returns. */ + public void clear() { + messages = Collections.emptyList(); + isMessagesListMutable = false; + if (builders != null) { + for (SingleFieldBuilderV3Internal entry : builders) { + if (entry != null) { + entry.dispose(); + } + } + builders = null; + } + onChanged(); + incrementModCounts(); + } + + /** + * Builds the list of messages from the builder and returns them. + * + * @return an immutable list of messages + */ + public List build() { + // Now that build has been called, we are required to dispatch + // invalidations. + isClean = true; + + if (!isMessagesListMutable && builders == null) { + // We still have an immutable list and we never created a builder. + return messages; + } + + boolean allMessagesInSync = true; + if (!isMessagesListMutable) { + // We still have an immutable list. Let's see if any of them are out + // of sync with their builders. + for (int i = 0; i < messages.size(); i++) { + Message message = messages.get(i); + SingleFieldBuilderV3Internal builder = builders.get(i); + if (builder != null) { + if (builder.build() != message) { + allMessagesInSync = false; + break; + } + } + } + if (allMessagesInSync) { + // Immutable list is still in sync. + return messages; + } + } + + // Need to make sure messages is up to date + ensureMutableMessageList(); + for (int i = 0; i < messages.size(); i++) { + messages.set(i, getMessage(i, true)); + } + + // We're going to return our list as immutable so we mark that we can + // no longer update it. + messages = Collections.unmodifiableList(messages); + isMessagesListMutable = false; + return messages; + } + + /** + * Gets a view of the builder as a list of messages. The returned list is live and will reflect + * any changes to the underlying builder. + * + * @return the messages in the list + */ + public List getMessageList() { + if (externalMessageList == null) { + externalMessageList = new MessageExternalList(this); + } + return externalMessageList; + } + + /** + * Gets a view of the builder as a list of builders. This returned list is live and will reflect + * any changes to the underlying builder. + * + * @return the builders in the list + */ + public List getBuilderList() { + if (externalBuilderList == null) { + externalBuilderList = new BuilderExternalList(this); + } + return externalBuilderList; + } + + /** + * Gets a view of the builder as a list of MessageOrBuilders. This returned list is live and will + * reflect any changes to the underlying builder. + * + * @return the builders in the list + */ + public List getMessageOrBuilderList() { + if (externalMessageOrBuilderList == null) { + externalMessageOrBuilderList = new MessageOrBuilderExternalList(this); + } + return externalMessageOrBuilderList; + } + + /** + * Called when a the builder or one of its nested children has changed and any parent should be + * notified of its invalidation. + */ + private void onChanged() { + if (isClean && parent != null) { + parent.markDirty(); + + // Don't keep dispatching invalidations until build is called again. + isClean = false; + } + } + + @Override + public void markDirty() { + onChanged(); + } + + /** + * Increments the mod counts so that an ConcurrentModificationException can be thrown if calling + * code tries to modify the builder while its iterating the list. + */ + private void incrementModCounts() { + if (externalMessageList != null) { + externalMessageList.incrementModCount(); + } + if (externalBuilderList != null) { + externalBuilderList.incrementModCount(); + } + if (externalMessageOrBuilderList != null) { + externalMessageOrBuilderList.incrementModCount(); + } + } + + /** + * Provides a live view of the builder as a list of messages. + * + * @param the type of message for the field + * @param the type of builder for the field + * @param the common interface for the message and the builder + */ + private static class MessageExternalList< + MType extends Message, + BType extends Message.Builder, + IType extends MessageOrBuilder> + extends AbstractList implements List, RandomAccess { + + RepeatedFieldBuilderV3Internal builder; + + MessageExternalList(RepeatedFieldBuilderV3Internal builder) { + this.builder = builder; + } + + @Override + public int size() { + return this.builder.getCount(); + } + + @Override + public MType get(int index) { + return builder.getMessage(index); + } + + void incrementModCount() { + modCount++; + } + } + + /** + * Provides a live view of the builder as a list of builders. + * + * @param the type of message for the field + * @param the type of builder for the field + * @param the common interface for the message and the builder + */ + private static class BuilderExternalList< + MType extends Message, + BType extends Message.Builder, + IType extends MessageOrBuilder> + extends AbstractList implements List, RandomAccess { + + RepeatedFieldBuilderV3Internal builder; + + BuilderExternalList(RepeatedFieldBuilderV3Internal builder) { + this.builder = builder; + } + + @Override + public int size() { + return this.builder.getCount(); + } + + @Override + public BType get(int index) { + return builder.getBuilder(index); + } + + void incrementModCount() { + modCount++; + } + } + + /** + * Provides a live view of the builder as a list of builders. + * + * @param the type of message for the field + * @param the type of builder for the field + * @param the common interface for the message and the builder + */ + private static class MessageOrBuilderExternalList< + MType extends Message, + BType extends Message.Builder, + IType extends MessageOrBuilder> + extends AbstractList implements List, RandomAccess { + + RepeatedFieldBuilderV3Internal builder; + + MessageOrBuilderExternalList(RepeatedFieldBuilderV3Internal builder) { + this.builder = builder; + } + + @Override + public int size() { + return this.builder.getCount(); + } + + @Override + public IType get(int index) { + return builder.getMessageOrBuilder(index); + } + + void incrementModCount() { + modCount++; + } + } +} diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/compiler/SingleFieldBuilderV3Internal.java b/protobuf-sdk/src/main/java/com/google/protobuf/compiler/SingleFieldBuilderV3Internal.java new file mode 100644 index 0000000..da0cd92 --- /dev/null +++ b/protobuf-sdk/src/main/java/com/google/protobuf/compiler/SingleFieldBuilderV3Internal.java @@ -0,0 +1,219 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd + +package com.google.protobuf.compiler; + +import com.google.protobuf.Message; +import com.google.protobuf.MessageOrBuilder; + +/** + * {@code SingleFieldBuilderV3} implements a structure that a protocol message uses to hold a single + * field of another protocol message. It supports the classical use case of setting an immutable + * {@link Message} as the value of the field and is highly optimized around this. + * + *

It also supports the additional use case of setting a {@link Message.Builder} as the field and + * deferring conversion of that {@code Builder} to an immutable {@code Message}. In this way, it's + * possible to maintain a tree of {@code Builder}'s that acts as a fully read/write data structure. + *
+ * Logically, one can think of a tree of builders as converting the entire tree to messages when + * build is called on the root or when any method is called that desires a Message instead of a + * Builder. In terms of the implementation, the {@code SingleFieldBuilderV3} and {@code + * RepeatedFieldBuilderV3} classes cache messages that were created so that messages only need to be + * created when some change occurred in its builder or a builder for one of its descendants. + * + * @param the type of message for the field + * @param the type of builder for the field + * @param the common interface for the message and the builder + * @author jonp@google.com (Jon Perlow) + */ +class SingleFieldBuilderV3Internal< + MType extends Message, + BType extends Message.Builder, + IType extends MessageOrBuilder> + implements Message.BuilderParent { + + // Parent to send changes to. + private Message.BuilderParent parent; + + // Invariant: one of builder or message fields must be non-null. + + // If set, this is the case where we are backed by a builder. In this case, + // message field represents a cached message for the builder (or null if + // there is no cached message). + private BType builder; + + // If builder is non-null, this represents a cached message from the builder. + // If builder is null, this is the authoritative message for the field. + private MType message; + + // Indicates that we've built a message and so we are now obligated + // to dispatch dirty invalidations. See AbstractMessage.BuilderListener. + private boolean isClean; + + public SingleFieldBuilderV3Internal(MType message, Message.BuilderParent parent, boolean isClean) { + this.message = checkNotNull(message); + this.parent = parent; + this.isClean = isClean; + } + + public void dispose() { + // Null out parent so we stop sending it invalidations. + parent = null; + } + + /** + * Get the message for the field. If the message is currently stored as a {@code Builder}, it is + * converted to a {@code Message} by calling {@link Message.Builder#buildPartial} on it. If no + * message has been set, returns the default instance of the message. + * + * @return the message for the field + */ + @SuppressWarnings("unchecked") + public MType getMessage() { + if (message == null) { + // If message is null, the invariant is that we must be have a builder. + message = (MType) builder.buildPartial(); + } + return message; + } + + /** + * Builds the message and returns it. + * + * @return the message + */ + public MType build() { + // Now that build has been called, we are required to dispatch + // invalidations. + isClean = true; + return getMessage(); + } + + /** + * Gets a builder for the field. If no builder has been created yet, a builder is created on + * demand by calling {@link Message#toBuilder}. + * + * @return The builder for the field + */ + @SuppressWarnings("unchecked") + public BType getBuilder() { + if (builder == null) { + // builder.mergeFrom() on a fresh builder + // does not create any sub-objects with independent clean/dirty states, + // therefore setting the builder itself to clean without actually calling + // build() cannot break any invariants. + builder = (BType) message.newBuilderForType(); + builder.mergeFrom(message); // no-op if message is the default message +// builder.markClean(); + } + return builder; + } + + /** + * Gets the base class interface for the field. This may either be a builder or a message. It will + * return whatever is more efficient. + * + * @return the message or builder for the field as the base class interface + */ + @SuppressWarnings("unchecked") + public IType getMessageOrBuilder() { + if (builder != null) { + return (IType) builder; + } else { + return (IType) message; + } + } + + /** + * Sets a message for the field replacing any existing value. + * + * @param message the message to set + * @return the builder + */ + // Comment out because CanIgnoreReturnValue is package private to com.google.protobuf +// @CanIgnoreReturnValue + public SingleFieldBuilderV3Internal setMessage(MType message) { + this.message = checkNotNull(message); + if (builder != null) { +// builder.dispose(); + builder = null; + } + onChanged(); + return this; + } + + /** + * Merges the field from another field. + * + * @param value the value to merge from + * @return the builder + */ +// @CanIgnoreReturnValue + public SingleFieldBuilderV3Internal mergeFrom(MType value) { + if (builder == null && message == message.getDefaultInstanceForType()) { + message = value; + } else { + getBuilder().mergeFrom(value); + } + onChanged(); + return this; + } + + /** + * Clears the value of the field. + * + * @return the builder + */ + @SuppressWarnings("unchecked") +// @CanIgnoreReturnValue + public SingleFieldBuilderV3Internal clear() { + message = + (MType) + (message != null + ? message.getDefaultInstanceForType() + : builder.getDefaultInstanceForType()); + if (builder != null) { +// builder.dispose(); + builder = null; + } + onChanged(); + // After clearing, parent is dirty, but this field builder is now clean and any changes should + // trickle up. + isClean = true; + return this; + } + + /** + * Called when a the builder or one of its nested children has changed and any parent should be + * notified of its invalidation. + */ + private void onChanged() { + // If builder is null, this is the case where onChanged is being called + // from setMessage or clear. + if (builder != null) { + message = null; + } + if (isClean && parent != null) { + parent.markDirty(); + + // Don't keep dispatching invalidations until build is called again. + isClean = false; + } + } + + static T checkNotNull(T obj) { + if (obj == null) { + throw new NullPointerException(); + } + return obj; + } + + @Override + public void markDirty() { + onChanged(); + } +} From db446fd5988eb8c472f3c016fa358d14ef2774da Mon Sep 17 00:00:00 2001 From: blakeli Date: Fri, 6 Jun 2025 14:24:33 -0400 Subject: [PATCH 37/42] Revert reflection usages for GeneratedMessageLite in ExtensionRegistryLite because we are not going to move GeneratedMessageLite. --- .../protobuf/ExtensionRegistryLite.java | 37 ++++++------------- 1 file changed, 11 insertions(+), 26 deletions(-) diff --git a/protobuf-api/src/main/java/com/google/protobuf/ExtensionRegistryLite.java b/protobuf-api/src/main/java/com/google/protobuf/ExtensionRegistryLite.java index 03a2761..0bd38f6 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/ExtensionRegistryLite.java +++ b/protobuf-api/src/main/java/com/google/protobuf/ExtensionRegistryLite.java @@ -73,19 +73,6 @@ static Class resolveExtensionClass() { } } } - private static final Class GENERATED_EXTENSION = getGeneratedExtensionClass(); - - private static Class getGeneratedExtensionClass() { - try { - Class generatedMessageLiteClass = Class.forName("com.google.protobuf.GeneratedMessageLite"); - return Arrays.stream(generatedMessageLiteClass.getClasses()) - .filter(innerClass -> innerClass.getName().equals("com.google.protobuf.GeneratedMessageLite$GeneratedExtension")) - .findFirst() - .get(); - } catch (Throwable e) { - return null; - } - } public static boolean isEagerlyParseMessageSets() { return eagerlyParseMessageSets; @@ -141,35 +128,33 @@ public ExtensionRegistryLite getUnmodifiable() { */ @SuppressWarnings("unchecked") public - ExtensionLite findLiteExtensionByNumber( + GeneratedMessageLite.GeneratedExtension findLiteExtensionByNumber( final ContainingType containingTypeDefaultInstance, final int fieldNumber) { - return (ExtensionLite) - extensionsByNumber.get(new ObjectIntPair(containingTypeDefaultInstance, fieldNumber)); + return (GeneratedMessageLite.GeneratedExtension) + extensionsByNumber.get(new ObjectIntPair(containingTypeDefaultInstance, fieldNumber)); } /** Add an extension from a lite generated file to the registry. */ -// public final void add(final ExtensionLite extension) { -// extensionsByNumber.put( -// new ObjectIntPair(extension, extension.getNumber()), -// extension); -// } + public final void add(final GeneratedMessageLite.GeneratedExtension extension) { + extensionsByNumber.put( + new ObjectIntPair(extension.getContainingTypeDefaultInstance(), extension.getNumber()), + extension); + } /** * Add an extension from a lite generated file to the registry only if it is a non-lite extension * i.e. {@link GeneratedMessageLite.GeneratedExtension}. */ public final void add(ExtensionLite extension) { - if (GENERATED_EXTENSION.isAssignableFrom(extension.getClass())) { - extensionsByNumber.put( - new ObjectIntPair(extension, extension.getNumber()), - extension); + if (GeneratedMessageLite.GeneratedExtension.class.isAssignableFrom(extension.getClass())) { + add((GeneratedMessageLite.GeneratedExtension) extension); } if (doFullRuntimeInheritanceCheck && ExtensionRegistryFactory.isFullRegistry(this)) { try { this.getClass().getMethod("add", ExtensionClassHolder.INSTANCE).invoke(this, extension); } catch (Exception e) { throw new IllegalArgumentException( - String.format("Could not invoke ExtensionRegistry#add for %s", extension), e); + String.format("Could not invoke ExtensionRegistry#add for %s", extension), e); } } } From 018d2ef19dc0dc8a4c84ea26f32f6e62fcbe73d4 Mon Sep 17 00:00:00 2001 From: blakeli Date: Fri, 6 Jun 2025 15:02:45 -0400 Subject: [PATCH 38/42] Introduce isGenerated flag to Message. This way we can tell if a Message is generated or handwritten like DynamicMessage. --- .../main/java/com/google/protobuf/Message.java | 8 ++++++++ .../com/google/protobuf/MessageReflection.java | 17 +---------------- .../com/google/protobuf/GeneratedMessage.java | 10 ++++++++++ 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/protobuf-api/src/main/java/com/google/protobuf/Message.java b/protobuf-api/src/main/java/com/google/protobuf/Message.java index 34c765a..d025bee 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/Message.java +++ b/protobuf-api/src/main/java/com/google/protobuf/Message.java @@ -84,6 +84,10 @@ interface BuilderParent { @Override String toString(); + default boolean isGenerated() { + return false; + } + // ================================================================= // Builders @@ -284,5 +288,9 @@ Builder mergeFrom(InputStream input, ExtensionRegistryLite extensionRegistry) @Override boolean mergeDelimitedFrom(InputStream input, ExtensionRegistryLite extensionRegistry) throws IOException; + + default boolean isGenerated() { + return false; + } } } diff --git a/protobuf-api/src/main/java/com/google/protobuf/MessageReflection.java b/protobuf-api/src/main/java/com/google/protobuf/MessageReflection.java index bb5871e..7dad81d 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/MessageReflection.java +++ b/protobuf-api/src/main/java/com/google/protobuf/MessageReflection.java @@ -11,7 +11,6 @@ import com.google.protobuf.Descriptors.FieldDescriptor; import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.TreeMap; @@ -639,7 +638,7 @@ public WireFormat.Utf8Validation getUtf8Validation(Descriptors.FieldDescriptor d return WireFormat.Utf8Validation.STRICT; } // TODO: support lazy strings for repeated fields. - if (!descriptor.isRepeated() && GENERATED_MESSAGE_BUILDER.isInstance(builder)) { + if (!descriptor.isRepeated() && builder.isGenerated()) { return WireFormat.Utf8Validation.LAZY; } return WireFormat.Utf8Validation.LOOSE; @@ -651,20 +650,6 @@ public Object finish() { } } - private static final Class GENERATED_MESSAGE_BUILDER = getGeneratedMessageBuilder(); - - private static Class getGeneratedMessageBuilder() { - try { - Class generatedMessageLiteClass = Class.forName("com.google.protobuf.GeneratedMessage"); - return Arrays.stream(generatedMessageLiteClass.getClasses()) - .filter(innerClass -> innerClass.getName().equals("com.google.protobuf.GeneratedMessage$Builder")) - .findFirst() - .get(); - } catch (Throwable e) { - return null; - } - } - static class ExtensionAdapter implements MergeTarget { private final FieldSet extensions; diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/GeneratedMessage.java b/protobuf-sdk/src/main/java/com/google/protobuf/GeneratedMessage.java index 8120ed5..0a68908 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/GeneratedMessage.java +++ b/protobuf-sdk/src/main/java/com/google/protobuf/GeneratedMessage.java @@ -54,6 +54,11 @@ protected GeneratedMessage(Builder builder) { unknownFields = builder.getUnknownFields(); } + @Override + public boolean isGenerated() { + return true; + } + @Override public Parser getParserForType() { throw new UnsupportedOperationException("This is supposed to be overridden by subclasses."); @@ -358,6 +363,11 @@ protected Builder(BuilderParent builderParent) { this.builderParent = builderParent; } + @Override + public boolean isGenerated() { + return true; + } + @Override void dispose() { builderParent = null; From 3e8d30dc6d9225a69e16352f4b302d043802a000 Mon Sep 17 00:00:00 2001 From: blakeli Date: Mon, 9 Jun 2025 16:40:49 -0400 Subject: [PATCH 39/42] Introduce GeneratedMessageV3Internal, GeneratedMessageInternal, AbstractMessageInternal. Use these internal classes instead of flattened classes in gen code. --- .../protobuf/AbstractMessageInternal.java | 582 +++ .../main/java/com/google/protobuf/Any.java | 34 +- .../java/com/google/protobuf/AnyProto.java | 4 +- .../main/java/com/google/protobuf/Api.java | 50 +- .../java/com/google/protobuf/ApiProto.java | 12 +- .../java/com/google/protobuf/BoolValue.java | 26 +- .../java/com/google/protobuf/BytesValue.java | 26 +- .../com/google/protobuf/DescriptorProtos.java | 1366 +++---- .../java/com/google/protobuf/DoubleValue.java | 26 +- .../java/com/google/protobuf/Duration.java | 26 +- .../com/google/protobuf/DurationProto.java | 4 +- .../main/java/com/google/protobuf/Empty.java | 26 +- .../java/com/google/protobuf/EmptyProto.java | 4 +- .../main/java/com/google/protobuf/Enum.java | 48 +- .../java/com/google/protobuf/EnumValue.java | 36 +- .../main/java/com/google/protobuf/Field.java | 60 +- .../java/com/google/protobuf/FieldMask.java | 28 +- .../com/google/protobuf/FieldMaskProto.java | 4 +- .../java/com/google/protobuf/FloatValue.java | 26 +- .../protobuf/GeneratedMessageInternal.java | 2987 ++++++++++++++ .../protobuf/GeneratedMessageV3Internal.java | 3414 +++++++++++++++++ .../java/com/google/protobuf/Int32Value.java | 26 +- .../java/com/google/protobuf/Int64Value.java | 26 +- .../java/com/google/protobuf/ListValue.java | 28 +- .../main/java/com/google/protobuf/Method.java | 52 +- .../main/java/com/google/protobuf/Mixin.java | 42 +- .../main/java/com/google/protobuf/Option.java | 36 +- .../java/com/google/protobuf/StringValue.java | 34 +- .../main/java/com/google/protobuf/Struct.java | 28 +- .../java/com/google/protobuf/StructProto.java | 16 +- .../java/com/google/protobuf/Timestamp.java | 26 +- .../com/google/protobuf/TimestampProto.java | 4 +- .../main/java/com/google/protobuf/Type.java | 50 +- .../java/com/google/protobuf/TypeProto.java | 20 +- .../java/com/google/protobuf/UInt32Value.java | 26 +- .../java/com/google/protobuf/UInt64Value.java | 26 +- .../main/java/com/google/protobuf/Value.java | 32 +- .../com/google/protobuf/WrappersProto.java | 36 +- 38 files changed, 8140 insertions(+), 1157 deletions(-) create mode 100644 protobuf-api/src/main/java/com/google/protobuf/AbstractMessageInternal.java create mode 100644 protobuf-api/src/main/java/com/google/protobuf/GeneratedMessageInternal.java create mode 100644 protobuf-api/src/main/java/com/google/protobuf/GeneratedMessageV3Internal.java diff --git a/protobuf-api/src/main/java/com/google/protobuf/AbstractMessageInternal.java b/protobuf-api/src/main/java/com/google/protobuf/AbstractMessageInternal.java new file mode 100644 index 0000000..e015d25 --- /dev/null +++ b/protobuf-api/src/main/java/com/google/protobuf/AbstractMessageInternal.java @@ -0,0 +1,582 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd + +package com.google.protobuf; + +import com.google.protobuf.Descriptors.EnumValueDescriptor; +import com.google.protobuf.Descriptors.FieldDescriptor; +import com.google.protobuf.Descriptors.OneofDescriptor; +import com.google.protobuf.Internal.EnumLite; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +/** + * A partial implementation of the {@link Message} interface which implements as many methods of + * that interface as possible in terms of other methods. + * + * @author kenton@google.com Kenton Varda + */ +abstract class AbstractMessageInternal + // TODO: Update GeneratedMessage to parameterize with MessageType and BuilderType. + extends AbstractMessageLite implements Message { + + @Override + public boolean isInitialized() { + return MessageReflection.isInitialized(this); + } + + /** + * Interface for the parent of a Builder that allows the builder to communicate invalidations back + * to the parent for use when using nested builders. + */ + protected interface BuilderParent extends Message.BuilderParent{ + + /** + * A builder becomes dirty whenever a field is modified -- including fields in nested builders + * -- and becomes clean when build() is called. Thus, when a builder becomes dirty, all its + * parents become dirty as well, and when it becomes clean, all its children become clean. The + * dirtiness state is used to invalidate certain cached values. + * + *

To this end, a builder calls markDirty() on its parent whenever it transitions from clean + * to dirty. The parent must propagate this call to its own parent, unless it was already dirty, + * in which case the grandparent must necessarily already be dirty as well. The parent can only + * transition back to "clean" after calling build() on all children. + */ + void markDirty(); + } + + /** Create a nested builder. */ + protected Message.Builder newBuilderForType(BuilderParent parent) { + throw new UnsupportedOperationException("Nested builder is not supported for this type."); + } + + @Override + public List findInitializationErrors() { + return MessageReflection.findMissingFields(this); + } + + @Override + public String getInitializationErrorString() { + return MessageReflection.delimitWithCommas(findInitializationErrors()); + } + + // TODO: Clear it when all subclasses have implemented this method. + @Override + public boolean hasOneof(OneofDescriptor oneof) { + throw new UnsupportedOperationException("hasOneof() is not implemented."); + } + + // TODO: Clear it when all subclasses have implemented this method. + @Override + public FieldDescriptor getOneofFieldDescriptor(OneofDescriptor oneof) { + throw new UnsupportedOperationException("getOneofFieldDescriptor() is not implemented."); + } + + @Override + public final String toString() { + return TextFormatInternal.printer().printToString(this); + } + + @Override + public void writeTo(final CodedOutputStream output) throws IOException { + MessageReflection.writeMessageTo(this, getAllFields(), output, false); + } + + protected int memoizedSize = -1; + + @Override + int getMemoizedSerializedSize() { + return memoizedSize; + } + + @Override + void setMemoizedSerializedSize(int size) { + memoizedSize = size; + } + + @Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) { + return size; + } + + memoizedSize = MessageReflection.getSerializedSize(this, getAllFields()); + return memoizedSize; + } + + @Override + public boolean equals(final Object other) { + if (other == this) { + return true; + } + if (!(other instanceof Message)) { + return false; + } + final Message otherMessage = (Message) other; + if (getDescriptorForType() != otherMessage.getDescriptorForType()) { + return false; + } + return compareFields(getAllFields(), otherMessage.getAllFields()) + && getUnknownFields().equals(otherMessage.getUnknownFields()); + } + + @Override + public int hashCode() { + int hash = memoizedHashCode; + if (hash == 0) { + hash = 41; + hash = (19 * hash) + getDescriptorForType().hashCode(); + hash = hashFields(hash, getAllFields()); + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + } + return hash; + } + + private static ByteString toByteString(Object value) { + if (value instanceof byte[]) { + return ByteString.copyFrom((byte[]) value); + } else { + return (ByteString) value; + } + } + + /** + * Compares two bytes fields. The parameters must be either a byte array or a ByteString object. + * They can be of different type though. + */ + private static boolean compareBytes(Object a, Object b) { + if (a instanceof byte[] && b instanceof byte[]) { + return Arrays.equals((byte[]) a, (byte[]) b); + } + return toByteString(a).equals(toByteString(b)); + } + + /** Converts a list of MapEntry messages into a Map used for equals() and hashCode(). */ + @SuppressWarnings({"rawtypes", "unchecked"}) + private static Map convertMapEntryListToMap(List list) { + if (list.isEmpty()) { + return Collections.emptyMap(); + } + Map result = new HashMap<>(); + Iterator iterator = list.iterator(); + Message entry = (Message) iterator.next(); + Descriptors.Descriptor descriptor = entry.getDescriptorForType(); + FieldDescriptor key = descriptor.findFieldByName("key"); + FieldDescriptor value = descriptor.findFieldByName("value"); + Object fieldValue = entry.getField(value); + if (fieldValue instanceof EnumValueDescriptor) { + fieldValue = ((EnumValueDescriptor) fieldValue).getNumber(); + } + result.put(entry.getField(key), fieldValue); + while (iterator.hasNext()) { + entry = (Message) iterator.next(); + fieldValue = entry.getField(value); + if (fieldValue instanceof EnumValueDescriptor) { + fieldValue = ((EnumValueDescriptor) fieldValue).getNumber(); + } + result.put(entry.getField(key), fieldValue); + } + return result; + } + + /** Compares two map fields. The parameters must be a list of MapEntry messages. */ + @SuppressWarnings({"rawtypes", "unchecked"}) + private static boolean compareMapField(Object a, Object b) { + Map ma = convertMapEntryListToMap((List) a); + Map mb = convertMapEntryListToMap((List) b); + return MapFieldLite.equals(ma, mb); + } + + /** + * Compares two sets of fields. This method is used to implement {@link + * AbstractMessageInternal#equals(Object)} and {@link AbstractMutableMessage#equals(Object)}. It takes + * special care of bytes fields because immutable messages and mutable messages use different Java + * type to represent a bytes field and this method should be able to compare immutable messages, + * mutable messages and also an immutable message to a mutable message. + */ + static boolean compareFields(Map a, Map b) { + if (a.size() != b.size()) { + return false; + } + for (FieldDescriptor descriptor : a.keySet()) { + if (!b.containsKey(descriptor)) { + return false; + } + Object value1 = a.get(descriptor); + Object value2 = b.get(descriptor); + if (descriptor.getType() == FieldDescriptor.Type.BYTES) { + if (descriptor.isRepeated()) { + List list1 = (List) value1; + List list2 = (List) value2; + if (list1.size() != list2.size()) { + return false; + } + for (int i = 0; i < list1.size(); i++) { + if (!compareBytes(list1.get(i), list2.get(i))) { + return false; + } + } + } else { + // Compares a singular bytes field. + if (!compareBytes(value1, value2)) { + return false; + } + } + } else if (descriptor.isMapField()) { + if (!compareMapField(value1, value2)) { + return false; + } + } else { + // Compare non-bytes fields. + if (!value1.equals(value2)) { + return false; + } + } + } + return true; + } + + /** Calculates the hash code of a map field. {@code value} must be a list of MapEntry messages. */ + @SuppressWarnings("unchecked") + private static int hashMapField(Object value) { + return MapFieldLite.calculateHashCodeForMap(convertMapEntryListToMap((List) value)); + } + + /** Get a hash code for given fields and values, using the given seed. */ + @SuppressWarnings("unchecked") + protected static int hashFields(int hash, Map map) { + for (Map.Entry entry : map.entrySet()) { + FieldDescriptor field = entry.getKey(); + Object value = entry.getValue(); + hash = (37 * hash) + field.getNumber(); + if (field.isMapField()) { + hash = (53 * hash) + hashMapField(value); + } else if (field.getType() != FieldDescriptor.Type.ENUM) { + hash = (53 * hash) + value.hashCode(); + } else if (field.isRepeated()) { + List list = (List) value; + hash = (53 * hash) + Internal.hashEnumList(list); + } else { + hash = (53 * hash) + Internal.hashEnum((EnumLite) value); + } + } + return hash; + } + + /** + * Package private helper method for AbstractParser to create UninitializedMessageException with + * missing field information. + */ + @Override + UninitializedMessageException newUninitializedMessageException() { + return Builder.newUninitializedMessageException(this); + } + + // ================================================================= + + /** + * A partial implementation of the {@link Message.Builder} interface which implements as many + * methods of that interface as possible in terms of other methods. + */ + @SuppressWarnings("unchecked") + public abstract static class Builder> + extends AbstractMessageLite.Builder implements Message.Builder { + // The compiler produces an error if this is not declared explicitly. + // Method isn't abstract to bypass Java 1.6 compiler issue: + // http://bugs.java.com/view_bug.do?bug_id=6908259 + @Override + public BuilderType clone() { + throw new UnsupportedOperationException("clone() should be implemented in subclasses."); + } + + /** TODO: Clear it when all subclasses have implemented this method. */ + @Override + public boolean hasOneof(OneofDescriptor oneof) { + throw new UnsupportedOperationException("hasOneof() is not implemented."); + } + + /** TODO: Clear it when all subclasses have implemented this method. */ + @Override + public FieldDescriptor getOneofFieldDescriptor(OneofDescriptor oneof) { + throw new UnsupportedOperationException("getOneofFieldDescriptor() is not implemented."); + } + + /** TODO: Clear it when all subclasses have implemented this method. */ + @Override + public BuilderType clearOneof(OneofDescriptor oneof) { + throw new UnsupportedOperationException("clearOneof() is not implemented."); + } + + @Override + public BuilderType clear() { + for (final Map.Entry entry : getAllFields().entrySet()) { + clearField(entry.getKey()); + } + return (BuilderType) this; + } + + @Override + public List findInitializationErrors() { + return MessageReflection.findMissingFields(this); + } + + @Override + public String getInitializationErrorString() { + return MessageReflection.delimitWithCommas(findInitializationErrors()); + } + + @Override + protected BuilderType internalMergeFrom(AbstractMessageLite other) { + return mergeFrom((Message) other); + } + + @Override + public BuilderType mergeFrom(final Message other) { + return mergeFrom(other, other.getAllFields()); + } + + BuilderType mergeFrom(final Message other, Map allFields) { + if (other.getDescriptorForType() != getDescriptorForType()) { + throw new IllegalArgumentException( + "mergeFrom(Message) can only merge messages of the same type."); + } + + // Note: We don't attempt to verify that other's fields have valid + // types. Doing so would be a losing battle. We'd have to verify + // all sub-messages as well, and we'd have to make copies of all of + // them to insure that they don't change after verification (since + // the Message interface itself cannot enforce immutability of + // implementations). + + for (final Map.Entry entry : allFields.entrySet()) { + final FieldDescriptor field = entry.getKey(); + if (field.isRepeated()) { + for (final Object element : (List) entry.getValue()) { + addRepeatedField(field, element); + } + } else if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { + final Message existingValue = (Message) getField(field); + if (existingValue == existingValue.getDefaultInstanceForType()) { + setField(field, entry.getValue()); + } else { + setField( + field, + existingValue + .newBuilderForType() + .mergeFrom(existingValue) + .mergeFrom((Message) entry.getValue()) + .build()); + } + } else { + setField(field, entry.getValue()); + } + } + + mergeUnknownFields(other.getUnknownFields()); + + return (BuilderType) this; + } + + @Override + public BuilderType mergeFrom(final CodedInputStream input) throws IOException { + return mergeFrom(input, ExtensionRegistry.getEmptyRegistry()); + } + + @Override + public BuilderType mergeFrom( + final CodedInputStream input, final ExtensionRegistryLite extensionRegistry) + throws IOException { + boolean discardUnknown = input.shouldDiscardUnknownFields(); + final UnknownFieldSet.Builder unknownFields = + discardUnknown ? null : getUnknownFieldSetBuilder(); + MessageReflection.mergeMessageFrom(this, unknownFields, input, extensionRegistry); + if (unknownFields != null) { + setUnknownFieldSetBuilder(unknownFields); + } + return (BuilderType) this; + } + + protected UnknownFieldSet.Builder getUnknownFieldSetBuilder() { + return UnknownFieldSet.newBuilder(getUnknownFields()); + } + + protected void setUnknownFieldSetBuilder(final UnknownFieldSet.Builder builder) { + setUnknownFields(builder.build()); + } + + @Override + public BuilderType mergeUnknownFields(final UnknownFieldSet unknownFields) { + setUnknownFields( + UnknownFieldSet.newBuilder(getUnknownFields()).mergeFrom(unknownFields).build()); + return (BuilderType) this; + } + + @Override + public Message.Builder getFieldBuilder(final FieldDescriptor field) { + throw new UnsupportedOperationException( + "getFieldBuilder() called on an unsupported message type."); + } + + @Override + public Message.Builder getRepeatedFieldBuilder(final FieldDescriptor field, int index) { + throw new UnsupportedOperationException( + "getRepeatedFieldBuilder() called on an unsupported message type."); + } + + @Override + public String toString() { + return TextFormatInternal.printer().printToString(this); + } + + /** Construct an UninitializedMessageException reporting missing fields in the given message. */ + protected static UninitializedMessageException newUninitializedMessageException( + Message message) { + return new UninitializedMessageException(MessageReflection.findMissingFields(message)); + } + + /** + * Used to support nested builders and called to mark this builder as clean. Clean builders will + * propagate the {@link BuilderParent#markDirty()} event to their parent builders, while dirty + * builders will not, as their parents should be dirty already. + * + *

NOTE: Implementations that don't support nested builders don't need to override this + * method. + */ + void markClean() { + throw new IllegalStateException("Should be overridden by subclasses."); + } + + /** + * Used to support nested builders and called when this nested builder is no longer used by its + * parent builder and should release the reference to its parent builder. + * + *

NOTE: Implementations that don't support nested builders don't need to override this + * method. + */ + void dispose() { + throw new IllegalStateException("Should be overridden by subclasses."); + } + + // =============================================================== + // The following definitions seem to be required in order to make javac + // not produce weird errors like: + // + // java/com/google/protobuf/DynamicMessage.java:203: types + // com.google.protobuf.AbstractMessage.Builder< + // com.google.protobuf.DynamicMessage.Builder> and + // com.google.protobuf.AbstractMessage.Builder< + // com.google.protobuf.DynamicMessage.Builder> are incompatible; both + // define mergeFrom(com.google.protobuf.ByteString), but with unrelated + // return types. + // + // Strangely, these lines are only needed if javac is invoked separately + // on AbstractMessage.java and AbstractMessageLite.java. If javac is + // invoked on both simultaneously, it works. (Or maybe the important + // point is whether or not DynamicMessage.java is compiled together with + // AbstractMessageLite.java -- not sure.) I suspect this is a compiler + // bug. + + @Override + public BuilderType mergeFrom(final ByteString data) throws InvalidProtocolBufferException { + return (BuilderType) super.mergeFrom(data); + } + + @Override + public BuilderType mergeFrom( + final ByteString data, final ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + return (BuilderType) super.mergeFrom(data, extensionRegistry); + } + + @Override + public BuilderType mergeFrom(final byte[] data) throws InvalidProtocolBufferException { + return (BuilderType) super.mergeFrom(data); + } + + @Override + public BuilderType mergeFrom(final byte[] data, final int off, final int len) + throws InvalidProtocolBufferException { + return (BuilderType) super.mergeFrom(data, off, len); + } + + @Override + public BuilderType mergeFrom(final byte[] data, final ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + return (BuilderType) super.mergeFrom(data, extensionRegistry); + } + + @Override + public BuilderType mergeFrom( + final byte[] data, + final int off, + final int len, + final ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + return (BuilderType) super.mergeFrom(data, off, len, extensionRegistry); + } + + @Override + public BuilderType mergeFrom(final InputStream input) throws IOException { + return (BuilderType) super.mergeFrom(input); + } + + @Override + public BuilderType mergeFrom( + final InputStream input, final ExtensionRegistryLite extensionRegistry) throws IOException { + return (BuilderType) super.mergeFrom(input, extensionRegistry); + } + } + + /** + * @deprecated from v3.0.0-beta-3+, for compatibility with v2.5.0 and v2.6.1 + * generated code. + */ + @Deprecated + protected static int hashLong(long n) { + return (int) (n ^ (n >>> 32)); + } + + /** + * @deprecated from v3.0.0-beta-3+, for compatibility with v2.5.0 and v2.6.1 + * generated code. + */ + @Deprecated + protected static int hashBoolean(boolean b) { + return b ? 1231 : 1237; + } + + /** + * @deprecated from v3.0.0-beta-3+, for compatibility with v2.5.0 and v2.6.1 + * generated code. + */ + @Deprecated + protected static int hashEnum(EnumLite e) { + return e.getNumber(); + } + + /** + * @deprecated from v3.0.0-beta-3+, for compatibility with v2.5.0 and v2.6.1 + * generated code. + */ + @Deprecated + protected static int hashEnumList(List list) { + int hash = 1; + for (EnumLite e : list) { + hash = 31 * hash + hashEnum(e); + } + return hash; + } +} diff --git a/protobuf-api/src/main/java/com/google/protobuf/Any.java b/protobuf-api/src/main/java/com/google/protobuf/Any.java index d950290..0573c59 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/Any.java +++ b/protobuf-api/src/main/java/com/google/protobuf/Any.java @@ -96,12 +96,12 @@ * Protobuf type {@code google.protobuf.Any} */ public final class Any extends - com.google.protobuf.FlattenedGeneratedMessageV3 implements + com.google.protobuf.GeneratedMessageV3Internal implements // @@protoc_insertion_point(message_implements:google.protobuf.Any) AnyOrBuilder { private static final long serialVersionUID = 0L; // Use Any.newBuilder() to construct. - private Any(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { + private Any(com.google.protobuf.GeneratedMessageV3Internal.Builder builder) { super(builder); } private Any() { @@ -122,7 +122,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.AnyProto.internal_static_google_protobuf_Any_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -355,8 +355,8 @@ public final boolean isInitialized() { @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(typeUrl_)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 1, typeUrl_); + if (!com.google.protobuf.GeneratedMessageV3Internal.isStringEmpty(typeUrl_)) { + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 1, typeUrl_); } if (!value_.isEmpty()) { output.writeBytes(2, value_); @@ -370,8 +370,8 @@ public int getSerializedSize() { if (size != -1) return size; size = 0; - if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(typeUrl_)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(1, typeUrl_); + if (!com.google.protobuf.GeneratedMessageV3Internal.isStringEmpty(typeUrl_)) { + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(1, typeUrl_); } if (!value_.isEmpty()) { size += com.google.protobuf.CodedOutputStream @@ -450,20 +450,20 @@ public static com.google.protobuf.Any parseFrom( } public static com.google.protobuf.Any parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.Any parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Any parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -471,20 +471,20 @@ public static com.google.protobuf.Any parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Any parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.Any parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -504,7 +504,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -600,7 +600,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.Any} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements + com.google.protobuf.GeneratedMessageV3Internal.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.Any) com.google.protobuf.AnyOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -609,7 +609,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.AnyProto.internal_static_google_protobuf_Any_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -622,7 +622,7 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); } diff --git a/protobuf-api/src/main/java/com/google/protobuf/AnyProto.java b/protobuf-api/src/main/java/com/google/protobuf/AnyProto.java index e312d05..bdb1d0d 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/AnyProto.java +++ b/protobuf-api/src/main/java/com/google/protobuf/AnyProto.java @@ -18,7 +18,7 @@ public static void registerAllExtensions( static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_Any_descriptor; static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_Any_fieldAccessorTable; public static com.google.protobuf.Descriptors.FileDescriptor @@ -43,7 +43,7 @@ public static void registerAllExtensions( internal_static_google_protobuf_Any_descriptor = getDescriptor().getMessageTypes().get(0); internal_static_google_protobuf_Any_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_Any_descriptor, new java.lang.String[] { "TypeUrl", "Value", }); } diff --git a/protobuf-api/src/main/java/com/google/protobuf/Api.java b/protobuf-api/src/main/java/com/google/protobuf/Api.java index a04ebcc..9471f31 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/Api.java +++ b/protobuf-api/src/main/java/com/google/protobuf/Api.java @@ -20,12 +20,12 @@ * Protobuf type {@code google.protobuf.Api} */ public final class Api extends - com.google.protobuf.FlattenedGeneratedMessageV3 implements + com.google.protobuf.GeneratedMessageV3Internal implements // @@protoc_insertion_point(message_implements:google.protobuf.Api) ApiOrBuilder { private static final long serialVersionUID = 0L; // Use Api.newBuilder() to construct. - private Api(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { + private Api(com.google.protobuf.GeneratedMessageV3Internal.Builder builder) { super(builder); } private Api() { @@ -50,7 +50,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.ApiProto.internal_static_google_protobuf_Api_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -454,8 +454,8 @@ public final boolean isInitialized() { @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(name_)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 1, name_); + if (!com.google.protobuf.GeneratedMessageV3Internal.isStringEmpty(name_)) { + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 1, name_); } for (int i = 0; i < methods_.size(); i++) { output.writeMessage(2, methods_.get(i)); @@ -463,8 +463,8 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) for (int i = 0; i < options_.size(); i++) { output.writeMessage(3, options_.get(i)); } - if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(version_)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 4, version_); + if (!com.google.protobuf.GeneratedMessageV3Internal.isStringEmpty(version_)) { + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 4, version_); } if (((bitField0_ & 0x00000001) != 0)) { output.writeMessage(5, getSourceContext()); @@ -484,8 +484,8 @@ public int getSerializedSize() { if (size != -1) return size; size = 0; - if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(name_)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(1, name_); + if (!com.google.protobuf.GeneratedMessageV3Internal.isStringEmpty(name_)) { + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(1, name_); } for (int i = 0; i < methods_.size(); i++) { size += com.google.protobuf.CodedOutputStream @@ -495,8 +495,8 @@ public int getSerializedSize() { size += com.google.protobuf.CodedOutputStream .computeMessageSize(3, options_.get(i)); } - if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(version_)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(4, version_); + if (!com.google.protobuf.GeneratedMessageV3Internal.isStringEmpty(version_)) { + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(4, version_); } if (((bitField0_ & 0x00000001) != 0)) { size += com.google.protobuf.CodedOutputStream @@ -613,20 +613,20 @@ public static com.google.protobuf.Api parseFrom( } public static com.google.protobuf.Api parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.Api parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Api parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -634,20 +634,20 @@ public static com.google.protobuf.Api parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Api parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.Api parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -667,7 +667,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -687,7 +687,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.Api} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements + com.google.protobuf.GeneratedMessageV3Internal.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.Api) com.google.protobuf.ApiOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -696,7 +696,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.ApiProto.internal_static_google_protobuf_Api_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -709,12 +709,12 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { - if (com.google.protobuf.FlattenedGeneratedMessageV3 + if (com.google.protobuf.GeneratedMessageV3Internal .alwaysUseFieldBuilders) { getMethodsFieldBuilder(); getOptionsFieldBuilder(); @@ -906,7 +906,7 @@ public Builder mergeFrom(com.google.protobuf.Api other) { methods_ = other.methods_; bitField0_ = (bitField0_ & ~0x00000002); methodsBuilder_ = - com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.GeneratedMessageV3Internal.alwaysUseFieldBuilders ? getMethodsFieldBuilder() : null; } else { methodsBuilder_.addAllMessages(other.methods_); @@ -932,7 +932,7 @@ public Builder mergeFrom(com.google.protobuf.Api other) { options_ = other.options_; bitField0_ = (bitField0_ & ~0x00000004); optionsBuilder_ = - com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.GeneratedMessageV3Internal.alwaysUseFieldBuilders ? getOptionsFieldBuilder() : null; } else { optionsBuilder_.addAllMessages(other.options_); @@ -966,7 +966,7 @@ public Builder mergeFrom(com.google.protobuf.Api other) { mixins_ = other.mixins_; bitField0_ = (bitField0_ & ~0x00000020); mixinsBuilder_ = - com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.GeneratedMessageV3Internal.alwaysUseFieldBuilders ? getMixinsFieldBuilder() : null; } else { mixinsBuilder_.addAllMessages(other.mixins_); diff --git a/protobuf-api/src/main/java/com/google/protobuf/ApiProto.java b/protobuf-api/src/main/java/com/google/protobuf/ApiProto.java index e12d52e..aa89982 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/ApiProto.java +++ b/protobuf-api/src/main/java/com/google/protobuf/ApiProto.java @@ -18,17 +18,17 @@ public static void registerAllExtensions( static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_Api_descriptor; static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_Api_fieldAccessorTable; static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_Method_descriptor; static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_Method_fieldAccessorTable; static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_Mixin_descriptor; static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_Mixin_fieldAccessorTable; public static com.google.protobuf.Descriptors.FileDescriptor @@ -68,19 +68,19 @@ public static void registerAllExtensions( internal_static_google_protobuf_Api_descriptor = getDescriptor().getMessageTypes().get(0); internal_static_google_protobuf_Api_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_Api_descriptor, new java.lang.String[] { "Name", "Methods", "Options", "Version", "SourceContext", "Mixins", "Syntax", }); internal_static_google_protobuf_Method_descriptor = getDescriptor().getMessageTypes().get(1); internal_static_google_protobuf_Method_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_Method_descriptor, new java.lang.String[] { "Name", "RequestTypeUrl", "RequestStreaming", "ResponseTypeUrl", "ResponseStreaming", "Options", "Syntax", }); internal_static_google_protobuf_Mixin_descriptor = getDescriptor().getMessageTypes().get(2); internal_static_google_protobuf_Mixin_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_Mixin_descriptor, new java.lang.String[] { "Name", "Root", }); com.google.protobuf.SourceContextProto.getDescriptor(); diff --git a/protobuf-api/src/main/java/com/google/protobuf/BoolValue.java b/protobuf-api/src/main/java/com/google/protobuf/BoolValue.java index c3b51ee..0034f38 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/BoolValue.java +++ b/protobuf-api/src/main/java/com/google/protobuf/BoolValue.java @@ -14,12 +14,12 @@ * Protobuf type {@code google.protobuf.BoolValue} */ public final class BoolValue extends - com.google.protobuf.FlattenedGeneratedMessageV3 implements + com.google.protobuf.GeneratedMessageV3Internal implements // @@protoc_insertion_point(message_implements:google.protobuf.BoolValue) BoolValueOrBuilder { private static final long serialVersionUID = 0L; // Use BoolValue.newBuilder() to construct. - private BoolValue(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { + private BoolValue(com.google.protobuf.GeneratedMessageV3Internal.Builder builder) { super(builder); } private BoolValue() { @@ -38,7 +38,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.WrappersProto.internal_static_google_protobuf_BoolValue_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -160,20 +160,20 @@ public static com.google.protobuf.BoolValue parseFrom( } public static com.google.protobuf.BoolValue parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.BoolValue parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.BoolValue parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -181,20 +181,20 @@ public static com.google.protobuf.BoolValue parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.BoolValue parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.BoolValue parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -214,7 +214,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -228,7 +228,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.BoolValue} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements + com.google.protobuf.GeneratedMessageV3Internal.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.BoolValue) com.google.protobuf.BoolValueOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -237,7 +237,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.WrappersProto.internal_static_google_protobuf_BoolValue_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -250,7 +250,7 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); } diff --git a/protobuf-api/src/main/java/com/google/protobuf/BytesValue.java b/protobuf-api/src/main/java/com/google/protobuf/BytesValue.java index 8b70f3e..9b1a079 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/BytesValue.java +++ b/protobuf-api/src/main/java/com/google/protobuf/BytesValue.java @@ -14,12 +14,12 @@ * Protobuf type {@code google.protobuf.BytesValue} */ public final class BytesValue extends - com.google.protobuf.FlattenedGeneratedMessageV3 implements + com.google.protobuf.GeneratedMessageV3Internal implements // @@protoc_insertion_point(message_implements:google.protobuf.BytesValue) BytesValueOrBuilder { private static final long serialVersionUID = 0L; // Use BytesValue.newBuilder() to construct. - private BytesValue(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { + private BytesValue(com.google.protobuf.GeneratedMessageV3Internal.Builder builder) { super(builder); } private BytesValue() { @@ -39,7 +39,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.WrappersProto.internal_static_google_protobuf_BytesValue_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -160,20 +160,20 @@ public static com.google.protobuf.BytesValue parseFrom( } public static com.google.protobuf.BytesValue parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.BytesValue parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.BytesValue parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -181,20 +181,20 @@ public static com.google.protobuf.BytesValue parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.BytesValue parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.BytesValue parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -214,7 +214,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -228,7 +228,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.BytesValue} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements + com.google.protobuf.GeneratedMessageV3Internal.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.BytesValue) com.google.protobuf.BytesValueOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -237,7 +237,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.WrappersProto.internal_static_google_protobuf_BytesValue_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -250,7 +250,7 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); } diff --git a/protobuf-api/src/main/java/com/google/protobuf/DescriptorProtos.java b/protobuf-api/src/main/java/com/google/protobuf/DescriptorProtos.java index 8c8fa7e..cb2cec8 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/DescriptorProtos.java +++ b/protobuf-api/src/main/java/com/google/protobuf/DescriptorProtos.java @@ -273,7 +273,7 @@ private Edition(int value) { public interface FileDescriptorSetOrBuilder extends // @@protoc_insertion_point(interface_extends:google.protobuf.FileDescriptorSet) - com.google.protobuf.FlattenedGeneratedMessageV3. + com.google.protobuf.GeneratedMessageV3Internal. ExtendableMessageOrBuilder { /** @@ -309,13 +309,13 @@ com.google.protobuf.DescriptorProtos.FileDescriptorProtoOrBuilder getFileOrBuild * Protobuf type {@code google.protobuf.FileDescriptorSet} */ public static final class FileDescriptorSet extends - com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableMessage< + com.google.protobuf.GeneratedMessageV3Internal.ExtendableMessage< FileDescriptorSet> implements // @@protoc_insertion_point(message_implements:google.protobuf.FileDescriptorSet) FileDescriptorSetOrBuilder { private static final long serialVersionUID = 0L; // Use FileDescriptorSet.newBuilder() to construct. - private FileDescriptorSet(com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableBuilder builder) { + private FileDescriptorSet(com.google.protobuf.GeneratedMessageV3Internal.ExtendableBuilder builder) { super(builder); } private FileDescriptorSet() { @@ -335,7 +335,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_FileDescriptorSet_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -407,7 +407,7 @@ public final boolean isInitialized() { @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - com.google.protobuf.FlattenedGeneratedMessageV3 + com.google.protobuf.GeneratedMessageV3Internal .ExtendableMessage.ExtensionWriter extensionWriter = newExtensionWriter(); for (int i = 0; i < file_.size(); i++) { @@ -502,20 +502,20 @@ public static com.google.protobuf.DescriptorProtos.FileDescriptorSet parseFrom( } public static com.google.protobuf.DescriptorProtos.FileDescriptorSet parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.FileDescriptorSet parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.FileDescriptorSet parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -523,20 +523,20 @@ public static com.google.protobuf.DescriptorProtos.FileDescriptorSet parseDelimi java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.FileDescriptorSet parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.FileDescriptorSet parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -556,7 +556,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -569,7 +569,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.FileDescriptorSet} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableBuilder< + com.google.protobuf.GeneratedMessageV3Internal.ExtendableBuilder< com.google.protobuf.DescriptorProtos.FileDescriptorSet, Builder> implements // @@protoc_insertion_point(builder_implements:google.protobuf.FileDescriptorSet) com.google.protobuf.DescriptorProtos.FileDescriptorSetOrBuilder { @@ -579,7 +579,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_FileDescriptorSet_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -592,7 +592,7 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); } @@ -745,7 +745,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.FileDescriptorSet file_ = other.file_; bitField0_ = (bitField0_ & ~0x00000001); fileBuilder_ = - com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.GeneratedMessageV3Internal.alwaysUseFieldBuilders ? getFileFieldBuilder() : null; } else { fileBuilder_.addAllMessages(other.file_); @@ -958,7 +958,7 @@ public Builder addAllFile( java.lang.Iterable values) { if (fileBuilder_ == null) { ensureFileIsMutable(); - com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( + com.google.protobuf.GeneratedMessageV3Internal.Builder.addAll( values, file_); onChanged(); } else { @@ -1531,12 +1531,12 @@ com.google.protobuf.DescriptorProtos.FieldDescriptorProtoOrBuilder getExtensionO * Protobuf type {@code google.protobuf.FileDescriptorProto} */ public static final class FileDescriptorProto extends - com.google.protobuf.FlattenedGeneratedMessageV3 implements + com.google.protobuf.GeneratedMessageV3Internal implements // @@protoc_insertion_point(message_implements:google.protobuf.FileDescriptorProto) FileDescriptorProtoOrBuilder { private static final long serialVersionUID = 0L; // Use FileDescriptorProto.newBuilder() to construct. - private FileDescriptorProto(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { + private FileDescriptorProto(com.google.protobuf.GeneratedMessageV3Internal.Builder builder) { super(builder); } private FileDescriptorProto() { @@ -1567,7 +1567,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_FileDescriptorProto_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -2254,13 +2254,13 @@ public final boolean isInitialized() { public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { if (((bitField0_ & 0x00000001) != 0)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 1, name_); + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 1, name_); } if (((bitField0_ & 0x00000002) != 0)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 2, package_); + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 2, package_); } for (int i = 0; i < dependency_.size(); i++) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 3, dependency_.getRaw(i)); + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 3, dependency_.getRaw(i)); } for (int i = 0; i < messageType_.size(); i++) { output.writeMessage(4, messageType_.get(i)); @@ -2287,7 +2287,7 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) output.writeInt32(11, weakDependency_.getInt(i)); } if (((bitField0_ & 0x00000010) != 0)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 12, syntax_); + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 12, syntax_); } if (((bitField0_ & 0x00000020) != 0)) { output.writeEnum(14, edition_); @@ -2302,10 +2302,10 @@ public int getSerializedSize() { size = 0; if (((bitField0_ & 0x00000001) != 0)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(1, name_); + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(1, name_); } if (((bitField0_ & 0x00000002) != 0)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(2, package_); + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(2, package_); } { int dataSize = 0; @@ -2358,7 +2358,7 @@ public int getSerializedSize() { size += 1 * getWeakDependencyList().size(); } if (((bitField0_ & 0x00000010) != 0)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(12, syntax_); + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(12, syntax_); } if (((bitField0_ & 0x00000020) != 0)) { size += com.google.protobuf.CodedOutputStream @@ -2524,20 +2524,20 @@ public static com.google.protobuf.DescriptorProtos.FileDescriptorProto parseFrom } public static com.google.protobuf.DescriptorProtos.FileDescriptorProto parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.FileDescriptorProto parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.FileDescriptorProto parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -2545,20 +2545,20 @@ public static com.google.protobuf.DescriptorProtos.FileDescriptorProto parseDeli java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.FileDescriptorProto parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.FileDescriptorProto parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -2578,7 +2578,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -2590,7 +2590,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.FileDescriptorProto} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements + com.google.protobuf.GeneratedMessageV3Internal.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.FileDescriptorProto) com.google.protobuf.DescriptorProtos.FileDescriptorProtoOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -2599,7 +2599,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_FileDescriptorProto_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -2612,12 +2612,12 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { - if (com.google.protobuf.FlattenedGeneratedMessageV3 + if (com.google.protobuf.GeneratedMessageV3Internal .alwaysUseFieldBuilders) { getMessageTypeFieldBuilder(); getEnumTypeFieldBuilder(); @@ -2899,7 +2899,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.FileDescriptorProt messageType_ = other.messageType_; bitField0_ = (bitField0_ & ~0x00000020); messageTypeBuilder_ = - com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.GeneratedMessageV3Internal.alwaysUseFieldBuilders ? getMessageTypeFieldBuilder() : null; } else { messageTypeBuilder_.addAllMessages(other.messageType_); @@ -2925,7 +2925,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.FileDescriptorProt enumType_ = other.enumType_; bitField0_ = (bitField0_ & ~0x00000040); enumTypeBuilder_ = - com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.GeneratedMessageV3Internal.alwaysUseFieldBuilders ? getEnumTypeFieldBuilder() : null; } else { enumTypeBuilder_.addAllMessages(other.enumType_); @@ -2951,7 +2951,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.FileDescriptorProt service_ = other.service_; bitField0_ = (bitField0_ & ~0x00000080); serviceBuilder_ = - com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.GeneratedMessageV3Internal.alwaysUseFieldBuilders ? getServiceFieldBuilder() : null; } else { serviceBuilder_.addAllMessages(other.service_); @@ -2977,7 +2977,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.FileDescriptorProt extension_ = other.extension_; bitField0_ = (bitField0_ & ~0x00000100); extensionBuilder_ = - com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.GeneratedMessageV3Internal.alwaysUseFieldBuilders ? getExtensionFieldBuilder() : null; } else { extensionBuilder_.addAllMessages(other.extension_); @@ -3516,7 +3516,7 @@ public Builder addDependency( public Builder addAllDependency( java.lang.Iterable values) { ensureDependencyIsMutable(); - com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( + com.google.protobuf.GeneratedMessageV3Internal.Builder.addAll( values, dependency_); bitField0_ |= 0x00000004; onChanged(); @@ -3647,7 +3647,7 @@ public Builder addPublicDependency(int value) { public Builder addAllPublicDependency( java.lang.Iterable values) { ensurePublicDependencyIsMutable(); - com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( + com.google.protobuf.GeneratedMessageV3Internal.Builder.addAll( values, publicDependency_); bitField0_ |= 0x00000008; onChanged(); @@ -3765,7 +3765,7 @@ public Builder addWeakDependency(int value) { public Builder addAllWeakDependency( java.lang.Iterable values) { ensureWeakDependencyIsMutable(); - com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( + com.google.protobuf.GeneratedMessageV3Internal.Builder.addAll( values, weakDependency_); bitField0_ |= 0x00000010; onChanged(); @@ -3968,7 +3968,7 @@ public Builder addAllMessageType( java.lang.Iterable values) { if (messageTypeBuilder_ == null) { ensureMessageTypeIsMutable(); - com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( + com.google.protobuf.GeneratedMessageV3Internal.Builder.addAll( values, messageType_); onChanged(); } else { @@ -4240,7 +4240,7 @@ public Builder addAllEnumType( java.lang.Iterable values) { if (enumTypeBuilder_ == null) { ensureEnumTypeIsMutable(); - com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( + com.google.protobuf.GeneratedMessageV3Internal.Builder.addAll( values, enumType_); onChanged(); } else { @@ -4480,7 +4480,7 @@ public Builder addAllService( java.lang.Iterable values) { if (serviceBuilder_ == null) { ensureServiceIsMutable(); - com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( + com.google.protobuf.GeneratedMessageV3Internal.Builder.addAll( values, service_); onChanged(); } else { @@ -4720,7 +4720,7 @@ public Builder addAllExtension( java.lang.Iterable values) { if (extensionBuilder_ == null) { ensureExtensionIsMutable(); - com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( + com.google.protobuf.GeneratedMessageV3Internal.Builder.addAll( values, extension_); onChanged(); } else { @@ -5654,12 +5654,12 @@ com.google.protobuf.DescriptorProtos.DescriptorProto.ReservedRangeOrBuilder getR * Protobuf type {@code google.protobuf.DescriptorProto} */ public static final class DescriptorProto extends - com.google.protobuf.FlattenedGeneratedMessageV3 implements + com.google.protobuf.GeneratedMessageV3Internal implements // @@protoc_insertion_point(message_implements:google.protobuf.DescriptorProto) DescriptorProtoOrBuilder { private static final long serialVersionUID = 0L; // Use DescriptorProto.newBuilder() to construct. - private DescriptorProto(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { + private DescriptorProto(com.google.protobuf.GeneratedMessageV3Internal.Builder builder) { super(builder); } private DescriptorProto() { @@ -5688,7 +5688,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_DescriptorProto_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -5756,12 +5756,12 @@ public interface ExtensionRangeOrBuilder extends * Protobuf type {@code google.protobuf.DescriptorProto.ExtensionRange} */ public static final class ExtensionRange extends - com.google.protobuf.FlattenedGeneratedMessageV3 implements + com.google.protobuf.GeneratedMessageV3Internal implements // @@protoc_insertion_point(message_implements:google.protobuf.DescriptorProto.ExtensionRange) ExtensionRangeOrBuilder { private static final long serialVersionUID = 0L; // Use ExtensionRange.newBuilder() to construct. - private ExtensionRange(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { + private ExtensionRange(com.google.protobuf.GeneratedMessageV3Internal.Builder builder) { super(builder); } private ExtensionRange() { @@ -5780,7 +5780,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_DescriptorProto_ExtensionRange_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -6010,20 +6010,20 @@ public static com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRang } public static com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -6031,20 +6031,20 @@ public static com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRang java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -6064,7 +6064,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -6072,7 +6072,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.DescriptorProto.ExtensionRange} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements + com.google.protobuf.GeneratedMessageV3Internal.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.DescriptorProto.ExtensionRange) com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRangeOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -6081,7 +6081,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_DescriptorProto_ExtensionRange_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -6094,12 +6094,12 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { - if (com.google.protobuf.FlattenedGeneratedMessageV3 + if (com.google.protobuf.GeneratedMessageV3Internal .alwaysUseFieldBuilders) { getOptionsFieldBuilder(); } @@ -6632,12 +6632,12 @@ public interface ReservedRangeOrBuilder extends * Protobuf type {@code google.protobuf.DescriptorProto.ReservedRange} */ public static final class ReservedRange extends - com.google.protobuf.FlattenedGeneratedMessageV3 implements + com.google.protobuf.GeneratedMessageV3Internal implements // @@protoc_insertion_point(message_implements:google.protobuf.DescriptorProto.ReservedRange) ReservedRangeOrBuilder { private static final long serialVersionUID = 0L; // Use ReservedRange.newBuilder() to construct. - private ReservedRange(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { + private ReservedRange(com.google.protobuf.GeneratedMessageV3Internal.Builder builder) { super(builder); } private ReservedRange() { @@ -6656,7 +6656,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_DescriptorProto_ReservedRange_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -6838,20 +6838,20 @@ public static com.google.protobuf.DescriptorProtos.DescriptorProto.ReservedRange } public static com.google.protobuf.DescriptorProtos.DescriptorProto.ReservedRange parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.DescriptorProto.ReservedRange parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.DescriptorProto.ReservedRange parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -6859,20 +6859,20 @@ public static com.google.protobuf.DescriptorProtos.DescriptorProto.ReservedRange java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.DescriptorProto.ReservedRange parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.DescriptorProto.ReservedRange parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -6892,7 +6892,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -6906,7 +6906,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.DescriptorProto.ReservedRange} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements + com.google.protobuf.GeneratedMessageV3Internal.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.DescriptorProto.ReservedRange) com.google.protobuf.DescriptorProtos.DescriptorProto.ReservedRangeOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -6915,7 +6915,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_DescriptorProto_ReservedRange_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -6928,7 +6928,7 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); } @@ -7738,7 +7738,7 @@ public final boolean isInitialized() { public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { if (((bitField0_ & 0x00000001) != 0)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 1, name_); + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 1, name_); } for (int i = 0; i < field_.size(); i++) { output.writeMessage(2, field_.get(i)); @@ -7765,7 +7765,7 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) output.writeMessage(9, reservedRange_.get(i)); } for (int i = 0; i < reservedName_.size(); i++) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 10, reservedName_.getRaw(i)); + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 10, reservedName_.getRaw(i)); } getUnknownFields().writeTo(output); } @@ -7777,7 +7777,7 @@ public int getSerializedSize() { size = 0; if (((bitField0_ & 0x00000001) != 0)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(1, name_); + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(1, name_); } for (int i = 0; i < field_.size(); i++) { size += com.google.protobuf.CodedOutputStream @@ -7950,20 +7950,20 @@ public static com.google.protobuf.DescriptorProtos.DescriptorProto parseFrom( } public static com.google.protobuf.DescriptorProtos.DescriptorProto parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.DescriptorProto parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.DescriptorProto parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -7971,20 +7971,20 @@ public static com.google.protobuf.DescriptorProtos.DescriptorProto parseDelimite java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.DescriptorProto parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.DescriptorProto parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -8004,7 +8004,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -8016,7 +8016,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.DescriptorProto} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements + com.google.protobuf.GeneratedMessageV3Internal.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.DescriptorProto) com.google.protobuf.DescriptorProtos.DescriptorProtoOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -8025,7 +8025,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_DescriptorProto_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -8038,12 +8038,12 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { - if (com.google.protobuf.FlattenedGeneratedMessageV3 + if (com.google.protobuf.GeneratedMessageV3Internal .alwaysUseFieldBuilders) { getFieldFieldBuilder(); getExtensionFieldBuilder(); @@ -8302,7 +8302,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.DescriptorProto ot field_ = other.field_; bitField0_ = (bitField0_ & ~0x00000002); fieldBuilder_ = - com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.GeneratedMessageV3Internal.alwaysUseFieldBuilders ? getFieldFieldBuilder() : null; } else { fieldBuilder_.addAllMessages(other.field_); @@ -8328,7 +8328,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.DescriptorProto ot extension_ = other.extension_; bitField0_ = (bitField0_ & ~0x00000004); extensionBuilder_ = - com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.GeneratedMessageV3Internal.alwaysUseFieldBuilders ? getExtensionFieldBuilder() : null; } else { extensionBuilder_.addAllMessages(other.extension_); @@ -8354,7 +8354,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.DescriptorProto ot nestedType_ = other.nestedType_; bitField0_ = (bitField0_ & ~0x00000008); nestedTypeBuilder_ = - com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.GeneratedMessageV3Internal.alwaysUseFieldBuilders ? getNestedTypeFieldBuilder() : null; } else { nestedTypeBuilder_.addAllMessages(other.nestedType_); @@ -8380,7 +8380,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.DescriptorProto ot enumType_ = other.enumType_; bitField0_ = (bitField0_ & ~0x00000010); enumTypeBuilder_ = - com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.GeneratedMessageV3Internal.alwaysUseFieldBuilders ? getEnumTypeFieldBuilder() : null; } else { enumTypeBuilder_.addAllMessages(other.enumType_); @@ -8406,7 +8406,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.DescriptorProto ot extensionRange_ = other.extensionRange_; bitField0_ = (bitField0_ & ~0x00000020); extensionRangeBuilder_ = - com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.GeneratedMessageV3Internal.alwaysUseFieldBuilders ? getExtensionRangeFieldBuilder() : null; } else { extensionRangeBuilder_.addAllMessages(other.extensionRange_); @@ -8432,7 +8432,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.DescriptorProto ot oneofDecl_ = other.oneofDecl_; bitField0_ = (bitField0_ & ~0x00000040); oneofDeclBuilder_ = - com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.GeneratedMessageV3Internal.alwaysUseFieldBuilders ? getOneofDeclFieldBuilder() : null; } else { oneofDeclBuilder_.addAllMessages(other.oneofDecl_); @@ -8461,7 +8461,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.DescriptorProto ot reservedRange_ = other.reservedRange_; bitField0_ = (bitField0_ & ~0x00000100); reservedRangeBuilder_ = - com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.GeneratedMessageV3Internal.alwaysUseFieldBuilders ? getReservedRangeFieldBuilder() : null; } else { reservedRangeBuilder_.addAllMessages(other.reservedRange_); @@ -8886,7 +8886,7 @@ public Builder addAllField( java.lang.Iterable values) { if (fieldBuilder_ == null) { ensureFieldIsMutable(); - com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( + com.google.protobuf.GeneratedMessageV3Internal.Builder.addAll( values, field_); onChanged(); } else { @@ -9126,7 +9126,7 @@ public Builder addAllExtension( java.lang.Iterable values) { if (extensionBuilder_ == null) { ensureExtensionIsMutable(); - com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( + com.google.protobuf.GeneratedMessageV3Internal.Builder.addAll( values, extension_); onChanged(); } else { @@ -9366,7 +9366,7 @@ public Builder addAllNestedType( java.lang.Iterable values) { if (nestedTypeBuilder_ == null) { ensureNestedTypeIsMutable(); - com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( + com.google.protobuf.GeneratedMessageV3Internal.Builder.addAll( values, nestedType_); onChanged(); } else { @@ -9606,7 +9606,7 @@ public Builder addAllEnumType( java.lang.Iterable values) { if (enumTypeBuilder_ == null) { ensureEnumTypeIsMutable(); - com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( + com.google.protobuf.GeneratedMessageV3Internal.Builder.addAll( values, enumType_); onChanged(); } else { @@ -9846,7 +9846,7 @@ public Builder addAllExtensionRange( java.lang.Iterable values) { if (extensionRangeBuilder_ == null) { ensureExtensionRangeIsMutable(); - com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( + com.google.protobuf.GeneratedMessageV3Internal.Builder.addAll( values, extensionRange_); onChanged(); } else { @@ -10086,7 +10086,7 @@ public Builder addAllOneofDecl( java.lang.Iterable values) { if (oneofDeclBuilder_ == null) { ensureOneofDeclIsMutable(); - com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( + com.google.protobuf.GeneratedMessageV3Internal.Builder.addAll( values, oneofDecl_); onChanged(); } else { @@ -10447,7 +10447,7 @@ public Builder addAllReservedRange( java.lang.Iterable values) { if (reservedRangeBuilder_ == null) { ensureReservedRangeIsMutable(); - com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( + com.google.protobuf.GeneratedMessageV3Internal.Builder.addAll( values, reservedRange_); onChanged(); } else { @@ -10659,7 +10659,7 @@ public Builder addReservedName( public Builder addAllReservedName( java.lang.Iterable values) { ensureReservedNameIsMutable(); - com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( + com.google.protobuf.GeneratedMessageV3Internal.Builder.addAll( values, reservedName_); bitField0_ |= 0x00000200; onChanged(); @@ -10766,7 +10766,7 @@ public com.google.protobuf.DescriptorProtos.DescriptorProto getDefaultInstanceFo public interface ExtensionRangeOptionsOrBuilder extends // @@protoc_insertion_point(interface_extends:google.protobuf.ExtensionRangeOptions) - com.google.protobuf.FlattenedGeneratedMessageV3. + com.google.protobuf.GeneratedMessageV3Internal. ExtendableMessageOrBuilder { /** @@ -10921,13 +10921,13 @@ com.google.protobuf.DescriptorProtos.ExtensionRangeOptions.DeclarationOrBuilder * Protobuf type {@code google.protobuf.ExtensionRangeOptions} */ public static final class ExtensionRangeOptions extends - com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableMessage< + com.google.protobuf.GeneratedMessageV3Internal.ExtendableMessage< ExtensionRangeOptions> implements // @@protoc_insertion_point(message_implements:google.protobuf.ExtensionRangeOptions) ExtensionRangeOptionsOrBuilder { private static final long serialVersionUID = 0L; // Use ExtensionRangeOptions.newBuilder() to construct. - private ExtensionRangeOptions(com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableBuilder builder) { + private ExtensionRangeOptions(com.google.protobuf.GeneratedMessageV3Internal.ExtendableBuilder builder) { super(builder); } private ExtensionRangeOptions() { @@ -10949,7 +10949,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_ExtensionRangeOptions_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -11202,12 +11202,12 @@ public interface DeclarationOrBuilder extends * Protobuf type {@code google.protobuf.ExtensionRangeOptions.Declaration} */ public static final class Declaration extends - com.google.protobuf.FlattenedGeneratedMessageV3 implements + com.google.protobuf.GeneratedMessageV3Internal implements // @@protoc_insertion_point(message_implements:google.protobuf.ExtensionRangeOptions.Declaration) DeclarationOrBuilder { private static final long serialVersionUID = 0L; // Use Declaration.newBuilder() to construct. - private Declaration(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { + private Declaration(com.google.protobuf.GeneratedMessageV3Internal.Builder builder) { super(builder); } private Declaration() { @@ -11228,7 +11228,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_ExtensionRangeOptions_Declaration_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -11472,10 +11472,10 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) output.writeInt32(1, number_); } if (((bitField0_ & 0x00000002) != 0)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 2, fullName_); + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 2, fullName_); } if (((bitField0_ & 0x00000004) != 0)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 3, type_); + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 3, type_); } if (((bitField0_ & 0x00000008) != 0)) { output.writeBool(5, reserved_); @@ -11497,10 +11497,10 @@ public int getSerializedSize() { .computeInt32Size(1, number_); } if (((bitField0_ & 0x00000002) != 0)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(2, fullName_); + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(2, fullName_); } if (((bitField0_ & 0x00000004) != 0)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(3, type_); + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(3, type_); } if (((bitField0_ & 0x00000008) != 0)) { size += com.google.protobuf.CodedOutputStream @@ -11622,20 +11622,20 @@ public static com.google.protobuf.DescriptorProtos.ExtensionRangeOptions.Declara } public static com.google.protobuf.DescriptorProtos.ExtensionRangeOptions.Declaration parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.ExtensionRangeOptions.Declaration parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.ExtensionRangeOptions.Declaration parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -11643,20 +11643,20 @@ public static com.google.protobuf.DescriptorProtos.ExtensionRangeOptions.Declara java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.ExtensionRangeOptions.Declaration parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.ExtensionRangeOptions.Declaration parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -11676,7 +11676,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -11684,7 +11684,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.ExtensionRangeOptions.Declaration} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements + com.google.protobuf.GeneratedMessageV3Internal.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.ExtensionRangeOptions.Declaration) com.google.protobuf.DescriptorProtos.ExtensionRangeOptions.DeclarationOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -11693,7 +11693,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_ExtensionRangeOptions_Declaration_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -11706,7 +11706,7 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); } @@ -12607,7 +12607,7 @@ public final boolean isInitialized() { @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - com.google.protobuf.FlattenedGeneratedMessageV3 + com.google.protobuf.GeneratedMessageV3Internal .ExtendableMessage.ExtensionWriter extensionWriter = newExtensionWriter(); for (int i = 0; i < declaration_.size(); i++) { @@ -12746,20 +12746,20 @@ public static com.google.protobuf.DescriptorProtos.ExtensionRangeOptions parseFr } public static com.google.protobuf.DescriptorProtos.ExtensionRangeOptions parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.ExtensionRangeOptions parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.ExtensionRangeOptions parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -12767,20 +12767,20 @@ public static com.google.protobuf.DescriptorProtos.ExtensionRangeOptions parseDe java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.ExtensionRangeOptions parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.ExtensionRangeOptions parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -12800,7 +12800,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -12808,7 +12808,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.ExtensionRangeOptions} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableBuilder< + com.google.protobuf.GeneratedMessageV3Internal.ExtendableBuilder< com.google.protobuf.DescriptorProtos.ExtensionRangeOptions, Builder> implements // @@protoc_insertion_point(builder_implements:google.protobuf.ExtensionRangeOptions) com.google.protobuf.DescriptorProtos.ExtensionRangeOptionsOrBuilder { @@ -12818,7 +12818,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_ExtensionRangeOptions_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -12831,12 +12831,12 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { - if (com.google.protobuf.FlattenedGeneratedMessageV3 + if (com.google.protobuf.GeneratedMessageV3Internal .alwaysUseFieldBuilders) { getUninterpretedOptionFieldBuilder(); getDeclarationFieldBuilder(); @@ -13026,7 +13026,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.ExtensionRangeOpti uninterpretedOption_ = other.uninterpretedOption_; bitField0_ = (bitField0_ & ~0x00000001); uninterpretedOptionBuilder_ = - com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.GeneratedMessageV3Internal.alwaysUseFieldBuilders ? getUninterpretedOptionFieldBuilder() : null; } else { uninterpretedOptionBuilder_.addAllMessages(other.uninterpretedOption_); @@ -13052,7 +13052,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.ExtensionRangeOpti declaration_ = other.declaration_; bitField0_ = (bitField0_ & ~0x00000002); declarationBuilder_ = - com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.GeneratedMessageV3Internal.alwaysUseFieldBuilders ? getDeclarationFieldBuilder() : null; } else { declarationBuilder_.addAllMessages(other.declaration_); @@ -13348,7 +13348,7 @@ public Builder addAllUninterpretedOption( java.lang.Iterable values) { if (uninterpretedOptionBuilder_ == null) { ensureUninterpretedOptionIsMutable(); - com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( + com.google.protobuf.GeneratedMessageV3Internal.Builder.addAll( values, uninterpretedOption_); onChanged(); } else { @@ -13680,7 +13680,7 @@ public Builder addAllDeclaration( java.lang.Iterable values) { if (declarationBuilder_ == null) { ensureDeclarationIsMutable(); - com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( + com.google.protobuf.GeneratedMessageV3Internal.Builder.addAll( values, declaration_); onChanged(); } else { @@ -14429,12 +14429,12 @@ public interface FieldDescriptorProtoOrBuilder extends * Protobuf type {@code google.protobuf.FieldDescriptorProto} */ public static final class FieldDescriptorProto extends - com.google.protobuf.FlattenedGeneratedMessageV3 implements + com.google.protobuf.GeneratedMessageV3Internal implements // @@protoc_insertion_point(message_implements:google.protobuf.FieldDescriptorProto) FieldDescriptorProtoOrBuilder { private static final long serialVersionUID = 0L; // Use FieldDescriptorProto.newBuilder() to construct. - private FieldDescriptorProto(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { + private FieldDescriptorProto(com.google.protobuf.GeneratedMessageV3Internal.Builder builder) { super(builder); } private FieldDescriptorProto() { @@ -14460,7 +14460,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_FieldDescriptorProto_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -15445,10 +15445,10 @@ public final boolean isInitialized() { public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { if (((bitField0_ & 0x00000001) != 0)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 1, name_); + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 1, name_); } if (((bitField0_ & 0x00000020) != 0)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 2, extendee_); + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 2, extendee_); } if (((bitField0_ & 0x00000002) != 0)) { output.writeInt32(3, number_); @@ -15460,10 +15460,10 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) output.writeEnum(5, type_); } if (((bitField0_ & 0x00000010) != 0)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 6, typeName_); + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 6, typeName_); } if (((bitField0_ & 0x00000040) != 0)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 7, defaultValue_); + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 7, defaultValue_); } if (((bitField0_ & 0x00000200) != 0)) { output.writeMessage(8, getOptions()); @@ -15472,7 +15472,7 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) output.writeInt32(9, oneofIndex_); } if (((bitField0_ & 0x00000100) != 0)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 10, jsonName_); + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 10, jsonName_); } if (((bitField0_ & 0x00000400) != 0)) { output.writeBool(17, proto3Optional_); @@ -15487,10 +15487,10 @@ public int getSerializedSize() { size = 0; if (((bitField0_ & 0x00000001) != 0)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(1, name_); + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(1, name_); } if (((bitField0_ & 0x00000020) != 0)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(2, extendee_); + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(2, extendee_); } if (((bitField0_ & 0x00000002) != 0)) { size += com.google.protobuf.CodedOutputStream @@ -15505,10 +15505,10 @@ public int getSerializedSize() { .computeEnumSize(5, type_); } if (((bitField0_ & 0x00000010) != 0)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(6, typeName_); + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(6, typeName_); } if (((bitField0_ & 0x00000040) != 0)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(7, defaultValue_); + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(7, defaultValue_); } if (((bitField0_ & 0x00000200) != 0)) { size += com.google.protobuf.CodedOutputStream @@ -15519,7 +15519,7 @@ public int getSerializedSize() { .computeInt32Size(9, oneofIndex_); } if (((bitField0_ & 0x00000100) != 0)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(10, jsonName_); + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(10, jsonName_); } if (((bitField0_ & 0x00000400) != 0)) { size += com.google.protobuf.CodedOutputStream @@ -15688,20 +15688,20 @@ public static com.google.protobuf.DescriptorProtos.FieldDescriptorProto parseFro } public static com.google.protobuf.DescriptorProtos.FieldDescriptorProto parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.FieldDescriptorProto parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.FieldDescriptorProto parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -15709,20 +15709,20 @@ public static com.google.protobuf.DescriptorProtos.FieldDescriptorProto parseDel java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.FieldDescriptorProto parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.FieldDescriptorProto parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -15742,7 +15742,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -15754,7 +15754,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.FieldDescriptorProto} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements + com.google.protobuf.GeneratedMessageV3Internal.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.FieldDescriptorProto) com.google.protobuf.DescriptorProtos.FieldDescriptorProtoOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -15763,7 +15763,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_FieldDescriptorProto_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -15776,12 +15776,12 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { - if (com.google.protobuf.FlattenedGeneratedMessageV3 + if (com.google.protobuf.GeneratedMessageV3Internal .alwaysUseFieldBuilders) { getOptionsFieldBuilder(); } @@ -17224,12 +17224,12 @@ public interface OneofDescriptorProtoOrBuilder extends * Protobuf type {@code google.protobuf.OneofDescriptorProto} */ public static final class OneofDescriptorProto extends - com.google.protobuf.FlattenedGeneratedMessageV3 implements + com.google.protobuf.GeneratedMessageV3Internal implements // @@protoc_insertion_point(message_implements:google.protobuf.OneofDescriptorProto) OneofDescriptorProtoOrBuilder { private static final long serialVersionUID = 0L; // Use OneofDescriptorProto.newBuilder() to construct. - private OneofDescriptorProto(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { + private OneofDescriptorProto(com.google.protobuf.GeneratedMessageV3Internal.Builder builder) { super(builder); } private OneofDescriptorProto() { @@ -17249,7 +17249,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_OneofDescriptorProto_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -17353,7 +17353,7 @@ public final boolean isInitialized() { public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { if (((bitField0_ & 0x00000001) != 0)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 1, name_); + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 1, name_); } if (((bitField0_ & 0x00000002) != 0)) { output.writeMessage(2, getOptions()); @@ -17368,7 +17368,7 @@ public int getSerializedSize() { size = 0; if (((bitField0_ & 0x00000001) != 0)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(1, name_); + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(1, name_); } if (((bitField0_ & 0x00000002) != 0)) { size += com.google.protobuf.CodedOutputStream @@ -17457,20 +17457,20 @@ public static com.google.protobuf.DescriptorProtos.OneofDescriptorProto parseFro } public static com.google.protobuf.DescriptorProtos.OneofDescriptorProto parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.OneofDescriptorProto parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.OneofDescriptorProto parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -17478,20 +17478,20 @@ public static com.google.protobuf.DescriptorProtos.OneofDescriptorProto parseDel java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.OneofDescriptorProto parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.OneofDescriptorProto parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -17511,7 +17511,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -17523,7 +17523,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.OneofDescriptorProto} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements + com.google.protobuf.GeneratedMessageV3Internal.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.OneofDescriptorProto) com.google.protobuf.DescriptorProtos.OneofDescriptorProtoOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -17532,7 +17532,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_OneofDescriptorProto_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -17545,12 +17545,12 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { - if (com.google.protobuf.FlattenedGeneratedMessageV3 + if (com.google.protobuf.GeneratedMessageV3Internal .alwaysUseFieldBuilders) { getOptionsFieldBuilder(); } @@ -18155,12 +18155,12 @@ com.google.protobuf.DescriptorProtos.EnumDescriptorProto.EnumReservedRangeOrBuil * Protobuf type {@code google.protobuf.EnumDescriptorProto} */ public static final class EnumDescriptorProto extends - com.google.protobuf.FlattenedGeneratedMessageV3 implements + com.google.protobuf.GeneratedMessageV3Internal implements // @@protoc_insertion_point(message_implements:google.protobuf.EnumDescriptorProto) EnumDescriptorProtoOrBuilder { private static final long serialVersionUID = 0L; // Use EnumDescriptorProto.newBuilder() to construct. - private EnumDescriptorProto(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { + private EnumDescriptorProto(com.google.protobuf.GeneratedMessageV3Internal.Builder builder) { super(builder); } private EnumDescriptorProto() { @@ -18184,7 +18184,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_EnumDescriptorProto_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -18246,12 +18246,12 @@ public interface EnumReservedRangeOrBuilder extends * Protobuf type {@code google.protobuf.EnumDescriptorProto.EnumReservedRange} */ public static final class EnumReservedRange extends - com.google.protobuf.FlattenedGeneratedMessageV3 implements + com.google.protobuf.GeneratedMessageV3Internal implements // @@protoc_insertion_point(message_implements:google.protobuf.EnumDescriptorProto.EnumReservedRange) EnumReservedRangeOrBuilder { private static final long serialVersionUID = 0L; // Use EnumReservedRange.newBuilder() to construct. - private EnumReservedRange(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { + private EnumReservedRange(com.google.protobuf.GeneratedMessageV3Internal.Builder builder) { super(builder); } private EnumReservedRange() { @@ -18270,7 +18270,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_EnumDescriptorProto_EnumReservedRange_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -18452,20 +18452,20 @@ public static com.google.protobuf.DescriptorProtos.EnumDescriptorProto.EnumReser } public static com.google.protobuf.DescriptorProtos.EnumDescriptorProto.EnumReservedRange parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.EnumDescriptorProto.EnumReservedRange parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.EnumDescriptorProto.EnumReservedRange parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -18473,20 +18473,20 @@ public static com.google.protobuf.DescriptorProtos.EnumDescriptorProto.EnumReser java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.EnumDescriptorProto.EnumReservedRange parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.EnumDescriptorProto.EnumReservedRange parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -18506,7 +18506,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -18523,7 +18523,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.EnumDescriptorProto.EnumReservedRange} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements + com.google.protobuf.GeneratedMessageV3Internal.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.EnumDescriptorProto.EnumReservedRange) com.google.protobuf.DescriptorProtos.EnumDescriptorProto.EnumReservedRangeOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -18532,7 +18532,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_EnumDescriptorProto_EnumReservedRange_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -18545,7 +18545,7 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); } @@ -19150,7 +19150,7 @@ public final boolean isInitialized() { public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { if (((bitField0_ & 0x00000001) != 0)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 1, name_); + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 1, name_); } for (int i = 0; i < value_.size(); i++) { output.writeMessage(2, value_.get(i)); @@ -19162,7 +19162,7 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) output.writeMessage(4, reservedRange_.get(i)); } for (int i = 0; i < reservedName_.size(); i++) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 5, reservedName_.getRaw(i)); + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 5, reservedName_.getRaw(i)); } getUnknownFields().writeTo(output); } @@ -19174,7 +19174,7 @@ public int getSerializedSize() { size = 0; if (((bitField0_ & 0x00000001) != 0)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(1, name_); + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(1, name_); } for (int i = 0; i < value_.size(); i++) { size += com.google.protobuf.CodedOutputStream @@ -19297,20 +19297,20 @@ public static com.google.protobuf.DescriptorProtos.EnumDescriptorProto parseFrom } public static com.google.protobuf.DescriptorProtos.EnumDescriptorProto parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.EnumDescriptorProto parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.EnumDescriptorProto parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -19318,20 +19318,20 @@ public static com.google.protobuf.DescriptorProtos.EnumDescriptorProto parseDeli java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.EnumDescriptorProto parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.EnumDescriptorProto parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -19351,7 +19351,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -19363,7 +19363,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.EnumDescriptorProto} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements + com.google.protobuf.GeneratedMessageV3Internal.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.EnumDescriptorProto) com.google.protobuf.DescriptorProtos.EnumDescriptorProtoOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -19372,7 +19372,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_EnumDescriptorProto_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -19385,12 +19385,12 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { - if (com.google.protobuf.FlattenedGeneratedMessageV3 + if (com.google.protobuf.GeneratedMessageV3Internal .alwaysUseFieldBuilders) { getValueFieldBuilder(); getOptionsFieldBuilder(); @@ -19564,7 +19564,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.EnumDescriptorProt value_ = other.value_; bitField0_ = (bitField0_ & ~0x00000002); valueBuilder_ = - com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.GeneratedMessageV3Internal.alwaysUseFieldBuilders ? getValueFieldBuilder() : null; } else { valueBuilder_.addAllMessages(other.value_); @@ -19593,7 +19593,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.EnumDescriptorProt reservedRange_ = other.reservedRange_; bitField0_ = (bitField0_ & ~0x00000008); reservedRangeBuilder_ = - com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.GeneratedMessageV3Internal.alwaysUseFieldBuilders ? getReservedRangeFieldBuilder() : null; } else { reservedRangeBuilder_.addAllMessages(other.reservedRange_); @@ -19928,7 +19928,7 @@ public Builder addAllValue( java.lang.Iterable values) { if (valueBuilder_ == null) { ensureValueIsMutable(); - com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( + com.google.protobuf.GeneratedMessageV3Internal.Builder.addAll( values, value_); onChanged(); } else { @@ -20349,7 +20349,7 @@ public Builder addAllReservedRange( java.lang.Iterable values) { if (reservedRangeBuilder_ == null) { ensureReservedRangeIsMutable(); - com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( + com.google.protobuf.GeneratedMessageV3Internal.Builder.addAll( values, reservedRange_); onChanged(); } else { @@ -20609,7 +20609,7 @@ public Builder addReservedName( public Builder addAllReservedName( java.lang.Iterable values) { ensureReservedNameIsMutable(); - com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( + com.google.protobuf.GeneratedMessageV3Internal.Builder.addAll( values, reservedName_); bitField0_ |= 0x00000010; onChanged(); @@ -20769,12 +20769,12 @@ public interface EnumValueDescriptorProtoOrBuilder extends * Protobuf type {@code google.protobuf.EnumValueDescriptorProto} */ public static final class EnumValueDescriptorProto extends - com.google.protobuf.FlattenedGeneratedMessageV3 implements + com.google.protobuf.GeneratedMessageV3Internal implements // @@protoc_insertion_point(message_implements:google.protobuf.EnumValueDescriptorProto) EnumValueDescriptorProtoOrBuilder { private static final long serialVersionUID = 0L; // Use EnumValueDescriptorProto.newBuilder() to construct. - private EnumValueDescriptorProto(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { + private EnumValueDescriptorProto(com.google.protobuf.GeneratedMessageV3Internal.Builder builder) { super(builder); } private EnumValueDescriptorProto() { @@ -20794,7 +20794,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_EnumValueDescriptorProto_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -20917,7 +20917,7 @@ public final boolean isInitialized() { public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { if (((bitField0_ & 0x00000001) != 0)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 1, name_); + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 1, name_); } if (((bitField0_ & 0x00000002) != 0)) { output.writeInt32(2, number_); @@ -20935,7 +20935,7 @@ public int getSerializedSize() { size = 0; if (((bitField0_ & 0x00000001) != 0)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(1, name_); + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(1, name_); } if (((bitField0_ & 0x00000002) != 0)) { size += com.google.protobuf.CodedOutputStream @@ -21037,20 +21037,20 @@ public static com.google.protobuf.DescriptorProtos.EnumValueDescriptorProto pars } public static com.google.protobuf.DescriptorProtos.EnumValueDescriptorProto parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.EnumValueDescriptorProto parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.EnumValueDescriptorProto parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -21058,20 +21058,20 @@ public static com.google.protobuf.DescriptorProtos.EnumValueDescriptorProto pars java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.EnumValueDescriptorProto parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.EnumValueDescriptorProto parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -21091,7 +21091,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -21103,7 +21103,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.EnumValueDescriptorProto} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements + com.google.protobuf.GeneratedMessageV3Internal.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.EnumValueDescriptorProto) com.google.protobuf.DescriptorProtos.EnumValueDescriptorProtoOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -21112,7 +21112,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_EnumValueDescriptorProto_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -21125,12 +21125,12 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { - if (com.google.protobuf.FlattenedGeneratedMessageV3 + if (com.google.protobuf.GeneratedMessageV3Internal .alwaysUseFieldBuilders) { getOptionsFieldBuilder(); } @@ -21689,12 +21689,12 @@ com.google.protobuf.DescriptorProtos.MethodDescriptorProtoOrBuilder getMethodOrB * Protobuf type {@code google.protobuf.ServiceDescriptorProto} */ public static final class ServiceDescriptorProto extends - com.google.protobuf.FlattenedGeneratedMessageV3 implements + com.google.protobuf.GeneratedMessageV3Internal implements // @@protoc_insertion_point(message_implements:google.protobuf.ServiceDescriptorProto) ServiceDescriptorProtoOrBuilder { private static final long serialVersionUID = 0L; // Use ServiceDescriptorProto.newBuilder() to construct. - private ServiceDescriptorProto(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { + private ServiceDescriptorProto(com.google.protobuf.GeneratedMessageV3Internal.Builder builder) { super(builder); } private ServiceDescriptorProto() { @@ -21715,7 +21715,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_ServiceDescriptorProto_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -21866,7 +21866,7 @@ public final boolean isInitialized() { public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { if (((bitField0_ & 0x00000001) != 0)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 1, name_); + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 1, name_); } for (int i = 0; i < method_.size(); i++) { output.writeMessage(2, method_.get(i)); @@ -21884,7 +21884,7 @@ public int getSerializedSize() { size = 0; if (((bitField0_ & 0x00000001) != 0)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(1, name_); + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(1, name_); } for (int i = 0; i < method_.size(); i++) { size += com.google.protobuf.CodedOutputStream @@ -21983,20 +21983,20 @@ public static com.google.protobuf.DescriptorProtos.ServiceDescriptorProto parseF } public static com.google.protobuf.DescriptorProtos.ServiceDescriptorProto parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.ServiceDescriptorProto parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.ServiceDescriptorProto parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -22004,20 +22004,20 @@ public static com.google.protobuf.DescriptorProtos.ServiceDescriptorProto parseD java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.ServiceDescriptorProto parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.ServiceDescriptorProto parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -22037,7 +22037,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -22049,7 +22049,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.ServiceDescriptorProto} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements + com.google.protobuf.GeneratedMessageV3Internal.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.ServiceDescriptorProto) com.google.protobuf.DescriptorProtos.ServiceDescriptorProtoOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -22058,7 +22058,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_ServiceDescriptorProto_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -22071,12 +22071,12 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { - if (com.google.protobuf.FlattenedGeneratedMessageV3 + if (com.google.protobuf.GeneratedMessageV3Internal .alwaysUseFieldBuilders) { getMethodFieldBuilder(); getOptionsFieldBuilder(); @@ -22227,7 +22227,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.ServiceDescriptorP method_ = other.method_; bitField0_ = (bitField0_ & ~0x00000002); methodBuilder_ = - com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.GeneratedMessageV3Internal.alwaysUseFieldBuilders ? getMethodFieldBuilder() : null; } else { methodBuilder_.addAllMessages(other.method_); @@ -22536,7 +22536,7 @@ public Builder addAllMethod( java.lang.Iterable values) { if (methodBuilder_ == null) { ensureMethodIsMutable(); - com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( + com.google.protobuf.GeneratedMessageV3Internal.Builder.addAll( values, method_); onChanged(); } else { @@ -22950,12 +22950,12 @@ public interface MethodDescriptorProtoOrBuilder extends * Protobuf type {@code google.protobuf.MethodDescriptorProto} */ public static final class MethodDescriptorProto extends - com.google.protobuf.FlattenedGeneratedMessageV3 implements + com.google.protobuf.GeneratedMessageV3Internal implements // @@protoc_insertion_point(message_implements:google.protobuf.MethodDescriptorProto) MethodDescriptorProtoOrBuilder { private static final long serialVersionUID = 0L; // Use MethodDescriptorProto.newBuilder() to construct. - private MethodDescriptorProto(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { + private MethodDescriptorProto(com.google.protobuf.GeneratedMessageV3Internal.Builder builder) { super(builder); } private MethodDescriptorProto() { @@ -22977,7 +22977,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_MethodDescriptorProto_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -23248,13 +23248,13 @@ public final boolean isInitialized() { public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { if (((bitField0_ & 0x00000001) != 0)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 1, name_); + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 1, name_); } if (((bitField0_ & 0x00000002) != 0)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 2, inputType_); + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 2, inputType_); } if (((bitField0_ & 0x00000004) != 0)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 3, outputType_); + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 3, outputType_); } if (((bitField0_ & 0x00000008) != 0)) { output.writeMessage(4, getOptions()); @@ -23275,13 +23275,13 @@ public int getSerializedSize() { size = 0; if (((bitField0_ & 0x00000001) != 0)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(1, name_); + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(1, name_); } if (((bitField0_ & 0x00000002) != 0)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(2, inputType_); + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(2, inputType_); } if (((bitField0_ & 0x00000004) != 0)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(3, outputType_); + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(3, outputType_); } if (((bitField0_ & 0x00000008) != 0)) { size += com.google.protobuf.CodedOutputStream @@ -23416,20 +23416,20 @@ public static com.google.protobuf.DescriptorProtos.MethodDescriptorProto parseFr } public static com.google.protobuf.DescriptorProtos.MethodDescriptorProto parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.MethodDescriptorProto parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.MethodDescriptorProto parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -23437,20 +23437,20 @@ public static com.google.protobuf.DescriptorProtos.MethodDescriptorProto parseDe java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.MethodDescriptorProto parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.MethodDescriptorProto parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -23470,7 +23470,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -23482,7 +23482,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.MethodDescriptorProto} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements + com.google.protobuf.GeneratedMessageV3Internal.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.MethodDescriptorProto) com.google.protobuf.DescriptorProtos.MethodDescriptorProtoOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -23491,7 +23491,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_MethodDescriptorProto_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -23504,12 +23504,12 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { - if (com.google.protobuf.FlattenedGeneratedMessageV3 + if (com.google.protobuf.GeneratedMessageV3Internal .alwaysUseFieldBuilders) { getOptionsFieldBuilder(); } @@ -24307,7 +24307,7 @@ public com.google.protobuf.DescriptorProtos.MethodDescriptorProto getDefaultInst public interface FileOptionsOrBuilder extends // @@protoc_insertion_point(interface_extends:google.protobuf.FileOptions) - com.google.protobuf.FlattenedGeneratedMessageV3. + com.google.protobuf.GeneratedMessageV3Internal. ExtendableMessageOrBuilder { /** @@ -24960,13 +24960,13 @@ com.google.protobuf.DescriptorProtos.UninterpretedOptionOrBuilder getUninterpret * Protobuf type {@code google.protobuf.FileOptions} */ public static final class FileOptions extends - com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableMessage< + com.google.protobuf.GeneratedMessageV3Internal.ExtendableMessage< FileOptions> implements // @@protoc_insertion_point(message_implements:google.protobuf.FileOptions) FileOptionsOrBuilder { private static final long serialVersionUID = 0L; // Use FileOptions.newBuilder() to construct. - private FileOptions(com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableBuilder builder) { + private FileOptions(com.google.protobuf.GeneratedMessageV3Internal.ExtendableBuilder builder) { super(builder); } private FileOptions() { @@ -24998,7 +24998,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_FileOptions_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -26234,14 +26234,14 @@ public final boolean isInitialized() { @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - com.google.protobuf.FlattenedGeneratedMessageV3 + com.google.protobuf.GeneratedMessageV3Internal .ExtendableMessage.ExtensionWriter extensionWriter = newExtensionWriter(); if (((bitField0_ & 0x00000001) != 0)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 1, javaPackage_); + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 1, javaPackage_); } if (((bitField0_ & 0x00000002) != 0)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 8, javaOuterClassname_); + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 8, javaOuterClassname_); } if (((bitField0_ & 0x00000020) != 0)) { output.writeEnum(9, optimizeFor_); @@ -26250,7 +26250,7 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) output.writeBool(10, javaMultipleFiles_); } if (((bitField0_ & 0x00000040) != 0)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 11, goPackage_); + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 11, goPackage_); } if (((bitField0_ & 0x00000080) != 0)) { output.writeBool(16, ccGenericServices_); @@ -26274,25 +26274,25 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) output.writeBool(31, ccEnableArenas_); } if (((bitField0_ & 0x00001000) != 0)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 36, objcClassPrefix_); + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 36, objcClassPrefix_); } if (((bitField0_ & 0x00002000) != 0)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 37, csharpNamespace_); + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 37, csharpNamespace_); } if (((bitField0_ & 0x00004000) != 0)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 39, swiftPrefix_); + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 39, swiftPrefix_); } if (((bitField0_ & 0x00008000) != 0)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 40, phpClassPrefix_); + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 40, phpClassPrefix_); } if (((bitField0_ & 0x00010000) != 0)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 41, phpNamespace_); + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 41, phpNamespace_); } if (((bitField0_ & 0x00020000) != 0)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 44, phpMetadataNamespace_); + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 44, phpMetadataNamespace_); } if (((bitField0_ & 0x00040000) != 0)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 45, rubyPackage_); + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 45, rubyPackage_); } if (((bitField0_ & 0x00080000) != 0)) { output.writeMessage(50, getFeatures()); @@ -26311,10 +26311,10 @@ public int getSerializedSize() { size = 0; if (((bitField0_ & 0x00000001) != 0)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(1, javaPackage_); + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(1, javaPackage_); } if (((bitField0_ & 0x00000002) != 0)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(8, javaOuterClassname_); + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(8, javaOuterClassname_); } if (((bitField0_ & 0x00000020) != 0)) { size += com.google.protobuf.CodedOutputStream @@ -26325,7 +26325,7 @@ public int getSerializedSize() { .computeBoolSize(10, javaMultipleFiles_); } if (((bitField0_ & 0x00000040) != 0)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(11, goPackage_); + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(11, goPackage_); } if (((bitField0_ & 0x00000080) != 0)) { size += com.google.protobuf.CodedOutputStream @@ -26356,25 +26356,25 @@ public int getSerializedSize() { .computeBoolSize(31, ccEnableArenas_); } if (((bitField0_ & 0x00001000) != 0)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(36, objcClassPrefix_); + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(36, objcClassPrefix_); } if (((bitField0_ & 0x00002000) != 0)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(37, csharpNamespace_); + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(37, csharpNamespace_); } if (((bitField0_ & 0x00004000) != 0)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(39, swiftPrefix_); + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(39, swiftPrefix_); } if (((bitField0_ & 0x00008000) != 0)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(40, phpClassPrefix_); + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(40, phpClassPrefix_); } if (((bitField0_ & 0x00010000) != 0)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(41, phpNamespace_); + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(41, phpNamespace_); } if (((bitField0_ & 0x00020000) != 0)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(44, phpMetadataNamespace_); + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(44, phpMetadataNamespace_); } if (((bitField0_ & 0x00040000) != 0)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(45, rubyPackage_); + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(45, rubyPackage_); } if (((bitField0_ & 0x00080000) != 0)) { size += com.google.protobuf.CodedOutputStream @@ -26646,20 +26646,20 @@ public static com.google.protobuf.DescriptorProtos.FileOptions parseFrom( } public static com.google.protobuf.DescriptorProtos.FileOptions parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.FileOptions parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.FileOptions parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -26667,20 +26667,20 @@ public static com.google.protobuf.DescriptorProtos.FileOptions parseDelimitedFro java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.FileOptions parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.FileOptions parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -26700,7 +26700,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -26708,7 +26708,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.FileOptions} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableBuilder< + com.google.protobuf.GeneratedMessageV3Internal.ExtendableBuilder< com.google.protobuf.DescriptorProtos.FileOptions, Builder> implements // @@protoc_insertion_point(builder_implements:google.protobuf.FileOptions) com.google.protobuf.DescriptorProtos.FileOptionsOrBuilder { @@ -26718,7 +26718,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_FileOptions_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -26731,12 +26731,12 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { - if (com.google.protobuf.FlattenedGeneratedMessageV3 + if (com.google.protobuf.GeneratedMessageV3Internal .alwaysUseFieldBuilders) { getFeaturesFieldBuilder(); getUninterpretedOptionFieldBuilder(); @@ -27079,7 +27079,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.FileOptions other) uninterpretedOption_ = other.uninterpretedOption_; bitField0_ = (bitField0_ & ~0x00100000); uninterpretedOptionBuilder_ = - com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.GeneratedMessageV3Internal.alwaysUseFieldBuilders ? getUninterpretedOptionFieldBuilder() : null; } else { uninterpretedOptionBuilder_.addAllMessages(other.uninterpretedOption_); @@ -29386,7 +29386,7 @@ public Builder addAllUninterpretedOption( java.lang.Iterable values) { if (uninterpretedOptionBuilder_ == null) { ensureUninterpretedOptionIsMutable(); - com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( + com.google.protobuf.GeneratedMessageV3Internal.Builder.addAll( values, uninterpretedOption_); onChanged(); } else { @@ -29590,7 +29590,7 @@ public com.google.protobuf.DescriptorProtos.FileOptions getDefaultInstanceForTyp public interface MessageOptionsOrBuilder extends // @@protoc_insertion_point(interface_extends:google.protobuf.MessageOptions) - com.google.protobuf.FlattenedGeneratedMessageV3. + com.google.protobuf.GeneratedMessageV3Internal. ExtendableMessageOrBuilder { /** @@ -29878,13 +29878,13 @@ com.google.protobuf.DescriptorProtos.UninterpretedOptionOrBuilder getUninterpret * Protobuf type {@code google.protobuf.MessageOptions} */ public static final class MessageOptions extends - com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableMessage< + com.google.protobuf.GeneratedMessageV3Internal.ExtendableMessage< MessageOptions> implements // @@protoc_insertion_point(message_implements:google.protobuf.MessageOptions) MessageOptionsOrBuilder { private static final long serialVersionUID = 0L; // Use MessageOptions.newBuilder() to construct. - private MessageOptions(com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableBuilder builder) { + private MessageOptions(com.google.protobuf.GeneratedMessageV3Internal.ExtendableBuilder builder) { super(builder); } private MessageOptions() { @@ -29904,7 +29904,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_MessageOptions_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -30291,7 +30291,7 @@ public final boolean isInitialized() { @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - com.google.protobuf.FlattenedGeneratedMessageV3 + com.google.protobuf.GeneratedMessageV3Internal .ExtendableMessage.ExtensionWriter extensionWriter = newExtensionWriter(); if (((bitField0_ & 0x00000001) != 0)) { @@ -30487,20 +30487,20 @@ public static com.google.protobuf.DescriptorProtos.MessageOptions parseFrom( } public static com.google.protobuf.DescriptorProtos.MessageOptions parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.MessageOptions parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.MessageOptions parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -30508,20 +30508,20 @@ public static com.google.protobuf.DescriptorProtos.MessageOptions parseDelimited java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.MessageOptions parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.MessageOptions parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -30541,7 +30541,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -30549,7 +30549,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.MessageOptions} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableBuilder< + com.google.protobuf.GeneratedMessageV3Internal.ExtendableBuilder< com.google.protobuf.DescriptorProtos.MessageOptions, Builder> implements // @@protoc_insertion_point(builder_implements:google.protobuf.MessageOptions) com.google.protobuf.DescriptorProtos.MessageOptionsOrBuilder { @@ -30559,7 +30559,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_MessageOptions_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -30572,12 +30572,12 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { - if (com.google.protobuf.FlattenedGeneratedMessageV3 + if (com.google.protobuf.GeneratedMessageV3Internal .alwaysUseFieldBuilders) { getFeaturesFieldBuilder(); getUninterpretedOptionFieldBuilder(); @@ -30788,7 +30788,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.MessageOptions oth uninterpretedOption_ = other.uninterpretedOption_; bitField0_ = (bitField0_ & ~0x00000040); uninterpretedOptionBuilder_ = - com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.GeneratedMessageV3Internal.alwaysUseFieldBuilders ? getUninterpretedOptionFieldBuilder() : null; } else { uninterpretedOptionBuilder_.addAllMessages(other.uninterpretedOption_); @@ -31754,7 +31754,7 @@ public Builder addAllUninterpretedOption( java.lang.Iterable values) { if (uninterpretedOptionBuilder_ == null) { ensureUninterpretedOptionIsMutable(); - com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( + com.google.protobuf.GeneratedMessageV3Internal.Builder.addAll( values, uninterpretedOption_); onChanged(); } else { @@ -31950,7 +31950,7 @@ public com.google.protobuf.DescriptorProtos.MessageOptions getDefaultInstanceFor public interface FieldOptionsOrBuilder extends // @@protoc_insertion_point(interface_extends:google.protobuf.FieldOptions) - com.google.protobuf.FlattenedGeneratedMessageV3. + com.google.protobuf.GeneratedMessageV3Internal. ExtendableMessageOrBuilder { /** @@ -32354,13 +32354,13 @@ com.google.protobuf.DescriptorProtos.UninterpretedOptionOrBuilder getUninterpret * Protobuf type {@code google.protobuf.FieldOptions} */ public static final class FieldOptions extends - com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableMessage< + com.google.protobuf.GeneratedMessageV3Internal.ExtendableMessage< FieldOptions> implements // @@protoc_insertion_point(message_implements:google.protobuf.FieldOptions) FieldOptionsOrBuilder { private static final long serialVersionUID = 0L; // Use FieldOptions.newBuilder() to construct. - private FieldOptions(com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableBuilder builder) { + private FieldOptions(com.google.protobuf.GeneratedMessageV3Internal.ExtendableBuilder builder) { super(builder); } private FieldOptions() { @@ -32385,7 +32385,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_FieldOptions_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -32983,12 +32983,12 @@ public interface EditionDefaultOrBuilder extends * Protobuf type {@code google.protobuf.FieldOptions.EditionDefault} */ public static final class EditionDefault extends - com.google.protobuf.FlattenedGeneratedMessageV3 implements + com.google.protobuf.GeneratedMessageV3Internal implements // @@protoc_insertion_point(message_implements:google.protobuf.FieldOptions.EditionDefault) EditionDefaultOrBuilder { private static final long serialVersionUID = 0L; // Use EditionDefault.newBuilder() to construct. - private EditionDefault(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { + private EditionDefault(com.google.protobuf.GeneratedMessageV3Internal.Builder builder) { super(builder); } private EditionDefault() { @@ -33009,7 +33009,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_FieldOptions_EditionDefault_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -33111,7 +33111,7 @@ public final boolean isInitialized() { public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { if (((bitField0_ & 0x00000002) != 0)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 2, value_); + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 2, value_); } if (((bitField0_ & 0x00000001) != 0)) { output.writeEnum(3, edition_); @@ -33126,7 +33126,7 @@ public int getSerializedSize() { size = 0; if (((bitField0_ & 0x00000002) != 0)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(2, value_); + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(2, value_); } if (((bitField0_ & 0x00000001) != 0)) { size += com.google.protobuf.CodedOutputStream @@ -33214,20 +33214,20 @@ public static com.google.protobuf.DescriptorProtos.FieldOptions.EditionDefault p } public static com.google.protobuf.DescriptorProtos.FieldOptions.EditionDefault parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.FieldOptions.EditionDefault parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.FieldOptions.EditionDefault parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -33235,20 +33235,20 @@ public static com.google.protobuf.DescriptorProtos.FieldOptions.EditionDefault p java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.FieldOptions.EditionDefault parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.FieldOptions.EditionDefault parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -33268,7 +33268,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -33276,7 +33276,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.FieldOptions.EditionDefault} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements + com.google.protobuf.GeneratedMessageV3Internal.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.FieldOptions.EditionDefault) com.google.protobuf.DescriptorProtos.FieldOptions.EditionDefaultOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -33285,7 +33285,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_FieldOptions_EditionDefault_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -33298,7 +33298,7 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); } @@ -33785,12 +33785,12 @@ public interface FeatureSupportOrBuilder extends * Protobuf type {@code google.protobuf.FieldOptions.FeatureSupport} */ public static final class FeatureSupport extends - com.google.protobuf.FlattenedGeneratedMessageV3 implements + com.google.protobuf.GeneratedMessageV3Internal implements // @@protoc_insertion_point(message_implements:google.protobuf.FieldOptions.FeatureSupport) FeatureSupportOrBuilder { private static final long serialVersionUID = 0L; // Use FeatureSupport.newBuilder() to construct. - private FeatureSupport(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { + private FeatureSupport(com.google.protobuf.GeneratedMessageV3Internal.Builder builder) { super(builder); } private FeatureSupport() { @@ -33813,7 +33813,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_FieldOptions_FeatureSupport_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -33994,7 +33994,7 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) output.writeEnum(2, editionDeprecated_); } if (((bitField0_ & 0x00000004) != 0)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 3, deprecationWarning_); + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 3, deprecationWarning_); } if (((bitField0_ & 0x00000008) != 0)) { output.writeEnum(4, editionRemoved_); @@ -34017,7 +34017,7 @@ public int getSerializedSize() { .computeEnumSize(2, editionDeprecated_); } if (((bitField0_ & 0x00000004) != 0)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(3, deprecationWarning_); + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(3, deprecationWarning_); } if (((bitField0_ & 0x00000008) != 0)) { size += com.google.protobuf.CodedOutputStream @@ -34121,20 +34121,20 @@ public static com.google.protobuf.DescriptorProtos.FieldOptions.FeatureSupport p } public static com.google.protobuf.DescriptorProtos.FieldOptions.FeatureSupport parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.FieldOptions.FeatureSupport parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.FieldOptions.FeatureSupport parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -34142,20 +34142,20 @@ public static com.google.protobuf.DescriptorProtos.FieldOptions.FeatureSupport p java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.FieldOptions.FeatureSupport parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.FieldOptions.FeatureSupport parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -34175,7 +34175,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -34187,7 +34187,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.FieldOptions.FeatureSupport} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements + com.google.protobuf.GeneratedMessageV3Internal.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.FieldOptions.FeatureSupport) com.google.protobuf.DescriptorProtos.FieldOptions.FeatureSupportOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -34196,7 +34196,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_FieldOptions_FeatureSupport_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -34209,7 +34209,7 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); } @@ -35358,7 +35358,7 @@ public final boolean isInitialized() { @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - com.google.protobuf.FlattenedGeneratedMessageV3 + com.google.protobuf.GeneratedMessageV3Internal .ExtendableMessage.ExtensionWriter extensionWriter = newExtensionWriter(); if (((bitField0_ & 0x00000001) != 0)) { @@ -35662,20 +35662,20 @@ public static com.google.protobuf.DescriptorProtos.FieldOptions parseFrom( } public static com.google.protobuf.DescriptorProtos.FieldOptions parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.FieldOptions parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.FieldOptions parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -35683,20 +35683,20 @@ public static com.google.protobuf.DescriptorProtos.FieldOptions parseDelimitedFr java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.FieldOptions parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.FieldOptions parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -35716,7 +35716,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -35724,7 +35724,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.FieldOptions} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableBuilder< + com.google.protobuf.GeneratedMessageV3Internal.ExtendableBuilder< com.google.protobuf.DescriptorProtos.FieldOptions, Builder> implements // @@protoc_insertion_point(builder_implements:google.protobuf.FieldOptions) com.google.protobuf.DescriptorProtos.FieldOptionsOrBuilder { @@ -35734,7 +35734,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_FieldOptions_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -35747,12 +35747,12 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { - if (com.google.protobuf.FlattenedGeneratedMessageV3 + if (com.google.protobuf.GeneratedMessageV3Internal .alwaysUseFieldBuilders) { getEditionDefaultsFieldBuilder(); getFeaturesFieldBuilder(); @@ -36038,7 +36038,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.FieldOptions other editionDefaults_ = other.editionDefaults_; bitField0_ = (bitField0_ & ~0x00000400); editionDefaultsBuilder_ = - com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.GeneratedMessageV3Internal.alwaysUseFieldBuilders ? getEditionDefaultsFieldBuilder() : null; } else { editionDefaultsBuilder_.addAllMessages(other.editionDefaults_); @@ -36070,7 +36070,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.FieldOptions other uninterpretedOption_ = other.uninterpretedOption_; bitField0_ = (bitField0_ & ~0x00002000); uninterpretedOptionBuilder_ = - com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.GeneratedMessageV3Internal.alwaysUseFieldBuilders ? getUninterpretedOptionFieldBuilder() : null; } else { uninterpretedOptionBuilder_.addAllMessages(other.uninterpretedOption_); @@ -37186,7 +37186,7 @@ public Builder addAllEditionDefaults( java.lang.Iterable values) { if (editionDefaultsBuilder_ == null) { ensureEditionDefaultsIsMutable(); - com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( + com.google.protobuf.GeneratedMessageV3Internal.Builder.addAll( values, editionDefaults_); onChanged(); } else { @@ -37771,7 +37771,7 @@ public Builder addAllUninterpretedOption( java.lang.Iterable values) { if (uninterpretedOptionBuilder_ == null) { ensureUninterpretedOptionIsMutable(); - com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( + com.google.protobuf.GeneratedMessageV3Internal.Builder.addAll( values, uninterpretedOption_); onChanged(); } else { @@ -37967,7 +37967,7 @@ public com.google.protobuf.DescriptorProtos.FieldOptions getDefaultInstanceForTy public interface OneofOptionsOrBuilder extends // @@protoc_insertion_point(interface_extends:google.protobuf.OneofOptions) - com.google.protobuf.FlattenedGeneratedMessageV3. + com.google.protobuf.GeneratedMessageV3Internal. ExtendableMessageOrBuilder { /** @@ -38054,13 +38054,13 @@ com.google.protobuf.DescriptorProtos.UninterpretedOptionOrBuilder getUninterpret * Protobuf type {@code google.protobuf.OneofOptions} */ public static final class OneofOptions extends - com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableMessage< + com.google.protobuf.GeneratedMessageV3Internal.ExtendableMessage< OneofOptions> implements // @@protoc_insertion_point(message_implements:google.protobuf.OneofOptions) OneofOptionsOrBuilder { private static final long serialVersionUID = 0L; // Use OneofOptions.newBuilder() to construct. - private OneofOptions(com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableBuilder builder) { + private OneofOptions(com.google.protobuf.GeneratedMessageV3Internal.ExtendableBuilder builder) { super(builder); } private OneofOptions() { @@ -38080,7 +38080,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_OneofOptions_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -38226,7 +38226,7 @@ public final boolean isInitialized() { @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - com.google.protobuf.FlattenedGeneratedMessageV3 + com.google.protobuf.GeneratedMessageV3Internal .ExtendableMessage.ExtensionWriter extensionWriter = newExtensionWriter(); if (((bitField0_ & 0x00000001) != 0)) { @@ -38337,20 +38337,20 @@ public static com.google.protobuf.DescriptorProtos.OneofOptions parseFrom( } public static com.google.protobuf.DescriptorProtos.OneofOptions parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.OneofOptions parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.OneofOptions parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -38358,20 +38358,20 @@ public static com.google.protobuf.DescriptorProtos.OneofOptions parseDelimitedFr java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.OneofOptions parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.OneofOptions parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -38391,7 +38391,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -38399,7 +38399,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.OneofOptions} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableBuilder< + com.google.protobuf.GeneratedMessageV3Internal.ExtendableBuilder< com.google.protobuf.DescriptorProtos.OneofOptions, Builder> implements // @@protoc_insertion_point(builder_implements:google.protobuf.OneofOptions) com.google.protobuf.DescriptorProtos.OneofOptionsOrBuilder { @@ -38409,7 +38409,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_OneofOptions_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -38422,12 +38422,12 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { - if (com.google.protobuf.FlattenedGeneratedMessageV3 + if (com.google.protobuf.GeneratedMessageV3Internal .alwaysUseFieldBuilders) { getFeaturesFieldBuilder(); getUninterpretedOptionFieldBuilder(); @@ -38598,7 +38598,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.OneofOptions other uninterpretedOption_ = other.uninterpretedOption_; bitField0_ = (bitField0_ & ~0x00000002); uninterpretedOptionBuilder_ = - com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.GeneratedMessageV3Internal.alwaysUseFieldBuilders ? getUninterpretedOptionFieldBuilder() : null; } else { uninterpretedOptionBuilder_.addAllMessages(other.uninterpretedOption_); @@ -39047,7 +39047,7 @@ public Builder addAllUninterpretedOption( java.lang.Iterable values) { if (uninterpretedOptionBuilder_ == null) { ensureUninterpretedOptionIsMutable(); - com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( + com.google.protobuf.GeneratedMessageV3Internal.Builder.addAll( values, uninterpretedOption_); onChanged(); } else { @@ -39243,7 +39243,7 @@ public com.google.protobuf.DescriptorProtos.OneofOptions getDefaultInstanceForTy public interface EnumOptionsOrBuilder extends // @@protoc_insertion_point(interface_extends:google.protobuf.EnumOptions) - com.google.protobuf.FlattenedGeneratedMessageV3. + com.google.protobuf.GeneratedMessageV3Internal. ExtendableMessageOrBuilder { /** @@ -39409,13 +39409,13 @@ com.google.protobuf.DescriptorProtos.UninterpretedOptionOrBuilder getUninterpret * Protobuf type {@code google.protobuf.EnumOptions} */ public static final class EnumOptions extends - com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableMessage< + com.google.protobuf.GeneratedMessageV3Internal.ExtendableMessage< EnumOptions> implements // @@protoc_insertion_point(message_implements:google.protobuf.EnumOptions) EnumOptionsOrBuilder { private static final long serialVersionUID = 0L; // Use EnumOptions.newBuilder() to construct. - private EnumOptions(com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableBuilder builder) { + private EnumOptions(com.google.protobuf.GeneratedMessageV3Internal.ExtendableBuilder builder) { super(builder); } private EnumOptions() { @@ -39435,7 +39435,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_EnumOptions_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -39684,7 +39684,7 @@ public final boolean isInitialized() { @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - com.google.protobuf.FlattenedGeneratedMessageV3 + com.google.protobuf.GeneratedMessageV3Internal .ExtendableMessage.ExtensionWriter extensionWriter = newExtensionWriter(); if (((bitField0_ & 0x00000001) != 0)) { @@ -39846,20 +39846,20 @@ public static com.google.protobuf.DescriptorProtos.EnumOptions parseFrom( } public static com.google.protobuf.DescriptorProtos.EnumOptions parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.EnumOptions parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.EnumOptions parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -39867,20 +39867,20 @@ public static com.google.protobuf.DescriptorProtos.EnumOptions parseDelimitedFro java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.EnumOptions parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.EnumOptions parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -39900,7 +39900,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -39908,7 +39908,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.EnumOptions} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableBuilder< + com.google.protobuf.GeneratedMessageV3Internal.ExtendableBuilder< com.google.protobuf.DescriptorProtos.EnumOptions, Builder> implements // @@protoc_insertion_point(builder_implements:google.protobuf.EnumOptions) com.google.protobuf.DescriptorProtos.EnumOptionsOrBuilder { @@ -39918,7 +39918,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_EnumOptions_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -39931,12 +39931,12 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { - if (com.google.protobuf.FlattenedGeneratedMessageV3 + if (com.google.protobuf.GeneratedMessageV3Internal .alwaysUseFieldBuilders) { getFeaturesFieldBuilder(); getUninterpretedOptionFieldBuilder(); @@ -40131,7 +40131,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.EnumOptions other) uninterpretedOption_ = other.uninterpretedOption_; bitField0_ = (bitField0_ & ~0x00000010); uninterpretedOptionBuilder_ = - com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.GeneratedMessageV3Internal.alwaysUseFieldBuilders ? getUninterpretedOptionFieldBuilder() : null; } else { uninterpretedOptionBuilder_.addAllMessages(other.uninterpretedOption_); @@ -40807,7 +40807,7 @@ public Builder addAllUninterpretedOption( java.lang.Iterable values) { if (uninterpretedOptionBuilder_ == null) { ensureUninterpretedOptionIsMutable(); - com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( + com.google.protobuf.GeneratedMessageV3Internal.Builder.addAll( values, uninterpretedOption_); onChanged(); } else { @@ -41003,7 +41003,7 @@ public com.google.protobuf.DescriptorProtos.EnumOptions getDefaultInstanceForTyp public interface EnumValueOptionsOrBuilder extends // @@protoc_insertion_point(interface_extends:google.protobuf.EnumValueOptions) - com.google.protobuf.FlattenedGeneratedMessageV3. + com.google.protobuf.GeneratedMessageV3Internal. ExtendableMessageOrBuilder { /** @@ -41165,13 +41165,13 @@ com.google.protobuf.DescriptorProtos.UninterpretedOptionOrBuilder getUninterpret * Protobuf type {@code google.protobuf.EnumValueOptions} */ public static final class EnumValueOptions extends - com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableMessage< + com.google.protobuf.GeneratedMessageV3Internal.ExtendableMessage< EnumValueOptions> implements // @@protoc_insertion_point(message_implements:google.protobuf.EnumValueOptions) EnumValueOptionsOrBuilder { private static final long serialVersionUID = 0L; // Use EnumValueOptions.newBuilder() to construct. - private EnumValueOptions(com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableBuilder builder) { + private EnumValueOptions(com.google.protobuf.GeneratedMessageV3Internal.ExtendableBuilder builder) { super(builder); } private EnumValueOptions() { @@ -41191,7 +41191,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_EnumValueOptions_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -41439,7 +41439,7 @@ public final boolean isInitialized() { @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - com.google.protobuf.FlattenedGeneratedMessageV3 + com.google.protobuf.GeneratedMessageV3Internal .ExtendableMessage.ExtensionWriter extensionWriter = newExtensionWriter(); if (((bitField0_ & 0x00000001) != 0)) { @@ -41600,20 +41600,20 @@ public static com.google.protobuf.DescriptorProtos.EnumValueOptions parseFrom( } public static com.google.protobuf.DescriptorProtos.EnumValueOptions parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.EnumValueOptions parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.EnumValueOptions parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -41621,20 +41621,20 @@ public static com.google.protobuf.DescriptorProtos.EnumValueOptions parseDelimit java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.EnumValueOptions parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.EnumValueOptions parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -41654,7 +41654,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -41662,7 +41662,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.EnumValueOptions} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableBuilder< + com.google.protobuf.GeneratedMessageV3Internal.ExtendableBuilder< com.google.protobuf.DescriptorProtos.EnumValueOptions, Builder> implements // @@protoc_insertion_point(builder_implements:google.protobuf.EnumValueOptions) com.google.protobuf.DescriptorProtos.EnumValueOptionsOrBuilder { @@ -41672,7 +41672,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_EnumValueOptions_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -41685,12 +41685,12 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { - if (com.google.protobuf.FlattenedGeneratedMessageV3 + if (com.google.protobuf.GeneratedMessageV3Internal .alwaysUseFieldBuilders) { getFeaturesFieldBuilder(); getFeatureSupportFieldBuilder(); @@ -41892,7 +41892,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.EnumValueOptions o uninterpretedOption_ = other.uninterpretedOption_; bitField0_ = (bitField0_ & ~0x00000010); uninterpretedOptionBuilder_ = - com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.GeneratedMessageV3Internal.alwaysUseFieldBuilders ? getUninterpretedOptionFieldBuilder() : null; } else { uninterpretedOptionBuilder_.addAllMessages(other.uninterpretedOption_); @@ -42647,7 +42647,7 @@ public Builder addAllUninterpretedOption( java.lang.Iterable values) { if (uninterpretedOptionBuilder_ == null) { ensureUninterpretedOptionIsMutable(); - com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( + com.google.protobuf.GeneratedMessageV3Internal.Builder.addAll( values, uninterpretedOption_); onChanged(); } else { @@ -42843,7 +42843,7 @@ public com.google.protobuf.DescriptorProtos.EnumValueOptions getDefaultInstanceF public interface ServiceOptionsOrBuilder extends // @@protoc_insertion_point(interface_extends:google.protobuf.ServiceOptions) - com.google.protobuf.FlattenedGeneratedMessageV3. + com.google.protobuf.GeneratedMessageV3Internal. ExtendableMessageOrBuilder { /** @@ -42955,13 +42955,13 @@ com.google.protobuf.DescriptorProtos.UninterpretedOptionOrBuilder getUninterpret * Protobuf type {@code google.protobuf.ServiceOptions} */ public static final class ServiceOptions extends - com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableMessage< + com.google.protobuf.GeneratedMessageV3Internal.ExtendableMessage< ServiceOptions> implements // @@protoc_insertion_point(message_implements:google.protobuf.ServiceOptions) ServiceOptionsOrBuilder { private static final long serialVersionUID = 0L; // Use ServiceOptions.newBuilder() to construct. - private ServiceOptions(com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableBuilder builder) { + private ServiceOptions(com.google.protobuf.GeneratedMessageV3Internal.ExtendableBuilder builder) { super(builder); } private ServiceOptions() { @@ -42981,7 +42981,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_ServiceOptions_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -43160,7 +43160,7 @@ public final boolean isInitialized() { @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - com.google.protobuf.FlattenedGeneratedMessageV3 + com.google.protobuf.GeneratedMessageV3Internal .ExtendableMessage.ExtensionWriter extensionWriter = newExtensionWriter(); if (((bitField0_ & 0x00000002) != 0)) { @@ -43288,20 +43288,20 @@ public static com.google.protobuf.DescriptorProtos.ServiceOptions parseFrom( } public static com.google.protobuf.DescriptorProtos.ServiceOptions parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.ServiceOptions parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.ServiceOptions parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -43309,20 +43309,20 @@ public static com.google.protobuf.DescriptorProtos.ServiceOptions parseDelimited java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.ServiceOptions parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.ServiceOptions parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -43342,7 +43342,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -43350,7 +43350,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.ServiceOptions} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableBuilder< + com.google.protobuf.GeneratedMessageV3Internal.ExtendableBuilder< com.google.protobuf.DescriptorProtos.ServiceOptions, Builder> implements // @@protoc_insertion_point(builder_implements:google.protobuf.ServiceOptions) com.google.protobuf.DescriptorProtos.ServiceOptionsOrBuilder { @@ -43360,7 +43360,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_ServiceOptions_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -43373,12 +43373,12 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { - if (com.google.protobuf.FlattenedGeneratedMessageV3 + if (com.google.protobuf.GeneratedMessageV3Internal .alwaysUseFieldBuilders) { getFeaturesFieldBuilder(); getUninterpretedOptionFieldBuilder(); @@ -43557,7 +43557,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.ServiceOptions oth uninterpretedOption_ = other.uninterpretedOption_; bitField0_ = (bitField0_ & ~0x00000004); uninterpretedOptionBuilder_ = - com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.GeneratedMessageV3Internal.alwaysUseFieldBuilders ? getUninterpretedOptionFieldBuilder() : null; } else { uninterpretedOptionBuilder_.addAllMessages(other.uninterpretedOption_); @@ -44079,7 +44079,7 @@ public Builder addAllUninterpretedOption( java.lang.Iterable values) { if (uninterpretedOptionBuilder_ == null) { ensureUninterpretedOptionIsMutable(); - com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( + com.google.protobuf.GeneratedMessageV3Internal.Builder.addAll( values, uninterpretedOption_); onChanged(); } else { @@ -44275,7 +44275,7 @@ public com.google.protobuf.DescriptorProtos.ServiceOptions getDefaultInstanceFor public interface MethodOptionsOrBuilder extends // @@protoc_insertion_point(interface_extends:google.protobuf.MethodOptions) - com.google.protobuf.FlattenedGeneratedMessageV3. + com.google.protobuf.GeneratedMessageV3Internal. ExtendableMessageOrBuilder { /** @@ -44398,13 +44398,13 @@ com.google.protobuf.DescriptorProtos.UninterpretedOptionOrBuilder getUninterpret * Protobuf type {@code google.protobuf.MethodOptions} */ public static final class MethodOptions extends - com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableMessage< + com.google.protobuf.GeneratedMessageV3Internal.ExtendableMessage< MethodOptions> implements // @@protoc_insertion_point(message_implements:google.protobuf.MethodOptions) MethodOptionsOrBuilder { private static final long serialVersionUID = 0L; // Use MethodOptions.newBuilder() to construct. - private MethodOptions(com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableBuilder builder) { + private MethodOptions(com.google.protobuf.GeneratedMessageV3Internal.ExtendableBuilder builder) { super(builder); } private MethodOptions() { @@ -44425,7 +44425,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_MethodOptions_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -44749,7 +44749,7 @@ public final boolean isInitialized() { @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - com.google.protobuf.FlattenedGeneratedMessageV3 + com.google.protobuf.GeneratedMessageV3Internal .ExtendableMessage.ExtensionWriter extensionWriter = newExtensionWriter(); if (((bitField0_ & 0x00000001) != 0)) { @@ -44892,20 +44892,20 @@ public static com.google.protobuf.DescriptorProtos.MethodOptions parseFrom( } public static com.google.protobuf.DescriptorProtos.MethodOptions parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.MethodOptions parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.MethodOptions parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -44913,20 +44913,20 @@ public static com.google.protobuf.DescriptorProtos.MethodOptions parseDelimitedF java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.MethodOptions parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.MethodOptions parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -44946,7 +44946,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -44954,7 +44954,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.MethodOptions} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableBuilder< + com.google.protobuf.GeneratedMessageV3Internal.ExtendableBuilder< com.google.protobuf.DescriptorProtos.MethodOptions, Builder> implements // @@protoc_insertion_point(builder_implements:google.protobuf.MethodOptions) com.google.protobuf.DescriptorProtos.MethodOptionsOrBuilder { @@ -44964,7 +44964,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_MethodOptions_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -44977,12 +44977,12 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { - if (com.google.protobuf.FlattenedGeneratedMessageV3 + if (com.google.protobuf.GeneratedMessageV3Internal .alwaysUseFieldBuilders) { getFeaturesFieldBuilder(); getUninterpretedOptionFieldBuilder(); @@ -45169,7 +45169,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.MethodOptions othe uninterpretedOption_ = other.uninterpretedOption_; bitField0_ = (bitField0_ & ~0x00000008); uninterpretedOptionBuilder_ = - com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.GeneratedMessageV3Internal.alwaysUseFieldBuilders ? getUninterpretedOptionFieldBuilder() : null; } else { uninterpretedOptionBuilder_.addAllMessages(other.uninterpretedOption_); @@ -45745,7 +45745,7 @@ public Builder addAllUninterpretedOption( java.lang.Iterable values) { if (uninterpretedOptionBuilder_ == null) { ensureUninterpretedOptionIsMutable(); - com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( + com.google.protobuf.GeneratedMessageV3Internal.Builder.addAll( values, uninterpretedOption_); onChanged(); } else { @@ -46073,12 +46073,12 @@ com.google.protobuf.DescriptorProtos.UninterpretedOption.NamePartOrBuilder getNa * Protobuf type {@code google.protobuf.UninterpretedOption} */ public static final class UninterpretedOption extends - com.google.protobuf.FlattenedGeneratedMessageV3 implements + com.google.protobuf.GeneratedMessageV3Internal implements // @@protoc_insertion_point(message_implements:google.protobuf.UninterpretedOption) UninterpretedOptionOrBuilder { private static final long serialVersionUID = 0L; // Use UninterpretedOption.newBuilder() to construct. - private UninterpretedOption(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { + private UninterpretedOption(com.google.protobuf.GeneratedMessageV3Internal.Builder builder) { super(builder); } private UninterpretedOption() { @@ -46101,7 +46101,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_UninterpretedOption_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -46152,12 +46152,12 @@ public interface NamePartOrBuilder extends * Protobuf type {@code google.protobuf.UninterpretedOption.NamePart} */ public static final class NamePart extends - com.google.protobuf.FlattenedGeneratedMessageV3 implements + com.google.protobuf.GeneratedMessageV3Internal implements // @@protoc_insertion_point(message_implements:google.protobuf.UninterpretedOption.NamePart) NamePartOrBuilder { private static final long serialVersionUID = 0L; // Use NamePart.newBuilder() to construct. - private NamePart(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { + private NamePart(com.google.protobuf.GeneratedMessageV3Internal.Builder builder) { super(builder); } private NamePart() { @@ -46177,7 +46177,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_UninterpretedOption_NamePart_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -46276,7 +46276,7 @@ public final boolean isInitialized() { public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { if (((bitField0_ & 0x00000001) != 0)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 1, namePart_); + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 1, namePart_); } if (((bitField0_ & 0x00000002) != 0)) { output.writeBool(2, isExtension_); @@ -46291,7 +46291,7 @@ public int getSerializedSize() { size = 0; if (((bitField0_ & 0x00000001) != 0)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(1, namePart_); + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(1, namePart_); } if (((bitField0_ & 0x00000002) != 0)) { size += com.google.protobuf.CodedOutputStream @@ -46381,20 +46381,20 @@ public static com.google.protobuf.DescriptorProtos.UninterpretedOption.NamePart } public static com.google.protobuf.DescriptorProtos.UninterpretedOption.NamePart parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.UninterpretedOption.NamePart parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.UninterpretedOption.NamePart parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -46402,20 +46402,20 @@ public static com.google.protobuf.DescriptorProtos.UninterpretedOption.NamePart java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.UninterpretedOption.NamePart parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.UninterpretedOption.NamePart parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -46435,7 +46435,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -46451,7 +46451,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.UninterpretedOption.NamePart} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements + com.google.protobuf.GeneratedMessageV3Internal.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.UninterpretedOption.NamePart) com.google.protobuf.DescriptorProtos.UninterpretedOption.NamePartOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -46460,7 +46460,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_UninterpretedOption_NamePart_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -46473,7 +46473,7 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); } @@ -47077,7 +47077,7 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) output.writeMessage(2, name_.get(i)); } if (((bitField0_ & 0x00000001) != 0)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 3, identifierValue_); + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 3, identifierValue_); } if (((bitField0_ & 0x00000002) != 0)) { output.writeUInt64(4, positiveIntValue_); @@ -47092,7 +47092,7 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) output.writeBytes(7, stringValue_); } if (((bitField0_ & 0x00000020) != 0)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 8, aggregateValue_); + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 8, aggregateValue_); } getUnknownFields().writeTo(output); } @@ -47108,7 +47108,7 @@ public int getSerializedSize() { .computeMessageSize(2, name_.get(i)); } if (((bitField0_ & 0x00000001) != 0)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(3, identifierValue_); + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(3, identifierValue_); } if (((bitField0_ & 0x00000002) != 0)) { size += com.google.protobuf.CodedOutputStream @@ -47127,7 +47127,7 @@ public int getSerializedSize() { .computeBytesSize(7, stringValue_); } if (((bitField0_ & 0x00000020) != 0)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(8, aggregateValue_); + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(8, aggregateValue_); } size += getUnknownFields().getSerializedSize(); memoizedSize = size; @@ -47258,20 +47258,20 @@ public static com.google.protobuf.DescriptorProtos.UninterpretedOption parseFrom } public static com.google.protobuf.DescriptorProtos.UninterpretedOption parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.UninterpretedOption parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.UninterpretedOption parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -47279,20 +47279,20 @@ public static com.google.protobuf.DescriptorProtos.UninterpretedOption parseDeli java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.UninterpretedOption parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.UninterpretedOption parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -47312,7 +47312,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -47329,7 +47329,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.UninterpretedOption} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements + com.google.protobuf.GeneratedMessageV3Internal.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.UninterpretedOption) com.google.protobuf.DescriptorProtos.UninterpretedOptionOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -47338,7 +47338,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_UninterpretedOption_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -47351,7 +47351,7 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); } @@ -47509,7 +47509,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.UninterpretedOptio name_ = other.name_; bitField0_ = (bitField0_ & ~0x00000001); nameBuilder_ = - com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.GeneratedMessageV3Internal.alwaysUseFieldBuilders ? getNameFieldBuilder() : null; } else { nameBuilder_.addAllMessages(other.name_); @@ -47770,7 +47770,7 @@ public Builder addAllName( java.lang.Iterable values) { if (nameBuilder_ == null) { ensureNameIsMutable(); - com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( + com.google.protobuf.GeneratedMessageV3Internal.Builder.addAll( values, name_); onChanged(); } else { @@ -48284,7 +48284,7 @@ public com.google.protobuf.DescriptorProtos.UninterpretedOption getDefaultInstan public interface FeatureSetOrBuilder extends // @@protoc_insertion_point(interface_extends:google.protobuf.FeatureSet) - com.google.protobuf.FlattenedGeneratedMessageV3. + com.google.protobuf.GeneratedMessageV3Internal. ExtendableMessageOrBuilder { /** @@ -48366,13 +48366,13 @@ public interface FeatureSetOrBuilder extends * Protobuf type {@code google.protobuf.FeatureSet} */ public static final class FeatureSet extends - com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableMessage< + com.google.protobuf.GeneratedMessageV3Internal.ExtendableMessage< FeatureSet> implements // @@protoc_insertion_point(message_implements:google.protobuf.FeatureSet) FeatureSetOrBuilder { private static final long serialVersionUID = 0L; // Use FeatureSet.newBuilder() to construct. - private FeatureSet(com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableBuilder builder) { + private FeatureSet(com.google.protobuf.GeneratedMessageV3Internal.ExtendableBuilder builder) { super(builder); } private FeatureSet() { @@ -48397,7 +48397,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_FeatureSet_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -49170,7 +49170,7 @@ public final boolean isInitialized() { @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - com.google.protobuf.FlattenedGeneratedMessageV3 + com.google.protobuf.GeneratedMessageV3Internal .ExtendableMessage.ExtensionWriter extensionWriter = newExtensionWriter(); if (((bitField0_ & 0x00000001) != 0)) { @@ -49342,20 +49342,20 @@ public static com.google.protobuf.DescriptorProtos.FeatureSet parseFrom( } public static com.google.protobuf.DescriptorProtos.FeatureSet parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.FeatureSet parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.FeatureSet parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -49363,20 +49363,20 @@ public static com.google.protobuf.DescriptorProtos.FeatureSet parseDelimitedFrom java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.FeatureSet parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.FeatureSet parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -49396,7 +49396,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -49413,7 +49413,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.FeatureSet} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableBuilder< + com.google.protobuf.GeneratedMessageV3Internal.ExtendableBuilder< com.google.protobuf.DescriptorProtos.FeatureSet, Builder> implements // @@protoc_insertion_point(builder_implements:google.protobuf.FeatureSet) com.google.protobuf.DescriptorProtos.FeatureSetOrBuilder { @@ -49423,7 +49423,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_FeatureSet_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -49436,7 +49436,7 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); } @@ -50115,12 +50115,12 @@ com.google.protobuf.DescriptorProtos.FeatureSetDefaults.FeatureSetEditionDefault * Protobuf type {@code google.protobuf.FeatureSetDefaults} */ public static final class FeatureSetDefaults extends - com.google.protobuf.FlattenedGeneratedMessageV3 implements + com.google.protobuf.GeneratedMessageV3Internal implements // @@protoc_insertion_point(message_implements:google.protobuf.FeatureSetDefaults) FeatureSetDefaultsOrBuilder { private static final long serialVersionUID = 0L; // Use FeatureSetDefaults.newBuilder() to construct. - private FeatureSetDefaults(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { + private FeatureSetDefaults(com.google.protobuf.GeneratedMessageV3Internal.Builder builder) { super(builder); } private FeatureSetDefaults() { @@ -50142,7 +50142,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_FeatureSetDefaults_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -50229,12 +50229,12 @@ public interface FeatureSetEditionDefaultOrBuilder extends * Protobuf type {@code google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault} */ public static final class FeatureSetEditionDefault extends - com.google.protobuf.FlattenedGeneratedMessageV3 implements + com.google.protobuf.GeneratedMessageV3Internal implements // @@protoc_insertion_point(message_implements:google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault) FeatureSetEditionDefaultOrBuilder { private static final long serialVersionUID = 0L; // Use FeatureSetEditionDefault.newBuilder() to construct. - private FeatureSetEditionDefault(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { + private FeatureSetEditionDefault(com.google.protobuf.GeneratedMessageV3Internal.Builder builder) { super(builder); } private FeatureSetEditionDefault() { @@ -50254,7 +50254,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -50503,20 +50503,20 @@ public static com.google.protobuf.DescriptorProtos.FeatureSetDefaults.FeatureSet } public static com.google.protobuf.DescriptorProtos.FeatureSetDefaults.FeatureSetEditionDefault parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.FeatureSetDefaults.FeatureSetEditionDefault parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.FeatureSetDefaults.FeatureSetEditionDefault parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -50524,20 +50524,20 @@ public static com.google.protobuf.DescriptorProtos.FeatureSetDefaults.FeatureSet java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.FeatureSetDefaults.FeatureSetEditionDefault parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.FeatureSetDefaults.FeatureSetEditionDefault parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -50557,7 +50557,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -50572,7 +50572,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements + com.google.protobuf.GeneratedMessageV3Internal.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault) com.google.protobuf.DescriptorProtos.FeatureSetDefaults.FeatureSetEditionDefaultOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -50581,7 +50581,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -50594,12 +50594,12 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { - if (com.google.protobuf.FlattenedGeneratedMessageV3 + if (com.google.protobuf.GeneratedMessageV3Internal .alwaysUseFieldBuilders) { getOverridableFeaturesFieldBuilder(); getFixedFeaturesFieldBuilder(); @@ -51459,20 +51459,20 @@ public static com.google.protobuf.DescriptorProtos.FeatureSetDefaults parseFrom( } public static com.google.protobuf.DescriptorProtos.FeatureSetDefaults parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.FeatureSetDefaults parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.FeatureSetDefaults parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -51480,20 +51480,20 @@ public static com.google.protobuf.DescriptorProtos.FeatureSetDefaults parseDelim java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.FeatureSetDefaults parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.FeatureSetDefaults parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -51513,7 +51513,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -51528,7 +51528,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.FeatureSetDefaults} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements + com.google.protobuf.GeneratedMessageV3Internal.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.FeatureSetDefaults) com.google.protobuf.DescriptorProtos.FeatureSetDefaultsOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -51537,7 +51537,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_FeatureSetDefaults_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -51550,7 +51550,7 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); } @@ -51688,7 +51688,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.FeatureSetDefaults defaults_ = other.defaults_; bitField0_ = (bitField0_ & ~0x00000001); defaultsBuilder_ = - com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.GeneratedMessageV3Internal.alwaysUseFieldBuilders ? getDefaultsFieldBuilder() : null; } else { defaultsBuilder_.addAllMessages(other.defaults_); @@ -51927,7 +51927,7 @@ public Builder addAllDefaults( java.lang.Iterable values) { if (defaultsBuilder_ == null) { ensureDefaultsIsMutable(); - com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( + com.google.protobuf.GeneratedMessageV3Internal.Builder.addAll( values, defaults_); onChanged(); } else { @@ -52215,7 +52215,7 @@ public com.google.protobuf.DescriptorProtos.FeatureSetDefaults getDefaultInstanc public interface SourceCodeInfoOrBuilder extends // @@protoc_insertion_point(interface_extends:google.protobuf.SourceCodeInfo) - com.google.protobuf.FlattenedGeneratedMessageV3. + com.google.protobuf.GeneratedMessageV3Internal. ExtendableMessageOrBuilder { /** @@ -52481,13 +52481,13 @@ com.google.protobuf.DescriptorProtos.SourceCodeInfo.LocationOrBuilder getLocatio * Protobuf type {@code google.protobuf.SourceCodeInfo} */ public static final class SourceCodeInfo extends - com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableMessage< + com.google.protobuf.GeneratedMessageV3Internal.ExtendableMessage< SourceCodeInfo> implements // @@protoc_insertion_point(message_implements:google.protobuf.SourceCodeInfo) SourceCodeInfoOrBuilder { private static final long serialVersionUID = 0L; // Use SourceCodeInfo.newBuilder() to construct. - private SourceCodeInfo(com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableBuilder builder) { + private SourceCodeInfo(com.google.protobuf.GeneratedMessageV3Internal.ExtendableBuilder builder) { super(builder); } private SourceCodeInfo() { @@ -52507,7 +52507,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_SourceCodeInfo_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -52867,12 +52867,12 @@ public interface LocationOrBuilder extends * Protobuf type {@code google.protobuf.SourceCodeInfo.Location} */ public static final class Location extends - com.google.protobuf.FlattenedGeneratedMessageV3 implements + com.google.protobuf.GeneratedMessageV3Internal implements // @@protoc_insertion_point(message_implements:google.protobuf.SourceCodeInfo.Location) LocationOrBuilder { private static final long serialVersionUID = 0L; // Use Location.newBuilder() to construct. - private Location(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { + private Location(com.google.protobuf.GeneratedMessageV3Internal.Builder builder) { super(builder); } private Location() { @@ -52897,7 +52897,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_SourceCodeInfo_Location_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -53382,13 +53382,13 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) output.writeInt32NoTag(span_.getInt(i)); } if (((bitField0_ & 0x00000001) != 0)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 3, leadingComments_); + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 3, leadingComments_); } if (((bitField0_ & 0x00000002) != 0)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 4, trailingComments_); + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 4, trailingComments_); } for (int i = 0; i < leadingDetachedComments_.size(); i++) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 6, leadingDetachedComments_.getRaw(i)); + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 6, leadingDetachedComments_.getRaw(i)); } getUnknownFields().writeTo(output); } @@ -53428,10 +53428,10 @@ public int getSerializedSize() { spanMemoizedSerializedSize = dataSize; } if (((bitField0_ & 0x00000001) != 0)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(3, leadingComments_); + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(3, leadingComments_); } if (((bitField0_ & 0x00000002) != 0)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(4, trailingComments_); + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(4, trailingComments_); } { int dataSize = 0; @@ -53542,20 +53542,20 @@ public static com.google.protobuf.DescriptorProtos.SourceCodeInfo.Location parse } public static com.google.protobuf.DescriptorProtos.SourceCodeInfo.Location parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.SourceCodeInfo.Location parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.SourceCodeInfo.Location parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -53563,20 +53563,20 @@ public static com.google.protobuf.DescriptorProtos.SourceCodeInfo.Location parse java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.SourceCodeInfo.Location parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.SourceCodeInfo.Location parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -53596,7 +53596,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -53604,7 +53604,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.SourceCodeInfo.Location} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements + com.google.protobuf.GeneratedMessageV3Internal.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.SourceCodeInfo.Location) com.google.protobuf.DescriptorProtos.SourceCodeInfo.LocationOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -53613,7 +53613,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_SourceCodeInfo_Location_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -53626,7 +53626,7 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); } @@ -54097,7 +54097,7 @@ public Builder addPath(int value) { public Builder addAllPath( java.lang.Iterable values) { ensurePathIsMutable(); - com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( + com.google.protobuf.GeneratedMessageV3Internal.Builder.addAll( values, path_); bitField0_ |= 0x00000001; onChanged(); @@ -54255,7 +54255,7 @@ public Builder addSpan(int value) { public Builder addAllSpan( java.lang.Iterable values) { ensureSpanIsMutable(); - com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( + com.google.protobuf.GeneratedMessageV3Internal.Builder.addAll( values, span_); bitField0_ |= 0x00000002; onChanged(); @@ -54818,7 +54818,7 @@ public Builder addLeadingDetachedComments( public Builder addAllLeadingDetachedComments( java.lang.Iterable values) { ensureLeadingDetachedCommentsIsMutable(); - com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( + com.google.protobuf.GeneratedMessageV3Internal.Builder.addAll( values, leadingDetachedComments_); bitField0_ |= 0x00000010; onChanged(); @@ -55202,7 +55202,7 @@ public final boolean isInitialized() { @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - com.google.protobuf.FlattenedGeneratedMessageV3 + com.google.protobuf.GeneratedMessageV3Internal .ExtendableMessage.ExtensionWriter extensionWriter = newExtensionWriter(); for (int i = 0; i < location_.size(); i++) { @@ -55297,20 +55297,20 @@ public static com.google.protobuf.DescriptorProtos.SourceCodeInfo parseFrom( } public static com.google.protobuf.DescriptorProtos.SourceCodeInfo parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.SourceCodeInfo parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.SourceCodeInfo parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -55318,20 +55318,20 @@ public static com.google.protobuf.DescriptorProtos.SourceCodeInfo parseDelimited java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.SourceCodeInfo parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.SourceCodeInfo parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -55351,7 +55351,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -55364,7 +55364,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.SourceCodeInfo} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.ExtendableBuilder< + com.google.protobuf.GeneratedMessageV3Internal.ExtendableBuilder< com.google.protobuf.DescriptorProtos.SourceCodeInfo, Builder> implements // @@protoc_insertion_point(builder_implements:google.protobuf.SourceCodeInfo) com.google.protobuf.DescriptorProtos.SourceCodeInfoOrBuilder { @@ -55374,7 +55374,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_SourceCodeInfo_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -55387,7 +55387,7 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); } @@ -55540,7 +55540,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.SourceCodeInfo oth location_ = other.location_; bitField0_ = (bitField0_ & ~0x00000001); locationBuilder_ = - com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.GeneratedMessageV3Internal.alwaysUseFieldBuilders ? getLocationFieldBuilder() : null; } else { locationBuilder_.addAllMessages(other.location_); @@ -56208,7 +56208,7 @@ public Builder addAllLocation( java.lang.Iterable values) { if (locationBuilder_ == null) { ensureLocationIsMutable(); - com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( + com.google.protobuf.GeneratedMessageV3Internal.Builder.addAll( values, location_); onChanged(); } else { @@ -56801,12 +56801,12 @@ com.google.protobuf.DescriptorProtos.GeneratedCodeInfo.AnnotationOrBuilder getAn * Protobuf type {@code google.protobuf.GeneratedCodeInfo} */ public static final class GeneratedCodeInfo extends - com.google.protobuf.FlattenedGeneratedMessageV3 implements + com.google.protobuf.GeneratedMessageV3Internal implements // @@protoc_insertion_point(message_implements:google.protobuf.GeneratedCodeInfo) GeneratedCodeInfoOrBuilder { private static final long serialVersionUID = 0L; // Use GeneratedCodeInfo.newBuilder() to construct. - private GeneratedCodeInfo(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { + private GeneratedCodeInfo(com.google.protobuf.GeneratedMessageV3Internal.Builder builder) { super(builder); } private GeneratedCodeInfo() { @@ -56826,7 +56826,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_GeneratedCodeInfo_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -56957,12 +56957,12 @@ public interface AnnotationOrBuilder extends * Protobuf type {@code google.protobuf.GeneratedCodeInfo.Annotation} */ public static final class Annotation extends - com.google.protobuf.FlattenedGeneratedMessageV3 implements + com.google.protobuf.GeneratedMessageV3Internal implements // @@protoc_insertion_point(message_implements:google.protobuf.GeneratedCodeInfo.Annotation) AnnotationOrBuilder { private static final long serialVersionUID = 0L; // Use Annotation.newBuilder() to construct. - private Annotation(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { + private Annotation(com.google.protobuf.GeneratedMessageV3Internal.Builder builder) { super(builder); } private Annotation() { @@ -56984,7 +56984,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_GeneratedCodeInfo_Annotation_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -57333,7 +57333,7 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) output.writeInt32NoTag(path_.getInt(i)); } if (((bitField0_ & 0x00000001) != 0)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 2, sourceFile_); + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 2, sourceFile_); } if (((bitField0_ & 0x00000002) != 0)) { output.writeInt32(3, begin_); @@ -57368,7 +57368,7 @@ public int getSerializedSize() { pathMemoizedSerializedSize = dataSize; } if (((bitField0_ & 0x00000001) != 0)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(2, sourceFile_); + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(2, sourceFile_); } if (((bitField0_ & 0x00000002) != 0)) { size += com.google.protobuf.CodedOutputStream @@ -57488,20 +57488,20 @@ public static com.google.protobuf.DescriptorProtos.GeneratedCodeInfo.Annotation } public static com.google.protobuf.DescriptorProtos.GeneratedCodeInfo.Annotation parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.GeneratedCodeInfo.Annotation parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.GeneratedCodeInfo.Annotation parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -57509,20 +57509,20 @@ public static com.google.protobuf.DescriptorProtos.GeneratedCodeInfo.Annotation java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.GeneratedCodeInfo.Annotation parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.GeneratedCodeInfo.Annotation parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -57542,7 +57542,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -57550,7 +57550,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.GeneratedCodeInfo.Annotation} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements + com.google.protobuf.GeneratedMessageV3Internal.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.GeneratedCodeInfo.Annotation) com.google.protobuf.DescriptorProtos.GeneratedCodeInfo.AnnotationOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -57559,7 +57559,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_GeneratedCodeInfo_Annotation_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -57572,7 +57572,7 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); } @@ -57894,7 +57894,7 @@ public Builder addPath(int value) { public Builder addAllPath( java.lang.Iterable values) { ensurePathIsMutable(); - com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( + com.google.protobuf.GeneratedMessageV3Internal.Builder.addAll( values, path_); bitField0_ |= 0x00000001; onChanged(); @@ -58416,20 +58416,20 @@ public static com.google.protobuf.DescriptorProtos.GeneratedCodeInfo parseFrom( } public static com.google.protobuf.DescriptorProtos.GeneratedCodeInfo parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.GeneratedCodeInfo parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.GeneratedCodeInfo parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -58437,20 +58437,20 @@ public static com.google.protobuf.DescriptorProtos.GeneratedCodeInfo parseDelimi java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DescriptorProtos.GeneratedCodeInfo parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DescriptorProtos.GeneratedCodeInfo parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -58470,7 +58470,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -58484,7 +58484,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.GeneratedCodeInfo} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements + com.google.protobuf.GeneratedMessageV3Internal.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.GeneratedCodeInfo) com.google.protobuf.DescriptorProtos.GeneratedCodeInfoOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -58493,7 +58493,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_GeneratedCodeInfo_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -58506,7 +58506,7 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); } @@ -58632,7 +58632,7 @@ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.GeneratedCodeInfo annotation_ = other.annotation_; bitField0_ = (bitField0_ & ~0x00000001); annotationBuilder_ = - com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.GeneratedMessageV3Internal.alwaysUseFieldBuilders ? getAnnotationFieldBuilder() : null; } else { annotationBuilder_.addAllMessages(other.annotation_); @@ -58886,7 +58886,7 @@ public Builder addAllAnnotation( java.lang.Iterable values) { if (annotationBuilder_ == null) { ensureAnnotationIsMutable(); - com.google.protobuf.FlattenedGeneratedMessageV3.Builder.addAll( + com.google.protobuf.GeneratedMessageV3Internal.Builder.addAll( values, annotation_); onChanged(); } else { @@ -59091,167 +59091,167 @@ public com.google.protobuf.DescriptorProtos.GeneratedCodeInfo getDefaultInstance private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_FileDescriptorSet_descriptor; private static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_FileDescriptorSet_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_FileDescriptorProto_descriptor; private static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_FileDescriptorProto_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_DescriptorProto_descriptor; private static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_DescriptorProto_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_DescriptorProto_ExtensionRange_descriptor; private static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_DescriptorProto_ExtensionRange_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_DescriptorProto_ReservedRange_descriptor; private static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_DescriptorProto_ReservedRange_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_ExtensionRangeOptions_descriptor; private static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_ExtensionRangeOptions_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_ExtensionRangeOptions_Declaration_descriptor; private static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_ExtensionRangeOptions_Declaration_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_FieldDescriptorProto_descriptor; private static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_FieldDescriptorProto_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_OneofDescriptorProto_descriptor; private static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_OneofDescriptorProto_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_EnumDescriptorProto_descriptor; private static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_EnumDescriptorProto_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_EnumDescriptorProto_EnumReservedRange_descriptor; private static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_EnumDescriptorProto_EnumReservedRange_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_EnumValueDescriptorProto_descriptor; private static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_EnumValueDescriptorProto_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_ServiceDescriptorProto_descriptor; private static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_ServiceDescriptorProto_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_MethodDescriptorProto_descriptor; private static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_MethodDescriptorProto_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_FileOptions_descriptor; private static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_FileOptions_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_MessageOptions_descriptor; private static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_MessageOptions_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_FieldOptions_descriptor; private static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_FieldOptions_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_FieldOptions_EditionDefault_descriptor; private static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_FieldOptions_EditionDefault_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_FieldOptions_FeatureSupport_descriptor; private static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_FieldOptions_FeatureSupport_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_OneofOptions_descriptor; private static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_OneofOptions_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_EnumOptions_descriptor; private static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_EnumOptions_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_EnumValueOptions_descriptor; private static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_EnumValueOptions_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_ServiceOptions_descriptor; private static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_ServiceOptions_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_MethodOptions_descriptor; private static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_MethodOptions_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_UninterpretedOption_descriptor; private static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_UninterpretedOption_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_UninterpretedOption_NamePart_descriptor; private static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_UninterpretedOption_NamePart_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_FeatureSet_descriptor; private static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_FeatureSet_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_FeatureSetDefaults_descriptor; private static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_FeatureSetDefaults_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_descriptor; private static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_SourceCodeInfo_descriptor; private static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_SourceCodeInfo_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_SourceCodeInfo_Location_descriptor; private static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_SourceCodeInfo_Location_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_GeneratedCodeInfo_descriptor; private static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_GeneratedCodeInfo_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_GeneratedCodeInfo_Annotation_descriptor; private static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_GeneratedCodeInfo_Annotation_fieldAccessorTable; public static com.google.protobuf.Descriptors.FileDescriptor @@ -59523,199 +59523,199 @@ public com.google.protobuf.DescriptorProtos.GeneratedCodeInfo getDefaultInstance internal_static_google_protobuf_FileDescriptorSet_descriptor = getDescriptor().getMessageTypes().get(0); internal_static_google_protobuf_FileDescriptorSet_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_FileDescriptorSet_descriptor, new java.lang.String[] { "File", }); internal_static_google_protobuf_FileDescriptorProto_descriptor = getDescriptor().getMessageTypes().get(1); internal_static_google_protobuf_FileDescriptorProto_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_FileDescriptorProto_descriptor, new java.lang.String[] { "Name", "Package", "Dependency", "PublicDependency", "WeakDependency", "MessageType", "EnumType", "Service", "Extension", "Options", "SourceCodeInfo", "Syntax", "Edition", }); internal_static_google_protobuf_DescriptorProto_descriptor = getDescriptor().getMessageTypes().get(2); internal_static_google_protobuf_DescriptorProto_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_DescriptorProto_descriptor, new java.lang.String[] { "Name", "Field", "Extension", "NestedType", "EnumType", "ExtensionRange", "OneofDecl", "Options", "ReservedRange", "ReservedName", }); internal_static_google_protobuf_DescriptorProto_ExtensionRange_descriptor = internal_static_google_protobuf_DescriptorProto_descriptor.getNestedTypes().get(0); internal_static_google_protobuf_DescriptorProto_ExtensionRange_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_DescriptorProto_ExtensionRange_descriptor, new java.lang.String[] { "Start", "End", "Options", }); internal_static_google_protobuf_DescriptorProto_ReservedRange_descriptor = internal_static_google_protobuf_DescriptorProto_descriptor.getNestedTypes().get(1); internal_static_google_protobuf_DescriptorProto_ReservedRange_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_DescriptorProto_ReservedRange_descriptor, new java.lang.String[] { "Start", "End", }); internal_static_google_protobuf_ExtensionRangeOptions_descriptor = getDescriptor().getMessageTypes().get(3); internal_static_google_protobuf_ExtensionRangeOptions_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_ExtensionRangeOptions_descriptor, new java.lang.String[] { "UninterpretedOption", "Declaration", "Features", "Verification", }); internal_static_google_protobuf_ExtensionRangeOptions_Declaration_descriptor = internal_static_google_protobuf_ExtensionRangeOptions_descriptor.getNestedTypes().get(0); internal_static_google_protobuf_ExtensionRangeOptions_Declaration_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_ExtensionRangeOptions_Declaration_descriptor, new java.lang.String[] { "Number", "FullName", "Type", "Reserved", "Repeated", }); internal_static_google_protobuf_FieldDescriptorProto_descriptor = getDescriptor().getMessageTypes().get(4); internal_static_google_protobuf_FieldDescriptorProto_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_FieldDescriptorProto_descriptor, new java.lang.String[] { "Name", "Number", "Label", "Type", "TypeName", "Extendee", "DefaultValue", "OneofIndex", "JsonName", "Options", "Proto3Optional", }); internal_static_google_protobuf_OneofDescriptorProto_descriptor = getDescriptor().getMessageTypes().get(5); internal_static_google_protobuf_OneofDescriptorProto_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_OneofDescriptorProto_descriptor, new java.lang.String[] { "Name", "Options", }); internal_static_google_protobuf_EnumDescriptorProto_descriptor = getDescriptor().getMessageTypes().get(6); internal_static_google_protobuf_EnumDescriptorProto_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_EnumDescriptorProto_descriptor, new java.lang.String[] { "Name", "Value", "Options", "ReservedRange", "ReservedName", }); internal_static_google_protobuf_EnumDescriptorProto_EnumReservedRange_descriptor = internal_static_google_protobuf_EnumDescriptorProto_descriptor.getNestedTypes().get(0); internal_static_google_protobuf_EnumDescriptorProto_EnumReservedRange_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_EnumDescriptorProto_EnumReservedRange_descriptor, new java.lang.String[] { "Start", "End", }); internal_static_google_protobuf_EnumValueDescriptorProto_descriptor = getDescriptor().getMessageTypes().get(7); internal_static_google_protobuf_EnumValueDescriptorProto_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_EnumValueDescriptorProto_descriptor, new java.lang.String[] { "Name", "Number", "Options", }); internal_static_google_protobuf_ServiceDescriptorProto_descriptor = getDescriptor().getMessageTypes().get(8); internal_static_google_protobuf_ServiceDescriptorProto_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_ServiceDescriptorProto_descriptor, new java.lang.String[] { "Name", "Method", "Options", }); internal_static_google_protobuf_MethodDescriptorProto_descriptor = getDescriptor().getMessageTypes().get(9); internal_static_google_protobuf_MethodDescriptorProto_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_MethodDescriptorProto_descriptor, new java.lang.String[] { "Name", "InputType", "OutputType", "Options", "ClientStreaming", "ServerStreaming", }); internal_static_google_protobuf_FileOptions_descriptor = getDescriptor().getMessageTypes().get(10); internal_static_google_protobuf_FileOptions_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_FileOptions_descriptor, new java.lang.String[] { "JavaPackage", "JavaOuterClassname", "JavaMultipleFiles", "JavaGenerateEqualsAndHash", "JavaStringCheckUtf8", "OptimizeFor", "GoPackage", "CcGenericServices", "JavaGenericServices", "PyGenericServices", "Deprecated", "CcEnableArenas", "ObjcClassPrefix", "CsharpNamespace", "SwiftPrefix", "PhpClassPrefix", "PhpNamespace", "PhpMetadataNamespace", "RubyPackage", "Features", "UninterpretedOption", }); internal_static_google_protobuf_MessageOptions_descriptor = getDescriptor().getMessageTypes().get(11); internal_static_google_protobuf_MessageOptions_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_MessageOptions_descriptor, new java.lang.String[] { "MessageSetWireFormat", "NoStandardDescriptorAccessor", "Deprecated", "MapEntry", "DeprecatedLegacyJsonFieldConflicts", "Features", "UninterpretedOption", }); internal_static_google_protobuf_FieldOptions_descriptor = getDescriptor().getMessageTypes().get(12); internal_static_google_protobuf_FieldOptions_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_FieldOptions_descriptor, new java.lang.String[] { "Ctype", "Packed", "Jstype", "Lazy", "UnverifiedLazy", "Deprecated", "Weak", "DebugRedact", "Retention", "Targets", "EditionDefaults", "Features", "FeatureSupport", "UninterpretedOption", }); internal_static_google_protobuf_FieldOptions_EditionDefault_descriptor = internal_static_google_protobuf_FieldOptions_descriptor.getNestedTypes().get(0); internal_static_google_protobuf_FieldOptions_EditionDefault_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_FieldOptions_EditionDefault_descriptor, new java.lang.String[] { "Edition", "Value", }); internal_static_google_protobuf_FieldOptions_FeatureSupport_descriptor = internal_static_google_protobuf_FieldOptions_descriptor.getNestedTypes().get(1); internal_static_google_protobuf_FieldOptions_FeatureSupport_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_FieldOptions_FeatureSupport_descriptor, new java.lang.String[] { "EditionIntroduced", "EditionDeprecated", "DeprecationWarning", "EditionRemoved", }); internal_static_google_protobuf_OneofOptions_descriptor = getDescriptor().getMessageTypes().get(13); internal_static_google_protobuf_OneofOptions_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_OneofOptions_descriptor, new java.lang.String[] { "Features", "UninterpretedOption", }); internal_static_google_protobuf_EnumOptions_descriptor = getDescriptor().getMessageTypes().get(14); internal_static_google_protobuf_EnumOptions_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_EnumOptions_descriptor, new java.lang.String[] { "AllowAlias", "Deprecated", "DeprecatedLegacyJsonFieldConflicts", "Features", "UninterpretedOption", }); internal_static_google_protobuf_EnumValueOptions_descriptor = getDescriptor().getMessageTypes().get(15); internal_static_google_protobuf_EnumValueOptions_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_EnumValueOptions_descriptor, new java.lang.String[] { "Deprecated", "Features", "DebugRedact", "FeatureSupport", "UninterpretedOption", }); internal_static_google_protobuf_ServiceOptions_descriptor = getDescriptor().getMessageTypes().get(16); internal_static_google_protobuf_ServiceOptions_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_ServiceOptions_descriptor, new java.lang.String[] { "Features", "Deprecated", "UninterpretedOption", }); internal_static_google_protobuf_MethodOptions_descriptor = getDescriptor().getMessageTypes().get(17); internal_static_google_protobuf_MethodOptions_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_MethodOptions_descriptor, new java.lang.String[] { "Deprecated", "IdempotencyLevel", "Features", "UninterpretedOption", }); internal_static_google_protobuf_UninterpretedOption_descriptor = getDescriptor().getMessageTypes().get(18); internal_static_google_protobuf_UninterpretedOption_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_UninterpretedOption_descriptor, new java.lang.String[] { "Name", "IdentifierValue", "PositiveIntValue", "NegativeIntValue", "DoubleValue", "StringValue", "AggregateValue", }); internal_static_google_protobuf_UninterpretedOption_NamePart_descriptor = internal_static_google_protobuf_UninterpretedOption_descriptor.getNestedTypes().get(0); internal_static_google_protobuf_UninterpretedOption_NamePart_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_UninterpretedOption_NamePart_descriptor, new java.lang.String[] { "NamePart", "IsExtension", }); internal_static_google_protobuf_FeatureSet_descriptor = getDescriptor().getMessageTypes().get(19); internal_static_google_protobuf_FeatureSet_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_FeatureSet_descriptor, new java.lang.String[] { "FieldPresence", "EnumType", "RepeatedFieldEncoding", "Utf8Validation", "MessageEncoding", "JsonFormat", }); internal_static_google_protobuf_FeatureSetDefaults_descriptor = getDescriptor().getMessageTypes().get(20); internal_static_google_protobuf_FeatureSetDefaults_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_FeatureSetDefaults_descriptor, new java.lang.String[] { "Defaults", "MinimumEdition", "MaximumEdition", }); internal_static_google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_descriptor = internal_static_google_protobuf_FeatureSetDefaults_descriptor.getNestedTypes().get(0); internal_static_google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_descriptor, new java.lang.String[] { "Edition", "OverridableFeatures", "FixedFeatures", }); internal_static_google_protobuf_SourceCodeInfo_descriptor = getDescriptor().getMessageTypes().get(21); internal_static_google_protobuf_SourceCodeInfo_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_SourceCodeInfo_descriptor, new java.lang.String[] { "Location", }); internal_static_google_protobuf_SourceCodeInfo_Location_descriptor = internal_static_google_protobuf_SourceCodeInfo_descriptor.getNestedTypes().get(0); internal_static_google_protobuf_SourceCodeInfo_Location_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_SourceCodeInfo_Location_descriptor, new java.lang.String[] { "Path", "Span", "LeadingComments", "TrailingComments", "LeadingDetachedComments", }); internal_static_google_protobuf_GeneratedCodeInfo_descriptor = getDescriptor().getMessageTypes().get(22); internal_static_google_protobuf_GeneratedCodeInfo_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_GeneratedCodeInfo_descriptor, new java.lang.String[] { "Annotation", }); internal_static_google_protobuf_GeneratedCodeInfo_Annotation_descriptor = internal_static_google_protobuf_GeneratedCodeInfo_descriptor.getNestedTypes().get(0); internal_static_google_protobuf_GeneratedCodeInfo_Annotation_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_GeneratedCodeInfo_Annotation_descriptor, new java.lang.String[] { "Path", "SourceFile", "Begin", "End", "Semantic", }); } diff --git a/protobuf-api/src/main/java/com/google/protobuf/DoubleValue.java b/protobuf-api/src/main/java/com/google/protobuf/DoubleValue.java index 9a0b11f..725a829 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/DoubleValue.java +++ b/protobuf-api/src/main/java/com/google/protobuf/DoubleValue.java @@ -14,12 +14,12 @@ * Protobuf type {@code google.protobuf.DoubleValue} */ public final class DoubleValue extends - com.google.protobuf.FlattenedGeneratedMessageV3 implements + com.google.protobuf.GeneratedMessageV3Internal implements // @@protoc_insertion_point(message_implements:google.protobuf.DoubleValue) DoubleValueOrBuilder { private static final long serialVersionUID = 0L; // Use DoubleValue.newBuilder() to construct. - private DoubleValue(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { + private DoubleValue(com.google.protobuf.GeneratedMessageV3Internal.Builder builder) { super(builder); } private DoubleValue() { @@ -38,7 +38,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.WrappersProto.internal_static_google_protobuf_DoubleValue_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -161,20 +161,20 @@ public static com.google.protobuf.DoubleValue parseFrom( } public static com.google.protobuf.DoubleValue parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DoubleValue parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DoubleValue parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -182,20 +182,20 @@ public static com.google.protobuf.DoubleValue parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.DoubleValue parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.DoubleValue parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -215,7 +215,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -229,7 +229,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.DoubleValue} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements + com.google.protobuf.GeneratedMessageV3Internal.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.DoubleValue) com.google.protobuf.DoubleValueOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -238,7 +238,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.WrappersProto.internal_static_google_protobuf_DoubleValue_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -251,7 +251,7 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); } diff --git a/protobuf-api/src/main/java/com/google/protobuf/Duration.java b/protobuf-api/src/main/java/com/google/protobuf/Duration.java index 361ee3d..13cdf17 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/Duration.java +++ b/protobuf-api/src/main/java/com/google/protobuf/Duration.java @@ -69,12 +69,12 @@ * Protobuf type {@code google.protobuf.Duration} */ public final class Duration extends - com.google.protobuf.FlattenedGeneratedMessageV3 implements + com.google.protobuf.GeneratedMessageV3Internal implements // @@protoc_insertion_point(message_implements:google.protobuf.Duration) DurationOrBuilder { private static final long serialVersionUID = 0L; // Use Duration.newBuilder() to construct. - private Duration(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { + private Duration(com.google.protobuf.GeneratedMessageV3Internal.Builder builder) { super(builder); } private Duration() { @@ -93,7 +93,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DurationProto.internal_static_google_protobuf_Duration_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -248,20 +248,20 @@ public static com.google.protobuf.Duration parseFrom( } public static com.google.protobuf.Duration parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.Duration parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Duration parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -269,20 +269,20 @@ public static com.google.protobuf.Duration parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Duration parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.Duration parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -302,7 +302,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -371,7 +371,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.Duration} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements + com.google.protobuf.GeneratedMessageV3Internal.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.Duration) com.google.protobuf.DurationOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -380,7 +380,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.DurationProto.internal_static_google_protobuf_Duration_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -393,7 +393,7 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); } diff --git a/protobuf-api/src/main/java/com/google/protobuf/DurationProto.java b/protobuf-api/src/main/java/com/google/protobuf/DurationProto.java index 275746b..7deb34e 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/DurationProto.java +++ b/protobuf-api/src/main/java/com/google/protobuf/DurationProto.java @@ -18,7 +18,7 @@ public static void registerAllExtensions( static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_Duration_descriptor; static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_Duration_fieldAccessorTable; public static com.google.protobuf.Descriptors.FileDescriptor @@ -43,7 +43,7 @@ public static void registerAllExtensions( internal_static_google_protobuf_Duration_descriptor = getDescriptor().getMessageTypes().get(0); internal_static_google_protobuf_Duration_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_Duration_descriptor, new java.lang.String[] { "Seconds", "Nanos", }); } diff --git a/protobuf-api/src/main/java/com/google/protobuf/Empty.java b/protobuf-api/src/main/java/com/google/protobuf/Empty.java index 38426dc..7b58465 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/Empty.java +++ b/protobuf-api/src/main/java/com/google/protobuf/Empty.java @@ -18,12 +18,12 @@ * Protobuf type {@code google.protobuf.Empty} */ public final class Empty extends - com.google.protobuf.FlattenedGeneratedMessageV3 implements + com.google.protobuf.GeneratedMessageV3Internal implements // @@protoc_insertion_point(message_implements:google.protobuf.Empty) EmptyOrBuilder { private static final long serialVersionUID = 0L; // Use Empty.newBuilder() to construct. - private Empty(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { + private Empty(com.google.protobuf.GeneratedMessageV3Internal.Builder builder) { super(builder); } private Empty() { @@ -42,7 +42,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.EmptyProto.internal_static_google_protobuf_Empty_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -137,20 +137,20 @@ public static com.google.protobuf.Empty parseFrom( } public static com.google.protobuf.Empty parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.Empty parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Empty parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -158,20 +158,20 @@ public static com.google.protobuf.Empty parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Empty parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.Empty parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -191,7 +191,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -209,7 +209,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.Empty} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements + com.google.protobuf.GeneratedMessageV3Internal.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.Empty) com.google.protobuf.EmptyOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -218,7 +218,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.EmptyProto.internal_static_google_protobuf_Empty_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -231,7 +231,7 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); } diff --git a/protobuf-api/src/main/java/com/google/protobuf/EmptyProto.java b/protobuf-api/src/main/java/com/google/protobuf/EmptyProto.java index dd55151..6c4ee36 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/EmptyProto.java +++ b/protobuf-api/src/main/java/com/google/protobuf/EmptyProto.java @@ -18,7 +18,7 @@ public static void registerAllExtensions( static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_Empty_descriptor; static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_Empty_fieldAccessorTable; public static com.google.protobuf.Descriptors.FileDescriptor @@ -42,7 +42,7 @@ public static void registerAllExtensions( internal_static_google_protobuf_Empty_descriptor = getDescriptor().getMessageTypes().get(0); internal_static_google_protobuf_Empty_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_Empty_descriptor, new java.lang.String[] { }); } diff --git a/protobuf-api/src/main/java/com/google/protobuf/Enum.java b/protobuf-api/src/main/java/com/google/protobuf/Enum.java index f65cd39..e4c44b1 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/Enum.java +++ b/protobuf-api/src/main/java/com/google/protobuf/Enum.java @@ -12,12 +12,12 @@ * Protobuf type {@code google.protobuf.Enum} */ public final class Enum extends - com.google.protobuf.FlattenedGeneratedMessageV3 implements + com.google.protobuf.GeneratedMessageV3Internal implements // @@protoc_insertion_point(message_implements:google.protobuf.Enum) EnumOrBuilder { private static final long serialVersionUID = 0L; // Use Enum.newBuilder() to construct. - private Enum(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { + private Enum(com.google.protobuf.GeneratedMessageV3Internal.Builder builder) { super(builder); } private Enum() { @@ -41,7 +41,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.TypeProto.internal_static_google_protobuf_Enum_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -343,8 +343,8 @@ public final boolean isInitialized() { @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(name_)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 1, name_); + if (!com.google.protobuf.GeneratedMessageV3Internal.isStringEmpty(name_)) { + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 1, name_); } for (int i = 0; i < enumvalue_.size(); i++) { output.writeMessage(2, enumvalue_.get(i)); @@ -358,8 +358,8 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) if (syntax_ != com.google.protobuf.Syntax.SYNTAX_PROTO2.getNumber()) { output.writeEnum(5, syntax_); } - if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(edition_)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 6, edition_); + if (!com.google.protobuf.GeneratedMessageV3Internal.isStringEmpty(edition_)) { + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 6, edition_); } getUnknownFields().writeTo(output); } @@ -370,8 +370,8 @@ public int getSerializedSize() { if (size != -1) return size; size = 0; - if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(name_)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(1, name_); + if (!com.google.protobuf.GeneratedMessageV3Internal.isStringEmpty(name_)) { + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(1, name_); } for (int i = 0; i < enumvalue_.size(); i++) { size += com.google.protobuf.CodedOutputStream @@ -389,8 +389,8 @@ public int getSerializedSize() { size += com.google.protobuf.CodedOutputStream .computeEnumSize(5, syntax_); } - if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(edition_)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(6, edition_); + if (!com.google.protobuf.GeneratedMessageV3Internal.isStringEmpty(edition_)) { + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(6, edition_); } size += getUnknownFields().getSerializedSize(); memoizedSize = size; @@ -489,20 +489,20 @@ public static com.google.protobuf.Enum parseFrom( } public static com.google.protobuf.Enum parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.Enum parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Enum parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -510,20 +510,20 @@ public static com.google.protobuf.Enum parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Enum parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.Enum parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -543,7 +543,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -555,7 +555,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.Enum} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements + com.google.protobuf.GeneratedMessageV3Internal.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.Enum) com.google.protobuf.EnumOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -564,7 +564,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.TypeProto.internal_static_google_protobuf_Enum_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -577,12 +577,12 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { - if (com.google.protobuf.FlattenedGeneratedMessageV3 + if (com.google.protobuf.GeneratedMessageV3Internal .alwaysUseFieldBuilders) { getEnumvalueFieldBuilder(); getOptionsFieldBuilder(); @@ -757,7 +757,7 @@ public Builder mergeFrom(com.google.protobuf.Enum other) { enumvalue_ = other.enumvalue_; bitField0_ = (bitField0_ & ~0x00000002); enumvalueBuilder_ = - com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.GeneratedMessageV3Internal.alwaysUseFieldBuilders ? getEnumvalueFieldBuilder() : null; } else { enumvalueBuilder_.addAllMessages(other.enumvalue_); @@ -783,7 +783,7 @@ public Builder mergeFrom(com.google.protobuf.Enum other) { options_ = other.options_; bitField0_ = (bitField0_ & ~0x00000004); optionsBuilder_ = - com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.GeneratedMessageV3Internal.alwaysUseFieldBuilders ? getOptionsFieldBuilder() : null; } else { optionsBuilder_.addAllMessages(other.options_); diff --git a/protobuf-api/src/main/java/com/google/protobuf/EnumValue.java b/protobuf-api/src/main/java/com/google/protobuf/EnumValue.java index 93c173b..41c3bf9 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/EnumValue.java +++ b/protobuf-api/src/main/java/com/google/protobuf/EnumValue.java @@ -12,12 +12,12 @@ * Protobuf type {@code google.protobuf.EnumValue} */ public final class EnumValue extends - com.google.protobuf.FlattenedGeneratedMessageV3 implements + com.google.protobuf.GeneratedMessageV3Internal implements // @@protoc_insertion_point(message_implements:google.protobuf.EnumValue) EnumValueOrBuilder { private static final long serialVersionUID = 0L; // Use EnumValue.newBuilder() to construct. - private EnumValue(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { + private EnumValue(com.google.protobuf.GeneratedMessageV3Internal.Builder builder) { super(builder); } private EnumValue() { @@ -38,7 +38,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.TypeProto.internal_static_google_protobuf_EnumValue_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -182,8 +182,8 @@ public final boolean isInitialized() { @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(name_)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 1, name_); + if (!com.google.protobuf.GeneratedMessageV3Internal.isStringEmpty(name_)) { + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 1, name_); } if (number_ != 0) { output.writeInt32(2, number_); @@ -200,8 +200,8 @@ public int getSerializedSize() { if (size != -1) return size; size = 0; - if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(name_)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(1, name_); + if (!com.google.protobuf.GeneratedMessageV3Internal.isStringEmpty(name_)) { + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(1, name_); } if (number_ != 0) { size += com.google.protobuf.CodedOutputStream @@ -290,20 +290,20 @@ public static com.google.protobuf.EnumValue parseFrom( } public static com.google.protobuf.EnumValue parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.EnumValue parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.EnumValue parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -311,20 +311,20 @@ public static com.google.protobuf.EnumValue parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.EnumValue parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.EnumValue parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -344,7 +344,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -356,7 +356,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.EnumValue} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements + com.google.protobuf.GeneratedMessageV3Internal.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.EnumValue) com.google.protobuf.EnumValueOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -365,7 +365,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.TypeProto.internal_static_google_protobuf_EnumValue_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -378,7 +378,7 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); } @@ -520,7 +520,7 @@ public Builder mergeFrom(com.google.protobuf.EnumValue other) { options_ = other.options_; bitField0_ = (bitField0_ & ~0x00000004); optionsBuilder_ = - com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.GeneratedMessageV3Internal.alwaysUseFieldBuilders ? getOptionsFieldBuilder() : null; } else { optionsBuilder_.addAllMessages(other.options_); diff --git a/protobuf-api/src/main/java/com/google/protobuf/Field.java b/protobuf-api/src/main/java/com/google/protobuf/Field.java index 3228d6e..566c163 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/Field.java +++ b/protobuf-api/src/main/java/com/google/protobuf/Field.java @@ -12,12 +12,12 @@ * Protobuf type {@code google.protobuf.Field} */ public final class Field extends - com.google.protobuf.FlattenedGeneratedMessageV3 implements + com.google.protobuf.GeneratedMessageV3Internal implements // @@protoc_insertion_point(message_implements:google.protobuf.Field) FieldOrBuilder { private static final long serialVersionUID = 0L; // Use Field.newBuilder() to construct. - private Field(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { + private Field(com.google.protobuf.GeneratedMessageV3Internal.Builder builder) { super(builder); } private Field() { @@ -43,7 +43,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.TypeProto.internal_static_google_protobuf_Field_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -1001,11 +1001,11 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) if (number_ != 0) { output.writeInt32(3, number_); } - if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(name_)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 4, name_); + if (!com.google.protobuf.GeneratedMessageV3Internal.isStringEmpty(name_)) { + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 4, name_); } - if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(typeUrl_)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 6, typeUrl_); + if (!com.google.protobuf.GeneratedMessageV3Internal.isStringEmpty(typeUrl_)) { + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 6, typeUrl_); } if (oneofIndex_ != 0) { output.writeInt32(7, oneofIndex_); @@ -1016,11 +1016,11 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) for (int i = 0; i < options_.size(); i++) { output.writeMessage(9, options_.get(i)); } - if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(jsonName_)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 10, jsonName_); + if (!com.google.protobuf.GeneratedMessageV3Internal.isStringEmpty(jsonName_)) { + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 10, jsonName_); } - if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(defaultValue_)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 11, defaultValue_); + if (!com.google.protobuf.GeneratedMessageV3Internal.isStringEmpty(defaultValue_)) { + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 11, defaultValue_); } getUnknownFields().writeTo(output); } @@ -1043,11 +1043,11 @@ public int getSerializedSize() { size += com.google.protobuf.CodedOutputStream .computeInt32Size(3, number_); } - if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(name_)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(4, name_); + if (!com.google.protobuf.GeneratedMessageV3Internal.isStringEmpty(name_)) { + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(4, name_); } - if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(typeUrl_)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(6, typeUrl_); + if (!com.google.protobuf.GeneratedMessageV3Internal.isStringEmpty(typeUrl_)) { + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(6, typeUrl_); } if (oneofIndex_ != 0) { size += com.google.protobuf.CodedOutputStream @@ -1061,11 +1061,11 @@ public int getSerializedSize() { size += com.google.protobuf.CodedOutputStream .computeMessageSize(9, options_.get(i)); } - if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(jsonName_)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(10, jsonName_); + if (!com.google.protobuf.GeneratedMessageV3Internal.isStringEmpty(jsonName_)) { + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(10, jsonName_); } - if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(defaultValue_)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(11, defaultValue_); + if (!com.google.protobuf.GeneratedMessageV3Internal.isStringEmpty(defaultValue_)) { + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(11, defaultValue_); } size += getUnknownFields().getSerializedSize(); memoizedSize = size; @@ -1173,20 +1173,20 @@ public static com.google.protobuf.Field parseFrom( } public static com.google.protobuf.Field parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.Field parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Field parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -1194,20 +1194,20 @@ public static com.google.protobuf.Field parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Field parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.Field parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -1227,7 +1227,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -1239,7 +1239,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.Field} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements + com.google.protobuf.GeneratedMessageV3Internal.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.Field) com.google.protobuf.FieldOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -1248,7 +1248,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.TypeProto.internal_static_google_protobuf_Field_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -1261,7 +1261,7 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); } @@ -1448,7 +1448,7 @@ public Builder mergeFrom(com.google.protobuf.Field other) { options_ = other.options_; bitField0_ = (bitField0_ & ~0x00000080); optionsBuilder_ = - com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.GeneratedMessageV3Internal.alwaysUseFieldBuilders ? getOptionsFieldBuilder() : null; } else { optionsBuilder_.addAllMessages(other.options_); diff --git a/protobuf-api/src/main/java/com/google/protobuf/FieldMask.java b/protobuf-api/src/main/java/com/google/protobuf/FieldMask.java index c5fa321..e96c5f9 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/FieldMask.java +++ b/protobuf-api/src/main/java/com/google/protobuf/FieldMask.java @@ -210,12 +210,12 @@ * Protobuf type {@code google.protobuf.FieldMask} */ public final class FieldMask extends - com.google.protobuf.FlattenedGeneratedMessageV3 implements + com.google.protobuf.GeneratedMessageV3Internal implements // @@protoc_insertion_point(message_implements:google.protobuf.FieldMask) FieldMaskOrBuilder { private static final long serialVersionUID = 0L; // Use FieldMask.newBuilder() to construct. - private FieldMask(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { + private FieldMask(com.google.protobuf.GeneratedMessageV3Internal.Builder builder) { super(builder); } private FieldMask() { @@ -236,7 +236,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.FieldMaskProto.internal_static_google_protobuf_FieldMask_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -311,7 +311,7 @@ public final boolean isInitialized() { public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { for (int i = 0; i < paths_.size(); i++) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 1, paths_.getRaw(i)); + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 1, paths_.getRaw(i)); } getUnknownFields().writeTo(output); } @@ -401,20 +401,20 @@ public static com.google.protobuf.FieldMask parseFrom( } public static com.google.protobuf.FieldMask parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.FieldMask parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.FieldMask parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -422,20 +422,20 @@ public static com.google.protobuf.FieldMask parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.FieldMask parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.FieldMask parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -455,7 +455,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -665,7 +665,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.FieldMask} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements + com.google.protobuf.GeneratedMessageV3Internal.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.FieldMask) com.google.protobuf.FieldMaskOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -674,7 +674,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.FieldMaskProto.internal_static_google_protobuf_FieldMask_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -687,7 +687,7 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); } diff --git a/protobuf-api/src/main/java/com/google/protobuf/FieldMaskProto.java b/protobuf-api/src/main/java/com/google/protobuf/FieldMaskProto.java index 39d49ab..396e60c 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/FieldMaskProto.java +++ b/protobuf-api/src/main/java/com/google/protobuf/FieldMaskProto.java @@ -18,7 +18,7 @@ public static void registerAllExtensions( static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_FieldMask_descriptor; static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_FieldMask_fieldAccessorTable; public static com.google.protobuf.Descriptors.FileDescriptor @@ -43,7 +43,7 @@ public static void registerAllExtensions( internal_static_google_protobuf_FieldMask_descriptor = getDescriptor().getMessageTypes().get(0); internal_static_google_protobuf_FieldMask_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_FieldMask_descriptor, new java.lang.String[] { "Paths", }); } diff --git a/protobuf-api/src/main/java/com/google/protobuf/FloatValue.java b/protobuf-api/src/main/java/com/google/protobuf/FloatValue.java index 07dc2da..b7d2b36 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/FloatValue.java +++ b/protobuf-api/src/main/java/com/google/protobuf/FloatValue.java @@ -14,12 +14,12 @@ * Protobuf type {@code google.protobuf.FloatValue} */ public final class FloatValue extends - com.google.protobuf.FlattenedGeneratedMessageV3 implements + com.google.protobuf.GeneratedMessageV3Internal implements // @@protoc_insertion_point(message_implements:google.protobuf.FloatValue) FloatValueOrBuilder { private static final long serialVersionUID = 0L; // Use FloatValue.newBuilder() to construct. - private FloatValue(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { + private FloatValue(com.google.protobuf.GeneratedMessageV3Internal.Builder builder) { super(builder); } private FloatValue() { @@ -38,7 +38,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.WrappersProto.internal_static_google_protobuf_FloatValue_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -161,20 +161,20 @@ public static com.google.protobuf.FloatValue parseFrom( } public static com.google.protobuf.FloatValue parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.FloatValue parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.FloatValue parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -182,20 +182,20 @@ public static com.google.protobuf.FloatValue parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.FloatValue parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.FloatValue parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -215,7 +215,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -229,7 +229,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.FloatValue} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements + com.google.protobuf.GeneratedMessageV3Internal.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.FloatValue) com.google.protobuf.FloatValueOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -238,7 +238,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.WrappersProto.internal_static_google_protobuf_FloatValue_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -251,7 +251,7 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); } diff --git a/protobuf-api/src/main/java/com/google/protobuf/GeneratedMessageInternal.java b/protobuf-api/src/main/java/com/google/protobuf/GeneratedMessageInternal.java new file mode 100644 index 0000000..045b157 --- /dev/null +++ b/protobuf-api/src/main/java/com/google/protobuf/GeneratedMessageInternal.java @@ -0,0 +1,2987 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd + +package com.google.protobuf; + +import com.google.protobuf.Descriptors.Descriptor; +import com.google.protobuf.Descriptors.EnumDescriptor; +import com.google.protobuf.Descriptors.EnumValueDescriptor; +import com.google.protobuf.Descriptors.FieldDescriptor; +import com.google.protobuf.Descriptors.FileDescriptor; +import com.google.protobuf.Descriptors.OneofDescriptor; + +import java.io.IOException; +import java.io.InputStream; +import java.io.ObjectStreamException; +import java.io.Serializable; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + +/** + * All generated protocol message classes extend this class. This class implements most of the + * Message and Builder interfaces using Java reflection. Users can ignore this class and pretend + * that generated messages implement the Message interface directly. + * + * @author kenton@google.com Kenton Varda + */ +abstract class GeneratedMessageInternal extends AbstractMessageInternal implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * For testing. Allows a test to disable the optimization that avoids using field builders for + * nested messages until they are requested. By disabling this optimization, existing tests can be + * reused to test the field builders. + */ + protected static boolean alwaysUseFieldBuilders = false; + + /** For use by generated code only. */ + protected UnknownFieldSet unknownFields; + + protected GeneratedMessageInternal() { + unknownFields = UnknownFieldSet.getDefaultInstance(); + } + + protected GeneratedMessageInternal(Builder builder) { + unknownFields = builder.getUnknownFields(); + } + + @Override + public boolean isGenerated() { + return true; + } + + @Override + public Parser getParserForType() { + throw new UnsupportedOperationException("This is supposed to be overridden by subclasses."); + } + + /** + * For testing. Allows a test to disable the optimization that avoids using field builders for + * nested messages until they are requested. By disabling this optimization, existing tests can be + * reused to test the field builders. See {@link RepeatedFieldBuilder} and {@link + * SingleFieldBuilder}. + */ + static void enableAlwaysUseFieldBuildersForTesting() { + alwaysUseFieldBuilders = true; + } + + /** + * Get the FieldAccessorTable for this type. We can't have the message class pass this in to the + * constructor because of bootstrapping trouble with DescriptorProtos. + */ + protected abstract FieldAccessorTable internalGetFieldAccessorTable(); + + @Override + public Descriptor getDescriptorForType() { + return internalGetFieldAccessorTable().descriptor; + } + + /** + * Internal helper to return a modifiable map containing all the fields. The returned Map is + * modifialbe so that the caller can add additional extension fields to implement {@link + * #getAllFields()}. + * + * @param getBytesForString whether to generate ByteString for string fields + */ + private Map getAllFieldsMutable(boolean getBytesForString) { + final TreeMap result = new TreeMap(); + final Descriptor descriptor = internalGetFieldAccessorTable().descriptor; + final List fields = descriptor.getFields(); + + for (int i = 0; i < fields.size(); i++) { + FieldDescriptor field = fields.get(i); + final OneofDescriptor oneofDescriptor = field.getContainingOneof(); + + /* + * If the field is part of a Oneof, then at maximum one field in the Oneof is set + * and it is not repeated. There is no need to iterate through the others. + */ + if (oneofDescriptor != null) { + // Skip other fields in the Oneof we know are not set + i += oneofDescriptor.getFieldCount() - 1; + if (!hasOneof(oneofDescriptor)) { + // If no field is set in the Oneof, skip all the fields in the Oneof + continue; + } + // Get the pointer to the only field which is set in the Oneof + field = getOneofFieldDescriptor(oneofDescriptor); + } else { + // If we are not in a Oneof, we need to check if the field is set and if it is repeated + if (field.isRepeated()) { + final List value = (List) getField(field); + if (!value.isEmpty()) { + result.put(field, value); + } + continue; + } + if (!hasField(field)) { + continue; + } + } + // Add the field to the map + if (getBytesForString && field.getJavaType() == FieldDescriptor.JavaType.STRING) { + result.put(field, getFieldRaw(field)); + } else { + result.put(field, getField(field)); + } + } + return result; + } + + @Override + public boolean isInitialized() { + for (final FieldDescriptor field : getDescriptorForType().getFields()) { + // Check that all required fields are present. + if (field.isRequired()) { + if (!hasField(field)) { + return false; + } + } + // Check that embedded messages are initialized. + if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { + if (field.isRepeated()) { + @SuppressWarnings("unchecked") + final List messageList = (List) getField(field); + for (final Message element : messageList) { + if (!element.isInitialized()) { + return false; + } + } + } else { + if (hasField(field) && !((Message) getField(field)).isInitialized()) { + return false; + } + } + } + } + + return true; + } + + @Override + public Map getAllFields() { + return Collections.unmodifiableMap(getAllFieldsMutable(/* getBytesForString = */ false)); + } + + /** + * Returns a collection of all the fields in this message which are set and their corresponding + * values. A singular ("required" or "optional") field is set iff hasField() returns true for that + * field. A "repeated" field is set iff getRepeatedFieldCount() is greater than zero. The values + * are exactly what would be returned by calling {@link #getFieldRaw(FieldDescriptor)} + * for each field. The map is guaranteed to be a sorted map, so iterating over it will return + * fields in order by field number. + */ + Map getAllFieldsRaw() { + return Collections.unmodifiableMap(getAllFieldsMutable(/* getBytesForString = */ true)); + } + + @Override + public boolean hasOneof(final OneofDescriptor oneof) { + return internalGetFieldAccessorTable().getOneof(oneof).has(this); + } + + @Override + public FieldDescriptor getOneofFieldDescriptor(final OneofDescriptor oneof) { + return internalGetFieldAccessorTable().getOneof(oneof).get(this); + } + + @Override + public boolean hasField(final FieldDescriptor field) { + return internalGetFieldAccessorTable().getField(field).has(this); + } + + @Override + public Object getField(final FieldDescriptor field) { + return internalGetFieldAccessorTable().getField(field).get(this); + } + + /** + * Obtains the value of the given field, or the default value if it is not set. For primitive + * fields, the boxed primitive value is returned. For enum fields, the EnumValueDescriptor for the + * value is returned. For embedded message fields, the sub-message is returned. For repeated + * fields, a java.util.List is returned. For present string fields, a ByteString is returned + * representing the bytes that the field contains. + */ + Object getFieldRaw(final FieldDescriptor field) { + return internalGetFieldAccessorTable().getField(field).getRaw(this); + } + + @Override + public int getRepeatedFieldCount(final FieldDescriptor field) { + return internalGetFieldAccessorTable().getField(field).getRepeatedCount(this); + } + + @Override + public Object getRepeatedField(final FieldDescriptor field, final int index) { + return internalGetFieldAccessorTable().getField(field).getRepeated(this, index); + } + + @Override + public UnknownFieldSet getUnknownFields() { + throw new UnsupportedOperationException("This is supposed to be overridden by subclasses."); + } + + /** + * Called by subclasses to parse an unknown field. + * + * @return {@code true} unless the tag is an end-group tag. + */ + protected boolean parseUnknownField( + CodedInputStream input, + UnknownFieldSet.Builder unknownFields, + ExtensionRegistryLite extensionRegistry, + int tag) + throws IOException { + return unknownFields.mergeFieldFrom(tag, input); + } + + protected static M parseWithIOException(Parser parser, InputStream input) + throws IOException { + try { + return parser.parseFrom(input); + } catch (InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } + } + + protected static M parseWithIOException( + Parser parser, InputStream input, ExtensionRegistryLite extensions) throws IOException { + try { + return parser.parseFrom(input, extensions); + } catch (InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } + } + + protected static M parseWithIOException( + Parser parser, CodedInputStream input) throws IOException { + try { + return parser.parseFrom(input); + } catch (InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } + } + + protected static M parseWithIOException( + Parser parser, CodedInputStream input, ExtensionRegistryLite extensions) + throws IOException { + try { + return parser.parseFrom(input, extensions); + } catch (InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } + } + + protected static M parseDelimitedWithIOException( + Parser parser, InputStream input) throws IOException { + try { + return parser.parseDelimitedFrom(input); + } catch (InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } + } + + protected static M parseDelimitedWithIOException( + Parser parser, InputStream input, ExtensionRegistryLite extensions) throws IOException { + try { + return parser.parseDelimitedFrom(input, extensions); + } catch (InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } + } + + @Override + public void writeTo(final CodedOutputStream output) throws IOException { + MessageReflection.writeMessageTo(this, getAllFieldsRaw(), output, false); + } + + @Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) { + return size; + } + + memoizedSize = MessageReflection.getSerializedSize(this, getAllFieldsRaw()); + return memoizedSize; + } + + /** Used by parsing constructors in generated classes. */ + protected void makeExtensionsImmutable() { + // Noop for messages without extensions. + } + + /** + * TODO: remove this after b/29368482 is fixed. We need to move this interface to + * AbstractMessage in order to versioning GeneratedMessageInternal but this move breaks binary + * compatibility for AppEngine. After AppEngine is fixed we can exclude this from google3. + */ + protected interface BuilderParent extends AbstractMessageInternal.BuilderParent {} + + /** TODO: remove this together with GeneratedMessageInternal.BuilderParent. */ + protected abstract Message.Builder newBuilderForType(BuilderParent parent); + + @Override + protected Message.Builder newBuilderForType(final AbstractMessageInternal.BuilderParent parent) { + return newBuilderForType( + new BuilderParent() { + @Override + public void markDirty() { + parent.markDirty(); + } + }); + } + + @SuppressWarnings("unchecked") + public abstract static class Builder> + extends AbstractMessageInternal.Builder { + + private BuilderParent builderParent; + + private BuilderParentImpl meAsParent; + + // Indicates that we've built a message and so we are now obligated + // to dispatch dirty invalidations. See GeneratedMessageInternal.BuilderListener. + private boolean isClean; + + private UnknownFieldSet unknownFields = UnknownFieldSet.getDefaultInstance(); + + protected Builder() { + this(null); + } + + protected Builder(BuilderParent builderParent) { + this.builderParent = builderParent; + } + + @Override + public boolean isGenerated() { + return true; + } + + @Override + void dispose() { + builderParent = null; + } + + /** Called by the subclass when a message is built. */ + protected void onBuilt() { + if (builderParent != null) { + markClean(); + } + } + + /** + * Called by the subclass or a builder to notify us that a message was built and may be cached + * and therefore invalidations are needed. + */ + @Override + protected void markClean() { + this.isClean = true; + } + + /** + * Gets whether invalidations are needed + * + * @return whether invalidations are needed + */ + protected boolean isClean() { + return isClean; + } + + @Override + public BuilderType clone() { + BuilderType builder = (BuilderType) getDefaultInstanceForType().newBuilderForType(); + builder.mergeFrom(buildPartial()); + return builder; + } + + /** + * Called by the initialization and clear code paths to allow subclasses to reset any of their + * builtin fields back to the initial values. + */ + @Override + public BuilderType clear() { + unknownFields = UnknownFieldSet.getDefaultInstance(); + onChanged(); + return (BuilderType) this; + } + + /** + * Get the FieldAccessorTable for this type. We can't have the message class pass this in to the + * constructor because of bootstrapping trouble with DescriptorProtos. + */ + protected abstract FieldAccessorTable internalGetFieldAccessorTable(); + + @Override + public Descriptor getDescriptorForType() { + return internalGetFieldAccessorTable().descriptor; + } + + @Override + public Map getAllFields() { + return Collections.unmodifiableMap(getAllFieldsMutable()); + } + + /** Internal helper which returns a mutable map. */ + private Map getAllFieldsMutable() { + final TreeMap result = new TreeMap(); + final Descriptor descriptor = internalGetFieldAccessorTable().descriptor; + final List fields = descriptor.getFields(); + + for (int i = 0; i < fields.size(); i++) { + FieldDescriptor field = fields.get(i); + final OneofDescriptor oneofDescriptor = field.getContainingOneof(); + + /* + * If the field is part of a Oneof, then at maximum one field in the Oneof is set + * and it is not repeated. There is no need to iterate through the others. + */ + if (oneofDescriptor != null) { + // Skip other fields in the Oneof we know are not set + i += oneofDescriptor.getFieldCount() - 1; + if (!hasOneof(oneofDescriptor)) { + // If no field is set in the Oneof, skip all the fields in the Oneof + continue; + } + // Get the pointer to the only field which is set in the Oneof + field = getOneofFieldDescriptor(oneofDescriptor); + } else { + // If we are not in a Oneof, we need to check if the field is set and if it is repeated + if (field.isRepeated()) { + final List value = (List) getField(field); + if (!value.isEmpty()) { + result.put(field, value); + } + continue; + } + if (!hasField(field)) { + continue; + } + } + // Add the field to the map + result.put(field, getField(field)); + } + return result; + } + + @Override + public Message.Builder newBuilderForField(final FieldDescriptor field) { + return internalGetFieldAccessorTable().getField(field).newBuilder(); + } + + @Override + public Message.Builder getFieldBuilder(final FieldDescriptor field) { + return internalGetFieldAccessorTable().getField(field).getBuilder(this); + } + + @Override + public Message.Builder getRepeatedFieldBuilder(final FieldDescriptor field, int index) { + return internalGetFieldAccessorTable().getField(field).getRepeatedBuilder(this, index); + } + + @Override + public boolean hasOneof(final OneofDescriptor oneof) { + return internalGetFieldAccessorTable().getOneof(oneof).has(this); + } + + @Override + public FieldDescriptor getOneofFieldDescriptor(final OneofDescriptor oneof) { + return internalGetFieldAccessorTable().getOneof(oneof).get(this); + } + + @Override + public boolean hasField(final FieldDescriptor field) { + return internalGetFieldAccessorTable().getField(field).has(this); + } + + @Override + public Object getField(final FieldDescriptor field) { + Object object = internalGetFieldAccessorTable().getField(field).get(this); + if (field.isRepeated()) { + // The underlying list object is still modifiable at this point. + // Make sure not to expose the modifiable list to the caller. + return Collections.unmodifiableList((List) object); + } else { + return object; + } + } + + @Override + public BuilderType setField(final FieldDescriptor field, final Object value) { + internalGetFieldAccessorTable().getField(field).set(this, value); + return (BuilderType) this; + } + + @Override + public BuilderType clearField(final FieldDescriptor field) { + internalGetFieldAccessorTable().getField(field).clear(this); + return (BuilderType) this; + } + + @Override + public BuilderType clearOneof(final OneofDescriptor oneof) { + internalGetFieldAccessorTable().getOneof(oneof).clear(this); + return (BuilderType) this; + } + + @Override + public int getRepeatedFieldCount(final FieldDescriptor field) { + return internalGetFieldAccessorTable().getField(field).getRepeatedCount(this); + } + + @Override + public Object getRepeatedField(final FieldDescriptor field, final int index) { + return internalGetFieldAccessorTable().getField(field).getRepeated(this, index); + } + + @Override + public BuilderType setRepeatedField( + final FieldDescriptor field, final int index, final Object value) { + internalGetFieldAccessorTable().getField(field).setRepeated(this, index, value); + return (BuilderType) this; + } + + @Override + public BuilderType addRepeatedField(final FieldDescriptor field, final Object value) { + internalGetFieldAccessorTable().getField(field).addRepeated(this, value); + return (BuilderType) this; + } + + @Override + public BuilderType setUnknownFields(final UnknownFieldSet unknownFields) { + this.unknownFields = unknownFields; + onChanged(); + return (BuilderType) this; + } + + @Override + public BuilderType mergeUnknownFields(final UnknownFieldSet unknownFields) { + this.unknownFields = + UnknownFieldSet.newBuilder(this.unknownFields).mergeFrom(unknownFields).build(); + onChanged(); + return (BuilderType) this; + } + + @Override + public boolean isInitialized() { + for (final FieldDescriptor field : getDescriptorForType().getFields()) { + // Check that all required fields are present. + if (field.isRequired()) { + if (!hasField(field)) { + return false; + } + } + // Check that embedded messages are initialized. + if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { + if (field.isRepeated()) { + @SuppressWarnings("unchecked") + final List messageList = (List) getField(field); + for (final Message element : messageList) { + if (!element.isInitialized()) { + return false; + } + } + } else { + if (hasField(field) && !((Message) getField(field)).isInitialized()) { + return false; + } + } + } + } + return true; + } + + @Override + public final UnknownFieldSet getUnknownFields() { + return unknownFields; + } + + /** + * Called by subclasses to parse an unknown field. + * + * @return {@code true} unless the tag is an end-group tag. + */ + protected boolean parseUnknownField( + final CodedInputStream input, + final UnknownFieldSet.Builder unknownFields, + final ExtensionRegistryLite extensionRegistry, + final int tag) + throws IOException { + return unknownFields.mergeFieldFrom(tag, input); + } + + /** + * Implementation of {@link BuilderParent} for giving to our children. This small inner class + * makes it so we don't publicly expose the BuilderParent methods. + */ + private class BuilderParentImpl implements BuilderParent { + + @Override + public void markDirty() { + onChanged(); + } + } + + /** + * Gets the {@link BuilderParent} for giving to our children. + * + * @return The builder parent for our children. + */ + protected BuilderParent getParentForChildren() { + if (meAsParent == null) { + meAsParent = new BuilderParentImpl(); + } + return meAsParent; + } + + /** + * Called when a the builder or one of its nested children has changed and any parent should be + * notified of its invalidation. + */ + protected final void onChanged() { + if (isClean && builderParent != null) { + builderParent.markDirty(); + + // Don't keep dispatching invalidations until build is called again. + isClean = false; + } + } + + /** + * Gets the map field with the given field number. This method should be overridden in the + * generated message class if the message contains map fields. + * + *

Unlike other field types, reflection support for map fields can't be implemented based on + * generated public API because we need to access a map field as a list in reflection API but + * the generated API only allows us to access it as a map. This method returns the underlying + * map field directly and thus enables us to access the map field as a list. + */ + @SuppressWarnings({"unused", "rawtypes"}) + protected MapField internalGetMapField(int fieldNumber) { + // Note that we can't use descriptor names here because this method will + // be called when descriptor is being initialized. + throw new RuntimeException("No map fields found in " + getClass().getName()); + } + + /** Like {@link #internalGetMapField} but return a mutable version. */ + @SuppressWarnings({"unused", "rawtypes"}) + protected MapField internalGetMutableMapField(int fieldNumber) { + // Note that we can't use descriptor names here because this method will + // be called when descriptor is being initialized. + throw new RuntimeException("No map fields found in " + getClass().getName()); + } + } + + // ================================================================= + // Extensions-related stuff + + public interface ExtendableMessageOrBuilder + extends MessageOrBuilder { + // Re-define for return type covariance. + @Override + Message getDefaultInstanceForType(); + + /** Check if a singular extension is present. */ + boolean hasExtension(ExtensionLite extension); + + /** Get the number of elements in a repeated extension. */ + int getExtensionCount(ExtensionLite> extension); + + /** Get the value of an extension. */ + Type getExtension(ExtensionLite extension); + + /** Get one element of a repeated extension. */ + Type getExtension(ExtensionLite> extension, int index); + + /** Check if a singular extension is present. */ + boolean hasExtension(Extension extension); + /** Check if a singular extension is present. */ + boolean hasExtension(GeneratedExtension extension); + /** Get the number of elements in a repeated extension. */ + int getExtensionCount(Extension> extension); + /** Get the number of elements in a repeated extension. */ + int getExtensionCount(GeneratedExtension> extension); + /** Get the value of an extension. */ + Type getExtension(Extension extension); + /** Get the value of an extension. */ + Type getExtension(GeneratedExtension extension); + /** Get one element of a repeated extension. */ + Type getExtension(Extension> extension, int index); + /** Get one element of a repeated extension. */ + Type getExtension(GeneratedExtension> extension, int index); + } + + /** + * Generated message classes for message types that contain extension ranges subclass this. + * + *

This class implements type-safe accessors for extensions. They implement all the same + * operations that you can do with normal fields -- e.g. "has", "get", and "getCount" -- but for + * extensions. The extensions are identified using instances of the class {@link + * GeneratedExtension}; the protocol compiler generates a static instance of this class for every + * extension in its input. Through the magic of generics, all is made type-safe. + * + *

For example, imagine you have the {@code .proto} file: + * + *

+   * option java_class = "MyProto";
+   *
+   * message Foo {
+   *   extensions 1000 to max;
+   * }
+   *
+   * extend Foo {
+   *   optional int32 bar;
+   * }
+   * 
+ * + *

Then you might write code like: + * + *

+   * MyProto.Foo foo = getFoo();
+   * int i = foo.getExtension(MyProto.bar);
+   * 
+ * + *

See also {@link ExtendableBuilder}. + */ + public abstract static class ExtendableMessage + extends GeneratedMessageInternal implements ExtendableMessageOrBuilder { + + private static final long serialVersionUID = 1L; + + private final FieldSet extensions; + + protected ExtendableMessage() { + this.extensions = FieldSet.newFieldSet(); + } + + protected ExtendableMessage(ExtendableBuilder builder) { + super(builder); + this.extensions = builder.buildExtensions(); + } + + private void verifyExtensionContainingType(final Extension extension) { + if (extension.getDescriptor().getContainingType() != getDescriptorForType()) { + // This can only happen if someone uses unchecked operations. + throw new IllegalArgumentException( + "Extension is for type \"" + + extension.getDescriptor().getContainingType().getFullName() + + "\" which does not match message type \"" + + getDescriptorForType().getFullName() + + "\"."); + } + } + + /** Check if a singular extension is present. */ + @Override + @SuppressWarnings("unchecked") + public final boolean hasExtension(final ExtensionLite extensionLite) { + Extension extension = checkNotLite(extensionLite); + + verifyExtensionContainingType(extension); + return extensions.hasField(extension.getDescriptor()); + } + + /** Get the number of elements in a repeated extension. */ + @Override + @SuppressWarnings("unchecked") + public final int getExtensionCount( + final ExtensionLite> extensionLite) { + Extension> extension = checkNotLite(extensionLite); + + verifyExtensionContainingType(extension); + final FieldDescriptor descriptor = extension.getDescriptor(); + return extensions.getRepeatedFieldCount(descriptor); + } + + /** Get the value of an extension. */ + @Override + @SuppressWarnings("unchecked") + public final Type getExtension(final ExtensionLite extensionLite) { + Extension extension = checkNotLite(extensionLite); + + verifyExtensionContainingType(extension); + FieldDescriptor descriptor = extension.getDescriptor(); + final Object value = extensions.getField(descriptor); + if (value == null) { + if (descriptor.isRepeated()) { + return (Type) Collections.emptyList(); + } else if (descriptor.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { + return (Type) extension.getMessageDefaultInstance(); + } else { + return (Type) extension.fromReflectionType(descriptor.getDefaultValue()); + } + } else { + return (Type) extension.fromReflectionType(value); + } + } + + /** Get one element of a repeated extension. */ + @Override + @SuppressWarnings("unchecked") + public final Type getExtension( + final ExtensionLite> extensionLite, final int index) { + Extension> extension = checkNotLite(extensionLite); + + verifyExtensionContainingType(extension); + FieldDescriptor descriptor = extension.getDescriptor(); + return (Type) + extension.singularFromReflectionType(extensions.getRepeatedField(descriptor, index)); + } + + /** Check if a singular extension is present. */ + @Override + public final boolean hasExtension(final Extension extension) { + return hasExtension((ExtensionLite) extension); + } + /** Check if a singular extension is present. */ + @Override + public final boolean hasExtension( + final GeneratedExtension extension) { + return hasExtension((ExtensionLite) extension); + } + /** Get the number of elements in a repeated extension. */ + @Override + public final int getExtensionCount(final Extension> extension) { + return getExtensionCount((ExtensionLite>) extension); + } + /** Get the number of elements in a repeated extension. */ + @Override + public final int getExtensionCount( + final GeneratedExtension> extension) { + return getExtensionCount((ExtensionLite>) extension); + } + /** Get the value of an extension. */ + @Override + public final Type getExtension(final Extension extension) { + return getExtension((ExtensionLite) extension); + } + /** Get the value of an extension. */ + @Override + public final Type getExtension(final GeneratedExtension extension) { + return getExtension((ExtensionLite) extension); + } + /** Get one element of a repeated extension. */ + @Override + public final Type getExtension( + final Extension> extension, final int index) { + return getExtension((ExtensionLite>) extension, index); + } + /** Get one element of a repeated extension. */ + @Override + public final Type getExtension( + final GeneratedExtension> extension, final int index) { + return getExtension((ExtensionLite>) extension, index); + } + + /** Called by subclasses to check if all extensions are initialized. */ + protected boolean extensionsAreInitialized() { + return extensions.isInitialized(); + } + + @Override + public boolean isInitialized() { + return super.isInitialized() && extensionsAreInitialized(); + } + + @Override + protected boolean parseUnknownField( + CodedInputStream input, + UnknownFieldSet.Builder unknownFields, + ExtensionRegistryLite extensionRegistry, + int tag) + throws IOException { + return MessageReflection.mergeFieldFrom( + input, + unknownFields, + extensionRegistry, + getDescriptorForType(), + new MessageReflection.ExtensionAdapter(extensions), + tag); + } + + /** Used by parsing constructors in generated classes. */ + @Override + protected void makeExtensionsImmutable() { + extensions.makeImmutable(); + } + + /** + * Used by subclasses to serialize extensions. Extension ranges may be interleaved with field + * numbers, but we must write them in canonical (sorted by field number) order. ExtensionWriter + * helps us write individual ranges of extensions at once. + */ + protected class ExtensionWriter { + // Imagine how much simpler this code would be if Java iterators had + // a way to get the next element without advancing the iterator. + + private final Iterator> iter = extensions.iterator(); + private Map.Entry next; + private final boolean messageSetWireFormat; + + private ExtensionWriter(final boolean messageSetWireFormat) { + if (iter.hasNext()) { + next = iter.next(); + } + this.messageSetWireFormat = messageSetWireFormat; + } + + public void writeUntil(final int end, final CodedOutputStream output) throws IOException { + while (next != null && next.getKey().getNumber() < end) { + FieldDescriptor descriptor = next.getKey(); + if (messageSetWireFormat + && descriptor.getLiteJavaType() == WireFormat.JavaType.MESSAGE + && !descriptor.isRepeated()) { + if (next instanceof LazyField.LazyEntry) { + output.writeRawMessageSetExtension( + descriptor.getNumber(), + ((LazyField.LazyEntry) next).getField().toByteString()); + } else { + output.writeMessageSetExtension(descriptor.getNumber(), (Message) next.getValue()); + } + } else { + // TODO: Taken care of following code, it may cause + // problem when we use LazyField for normal fields/extensions. + // Due to the optional field can be duplicated at the end of + // serialized bytes, which will make the serialized size change + // after lazy field parsed. So when we use LazyField globally, + // we need to change the following write method to write cached + // bytes directly rather than write the parsed message. + FieldSet.writeField(descriptor, next.getValue(), output); + } + if (iter.hasNext()) { + next = iter.next(); + } else { + next = null; + } + } + } + } + + protected ExtensionWriter newExtensionWriter() { + return new ExtensionWriter(false); + } + + protected ExtensionWriter newMessageSetExtensionWriter() { + return new ExtensionWriter(true); + } + + /** Called by subclasses to compute the size of extensions. */ + protected int extensionsSerializedSize() { + return extensions.getSerializedSize(); + } + + protected int extensionsSerializedSizeAsMessageSet() { + return extensions.getMessageSetSerializedSize(); + } + + // --------------------------------------------------------------- + // Reflection + + protected Map getExtensionFields() { + return extensions.getAllFields(); + } + + @Override + public Map getAllFields() { + final Map result = + super.getAllFieldsMutable(/* getBytesForString = */ false); + result.putAll(getExtensionFields()); + return Collections.unmodifiableMap(result); + } + + @Override + public Map getAllFieldsRaw() { + final Map result = + super.getAllFieldsMutable(/* getBytesForString = */ false); + result.putAll(getExtensionFields()); + return Collections.unmodifiableMap(result); + } + + @Override + public boolean hasField(final FieldDescriptor field) { + if (field.isExtension()) { + verifyContainingType(field); + return extensions.hasField(field); + } else { + return super.hasField(field); + } + } + + @Override + public Object getField(final FieldDescriptor field) { + if (field.isExtension()) { + verifyContainingType(field); + final Object value = extensions.getField(field); + if (value == null) { + if (field.isRepeated()) { + return Collections.emptyList(); + } else if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { + // Lacking an ExtensionRegistry, we have no way to determine the + // extension's real type, so we return a DynamicMessage. + return DynamicMessage.getDefaultInstance(field.getMessageType()); + } else { + return field.getDefaultValue(); + } + } else { + return value; + } + } else { + return super.getField(field); + } + } + + @Override + public int getRepeatedFieldCount(final FieldDescriptor field) { + if (field.isExtension()) { + verifyContainingType(field); + return extensions.getRepeatedFieldCount(field); + } else { + return super.getRepeatedFieldCount(field); + } + } + + @Override + public Object getRepeatedField(final FieldDescriptor field, final int index) { + if (field.isExtension()) { + verifyContainingType(field); + return extensions.getRepeatedField(field, index); + } else { + return super.getRepeatedField(field, index); + } + } + + private void verifyContainingType(final FieldDescriptor field) { + if (field.getContainingType() != getDescriptorForType()) { + throw new IllegalArgumentException("FieldDescriptor does not match message type."); + } + } + } + + /** + * Generated message builders for message types that contain extension ranges subclass this. + * + *

This class implements type-safe accessors for extensions. They implement all the same + * operations that you can do with normal fields -- e.g. "get", "set", and "add" -- but for + * extensions. The extensions are identified using instances of the class {@link + * GeneratedExtension}; the protocol compiler generates a static instance of this class for every + * extension in its input. Through the magic of generics, all is made type-safe. + * + *

For example, imagine you have the {@code .proto} file: + * + *

+   * option java_class = "MyProto";
+   *
+   * message Foo {
+   *   extensions 1000 to max;
+   * }
+   *
+   * extend Foo {
+   *   optional int32 bar;
+   * }
+   * 
+ * + *

Then you might write code like: + * + *

+   * MyProto.Foo foo =
+   *   MyProto.Foo.newBuilder()
+   *     .setExtension(MyProto.bar, 123)
+   *     .build();
+   * 
+ * + *

See also {@link ExtendableMessage}. + */ + @SuppressWarnings("unchecked") + public abstract static class ExtendableBuilder< + MessageType extends ExtendableMessage, + BuilderType extends ExtendableBuilder> + extends Builder implements ExtendableMessageOrBuilder { + + private FieldSet extensions = FieldSet.emptySet(); + + protected ExtendableBuilder() {} + + protected ExtendableBuilder(BuilderParent parent) { + super(parent); + } + + // For immutable message conversion. + void internalSetExtensionSet(FieldSet extensions) { + this.extensions = extensions; + } + + @Override + public BuilderType clear() { + extensions = FieldSet.emptySet(); + return super.clear(); + } + + // This is implemented here only to work around an apparent bug in the + // Java compiler and/or build system. See bug #1898463. The mere presence + // of this clone() implementation makes it go away. + @Override + public BuilderType clone() { + return super.clone(); + } + + private void ensureExtensionsIsMutable() { + if (extensions.isImmutable()) { + extensions = extensions.clone(); + } + } + + private void verifyExtensionContainingType(final Extension extension) { + if (extension.getDescriptor().getContainingType() != getDescriptorForType()) { + // This can only happen if someone uses unchecked operations. + throw new IllegalArgumentException( + "Extension is for type \"" + + extension.getDescriptor().getContainingType().getFullName() + + "\" which does not match message type \"" + + getDescriptorForType().getFullName() + + "\"."); + } + } + + /** Check if a singular extension is present. */ + @Override + public final boolean hasExtension(final ExtensionLite extensionLite) { + Extension extension = checkNotLite(extensionLite); + + verifyExtensionContainingType(extension); + return extensions.hasField(extension.getDescriptor()); + } + + /** Get the number of elements in a repeated extension. */ + @Override + public final int getExtensionCount( + final ExtensionLite> extensionLite) { + Extension> extension = checkNotLite(extensionLite); + + verifyExtensionContainingType(extension); + final FieldDescriptor descriptor = extension.getDescriptor(); + return extensions.getRepeatedFieldCount(descriptor); + } + + /** Get the value of an extension. */ + @Override + public final Type getExtension(final ExtensionLite extensionLite) { + Extension extension = checkNotLite(extensionLite); + + verifyExtensionContainingType(extension); + FieldDescriptor descriptor = extension.getDescriptor(); + final Object value = extensions.getField(descriptor); + if (value == null) { + if (descriptor.isRepeated()) { + return (Type) Collections.emptyList(); + } else if (descriptor.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { + return (Type) extension.getMessageDefaultInstance(); + } else { + return (Type) extension.fromReflectionType(descriptor.getDefaultValue()); + } + } else { + return (Type) extension.fromReflectionType(value); + } + } + + /** Get one element of a repeated extension. */ + @Override + public final Type getExtension( + final ExtensionLite> extensionLite, final int index) { + Extension> extension = checkNotLite(extensionLite); + + verifyExtensionContainingType(extension); + FieldDescriptor descriptor = extension.getDescriptor(); + return (Type) + extension.singularFromReflectionType(extensions.getRepeatedField(descriptor, index)); + } + + /** Set the value of an extension. */ + public final BuilderType setExtension( + final ExtensionLite extensionLite, final Type value) { + Extension extension = checkNotLite(extensionLite); + + verifyExtensionContainingType(extension); + ensureExtensionsIsMutable(); + final FieldDescriptor descriptor = extension.getDescriptor(); + extensions.setField(descriptor, extension.toReflectionType(value)); + onChanged(); + return (BuilderType) this; + } + + /** Set the value of one element of a repeated extension. */ + public final BuilderType setExtension( + final ExtensionLite> extensionLite, + final int index, + final Type value) { + Extension> extension = checkNotLite(extensionLite); + + verifyExtensionContainingType(extension); + ensureExtensionsIsMutable(); + final FieldDescriptor descriptor = extension.getDescriptor(); + extensions.setRepeatedField(descriptor, index, extension.singularToReflectionType(value)); + onChanged(); + return (BuilderType) this; + } + + /** Append a value to a repeated extension. */ + public final BuilderType addExtension( + final ExtensionLite> extensionLite, final Type value) { + Extension> extension = checkNotLite(extensionLite); + + verifyExtensionContainingType(extension); + ensureExtensionsIsMutable(); + final FieldDescriptor descriptor = extension.getDescriptor(); + extensions.addRepeatedField(descriptor, extension.singularToReflectionType(value)); + onChanged(); + return (BuilderType) this; + } + + /** Clear an extension. */ + public final BuilderType clearExtension( + final ExtensionLite extensionLite) { + Extension extension = checkNotLite(extensionLite); + + verifyExtensionContainingType(extension); + ensureExtensionsIsMutable(); + extensions.clearField(extension.getDescriptor()); + onChanged(); + return (BuilderType) this; + } + + /** Check if a singular extension is present. */ + @Override + public final boolean hasExtension(final Extension extension) { + return hasExtension((ExtensionLite) extension); + } + /** Check if a singular extension is present. */ + @Override + public final boolean hasExtension( + final GeneratedExtension extension) { + return hasExtension((ExtensionLite) extension); + } + /** Get the number of elements in a repeated extension. */ + @Override + public final int getExtensionCount(final Extension> extension) { + return getExtensionCount((ExtensionLite>) extension); + } + /** Get the number of elements in a repeated extension. */ + @Override + public final int getExtensionCount( + final GeneratedExtension> extension) { + return getExtensionCount((ExtensionLite>) extension); + } + /** Get the value of an extension. */ + @Override + public final Type getExtension(final Extension extension) { + return getExtension((ExtensionLite) extension); + } + /** Get the value of an extension. */ + @Override + public final Type getExtension(final GeneratedExtension extension) { + return getExtension((ExtensionLite) extension); + } + /** Get the value of an extension. */ + @Override + public final Type getExtension( + final Extension> extension, final int index) { + return getExtension((ExtensionLite>) extension, index); + } + /** Get the value of an extension. */ + @Override + public final Type getExtension( + final GeneratedExtension> extension, final int index) { + return getExtension((ExtensionLite>) extension, index); + } + /** Set the value of an extension. */ + public final BuilderType setExtension( + final Extension extension, final Type value) { + return setExtension((ExtensionLite) extension, value); + } + /** Set the value of an extension. */ + public BuilderType setExtension( + final GeneratedExtension extension, final Type value) { + return setExtension((ExtensionLite) extension, value); + } + /** Set the value of one element of a repeated extension. */ + public final BuilderType setExtension( + final Extension> extension, final int index, final Type value) { + return setExtension((ExtensionLite>) extension, index, value); + } + /** Set the value of one element of a repeated extension. */ + public BuilderType setExtension( + final GeneratedExtension> extension, + final int index, + final Type value) { + return setExtension((ExtensionLite>) extension, index, value); + } + /** Append a value to a repeated extension. */ + public final BuilderType addExtension( + final Extension> extension, final Type value) { + return addExtension((ExtensionLite>) extension, value); + } + /** Append a value to a repeated extension. */ + public BuilderType addExtension( + final GeneratedExtension> extension, final Type value) { + return addExtension((ExtensionLite>) extension, value); + } + /** Clear an extension. */ + public final BuilderType clearExtension(final Extension extension) { + return clearExtension((ExtensionLite) extension); + } + /** Clear an extension. */ + public BuilderType clearExtension(final GeneratedExtension extension) { + return clearExtension((ExtensionLite) extension); + } + + /** Called by subclasses to check if all extensions are initialized. */ + protected boolean extensionsAreInitialized() { + return extensions.isInitialized(); + } + + /** + * Called by the build code path to create a copy of the extensions for building the message. + */ + private FieldSet buildExtensions() { + extensions.makeImmutable(); + return extensions; + } + + @Override + public boolean isInitialized() { + return super.isInitialized() && extensionsAreInitialized(); + } + + /** + * Called by subclasses to parse an unknown field or an extension. + * + * @return {@code true} unless the tag is an end-group tag. + */ + @Override + protected boolean parseUnknownField( + final CodedInputStream input, + final UnknownFieldSet.Builder unknownFields, + final ExtensionRegistryLite extensionRegistry, + final int tag) + throws IOException { + return MessageReflection.mergeFieldFrom( + input, + unknownFields, + extensionRegistry, + getDescriptorForType(), + new MessageReflection.BuilderAdapter(this), + tag); + } + + // --------------------------------------------------------------- + // Reflection + + @Override + public Map getAllFields() { + final Map result = super.getAllFieldsMutable(); + result.putAll(extensions.getAllFields()); + return Collections.unmodifiableMap(result); + } + + @Override + public Object getField(final FieldDescriptor field) { + if (field.isExtension()) { + verifyContainingType(field); + final Object value = extensions.getField(field); + if (value == null) { + if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { + // Lacking an ExtensionRegistry, we have no way to determine the + // extension's real type, so we return a DynamicMessage. + return DynamicMessage.getDefaultInstance(field.getMessageType()); + } else { + return field.getDefaultValue(); + } + } else { + return value; + } + } else { + return super.getField(field); + } + } + + @Override + public int getRepeatedFieldCount(final FieldDescriptor field) { + if (field.isExtension()) { + verifyContainingType(field); + return extensions.getRepeatedFieldCount(field); + } else { + return super.getRepeatedFieldCount(field); + } + } + + @Override + public Object getRepeatedField(final FieldDescriptor field, final int index) { + if (field.isExtension()) { + verifyContainingType(field); + return extensions.getRepeatedField(field, index); + } else { + return super.getRepeatedField(field, index); + } + } + + @Override + public boolean hasField(final FieldDescriptor field) { + if (field.isExtension()) { + verifyContainingType(field); + return extensions.hasField(field); + } else { + return super.hasField(field); + } + } + + @Override + public BuilderType setField(final FieldDescriptor field, final Object value) { + if (field.isExtension()) { + verifyContainingType(field); + ensureExtensionsIsMutable(); + extensions.setField(field, value); + onChanged(); + return (BuilderType) this; + } else { + return super.setField(field, value); + } + } + + @Override + public BuilderType clearField(final FieldDescriptor field) { + if (field.isExtension()) { + verifyContainingType(field); + ensureExtensionsIsMutable(); + extensions.clearField(field); + onChanged(); + return (BuilderType) this; + } else { + return super.clearField(field); + } + } + + @Override + public BuilderType setRepeatedField( + final FieldDescriptor field, final int index, final Object value) { + if (field.isExtension()) { + verifyContainingType(field); + ensureExtensionsIsMutable(); + extensions.setRepeatedField(field, index, value); + onChanged(); + return (BuilderType) this; + } else { + return super.setRepeatedField(field, index, value); + } + } + + @Override + public BuilderType addRepeatedField(final FieldDescriptor field, final Object value) { + if (field.isExtension()) { + verifyContainingType(field); + ensureExtensionsIsMutable(); + extensions.addRepeatedField(field, value); + onChanged(); + return (BuilderType) this; + } else { + return super.addRepeatedField(field, value); + } + } + + protected final void mergeExtensionFields(final ExtendableMessage other) { + ensureExtensionsIsMutable(); + extensions.mergeFrom(other.extensions); + onChanged(); + } + + private void verifyContainingType(final FieldDescriptor field) { + if (field.getContainingType() != getDescriptorForType()) { + throw new IllegalArgumentException("FieldDescriptor does not match message type."); + } + } + } + + // ----------------------------------------------------------------- + + /** + * Gets the descriptor for an extension. The implementation depends on whether the extension is + * scoped in the top level of a file or scoped in a Message. + */ + static interface ExtensionDescriptorRetriever { + FieldDescriptor getDescriptor(); + } + + /** For use by generated code only. */ + public static + GeneratedExtension newMessageScopedGeneratedExtension( + final Message scope, + final int descriptorIndex, + final Class singularType, + final Message defaultInstance) { + // For extensions scoped within a Message, we use the Message to resolve + // the outer class's descriptor, from which the extension descriptor is + // obtained. + return new GeneratedExtension( + new CachedDescriptorRetriever() { + @Override + public FieldDescriptor loadDescriptor() { + return scope.getDescriptorForType().getExtensions().get(descriptorIndex); + } + }, + singularType, + defaultInstance, + Extension.ExtensionType.IMMUTABLE); + } + + /** For use by generated code only. */ + public static + GeneratedExtension newFileScopedGeneratedExtension( + final Class singularType, final Message defaultInstance) { + // For extensions scoped within a file, we rely on the outer class's + // static initializer to call internalInit() on the extension when the + // descriptor is available. + return new GeneratedExtension( + null, // ExtensionDescriptorRetriever is initialized in internalInit(); + singularType, + defaultInstance, + Extension.ExtensionType.IMMUTABLE); + } + + private abstract static class CachedDescriptorRetriever implements ExtensionDescriptorRetriever { + private volatile FieldDescriptor descriptor; + + protected abstract FieldDescriptor loadDescriptor(); + + @Override + public FieldDescriptor getDescriptor() { + if (descriptor == null) { + synchronized (this) { + if (descriptor == null) { + descriptor = loadDescriptor(); + } + } + } + return descriptor; + } + } + + /** + * Used in proto1 generated code only. + * + *

After enabling bridge, we can define proto2 extensions (the extended type is a proto2 + * mutable message) in a proto1 .proto file. For these extensions we should generate proto2 + * GeneratedExtensions. + */ + public static + GeneratedExtension newMessageScopedGeneratedExtension( + final Message scope, + final String name, + final Class singularType, + final Message defaultInstance) { + // For extensions scoped within a Message, we use the Message to resolve + // the outer class's descriptor, from which the extension descriptor is + // obtained. + return new GeneratedExtension( + new CachedDescriptorRetriever() { + @Override + protected FieldDescriptor loadDescriptor() { + return scope.getDescriptorForType().findFieldByName(name); + } + }, + singularType, + defaultInstance, + Extension.ExtensionType.MUTABLE); + } + + /** + * Used in proto1 generated code only. + * + *

After enabling bridge, we can define proto2 extensions (the extended type is a proto2 + * mutable message) in a proto1 .proto file. For these extensions we should generate proto2 + * GeneratedExtensions. + */ + public static + GeneratedExtension newFileScopedGeneratedExtension( + final Class singularType, + final Message defaultInstance, + final String descriptorOuterClass, + final String extensionName) { + // For extensions scoped within a file, we load the descriptor outer + // class and rely on it to get the FileDescriptor which then can be + // used to obtain the extension's FieldDescriptor. + return new GeneratedExtension( + new CachedDescriptorRetriever() { + @Override + protected FieldDescriptor loadDescriptor() { + try { + Class clazz = singularType.getClassLoader().loadClass(descriptorOuterClass); + FileDescriptor file = (FileDescriptor) clazz.getField("descriptor").get(null); + return file.findExtensionByName(extensionName); + } catch (Exception e) { + throw new RuntimeException( + "Cannot load descriptors: " + + descriptorOuterClass + + " is not a valid descriptor class name", + e); + } + } + }, + singularType, + defaultInstance, + Extension.ExtensionType.MUTABLE); + } + + /** + * Type used to represent generated extensions. The protocol compiler generates a static singleton + * instance of this class for each extension. + * + *

For example, imagine you have the {@code .proto} file: + * + *

+   * option java_class = "MyProto";
+   *
+   * message Foo {
+   *   extensions 1000 to max;
+   * }
+   *
+   * extend Foo {
+   *   optional int32 bar;
+   * }
+   * 
+ * + *

Then, {@code MyProto.Foo.bar} has type {@code GeneratedExtension}. + * + *

In general, users should ignore the details of this type, and simply use these static + * singletons as parameters to the extension accessors defined in {@link ExtendableMessage} and + * {@link ExtendableBuilder}. + */ + public static class GeneratedExtension + extends Extension { + // TODO: Find ways to avoid using Java reflection within this + // class. Also try to avoid suppressing unchecked warnings. + + // We can't always initialize the descriptor of a GeneratedExtension when + // we first construct it due to initialization order difficulties (namely, + // the descriptor may not have been constructed yet, since it is often + // constructed by the initializer of a separate module). + // + // In the case of nested extensions, we initialize the + // ExtensionDescriptorRetriever with an instance that uses the scoping + // Message's default instance to retrieve the extension's descriptor. + // + // In the case of non-nested extensions, we initialize the + // ExtensionDescriptorRetriever to null and rely on the outer class's static + // initializer to call internalInit() after the descriptor has been parsed. + GeneratedExtension( + ExtensionDescriptorRetriever descriptorRetriever, + Class singularType, + Message messageDefaultInstance, + ExtensionType extensionType) { + if (Message.class.isAssignableFrom(singularType) + && !singularType.isInstance(messageDefaultInstance)) { + throw new IllegalArgumentException( + "Bad messageDefaultInstance for " + singularType.getName()); + } + this.descriptorRetriever = descriptorRetriever; + this.singularType = singularType; + this.messageDefaultInstance = messageDefaultInstance; + + if (ProtocolMessageEnum.class.isAssignableFrom(singularType)) { + this.enumValueOf = getMethodOrDie(singularType, "valueOf", EnumValueDescriptor.class); + this.enumGetValueDescriptor = getMethodOrDie(singularType, "getValueDescriptor"); + } else { + this.enumValueOf = null; + this.enumGetValueDescriptor = null; + } + this.extensionType = extensionType; + } + + /** For use by generated code only. */ + public void internalInit(final FieldDescriptor descriptor) { + if (descriptorRetriever != null) { + throw new IllegalStateException("Already initialized."); + } + descriptorRetriever = + new ExtensionDescriptorRetriever() { + @Override + public FieldDescriptor getDescriptor() { + return descriptor; + } + }; + } + + private ExtensionDescriptorRetriever descriptorRetriever; + private final Class singularType; + private final Message messageDefaultInstance; + private final Method enumValueOf; + private final Method enumGetValueDescriptor; + private final ExtensionType extensionType; + + @Override + public FieldDescriptor getDescriptor() { + if (descriptorRetriever == null) { + throw new IllegalStateException("getDescriptor() called before internalInit()"); + } + return descriptorRetriever.getDescriptor(); + } + + /** + * If the extension is an embedded message or group, returns the default instance of the + * message. + */ + @Override + public Message getMessageDefaultInstance() { + return messageDefaultInstance; + } + + @Override + protected ExtensionType getExtensionType() { + return extensionType; + } + + /** + * Convert from the type used by the reflection accessors to the type used by native accessors. + * E.g., for enums, the reflection accessors use EnumValueDescriptors but the native accessors + * use the generated enum type. + */ + @Override + @SuppressWarnings("unchecked") + protected Object fromReflectionType(final Object value) { + FieldDescriptor descriptor = getDescriptor(); + if (descriptor.isRepeated()) { + if (descriptor.getJavaType() == FieldDescriptor.JavaType.MESSAGE + || descriptor.getJavaType() == FieldDescriptor.JavaType.ENUM) { + // Must convert the whole list. + final List result = new ArrayList(); + for (final Object element : (List) value) { + result.add(singularFromReflectionType(element)); + } + return result; + } else { + return value; + } + } else { + return singularFromReflectionType(value); + } + } + + /** + * Like {@link #fromReflectionType(Object)}, but if the type is a repeated type, this converts a + * single element. + */ + @Override + protected Object singularFromReflectionType(final Object value) { + FieldDescriptor descriptor = getDescriptor(); + switch (descriptor.getJavaType()) { + case MESSAGE: + if (singularType.isInstance(value)) { + return value; + } else { + return messageDefaultInstance.newBuilderForType().mergeFrom((Message) value).build(); + } + case ENUM: + return invokeOrDie(enumValueOf, null, (EnumValueDescriptor) value); + default: + return value; + } + } + + /** + * Convert from the type used by the native accessors to the type used by reflection accessors. + * E.g., for enums, the reflection accessors use EnumValueDescriptors but the native accessors + * use the generated enum type. + */ + @Override + @SuppressWarnings("unchecked") + protected Object toReflectionType(final Object value) { + FieldDescriptor descriptor = getDescriptor(); + if (descriptor.isRepeated()) { + if (descriptor.getJavaType() == FieldDescriptor.JavaType.ENUM) { + // Must convert the whole list. + final List result = new ArrayList(); + for (final Object element : (List) value) { + result.add(singularToReflectionType(element)); + } + return result; + } else { + return value; + } + } else { + return singularToReflectionType(value); + } + } + + /** + * Like {@link #toReflectionType(Object)}, but if the type is a repeated type, this converts a + * single element. + */ + @Override + protected Object singularToReflectionType(final Object value) { + FieldDescriptor descriptor = getDescriptor(); + switch (descriptor.getJavaType()) { + case ENUM: + return invokeOrDie(enumGetValueDescriptor, value); + default: + return value; + } + } + + @Override + public int getNumber() { + return getDescriptor().getNumber(); + } + + @Override + public WireFormat.FieldType getLiteType() { + return getDescriptor().getLiteType(); + } + + @Override + public boolean isRepeated() { + return getDescriptor().isRepeated(); + } + + @Override + @SuppressWarnings("unchecked") + public Type getDefaultValue() { + if (isRepeated()) { + return (Type) Collections.emptyList(); + } + if (getDescriptor().getJavaType() == FieldDescriptor.JavaType.MESSAGE) { + return (Type) messageDefaultInstance; + } + return (Type) singularFromReflectionType(getDescriptor().getDefaultValue()); + } + } + + // ================================================================= + + /** Calls Class.getMethod and throws a RuntimeException if it fails. */ + @SuppressWarnings("unchecked") + private static Method getMethodOrDie( + final Class clazz, final String name, final Class... params) { + try { + return clazz.getMethod(name, params); + } catch (NoSuchMethodException e) { + throw new RuntimeException( + "Generated message class \"" + clazz.getName() + "\" missing method \"" + name + "\".", + e); + } + } + + /** Calls invoke and throws a RuntimeException if it fails. */ + private static Object invokeOrDie( + final Method method, final Object object, final Object... params) { + try { + return method.invoke(object, params); + } catch (IllegalAccessException e) { + throw new RuntimeException( + "Couldn't use Java reflection to implement protocol message " + "reflection.", e); + } catch (InvocationTargetException e) { + final Throwable cause = e.getCause(); + if (cause instanceof RuntimeException) { + throw (RuntimeException) cause; + } else if (cause instanceof Error) { + throw (Error) cause; + } else { + throw new RuntimeException( + "Unexpected exception thrown by generated accessor method.", cause); + } + } + } + + /** + * Gets the map field with the given field number. This method should be overridden in the + * generated message class if the message contains map fields. + * + *

Unlike other field types, reflection support for map fields can't be implemented based on + * generated public API because we need to access a map field as a list in reflection API but the + * generated API only allows us to access it as a map. This method returns the underlying map + * field directly and thus enables us to access the map field as a list. + */ + @SuppressWarnings({"rawtypes", "unused"}) + protected MapField internalGetMapField(int fieldNumber) { + // Note that we can't use descriptor names here because this method will + // be called when descriptor is being initialized. + throw new RuntimeException("No map fields found in " + getClass().getName()); + } + + /** + * Users should ignore this class. This class provides the implementation with access to the + * fields of a message object using Java reflection. + */ + public static final class FieldAccessorTable { + + /** + * Construct a FieldAccessorTable for a particular message class. Only one FieldAccessorTable + * should ever be constructed per class. + * + * @param descriptor The type's descriptor. + * @param camelCaseNames The camelcase names of all fields in the message. These are used to + * derive the accessor method names. + * @param messageClass The message type. + * @param builderClass The builder type. + */ + public FieldAccessorTable( + final Descriptor descriptor, + final String[] camelCaseNames, + final Class messageClass, + final Class builderClass) { + this(descriptor, camelCaseNames); + ensureFieldAccessorsInitialized(messageClass, builderClass); + } + + /** + * Construct a FieldAccessorTable for a particular message class without initializing + * FieldAccessors. + */ + public FieldAccessorTable(final Descriptor descriptor, final String[] camelCaseNames) { + this.descriptor = descriptor; + this.camelCaseNames = camelCaseNames; + fields = new FieldAccessor[descriptor.getFields().size()]; + oneofs = new OneofAccessor[descriptor.getOneofs().size()]; + initialized = false; + } + + private boolean isMapFieldEnabled(FieldDescriptor field) { + boolean result = true; + return result; + } + + /** + * Ensures the field accessors are initialized. This method is thread-safe. + * + * @param messageClass The message type. + * @param builderClass The builder type. + * @return this + */ + public FieldAccessorTable ensureFieldAccessorsInitialized( + Class messageClass, Class builderClass) { + if (initialized) { + return this; + } + synchronized (this) { + if (initialized) { + return this; + } + int fieldsSize = fields.length; + for (int i = 0; i < fieldsSize; i++) { + FieldDescriptor field = descriptor.getFields().get(i); + String containingOneofCamelCaseName = null; + if (field.getContainingOneof() != null) { + containingOneofCamelCaseName = + camelCaseNames[fieldsSize + field.getContainingOneof().getIndex()]; + } + if (field.isRepeated()) { + if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { + if (field.isMapField() && isMapFieldEnabled(field)) { + fields[i] = + new MapFieldAccessor(field, camelCaseNames[i], messageClass, builderClass); + } else { + fields[i] = + new RepeatedMessageFieldAccessor( + field, camelCaseNames[i], messageClass, builderClass); + } + } else if (field.getJavaType() == FieldDescriptor.JavaType.ENUM) { + fields[i] = + new RepeatedEnumFieldAccessor( + field, camelCaseNames[i], messageClass, builderClass); + } else { + fields[i] = + new RepeatedFieldAccessor(field, camelCaseNames[i], messageClass, builderClass); + } + } else { + if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { + fields[i] = + new SingularMessageFieldAccessor( + field, + camelCaseNames[i], + messageClass, + builderClass, + containingOneofCamelCaseName); + } else if (field.getJavaType() == FieldDescriptor.JavaType.ENUM) { + fields[i] = + new SingularEnumFieldAccessor( + field, + camelCaseNames[i], + messageClass, + builderClass, + containingOneofCamelCaseName); + } else if (field.getJavaType() == FieldDescriptor.JavaType.STRING) { + fields[i] = + new SingularStringFieldAccessor( + field, + camelCaseNames[i], + messageClass, + builderClass, + containingOneofCamelCaseName); + } else { + fields[i] = + new SingularFieldAccessor( + field, + camelCaseNames[i], + messageClass, + builderClass, + containingOneofCamelCaseName); + } + } + } + + int oneofsSize = oneofs.length; + for (int i = 0; i < oneofsSize; i++) { + oneofs[i] = + new OneofAccessor( + descriptor, camelCaseNames[i + fieldsSize], messageClass, builderClass); + } + initialized = true; + camelCaseNames = null; + return this; + } + } + + private final Descriptor descriptor; + private final FieldAccessor[] fields; + private String[] camelCaseNames; + private final OneofAccessor[] oneofs; + private volatile boolean initialized; + + /** Get the FieldAccessor for a particular field. */ + private FieldAccessor getField(final FieldDescriptor field) { + if (field.getContainingType() != descriptor) { + throw new IllegalArgumentException("FieldDescriptor does not match message type."); + } else if (field.isExtension()) { + // If this type had extensions, it would subclass ExtendableMessage, + // which overrides the reflection interface to handle extensions. + throw new IllegalArgumentException("This type does not have extensions."); + } + return fields[field.getIndex()]; + } + + /** Get the OneofAccessor for a particular oneof. */ + private OneofAccessor getOneof(final OneofDescriptor oneof) { + if (oneof.getContainingType() != descriptor) { + throw new IllegalArgumentException("OneofDescriptor does not match message type."); + } + return oneofs[oneof.getIndex()]; + } + + /** + * Abstract interface that provides access to a single field. This is implemented differently + * depending on the field type and cardinality. + */ + private interface FieldAccessor { + Object get(GeneratedMessageInternal message); + + Object get(GeneratedMessageInternal.Builder builder); + + Object getRaw(GeneratedMessageInternal message); + + Object getRaw(GeneratedMessageInternal.Builder builder); + + void set(Builder builder, Object value); + + Object getRepeated(GeneratedMessageInternal message, int index); + + Object getRepeated(GeneratedMessageInternal.Builder builder, int index); + + Object getRepeatedRaw(GeneratedMessageInternal message, int index); + + Object getRepeatedRaw(GeneratedMessageInternal.Builder builder, int index); + + void setRepeated(Builder builder, int index, Object value); + + void addRepeated(Builder builder, Object value); + + boolean has(GeneratedMessageInternal message); + + boolean has(GeneratedMessageInternal.Builder builder); + + int getRepeatedCount(GeneratedMessageInternal message); + + int getRepeatedCount(GeneratedMessageInternal.Builder builder); + + void clear(Builder builder); + + Message.Builder newBuilder(); + + Message.Builder getBuilder(GeneratedMessageInternal.Builder builder); + + Message.Builder getRepeatedBuilder(GeneratedMessageInternal.Builder builder, int index); + } + + /** OneofAccessor provides access to a single oneof. */ + private static class OneofAccessor { + OneofAccessor( + final Descriptor descriptor, + final String camelCaseName, + final Class messageClass, + final Class builderClass) { + this.descriptor = descriptor; + caseMethod = getMethodOrDie(messageClass, "get" + camelCaseName + "Case"); + caseMethodBuilder = getMethodOrDie(builderClass, "get" + camelCaseName + "Case"); + clearMethod = getMethodOrDie(builderClass, "clear" + camelCaseName); + } + + private final Descriptor descriptor; + private final Method caseMethod; + private final Method caseMethodBuilder; + private final Method clearMethod; + + public boolean has(final GeneratedMessageInternal message) { + if (((Internal.EnumLite) invokeOrDie(caseMethod, message)).getNumber() == 0) { + return false; + } + return true; + } + + public boolean has(GeneratedMessageInternal.Builder builder) { + if (((Internal.EnumLite) invokeOrDie(caseMethodBuilder, builder)).getNumber() == 0) { + return false; + } + return true; + } + + public FieldDescriptor get(final GeneratedMessageInternal message) { + int fieldNumber = ((Internal.EnumLite) invokeOrDie(caseMethod, message)).getNumber(); + if (fieldNumber > 0) { + return descriptor.findFieldByNumber(fieldNumber); + } + return null; + } + + public FieldDescriptor get(GeneratedMessageInternal.Builder builder) { + int fieldNumber = ((Internal.EnumLite) invokeOrDie(caseMethodBuilder, builder)).getNumber(); + if (fieldNumber > 0) { + return descriptor.findFieldByNumber(fieldNumber); + } + return null; + } + + public void clear(final Builder builder) { + invokeOrDie(clearMethod, builder); + } + } + + private static boolean supportFieldPresence(FileDescriptor file) { + return file.getSyntax() == FileDescriptor.Syntax.PROTO2; + } + + // --------------------------------------------------------------- + + private static class SingularFieldAccessor implements FieldAccessor { + SingularFieldAccessor( + final FieldDescriptor descriptor, + final String camelCaseName, + final Class messageClass, + final Class builderClass, + final String containingOneofCamelCaseName) { + field = descriptor; + isOneofField = descriptor.getContainingOneof() != null; + hasHasMethod = + supportFieldPresence(descriptor.getFile()) + || (!isOneofField && descriptor.getJavaType() == FieldDescriptor.JavaType.MESSAGE); + getMethod = getMethodOrDie(messageClass, "get" + camelCaseName); + getMethodBuilder = getMethodOrDie(builderClass, "get" + camelCaseName); + type = getMethod.getReturnType(); + setMethod = getMethodOrDie(builderClass, "set" + camelCaseName, type); + hasMethod = hasHasMethod ? getMethodOrDie(messageClass, "has" + camelCaseName) : null; + hasMethodBuilder = + hasHasMethod ? getMethodOrDie(builderClass, "has" + camelCaseName) : null; + clearMethod = getMethodOrDie(builderClass, "clear" + camelCaseName); + caseMethod = + isOneofField + ? getMethodOrDie(messageClass, "get" + containingOneofCamelCaseName + "Case") + : null; + caseMethodBuilder = + isOneofField + ? getMethodOrDie(builderClass, "get" + containingOneofCamelCaseName + "Case") + : null; + } + + // Note: We use Java reflection to call public methods rather than + // access private fields directly as this avoids runtime security + // checks. + protected final Class type; + protected final Method getMethod; + protected final Method getMethodBuilder; + protected final Method setMethod; + protected final Method hasMethod; + protected final Method hasMethodBuilder; + protected final Method clearMethod; + protected final Method caseMethod; + protected final Method caseMethodBuilder; + protected final FieldDescriptor field; + protected final boolean isOneofField; + protected final boolean hasHasMethod; + + private int getOneofFieldNumber(final GeneratedMessageInternal message) { + return ((Internal.EnumLite) invokeOrDie(caseMethod, message)).getNumber(); + } + + private int getOneofFieldNumber(final GeneratedMessageInternal.Builder builder) { + return ((Internal.EnumLite) invokeOrDie(caseMethodBuilder, builder)).getNumber(); + } + + @Override + public Object get(final GeneratedMessageInternal message) { + return invokeOrDie(getMethod, message); + } + + @Override + public Object get(GeneratedMessageInternal.Builder builder) { + return invokeOrDie(getMethodBuilder, builder); + } + + @Override + public Object getRaw(final GeneratedMessageInternal message) { + return get(message); + } + + @Override + public Object getRaw(GeneratedMessageInternal.Builder builder) { + return get(builder); + } + + @Override + public void set(final Builder builder, final Object value) { + invokeOrDie(setMethod, builder, value); + } + + @Override + public Object getRepeated(final GeneratedMessageInternal message, final int index) { + throw new UnsupportedOperationException("getRepeatedField() called on a singular field."); + } + + @Override + public Object getRepeatedRaw(final GeneratedMessageInternal message, final int index) { + throw new UnsupportedOperationException( + "getRepeatedFieldRaw() called on a singular field."); + } + + @Override + public Object getRepeated(GeneratedMessageInternal.Builder builder, int index) { + throw new UnsupportedOperationException("getRepeatedField() called on a singular field."); + } + + @Override + public Object getRepeatedRaw(GeneratedMessageInternal.Builder builder, int index) { + throw new UnsupportedOperationException( + "getRepeatedFieldRaw() called on a singular field."); + } + + @Override + public void setRepeated(final Builder builder, final int index, final Object value) { + throw new UnsupportedOperationException("setRepeatedField() called on a singular field."); + } + + @Override + public void addRepeated(final Builder builder, final Object value) { + throw new UnsupportedOperationException("addRepeatedField() called on a singular field."); + } + + @Override + public boolean has(final GeneratedMessageInternal message) { + if (!hasHasMethod) { + if (isOneofField) { + return getOneofFieldNumber(message) == field.getNumber(); + } + return !get(message).equals(field.getDefaultValue()); + } + return (Boolean) invokeOrDie(hasMethod, message); + } + + @Override + public boolean has(GeneratedMessageInternal.Builder builder) { + if (!hasHasMethod) { + if (isOneofField) { + return getOneofFieldNumber(builder) == field.getNumber(); + } + return !get(builder).equals(field.getDefaultValue()); + } + return (Boolean) invokeOrDie(hasMethodBuilder, builder); + } + + @Override + public int getRepeatedCount(final GeneratedMessageInternal message) { + throw new UnsupportedOperationException( + "getRepeatedFieldSize() called on a singular field."); + } + + @Override + public int getRepeatedCount(GeneratedMessageInternal.Builder builder) { + throw new UnsupportedOperationException( + "getRepeatedFieldSize() called on a singular field."); + } + + @Override + public void clear(final Builder builder) { + invokeOrDie(clearMethod, builder); + } + + @Override + public Message.Builder newBuilder() { + throw new UnsupportedOperationException( + "newBuilderForField() called on a non-Message type."); + } + + @Override + public Message.Builder getBuilder(GeneratedMessageInternal.Builder builder) { + throw new UnsupportedOperationException("getFieldBuilder() called on a non-Message type."); + } + + @Override + public Message.Builder getRepeatedBuilder(GeneratedMessageInternal.Builder builder, int index) { + throw new UnsupportedOperationException( + "getRepeatedFieldBuilder() called on a non-Message type."); + } + } + + private static class RepeatedFieldAccessor implements FieldAccessor { + protected final Class type; + protected final Method getMethod; + protected final Method getMethodBuilder; + protected final Method getRepeatedMethod; + protected final Method getRepeatedMethodBuilder; + protected final Method setRepeatedMethod; + protected final Method addRepeatedMethod; + protected final Method getCountMethod; + protected final Method getCountMethodBuilder; + protected final Method clearMethod; + + RepeatedFieldAccessor( + final FieldDescriptor descriptor, + final String camelCaseName, + final Class messageClass, + final Class builderClass) { + getMethod = getMethodOrDie(messageClass, "get" + camelCaseName + "List"); + getMethodBuilder = getMethodOrDie(builderClass, "get" + camelCaseName + "List"); + getRepeatedMethod = getMethodOrDie(messageClass, "get" + camelCaseName, Integer.TYPE); + getRepeatedMethodBuilder = + getMethodOrDie(builderClass, "get" + camelCaseName, Integer.TYPE); + type = getRepeatedMethod.getReturnType(); + setRepeatedMethod = getMethodOrDie(builderClass, "set" + camelCaseName, Integer.TYPE, type); + addRepeatedMethod = getMethodOrDie(builderClass, "add" + camelCaseName, type); + getCountMethod = getMethodOrDie(messageClass, "get" + camelCaseName + "Count"); + getCountMethodBuilder = getMethodOrDie(builderClass, "get" + camelCaseName + "Count"); + + clearMethod = getMethodOrDie(builderClass, "clear" + camelCaseName); + } + + @Override + public Object get(final GeneratedMessageInternal message) { + return invokeOrDie(getMethod, message); + } + + @Override + public Object get(GeneratedMessageInternal.Builder builder) { + return invokeOrDie(getMethodBuilder, builder); + } + + @Override + public Object getRaw(final GeneratedMessageInternal message) { + return get(message); + } + + @Override + public Object getRaw(GeneratedMessageInternal.Builder builder) { + return get(builder); + } + + @Override + public void set(final Builder builder, final Object value) { + // Add all the elements individually. This serves two purposes: + // 1) Verifies that each element has the correct type. + // 2) Insures that the caller cannot modify the list later on and + // have the modifications be reflected in the message. + clear(builder); + for (final Object element : (List) value) { + addRepeated(builder, element); + } + } + + @Override + public Object getRepeated(final GeneratedMessageInternal message, final int index) { + return invokeOrDie(getRepeatedMethod, message, index); + } + + @Override + public Object getRepeated(GeneratedMessageInternal.Builder builder, int index) { + return invokeOrDie(getRepeatedMethodBuilder, builder, index); + } + + @Override + public Object getRepeatedRaw(GeneratedMessageInternal message, int index) { + return getRepeated(message, index); + } + + @Override + public Object getRepeatedRaw(GeneratedMessageInternal.Builder builder, int index) { + return getRepeated(builder, index); + } + + @Override + public void setRepeated(final Builder builder, final int index, final Object value) { + invokeOrDie(setRepeatedMethod, builder, index, value); + } + + @Override + public void addRepeated(final Builder builder, final Object value) { + invokeOrDie(addRepeatedMethod, builder, value); + } + + @Override + public boolean has(final GeneratedMessageInternal message) { + throw new UnsupportedOperationException("hasField() called on a repeated field."); + } + + @Override + public boolean has(GeneratedMessageInternal.Builder builder) { + throw new UnsupportedOperationException("hasField() called on a repeated field."); + } + + @Override + public int getRepeatedCount(final GeneratedMessageInternal message) { + return (Integer) invokeOrDie(getCountMethod, message); + } + + @Override + public int getRepeatedCount(GeneratedMessageInternal.Builder builder) { + return (Integer) invokeOrDie(getCountMethodBuilder, builder); + } + + @Override + public void clear(final Builder builder) { + invokeOrDie(clearMethod, builder); + } + + @Override + public Message.Builder newBuilder() { + throw new UnsupportedOperationException( + "newBuilderForField() called on a non-Message type."); + } + + @Override + public Message.Builder getBuilder(GeneratedMessageInternal.Builder builder) { + throw new UnsupportedOperationException("getFieldBuilder() called on a non-Message type."); + } + + @Override + public Message.Builder getRepeatedBuilder(GeneratedMessageInternal.Builder builder, int index) { + throw new UnsupportedOperationException( + "getRepeatedFieldBuilder() called on a non-Message type."); + } + } + + private static class MapFieldAccessor implements FieldAccessor { + MapFieldAccessor( + final FieldDescriptor descriptor, + final String camelCaseName, + final Class messageClass, + final Class builderClass) { + field = descriptor; + Method getDefaultInstanceMethod = getMethodOrDie(messageClass, "getDefaultInstance"); + MapField defaultMapField = + getMapField((GeneratedMessageInternal) invokeOrDie(getDefaultInstanceMethod, null)); + mapEntryMessageDefaultInstance = defaultMapField.getMapEntryMessageDefaultInstance(); + } + + private final FieldDescriptor field; + private final Message mapEntryMessageDefaultInstance; + + private MapField getMapField(GeneratedMessageInternal message) { + return (MapField) message.internalGetMapField(field.getNumber()); + } + + private MapField getMapField(GeneratedMessageInternal.Builder builder) { + return (MapField) builder.internalGetMapField(field.getNumber()); + } + + private MapField getMutableMapField(GeneratedMessageInternal.Builder builder) { + return (MapField) builder.internalGetMutableMapField(field.getNumber()); + } + + @Override + @SuppressWarnings("unchecked") + public Object get(GeneratedMessageInternal message) { + List result = new ArrayList(); + for (int i = 0; i < getRepeatedCount(message); i++) { + result.add(getRepeated(message, i)); + } + return Collections.unmodifiableList(result); + } + + @Override + @SuppressWarnings("unchecked") + public Object get(Builder builder) { + List result = new ArrayList(); + for (int i = 0; i < getRepeatedCount(builder); i++) { + result.add(getRepeated(builder, i)); + } + return Collections.unmodifiableList(result); + } + + @Override + public Object getRaw(GeneratedMessageInternal message) { + return get(message); + } + + @Override + public Object getRaw(GeneratedMessageInternal.Builder builder) { + return get(builder); + } + + @Override + public void set(Builder builder, Object value) { + clear(builder); + for (Object entry : (List) value) { + addRepeated(builder, entry); + } + } + + @Override + public Object getRepeated(GeneratedMessageInternal message, int index) { + return getMapField(message).getList().get(index); + } + + @Override + public Object getRepeated(Builder builder, int index) { + return getMapField(builder).getList().get(index); + } + + @Override + public Object getRepeatedRaw(GeneratedMessageInternal message, int index) { + return getRepeated(message, index); + } + + @Override + public Object getRepeatedRaw(Builder builder, int index) { + return getRepeated(builder, index); + } + + @Override + public void setRepeated(Builder builder, int index, Object value) { + getMutableMapField(builder).getMutableList().set(index, (Message) value); + } + + @Override + public void addRepeated(Builder builder, Object value) { + getMutableMapField(builder).getMutableList().add((Message) value); + } + + @Override + public boolean has(GeneratedMessageInternal message) { + throw new UnsupportedOperationException("hasField() is not supported for repeated fields."); + } + + @Override + public boolean has(Builder builder) { + throw new UnsupportedOperationException("hasField() is not supported for repeated fields."); + } + + @Override + public int getRepeatedCount(GeneratedMessageInternal message) { + return getMapField(message).getList().size(); + } + + @Override + public int getRepeatedCount(Builder builder) { + return getMapField(builder).getList().size(); + } + + @Override + public void clear(Builder builder) { + getMutableMapField(builder).getMutableList().clear(); + } + + @Override + public Message.Builder newBuilder() { + return mapEntryMessageDefaultInstance.newBuilderForType(); + } + + @Override + public Message.Builder getBuilder(Builder builder) { + throw new UnsupportedOperationException("Nested builder not supported for map fields."); + } + + @Override + public Message.Builder getRepeatedBuilder(Builder builder, int index) { + throw new UnsupportedOperationException("Nested builder not supported for map fields."); + } + } + + // --------------------------------------------------------------- + + private static final class SingularEnumFieldAccessor extends SingularFieldAccessor { + SingularEnumFieldAccessor( + final FieldDescriptor descriptor, + final String camelCaseName, + final Class messageClass, + final Class builderClass, + final String containingOneofCamelCaseName) { + super(descriptor, camelCaseName, messageClass, builderClass, containingOneofCamelCaseName); + + enumDescriptor = descriptor.getEnumType(); + + valueOfMethod = getMethodOrDie(type, "valueOf", EnumValueDescriptor.class); + getValueDescriptorMethod = getMethodOrDie(type, "getValueDescriptor"); + + supportUnknownEnumValue = !descriptor.legacyEnumFieldTreatedAsClosed(); + if (supportUnknownEnumValue) { + getValueMethod = getMethodOrDie(messageClass, "get" + camelCaseName + "Value"); + getValueMethodBuilder = getMethodOrDie(builderClass, "get" + camelCaseName + "Value"); + setValueMethod = getMethodOrDie(builderClass, "set" + camelCaseName + "Value", int.class); + } + } + + private EnumDescriptor enumDescriptor; + + private Method valueOfMethod; + private Method getValueDescriptorMethod; + + private boolean supportUnknownEnumValue; + private Method getValueMethod; + private Method getValueMethodBuilder; + private Method setValueMethod; + + @Override + public Object get(final GeneratedMessageInternal message) { + if (supportUnknownEnumValue) { + int value = (Integer) invokeOrDie(getValueMethod, message); + return enumDescriptor.findValueByNumberCreatingIfUnknown(value); + } + return invokeOrDie(getValueDescriptorMethod, super.get(message)); + } + + @Override + public Object get(final GeneratedMessageInternal.Builder builder) { + if (supportUnknownEnumValue) { + int value = (Integer) invokeOrDie(getValueMethodBuilder, builder); + return enumDescriptor.findValueByNumberCreatingIfUnknown(value); + } + return invokeOrDie(getValueDescriptorMethod, super.get(builder)); + } + + @Override + public void set(final Builder builder, final Object value) { + if (supportUnknownEnumValue) { + invokeOrDie(setValueMethod, builder, ((EnumValueDescriptor) value).getNumber()); + return; + } + super.set(builder, invokeOrDie(valueOfMethod, null, value)); + } + } + + private static final class RepeatedEnumFieldAccessor extends RepeatedFieldAccessor { + RepeatedEnumFieldAccessor( + final FieldDescriptor descriptor, + final String camelCaseName, + final Class messageClass, + final Class builderClass) { + super(descriptor, camelCaseName, messageClass, builderClass); + + enumDescriptor = descriptor.getEnumType(); + + valueOfMethod = getMethodOrDie(type, "valueOf", EnumValueDescriptor.class); + getValueDescriptorMethod = getMethodOrDie(type, "getValueDescriptor"); + + supportUnknownEnumValue = !descriptor.legacyEnumFieldTreatedAsClosed(); + if (supportUnknownEnumValue) { + getRepeatedValueMethod = + getMethodOrDie(messageClass, "get" + camelCaseName + "Value", int.class); + getRepeatedValueMethodBuilder = + getMethodOrDie(builderClass, "get" + camelCaseName + "Value", int.class); + setRepeatedValueMethod = + getMethodOrDie(builderClass, "set" + camelCaseName + "Value", int.class, int.class); + addRepeatedValueMethod = + getMethodOrDie(builderClass, "add" + camelCaseName + "Value", int.class); + } + } + + private EnumDescriptor enumDescriptor; + + private final Method valueOfMethod; + private final Method getValueDescriptorMethod; + + private boolean supportUnknownEnumValue; + private Method getRepeatedValueMethod; + private Method getRepeatedValueMethodBuilder; + private Method setRepeatedValueMethod; + private Method addRepeatedValueMethod; + + @Override + @SuppressWarnings("unchecked") + public Object get(final GeneratedMessageInternal message) { + final List newList = new ArrayList(); + final int size = getRepeatedCount(message); + for (int i = 0; i < size; i++) { + newList.add(getRepeated(message, i)); + } + return Collections.unmodifiableList(newList); + } + + @Override + @SuppressWarnings("unchecked") + public Object get(final GeneratedMessageInternal.Builder builder) { + final List newList = new ArrayList(); + final int size = getRepeatedCount(builder); + for (int i = 0; i < size; i++) { + newList.add(getRepeated(builder, i)); + } + return Collections.unmodifiableList(newList); + } + + @Override + public Object getRepeated(final GeneratedMessageInternal message, final int index) { + if (supportUnknownEnumValue) { + int value = (Integer) invokeOrDie(getRepeatedValueMethod, message, index); + return enumDescriptor.findValueByNumberCreatingIfUnknown(value); + } + return invokeOrDie(getValueDescriptorMethod, super.getRepeated(message, index)); + } + + @Override + public Object getRepeated(final GeneratedMessageInternal.Builder builder, final int index) { + if (supportUnknownEnumValue) { + int value = (Integer) invokeOrDie(getRepeatedValueMethodBuilder, builder, index); + return enumDescriptor.findValueByNumberCreatingIfUnknown(value); + } + return invokeOrDie(getValueDescriptorMethod, super.getRepeated(builder, index)); + } + + @Override + public void setRepeated(final Builder builder, final int index, final Object value) { + if (supportUnknownEnumValue) { + invokeOrDie( + setRepeatedValueMethod, builder, index, ((EnumValueDescriptor) value).getNumber()); + return; + } + super.setRepeated(builder, index, invokeOrDie(valueOfMethod, null, value)); + } + + @Override + public void addRepeated(final Builder builder, final Object value) { + if (supportUnknownEnumValue) { + invokeOrDie(addRepeatedValueMethod, builder, ((EnumValueDescriptor) value).getNumber()); + return; + } + super.addRepeated(builder, invokeOrDie(valueOfMethod, null, value)); + } + } + + // --------------------------------------------------------------- + + /** + * Field accessor for string fields. + * + *

This class makes getFooBytes() and setFooBytes() available for reflection API so that + * reflection based serialize/parse functions can access the raw bytes of the field to preserve + * non-UTF8 bytes in the string. + * + *

This ensures the serialize/parse round-trip safety, which is important for servers which + * forward messages. + */ + private static final class SingularStringFieldAccessor extends SingularFieldAccessor { + SingularStringFieldAccessor( + final FieldDescriptor descriptor, + final String camelCaseName, + final Class messageClass, + final Class builderClass, + final String containingOneofCamelCaseName) { + super(descriptor, camelCaseName, messageClass, builderClass, containingOneofCamelCaseName); + getBytesMethod = getMethodOrDie(messageClass, "get" + camelCaseName + "Bytes"); + getBytesMethodBuilder = getMethodOrDie(builderClass, "get" + camelCaseName + "Bytes"); + setBytesMethodBuilder = + getMethodOrDie(builderClass, "set" + camelCaseName + "Bytes", ByteString.class); + } + + private final Method getBytesMethod; + private final Method getBytesMethodBuilder; + private final Method setBytesMethodBuilder; + + @Override + public Object getRaw(final GeneratedMessageInternal message) { + return invokeOrDie(getBytesMethod, message); + } + + @Override + public Object getRaw(GeneratedMessageInternal.Builder builder) { + return invokeOrDie(getBytesMethodBuilder, builder); + } + + @Override + public void set(GeneratedMessageInternal.Builder builder, Object value) { + if (value instanceof ByteString) { + invokeOrDie(setBytesMethodBuilder, builder, value); + } else { + super.set(builder, value); + } + } + } + + // --------------------------------------------------------------- + + private static final class SingularMessageFieldAccessor extends SingularFieldAccessor { + SingularMessageFieldAccessor( + final FieldDescriptor descriptor, + final String camelCaseName, + final Class messageClass, + final Class builderClass, + final String containingOneofCamelCaseName) { + super(descriptor, camelCaseName, messageClass, builderClass, containingOneofCamelCaseName); + + newBuilderMethod = getMethodOrDie(type, "newBuilder"); + getBuilderMethodBuilder = getMethodOrDie(builderClass, "get" + camelCaseName + "Builder"); + } + + private final Method newBuilderMethod; + private final Method getBuilderMethodBuilder; + + private Object coerceType(final Object value) { + if (type.isInstance(value)) { + return value; + } else { + // The value is not the exact right message type. However, if it + // is an alternative implementation of the same type -- e.g. a + // DynamicMessage -- we should accept it. In this case we can make + // a copy of the message. + return ((Message.Builder) invokeOrDie(newBuilderMethod, null)) + .mergeFrom((Message) value) + .buildPartial(); + } + } + + @Override + public void set(final Builder builder, final Object value) { + super.set(builder, coerceType(value)); + } + + @Override + public Message.Builder newBuilder() { + return (Message.Builder) invokeOrDie(newBuilderMethod, null); + } + + @Override + public Message.Builder getBuilder(GeneratedMessageInternal.Builder builder) { + return (Message.Builder) invokeOrDie(getBuilderMethodBuilder, builder); + } + } + + private static final class RepeatedMessageFieldAccessor extends RepeatedFieldAccessor { + RepeatedMessageFieldAccessor( + final FieldDescriptor descriptor, + final String camelCaseName, + final Class messageClass, + final Class builderClass) { + super(descriptor, camelCaseName, messageClass, builderClass); + + newBuilderMethod = getMethodOrDie(type, "newBuilder"); + getBuilderMethodBuilder = + getMethodOrDie(builderClass, "get" + camelCaseName + "Builder", Integer.TYPE); + } + + private final Method newBuilderMethod; + private final Method getBuilderMethodBuilder; + + private Object coerceType(final Object value) { + if (type.isInstance(value)) { + return value; + } else { + // The value is not the exact right message type. However, if it + // is an alternative implementation of the same type -- e.g. a + // DynamicMessage -- we should accept it. In this case we can make + // a copy of the message. + return ((Message.Builder) invokeOrDie(newBuilderMethod, null)) + .mergeFrom((Message) value) + .build(); + } + } + + @Override + public void setRepeated(final Builder builder, final int index, final Object value) { + super.setRepeated(builder, index, coerceType(value)); + } + + @Override + public void addRepeated(final Builder builder, final Object value) { + super.addRepeated(builder, coerceType(value)); + } + + @Override + public Message.Builder newBuilder() { + return (Message.Builder) invokeOrDie(newBuilderMethod, null); + } + + @Override + public Message.Builder getRepeatedBuilder( + final GeneratedMessageInternal.Builder builder, final int index) { + return (Message.Builder) invokeOrDie(getBuilderMethodBuilder, builder, index); + } + } + } + + /** + * Replaces this object in the output stream with a serialized form. Part of Java's serialization + * magic. Generated sub-classes must override this method by calling {@code return + * super.writeReplace();} + * + * @return a SerializedForm of this message + */ + protected Object writeReplace() throws ObjectStreamException { + return new SerializedForm(this); + } + + /** + * Checks that the {@link Extension} is non-Lite and returns it as a {@link GeneratedExtension}. + */ + private static , T> + Extension checkNotLite(ExtensionLite extension) { + if (extension.isLite()) { + throw new IllegalArgumentException("Expected non-lite extension."); + } + + return (Extension) extension; + } + + protected static int computeStringSize(final int fieldNumber, final Object value) { + if (value instanceof String) { + return CodedOutputStream.computeStringSize(fieldNumber, (String) value); + } else { + return CodedOutputStream.computeBytesSize(fieldNumber, (ByteString) value); + } + } + + protected static int computeStringSizeNoTag(final Object value) { + if (value instanceof String) { + return CodedOutputStream.computeStringSizeNoTag((String) value); + } else { + return CodedOutputStream.computeBytesSizeNoTag((ByteString) value); + } + } + + protected static void writeString( + CodedOutputStream output, final int fieldNumber, final Object value) throws IOException { + if (value instanceof String) { + output.writeString(fieldNumber, (String) value); + } else { + output.writeBytes(fieldNumber, (ByteString) value); + } + } + + protected static void writeStringNoTag(CodedOutputStream output, final Object value) + throws IOException { + if (value instanceof String) { + output.writeStringNoTag((String) value); + } else { + output.writeBytesNoTag((ByteString) value); + } + } +} diff --git a/protobuf-api/src/main/java/com/google/protobuf/GeneratedMessageV3Internal.java b/protobuf-api/src/main/java/com/google/protobuf/GeneratedMessageV3Internal.java new file mode 100644 index 0000000..379e837 --- /dev/null +++ b/protobuf-api/src/main/java/com/google/protobuf/GeneratedMessageV3Internal.java @@ -0,0 +1,3414 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd + +package com.google.protobuf; + +import com.google.protobuf.Descriptors.Descriptor; +import com.google.protobuf.Descriptors.EnumDescriptor; +import com.google.protobuf.Descriptors.EnumValueDescriptor; +import com.google.protobuf.Descriptors.FieldDescriptor; +import com.google.protobuf.Descriptors.FileDescriptor; +import com.google.protobuf.Descriptors.OneofDescriptor; +import com.google.protobuf.GeneratedMessageInternal.GeneratedExtension; +import com.google.protobuf.Internal.BooleanList; +import com.google.protobuf.Internal.DoubleList; +import com.google.protobuf.Internal.FloatList; +import com.google.protobuf.Internal.IntList; +import com.google.protobuf.Internal.LongList; +import com.google.protobuf.Internal.ProtobufList; + +import java.io.IOException; +import java.io.InputStream; +import java.io.ObjectStreamException; +import java.io.Serializable; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + +/** + * All generated protocol message classes extend this class. This class implements most of the + * Message and Builder interfaces using Java reflection. Users can ignore this class and pretend + * that generated messages implement the Message interface directly. + * + * @author kenton@google.com Kenton Varda + */ +abstract class GeneratedMessageV3Internal extends AbstractMessageInternal implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * For testing. Allows a test to disable the optimization that avoids using field builders for + * nested messages until they are requested. By disabling this optimization, existing tests can be + * reused to test the field builders. + */ + protected static boolean alwaysUseFieldBuilders = false; + + /** + * For use by generated code only. + * + *

TODO: mark this private and final (breaking change) + */ + protected UnknownFieldSet unknownFields; + + protected GeneratedMessageV3Internal() { + unknownFields = UnknownFieldSet.getDefaultInstance(); + } + + protected GeneratedMessageV3Internal(Builder builder) { + unknownFields = builder.getUnknownFields(); + } + + /** TODO: Remove this unnecessary intermediate implementation of this method. */ + @Override + public Parser getParserForType() { + throw new UnsupportedOperationException("This is supposed to be overridden by subclasses."); + } + + /** + * TODO: Stop using SingleFieldBuilder and remove this setting + * + * @see #setAlwaysUseFieldBuildersForTesting(boolean) + */ + static void enableAlwaysUseFieldBuildersForTesting() { + setAlwaysUseFieldBuildersForTesting(true); + } + + /** + * For testing. Allows a test to disable/re-enable the optimization that avoids using field + * builders for nested messages until they are requested. By disabling this optimization, existing + * tests can be reused to test the field builders. See {@link RepeatedFieldBuilder} and {@link + * SingleFieldBuilder}. + * + *

TODO: Stop using SingleFieldBuilder and remove this setting + */ + static void setAlwaysUseFieldBuildersForTesting(boolean useBuilders) { + alwaysUseFieldBuilders = useBuilders; + } + + /** + * Get the FieldAccessorTable for this type. We can't have the message class pass this in to the + * constructor because of bootstrapping trouble with DescriptorProtos. + */ + protected abstract FieldAccessorTable internalGetFieldAccessorTable(); + + @Override + public Descriptor getDescriptorForType() { + return internalGetFieldAccessorTable().descriptor; + } + + /** + * TODO: This method should be removed. It enables parsing directly into an + * "immutable" message. Have to leave it for now to support old gencode. + * + * @deprecated use newBuilder().mergeFrom() instead + */ + @Deprecated + protected void mergeFromAndMakeImmutableInternal( + CodedInputStream input, ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + Schema schema = Protobuf.getInstance().schemaFor(this); + try { + schema.mergeFrom(this, CodedInputStreamReader.forCodedInput(input), extensionRegistry); + } catch (InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(this); + } catch (IOException e) { + throw new InvalidProtocolBufferException(e).setUnfinishedMessage(this); + } + schema.makeImmutable(this); + } + + /** + * Internal helper to return a modifiable map containing all the fields. The returned Map is + * modifiable so that the caller can add additional extension fields to implement {@link + * #getAllFields()}. + * + * @param getBytesForString whether to generate ByteString for string fields + */ + private Map getAllFieldsMutable(boolean getBytesForString) { + final TreeMap result = new TreeMap<>(); + final Descriptor descriptor = internalGetFieldAccessorTable().descriptor; + final List fields = descriptor.getFields(); + + for (int i = 0; i < fields.size(); i++) { + FieldDescriptor field = fields.get(i); + final OneofDescriptor oneofDescriptor = field.getContainingOneof(); + + /* + * If the field is part of a Oneof, then at maximum one field in the Oneof is set + * and it is not repeated. There is no need to iterate through the others. + */ + if (oneofDescriptor != null) { + // Skip other fields in the Oneof we know are not set + i += oneofDescriptor.getFieldCount() - 1; + if (!hasOneof(oneofDescriptor)) { + // If no field is set in the Oneof, skip all the fields in the Oneof + continue; + } + // Get the pointer to the only field which is set in the Oneof + field = getOneofFieldDescriptor(oneofDescriptor); + } else { + // If we are not in a Oneof, we need to check if the field is set and if it is repeated + if (field.isRepeated()) { + final List value = (List) getField(field); + if (!value.isEmpty()) { + result.put(field, value); + } + continue; + } + if (!hasField(field)) { + continue; + } + } + // Add the field to the map + if (getBytesForString && field.getJavaType() == FieldDescriptor.JavaType.STRING) { + result.put(field, getFieldRaw(field)); + } else { + result.put(field, getField(field)); + } + } + return result; + } + + // TODO: compute this at {@code build()} time in the Builder class. + @Override + public boolean isInitialized() { + for (final FieldDescriptor field : getDescriptorForType().getFields()) { + // Check that all required fields are present. + if (field.isRequired()) { + if (!hasField(field)) { + return false; + } + } + // Check that embedded messages are initialized. + if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { + if (field.isRepeated()) { + @SuppressWarnings("unchecked") + final List messageList = (List) getField(field); + for (final Message element : messageList) { + if (!element.isInitialized()) { + return false; + } + } + } else { + if (hasField(field) && !((Message) getField(field)).isInitialized()) { + return false; + } + } + } + } + + return true; + } + + @Override + public Map getAllFields() { + return Collections.unmodifiableMap(getAllFieldsMutable(/* getBytesForString= */ false)); + } + + /** + * Returns a collection of all the fields in this message which are set and their corresponding + * values. A singular ("required" or "optional") field is set iff hasField() returns true for that + * field. A "repeated" field is set iff getRepeatedFieldCount() is greater than zero. The values + * are exactly what would be returned by calling {@link #getFieldRaw(FieldDescriptor)} + * for each field. The map is guaranteed to be a sorted map, so iterating over it will return + * fields in order by field number. + */ + Map getAllFieldsRaw() { + return Collections.unmodifiableMap(getAllFieldsMutable(/* getBytesForString= */ true)); + } + + @Override + public boolean hasOneof(final OneofDescriptor oneof) { + return internalGetFieldAccessorTable().getOneof(oneof).has(this); + } + + @Override + public FieldDescriptor getOneofFieldDescriptor(final OneofDescriptor oneof) { + return internalGetFieldAccessorTable().getOneof(oneof).get(this); + } + + @Override + public boolean hasField(final FieldDescriptor field) { + return internalGetFieldAccessorTable().getField(field).has(this); + } + + @Override + public Object getField(final FieldDescriptor field) { + return internalGetFieldAccessorTable().getField(field).get(this); + } + + /** + * Obtains the value of the given field, or the default value if it is not set. For primitive + * fields, the boxed primitive value is returned. For enum fields, the EnumValueDescriptor for the + * value is returned. For embedded message fields, the sub-message is returned. For repeated + * fields, a java.util.List is returned. For present string fields, a ByteString is returned + * representing the bytes that the field contains. + */ + Object getFieldRaw(final FieldDescriptor field) { + return internalGetFieldAccessorTable().getField(field).getRaw(this); + } + + @Override + public int getRepeatedFieldCount(final FieldDescriptor field) { + return internalGetFieldAccessorTable().getField(field).getRepeatedCount(this); + } + + @Override + public Object getRepeatedField(final FieldDescriptor field, final int index) { + return internalGetFieldAccessorTable().getField(field).getRepeated(this, index); + } + + // TODO: This method should be final. + @Override + public UnknownFieldSet getUnknownFields() { + return unknownFields; + } + + // TODO: This should go away when Schema classes cannot modify immutable + // GeneratedMessageV3Internal objects anymore. + void setUnknownFields(UnknownFieldSet unknownFields) { + this.unknownFields = unknownFields; + } + + /** + * Called by subclasses to parse an unknown field. + * + *

TODO remove this method + * + * @return {@code true} unless the tag is an end-group tag. + */ + protected boolean parseUnknownField( + CodedInputStream input, + UnknownFieldSet.Builder unknownFields, + ExtensionRegistryLite extensionRegistry, + int tag) + throws IOException { + if (input.shouldDiscardUnknownFields()) { + return input.skipField(tag); + } + return unknownFields.mergeFieldFrom(tag, input); + } + + /** + * Delegates to parseUnknownField. This method is obsolete, but we must retain it for + * compatibility with older generated code. + * + *

TODO remove this method + */ + protected boolean parseUnknownFieldProto3( + CodedInputStream input, + UnknownFieldSet.Builder unknownFields, + ExtensionRegistryLite extensionRegistry, + int tag) + throws IOException { + return parseUnknownField(input, unknownFields, extensionRegistry, tag); + } + + /** Used by generated code. */ + @SuppressWarnings("ProtoParseWithRegistry") + protected static M parseWithIOException(Parser parser, InputStream input) + throws IOException { + try { + return parser.parseFrom(input); + } catch (InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } + } + + /** Used by generated code. */ + protected static M parseWithIOException( + Parser parser, InputStream input, ExtensionRegistryLite extensions) throws IOException { + try { + return parser.parseFrom(input, extensions); + } catch (InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } + } + + /** Used by generated code. */ + @SuppressWarnings("ProtoParseWithRegistry") + protected static M parseWithIOException( + Parser parser, CodedInputStream input) throws IOException { + try { + return parser.parseFrom(input); + } catch (InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } + } + + /** Used by generated code. */ + protected static M parseWithIOException( + Parser parser, CodedInputStream input, ExtensionRegistryLite extensions) + throws IOException { + try { + return parser.parseFrom(input, extensions); + } catch (InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } + } + + /** Used by generated code. */ + @SuppressWarnings("ProtoParseWithRegistry") + protected static M parseDelimitedWithIOException( + Parser parser, InputStream input) throws IOException { + try { + return parser.parseDelimitedFrom(input); + } catch (InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } + } + + /** Used by generated code. */ + protected static M parseDelimitedWithIOException( + Parser parser, InputStream input, ExtensionRegistryLite extensions) throws IOException { + try { + return parser.parseDelimitedFrom(input, extensions); + } catch (InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } + } + + protected static boolean canUseUnsafe() { + return UnsafeUtil.hasUnsafeArrayOperations() && UnsafeUtil.hasUnsafeByteBufferOperations(); + } + + protected static IntList emptyIntList() { + return IntArrayList.emptyList(); + } + + // TODO: Unused. Remove. + protected static IntList newIntList() { + return new IntArrayList(); + } + + // TODO: Redundant with makeMutableCopy(). Remove. + protected static IntList mutableCopy(IntList list) { + return makeMutableCopy(list); + } + + // TODO: Redundant with makeMutableCopy(). Remove. + protected static LongList mutableCopy(LongList list) { + return makeMutableCopy(list); + } + + // TODO: Redundant with makeMutableCopy(). Remove. + protected static FloatList mutableCopy(FloatList list) { + return makeMutableCopy(list); + } + + // TODO: Redundant with makeMutableCopy(). Remove. + protected static DoubleList mutableCopy(DoubleList list) { + return makeMutableCopy(list); + } + + // TODO: Redundant with makeMutableCopy(). Remove. + protected static BooleanList mutableCopy(BooleanList list) { + return makeMutableCopy(list); + } + + protected static LongList emptyLongList() { + return LongArrayList.emptyList(); + } + + // TODO: Unused. Remove. + protected static LongList newLongList() { + return new LongArrayList(); + } + + protected static FloatList emptyFloatList() { + return FloatArrayList.emptyList(); + } + + // TODO: Unused. Remove. + protected static FloatList newFloatList() { + return new FloatArrayList(); + } + + protected static DoubleList emptyDoubleList() { + return DoubleArrayList.emptyList(); + } + + // TODO: Unused. Remove. + protected static DoubleList newDoubleList() { + return new DoubleArrayList(); + } + + protected static BooleanList emptyBooleanList() { + return BooleanArrayList.emptyList(); + } + + // TODO: Unused. Remove. + protected static BooleanList newBooleanList() { + return new BooleanArrayList(); + } + + protected static > ListT makeMutableCopy(ListT list) { + return makeMutableCopy(list, 0); + } + + @SuppressWarnings("unchecked") // Guaranteed by proto runtime. + protected static > ListT makeMutableCopy( + ListT list, int minCapacity) { + int size = list.size(); + if (minCapacity <= size) { + minCapacity = size * 2; + } + if (minCapacity <= 0) { + minCapacity = AbstractProtobufList.DEFAULT_CAPACITY; + } + + return (ListT) list.mutableCopyWithCapacity(minCapacity); + } + + @SuppressWarnings("unchecked") // The empty list can be safely cast + protected static ProtobufList emptyList(Class elementType) { + return (ProtobufList) ProtobufArrayList.emptyList(); + } + + @Override + public void writeTo(final CodedOutputStream output) throws IOException { + MessageReflection.writeMessageTo(this, getAllFieldsRaw(), output, false); + } + + @Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) { + return size; + } + + memoizedSize = MessageReflection.getSerializedSize( + this, getAllFieldsRaw()); + return memoizedSize; + } + + /** + * This class is used to make a generated protected method inaccessible from user's code (e.g., + * the {@link #newInstance} method below). When this class is used as a parameter's type in a + * generated protected method, the method is visible to user's code in the same package, but since + * the constructor of this class is private to protobuf runtime, user's code can't obtain an + * instance of this class and as such can't actually make a method call on the protected method. + */ + protected static final class UnusedPrivateParameter { + static final UnusedPrivateParameter INSTANCE = new UnusedPrivateParameter(); + + private UnusedPrivateParameter() {} + } + + /** Creates a new instance of this message type. Overridden in the generated code. */ + @SuppressWarnings({"unused"}) + protected Object newInstance(UnusedPrivateParameter unused) { + throw new UnsupportedOperationException("This method must be overridden by the subclass."); + } + + /** + * Used by parsing constructors in generated classes. + * + *

TODO: remove unused method (extensions should be immutable after build) + */ + protected void makeExtensionsImmutable() { + // Noop for messages without extensions. + } + + /** + * TODO: remove this after b/29368482 is fixed. We need to move this interface to + * AbstractMessage in order to versioning GeneratedMessageV3Internal but this move breaks binary + * compatibility for AppEngine. After AppEngine is fixed we can exclude this from google3. + * + *

TODO: Remove at breaking change since b/29368482 was fixed in 2020 + */ + protected interface BuilderParent extends AbstractMessageInternal.BuilderParent {} + + /** TODO: remove this together with GeneratedMessageV3Internal.BuilderParent. */ + protected abstract Message.Builder newBuilderForType(BuilderParent parent); + + /** TODO: generated class should implement this directly */ + @Override + protected Message.Builder newBuilderForType(final AbstractMessageInternal.BuilderParent parent) { + return newBuilderForType( + new BuilderParent() { + @Override + public void markDirty() { + parent.markDirty(); + } + }); + } + + /** Builder class for {@link GeneratedMessageV3Internal}. */ + @SuppressWarnings("unchecked") + public abstract static class Builder> + extends AbstractMessageInternal.Builder { + + private BuilderParent builderParent; + + private BuilderParentImpl meAsParent; + + // Indicates that we've built a message and so we are now obligated + // to dispatch dirty invalidations. See GeneratedMessageV3Internal.BuilderListener. + private boolean isClean; + + /** + * This field holds either an {@link UnknownFieldSet} or {@link UnknownFieldSet.Builder}. + * + *

We use an object because it should only be one or the other of those things at a time and + * Object is the only common base. This also saves space. + * + *

Conversions are lazy: if {@link #setUnknownFields} is called, this will contain {@link + * UnknownFieldSet}. If unknown fields are merged into this builder, the current {@link + * UnknownFieldSet} will be converted to a {@link UnknownFieldSet.Builder} and left that way + * until either {@link #setUnknownFields} or {@link #buildPartial} or {@link #build} is called. + */ + private Object unknownFieldsOrBuilder = UnknownFieldSet.getDefaultInstance(); + + protected Builder() { + this(null); + } + + protected Builder(BuilderParent builderParent) { + this.builderParent = builderParent; + } + + @Override + void dispose() { + builderParent = null; + } + + /** Called by the subclass when a message is built. */ + protected void onBuilt() { + if (builderParent != null) { + markClean(); + } + } + + /** + * Called by the subclass or a builder to notify us that a message was built and may be cached + * and therefore invalidations are needed. + */ + @Override + protected void markClean() { + this.isClean = true; + } + + /** + * Gets whether invalidations are needed + * + * @return whether invalidations are needed + */ + protected boolean isClean() { + return isClean; + } + + @Override + public BuilderT clone() { + BuilderT builder = (BuilderT) getDefaultInstanceForType().newBuilderForType(); + builder.mergeFrom(buildPartial()); + return builder; + } + + /** + * Called by the initialization and clear code paths to allow subclasses to reset any of their + * builtin fields back to the initial values. + */ + @Override + public BuilderT clear() { + unknownFieldsOrBuilder = UnknownFieldSet.getDefaultInstance(); + onChanged(); + return (BuilderT) this; + } + + /** + * Get the FieldAccessorTable for this type. We can't have the message class pass this in to the + * constructor because of bootstrapping trouble with DescriptorProtos. + */ + protected abstract FieldAccessorTable internalGetFieldAccessorTable(); + + @Override + public Descriptor getDescriptorForType() { + return internalGetFieldAccessorTable().descriptor; + } + + @Override + public Map getAllFields() { + return Collections.unmodifiableMap(getAllFieldsMutable()); + } + + /** Internal helper which returns a mutable map. */ + private Map getAllFieldsMutable() { + final TreeMap result = new TreeMap<>(); + final Descriptor descriptor = internalGetFieldAccessorTable().descriptor; + final List fields = descriptor.getFields(); + + for (int i = 0; i < fields.size(); i++) { + FieldDescriptor field = fields.get(i); + final OneofDescriptor oneofDescriptor = field.getContainingOneof(); + + /* + * If the field is part of a Oneof, then at maximum one field in the Oneof is set + * and it is not repeated. There is no need to iterate through the others. + */ + if (oneofDescriptor != null) { + // Skip other fields in the Oneof we know are not set + i += oneofDescriptor.getFieldCount() - 1; + if (!hasOneof(oneofDescriptor)) { + // If no field is set in the Oneof, skip all the fields in the Oneof + continue; + } + // Get the pointer to the only field which is set in the Oneof + field = getOneofFieldDescriptor(oneofDescriptor); + } else { + // If we are not in a Oneof, we need to check if the field is set and if it is repeated + if (field.isRepeated()) { + final List value = (List) getField(field); + if (!value.isEmpty()) { + result.put(field, value); + } + continue; + } + if (!hasField(field)) { + continue; + } + } + // Add the field to the map + result.put(field, getField(field)); + } + return result; + } + + @Override + public Message.Builder newBuilderForField(final FieldDescriptor field) { + return internalGetFieldAccessorTable().getField(field).newBuilder(); + } + + @Override + public Message.Builder getFieldBuilder(final FieldDescriptor field) { + return internalGetFieldAccessorTable().getField(field).getBuilder(this); + } + + @Override + public Message.Builder getRepeatedFieldBuilder(final FieldDescriptor field, int index) { + return internalGetFieldAccessorTable().getField(field).getRepeatedBuilder(this, index); + } + + @Override + public boolean hasOneof(final OneofDescriptor oneof) { + return internalGetFieldAccessorTable().getOneof(oneof).has(this); + } + + @Override + public FieldDescriptor getOneofFieldDescriptor(final OneofDescriptor oneof) { + return internalGetFieldAccessorTable().getOneof(oneof).get(this); + } + + @Override + public boolean hasField(final FieldDescriptor field) { + return internalGetFieldAccessorTable().getField(field).has(this); + } + + @Override + public Object getField(final FieldDescriptor field) { + Object object = internalGetFieldAccessorTable().getField(field).get(this); + if (field.isRepeated()) { + // The underlying list object is still modifiable at this point. + // Make sure not to expose the modifiable list to the caller. + return Collections.unmodifiableList((List) object); + } else { + return object; + } + } + + @Override + public BuilderT setField(final FieldDescriptor field, final Object value) { + internalGetFieldAccessorTable().getField(field).set(this, value); + return (BuilderT) this; + } + + @Override + public BuilderT clearField(final FieldDescriptor field) { + internalGetFieldAccessorTable().getField(field).clear(this); + return (BuilderT) this; + } + + @Override + public BuilderT clearOneof(final OneofDescriptor oneof) { + internalGetFieldAccessorTable().getOneof(oneof).clear(this); + return (BuilderT) this; + } + + @Override + public int getRepeatedFieldCount(final FieldDescriptor field) { + return internalGetFieldAccessorTable().getField(field).getRepeatedCount(this); + } + + @Override + public Object getRepeatedField(final FieldDescriptor field, final int index) { + return internalGetFieldAccessorTable().getField(field).getRepeated(this, index); + } + + @Override + public BuilderT setRepeatedField( + final FieldDescriptor field, final int index, final Object value) { + internalGetFieldAccessorTable().getField(field).setRepeated(this, index, value); + return (BuilderT) this; + } + + @Override + public BuilderT addRepeatedField(final FieldDescriptor field, final Object value) { + internalGetFieldAccessorTable().getField(field).addRepeated(this, value); + return (BuilderT) this; + } + + private BuilderT setUnknownFieldsInternal(final UnknownFieldSet unknownFields) { + unknownFieldsOrBuilder = unknownFields; + onChanged(); + return (BuilderT) this; + } + + @Override + public BuilderT setUnknownFields(final UnknownFieldSet unknownFields) { + return setUnknownFieldsInternal(unknownFields); + } + + /** + * This method is obsolete, but we must retain it for compatibility with older generated code. + */ + protected BuilderT setUnknownFieldsProto3(final UnknownFieldSet unknownFields) { + return setUnknownFieldsInternal(unknownFields); + } + + @Override + public BuilderT mergeUnknownFields(final UnknownFieldSet unknownFields) { + if (UnknownFieldSet.getDefaultInstance().equals(unknownFields)) { + return (BuilderT) this; + } + + if (UnknownFieldSet.getDefaultInstance().equals(unknownFieldsOrBuilder)) { + unknownFieldsOrBuilder = unknownFields; + onChanged(); + return (BuilderT) this; + } + + getUnknownFieldSetBuilder().mergeFrom(unknownFields); + onChanged(); + return (BuilderT) this; + } + + @Override + public boolean isInitialized() { + for (final FieldDescriptor field : getDescriptorForType().getFields()) { + // Check that all required fields are present. + if (field.isRequired()) { + if (!hasField(field)) { + return false; + } + } + // Check that embedded messages are initialized. + if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { + if (field.isRepeated()) { + @SuppressWarnings("unchecked") + final List messageList = (List) getField(field); + for (final Message element : messageList) { + if (!element.isInitialized()) { + return false; + } + } + } else { + if (hasField(field) && !((Message) getField(field)).isInitialized()) { + return false; + } + } + } + } + return true; + } + + @Override + public final UnknownFieldSet getUnknownFields() { + if (unknownFieldsOrBuilder instanceof UnknownFieldSet) { + return (UnknownFieldSet) unknownFieldsOrBuilder; + } else { + return ((UnknownFieldSet.Builder) unknownFieldsOrBuilder).buildPartial(); + } + } + + /** + * Called by generated subclasses to parse an unknown field. + * + * @return {@code true} unless the tag is an end-group tag. + */ + protected boolean parseUnknownField( + CodedInputStream input, ExtensionRegistryLite extensionRegistry, int tag) + throws IOException { + if (input.shouldDiscardUnknownFields()) { + return input.skipField(tag); + } + return getUnknownFieldSetBuilder().mergeFieldFrom(tag, input); + } + + /** Called by generated subclasses to add to the unknown field set. */ + protected final void mergeUnknownLengthDelimitedField(int number, ByteString bytes) { + getUnknownFieldSetBuilder().mergeLengthDelimitedField(number, bytes); + } + + /** Called by generated subclasses to add to the unknown field set. */ + protected final void mergeUnknownVarintField(int number, int value) { + getUnknownFieldSetBuilder().mergeVarintField(number, value); + } + + @Override + protected UnknownFieldSet.Builder getUnknownFieldSetBuilder() { + if (unknownFieldsOrBuilder instanceof UnknownFieldSet) { + unknownFieldsOrBuilder = ((UnknownFieldSet) unknownFieldsOrBuilder).toBuilder(); + } + onChanged(); + return (UnknownFieldSet.Builder) unknownFieldsOrBuilder; + } + + @Override + protected void setUnknownFieldSetBuilder(UnknownFieldSet.Builder builder) { + unknownFieldsOrBuilder = builder; + onChanged(); + } + + /** + * Implementation of {@link BuilderParent} for giving to our children. This small inner class + * makes it so we don't publicly expose the BuilderParent methods. + */ + private class BuilderParentImpl implements BuilderParent { + + @Override + public void markDirty() { + onChanged(); + } + } + + /** + * Gets the {@link BuilderParent} for giving to our children. + * + * @return The builder parent for our children. + */ + protected BuilderParent getParentForChildren() { + if (meAsParent == null) { + meAsParent = new BuilderParentImpl(); + } + return meAsParent; + } + + /** + * Called when a builder or one of its nested children has changed and any parent should be + * notified of its invalidation. + */ + protected final void onChanged() { + if (isClean && builderParent != null) { + builderParent.markDirty(); + + // Don't keep dispatching invalidations until build is called again. + isClean = false; + } + } + + /** + * Gets the map field with the given field number. This method should be overridden in the + * generated message class if the message contains map fields. + * + *

Unlike other field types, reflection support for map fields can't be implemented based on + * generated public API because we need to access a map field as a list in reflection API but + * the generated API only allows us to access it as a map. This method returns the underlying + * map field directly and thus enables us to access the map field as a list. + */ + @SuppressWarnings({"unused", "rawtypes"}) + protected MapFieldReflectionAccessor internalGetMapFieldReflection(int fieldNumber) { + return internalGetMapField(fieldNumber); + } + + /** TODO: Remove, exists for compatibility with generated code. */ + @Deprecated + @SuppressWarnings({"unused", "rawtypes"}) + protected MapField internalGetMapField(int fieldNumber) { + // Note that we can't use descriptor names here because this method will + // be called when descriptor is being initialized. + throw new IllegalArgumentException("No map fields found in " + getClass().getName()); + } + + /** Like {@link #internalGetMapFieldReflection} but return a mutable version. */ + @SuppressWarnings({"unused", "rawtypes"}) + protected MapFieldReflectionAccessor internalGetMutableMapFieldReflection(int fieldNumber) { + return internalGetMutableMapField(fieldNumber); + } + + /** TODO: Remove, exists for compatibility with generated code. */ + @Deprecated + @SuppressWarnings({"unused", "rawtypes"}) + protected MapField internalGetMutableMapField(int fieldNumber) { + // Note that we can't use descriptor names here because this method will + // be called when descriptor is being initialized. + throw new IllegalArgumentException("No map fields found in " + getClass().getName()); + } + } + + // ================================================================= + // Extensions-related stuff + + /** Extends {@link MessageOrBuilder} with extension-related functions. */ + public interface ExtendableMessageOrBuilder> + extends MessageOrBuilder { + // Re-define for return type covariance. + @Override + Message getDefaultInstanceForType(); + + /** Check if a singular extension is present. */ + boolean hasExtension(ExtensionLite extension); + + /** Get the number of elements in a repeated extension. */ + int getExtensionCount(ExtensionLite> extension); + + /** Get the value of an extension. */ + T getExtension(ExtensionLite extension); + + /** Get one element of a repeated extension. */ + T getExtension(ExtensionLite> extension, int index); + + /** + * Check if a singular extension is present. + *

TODO: handled by ExtensionLite version + */ + boolean hasExtension( + Extension extension); + /** + * Check if a singular extension is present. + *

TODO: handled by ExtensionLite version + */ + boolean hasExtension( + GeneratedExtension extension); + /** + * Get the number of elements in a repeated extension. + *

TODO: handled by ExtensionLite version + */ + int getExtensionCount( + Extension> extension); + /** + * Get the number of elements in a repeated extension. + *

TODO: handled by ExtensionLite version + */ + int getExtensionCount( + GeneratedExtension> extension); + /** + * Get the value of an extension. + *

TODO: handled by ExtensionLite version + */ + T getExtension( + Extension extension); + /** + * Get the value of an extension. + *

TODO: handled by ExtensionLite version + */ + T getExtension( + GeneratedExtension extension); + /** + * Get one element of a repeated extension. + *

TODO: handled by ExtensionLite version + */ + T getExtension( + Extension> extension, + int index); + /** + * Get one element of a repeated extension. + *

TODO: handled by ExtensionLite version + */ + T getExtension( + GeneratedExtension> extension, + int index); + } + + /** + * Generated message classes for message types that contain extension ranges subclass this. + * + *

This class implements type-safe accessors for extensions. They implement all the same + * operations that you can do with normal fields -- e.g. "has", "get", and "getCount" -- but for + * extensions. The extensions are identified using instances of the class {@link + * GeneratedExtension}; the protocol compiler generates a static instance of this class for every + * extension in its input. Through the magic of generics, all is made type-safe. + * + *

For example, imagine you have the {@code .proto} file: + * + *

+   * option java_class = "MyProto";
+   *
+   * message Foo {
+   *   extensions 1000 to max;
+   * }
+   *
+   * extend Foo {
+   *   optional int32 bar;
+   * }
+   * 
+ * + *

Then you might write code like: + * + *

+   * MyProto.Foo foo = getFoo();
+   * int i = foo.getExtension(MyProto.bar);
+   * 
+ * + *

See also {@link ExtendableBuilder}. + */ + public abstract static class ExtendableMessage> + extends GeneratedMessageV3Internal implements ExtendableMessageOrBuilder { + + private static final long serialVersionUID = 1L; + + private final FieldSet extensions; + + protected ExtendableMessage() { + this.extensions = FieldSet.newFieldSet(); + } + + protected ExtendableMessage(ExtendableBuilder builder) { + super(builder); + this.extensions = builder.buildExtensions(); + } + + private void verifyExtensionContainingType(final Extension extension) { + if (extension.getDescriptor().getContainingType() != getDescriptorForType()) { + // This can only happen if someone uses unchecked operations. + throw new IllegalArgumentException( + "Extension is for type \"" + + extension.getDescriptor().getContainingType().getFullName() + + "\" which does not match message type \"" + + getDescriptorForType().getFullName() + + "\"."); + } + } + + /** Check if a singular extension is present. */ + @Override + public final boolean hasExtension(final ExtensionLite extensionLite) { + Extension extension = checkNotLite(extensionLite); + + verifyExtensionContainingType(extension); + return extensions.hasField(extension.getDescriptor()); + } + + /** Get the number of elements in a repeated extension. */ + @Override + public final int getExtensionCount(final ExtensionLite> extensionLite) { + Extension> extension = checkNotLite(extensionLite); + + verifyExtensionContainingType(extension); + final FieldDescriptor descriptor = extension.getDescriptor(); + return extensions.getRepeatedFieldCount(descriptor); + } + + /** Get the value of an extension. */ + @Override + @SuppressWarnings("unchecked") + public final T getExtension(final ExtensionLite extensionLite) { + Extension extension = checkNotLite(extensionLite); + + verifyExtensionContainingType(extension); + FieldDescriptor descriptor = extension.getDescriptor(); + final Object value = extensions.getField(descriptor); + if (value == null) { + if (descriptor.isRepeated()) { + return (T) Collections.emptyList(); + } else if (descriptor.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { + return (T) extension.getMessageDefaultInstance(); + } else { + return (T) extension.fromReflectionType(descriptor.getDefaultValue()); + } + } else { + return (T) extension.fromReflectionType(value); + } + } + + /** Get one element of a repeated extension. */ + @Override + @SuppressWarnings("unchecked") + public final T getExtension( + final ExtensionLite> extensionLite, final int index) { + Extension> extension = checkNotLite(extensionLite); + + verifyExtensionContainingType(extension); + FieldDescriptor descriptor = extension.getDescriptor(); + return (T) + extension.singularFromReflectionType(extensions.getRepeatedField(descriptor, index)); + } + + /** + * Check if a singular extension is present. + *

TODO: handled by ExtensionLite version + */ + @Override + public final boolean hasExtension(final Extension extension) { + return hasExtension((ExtensionLite) extension); + } + /** + * Check if a singular extension is present. + *

TODO: handled by ExtensionLite version + */ + @Override + public final boolean hasExtension( + final GeneratedExtension extension) { + return hasExtension((ExtensionLite) extension); + } + /** + * Get the number of elements in a repeated extension. + *

TODO: handled by ExtensionLite version + */ + @Override + public final int getExtensionCount( + final Extension> extension) { + return getExtensionCount((ExtensionLite>) extension); + } + /** + * Get the number of elements in a repeated extension. + *

TODO: handled by ExtensionLite version + */ + @Override + public final int getExtensionCount( + final GeneratedExtension> extension) { + return getExtensionCount((ExtensionLite>) extension); + } + /** + * Get the value of an extension. + *

TODO: handled by ExtensionLite version + */ + @Override + public final T getExtension(final Extension extension) { + return getExtension((ExtensionLite) extension); + } + /** + * Get the value of an extension. + *

TODO: handled by ExtensionLite version + */ + @Override + public final T getExtension( + final GeneratedExtension extension) { + return getExtension((ExtensionLite) extension); + } + /** + * Get one element of a repeated extension. + *

TODO: handled by ExtensionLite version + */ + @Override + public final T getExtension( + final Extension> extension, final int index) { + return getExtension((ExtensionLite>) extension, index); + } + /** + * Get one element of a repeated extension. + *

TODO: handled by ExtensionLite version + */ + @Override + public final T getExtension( + final GeneratedExtension> extension, final int index) { + return getExtension((ExtensionLite>) extension, index); + } + + /** Called by subclasses to check if all extensions are initialized. */ + protected boolean extensionsAreInitialized() { + return extensions.isInitialized(); + } + + // TODO: compute this in the builder at {@code build()} time. + @Override + public boolean isInitialized() { + return super.isInitialized() && extensionsAreInitialized(); + } + + // TODO: remove mutating method from immutable type + @Override + protected boolean parseUnknownField( + CodedInputStream input, + UnknownFieldSet.Builder unknownFields, + ExtensionRegistryLite extensionRegistry, + int tag) + throws IOException { + return MessageReflection.mergeFieldFrom( + input, + input.shouldDiscardUnknownFields() ? null : unknownFields, + extensionRegistry, + getDescriptorForType(), + new MessageReflection.ExtensionAdapter(extensions), + tag); + } + + /** + * Delegates to parseUnknownField. This method is obsolete, but we must retain it for + * compatibility with older generated code. + * + *

TODO: remove mutating method from immutable type + */ + @Override + protected boolean parseUnknownFieldProto3( + CodedInputStream input, + UnknownFieldSet.Builder unknownFields, + ExtensionRegistryLite extensionRegistry, + int tag) + throws IOException { + return parseUnknownField(input, unknownFields, extensionRegistry, tag); + } + + /** + * Used by parsing constructors in generated classes. + * + *

TODO: remove unused method (extensions should be immutable after build) + */ + @Override + protected void makeExtensionsImmutable() { + extensions.makeImmutable(); + } + + /** + * Used by subclasses to serialize extensions. Extension ranges may be interleaved with field + * numbers, but we must write them in canonical (sorted by field number) order. ExtensionWriter + * helps us write individual ranges of extensions at once. + */ + protected class ExtensionWriter { + // Imagine how much simpler this code would be if Java iterators had + // a way to get the next element without advancing the iterator. + + private final Iterator> iter = extensions.iterator(); + private Map.Entry next; + private final boolean messageSetWireFormat; + + private ExtensionWriter(final boolean messageSetWireFormat) { + if (iter.hasNext()) { + next = iter.next(); + } + this.messageSetWireFormat = messageSetWireFormat; + } + + public void writeUntil(final int end, final CodedOutputStream output) throws IOException { + while (next != null && next.getKey().getNumber() < end) { + FieldDescriptor descriptor = next.getKey(); + if (messageSetWireFormat + && descriptor.getLiteJavaType() == WireFormat.JavaType.MESSAGE + && !descriptor.isRepeated()) { + if (next instanceof LazyField.LazyEntry) { + output.writeRawMessageSetExtension( + descriptor.getNumber(), + ((LazyField.LazyEntry) next).getField().toByteString()); + } else { + output.writeMessageSetExtension(descriptor.getNumber(), (Message) next.getValue()); + } + } else { + // TODO: Taken care of following code, it may cause + // problem when we use LazyField for normal fields/extensions. + // Due to the optional field can be duplicated at the end of + // serialized bytes, which will make the serialized size change + // after lazy field parsed. So when we use LazyField globally, + // we need to change the following write method to write cached + // bytes directly rather than write the parsed message. + FieldSet.writeField(descriptor, next.getValue(), output); + } + if (iter.hasNext()) { + next = iter.next(); + } else { + next = null; + } + } + } + } + + protected ExtensionWriter newExtensionWriter() { + return new ExtensionWriter(false); + } + + protected ExtensionWriter newMessageSetExtensionWriter() { + return new ExtensionWriter(true); + } + + /** Called by subclasses to compute the size of extensions. */ + protected int extensionsSerializedSize() { + return extensions.getSerializedSize(); + } + + protected int extensionsSerializedSizeAsMessageSet() { + return extensions.getMessageSetSerializedSize(); + } + + // --------------------------------------------------------------- + // Reflection + + protected Map getExtensionFields() { + return extensions.getAllFields(); + } + + @Override + public Map getAllFields() { + final Map result = + super.getAllFieldsMutable(/* getBytesForString= */ false); + result.putAll(getExtensionFields()); + return Collections.unmodifiableMap(result); + } + + @Override + public Map getAllFieldsRaw() { + final Map result = + super.getAllFieldsMutable(/* getBytesForString= */ false); + result.putAll(getExtensionFields()); + return Collections.unmodifiableMap(result); + } + + @Override + public boolean hasField(final FieldDescriptor field) { + if (field.isExtension()) { + verifyContainingType(field); + return extensions.hasField(field); + } else { + return super.hasField(field); + } + } + + @Override + public Object getField(final FieldDescriptor field) { + if (field.isExtension()) { + verifyContainingType(field); + final Object value = extensions.getField(field); + if (value == null) { + if (field.isRepeated()) { + return Collections.emptyList(); + } else if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { + // Lacking an ExtensionRegistry, we have no way to determine the + // extension's real type, so we return a DynamicMessage. + return DynamicMessage.getDefaultInstance(field.getMessageType()); + } else { + return field.getDefaultValue(); + } + } else { + return value; + } + } else { + return super.getField(field); + } + } + + @Override + public int getRepeatedFieldCount(final FieldDescriptor field) { + if (field.isExtension()) { + verifyContainingType(field); + return extensions.getRepeatedFieldCount(field); + } else { + return super.getRepeatedFieldCount(field); + } + } + + @Override + public Object getRepeatedField(final FieldDescriptor field, final int index) { + if (field.isExtension()) { + verifyContainingType(field); + return extensions.getRepeatedField(field, index); + } else { + return super.getRepeatedField(field, index); + } + } + + private void verifyContainingType(final FieldDescriptor field) { + if (field.getContainingType() != getDescriptorForType()) { + throw new IllegalArgumentException("FieldDescriptor does not match message type."); + } + } + } + + /** + * Generated message builders for message types that contain extension ranges subclass this. + * + *

This class implements type-safe accessors for extensions. They implement all the same + * operations that you can do with normal fields -- e.g. "get", "set", and "add" -- but for + * extensions. The extensions are identified using instances of the class {@link + * GeneratedExtension}; the protocol compiler generates a static instance of this class for every + * extension in its input. Through the magic of generics, all is made type-safe. + * + *

For example, imagine you have the {@code .proto} file: + * + *

+   * option java_class = "MyProto";
+   *
+   * message Foo {
+   *   extensions 1000 to max;
+   * }
+   *
+   * extend Foo {
+   *   optional int32 bar;
+   * }
+   * 
+ * + *

Then you might write code like: + * + *

+   * MyProto.Foo foo =
+   *   MyProto.Foo.newBuilder()
+   *     .setExtension(MyProto.bar, 123)
+   *     .build();
+   * 
+ * + *

See also {@link ExtendableMessage}. + */ + @SuppressWarnings("unchecked") + public abstract static class ExtendableBuilder< + MessageT extends ExtendableMessage, + BuilderT extends ExtendableBuilder> + extends Builder implements ExtendableMessageOrBuilder { + + private FieldSet.Builder extensions; + + protected ExtendableBuilder() {} + + protected ExtendableBuilder(BuilderParent parent) { + super(parent); + } + + // For immutable message conversion. + void internalSetExtensionSet(FieldSet extensions) { + this.extensions = FieldSet.Builder.fromFieldSet(extensions); + } + + @Override + public BuilderT clear() { + extensions = null; + return super.clear(); + } + + private void ensureExtensionsIsMutable() { + if (extensions == null) { + extensions = FieldSet.newBuilder(); + } + } + + private void verifyExtensionContainingType(final Extension extension) { + if (extension.getDescriptor().getContainingType() != getDescriptorForType()) { + // This can only happen if someone uses unchecked operations. + throw new IllegalArgumentException( + "Extension is for type \"" + + extension.getDescriptor().getContainingType().getFullName() + + "\" which does not match message type \"" + + getDescriptorForType().getFullName() + + "\"."); + } + } + + /** Check if a singular extension is present. */ + @Override + public final boolean hasExtension(final ExtensionLite extensionLite) { + Extension extension = checkNotLite(extensionLite); + + verifyExtensionContainingType(extension); + return extensions != null && extensions.hasField(extension.getDescriptor()); + } + + /** Get the number of elements in a repeated extension. */ + @Override + public final int getExtensionCount(final ExtensionLite> extensionLite) { + Extension> extension = checkNotLite(extensionLite); + + verifyExtensionContainingType(extension); + final FieldDescriptor descriptor = extension.getDescriptor(); + return extensions == null ? 0 : extensions.getRepeatedFieldCount(descriptor); + } + + /** Get the value of an extension. */ + @Override + public final T getExtension(final ExtensionLite extensionLite) { + Extension extension = checkNotLite(extensionLite); + + verifyExtensionContainingType(extension); + FieldDescriptor descriptor = extension.getDescriptor(); + final Object value = extensions == null ? null : extensions.getField(descriptor); + if (value == null) { + if (descriptor.isRepeated()) { + return (T) Collections.emptyList(); + } else if (descriptor.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { + return (T) extension.getMessageDefaultInstance(); + } else { + return (T) extension.fromReflectionType(descriptor.getDefaultValue()); + } + } else { + return (T) extension.fromReflectionType(value); + } + } + + /** Get one element of a repeated extension. */ + @Override + public final T getExtension( + final ExtensionLite> extensionLite, final int index) { + Extension> extension = checkNotLite(extensionLite); + + verifyExtensionContainingType(extension); + FieldDescriptor descriptor = extension.getDescriptor(); + if (extensions == null) { + throw new IndexOutOfBoundsException(); + } + return (T) + extension.singularFromReflectionType(extensions.getRepeatedField(descriptor, index)); + } + + /** Set the value of an extension. */ + public final BuilderT setExtension( + final ExtensionLite extensionLite, final T value) { + Extension extension = checkNotLite(extensionLite); + + verifyExtensionContainingType(extension); + ensureExtensionsIsMutable(); + final FieldDescriptor descriptor = extension.getDescriptor(); + extensions.setField(descriptor, extension.toReflectionType(value)); + onChanged(); + return (BuilderT) this; + } + + /** Set the value of one element of a repeated extension. */ + public final BuilderT setExtension( + final ExtensionLite> extensionLite, final int index, final T value) { + Extension> extension = checkNotLite(extensionLite); + + verifyExtensionContainingType(extension); + ensureExtensionsIsMutable(); + final FieldDescriptor descriptor = extension.getDescriptor(); + extensions.setRepeatedField(descriptor, index, extension.singularToReflectionType(value)); + onChanged(); + return (BuilderT) this; + } + + /** Append a value to a repeated extension. */ + public final BuilderT addExtension( + final ExtensionLite> extensionLite, final T value) { + Extension> extension = checkNotLite(extensionLite); + + verifyExtensionContainingType(extension); + ensureExtensionsIsMutable(); + final FieldDescriptor descriptor = extension.getDescriptor(); + extensions.addRepeatedField(descriptor, extension.singularToReflectionType(value)); + onChanged(); + return (BuilderT) this; + } + + /** Clear an extension. */ + public final BuilderT clearExtension(final ExtensionLite extensionLite) { + Extension extension = checkNotLite(extensionLite); + + verifyExtensionContainingType(extension); + ensureExtensionsIsMutable(); + extensions.clearField(extension.getDescriptor()); + onChanged(); + return (BuilderT) this; + } + + /** + * Check if a singular extension is present. + *

TODO: handled by ExtensionLite version + */ + @Override + public final boolean hasExtension(final Extension extension) { + return hasExtension((ExtensionLite) extension); + } + /** + * Check if a singular extension is present. + *

TODO: handled by ExtensionLite version + */ + @Override + public final boolean hasExtension( + final GeneratedExtension extension) { + return hasExtension((ExtensionLite) extension); + } + /** + * Get the number of elements in a repeated extension. + *

TODO: handled by ExtensionLite version + */ + @Override + public final int getExtensionCount( + final Extension> extension) { + return getExtensionCount((ExtensionLite>) extension); + } + /** + * Get the number of elements in a repeated extension. + *

TODO: handled by ExtensionLite version + */ + @Override + public final int getExtensionCount( + final GeneratedExtension> extension) { + return getExtensionCount((ExtensionLite>) extension); + } + /** + * Get the value of an extension. + *

TODO: handled by ExtensionLite version + */ + @Override + public final T getExtension(final Extension extension) { + return getExtension((ExtensionLite) extension); + } + /** Get the value of an extension. + *

TODO: handled by ExtensionLite version + */ + @Override + public final T getExtension( + final GeneratedExtension extension) { + return getExtension((ExtensionLite) extension); + } + /** + * Get the value of an extension. + *

TODO: handled by ExtensionLite version + */ + @Override + public final T getExtension( + final Extension> extension, final int index) { + return getExtension((ExtensionLite>) extension, index); + } + /** + * Get the value of an extension. + *

TODO: handled by ExtensionLite version + */ + @Override + public final T getExtension( + final GeneratedExtension> extension, final int index) { + return getExtension((ExtensionLite>) extension, index); + } + /** + * Set the value of an extension. + *

TODO: handled by ExtensionLite version + */ + public final BuilderT setExtension( + final Extension extension, final T value) { + return setExtension((ExtensionLite) extension, value); + } + /** + * Set the value of an extension. + *

TODO: handled by ExtensionLite version + */ + public BuilderT setExtension( + final GeneratedExtension extension, final T value) { + return setExtension((ExtensionLite) extension, value); + } + /** + * Set the value of one element of a repeated extension. + *

TODO: handled by ExtensionLite version + */ + public final BuilderT setExtension( + final Extension> extension, + final int index, final T value) { + return setExtension((ExtensionLite>) extension, index, value); + } + /** + * Set the value of one element of a repeated extension. + *

TODO: handled by ExtensionLite version + */ + public BuilderT setExtension( + final GeneratedExtension> extension, + final int index, final T value) { + return setExtension((ExtensionLite>) extension, index, value); + } + /** + * Append a value to a repeated extension. + *

TODO: handled by ExtensionLite version + */ + public final BuilderT addExtension( + final Extension> extension, final T value) { + return addExtension((ExtensionLite>) extension, value); + } + /** + * Append a value to a repeated extension. + *

TODO: handled by ExtensionLite version + */ + public BuilderT addExtension( + final GeneratedExtension> extension, final T value) { + return addExtension((ExtensionLite>) extension, value); + } + /** + * Clear an extension. + *

TODO: handled by ExtensionLite version + */ + public final BuilderT clearExtension( + final Extension extension) { + return clearExtension((ExtensionLite) extension); + } + /** + * Clears an extension. + *

TODO: handled by ExtensionLite version + */ + public BuilderT clearExtension( + final GeneratedExtension extension) { + return clearExtension((ExtensionLite) extension); + } + + /** Called by subclasses to check if all extensions are initialized. */ + protected boolean extensionsAreInitialized() { + return extensions == null || extensions.isInitialized(); + } + + /** + * Called by the build code path to create a copy of the extensions for building the message. + */ + private FieldSet buildExtensions() { + return extensions == null + ? (FieldSet) FieldSet.emptySet() + : extensions.buildPartial(); + } + + @Override + public boolean isInitialized() { + return super.isInitialized() && extensionsAreInitialized(); + } + + // --------------------------------------------------------------- + // Reflection + + @Override + public Map getAllFields() { + final Map result = super.getAllFieldsMutable(); + if (extensions != null) { + result.putAll(extensions.getAllFields()); + } + return Collections.unmodifiableMap(result); + } + + @Override + public Object getField(final FieldDescriptor field) { + if (field.isExtension()) { + verifyContainingType(field); + final Object value = extensions == null ? null : extensions.getField(field); + if (value == null) { + if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { + // Lacking an ExtensionRegistry, we have no way to determine the + // extension's real type, so we return a DynamicMessage. + return DynamicMessage.getDefaultInstance(field.getMessageType()); + } else { + return field.getDefaultValue(); + } + } else { + return value; + } + } else { + return super.getField(field); + } + } + + @Override + public Message.Builder getFieldBuilder(final FieldDescriptor field) { + if (field.isExtension()) { + verifyContainingType(field); + if (field.getJavaType() != FieldDescriptor.JavaType.MESSAGE) { + throw new UnsupportedOperationException( + "getFieldBuilder() called on a non-Message type."); + } + ensureExtensionsIsMutable(); + final Object value = extensions.getFieldAllowBuilders(field); + if (value == null) { + Message.Builder builder = DynamicMessage.newBuilder(field.getMessageType()); + extensions.setField(field, builder); + onChanged(); + return builder; + } else { + if (value instanceof Message.Builder) { + return (Message.Builder) value; + } else if (value instanceof Message) { + Message.Builder builder = ((Message) value).toBuilder(); + extensions.setField(field, builder); + onChanged(); + return builder; + } else { + throw new UnsupportedOperationException( + "getRepeatedFieldBuilder() called on a non-Message type."); + } + } + } else { + return super.getFieldBuilder(field); + } + } + + @Override + public int getRepeatedFieldCount(final FieldDescriptor field) { + if (field.isExtension()) { + verifyContainingType(field); + return extensions == null ? 0 : extensions.getRepeatedFieldCount(field); + } else { + return super.getRepeatedFieldCount(field); + } + } + + @Override + public Object getRepeatedField(final FieldDescriptor field, final int index) { + if (field.isExtension()) { + verifyContainingType(field); + if (extensions == null) { + throw new IndexOutOfBoundsException(); + } + return extensions.getRepeatedField(field, index); + } else { + return super.getRepeatedField(field, index); + } + } + + @Override + public Message.Builder getRepeatedFieldBuilder(final FieldDescriptor field, final int index) { + if (field.isExtension()) { + verifyContainingType(field); + ensureExtensionsIsMutable(); + if (field.getJavaType() != FieldDescriptor.JavaType.MESSAGE) { + throw new UnsupportedOperationException( + "getRepeatedFieldBuilder() called on a non-Message type."); + } + final Object value = extensions.getRepeatedFieldAllowBuilders(field, index); + if (value instanceof Message.Builder) { + return (Message.Builder) value; + } else if (value instanceof Message) { + Message.Builder builder = ((Message) value).toBuilder(); + extensions.setRepeatedField(field, index, builder); + onChanged(); + return builder; + } else { + throw new UnsupportedOperationException( + "getRepeatedFieldBuilder() called on a non-Message type."); + } + } else { + return super.getRepeatedFieldBuilder(field, index); + } + } + + @Override + public boolean hasField(final FieldDescriptor field) { + if (field.isExtension()) { + verifyContainingType(field); + return extensions != null && extensions.hasField(field); + } else { + return super.hasField(field); + } + } + + @Override + public BuilderT setField(final FieldDescriptor field, final Object value) { + if (field.isExtension()) { + verifyContainingType(field); + ensureExtensionsIsMutable(); + extensions.setField(field, value); + onChanged(); + return (BuilderT) this; + } else { + return super.setField(field, value); + } + } + + @Override + public BuilderT clearField(final FieldDescriptor field) { + if (field.isExtension()) { + verifyContainingType(field); + ensureExtensionsIsMutable(); + extensions.clearField(field); + onChanged(); + return (BuilderT) this; + } else { + return super.clearField(field); + } + } + + @Override + public BuilderT setRepeatedField( + final FieldDescriptor field, final int index, final Object value) { + if (field.isExtension()) { + verifyContainingType(field); + ensureExtensionsIsMutable(); + extensions.setRepeatedField(field, index, value); + onChanged(); + return (BuilderT) this; + } else { + return super.setRepeatedField(field, index, value); + } + } + + @Override + public BuilderT addRepeatedField(final FieldDescriptor field, final Object value) { + if (field.isExtension()) { + verifyContainingType(field); + ensureExtensionsIsMutable(); + extensions.addRepeatedField(field, value); + onChanged(); + return (BuilderT) this; + } else { + return super.addRepeatedField(field, value); + } + } + + @Override + public Message.Builder newBuilderForField(final FieldDescriptor field) { + if (field.isExtension()) { + return DynamicMessage.newBuilder(field.getMessageType()); + } else { + return super.newBuilderForField(field); + } + } + + protected final void mergeExtensionFields(final ExtendableMessage other) { + if (other.extensions != null) { + ensureExtensionsIsMutable(); + extensions.mergeFrom(other.extensions); + onChanged(); + } + } + + @Override + protected boolean parseUnknownField( + CodedInputStream input, ExtensionRegistryLite extensionRegistry, int tag) + throws IOException { + ensureExtensionsIsMutable(); + return MessageReflection.mergeFieldFrom( + input, + input.shouldDiscardUnknownFields() ? null : getUnknownFieldSetBuilder(), + extensionRegistry, + getDescriptorForType(), + new MessageReflection.ExtensionBuilderAdapter(extensions), + tag); + } + + private void verifyContainingType(final FieldDescriptor field) { + if (field.getContainingType() != getDescriptorForType()) { + throw new IllegalArgumentException("FieldDescriptor does not match message type."); + } + } + } + + // ----------------------------------------------------------------- + + /** + * Gets the descriptor for an extension. The implementation depends on whether the extension is + * scoped in the top level of a file or scoped in a Message. + */ + interface ExtensionDescriptorRetriever { + FieldDescriptor getDescriptor(); + } + + // ================================================================= + + /** Calls Class.getMethod and throws a RuntimeException if it fails. */ + private static Method getMethodOrDie( + final Class clazz, final String name, final Class... params) { + try { + return clazz.getMethod(name, params); + } catch (NoSuchMethodException e) { + throw new IllegalStateException( + "Generated message class \"" + clazz.getName() + "\" missing method \"" + name + "\".", + e); + } + } + + /** Calls invoke and throws a RuntimeException if it fails. */ + @CanIgnoreReturnValue + private static Object invokeOrDie( + final Method method, final Object object, final Object... params) { + try { + return method.invoke(object, params); + } catch (IllegalAccessException e) { + throw new IllegalStateException( + "Couldn't use Java reflection to implement protocol message reflection.", e); + } catch (InvocationTargetException e) { + final Throwable cause = e.getCause(); + if (cause instanceof RuntimeException) { + throw (RuntimeException) cause; + } else if (cause instanceof Error) { + throw (Error) cause; + } else { + throw new IllegalStateException( + "Unexpected exception thrown by generated accessor method.", cause); + } + } + } + + /** + * Gets the map field with the given field number. This method should be overridden in the + * generated message class if the message contains map fields. + * + *

Unlike other field types, reflection support for map fields can't be implemented based on + * generated public API because we need to access a map field as a list in reflection API but the + * generated API only allows us to access it as a map. This method returns the underlying map + * field directly and thus enables us to access the map field as a list. + */ + @SuppressWarnings("unused") + protected MapFieldReflectionAccessor internalGetMapFieldReflection(int fieldNumber) { + return internalGetMapField(fieldNumber); + } + + /** TODO: Remove, exists for compatibility with generated code. */ + @Deprecated + @SuppressWarnings({"rawtypes", "unused"}) + protected MapField internalGetMapField(int fieldNumber) { + // Note that we can't use descriptor names here because this method will + // be called when descriptor is being initialized. + throw new IllegalArgumentException("No map fields found in " + getClass().getName()); + } + + /** + * Users should ignore this class. This class provides the implementation with access to the + * fields of a message object using Java reflection. + */ + public static final class FieldAccessorTable { + + /** + * Construct a FieldAccessorTable for a particular message class. Only one FieldAccessorTable + * should ever be constructed per class. + * + * @param descriptor The type's descriptor. + * @param camelCaseNames The camelcase names of all fields in the message. These are used to + * derive the accessor method names. + * @param messageClass The message type. + * @param builderClass The builder type. + */ + public FieldAccessorTable( + final Descriptor descriptor, + final String[] camelCaseNames, + final Class messageClass, + final Class> builderClass) { + this(descriptor, camelCaseNames); + ensureFieldAccessorsInitialized(messageClass, builderClass); + } + + /** + * Construct a FieldAccessorTable for a particular message class without initializing + * FieldAccessors. + */ + public FieldAccessorTable(final Descriptor descriptor, final String[] camelCaseNames) { + this.descriptor = descriptor; + this.camelCaseNames = camelCaseNames; + fields = new FieldAccessor[descriptor.getFields().size()]; + oneofs = new OneofAccessor[descriptor.getOneofs().size()]; + initialized = false; + } + + /** + * Ensures the field accessors are initialized. This method is thread-safe. + * + * @param messageClass The message type. + * @param builderClass The builder type. + * @return this + */ + public FieldAccessorTable ensureFieldAccessorsInitialized( + Class messageClass, Class> builderClass) { + if (initialized) { + return this; + } + synchronized (this) { + if (initialized) { + return this; + } + int fieldsSize = fields.length; + for (int i = 0; i < fieldsSize; i++) { + FieldDescriptor field = descriptor.getFields().get(i); + String containingOneofCamelCaseName = null; + if (field.getContainingOneof() != null) { + int index = fieldsSize + field.getContainingOneof().getIndex(); + if (index < camelCaseNames.length) { + containingOneofCamelCaseName = camelCaseNames[index]; + } + } + if (field.isRepeated()) { + if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { + if (field.isMapField()) { + fields[i] = new MapFieldAccessor(field, messageClass); + } else { + fields[i] = + new RepeatedMessageFieldAccessor( + field, camelCaseNames[i], messageClass, builderClass); + } + } else if (field.getJavaType() == FieldDescriptor.JavaType.ENUM) { + fields[i] = + new RepeatedEnumFieldAccessor( + field, camelCaseNames[i], messageClass, builderClass); + } else { + fields[i] = + new RepeatedFieldAccessor(field, camelCaseNames[i], messageClass, builderClass); + } + } else { + if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { + fields[i] = + new SingularMessageFieldAccessor( + field, + camelCaseNames[i], + messageClass, + builderClass, + containingOneofCamelCaseName); + } else if (field.getJavaType() == FieldDescriptor.JavaType.ENUM) { + fields[i] = + new SingularEnumFieldAccessor( + field, + camelCaseNames[i], + messageClass, + builderClass, + containingOneofCamelCaseName); + } else if (field.getJavaType() == FieldDescriptor.JavaType.STRING) { + fields[i] = + new SingularStringFieldAccessor( + field, + camelCaseNames[i], + messageClass, + builderClass, + containingOneofCamelCaseName); + } else { + fields[i] = + new SingularFieldAccessor( + field, + camelCaseNames[i], + messageClass, + builderClass, + containingOneofCamelCaseName); + } + } + } + + for (int i = 0; i < descriptor.getOneofs().size(); i++) { + if (i < descriptor.getRealOneofs().size()) { + oneofs[i] = + new RealOneofAccessor( + descriptor, i, camelCaseNames[i + fieldsSize], messageClass, builderClass); + } else { + oneofs[i] = new SyntheticOneofAccessor(descriptor, i); + } + } + + initialized = true; + camelCaseNames = null; + return this; + } + } + + private final Descriptor descriptor; + private final FieldAccessor[] fields; + private String[] camelCaseNames; + private final OneofAccessor[] oneofs; + private volatile boolean initialized; + + /** Get the FieldAccessor for a particular field. */ + private FieldAccessor getField(final FieldDescriptor field) { + if (field.getContainingType() != descriptor) { + throw new IllegalArgumentException("FieldDescriptor does not match message type."); + } else if (field.isExtension()) { + // If this type had extensions, it would subclass ExtendableMessage, + // which overrides the reflection interface to handle extensions. + throw new IllegalArgumentException("This type does not have extensions."); + } + return fields[field.getIndex()]; + } + + /** Get the OneofAccessor for a particular oneof. */ + private OneofAccessor getOneof(final OneofDescriptor oneof) { + if (oneof.getContainingType() != descriptor) { + throw new IllegalArgumentException("OneofDescriptor does not match message type."); + } + return oneofs[oneof.getIndex()]; + } + + /** + * Abstract interface that provides access to a single field. This is implemented differently + * depending on the field type and cardinality. + */ + private interface FieldAccessor { + Object get(GeneratedMessageV3Internal message); + + Object get(GeneratedMessageV3Internal.Builder builder); + + Object getRaw(GeneratedMessageV3Internal message); + + void set(Builder builder, Object value); + + Object getRepeated(GeneratedMessageV3Internal message, int index); + + Object getRepeated(GeneratedMessageV3Internal.Builder builder, int index); + + void setRepeated(Builder builder, int index, Object value); + + void addRepeated(Builder builder, Object value); + + boolean has(GeneratedMessageV3Internal message); + + boolean has(GeneratedMessageV3Internal.Builder builder); + + int getRepeatedCount(GeneratedMessageV3Internal message); + + int getRepeatedCount(GeneratedMessageV3Internal.Builder builder); + + void clear(Builder builder); + + Message.Builder newBuilder(); + + Message.Builder getBuilder(GeneratedMessageV3Internal.Builder builder); + + Message.Builder getRepeatedBuilder(GeneratedMessageV3Internal.Builder builder, int index); + } + + /** OneofAccessor provides access to a single oneof. */ + private static interface OneofAccessor { + public boolean has(final GeneratedMessageV3Internal message); + + public boolean has(GeneratedMessageV3Internal.Builder builder); + + public FieldDescriptor get(final GeneratedMessageV3Internal message); + + public FieldDescriptor get(GeneratedMessageV3Internal.Builder builder); + + public void clear(final Builder builder); + } + + /** RealOneofAccessor provides access to a single real oneof. */ + private static class RealOneofAccessor implements OneofAccessor { + RealOneofAccessor( + final Descriptor descriptor, + final int oneofIndex, + final String camelCaseName, + final Class messageClass, + final Class> builderClass) { + this.descriptor = descriptor; + caseMethod = getMethodOrDie(messageClass, "get" + camelCaseName + "Case"); + caseMethodBuilder = getMethodOrDie(builderClass, "get" + camelCaseName + "Case"); + clearMethod = getMethodOrDie(builderClass, "clear" + camelCaseName); + } + + private final Descriptor descriptor; + private final Method caseMethod; + private final Method caseMethodBuilder; + private final Method clearMethod; + + @Override + public boolean has(final GeneratedMessageV3Internal message) { + return ((Internal.EnumLite) invokeOrDie(caseMethod, message)).getNumber() != 0; + } + + @Override + public boolean has(GeneratedMessageV3Internal.Builder builder) { + return ((Internal.EnumLite) invokeOrDie(caseMethodBuilder, builder)).getNumber() != 0; + } + + @Override + public FieldDescriptor get(final GeneratedMessageV3Internal message) { + int fieldNumber = ((Internal.EnumLite) invokeOrDie(caseMethod, message)).getNumber(); + if (fieldNumber > 0) { + return descriptor.findFieldByNumber(fieldNumber); + } + return null; + } + + @Override + public FieldDescriptor get(GeneratedMessageV3Internal.Builder builder) { + int fieldNumber = ((Internal.EnumLite) invokeOrDie(caseMethodBuilder, builder)).getNumber(); + if (fieldNumber > 0) { + return descriptor.findFieldByNumber(fieldNumber); + } + return null; + } + + @Override + public void clear(final Builder builder) { + // TODO: remove the unused variable + Object unused = invokeOrDie(clearMethod, builder); + } + } + + /** SyntheticOneofAccessor provides access to a single synthetic oneof. */ + private static class SyntheticOneofAccessor implements OneofAccessor { + SyntheticOneofAccessor(final Descriptor descriptor, final int oneofIndex) { + OneofDescriptor oneofDescriptor = descriptor.getOneofs().get(oneofIndex); + fieldDescriptor = oneofDescriptor.getFields().get(0); + } + + private final FieldDescriptor fieldDescriptor; + + @Override + public boolean has(final GeneratedMessageV3Internal message) { + return message.hasField(fieldDescriptor); + } + + @Override + public boolean has(GeneratedMessageV3Internal.Builder builder) { + return builder.hasField(fieldDescriptor); + } + + @Override + public FieldDescriptor get(final GeneratedMessageV3Internal message) { + return message.hasField(fieldDescriptor) ? fieldDescriptor : null; + } + + public FieldDescriptor get(GeneratedMessageV3Internal.Builder builder) { + return builder.hasField(fieldDescriptor) ? fieldDescriptor : null; + } + + @Override + public void clear(final Builder builder) { + builder.clearField(fieldDescriptor); + } + } + + // --------------------------------------------------------------- + + @SuppressWarnings("SameNameButDifferent") + private static class SingularFieldAccessor implements FieldAccessor { + private interface MethodInvoker { + Object get(final GeneratedMessageV3Internal message); + + Object get(GeneratedMessageV3Internal.Builder builder); + + int getOneofFieldNumber(final GeneratedMessageV3Internal message); + + int getOneofFieldNumber(final GeneratedMessageV3Internal.Builder builder); + + void set(final GeneratedMessageV3Internal.Builder builder, final Object value); + + boolean has(final GeneratedMessageV3Internal message); + + boolean has(GeneratedMessageV3Internal.Builder builder); + + void clear(final GeneratedMessageV3Internal.Builder builder); + } + + private static final class ReflectionInvoker implements MethodInvoker { + private final Method getMethod; + private final Method getMethodBuilder; + private final Method setMethod; + private final Method hasMethod; + private final Method hasMethodBuilder; + private final Method clearMethod; + private final Method caseMethod; + private final Method caseMethodBuilder; + + ReflectionInvoker( + final FieldDescriptor descriptor, + final String camelCaseName, + final Class messageClass, + final Class> builderClass, + final String containingOneofCamelCaseName, + boolean isOneofField, + boolean hasHasMethod) { + getMethod = getMethodOrDie(messageClass, "get" + camelCaseName); + getMethodBuilder = getMethodOrDie(builderClass, "get" + camelCaseName); + Class type = getMethod.getReturnType(); + setMethod = getMethodOrDie(builderClass, "set" + camelCaseName, type); + hasMethod = hasHasMethod ? getMethodOrDie(messageClass, "has" + camelCaseName) : null; + hasMethodBuilder = + hasHasMethod ? getMethodOrDie(builderClass, "has" + camelCaseName) : null; + clearMethod = getMethodOrDie(builderClass, "clear" + camelCaseName); + caseMethod = + isOneofField + ? getMethodOrDie(messageClass, "get" + containingOneofCamelCaseName + "Case") + : null; + caseMethodBuilder = + isOneofField + ? getMethodOrDie(builderClass, "get" + containingOneofCamelCaseName + "Case") + : null; + } + + @Override + public Object get(final GeneratedMessageV3Internal message) { + return invokeOrDie(getMethod, message); + } + + @Override + public Object get(GeneratedMessageV3Internal.Builder builder) { + return invokeOrDie(getMethodBuilder, builder); + } + + @Override + public int getOneofFieldNumber(final GeneratedMessageV3Internal message) { + return ((Internal.EnumLite) invokeOrDie(caseMethod, message)).getNumber(); + } + + @Override + public int getOneofFieldNumber(final GeneratedMessageV3Internal.Builder builder) { + return ((Internal.EnumLite) invokeOrDie(caseMethodBuilder, builder)).getNumber(); + } + + @Override + public void set(final GeneratedMessageV3Internal.Builder builder, final Object value) { + // TODO: remove the unused variable + Object unused = invokeOrDie(setMethod, builder, value); + } + + @Override + public boolean has(final GeneratedMessageV3Internal message) { + return (Boolean) invokeOrDie(hasMethod, message); + } + + @Override + public boolean has(GeneratedMessageV3Internal.Builder builder) { + return (Boolean) invokeOrDie(hasMethodBuilder, builder); + } + + @Override + public void clear(final GeneratedMessageV3Internal.Builder builder) { + // TODO: remove the unused variable + Object unused = invokeOrDie(clearMethod, builder); + } + } + + SingularFieldAccessor( + final FieldDescriptor descriptor, + final String camelCaseName, + final Class messageClass, + final Class> builderClass, + final String containingOneofCamelCaseName) { + isOneofField = + descriptor.getRealContainingOneof() != null; + hasHasMethod = + descriptor.getFile().getSyntax() == FileDescriptor.Syntax.EDITIONS && descriptor.hasPresence() + || descriptor.getFile().getSyntax() == FileDescriptor.Syntax.PROTO2 + || descriptor.hasOptionalKeyword() + || (!isOneofField && descriptor.getJavaType() == FieldDescriptor.JavaType.MESSAGE); + ReflectionInvoker reflectionInvoker = + new ReflectionInvoker( + descriptor, + camelCaseName, + messageClass, + builderClass, + containingOneofCamelCaseName, + isOneofField, + hasHasMethod); + field = descriptor; + type = reflectionInvoker.getMethod.getReturnType(); + invoker = getMethodInvoker(reflectionInvoker); + } + + static MethodInvoker getMethodInvoker(ReflectionInvoker accessor) { + return accessor; + } + + // Note: We use Java reflection to call public methods rather than + // access private fields directly as this avoids runtime security + // checks. + protected final Class type; + protected final FieldDescriptor field; + protected final boolean isOneofField; + protected final boolean hasHasMethod; + protected final MethodInvoker invoker; + + @Override + public Object get(final GeneratedMessageV3Internal message) { + return invoker.get(message); + } + + @Override + public Object get(GeneratedMessageV3Internal.Builder builder) { + return invoker.get(builder); + } + + @Override + public Object getRaw(final GeneratedMessageV3Internal message) { + return get(message); + } + + @Override + public void set(final Builder builder, final Object value) { + invoker.set(builder, value); + } + + @Override + public Object getRepeated(final GeneratedMessageV3Internal message, final int index) { + throw new UnsupportedOperationException("getRepeatedField() called on a singular field."); + } + + @Override + public Object getRepeated(GeneratedMessageV3Internal.Builder builder, int index) { + throw new UnsupportedOperationException("getRepeatedField() called on a singular field."); + } + + @Override + public void setRepeated(final Builder builder, final int index, final Object value) { + throw new UnsupportedOperationException("setRepeatedField() called on a singular field."); + } + + @Override + public void addRepeated(final Builder builder, final Object value) { + throw new UnsupportedOperationException("addRepeatedField() called on a singular field."); + } + + @Override + public boolean has(final GeneratedMessageV3Internal message) { + if (!hasHasMethod) { + if (isOneofField) { + return invoker.getOneofFieldNumber(message) == field.getNumber(); + } + return !get(message).equals(field.getDefaultValue()); + } + return invoker.has(message); + } + + @Override + public boolean has(GeneratedMessageV3Internal.Builder builder) { + if (!hasHasMethod) { + if (isOneofField) { + return invoker.getOneofFieldNumber(builder) == field.getNumber(); + } + return !get(builder).equals(field.getDefaultValue()); + } + return invoker.has(builder); + } + + @Override + public int getRepeatedCount(final GeneratedMessageV3Internal message) { + throw new UnsupportedOperationException( + "getRepeatedFieldSize() called on a singular field."); + } + + @Override + public int getRepeatedCount(GeneratedMessageV3Internal.Builder builder) { + throw new UnsupportedOperationException( + "getRepeatedFieldSize() called on a singular field."); + } + + @Override + public void clear(final Builder builder) { + invoker.clear(builder); + } + + @Override + public Message.Builder newBuilder() { + throw new UnsupportedOperationException( + "newBuilderForField() called on a non-Message type."); + } + + @Override + public Message.Builder getBuilder(GeneratedMessageV3Internal.Builder builder) { + throw new UnsupportedOperationException("getFieldBuilder() called on a non-Message type."); + } + + @Override + public Message.Builder getRepeatedBuilder(GeneratedMessageV3Internal.Builder builder, int index) { + throw new UnsupportedOperationException( + "getRepeatedFieldBuilder() called on a non-Message type."); + } + } + + @SuppressWarnings("SameNameButDifferent") + private static class RepeatedFieldAccessor implements FieldAccessor { + interface MethodInvoker { + Object get(final GeneratedMessageV3Internal message); + + Object get(GeneratedMessageV3Internal.Builder builder); + + Object getRepeated(final GeneratedMessageV3Internal message, final int index); + + Object getRepeated(GeneratedMessageV3Internal.Builder builder, int index); + + void setRepeated( + final GeneratedMessageV3Internal.Builder builder, final int index, final Object value); + + void addRepeated(final GeneratedMessageV3Internal.Builder builder, final Object value); + + int getRepeatedCount(final GeneratedMessageV3Internal message); + + int getRepeatedCount(GeneratedMessageV3Internal.Builder builder); + + void clear(final GeneratedMessageV3Internal.Builder builder); + } + + private static final class ReflectionInvoker implements MethodInvoker { + private final Method getMethod; + private final Method getMethodBuilder; + private final Method getRepeatedMethod; + private final Method getRepeatedMethodBuilder; + private final Method setRepeatedMethod; + private final Method addRepeatedMethod; + private final Method getCountMethod; + private final Method getCountMethodBuilder; + private final Method clearMethod; + + ReflectionInvoker( + final FieldDescriptor descriptor, + final String camelCaseName, + final Class messageClass, + final Class> builderClass) { + getMethod = getMethodOrDie(messageClass, "get" + camelCaseName + "List"); + getMethodBuilder = getMethodOrDie(builderClass, "get" + camelCaseName + "List"); + getRepeatedMethod = getMethodOrDie(messageClass, "get" + camelCaseName, Integer.TYPE); + getRepeatedMethodBuilder = + getMethodOrDie(builderClass, "get" + camelCaseName, Integer.TYPE); + Class type = getRepeatedMethod.getReturnType(); + setRepeatedMethod = + getMethodOrDie(builderClass, "set" + camelCaseName, Integer.TYPE, type); + addRepeatedMethod = getMethodOrDie(builderClass, "add" + camelCaseName, type); + getCountMethod = getMethodOrDie(messageClass, "get" + camelCaseName + "Count"); + getCountMethodBuilder = getMethodOrDie(builderClass, "get" + camelCaseName + "Count"); + clearMethod = getMethodOrDie(builderClass, "clear" + camelCaseName); + } + + @Override + public Object get(final GeneratedMessageV3Internal message) { + return invokeOrDie(getMethod, message); + } + + @Override + public Object get(GeneratedMessageV3Internal.Builder builder) { + return invokeOrDie(getMethodBuilder, builder); + } + + @Override + public Object getRepeated(final GeneratedMessageV3Internal message, final int index) { + return invokeOrDie(getRepeatedMethod, message, index); + } + + @Override + public Object getRepeated(GeneratedMessageV3Internal.Builder builder, int index) { + return invokeOrDie(getRepeatedMethodBuilder, builder, index); + } + + @Override + public void setRepeated( + final GeneratedMessageV3Internal.Builder builder, final int index, final Object value) { + // TODO: remove the unused variable + Object unused = invokeOrDie(setRepeatedMethod, builder, index, value); + } + + @Override + public void addRepeated(final GeneratedMessageV3Internal.Builder builder, final Object value) { + // TODO: remove the unused variable + Object unused = invokeOrDie(addRepeatedMethod, builder, value); + } + + @Override + public int getRepeatedCount(final GeneratedMessageV3Internal message) { + return (Integer) invokeOrDie(getCountMethod, message); + } + + @Override + public int getRepeatedCount(GeneratedMessageV3Internal.Builder builder) { + return (Integer) invokeOrDie(getCountMethodBuilder, builder); + } + + @Override + public void clear(final GeneratedMessageV3Internal.Builder builder) { + // TODO: remove the unused variable + Object unused = invokeOrDie(clearMethod, builder); + } + } + + protected final Class type; + protected final MethodInvoker invoker; + + RepeatedFieldAccessor( + final FieldDescriptor descriptor, + final String camelCaseName, + final Class messageClass, + final Class> builderClass) { + ReflectionInvoker reflectionInvoker = + new ReflectionInvoker(descriptor, camelCaseName, messageClass, builderClass); + type = reflectionInvoker.getRepeatedMethod.getReturnType(); + invoker = getMethodInvoker(reflectionInvoker); + } + + static MethodInvoker getMethodInvoker(ReflectionInvoker accessor) { + return accessor; + } + + @Override + public Object get(final GeneratedMessageV3Internal message) { + return invoker.get(message); + } + + @Override + public Object get(GeneratedMessageV3Internal.Builder builder) { + return invoker.get(builder); + } + + @Override + public Object getRaw(final GeneratedMessageV3Internal message) { + return get(message); + } + + @Override + public void set(final Builder builder, final Object value) { + // Add all the elements individually. This serves two purposes: + // 1) Verifies that each element has the correct type. + // 2) Insures that the caller cannot modify the list later on and + // have the modifications be reflected in the message. + clear(builder); + for (final Object element : (List) value) { + addRepeated(builder, element); + } + } + + @Override + public Object getRepeated(final GeneratedMessageV3Internal message, final int index) { + return invoker.getRepeated(message, index); + } + + @Override + public Object getRepeated(GeneratedMessageV3Internal.Builder builder, int index) { + return invoker.getRepeated(builder, index); + } + + @Override + public void setRepeated(final Builder builder, final int index, final Object value) { + invoker.setRepeated(builder, index, value); + } + + @Override + public void addRepeated(final Builder builder, final Object value) { + invoker.addRepeated(builder, value); + } + + @Override + public boolean has(final GeneratedMessageV3Internal message) { + throw new UnsupportedOperationException("hasField() called on a repeated field."); + } + + @Override + public boolean has(GeneratedMessageV3Internal.Builder builder) { + throw new UnsupportedOperationException("hasField() called on a repeated field."); + } + + @Override + public int getRepeatedCount(final GeneratedMessageV3Internal message) { + return invoker.getRepeatedCount(message); + } + + @Override + public int getRepeatedCount(GeneratedMessageV3Internal.Builder builder) { + return invoker.getRepeatedCount(builder); + } + + @Override + public void clear(final Builder builder) { + invoker.clear(builder); + } + + @Override + public Message.Builder newBuilder() { + throw new UnsupportedOperationException( + "newBuilderForField() called on a non-Message type."); + } + + @Override + public Message.Builder getBuilder(GeneratedMessageV3Internal.Builder builder) { + throw new UnsupportedOperationException("getFieldBuilder() called on a non-Message type."); + } + + @Override + public Message.Builder getRepeatedBuilder(GeneratedMessageV3Internal.Builder builder, int index) { + throw new UnsupportedOperationException( + "getRepeatedFieldBuilder() called on a non-Message type."); + } + } + + private static class MapFieldAccessor implements FieldAccessor { + MapFieldAccessor( + final FieldDescriptor descriptor, final Class messageClass) { + field = descriptor; + Method getDefaultInstanceMethod = getMethodOrDie(messageClass, "getDefaultInstance"); + MapFieldReflectionAccessor defaultMapField = + getMapField((GeneratedMessageV3Internal) invokeOrDie(getDefaultInstanceMethod, null)); + mapEntryMessageDefaultInstance = defaultMapField.getMapEntryMessageDefaultInstance(); + } + + private final FieldDescriptor field; + private final Message mapEntryMessageDefaultInstance; + + private MapFieldReflectionAccessor getMapField(GeneratedMessageV3Internal message) { + return message.internalGetMapFieldReflection(field.getNumber()); + } + + private MapFieldReflectionAccessor getMapField(GeneratedMessageV3Internal.Builder builder) { + return builder.internalGetMapFieldReflection(field.getNumber()); + } + + private MapFieldReflectionAccessor getMutableMapField(GeneratedMessageV3Internal.Builder builder) { + return builder.internalGetMutableMapFieldReflection(field.getNumber()); + } + + private Message coerceType(Message value) { + if (value == null) { + return null; + } + if (mapEntryMessageDefaultInstance.getClass().isInstance(value)) { + return value; + } + // The value is not the exact right message type. However, if it + // is an alternative implementation of the same type -- e.g. a + // DynamicMessage -- we should accept it. In this case we can make + // a copy of the message. + return mapEntryMessageDefaultInstance.toBuilder().mergeFrom(value).build(); + } + + @Override + public Object get(GeneratedMessageV3Internal message) { + List result = new ArrayList<>(); + for (int i = 0; i < getRepeatedCount(message); i++) { + result.add(getRepeated(message, i)); + } + return Collections.unmodifiableList(result); + } + + @Override + public Object get(Builder builder) { + List result = new ArrayList<>(); + for (int i = 0; i < getRepeatedCount(builder); i++) { + result.add(getRepeated(builder, i)); + } + return Collections.unmodifiableList(result); + } + + @Override + public Object getRaw(GeneratedMessageV3Internal message) { + return get(message); + } + + @Override + public void set(Builder builder, Object value) { + clear(builder); + for (Object entry : (List) value) { + addRepeated(builder, entry); + } + } + + @Override + public Object getRepeated(GeneratedMessageV3Internal message, int index) { + return getMapField(message).getList().get(index); + } + + @Override + public Object getRepeated(Builder builder, int index) { + return getMapField(builder).getList().get(index); + } + + @Override + public void setRepeated(Builder builder, int index, Object value) { + getMutableMapField(builder).getMutableList().set(index, coerceType((Message) value)); + } + + @Override + public void addRepeated(Builder builder, Object value) { + getMutableMapField(builder).getMutableList().add(coerceType((Message) value)); + } + + @Override + public boolean has(GeneratedMessageV3Internal message) { + throw new UnsupportedOperationException("hasField() is not supported for repeated fields."); + } + + @Override + public boolean has(Builder builder) { + throw new UnsupportedOperationException("hasField() is not supported for repeated fields."); + } + + @Override + public int getRepeatedCount(GeneratedMessageV3Internal message) { + return getMapField(message).getList().size(); + } + + @Override + public int getRepeatedCount(Builder builder) { + return getMapField(builder).getList().size(); + } + + @Override + public void clear(Builder builder) { + getMutableMapField(builder).getMutableList().clear(); + } + + @Override + public Message.Builder newBuilder() { + return mapEntryMessageDefaultInstance.newBuilderForType(); + } + + @Override + public Message.Builder getBuilder(Builder builder) { + throw new UnsupportedOperationException("Nested builder not supported for map fields."); + } + + @Override + public Message.Builder getRepeatedBuilder(Builder builder, int index) { + throw new UnsupportedOperationException("Map fields cannot be repeated"); + } + } + + // --------------------------------------------------------------- + + private static final class SingularEnumFieldAccessor extends SingularFieldAccessor { + SingularEnumFieldAccessor( + final FieldDescriptor descriptor, + final String camelCaseName, + final Class messageClass, + final Class> builderClass, + final String containingOneofCamelCaseName) { + super(descriptor, camelCaseName, messageClass, builderClass, containingOneofCamelCaseName); + + enumDescriptor = descriptor.getEnumType(); + + valueOfMethod = getMethodOrDie(type, "valueOf", EnumValueDescriptor.class); + getValueDescriptorMethod = getMethodOrDie(type, "getValueDescriptor"); + + supportUnknownEnumValue = !descriptor.legacyEnumFieldTreatedAsClosed(); + if (supportUnknownEnumValue) { + getValueMethod = getMethodOrDie(messageClass, "get" + camelCaseName + "Value"); + getValueMethodBuilder = getMethodOrDie(builderClass, "get" + camelCaseName + "Value"); + setValueMethod = getMethodOrDie(builderClass, "set" + camelCaseName + "Value", int.class); + } + } + + private final EnumDescriptor enumDescriptor; + + private final Method valueOfMethod; + private final Method getValueDescriptorMethod; + + private final boolean supportUnknownEnumValue; + private Method getValueMethod; + private Method getValueMethodBuilder; + private Method setValueMethod; + + @Override + public Object get(final GeneratedMessageV3Internal message) { + if (supportUnknownEnumValue) { + int value = (Integer) invokeOrDie(getValueMethod, message); + return enumDescriptor.findValueByNumberCreatingIfUnknown(value); + } + return invokeOrDie(getValueDescriptorMethod, super.get(message)); + } + + @Override + public Object get(final GeneratedMessageV3Internal.Builder builder) { + if (supportUnknownEnumValue) { + int value = (Integer) invokeOrDie(getValueMethodBuilder, builder); + return enumDescriptor.findValueByNumberCreatingIfUnknown(value); + } + return invokeOrDie(getValueDescriptorMethod, super.get(builder)); + } + + @Override + public void set(final Builder builder, final Object value) { + if (supportUnknownEnumValue) { + // TODO: remove the unused variable + Object unused = + invokeOrDie(setValueMethod, builder, ((EnumValueDescriptor) value).getNumber()); + return; + } + super.set(builder, invokeOrDie(valueOfMethod, null, value)); + } + } + + private static final class RepeatedEnumFieldAccessor extends RepeatedFieldAccessor { + RepeatedEnumFieldAccessor( + final FieldDescriptor descriptor, + final String camelCaseName, + final Class messageClass, + final Class> builderClass) { + super(descriptor, camelCaseName, messageClass, builderClass); + + enumDescriptor = descriptor.getEnumType(); + + valueOfMethod = getMethodOrDie(type, "valueOf", EnumValueDescriptor.class); + getValueDescriptorMethod = getMethodOrDie(type, "getValueDescriptor"); + + supportUnknownEnumValue = !descriptor.legacyEnumFieldTreatedAsClosed(); + if (supportUnknownEnumValue) { + getRepeatedValueMethod = + getMethodOrDie(messageClass, "get" + camelCaseName + "Value", int.class); + getRepeatedValueMethodBuilder = + getMethodOrDie(builderClass, "get" + camelCaseName + "Value", int.class); + setRepeatedValueMethod = + getMethodOrDie(builderClass, "set" + camelCaseName + "Value", int.class, int.class); + addRepeatedValueMethod = + getMethodOrDie(builderClass, "add" + camelCaseName + "Value", int.class); + } + } + + private final EnumDescriptor enumDescriptor; + + private final Method valueOfMethod; + private final Method getValueDescriptorMethod; + + private final boolean supportUnknownEnumValue; + + private Method getRepeatedValueMethod; + private Method getRepeatedValueMethodBuilder; + private Method setRepeatedValueMethod; + private Method addRepeatedValueMethod; + + @Override + public Object get(final GeneratedMessageV3Internal message) { + final List newList = new ArrayList<>(); + final int size = getRepeatedCount(message); + for (int i = 0; i < size; i++) { + newList.add(getRepeated(message, i)); + } + return Collections.unmodifiableList(newList); + } + + @Override + public Object get(final GeneratedMessageV3Internal.Builder builder) { + final List newList = new ArrayList<>(); + final int size = getRepeatedCount(builder); + for (int i = 0; i < size; i++) { + newList.add(getRepeated(builder, i)); + } + return Collections.unmodifiableList(newList); + } + + @Override + public Object getRepeated(final GeneratedMessageV3Internal message, final int index) { + if (supportUnknownEnumValue) { + int value = (Integer) invokeOrDie(getRepeatedValueMethod, message, index); + return enumDescriptor.findValueByNumberCreatingIfUnknown(value); + } + return invokeOrDie(getValueDescriptorMethod, super.getRepeated(message, index)); + } + + @Override + public Object getRepeated(final GeneratedMessageV3Internal.Builder builder, final int index) { + if (supportUnknownEnumValue) { + int value = (Integer) invokeOrDie(getRepeatedValueMethodBuilder, builder, index); + return enumDescriptor.findValueByNumberCreatingIfUnknown(value); + } + return invokeOrDie(getValueDescriptorMethod, super.getRepeated(builder, index)); + } + + @Override + public void setRepeated(final Builder builder, final int index, final Object value) { + if (supportUnknownEnumValue) { + // TODO: remove the unused variable + Object unused = + invokeOrDie( + setRepeatedValueMethod, + builder, + index, + ((EnumValueDescriptor) value).getNumber()); + return; + } + super.setRepeated(builder, index, invokeOrDie(valueOfMethod, null, value)); + } + + @Override + public void addRepeated(final Builder builder, final Object value) { + if (supportUnknownEnumValue) { + // TODO: remove the unused variable + Object unused = + invokeOrDie( + addRepeatedValueMethod, builder, ((EnumValueDescriptor) value).getNumber()); + return; + } + super.addRepeated(builder, invokeOrDie(valueOfMethod, null, value)); + } + } + + // --------------------------------------------------------------- + + /** + * Field accessor for string fields. + * + *

This class makes getFooBytes() and setFooBytes() available for reflection API so that + * reflection based serialize/parse functions can access the raw bytes of the field to preserve + * non-UTF8 bytes in the string. + * + *

This ensures the serialize/parse round-trip safety, which is important for servers which + * forward messages. + */ + private static final class SingularStringFieldAccessor extends SingularFieldAccessor { + SingularStringFieldAccessor( + final FieldDescriptor descriptor, + final String camelCaseName, + final Class messageClass, + final Class> builderClass, + final String containingOneofCamelCaseName) { + super(descriptor, camelCaseName, messageClass, builderClass, containingOneofCamelCaseName); + getBytesMethod = getMethodOrDie(messageClass, "get" + camelCaseName + "Bytes"); + setBytesMethodBuilder = + getMethodOrDie(builderClass, "set" + camelCaseName + "Bytes", ByteString.class); + } + + private final Method getBytesMethod; + private final Method setBytesMethodBuilder; + + @Override + public Object getRaw(final GeneratedMessageV3Internal message) { + return invokeOrDie(getBytesMethod, message); + } + + @Override + public void set(GeneratedMessageV3Internal.Builder builder, Object value) { + if (value instanceof ByteString) { + // TODO: remove the unused variable + Object unused = invokeOrDie(setBytesMethodBuilder, builder, value); + } else { + super.set(builder, value); + } + } + } + + // --------------------------------------------------------------- + + private static final class SingularMessageFieldAccessor extends SingularFieldAccessor { + SingularMessageFieldAccessor( + final FieldDescriptor descriptor, + final String camelCaseName, + final Class messageClass, + final Class> builderClass, + final String containingOneofCamelCaseName) { + super(descriptor, camelCaseName, messageClass, builderClass, containingOneofCamelCaseName); + + newBuilderMethod = getMethodOrDie(type, "newBuilder"); + getBuilderMethodBuilder = getMethodOrDie(builderClass, "get" + camelCaseName + "Builder"); + } + + private final Method newBuilderMethod; + private final Method getBuilderMethodBuilder; + + private Object coerceType(final Object value) { + if (type.isInstance(value)) { + return value; + } else { + // The value is not the exact right message type. However, if it + // is an alternative implementation of the same type -- e.g. a + // DynamicMessage -- we should accept it. In this case we can make + // a copy of the message. + return ((Message.Builder) invokeOrDie(newBuilderMethod, null)) + .mergeFrom((Message) value) + .buildPartial(); + } + } + + @Override + public void set(final Builder builder, final Object value) { + super.set(builder, coerceType(value)); + } + + @Override + public Message.Builder newBuilder() { + return (Message.Builder) invokeOrDie(newBuilderMethod, null); + } + + @Override + public Message.Builder getBuilder(GeneratedMessageV3Internal.Builder builder) { + return (Message.Builder) invokeOrDie(getBuilderMethodBuilder, builder); + } + } + + private static final class RepeatedMessageFieldAccessor extends RepeatedFieldAccessor { + RepeatedMessageFieldAccessor( + final FieldDescriptor descriptor, + final String camelCaseName, + final Class messageClass, + final Class> builderClass) { + super(descriptor, camelCaseName, messageClass, builderClass); + + newBuilderMethod = getMethodOrDie(type, "newBuilder"); + getBuilderMethodBuilder = + getMethodOrDie(builderClass, "get" + camelCaseName + "Builder", Integer.TYPE); + } + + private final Method newBuilderMethod; + private final Method getBuilderMethodBuilder; + + private Object coerceType(final Object value) { + if (type.isInstance(value)) { + return value; + } else { + // The value is not the exact right message type. However, if it + // is an alternative implementation of the same type -- e.g. a + // DynamicMessage -- we should accept it. In this case we can make + // a copy of the message. + return ((Message.Builder) invokeOrDie(newBuilderMethod, null)) + .mergeFrom((Message) value) + .build(); + } + } + + @Override + public void setRepeated(final Builder builder, final int index, final Object value) { + super.setRepeated(builder, index, coerceType(value)); + } + + @Override + public void addRepeated(final Builder builder, final Object value) { + super.addRepeated(builder, coerceType(value)); + } + + @Override + public Message.Builder newBuilder() { + return (Message.Builder) invokeOrDie(newBuilderMethod, null); + } + + @Override + public Message.Builder getRepeatedBuilder( + final GeneratedMessageV3Internal.Builder builder, final int index) { + return (Message.Builder) invokeOrDie(getBuilderMethodBuilder, builder, index); + } + } + } + + /** + * Replaces this object in the output stream with a serialized form. Part of Java's serialization + * magic. Generated sub-classes must override this method by calling {@code return + * super.writeReplace();} + * + * @return a SerializedForm of this message + */ + protected Object writeReplace() throws ObjectStreamException { + return new SerializedForm(this); + } + + /** + * Checks that the {@link Extension} is non-Lite and returns it as a {@link GeneratedExtension}. + */ + private static , T> + Extension checkNotLite(ExtensionLite extension) { + if (extension.isLite()) { + throw new IllegalArgumentException("Expected non-lite extension."); + } + + return (Extension) extension; + } + + protected static boolean isStringEmpty(final Object value) { + if (value instanceof String) { + return ((String) value).isEmpty(); + } else { + return ((ByteString) value).isEmpty(); + } + } + + protected static int computeStringSize(final int fieldNumber, final Object value) { + if (value instanceof String) { + return CodedOutputStream.computeStringSize(fieldNumber, (String) value); + } else { + return CodedOutputStream.computeBytesSize(fieldNumber, (ByteString) value); + } + } + + protected static int computeStringSizeNoTag(final Object value) { + if (value instanceof String) { + return CodedOutputStream.computeStringSizeNoTag((String) value); + } else { + return CodedOutputStream.computeBytesSizeNoTag((ByteString) value); + } + } + + protected static void writeString( + CodedOutputStream output, final int fieldNumber, final Object value) throws IOException { + if (value instanceof String) { + output.writeString(fieldNumber, (String) value); + } else { + output.writeBytes(fieldNumber, (ByteString) value); + } + } + + protected static void writeStringNoTag(CodedOutputStream output, final Object value) + throws IOException { + if (value instanceof String) { + output.writeStringNoTag((String) value); + } else { + output.writeBytesNoTag((ByteString) value); + } + } + + protected static void serializeIntegerMapTo( + CodedOutputStream out, + MapField field, + MapEntry defaultEntry, + int fieldNumber) + throws IOException { + Map m = field.getMap(); + if (!out.isSerializationDeterministic()) { + serializeMapTo(out, m, defaultEntry, fieldNumber); + return; + } + // Sorting the unboxed keys and then look up the values during serialization is 2x faster + // than sorting map entries with a custom comparator directly. + int[] keys = new int[m.size()]; + int index = 0; + for (int k : m.keySet()) { + keys[index++] = k; + } + Arrays.sort(keys); + for (int key : keys) { + out.writeMessage( + fieldNumber, defaultEntry.newBuilderForType().setKey(key).setValue(m.get(key)).build()); + } + } + + protected static void serializeLongMapTo( + CodedOutputStream out, + MapField field, + MapEntry defaultEntry, + int fieldNumber) + throws IOException { + Map m = field.getMap(); + if (!out.isSerializationDeterministic()) { + serializeMapTo(out, m, defaultEntry, fieldNumber); + return; + } + + long[] keys = new long[m.size()]; + int index = 0; + for (long k : m.keySet()) { + keys[index++] = k; + } + Arrays.sort(keys); + for (long key : keys) { + out.writeMessage( + fieldNumber, defaultEntry.newBuilderForType().setKey(key).setValue(m.get(key)).build()); + } + } + + protected static void serializeStringMapTo( + CodedOutputStream out, + MapField field, + MapEntry defaultEntry, + int fieldNumber) + throws IOException { + Map m = field.getMap(); + if (!out.isSerializationDeterministic()) { + serializeMapTo(out, m, defaultEntry, fieldNumber); + return; + } + + // Sorting the String keys and then look up the values during serialization is 25% faster than + // sorting map entries with a custom comparator directly. + String[] keys = new String[m.size()]; + keys = m.keySet().toArray(keys); + Arrays.sort(keys); + for (String key : keys) { + out.writeMessage( + fieldNumber, defaultEntry.newBuilderForType().setKey(key).setValue(m.get(key)).build()); + } + } + + protected static void serializeBooleanMapTo( + CodedOutputStream out, + MapField field, + MapEntry defaultEntry, + int fieldNumber) + throws IOException { + Map m = field.getMap(); + if (!out.isSerializationDeterministic()) { + serializeMapTo(out, m, defaultEntry, fieldNumber); + return; + } + maybeSerializeBooleanEntryTo(out, m, defaultEntry, fieldNumber, false); + maybeSerializeBooleanEntryTo(out, m, defaultEntry, fieldNumber, true); + } + + private static void maybeSerializeBooleanEntryTo( + CodedOutputStream out, + Map m, + MapEntry defaultEntry, + int fieldNumber, + boolean key) + throws IOException { + if (m.containsKey(key)) { + out.writeMessage( + fieldNumber, defaultEntry.newBuilderForType().setKey(key).setValue(m.get(key)).build()); + } + } + + /** Serialize the map using the iteration order. */ + private static void serializeMapTo( + CodedOutputStream out, Map m, MapEntry defaultEntry, int fieldNumber) + throws IOException { + for (Map.Entry entry : m.entrySet()) { + out.writeMessage( + fieldNumber, + defaultEntry + .newBuilderForType() + .setKey(entry.getKey()) + .setValue(entry.getValue()) + .build()); + } + } +} diff --git a/protobuf-api/src/main/java/com/google/protobuf/Int32Value.java b/protobuf-api/src/main/java/com/google/protobuf/Int32Value.java index b6ca2bb..3891573 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/Int32Value.java +++ b/protobuf-api/src/main/java/com/google/protobuf/Int32Value.java @@ -14,12 +14,12 @@ * Protobuf type {@code google.protobuf.Int32Value} */ public final class Int32Value extends - com.google.protobuf.FlattenedGeneratedMessageV3 implements + com.google.protobuf.GeneratedMessageV3Internal implements // @@protoc_insertion_point(message_implements:google.protobuf.Int32Value) Int32ValueOrBuilder { private static final long serialVersionUID = 0L; // Use Int32Value.newBuilder() to construct. - private Int32Value(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { + private Int32Value(com.google.protobuf.GeneratedMessageV3Internal.Builder builder) { super(builder); } private Int32Value() { @@ -38,7 +38,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.WrappersProto.internal_static_google_protobuf_Int32Value_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -159,20 +159,20 @@ public static com.google.protobuf.Int32Value parseFrom( } public static com.google.protobuf.Int32Value parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.Int32Value parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Int32Value parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -180,20 +180,20 @@ public static com.google.protobuf.Int32Value parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Int32Value parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.Int32Value parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -213,7 +213,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -227,7 +227,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.Int32Value} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements + com.google.protobuf.GeneratedMessageV3Internal.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.Int32Value) com.google.protobuf.Int32ValueOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -236,7 +236,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.WrappersProto.internal_static_google_protobuf_Int32Value_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -249,7 +249,7 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); } diff --git a/protobuf-api/src/main/java/com/google/protobuf/Int64Value.java b/protobuf-api/src/main/java/com/google/protobuf/Int64Value.java index 250d70d..19b499c 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/Int64Value.java +++ b/protobuf-api/src/main/java/com/google/protobuf/Int64Value.java @@ -14,12 +14,12 @@ * Protobuf type {@code google.protobuf.Int64Value} */ public final class Int64Value extends - com.google.protobuf.FlattenedGeneratedMessageV3 implements + com.google.protobuf.GeneratedMessageV3Internal implements // @@protoc_insertion_point(message_implements:google.protobuf.Int64Value) Int64ValueOrBuilder { private static final long serialVersionUID = 0L; // Use Int64Value.newBuilder() to construct. - private Int64Value(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { + private Int64Value(com.google.protobuf.GeneratedMessageV3Internal.Builder builder) { super(builder); } private Int64Value() { @@ -38,7 +38,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.WrappersProto.internal_static_google_protobuf_Int64Value_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -160,20 +160,20 @@ public static com.google.protobuf.Int64Value parseFrom( } public static com.google.protobuf.Int64Value parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.Int64Value parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Int64Value parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -181,20 +181,20 @@ public static com.google.protobuf.Int64Value parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Int64Value parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.Int64Value parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -214,7 +214,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -228,7 +228,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.Int64Value} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements + com.google.protobuf.GeneratedMessageV3Internal.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.Int64Value) com.google.protobuf.Int64ValueOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -237,7 +237,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.WrappersProto.internal_static_google_protobuf_Int64Value_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -250,7 +250,7 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); } diff --git a/protobuf-api/src/main/java/com/google/protobuf/ListValue.java b/protobuf-api/src/main/java/com/google/protobuf/ListValue.java index 05fbedc..e4e6496 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/ListValue.java +++ b/protobuf-api/src/main/java/com/google/protobuf/ListValue.java @@ -14,12 +14,12 @@ * Protobuf type {@code google.protobuf.ListValue} */ public final class ListValue extends - com.google.protobuf.FlattenedGeneratedMessageV3 implements + com.google.protobuf.GeneratedMessageV3Internal implements // @@protoc_insertion_point(message_implements:google.protobuf.ListValue) ListValueOrBuilder { private static final long serialVersionUID = 0L; // Use ListValue.newBuilder() to construct. - private ListValue(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { + private ListValue(com.google.protobuf.GeneratedMessageV3Internal.Builder builder) { super(builder); } private ListValue() { @@ -39,7 +39,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.StructProto.internal_static_google_protobuf_ListValue_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -208,20 +208,20 @@ public static com.google.protobuf.ListValue parseFrom( } public static com.google.protobuf.ListValue parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.ListValue parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.ListValue parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -229,20 +229,20 @@ public static com.google.protobuf.ListValue parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.ListValue parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.ListValue parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -262,7 +262,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -276,7 +276,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.ListValue} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements + com.google.protobuf.GeneratedMessageV3Internal.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.ListValue) com.google.protobuf.ListValueOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -285,7 +285,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.StructProto.internal_static_google_protobuf_ListValue_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -298,7 +298,7 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); } @@ -424,7 +424,7 @@ public Builder mergeFrom(com.google.protobuf.ListValue other) { values_ = other.values_; bitField0_ = (bitField0_ & ~0x00000001); valuesBuilder_ = - com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.GeneratedMessageV3Internal.alwaysUseFieldBuilders ? getValuesFieldBuilder() : null; } else { valuesBuilder_.addAllMessages(other.values_); diff --git a/protobuf-api/src/main/java/com/google/protobuf/Method.java b/protobuf-api/src/main/java/com/google/protobuf/Method.java index 208b8b9..f38d63b 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/Method.java +++ b/protobuf-api/src/main/java/com/google/protobuf/Method.java @@ -12,12 +12,12 @@ * Protobuf type {@code google.protobuf.Method} */ public final class Method extends - com.google.protobuf.FlattenedGeneratedMessageV3 implements + com.google.protobuf.GeneratedMessageV3Internal implements // @@protoc_insertion_point(message_implements:google.protobuf.Method) MethodOrBuilder { private static final long serialVersionUID = 0L; // Use Method.newBuilder() to construct. - private Method(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { + private Method(com.google.protobuf.GeneratedMessageV3Internal.Builder builder) { super(builder); } private Method() { @@ -41,7 +41,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.ApiProto.internal_static_google_protobuf_Method_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -320,17 +320,17 @@ public final boolean isInitialized() { @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(name_)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 1, name_); + if (!com.google.protobuf.GeneratedMessageV3Internal.isStringEmpty(name_)) { + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 1, name_); } - if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(requestTypeUrl_)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 2, requestTypeUrl_); + if (!com.google.protobuf.GeneratedMessageV3Internal.isStringEmpty(requestTypeUrl_)) { + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 2, requestTypeUrl_); } if (requestStreaming_ != false) { output.writeBool(3, requestStreaming_); } - if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(responseTypeUrl_)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 4, responseTypeUrl_); + if (!com.google.protobuf.GeneratedMessageV3Internal.isStringEmpty(responseTypeUrl_)) { + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 4, responseTypeUrl_); } if (responseStreaming_ != false) { output.writeBool(5, responseStreaming_); @@ -350,18 +350,18 @@ public int getSerializedSize() { if (size != -1) return size; size = 0; - if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(name_)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(1, name_); + if (!com.google.protobuf.GeneratedMessageV3Internal.isStringEmpty(name_)) { + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(1, name_); } - if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(requestTypeUrl_)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(2, requestTypeUrl_); + if (!com.google.protobuf.GeneratedMessageV3Internal.isStringEmpty(requestTypeUrl_)) { + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(2, requestTypeUrl_); } if (requestStreaming_ != false) { size += com.google.protobuf.CodedOutputStream .computeBoolSize(3, requestStreaming_); } - if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(responseTypeUrl_)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(4, responseTypeUrl_); + if (!com.google.protobuf.GeneratedMessageV3Internal.isStringEmpty(responseTypeUrl_)) { + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(4, responseTypeUrl_); } if (responseStreaming_ != false) { size += com.google.protobuf.CodedOutputStream @@ -471,20 +471,20 @@ public static com.google.protobuf.Method parseFrom( } public static com.google.protobuf.Method parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.Method parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Method parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -492,20 +492,20 @@ public static com.google.protobuf.Method parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Method parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.Method parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -525,7 +525,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -537,7 +537,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.Method} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements + com.google.protobuf.GeneratedMessageV3Internal.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.Method) com.google.protobuf.MethodOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -546,7 +546,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.ApiProto.internal_static_google_protobuf_Method_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -559,7 +559,7 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); } @@ -730,7 +730,7 @@ public Builder mergeFrom(com.google.protobuf.Method other) { options_ = other.options_; bitField0_ = (bitField0_ & ~0x00000020); optionsBuilder_ = - com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.GeneratedMessageV3Internal.alwaysUseFieldBuilders ? getOptionsFieldBuilder() : null; } else { optionsBuilder_.addAllMessages(other.options_); diff --git a/protobuf-api/src/main/java/com/google/protobuf/Mixin.java b/protobuf-api/src/main/java/com/google/protobuf/Mixin.java index 3731fe4..b73f95d 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/Mixin.java +++ b/protobuf-api/src/main/java/com/google/protobuf/Mixin.java @@ -89,12 +89,12 @@ * Protobuf type {@code google.protobuf.Mixin} */ public final class Mixin extends - com.google.protobuf.FlattenedGeneratedMessageV3 implements + com.google.protobuf.GeneratedMessageV3Internal implements // @@protoc_insertion_point(message_implements:google.protobuf.Mixin) MixinOrBuilder { private static final long serialVersionUID = 0L; // Use Mixin.newBuilder() to construct. - private Mixin(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { + private Mixin(com.google.protobuf.GeneratedMessageV3Internal.Builder builder) { super(builder); } private Mixin() { @@ -115,7 +115,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.ApiProto.internal_static_google_protobuf_Mixin_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -232,11 +232,11 @@ public final boolean isInitialized() { @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(name_)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 1, name_); + if (!com.google.protobuf.GeneratedMessageV3Internal.isStringEmpty(name_)) { + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 1, name_); } - if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(root_)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 2, root_); + if (!com.google.protobuf.GeneratedMessageV3Internal.isStringEmpty(root_)) { + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 2, root_); } getUnknownFields().writeTo(output); } @@ -247,11 +247,11 @@ public int getSerializedSize() { if (size != -1) return size; size = 0; - if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(name_)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(1, name_); + if (!com.google.protobuf.GeneratedMessageV3Internal.isStringEmpty(name_)) { + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(1, name_); } - if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(root_)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(2, root_); + if (!com.google.protobuf.GeneratedMessageV3Internal.isStringEmpty(root_)) { + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(2, root_); } size += getUnknownFields().getSerializedSize(); memoizedSize = size; @@ -326,20 +326,20 @@ public static com.google.protobuf.Mixin parseFrom( } public static com.google.protobuf.Mixin parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.Mixin parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Mixin parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -347,20 +347,20 @@ public static com.google.protobuf.Mixin parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Mixin parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.Mixin parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -380,7 +380,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -469,7 +469,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.Mixin} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements + com.google.protobuf.GeneratedMessageV3Internal.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.Mixin) com.google.protobuf.MixinOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -478,7 +478,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.ApiProto.internal_static_google_protobuf_Mixin_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -491,7 +491,7 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); } diff --git a/protobuf-api/src/main/java/com/google/protobuf/Option.java b/protobuf-api/src/main/java/com/google/protobuf/Option.java index dac0036..331d8aa 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/Option.java +++ b/protobuf-api/src/main/java/com/google/protobuf/Option.java @@ -13,12 +13,12 @@ * Protobuf type {@code google.protobuf.Option} */ public final class Option extends - com.google.protobuf.FlattenedGeneratedMessageV3 implements + com.google.protobuf.GeneratedMessageV3Internal implements // @@protoc_insertion_point(message_implements:google.protobuf.Option) OptionOrBuilder { private static final long serialVersionUID = 0L; // Use Option.newBuilder() to construct. - private Option(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { + private Option(com.google.protobuf.GeneratedMessageV3Internal.Builder builder) { super(builder); } private Option() { @@ -38,7 +38,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.TypeProto.internal_static_google_protobuf_Option_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -160,8 +160,8 @@ public final boolean isInitialized() { @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(name_)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 1, name_); + if (!com.google.protobuf.GeneratedMessageV3Internal.isStringEmpty(name_)) { + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 1, name_); } if (((bitField0_ & 0x00000001) != 0)) { output.writeMessage(2, getValue()); @@ -175,8 +175,8 @@ public int getSerializedSize() { if (size != -1) return size; size = 0; - if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(name_)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(1, name_); + if (!com.google.protobuf.GeneratedMessageV3Internal.isStringEmpty(name_)) { + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(1, name_); } if (((bitField0_ & 0x00000001) != 0)) { size += com.google.protobuf.CodedOutputStream @@ -260,20 +260,20 @@ public static com.google.protobuf.Option parseFrom( } public static com.google.protobuf.Option parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.Option parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Option parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -281,20 +281,20 @@ public static com.google.protobuf.Option parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Option parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.Option parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -314,7 +314,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -327,7 +327,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.Option} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements + com.google.protobuf.GeneratedMessageV3Internal.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.Option) com.google.protobuf.OptionOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -336,7 +336,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.TypeProto.internal_static_google_protobuf_Option_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -349,12 +349,12 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { - if (com.google.protobuf.FlattenedGeneratedMessageV3 + if (com.google.protobuf.GeneratedMessageV3Internal .alwaysUseFieldBuilders) { getValueFieldBuilder(); } diff --git a/protobuf-api/src/main/java/com/google/protobuf/StringValue.java b/protobuf-api/src/main/java/com/google/protobuf/StringValue.java index 7943deb..d9d3615 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/StringValue.java +++ b/protobuf-api/src/main/java/com/google/protobuf/StringValue.java @@ -14,12 +14,12 @@ * Protobuf type {@code google.protobuf.StringValue} */ public final class StringValue extends - com.google.protobuf.FlattenedGeneratedMessageV3 implements + com.google.protobuf.GeneratedMessageV3Internal implements // @@protoc_insertion_point(message_implements:google.protobuf.StringValue) StringValueOrBuilder { private static final long serialVersionUID = 0L; // Use StringValue.newBuilder() to construct. - private StringValue(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { + private StringValue(com.google.protobuf.GeneratedMessageV3Internal.Builder builder) { super(builder); } private StringValue() { @@ -39,7 +39,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.WrappersProto.internal_static_google_protobuf_StringValue_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -107,8 +107,8 @@ public final boolean isInitialized() { @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(value_)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 1, value_); + if (!com.google.protobuf.GeneratedMessageV3Internal.isStringEmpty(value_)) { + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 1, value_); } getUnknownFields().writeTo(output); } @@ -119,8 +119,8 @@ public int getSerializedSize() { if (size != -1) return size; size = 0; - if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(value_)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(1, value_); + if (!com.google.protobuf.GeneratedMessageV3Internal.isStringEmpty(value_)) { + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(1, value_); } size += getUnknownFields().getSerializedSize(); memoizedSize = size; @@ -191,20 +191,20 @@ public static com.google.protobuf.StringValue parseFrom( } public static com.google.protobuf.StringValue parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.StringValue parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.StringValue parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -212,20 +212,20 @@ public static com.google.protobuf.StringValue parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.StringValue parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.StringValue parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -245,7 +245,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -259,7 +259,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.StringValue} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements + com.google.protobuf.GeneratedMessageV3Internal.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.StringValue) com.google.protobuf.StringValueOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -268,7 +268,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.WrappersProto.internal_static_google_protobuf_StringValue_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -281,7 +281,7 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); } diff --git a/protobuf-api/src/main/java/com/google/protobuf/Struct.java b/protobuf-api/src/main/java/com/google/protobuf/Struct.java index 9ec8a2a..387e27b 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/Struct.java +++ b/protobuf-api/src/main/java/com/google/protobuf/Struct.java @@ -19,12 +19,12 @@ * Protobuf type {@code google.protobuf.Struct} */ public final class Struct extends - com.google.protobuf.FlattenedGeneratedMessageV3 implements + com.google.protobuf.GeneratedMessageV3Internal implements // @@protoc_insertion_point(message_implements:google.protobuf.Struct) StructOrBuilder { private static final long serialVersionUID = 0L; // Use Struct.newBuilder() to construct. - private Struct(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { + private Struct(com.google.protobuf.GeneratedMessageV3Internal.Builder builder) { super(builder); } private Struct() { @@ -55,7 +55,7 @@ protected com.google.protobuf.MapFieldReflectionAccessor internalGetMapFieldRefl } } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.StructProto.internal_static_google_protobuf_Struct_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -171,7 +171,7 @@ public final boolean isInitialized() { @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - com.google.protobuf.FlattenedGeneratedMessageV3 + com.google.protobuf.GeneratedMessageV3Internal .serializeStringMapTo( output, internalGetFields(), @@ -267,20 +267,20 @@ public static com.google.protobuf.Struct parseFrom( } public static com.google.protobuf.Struct parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.Struct parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Struct parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -288,20 +288,20 @@ public static com.google.protobuf.Struct parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Struct parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.Struct parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -321,7 +321,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -340,7 +340,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.Struct} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements + com.google.protobuf.GeneratedMessageV3Internal.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.Struct) com.google.protobuf.StructOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -371,7 +371,7 @@ protected com.google.protobuf.MapFieldReflectionAccessor internalGetMutableMapFi } } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.StructProto.internal_static_google_protobuf_Struct_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -384,7 +384,7 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); } diff --git a/protobuf-api/src/main/java/com/google/protobuf/StructProto.java b/protobuf-api/src/main/java/com/google/protobuf/StructProto.java index 5bf2429..42bb4dd 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/StructProto.java +++ b/protobuf-api/src/main/java/com/google/protobuf/StructProto.java @@ -18,22 +18,22 @@ public static void registerAllExtensions( static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_Struct_descriptor; static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_Struct_fieldAccessorTable; static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_Struct_FieldsEntry_descriptor; static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_Struct_FieldsEntry_fieldAccessorTable; static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_Value_descriptor; static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_Value_fieldAccessorTable; static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_ListValue_descriptor; static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_ListValue_fieldAccessorTable; public static com.google.protobuf.Descriptors.FileDescriptor @@ -68,25 +68,25 @@ public static void registerAllExtensions( internal_static_google_protobuf_Struct_descriptor = getDescriptor().getMessageTypes().get(0); internal_static_google_protobuf_Struct_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_Struct_descriptor, new java.lang.String[] { "Fields", }); internal_static_google_protobuf_Struct_FieldsEntry_descriptor = internal_static_google_protobuf_Struct_descriptor.getNestedTypes().get(0); internal_static_google_protobuf_Struct_FieldsEntry_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_Struct_FieldsEntry_descriptor, new java.lang.String[] { "Key", "Value", }); internal_static_google_protobuf_Value_descriptor = getDescriptor().getMessageTypes().get(1); internal_static_google_protobuf_Value_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_Value_descriptor, new java.lang.String[] { "NullValue", "NumberValue", "StringValue", "BoolValue", "StructValue", "ListValue", "Kind", }); internal_static_google_protobuf_ListValue_descriptor = getDescriptor().getMessageTypes().get(2); internal_static_google_protobuf_ListValue_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_ListValue_descriptor, new java.lang.String[] { "Values", }); } diff --git a/protobuf-api/src/main/java/com/google/protobuf/Timestamp.java b/protobuf-api/src/main/java/com/google/protobuf/Timestamp.java index b7eb723..a494a67 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/Timestamp.java +++ b/protobuf-api/src/main/java/com/google/protobuf/Timestamp.java @@ -100,12 +100,12 @@ * Protobuf type {@code google.protobuf.Timestamp} */ public final class Timestamp extends - com.google.protobuf.FlattenedGeneratedMessageV3 implements + com.google.protobuf.GeneratedMessageV3Internal implements // @@protoc_insertion_point(message_implements:google.protobuf.Timestamp) TimestampOrBuilder { private static final long serialVersionUID = 0L; // Use Timestamp.newBuilder() to construct. - private Timestamp(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { + private Timestamp(com.google.protobuf.GeneratedMessageV3Internal.Builder builder) { super(builder); } private Timestamp() { @@ -124,7 +124,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.TimestampProto.internal_static_google_protobuf_Timestamp_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -277,20 +277,20 @@ public static com.google.protobuf.Timestamp parseFrom( } public static com.google.protobuf.Timestamp parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.Timestamp parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Timestamp parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -298,20 +298,20 @@ public static com.google.protobuf.Timestamp parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Timestamp parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.Timestamp parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -331,7 +331,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -431,7 +431,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.Timestamp} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements + com.google.protobuf.GeneratedMessageV3Internal.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.Timestamp) com.google.protobuf.TimestampOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -440,7 +440,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.TimestampProto.internal_static_google_protobuf_Timestamp_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -453,7 +453,7 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); } diff --git a/protobuf-api/src/main/java/com/google/protobuf/TimestampProto.java b/protobuf-api/src/main/java/com/google/protobuf/TimestampProto.java index 9b784c2..2512638 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/TimestampProto.java +++ b/protobuf-api/src/main/java/com/google/protobuf/TimestampProto.java @@ -18,7 +18,7 @@ public static void registerAllExtensions( static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_Timestamp_descriptor; static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_Timestamp_fieldAccessorTable; public static com.google.protobuf.Descriptors.FileDescriptor @@ -43,7 +43,7 @@ public static void registerAllExtensions( internal_static_google_protobuf_Timestamp_descriptor = getDescriptor().getMessageTypes().get(0); internal_static_google_protobuf_Timestamp_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_Timestamp_descriptor, new java.lang.String[] { "Seconds", "Nanos", }); } diff --git a/protobuf-api/src/main/java/com/google/protobuf/Type.java b/protobuf-api/src/main/java/com/google/protobuf/Type.java index 0b7261f..1b70195 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/Type.java +++ b/protobuf-api/src/main/java/com/google/protobuf/Type.java @@ -12,12 +12,12 @@ * Protobuf type {@code google.protobuf.Type} */ public final class Type extends - com.google.protobuf.FlattenedGeneratedMessageV3 implements + com.google.protobuf.GeneratedMessageV3Internal implements // @@protoc_insertion_point(message_implements:google.protobuf.Type) TypeOrBuilder { private static final long serialVersionUID = 0L; // Use Type.newBuilder() to construct. - private Type(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { + private Type(com.google.protobuf.GeneratedMessageV3Internal.Builder builder) { super(builder); } private Type() { @@ -43,7 +43,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.TypeProto.internal_static_google_protobuf_Type_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -398,14 +398,14 @@ public final boolean isInitialized() { @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(name_)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 1, name_); + if (!com.google.protobuf.GeneratedMessageV3Internal.isStringEmpty(name_)) { + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 1, name_); } for (int i = 0; i < fields_.size(); i++) { output.writeMessage(2, fields_.get(i)); } for (int i = 0; i < oneofs_.size(); i++) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 3, oneofs_.getRaw(i)); + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 3, oneofs_.getRaw(i)); } for (int i = 0; i < options_.size(); i++) { output.writeMessage(4, options_.get(i)); @@ -416,8 +416,8 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) if (syntax_ != com.google.protobuf.Syntax.SYNTAX_PROTO2.getNumber()) { output.writeEnum(6, syntax_); } - if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(edition_)) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 7, edition_); + if (!com.google.protobuf.GeneratedMessageV3Internal.isStringEmpty(edition_)) { + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 7, edition_); } getUnknownFields().writeTo(output); } @@ -428,8 +428,8 @@ public int getSerializedSize() { if (size != -1) return size; size = 0; - if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(name_)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(1, name_); + if (!com.google.protobuf.GeneratedMessageV3Internal.isStringEmpty(name_)) { + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(1, name_); } for (int i = 0; i < fields_.size(); i++) { size += com.google.protobuf.CodedOutputStream @@ -455,8 +455,8 @@ public int getSerializedSize() { size += com.google.protobuf.CodedOutputStream .computeEnumSize(6, syntax_); } - if (!com.google.protobuf.FlattenedGeneratedMessageV3.isStringEmpty(edition_)) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(7, edition_); + if (!com.google.protobuf.GeneratedMessageV3Internal.isStringEmpty(edition_)) { + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(7, edition_); } size += getUnknownFields().getSerializedSize(); memoizedSize = size; @@ -561,20 +561,20 @@ public static com.google.protobuf.Type parseFrom( } public static com.google.protobuf.Type parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.Type parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Type parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -582,20 +582,20 @@ public static com.google.protobuf.Type parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Type parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.Type parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -615,7 +615,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -627,7 +627,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.Type} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements + com.google.protobuf.GeneratedMessageV3Internal.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.Type) com.google.protobuf.TypeOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -636,7 +636,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.TypeProto.internal_static_google_protobuf_Type_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -649,12 +649,12 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { - if (com.google.protobuf.FlattenedGeneratedMessageV3 + if (com.google.protobuf.GeneratedMessageV3Internal .alwaysUseFieldBuilders) { getFieldsFieldBuilder(); getOptionsFieldBuilder(); @@ -835,7 +835,7 @@ public Builder mergeFrom(com.google.protobuf.Type other) { fields_ = other.fields_; bitField0_ = (bitField0_ & ~0x00000002); fieldsBuilder_ = - com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.GeneratedMessageV3Internal.alwaysUseFieldBuilders ? getFieldsFieldBuilder() : null; } else { fieldsBuilder_.addAllMessages(other.fields_); @@ -871,7 +871,7 @@ public Builder mergeFrom(com.google.protobuf.Type other) { options_ = other.options_; bitField0_ = (bitField0_ & ~0x00000008); optionsBuilder_ = - com.google.protobuf.FlattenedGeneratedMessageV3.alwaysUseFieldBuilders ? + com.google.protobuf.GeneratedMessageV3Internal.alwaysUseFieldBuilders ? getOptionsFieldBuilder() : null; } else { optionsBuilder_.addAllMessages(other.options_); diff --git a/protobuf-api/src/main/java/com/google/protobuf/TypeProto.java b/protobuf-api/src/main/java/com/google/protobuf/TypeProto.java index b94a6aa..03a0e71 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/TypeProto.java +++ b/protobuf-api/src/main/java/com/google/protobuf/TypeProto.java @@ -18,27 +18,27 @@ public static void registerAllExtensions( static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_Type_descriptor; static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_Type_fieldAccessorTable; static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_Field_descriptor; static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_Field_fieldAccessorTable; static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_Enum_descriptor; static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_Enum_fieldAccessorTable; static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_EnumValue_descriptor; static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_EnumValue_fieldAccessorTable; static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_Option_descriptor; static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_Option_fieldAccessorTable; public static com.google.protobuf.Descriptors.FileDescriptor @@ -101,31 +101,31 @@ public static void registerAllExtensions( internal_static_google_protobuf_Type_descriptor = getDescriptor().getMessageTypes().get(0); internal_static_google_protobuf_Type_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_Type_descriptor, new java.lang.String[] { "Name", "Fields", "Oneofs", "Options", "SourceContext", "Syntax", "Edition", }); internal_static_google_protobuf_Field_descriptor = getDescriptor().getMessageTypes().get(1); internal_static_google_protobuf_Field_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_Field_descriptor, new java.lang.String[] { "Kind", "Cardinality", "Number", "Name", "TypeUrl", "OneofIndex", "Packed", "Options", "JsonName", "DefaultValue", }); internal_static_google_protobuf_Enum_descriptor = getDescriptor().getMessageTypes().get(2); internal_static_google_protobuf_Enum_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_Enum_descriptor, new java.lang.String[] { "Name", "Enumvalue", "Options", "SourceContext", "Syntax", "Edition", }); internal_static_google_protobuf_EnumValue_descriptor = getDescriptor().getMessageTypes().get(3); internal_static_google_protobuf_EnumValue_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_EnumValue_descriptor, new java.lang.String[] { "Name", "Number", "Options", }); internal_static_google_protobuf_Option_descriptor = getDescriptor().getMessageTypes().get(4); internal_static_google_protobuf_Option_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_Option_descriptor, new java.lang.String[] { "Name", "Value", }); com.google.protobuf.AnyProto.getDescriptor(); diff --git a/protobuf-api/src/main/java/com/google/protobuf/UInt32Value.java b/protobuf-api/src/main/java/com/google/protobuf/UInt32Value.java index 885b63d..496998a 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/UInt32Value.java +++ b/protobuf-api/src/main/java/com/google/protobuf/UInt32Value.java @@ -14,12 +14,12 @@ * Protobuf type {@code google.protobuf.UInt32Value} */ public final class UInt32Value extends - com.google.protobuf.FlattenedGeneratedMessageV3 implements + com.google.protobuf.GeneratedMessageV3Internal implements // @@protoc_insertion_point(message_implements:google.protobuf.UInt32Value) UInt32ValueOrBuilder { private static final long serialVersionUID = 0L; // Use UInt32Value.newBuilder() to construct. - private UInt32Value(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { + private UInt32Value(com.google.protobuf.GeneratedMessageV3Internal.Builder builder) { super(builder); } private UInt32Value() { @@ -38,7 +38,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.WrappersProto.internal_static_google_protobuf_UInt32Value_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -159,20 +159,20 @@ public static com.google.protobuf.UInt32Value parseFrom( } public static com.google.protobuf.UInt32Value parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.UInt32Value parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.UInt32Value parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -180,20 +180,20 @@ public static com.google.protobuf.UInt32Value parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.UInt32Value parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.UInt32Value parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -213,7 +213,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -227,7 +227,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.UInt32Value} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements + com.google.protobuf.GeneratedMessageV3Internal.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.UInt32Value) com.google.protobuf.UInt32ValueOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -236,7 +236,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.WrappersProto.internal_static_google_protobuf_UInt32Value_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -249,7 +249,7 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); } diff --git a/protobuf-api/src/main/java/com/google/protobuf/UInt64Value.java b/protobuf-api/src/main/java/com/google/protobuf/UInt64Value.java index b0db2f5..054b07c 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/UInt64Value.java +++ b/protobuf-api/src/main/java/com/google/protobuf/UInt64Value.java @@ -14,12 +14,12 @@ * Protobuf type {@code google.protobuf.UInt64Value} */ public final class UInt64Value extends - com.google.protobuf.FlattenedGeneratedMessageV3 implements + com.google.protobuf.GeneratedMessageV3Internal implements // @@protoc_insertion_point(message_implements:google.protobuf.UInt64Value) UInt64ValueOrBuilder { private static final long serialVersionUID = 0L; // Use UInt64Value.newBuilder() to construct. - private UInt64Value(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { + private UInt64Value(com.google.protobuf.GeneratedMessageV3Internal.Builder builder) { super(builder); } private UInt64Value() { @@ -38,7 +38,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.WrappersProto.internal_static_google_protobuf_UInt64Value_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -160,20 +160,20 @@ public static com.google.protobuf.UInt64Value parseFrom( } public static com.google.protobuf.UInt64Value parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.UInt64Value parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.UInt64Value parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -181,20 +181,20 @@ public static com.google.protobuf.UInt64Value parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.UInt64Value parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.UInt64Value parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -214,7 +214,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -228,7 +228,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.UInt64Value} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements + com.google.protobuf.GeneratedMessageV3Internal.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.UInt64Value) com.google.protobuf.UInt64ValueOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -237,7 +237,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.WrappersProto.internal_static_google_protobuf_UInt64Value_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -250,7 +250,7 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); } diff --git a/protobuf-api/src/main/java/com/google/protobuf/Value.java b/protobuf-api/src/main/java/com/google/protobuf/Value.java index e59e991..c56accd 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/Value.java +++ b/protobuf-api/src/main/java/com/google/protobuf/Value.java @@ -17,12 +17,12 @@ * Protobuf type {@code google.protobuf.Value} */ public final class Value extends - com.google.protobuf.FlattenedGeneratedMessageV3 implements + com.google.protobuf.GeneratedMessageV3Internal implements // @@protoc_insertion_point(message_implements:google.protobuf.Value) ValueOrBuilder { private static final long serialVersionUID = 0L; // Use Value.newBuilder() to construct. - private Value(com.google.protobuf.FlattenedGeneratedMessageV3.Builder builder) { + private Value(com.google.protobuf.GeneratedMessageV3Internal.Builder builder) { super(builder); } private Value() { @@ -41,7 +41,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.StructProto.internal_static_google_protobuf_Value_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -53,7 +53,7 @@ protected java.lang.Object newInstance( private java.lang.Object kind_; public enum KindCase implements com.google.protobuf.Internal.EnumLite, - com.google.protobuf.FlattenedGeneratedMessageV3.InternalOneOfEnum { + com.google.protobuf.GeneratedMessageV3Internal.InternalOneOfEnum { NULL_VALUE(1), NUMBER_VALUE(2), STRING_VALUE(3), @@ -371,7 +371,7 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) 2, (double)((java.lang.Double) kind_)); } if (kindCase_ == 3) { - com.google.protobuf.FlattenedGeneratedMessageV3.writeString(output, 3, kind_); + com.google.protobuf.GeneratedMessageV3Internal.writeString(output, 3, kind_); } if (kindCase_ == 4) { output.writeBool( @@ -402,7 +402,7 @@ public int getSerializedSize() { 2, (double)((java.lang.Double) kind_)); } if (kindCase_ == 3) { - size += com.google.protobuf.FlattenedGeneratedMessageV3.computeStringSize(3, kind_); + size += com.google.protobuf.GeneratedMessageV3Internal.computeStringSize(3, kind_); } if (kindCase_ == 4) { size += com.google.protobuf.CodedOutputStream @@ -542,20 +542,20 @@ public static com.google.protobuf.Value parseFrom( } public static com.google.protobuf.Value parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.Value parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Value parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input); } @@ -563,20 +563,20 @@ public static com.google.protobuf.Value parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.google.protobuf.Value parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input); } public static com.google.protobuf.Value parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.FlattenedGeneratedMessageV3 + return com.google.protobuf.GeneratedMessageV3Internal .parseWithIOException(PARSER, input, extensionRegistry); } @@ -596,7 +596,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -613,7 +613,7 @@ protected Builder newBuilderForType( * Protobuf type {@code google.protobuf.Value} */ public static final class Builder extends - com.google.protobuf.FlattenedGeneratedMessageV3.Builder implements + com.google.protobuf.GeneratedMessageV3Internal.Builder implements // @@protoc_insertion_point(builder_implements:google.protobuf.Value) com.google.protobuf.ValueOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -622,7 +622,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internalGetFieldAccessorTable() { return com.google.protobuf.StructProto.internal_static_google_protobuf_Value_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -635,7 +635,7 @@ private Builder() { } private Builder( - com.google.protobuf.FlattenedGeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3Internal.BuilderParent parent) { super(parent); } diff --git a/protobuf-api/src/main/java/com/google/protobuf/WrappersProto.java b/protobuf-api/src/main/java/com/google/protobuf/WrappersProto.java index 1d2e0cb..0feeeba 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/WrappersProto.java +++ b/protobuf-api/src/main/java/com/google/protobuf/WrappersProto.java @@ -18,47 +18,47 @@ public static void registerAllExtensions( static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_DoubleValue_descriptor; static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_DoubleValue_fieldAccessorTable; static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_FloatValue_descriptor; static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_FloatValue_fieldAccessorTable; static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_Int64Value_descriptor; static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_Int64Value_fieldAccessorTable; static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_UInt64Value_descriptor; static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_UInt64Value_fieldAccessorTable; static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_Int32Value_descriptor; static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_Int32Value_fieldAccessorTable; static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_UInt32Value_descriptor; static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_UInt32Value_fieldAccessorTable; static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_BoolValue_descriptor; static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_BoolValue_fieldAccessorTable; static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_StringValue_descriptor; static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_StringValue_fieldAccessorTable; static final com.google.protobuf.Descriptors.Descriptor internal_static_google_protobuf_BytesValue_descriptor; static final - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable internal_static_google_protobuf_BytesValue_fieldAccessorTable; public static com.google.protobuf.Descriptors.FileDescriptor @@ -89,55 +89,55 @@ public static void registerAllExtensions( internal_static_google_protobuf_DoubleValue_descriptor = getDescriptor().getMessageTypes().get(0); internal_static_google_protobuf_DoubleValue_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_DoubleValue_descriptor, new java.lang.String[] { "Value", }); internal_static_google_protobuf_FloatValue_descriptor = getDescriptor().getMessageTypes().get(1); internal_static_google_protobuf_FloatValue_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_FloatValue_descriptor, new java.lang.String[] { "Value", }); internal_static_google_protobuf_Int64Value_descriptor = getDescriptor().getMessageTypes().get(2); internal_static_google_protobuf_Int64Value_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_Int64Value_descriptor, new java.lang.String[] { "Value", }); internal_static_google_protobuf_UInt64Value_descriptor = getDescriptor().getMessageTypes().get(3); internal_static_google_protobuf_UInt64Value_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_UInt64Value_descriptor, new java.lang.String[] { "Value", }); internal_static_google_protobuf_Int32Value_descriptor = getDescriptor().getMessageTypes().get(4); internal_static_google_protobuf_Int32Value_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_Int32Value_descriptor, new java.lang.String[] { "Value", }); internal_static_google_protobuf_UInt32Value_descriptor = getDescriptor().getMessageTypes().get(5); internal_static_google_protobuf_UInt32Value_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_UInt32Value_descriptor, new java.lang.String[] { "Value", }); internal_static_google_protobuf_BoolValue_descriptor = getDescriptor().getMessageTypes().get(6); internal_static_google_protobuf_BoolValue_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_BoolValue_descriptor, new java.lang.String[] { "Value", }); internal_static_google_protobuf_StringValue_descriptor = getDescriptor().getMessageTypes().get(7); internal_static_google_protobuf_StringValue_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_StringValue_descriptor, new java.lang.String[] { "Value", }); internal_static_google_protobuf_BytesValue_descriptor = getDescriptor().getMessageTypes().get(8); internal_static_google_protobuf_BytesValue_fieldAccessorTable = new - com.google.protobuf.FlattenedGeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessageV3Internal.FieldAccessorTable( internal_static_google_protobuf_BytesValue_descriptor, new java.lang.String[] { "Value", }); } From af1cc202826869fda2e0814dc10ca90b400ff342 Mon Sep 17 00:00:00 2001 From: blakeli Date: Mon, 9 Jun 2025 17:03:14 -0400 Subject: [PATCH 40/42] Change the generic type of SingleFieldBuilderV3 and RepeatedFieldBuilderV3 from AbstractMessage to Message. This requires us extracting a few methods from AbstractMessage to Message as well. --- .../protobuf/AbstractMessageInternal.java | 23 --------- .../protobuf/FlattenedAbstractMessage.java | 23 --------- .../protobuf/FlattenedGeneratedMessageV3.java | 6 +-- .../protobuf/GeneratedMessageInternal.java | 4 +- .../protobuf/GeneratedMessageV3Internal.java | 4 +- .../java/com/google/protobuf/MapEntry.java | 28 ----------- .../java/com/google/protobuf/Message.java | 26 ++++++++++ .../com/google/protobuf/AbstractMessage.java | 48 ------------------- .../com/google/protobuf/GeneratedMessage.java | 6 +-- .../google/protobuf/GeneratedMessageV3.java | 6 +-- .../protobuf/RepeatedFieldBuilderV3.java | 24 +++++----- .../google/protobuf/SingleFieldBuilderV3.java | 12 ++--- 12 files changed, 57 insertions(+), 153 deletions(-) diff --git a/protobuf-api/src/main/java/com/google/protobuf/AbstractMessageInternal.java b/protobuf-api/src/main/java/com/google/protobuf/AbstractMessageInternal.java index e015d25..c8f84dc 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/AbstractMessageInternal.java +++ b/protobuf-api/src/main/java/com/google/protobuf/AbstractMessageInternal.java @@ -447,29 +447,6 @@ protected static UninitializedMessageException newUninitializedMessageException( return new UninitializedMessageException(MessageReflection.findMissingFields(message)); } - /** - * Used to support nested builders and called to mark this builder as clean. Clean builders will - * propagate the {@link BuilderParent#markDirty()} event to their parent builders, while dirty - * builders will not, as their parents should be dirty already. - * - *

NOTE: Implementations that don't support nested builders don't need to override this - * method. - */ - void markClean() { - throw new IllegalStateException("Should be overridden by subclasses."); - } - - /** - * Used to support nested builders and called when this nested builder is no longer used by its - * parent builder and should release the reference to its parent builder. - * - *

NOTE: Implementations that don't support nested builders don't need to override this - * method. - */ - void dispose() { - throw new IllegalStateException("Should be overridden by subclasses."); - } - // =============================================================== // The following definitions seem to be required in order to make javac // not produce weird errors like: diff --git a/protobuf-api/src/main/java/com/google/protobuf/FlattenedAbstractMessage.java b/protobuf-api/src/main/java/com/google/protobuf/FlattenedAbstractMessage.java index df84945..c5542d2 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/FlattenedAbstractMessage.java +++ b/protobuf-api/src/main/java/com/google/protobuf/FlattenedAbstractMessage.java @@ -695,29 +695,6 @@ protected static UninitializedMessageException newUninitializedMessageException( return new UninitializedMessageException(MessageReflection.findMissingFields(message)); } - /** - * Used to support nested builders and called to mark this builder as clean. Clean builders will - * propagate the {@link BuilderParent#markDirty()} event to their parent builders, while dirty - * builders will not, as their parents should be dirty already. - * - *

NOTE: Implementations that don't support nested builders don't need to override this - * method. - */ - void markClean() { - throw new IllegalStateException("Should be overridden by subclasses."); - } - - /** - * Used to support nested builders and called when this nested builder is no longer used by its - * parent builder and should release the reference to its parent builder. - * - *

NOTE: Implementations that don't support nested builders don't need to override this - * method. - */ - void dispose() { - throw new IllegalStateException("Should be overridden by subclasses."); - } - // =============================================================== // The following definitions seem to be required in order to make javac // not produce weird errors like: diff --git a/protobuf-api/src/main/java/com/google/protobuf/FlattenedGeneratedMessageV3.java b/protobuf-api/src/main/java/com/google/protobuf/FlattenedGeneratedMessageV3.java index d51c6c6..1d0eade 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/FlattenedGeneratedMessageV3.java +++ b/protobuf-api/src/main/java/com/google/protobuf/FlattenedGeneratedMessageV3.java @@ -798,7 +798,7 @@ protected void makeExtensionsImmutable() { protected abstract Message.Builder newBuilderForType(BuilderParent parent); /** TODO: generated class should implement this directly */ - protected Message.Builder newBuilderForType(final Message.BuilderParent parent) { + public Message.Builder newBuilderForType(final Message.BuilderParent parent) { return newBuilderForType( new BuilderParent() { @Override @@ -1237,7 +1237,7 @@ protected static int hashEnumList(List list) { return hash; } - void dispose() { + public void dispose() { builderParent = null; } @@ -1252,7 +1252,7 @@ protected void onBuilt() { * Called by the subclass or a builder to notify us that a message was built and may be cached * and therefore invalidations are needed. */ - protected void markClean() { + public void markClean() { this.isClean = true; } diff --git a/protobuf-api/src/main/java/com/google/protobuf/GeneratedMessageInternal.java b/protobuf-api/src/main/java/com/google/protobuf/GeneratedMessageInternal.java index 045b157..17a79bd 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/GeneratedMessageInternal.java +++ b/protobuf-api/src/main/java/com/google/protobuf/GeneratedMessageInternal.java @@ -370,7 +370,7 @@ public boolean isGenerated() { } @Override - void dispose() { + public void dispose() { builderParent = null; } @@ -386,7 +386,7 @@ protected void onBuilt() { * and therefore invalidations are needed. */ @Override - protected void markClean() { + public void markClean() { this.isClean = true; } diff --git a/protobuf-api/src/main/java/com/google/protobuf/GeneratedMessageV3Internal.java b/protobuf-api/src/main/java/com/google/protobuf/GeneratedMessageV3Internal.java index 379e837..1dfcbb1 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/GeneratedMessageV3Internal.java +++ b/protobuf-api/src/main/java/com/google/protobuf/GeneratedMessageV3Internal.java @@ -578,7 +578,7 @@ protected Builder(BuilderParent builderParent) { } @Override - void dispose() { + public void dispose() { builderParent = null; } @@ -594,7 +594,7 @@ protected void onBuilt() { * and therefore invalidations are needed. */ @Override - protected void markClean() { + public void markClean() { this.isClean = true; } diff --git a/protobuf-api/src/main/java/com/google/protobuf/MapEntry.java b/protobuf-api/src/main/java/com/google/protobuf/MapEntry.java index 8cc3622..a8127c9 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/MapEntry.java +++ b/protobuf-api/src/main/java/com/google/protobuf/MapEntry.java @@ -328,11 +328,6 @@ protected interface BuilderParent { void markDirty(); } - /** Create a nested builder. */ - protected Message.Builder newBuilderForType(Message.BuilderParent parent) { - throw new UnsupportedOperationException("Nested builder is not supported for this type."); - } - @Override public List findInitializationErrors() { return MessageReflection.findMissingFields(this); @@ -998,29 +993,6 @@ protected static UninitializedMessageException newUninitializedMessageException( return new UninitializedMessageException(MessageReflection.findMissingFields(message)); } - /** - * Used to support nested builders and called to mark this builder as clean. Clean builders will - * propagate the {@link FlattenedAbstractMapEntry.BuilderParent#markDirty()} event to their parent builders, while dirty - * builders will not, as their parents should be dirty already. - * - *

NOTE: Implementations that don't support nested builders don't need to override this - * method. - */ - void markClean() { - throw new IllegalStateException("Should be overridden by subclasses."); - } - - /** - * Used to support nested builders and called when this nested builder is no longer used by its - * parent builder and should release the reference to its parent builder. - * - *

NOTE: Implementations that don't support nested builders don't need to override this - * method. - */ - void dispose() { - throw new IllegalStateException("Should be overridden by subclasses."); - } - public MapEntry.Builder mergeFrom(final ByteString data) throws InvalidProtocolBufferException { try { final CodedInputStream input = data.newCodedInput(); diff --git a/protobuf-api/src/main/java/com/google/protobuf/Message.java b/protobuf-api/src/main/java/com/google/protobuf/Message.java index d025bee..f35175e 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/Message.java +++ b/protobuf-api/src/main/java/com/google/protobuf/Message.java @@ -95,12 +95,38 @@ default boolean isGenerated() { @Override Builder newBuilderForType(); + default Message.Builder newBuilderForType(BuilderParent parent) { + throw new UnsupportedOperationException("Nested builder is not supported for this type."); + } @Override Builder toBuilder(); /** Abstract interface implemented by Protocol Message builders. */ interface Builder extends MessageLite.Builder, MessageOrBuilder { + /** + * Used to support nested builders and called to mark this builder as clean. Clean builders will + * propagate the {@link BuilderParent#markDirty()} event to their parent builders, while dirty + * builders will not, as their parents should be dirty already. + * + *

NOTE: Implementations that don't support nested builders don't need to override this + * method. + */ + default void markClean() { + throw new IllegalStateException("Should be overridden by subclasses."); + } + + /** + * Used to support nested builders and called when this nested builder is no longer used by its + * parent builder and should release the reference to its parent builder. + * + *

NOTE: Implementations that don't support nested builders don't need to override this + * method. + */ + default void dispose() { + throw new IllegalStateException("Should be overridden by subclasses."); + } + // (From MessageLite.Builder, re-declared here only for return type // covariance.) @Override diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/AbstractMessage.java b/protobuf-sdk/src/main/java/com/google/protobuf/AbstractMessage.java index 9c6e207..49ef6fd 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/AbstractMessage.java +++ b/protobuf-sdk/src/main/java/com/google/protobuf/AbstractMessage.java @@ -35,31 +35,6 @@ public boolean isInitialized() { return MessageReflection.isInitialized(this); } - /** - * Interface for the parent of a Builder that allows the builder to communicate invalidations back - * to the parent for use when using nested builders. - */ - protected interface BuilderParent extends Message.BuilderParent{ - - /** - * A builder becomes dirty whenever a field is modified -- including fields in nested builders - * -- and becomes clean when build() is called. Thus, when a builder becomes dirty, all its - * parents become dirty as well, and when it becomes clean, all its children become clean. The - * dirtiness state is used to invalidate certain cached values. - * - *

To this end, a builder calls markDirty() on its parent whenever it transitions from clean - * to dirty. The parent must propagate this call to its own parent, unless it was already dirty, - * in which case the grandparent must necessarily already be dirty as well. The parent can only - * transition back to "clean" after calling build() on all children. - */ - void markDirty(); - } - - /** Create a nested builder. */ - protected Message.Builder newBuilderForType(BuilderParent parent) { - throw new UnsupportedOperationException("Nested builder is not supported for this type."); - } - @Override public List findInitializationErrors() { return MessageReflection.findMissingFields(this); @@ -446,29 +421,6 @@ protected static UninitializedMessageException newUninitializedMessageException( return new UninitializedMessageException(MessageReflection.findMissingFields(message)); } - /** - * Used to support nested builders and called to mark this builder as clean. Clean builders will - * propagate the {@link BuilderParent#markDirty()} event to their parent builders, while dirty - * builders will not, as their parents should be dirty already. - * - *

NOTE: Implementations that don't support nested builders don't need to override this - * method. - */ - void markClean() { - throw new IllegalStateException("Should be overridden by subclasses."); - } - - /** - * Used to support nested builders and called when this nested builder is no longer used by its - * parent builder and should release the reference to its parent builder. - * - *

NOTE: Implementations that don't support nested builders don't need to override this - * method. - */ - void dispose() { - throw new IllegalStateException("Should be overridden by subclasses."); - } - // =============================================================== // The following definitions seem to be required in order to make javac // not produce weird errors like: diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/GeneratedMessage.java b/protobuf-sdk/src/main/java/com/google/protobuf/GeneratedMessage.java index 0a68908..6df14a1 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/GeneratedMessage.java +++ b/protobuf-sdk/src/main/java/com/google/protobuf/GeneratedMessage.java @@ -331,7 +331,7 @@ protected interface BuilderParent extends AbstractMessage.BuilderParent {} protected abstract Message.Builder newBuilderForType(BuilderParent parent); @Override - protected Message.Builder newBuilderForType(final AbstractMessage.BuilderParent parent) { + public Message.Builder newBuilderForType(final AbstractMessage.BuilderParent parent) { return newBuilderForType( new BuilderParent() { @Override @@ -369,7 +369,7 @@ public boolean isGenerated() { } @Override - void dispose() { + public void dispose() { builderParent = null; } @@ -385,7 +385,7 @@ protected void onBuilt() { * and therefore invalidations are needed. */ @Override - protected void markClean() { + public void markClean() { this.isClean = true; } diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/GeneratedMessageV3.java b/protobuf-sdk/src/main/java/com/google/protobuf/GeneratedMessageV3.java index 10642ca..11a97ba 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/GeneratedMessageV3.java +++ b/protobuf-sdk/src/main/java/com/google/protobuf/GeneratedMessageV3.java @@ -544,7 +544,7 @@ protected interface BuilderParent extends AbstractMessage.BuilderParent {} /** TODO: generated class should implement this directly */ @Override - protected Message.Builder newBuilderForType(final AbstractMessage.BuilderParent parent) { + public Message.Builder newBuilderForType(final AbstractMessage.BuilderParent parent) { return newBuilderForType( new BuilderParent() { @Override @@ -589,7 +589,7 @@ protected Builder(BuilderParent builderParent) { } @Override - void dispose() { + public void dispose() { builderParent = null; } @@ -605,7 +605,7 @@ protected void onBuilt() { * and therefore invalidations are needed. */ @Override - protected void markClean() { + public void markClean() { this.isClean = true; } diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/RepeatedFieldBuilderV3.java b/protobuf-sdk/src/main/java/com/google/protobuf/RepeatedFieldBuilderV3.java index aeb2c09..e1dddbe 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/RepeatedFieldBuilderV3.java +++ b/protobuf-sdk/src/main/java/com/google/protobuf/RepeatedFieldBuilderV3.java @@ -35,13 +35,13 @@ * @author jonp@google.com (Jon Perlow) */ public class RepeatedFieldBuilderV3< - MType extends AbstractMessage, - BType extends AbstractMessage.Builder, + MType extends Message, + BType extends Message.Builder, IType extends MessageOrBuilder> - implements AbstractMessage.BuilderParent { + implements Message.BuilderParent { // Parent to send changes to. - private AbstractMessage.BuilderParent parent; + private Message.BuilderParent parent; // List of messages. Never null. It may be immutable, in which case // isMessagesListMutable will be false. See note below. @@ -69,7 +69,7 @@ public class RepeatedFieldBuilderV3< // was set directly for an index. // Indicates that we've built a message and so we are now obligated - // to dispatch dirty invalidations. See AbstractMessage.BuilderListener. + // to dispatch dirty invalidations. See Message.BuilderListener. private boolean isClean; // A view of this builder that exposes a List interface of messages. This is @@ -102,7 +102,7 @@ public class RepeatedFieldBuilderV3< public RepeatedFieldBuilderV3( List messages, boolean isMessagesListMutable, - AbstractMessage.BuilderParent parent, + Message.BuilderParent parent, boolean isClean) { this.messages = messages; this.isMessagesListMutable = isMessagesListMutable; @@ -556,8 +556,8 @@ private void incrementModCounts() { * @param the common interface for the message and the builder */ private static class MessageExternalList< - MType extends AbstractMessage, - BType extends AbstractMessage.Builder, + MType extends Message, + BType extends Message.Builder, IType extends MessageOrBuilder> extends AbstractList implements List, RandomAccess { @@ -590,8 +590,8 @@ void incrementModCount() { * @param the common interface for the message and the builder */ private static class BuilderExternalList< - MType extends AbstractMessage, - BType extends AbstractMessage.Builder, + MType extends Message, + BType extends Message.Builder, IType extends MessageOrBuilder> extends AbstractList implements List, RandomAccess { @@ -624,8 +624,8 @@ void incrementModCount() { * @param the common interface for the message and the builder */ private static class MessageOrBuilderExternalList< - MType extends AbstractMessage, - BType extends AbstractMessage.Builder, + MType extends Message, + BType extends Message.Builder, IType extends MessageOrBuilder> extends AbstractList implements List, RandomAccess { diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/SingleFieldBuilderV3.java b/protobuf-sdk/src/main/java/com/google/protobuf/SingleFieldBuilderV3.java index 991404e..d8d2532 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/SingleFieldBuilderV3.java +++ b/protobuf-sdk/src/main/java/com/google/protobuf/SingleFieldBuilderV3.java @@ -28,13 +28,13 @@ * @author jonp@google.com (Jon Perlow) */ public class SingleFieldBuilderV3< - MType extends AbstractMessage, - BType extends AbstractMessage.Builder, + MType extends Message, + BType extends Message.Builder, IType extends MessageOrBuilder> - implements AbstractMessage.BuilderParent { + implements Message.BuilderParent { // Parent to send changes to. - private AbstractMessage.BuilderParent parent; + private Message.BuilderParent parent; // Invariant: one of builder or message fields must be non-null. @@ -48,10 +48,10 @@ public class SingleFieldBuilderV3< private MType message; // Indicates that we've built a message and so we are now obligated - // to dispatch dirty invalidations. See AbstractMessage.BuilderListener. + // to dispatch dirty invalidations. See Message.BuilderListener. private boolean isClean; - public SingleFieldBuilderV3(MType message, AbstractMessage.BuilderParent parent, boolean isClean) { + public SingleFieldBuilderV3(MType message, Message.BuilderParent parent, boolean isClean) { this.message = checkNotNull(message); this.parent = parent; this.isClean = isClean; From 722196f060c91e827c562c7d68085f13d21b48fd Mon Sep 17 00:00:00 2001 From: blakeli Date: Tue, 10 Jun 2025 15:12:14 -0400 Subject: [PATCH 41/42] Add BuilderParent back to AbstractMessage, otherwise moving an inner class up is a binary breaking change. Change the parameter type of newBuilderForType from AbstractMessage.BuilderParent Message.BuilderParent --- .../java/com/google/protobuf/Message.java | 1 + .../com/google/protobuf/AbstractMessage.java | 20 +++++++++++++++++++ .../com/google/protobuf/GeneratedMessage.java | 2 +- .../google/protobuf/GeneratedMessageV3.java | 2 +- 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/protobuf-api/src/main/java/com/google/protobuf/Message.java b/protobuf-api/src/main/java/com/google/protobuf/Message.java index f35175e..830587e 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/Message.java +++ b/protobuf-api/src/main/java/com/google/protobuf/Message.java @@ -98,6 +98,7 @@ default boolean isGenerated() { default Message.Builder newBuilderForType(BuilderParent parent) { throw new UnsupportedOperationException("Nested builder is not supported for this type."); } + @Override Builder toBuilder(); diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/AbstractMessage.java b/protobuf-sdk/src/main/java/com/google/protobuf/AbstractMessage.java index 49ef6fd..0d9651e 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/AbstractMessage.java +++ b/protobuf-sdk/src/main/java/com/google/protobuf/AbstractMessage.java @@ -30,6 +30,26 @@ public abstract class AbstractMessage // TODO: Update GeneratedMessage to parameterize with MessageType and BuilderType. extends AbstractMessageLite implements Message { + /** + * Interface for the parent of a Builder that allows the builder to communicate invalidations back + * to the parent for use when using nested builders. + */ + protected interface BuilderParent extends Message.BuilderParent{ + + /** + * A builder becomes dirty whenever a field is modified -- including fields in nested builders + * -- and becomes clean when build() is called. Thus, when a builder becomes dirty, all its + * parents become dirty as well, and when it becomes clean, all its children become clean. The + * dirtiness state is used to invalidate certain cached values. + * + *

To this end, a builder calls markDirty() on its parent whenever it transitions from clean + * to dirty. The parent must propagate this call to its own parent, unless it was already dirty, + * in which case the grandparent must necessarily already be dirty as well. The parent can only + * transition back to "clean" after calling build() on all children. + */ + void markDirty(); + } + @Override public boolean isInitialized() { return MessageReflection.isInitialized(this); diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/GeneratedMessage.java b/protobuf-sdk/src/main/java/com/google/protobuf/GeneratedMessage.java index 6df14a1..bb4f8d6 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/GeneratedMessage.java +++ b/protobuf-sdk/src/main/java/com/google/protobuf/GeneratedMessage.java @@ -331,7 +331,7 @@ protected interface BuilderParent extends AbstractMessage.BuilderParent {} protected abstract Message.Builder newBuilderForType(BuilderParent parent); @Override - public Message.Builder newBuilderForType(final AbstractMessage.BuilderParent parent) { + public Message.Builder newBuilderForType(final Message.BuilderParent parent) { return newBuilderForType( new BuilderParent() { @Override diff --git a/protobuf-sdk/src/main/java/com/google/protobuf/GeneratedMessageV3.java b/protobuf-sdk/src/main/java/com/google/protobuf/GeneratedMessageV3.java index 11a97ba..d2a99ae 100644 --- a/protobuf-sdk/src/main/java/com/google/protobuf/GeneratedMessageV3.java +++ b/protobuf-sdk/src/main/java/com/google/protobuf/GeneratedMessageV3.java @@ -544,7 +544,7 @@ protected interface BuilderParent extends AbstractMessage.BuilderParent {} /** TODO: generated class should implement this directly */ @Override - public Message.Builder newBuilderForType(final AbstractMessage.BuilderParent parent) { + public Message.Builder newBuilderForType(final Message.BuilderParent parent) { return newBuilderForType( new BuilderParent() { @Override From aa016d5aa8a5c5cb9992cf072d681c2d73a0827a Mon Sep 17 00:00:00 2001 From: blakeli Date: Tue, 10 Jun 2025 15:52:29 -0400 Subject: [PATCH 42/42] Update the argument type of newBuilderForType from AbstractMessageInternal.BuilderParent to Message.BuilderParent --- .../java/com/google/protobuf/AbstractMessageInternal.java | 5 ----- .../java/com/google/protobuf/GeneratedMessageInternal.java | 3 +-- .../java/com/google/protobuf/GeneratedMessageV3Internal.java | 3 +-- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/protobuf-api/src/main/java/com/google/protobuf/AbstractMessageInternal.java b/protobuf-api/src/main/java/com/google/protobuf/AbstractMessageInternal.java index c8f84dc..3e9d6be 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/AbstractMessageInternal.java +++ b/protobuf-api/src/main/java/com/google/protobuf/AbstractMessageInternal.java @@ -56,11 +56,6 @@ protected interface BuilderParent extends Message.BuilderParent{ void markDirty(); } - /** Create a nested builder. */ - protected Message.Builder newBuilderForType(BuilderParent parent) { - throw new UnsupportedOperationException("Nested builder is not supported for this type."); - } - @Override public List findInitializationErrors() { return MessageReflection.findMissingFields(this); diff --git a/protobuf-api/src/main/java/com/google/protobuf/GeneratedMessageInternal.java b/protobuf-api/src/main/java/com/google/protobuf/GeneratedMessageInternal.java index 17a79bd..e247677 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/GeneratedMessageInternal.java +++ b/protobuf-api/src/main/java/com/google/protobuf/GeneratedMessageInternal.java @@ -331,8 +331,7 @@ protected interface BuilderParent extends AbstractMessageInternal.BuilderParent /** TODO: remove this together with GeneratedMessageInternal.BuilderParent. */ protected abstract Message.Builder newBuilderForType(BuilderParent parent); - @Override - protected Message.Builder newBuilderForType(final AbstractMessageInternal.BuilderParent parent) { + public Message.Builder newBuilderForType(final Message.BuilderParent parent) { return newBuilderForType( new BuilderParent() { @Override diff --git a/protobuf-api/src/main/java/com/google/protobuf/GeneratedMessageV3Internal.java b/protobuf-api/src/main/java/com/google/protobuf/GeneratedMessageV3Internal.java index 1dfcbb1..5553325 100644 --- a/protobuf-api/src/main/java/com/google/protobuf/GeneratedMessageV3Internal.java +++ b/protobuf-api/src/main/java/com/google/protobuf/GeneratedMessageV3Internal.java @@ -532,8 +532,7 @@ protected interface BuilderParent extends AbstractMessageInternal.BuilderParent protected abstract Message.Builder newBuilderForType(BuilderParent parent); /** TODO: generated class should implement this directly */ - @Override - protected Message.Builder newBuilderForType(final AbstractMessageInternal.BuilderParent parent) { + public Message.Builder newBuilderForType(final Message.BuilderParent parent) { return newBuilderForType( new BuilderParent() { @Override