diff --git a/java/core/generate-test-sources-build.xml b/java/core/generate-test-sources-build.xml index e3a4a724a557e..71a88d07b33b3 100644 --- a/java/core/generate-test-sources-build.xml +++ b/java/core/generate-test-sources-build.xml @@ -4,8 +4,6 @@ - - @@ -24,9 +22,6 @@ - - - @@ -36,7 +31,6 @@ - @@ -64,17 +58,4 @@ - - - - - - - - - - - - - diff --git a/java/core/pom.xml b/java/core/pom.xml index c0e773b7cdccd..70e4bfc6ad9bd 100644 --- a/java/core/pom.xml +++ b/java/core/pom.xml @@ -16,10 +16,6 @@ efficient yet extensible format. - - 1.4.31 - - junit @@ -51,17 +47,6 @@ truth test - - org.jetbrains.kotlin - kotlin-stdlib-jdk7 - ${kotlin.version} - - - org.jetbrains.kotlin - kotlin-test - ${kotlin.version} - test - @@ -161,35 +146,7 @@ - - org.jetbrains.kotlin - kotlin-maven-plugin - ${kotlin.version} - true - - - compile - compile - - - ${project.basedir}/src/main/java - ${project.basedir}/src/main/kotlin - - - - - test-compile - test-compile - - - ${project.basedir}/src/test/java - ${project.basedir}/src/test/kotlin - ${generated.testsources.dir} - - - - - + org.apache.felix diff --git a/java/kotlin-lite/generate-sources-build.xml b/java/kotlin-lite/generate-sources-build.xml new file mode 100644 index 0000000000000..74d96a2f10538 --- /dev/null +++ b/java/kotlin-lite/generate-sources-build.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/java/kotlin-lite/generate-test-sources-build.xml b/java/kotlin-lite/generate-test-sources-build.xml new file mode 100644 index 0000000000000..c5f60b8653692 --- /dev/null +++ b/java/kotlin-lite/generate-test-sources-build.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/java/kotlin-lite/lite.awk b/java/kotlin-lite/lite.awk new file mode 100644 index 0000000000000..b22d965b6fd02 --- /dev/null +++ b/java/kotlin-lite/lite.awk @@ -0,0 +1,25 @@ +# Remove code enclosed by "BEGIN FULL-RUNTIME" and "END FULL-RUNTIME" to +# create the lite-only version of a test file. + +BEGIN { + in_full_runtime = 0; +} + +/BEGIN FULL-RUNTIME/ { + in_full_runtime = 1; + next; +} + +/END FULL-RUNTIME/ { + in_full_runtime = 0; + next; +} + +in_full_runtime { + # Skip full runtime code path. + next; +} + +{ + print; +} diff --git a/java/kotlin-lite/pom.xml b/java/kotlin-lite/pom.xml new file mode 100644 index 0000000000000..29a379994d086 --- /dev/null +++ b/java/kotlin-lite/pom.xml @@ -0,0 +1,383 @@ + + + 4.0.0 + + com.google.protobuf + protobuf-parent + 3.15.6 + + + protobuf-javalite + bundle + + Protocol Buffers [Lite] + + Lite version of Protocol Buffers library. This version is optimized for code size, but does + not guarantee API/ABI stability. + + + + 1.4.31 + + + + + junit + junit + test + + + org.easymock + easymock + test + + + org.easymock + easymockclassextension + test + + + com.google.guava + guava + test + + + com.google.guava + guava-testlib + test + + + com.google.truth + truth + test + + + org.jetbrains.kotlin + kotlin-stdlib + ${kotlin.version} + + + org.jetbrains.kotlin + kotlin-test + ${kotlin.version} + + + + + + + + ${protobuf.source.dir} + + google/protobuf/any.proto + google/protobuf/api.proto + google/protobuf/duration.proto + google/protobuf/empty.proto + google/protobuf/field_mask.proto + google/protobuf/source_context.proto + google/protobuf/struct.proto + google/protobuf/timestamp.proto + google/protobuf/type.proto + google/protobuf/wrappers.proto + + + + + + ${protobuf.source.dir} + + google/protobuf/testdata/golden_message_oneof_implemented + google/protobuf/testdata/golden_packed_fields_message + + + + + + + maven-resources-plugin + 3.1.0 + + + copy-source-files + generate-sources + + copy-resources + + + ${generated.sources.dir}/com/google/protobuf + + + ${basedir}/../core/src/main/java/com/google/protobuf + + + AbstractMessageLite.java + AbstractParser.java + AbstractProtobufList.java + AllocatedBuffer.java + Android.java + ArrayDecoders.java + BinaryReader.java + BinaryWriter.java + BooleanArrayList.java + BufferAllocator.java + ByteBufferWriter.java + ByteOutput.java + ByteString.java + CodedInputStream.java + CodedInputStreamReader.java + CodedOutputStream.java + CodedOutputStreamWriter.java + DoubleArrayList.java + ExperimentalApi.java + ExtensionLite.java + ExtensionRegistryFactory.java + ExtensionRegistryLite.java + ExtensionSchema.java + ExtensionSchemaLite.java + ExtensionSchemas.java + FieldInfo.java + FieldSet.java + FieldType.java + FloatArrayList.java + GeneratedMessageInfoFactory.java + GeneratedMessageLite.java + IntArrayList.java + Internal.java + InvalidProtocolBufferException.java + IterableByteBufferInputStream.java + JavaType.java + LazyField.java + LazyFieldLite.java + LazyStringArrayList.java + LazyStringList.java + ListFieldSchema.java + LongArrayList.java + ManifestSchemaFactory.java + MapEntryLite.java + MapFieldLite.java + MapFieldSchema.java + MapFieldSchemaLite.java + MapFieldSchemas.java + MessageInfo.java + MessageInfoFactory.java + MessageLite.java + MessageLiteOrBuilder.java + MessageLiteToString.java + MessageSchema.java + MessageSetSchema.java + MutabilityOracle.java + NewInstanceSchema.java + NewInstanceSchemaLite.java + NewInstanceSchemas.java + NioByteString.java + OneofInfo.java + Parser.java + PrimitiveNonBoxingCollection.java + ProtoSyntax.java + Protobuf.java + ProtobufArrayList.java + ProtobufLists.java + ProtocolStringList.java + RawMessageInfo.java + Reader.java + RopeByteString.java + Schema.java + SchemaFactory.java + SchemaUtil.java + SmallSortedMap.java + StructuralMessageInfo.java + TextFormatEscaper.java + UninitializedMessageException.java + UnknownFieldSchema.java + UnknownFieldSetLite.java + UnknownFieldSetLiteSchema.java + UnmodifiableLazyStringList.java + UnsafeUtil.java + Utf8.java + WireFormat.java + Writer.java + + + + + + + copy-kotlin-source-files + generate-sources + + copy-resources + + + ${generated.sources.dir}/com/google/protobuf + + + ${basedir}/../kotlin/src/main/kotlin/com/google/protobuf + + DslList.kt + DslMap.kt + DslProxy.kt + ExtendableMessageLiteExtensions.kt + ExtensionList.kt + OnlyForUseByGeneratedProtoCode.kt + ProtoDslMarker.kt + UnmodifiableCollections.kt + + + + + + + copy-test-source-files + generate-test-sources + + copy-resources + + + ${generated.testsources.dir}/com/google/protobuf + + + ${basedir}/../core/src/test/java/com/google/protobuf + + TestUtilLite.java + + + + ${basedir}/../kotlin/src/test/kotlin/com/google/protobuf + + ExtendableMessageExtensionsTest.kt + Proto2Test.kt + ProtoUtil.java + + + + + + + + + + + maven-antrun-plugin + + + + generate-sources + generate-sources + + + + + + + run + + + + + + generate-test-sources + generate-test-sources + + + + + + + run + + + + + process-lite-sources + generate-test-sources + + + + + + + run + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + + + add-generated-sources + generate-sources + + add-source + + + + ${generated.sources.dir} + + + + + + add-generated-test-sources + generate-test-sources + + add-test-source + + + + ${generated.testsources.dir} + + + + + + + + org.jetbrains.kotlin + kotlin-maven-plugin + ${kotlin.version} + true + + + compile + compile + + + ${generated.sources.dir} + ${project.basedir}/src/main/kotlin + + + + + test-compile + test-compile + + + ${project.basedir}/src/test/kotlin + ${generated.testsources.dir} + + + + + + + + + org.apache.felix + maven-bundle-plugin + true + + + com.google.protobuf + https://developers.google.com/protocol-buffers/ + com.google.protobuf + com.google.protobuf;version=${project.version} + sun.misc;resolution:=optional,* + + + + + + diff --git a/java/kotlin-lite/process-lite-sources-build.xml b/java/kotlin-lite/process-lite-sources-build.xml new file mode 100644 index 0000000000000..d49cf3aac03f1 --- /dev/null +++ b/java/kotlin-lite/process-lite-sources-build.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/java/lite/src/test/kotlin/com/google/protobuf/ExtendableMessageLiteExtensionsTest.kt b/java/kotlin-lite/src/test/kotlin/com/google/protobuf/ExtendableMessageLiteExtensionsTest.kt similarity index 100% rename from java/lite/src/test/kotlin/com/google/protobuf/ExtendableMessageLiteExtensionsTest.kt rename to java/kotlin-lite/src/test/kotlin/com/google/protobuf/ExtendableMessageLiteExtensionsTest.kt diff --git a/java/lite/src/test/kotlin/com/google/protobuf/Proto2LiteTest.kt b/java/kotlin-lite/src/test/kotlin/com/google/protobuf/Proto2LiteTest.kt similarity index 100% rename from java/lite/src/test/kotlin/com/google/protobuf/Proto2LiteTest.kt rename to java/kotlin-lite/src/test/kotlin/com/google/protobuf/Proto2LiteTest.kt diff --git a/java/kotlin-lite/target/antrun/build-main.xml b/java/kotlin-lite/target/antrun/build-main.xml new file mode 100644 index 0000000000000..e6948030ea980 --- /dev/null +++ b/java/kotlin-lite/target/antrun/build-main.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/java/kotlin-lite/target/classes/META-INF/MANIFEST.MF b/java/kotlin-lite/target/classes/META-INF/MANIFEST.MF new file mode 100644 index 0000000000000..99837bdcf5dd8 --- /dev/null +++ b/java/kotlin-lite/target/classes/META-INF/MANIFEST.MF @@ -0,0 +1,21 @@ +Manifest-Version: 1.0 +Automatic-Module-Name: com.google.protobuf +Bnd-LastModified: 1617123864936 +Build-Jdk: 11.0.10 +Built-By: deannagarcia +Bundle-Description: Lite version of Protocol Buffers library. This versi + on is optimized for code size, but does not guarantee API/ABI stabil + ity. +Bundle-DocURL: https://developers.google.com/protocol-buffers/ +Bundle-License: https://opensource.org/licenses/BSD-3-Clause +Bundle-ManifestVersion: 2 +Bundle-Name: Protocol Buffers [Lite] +Bundle-SymbolicName: com.google.protobuf +Bundle-Version: 3.15.6 +Created-By: Apache Maven Bundle Plugin +Export-Package: com.google.protobuf;version="3.15.6" +Import-Package: sun.misc;resolution:=optional,com.google.protobuf;versio + n="[3.15,4)",kotlin,kotlin.annotation,kotlin.jvm.internal,kotlin.jvm.in + ternal.markers +Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.7))" +Tool: Bnd-3.0.0.201509101326 diff --git a/java/kotlin-lite/target/classes/META-INF/protobuf-javalite.kotlin_module b/java/kotlin-lite/target/classes/META-INF/protobuf-javalite.kotlin_module new file mode 100644 index 0000000000000..966edfe3ce5e7 Binary files /dev/null and b/java/kotlin-lite/target/classes/META-INF/protobuf-javalite.kotlin_module differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/AbstractMessageLite$Builder$LimitedInputStream.class b/java/kotlin-lite/target/classes/com/google/protobuf/AbstractMessageLite$Builder$LimitedInputStream.class new file mode 100644 index 0000000000000..b79c69aaccb5a Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/AbstractMessageLite$Builder$LimitedInputStream.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/AbstractMessageLite$Builder.class b/java/kotlin-lite/target/classes/com/google/protobuf/AbstractMessageLite$Builder.class new file mode 100644 index 0000000000000..fa13546036c5d Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/AbstractMessageLite$Builder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/AbstractMessageLite$InternalOneOfEnum.class b/java/kotlin-lite/target/classes/com/google/protobuf/AbstractMessageLite$InternalOneOfEnum.class new file mode 100644 index 0000000000000..8e98f8c3309e6 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/AbstractMessageLite$InternalOneOfEnum.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/AbstractMessageLite.class b/java/kotlin-lite/target/classes/com/google/protobuf/AbstractMessageLite.class new file mode 100644 index 0000000000000..1baec63ad0f2f Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/AbstractMessageLite.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/AbstractParser.class b/java/kotlin-lite/target/classes/com/google/protobuf/AbstractParser.class new file mode 100644 index 0000000000000..eeefa54df537f Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/AbstractParser.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/AbstractProtobufList.class b/java/kotlin-lite/target/classes/com/google/protobuf/AbstractProtobufList.class new file mode 100644 index 0000000000000..21e65d35e2b0d Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/AbstractProtobufList.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/AllocatedBuffer$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/AllocatedBuffer$1.class new file mode 100644 index 0000000000000..92e3ada44a433 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/AllocatedBuffer$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/AllocatedBuffer$2.class b/java/kotlin-lite/target/classes/com/google/protobuf/AllocatedBuffer$2.class new file mode 100644 index 0000000000000..2d21560d16d19 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/AllocatedBuffer$2.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/AllocatedBuffer.class b/java/kotlin-lite/target/classes/com/google/protobuf/AllocatedBuffer.class new file mode 100644 index 0000000000000..53703cef83a3d Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/AllocatedBuffer.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Android.class b/java/kotlin-lite/target/classes/com/google/protobuf/Android.class new file mode 100644 index 0000000000000..94bccbd420ca5 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Android.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Any$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/Any$1.class new file mode 100644 index 0000000000000..397b7f2589cdf Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Any$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Any$Builder.class b/java/kotlin-lite/target/classes/com/google/protobuf/Any$Builder.class new file mode 100644 index 0000000000000..8f9308fc0cbe4 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Any$Builder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Any.class b/java/kotlin-lite/target/classes/com/google/protobuf/Any.class new file mode 100644 index 0000000000000..48f0e812c42ea Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Any.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/AnyOrBuilder.class b/java/kotlin-lite/target/classes/com/google/protobuf/AnyOrBuilder.class new file mode 100644 index 0000000000000..63a6a711b2999 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/AnyOrBuilder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/AnyProto.class b/java/kotlin-lite/target/classes/com/google/protobuf/AnyProto.class new file mode 100644 index 0000000000000..c5b81489518cd Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/AnyProto.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Api$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/Api$1.class new file mode 100644 index 0000000000000..189b46b2ee579 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Api$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Api$Builder.class b/java/kotlin-lite/target/classes/com/google/protobuf/Api$Builder.class new file mode 100644 index 0000000000000..92fb1ab9017df Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Api$Builder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Api.class b/java/kotlin-lite/target/classes/com/google/protobuf/Api.class new file mode 100644 index 0000000000000..d41c0edba34ae Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Api.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/ApiOrBuilder.class b/java/kotlin-lite/target/classes/com/google/protobuf/ApiOrBuilder.class new file mode 100644 index 0000000000000..d197152fb9f23 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/ApiOrBuilder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/ApiProto.class b/java/kotlin-lite/target/classes/com/google/protobuf/ApiProto.class new file mode 100644 index 0000000000000..c3bf617bc7ffc Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/ApiProto.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/ArrayDecoders$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/ArrayDecoders$1.class new file mode 100644 index 0000000000000..799ca8e160b58 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/ArrayDecoders$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/ArrayDecoders$Registers.class b/java/kotlin-lite/target/classes/com/google/protobuf/ArrayDecoders$Registers.class new file mode 100644 index 0000000000000..b551c2358dd68 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/ArrayDecoders$Registers.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/ArrayDecoders.class b/java/kotlin-lite/target/classes/com/google/protobuf/ArrayDecoders.class new file mode 100644 index 0000000000000..ed353ddb1aee1 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/ArrayDecoders.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/BinaryReader$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/BinaryReader$1.class new file mode 100644 index 0000000000000..db2ae3b1c8e54 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/BinaryReader$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/BinaryReader$SafeHeapReader.class b/java/kotlin-lite/target/classes/com/google/protobuf/BinaryReader$SafeHeapReader.class new file mode 100644 index 0000000000000..1333693a57205 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/BinaryReader$SafeHeapReader.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/BinaryReader.class b/java/kotlin-lite/target/classes/com/google/protobuf/BinaryReader.class new file mode 100644 index 0000000000000..30d971b1ff2f0 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/BinaryReader.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/BinaryWriter$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/BinaryWriter$1.class new file mode 100644 index 0000000000000..d1f16c73372a7 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/BinaryWriter$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/BinaryWriter$SafeDirectWriter.class b/java/kotlin-lite/target/classes/com/google/protobuf/BinaryWriter$SafeDirectWriter.class new file mode 100644 index 0000000000000..b5fe1bd2a146d Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/BinaryWriter$SafeDirectWriter.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/BinaryWriter$SafeHeapWriter.class b/java/kotlin-lite/target/classes/com/google/protobuf/BinaryWriter$SafeHeapWriter.class new file mode 100644 index 0000000000000..57d03fe3a5b39 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/BinaryWriter$SafeHeapWriter.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/BinaryWriter$UnsafeDirectWriter.class b/java/kotlin-lite/target/classes/com/google/protobuf/BinaryWriter$UnsafeDirectWriter.class new file mode 100644 index 0000000000000..ff45dea6b8124 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/BinaryWriter$UnsafeDirectWriter.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/BinaryWriter$UnsafeHeapWriter.class b/java/kotlin-lite/target/classes/com/google/protobuf/BinaryWriter$UnsafeHeapWriter.class new file mode 100644 index 0000000000000..d82dff1a2e916 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/BinaryWriter$UnsafeHeapWriter.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/BinaryWriter.class b/java/kotlin-lite/target/classes/com/google/protobuf/BinaryWriter.class new file mode 100644 index 0000000000000..d797930d7d68f Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/BinaryWriter.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/BoolValue$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/BoolValue$1.class new file mode 100644 index 0000000000000..a49a5abdb2c8e Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/BoolValue$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/BoolValue$Builder.class b/java/kotlin-lite/target/classes/com/google/protobuf/BoolValue$Builder.class new file mode 100644 index 0000000000000..70656b75e6e7f Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/BoolValue$Builder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/BoolValue.class b/java/kotlin-lite/target/classes/com/google/protobuf/BoolValue.class new file mode 100644 index 0000000000000..ab79d2cc57b24 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/BoolValue.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/BoolValueOrBuilder.class b/java/kotlin-lite/target/classes/com/google/protobuf/BoolValueOrBuilder.class new file mode 100644 index 0000000000000..344b97713a15b Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/BoolValueOrBuilder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/BooleanArrayList.class b/java/kotlin-lite/target/classes/com/google/protobuf/BooleanArrayList.class new file mode 100644 index 0000000000000..68e7c9b68a5e3 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/BooleanArrayList.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/BufferAllocator$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/BufferAllocator$1.class new file mode 100644 index 0000000000000..db88c0e817838 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/BufferAllocator$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/BufferAllocator.class b/java/kotlin-lite/target/classes/com/google/protobuf/BufferAllocator.class new file mode 100644 index 0000000000000..66b5a08c9c421 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/BufferAllocator.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/ByteBufferWriter.class b/java/kotlin-lite/target/classes/com/google/protobuf/ByteBufferWriter.class new file mode 100644 index 0000000000000..1f5fa25d63a85 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/ByteBufferWriter.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/ByteOutput.class b/java/kotlin-lite/target/classes/com/google/protobuf/ByteOutput.class new file mode 100644 index 0000000000000..3307ca98d6be8 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/ByteOutput.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/ByteString$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/ByteString$1.class new file mode 100644 index 0000000000000..28e3b9c4f8abd Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/ByteString$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/ByteString$2.class b/java/kotlin-lite/target/classes/com/google/protobuf/ByteString$2.class new file mode 100644 index 0000000000000..192acaa8d873d Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/ByteString$2.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/ByteString$AbstractByteIterator.class b/java/kotlin-lite/target/classes/com/google/protobuf/ByteString$AbstractByteIterator.class new file mode 100644 index 0000000000000..eaa31e30040ad Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/ByteString$AbstractByteIterator.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/ByteString$ArraysByteArrayCopier.class b/java/kotlin-lite/target/classes/com/google/protobuf/ByteString$ArraysByteArrayCopier.class new file mode 100644 index 0000000000000..13bb1e8d26037 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/ByteString$ArraysByteArrayCopier.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/ByteString$BoundedByteString.class b/java/kotlin-lite/target/classes/com/google/protobuf/ByteString$BoundedByteString.class new file mode 100644 index 0000000000000..35baf6eb68003 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/ByteString$BoundedByteString.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/ByteString$ByteArrayCopier.class b/java/kotlin-lite/target/classes/com/google/protobuf/ByteString$ByteArrayCopier.class new file mode 100644 index 0000000000000..bcb2ee5261fd7 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/ByteString$ByteArrayCopier.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/ByteString$ByteIterator.class b/java/kotlin-lite/target/classes/com/google/protobuf/ByteString$ByteIterator.class new file mode 100644 index 0000000000000..72086f6435203 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/ByteString$ByteIterator.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/ByteString$CodedBuilder.class b/java/kotlin-lite/target/classes/com/google/protobuf/ByteString$CodedBuilder.class new file mode 100644 index 0000000000000..92f9f69968d52 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/ByteString$CodedBuilder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/ByteString$LeafByteString.class b/java/kotlin-lite/target/classes/com/google/protobuf/ByteString$LeafByteString.class new file mode 100644 index 0000000000000..5696237c1848c Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/ByteString$LeafByteString.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/ByteString$LiteralByteString.class b/java/kotlin-lite/target/classes/com/google/protobuf/ByteString$LiteralByteString.class new file mode 100644 index 0000000000000..157ad95a32cac Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/ByteString$LiteralByteString.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/ByteString$Output.class b/java/kotlin-lite/target/classes/com/google/protobuf/ByteString$Output.class new file mode 100644 index 0000000000000..2a59b8dc25f09 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/ByteString$Output.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/ByteString$SystemByteArrayCopier.class b/java/kotlin-lite/target/classes/com/google/protobuf/ByteString$SystemByteArrayCopier.class new file mode 100644 index 0000000000000..b409059ca821c Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/ByteString$SystemByteArrayCopier.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/ByteString.class b/java/kotlin-lite/target/classes/com/google/protobuf/ByteString.class new file mode 100644 index 0000000000000..b7d64f16c8f4c Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/ByteString.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/BytesValue$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/BytesValue$1.class new file mode 100644 index 0000000000000..05897e9f01433 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/BytesValue$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/BytesValue$Builder.class b/java/kotlin-lite/target/classes/com/google/protobuf/BytesValue$Builder.class new file mode 100644 index 0000000000000..b3c6a991ce795 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/BytesValue$Builder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/BytesValue.class b/java/kotlin-lite/target/classes/com/google/protobuf/BytesValue.class new file mode 100644 index 0000000000000..8a83ead68ac75 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/BytesValue.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/BytesValueOrBuilder.class b/java/kotlin-lite/target/classes/com/google/protobuf/BytesValueOrBuilder.class new file mode 100644 index 0000000000000..da5c8b58687fd Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/BytesValueOrBuilder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/CodedInputStream$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/CodedInputStream$1.class new file mode 100644 index 0000000000000..16da296d83ea8 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/CodedInputStream$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/CodedInputStream$ArrayDecoder.class b/java/kotlin-lite/target/classes/com/google/protobuf/CodedInputStream$ArrayDecoder.class new file mode 100644 index 0000000000000..04a4409d3e38f Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/CodedInputStream$ArrayDecoder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/CodedInputStream$IterableDirectByteBufferDecoder.class b/java/kotlin-lite/target/classes/com/google/protobuf/CodedInputStream$IterableDirectByteBufferDecoder.class new file mode 100644 index 0000000000000..24448bd4dd6d9 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/CodedInputStream$IterableDirectByteBufferDecoder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/CodedInputStream$StreamDecoder$RefillCallback.class b/java/kotlin-lite/target/classes/com/google/protobuf/CodedInputStream$StreamDecoder$RefillCallback.class new file mode 100644 index 0000000000000..e515f4d9267f5 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/CodedInputStream$StreamDecoder$RefillCallback.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/CodedInputStream$StreamDecoder$SkippedDataSink.class b/java/kotlin-lite/target/classes/com/google/protobuf/CodedInputStream$StreamDecoder$SkippedDataSink.class new file mode 100644 index 0000000000000..31a6caa2bcee1 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/CodedInputStream$StreamDecoder$SkippedDataSink.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/CodedInputStream$StreamDecoder.class b/java/kotlin-lite/target/classes/com/google/protobuf/CodedInputStream$StreamDecoder.class new file mode 100644 index 0000000000000..af4848ceec7a6 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/CodedInputStream$StreamDecoder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/CodedInputStream$UnsafeDirectNioDecoder.class b/java/kotlin-lite/target/classes/com/google/protobuf/CodedInputStream$UnsafeDirectNioDecoder.class new file mode 100644 index 0000000000000..9aa2072eba2b2 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/CodedInputStream$UnsafeDirectNioDecoder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/CodedInputStream.class b/java/kotlin-lite/target/classes/com/google/protobuf/CodedInputStream.class new file mode 100644 index 0000000000000..8c1ca5e98e649 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/CodedInputStream.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/CodedInputStreamReader$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/CodedInputStreamReader$1.class new file mode 100644 index 0000000000000..57a9277b5f15d Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/CodedInputStreamReader$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/CodedInputStreamReader.class b/java/kotlin-lite/target/classes/com/google/protobuf/CodedInputStreamReader.class new file mode 100644 index 0000000000000..10351915efa01 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/CodedInputStreamReader.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/CodedOutputStream$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/CodedOutputStream$1.class new file mode 100644 index 0000000000000..6e8f8b614b5cb Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/CodedOutputStream$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/CodedOutputStream$AbstractBufferedEncoder.class b/java/kotlin-lite/target/classes/com/google/protobuf/CodedOutputStream$AbstractBufferedEncoder.class new file mode 100644 index 0000000000000..cd6be47d194c4 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/CodedOutputStream$AbstractBufferedEncoder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/CodedOutputStream$ArrayEncoder.class b/java/kotlin-lite/target/classes/com/google/protobuf/CodedOutputStream$ArrayEncoder.class new file mode 100644 index 0000000000000..47decd5453d05 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/CodedOutputStream$ArrayEncoder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/CodedOutputStream$ByteOutputEncoder.class b/java/kotlin-lite/target/classes/com/google/protobuf/CodedOutputStream$ByteOutputEncoder.class new file mode 100644 index 0000000000000..5ee2a32de628b Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/CodedOutputStream$ByteOutputEncoder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/CodedOutputStream$HeapNioEncoder.class b/java/kotlin-lite/target/classes/com/google/protobuf/CodedOutputStream$HeapNioEncoder.class new file mode 100644 index 0000000000000..4cdd2390202ed Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/CodedOutputStream$HeapNioEncoder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/CodedOutputStream$OutOfSpaceException.class b/java/kotlin-lite/target/classes/com/google/protobuf/CodedOutputStream$OutOfSpaceException.class new file mode 100644 index 0000000000000..1287580243033 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/CodedOutputStream$OutOfSpaceException.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/CodedOutputStream$OutputStreamEncoder.class b/java/kotlin-lite/target/classes/com/google/protobuf/CodedOutputStream$OutputStreamEncoder.class new file mode 100644 index 0000000000000..a16a1d70c4c5e Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/CodedOutputStream$OutputStreamEncoder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/CodedOutputStream$SafeDirectNioEncoder.class b/java/kotlin-lite/target/classes/com/google/protobuf/CodedOutputStream$SafeDirectNioEncoder.class new file mode 100644 index 0000000000000..166bd513cf9f8 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/CodedOutputStream$SafeDirectNioEncoder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/CodedOutputStream$UnsafeDirectNioEncoder.class b/java/kotlin-lite/target/classes/com/google/protobuf/CodedOutputStream$UnsafeDirectNioEncoder.class new file mode 100644 index 0000000000000..0208cf091bc0a Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/CodedOutputStream$UnsafeDirectNioEncoder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/CodedOutputStream.class b/java/kotlin-lite/target/classes/com/google/protobuf/CodedOutputStream.class new file mode 100644 index 0000000000000..29fcf07fec5ec Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/CodedOutputStream.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/CodedOutputStreamWriter$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/CodedOutputStreamWriter$1.class new file mode 100644 index 0000000000000..2400384084233 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/CodedOutputStreamWriter$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/CodedOutputStreamWriter.class b/java/kotlin-lite/target/classes/com/google/protobuf/CodedOutputStreamWriter.class new file mode 100644 index 0000000000000..7b8fe1b90bd2c Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/CodedOutputStreamWriter.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/DoubleArrayList.class b/java/kotlin-lite/target/classes/com/google/protobuf/DoubleArrayList.class new file mode 100644 index 0000000000000..b8e0dc20eec29 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/DoubleArrayList.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/DoubleValue$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/DoubleValue$1.class new file mode 100644 index 0000000000000..11b102b22ce4f Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/DoubleValue$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/DoubleValue$Builder.class b/java/kotlin-lite/target/classes/com/google/protobuf/DoubleValue$Builder.class new file mode 100644 index 0000000000000..b5405e9f5f27e Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/DoubleValue$Builder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/DoubleValue.class b/java/kotlin-lite/target/classes/com/google/protobuf/DoubleValue.class new file mode 100644 index 0000000000000..e3cbe73f3cb3f Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/DoubleValue.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/DoubleValueOrBuilder.class b/java/kotlin-lite/target/classes/com/google/protobuf/DoubleValueOrBuilder.class new file mode 100644 index 0000000000000..c7ae32144cd6d Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/DoubleValueOrBuilder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Duration$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/Duration$1.class new file mode 100644 index 0000000000000..7228c3f2441a9 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Duration$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Duration$Builder.class b/java/kotlin-lite/target/classes/com/google/protobuf/Duration$Builder.class new file mode 100644 index 0000000000000..f81da9797d3fb Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Duration$Builder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Duration.class b/java/kotlin-lite/target/classes/com/google/protobuf/Duration.class new file mode 100644 index 0000000000000..336ffbeb8b3fb Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Duration.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/DurationOrBuilder.class b/java/kotlin-lite/target/classes/com/google/protobuf/DurationOrBuilder.class new file mode 100644 index 0000000000000..067fb708b77f3 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/DurationOrBuilder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/DurationProto.class b/java/kotlin-lite/target/classes/com/google/protobuf/DurationProto.class new file mode 100644 index 0000000000000..3cb3ec67575d4 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/DurationProto.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Empty$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/Empty$1.class new file mode 100644 index 0000000000000..d1b55ddb83aa2 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Empty$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Empty$Builder.class b/java/kotlin-lite/target/classes/com/google/protobuf/Empty$Builder.class new file mode 100644 index 0000000000000..8af81c9ee1f5b Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Empty$Builder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Empty.class b/java/kotlin-lite/target/classes/com/google/protobuf/Empty.class new file mode 100644 index 0000000000000..54120182ddeff Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Empty.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/EmptyOrBuilder.class b/java/kotlin-lite/target/classes/com/google/protobuf/EmptyOrBuilder.class new file mode 100644 index 0000000000000..0e3e1fa76771f Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/EmptyOrBuilder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/EmptyProto.class b/java/kotlin-lite/target/classes/com/google/protobuf/EmptyProto.class new file mode 100644 index 0000000000000..622d06fea396f Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/EmptyProto.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Enum$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/Enum$1.class new file mode 100644 index 0000000000000..e9e9fed868c57 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Enum$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Enum$Builder.class b/java/kotlin-lite/target/classes/com/google/protobuf/Enum$Builder.class new file mode 100644 index 0000000000000..335c20a24e611 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Enum$Builder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Enum.class b/java/kotlin-lite/target/classes/com/google/protobuf/Enum.class new file mode 100644 index 0000000000000..ddd94aea0f731 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Enum.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/EnumOrBuilder.class b/java/kotlin-lite/target/classes/com/google/protobuf/EnumOrBuilder.class new file mode 100644 index 0000000000000..122ee9147ab0f Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/EnumOrBuilder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/EnumValue$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/EnumValue$1.class new file mode 100644 index 0000000000000..aac3008e97ed8 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/EnumValue$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/EnumValue$Builder.class b/java/kotlin-lite/target/classes/com/google/protobuf/EnumValue$Builder.class new file mode 100644 index 0000000000000..0d31584078841 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/EnumValue$Builder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/EnumValue.class b/java/kotlin-lite/target/classes/com/google/protobuf/EnumValue.class new file mode 100644 index 0000000000000..2cfdad40d01e5 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/EnumValue.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/EnumValueOrBuilder.class b/java/kotlin-lite/target/classes/com/google/protobuf/EnumValueOrBuilder.class new file mode 100644 index 0000000000000..2e5a21ba4cfc3 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/EnumValueOrBuilder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/ExperimentalApi.class b/java/kotlin-lite/target/classes/com/google/protobuf/ExperimentalApi.class new file mode 100644 index 0000000000000..ee21fbf935906 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/ExperimentalApi.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/ExtensionLite.class b/java/kotlin-lite/target/classes/com/google/protobuf/ExtensionLite.class new file mode 100644 index 0000000000000..4cc58a768103b Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/ExtensionLite.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/ExtensionRegistryFactory.class b/java/kotlin-lite/target/classes/com/google/protobuf/ExtensionRegistryFactory.class new file mode 100644 index 0000000000000..a881401d2a696 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/ExtensionRegistryFactory.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/ExtensionRegistryLite$ExtensionClassHolder.class b/java/kotlin-lite/target/classes/com/google/protobuf/ExtensionRegistryLite$ExtensionClassHolder.class new file mode 100644 index 0000000000000..5fe9f764395dd Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/ExtensionRegistryLite$ExtensionClassHolder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/ExtensionRegistryLite$ObjectIntPair.class b/java/kotlin-lite/target/classes/com/google/protobuf/ExtensionRegistryLite$ObjectIntPair.class new file mode 100644 index 0000000000000..72c48235151f6 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/ExtensionRegistryLite$ObjectIntPair.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/ExtensionRegistryLite.class b/java/kotlin-lite/target/classes/com/google/protobuf/ExtensionRegistryLite.class new file mode 100644 index 0000000000000..034cdac2c9866 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/ExtensionRegistryLite.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/ExtensionSchema.class b/java/kotlin-lite/target/classes/com/google/protobuf/ExtensionSchema.class new file mode 100644 index 0000000000000..2012de780198a Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/ExtensionSchema.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/ExtensionSchemaLite$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/ExtensionSchemaLite$1.class new file mode 100644 index 0000000000000..1b67f7a6b6457 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/ExtensionSchemaLite$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/ExtensionSchemaLite.class b/java/kotlin-lite/target/classes/com/google/protobuf/ExtensionSchemaLite.class new file mode 100644 index 0000000000000..c45dcff88b19d Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/ExtensionSchemaLite.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/ExtensionSchemas.class b/java/kotlin-lite/target/classes/com/google/protobuf/ExtensionSchemas.class new file mode 100644 index 0000000000000..cb980fe2036e5 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/ExtensionSchemas.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Field$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/Field$1.class new file mode 100644 index 0000000000000..933f7341b8980 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Field$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Field$Builder.class b/java/kotlin-lite/target/classes/com/google/protobuf/Field$Builder.class new file mode 100644 index 0000000000000..36ff454ba0029 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Field$Builder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Field$Cardinality$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/Field$Cardinality$1.class new file mode 100644 index 0000000000000..576076045118e Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Field$Cardinality$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Field$Cardinality$CardinalityVerifier.class b/java/kotlin-lite/target/classes/com/google/protobuf/Field$Cardinality$CardinalityVerifier.class new file mode 100644 index 0000000000000..7622b72e003da Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Field$Cardinality$CardinalityVerifier.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Field$Cardinality.class b/java/kotlin-lite/target/classes/com/google/protobuf/Field$Cardinality.class new file mode 100644 index 0000000000000..23f3dc52f3f1c Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Field$Cardinality.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Field$Kind$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/Field$Kind$1.class new file mode 100644 index 0000000000000..81eb3031b88cd Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Field$Kind$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Field$Kind$KindVerifier.class b/java/kotlin-lite/target/classes/com/google/protobuf/Field$Kind$KindVerifier.class new file mode 100644 index 0000000000000..e9a1f24f391e0 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Field$Kind$KindVerifier.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Field$Kind.class b/java/kotlin-lite/target/classes/com/google/protobuf/Field$Kind.class new file mode 100644 index 0000000000000..528963c75a249 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Field$Kind.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Field.class b/java/kotlin-lite/target/classes/com/google/protobuf/Field.class new file mode 100644 index 0000000000000..96afb9ea700c5 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Field.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/FieldInfo$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/FieldInfo$1.class new file mode 100644 index 0000000000000..2c2e2a3d759ef Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/FieldInfo$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/FieldInfo$Builder.class b/java/kotlin-lite/target/classes/com/google/protobuf/FieldInfo$Builder.class new file mode 100644 index 0000000000000..21b24b6782c29 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/FieldInfo$Builder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/FieldInfo.class b/java/kotlin-lite/target/classes/com/google/protobuf/FieldInfo.class new file mode 100644 index 0000000000000..f321af73bbac5 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/FieldInfo.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/FieldMask$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/FieldMask$1.class new file mode 100644 index 0000000000000..cc0d4165d2313 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/FieldMask$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/FieldMask$Builder.class b/java/kotlin-lite/target/classes/com/google/protobuf/FieldMask$Builder.class new file mode 100644 index 0000000000000..c738aad07a646 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/FieldMask$Builder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/FieldMask.class b/java/kotlin-lite/target/classes/com/google/protobuf/FieldMask.class new file mode 100644 index 0000000000000..b123060cf920d Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/FieldMask.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/FieldMaskOrBuilder.class b/java/kotlin-lite/target/classes/com/google/protobuf/FieldMaskOrBuilder.class new file mode 100644 index 0000000000000..2e4ea044d1671 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/FieldMaskOrBuilder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/FieldMaskProto.class b/java/kotlin-lite/target/classes/com/google/protobuf/FieldMaskProto.class new file mode 100644 index 0000000000000..b0bac3bf387e2 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/FieldMaskProto.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/FieldOrBuilder.class b/java/kotlin-lite/target/classes/com/google/protobuf/FieldOrBuilder.class new file mode 100644 index 0000000000000..667c55178c7b7 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/FieldOrBuilder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/FieldSet$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/FieldSet$1.class new file mode 100644 index 0000000000000..1264bc4c6b5a2 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/FieldSet$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/FieldSet$Builder.class b/java/kotlin-lite/target/classes/com/google/protobuf/FieldSet$Builder.class new file mode 100644 index 0000000000000..9beda36f54497 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/FieldSet$Builder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/FieldSet$FieldDescriptorLite.class b/java/kotlin-lite/target/classes/com/google/protobuf/FieldSet$FieldDescriptorLite.class new file mode 100644 index 0000000000000..170d3b225393c Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/FieldSet$FieldDescriptorLite.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/FieldSet.class b/java/kotlin-lite/target/classes/com/google/protobuf/FieldSet.class new file mode 100644 index 0000000000000..bde362b9998fb Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/FieldSet.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/FieldType$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/FieldType$1.class new file mode 100644 index 0000000000000..5e31d0a588c43 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/FieldType$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/FieldType$Collection.class b/java/kotlin-lite/target/classes/com/google/protobuf/FieldType$Collection.class new file mode 100644 index 0000000000000..62e80edd8d1df Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/FieldType$Collection.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/FieldType.class b/java/kotlin-lite/target/classes/com/google/protobuf/FieldType.class new file mode 100644 index 0000000000000..1db06ab46d3bb Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/FieldType.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/FloatArrayList.class b/java/kotlin-lite/target/classes/com/google/protobuf/FloatArrayList.class new file mode 100644 index 0000000000000..84e15f1b6e82c Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/FloatArrayList.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/FloatValue$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/FloatValue$1.class new file mode 100644 index 0000000000000..79737cd7c2bfd Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/FloatValue$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/FloatValue$Builder.class b/java/kotlin-lite/target/classes/com/google/protobuf/FloatValue$Builder.class new file mode 100644 index 0000000000000..944b681a99004 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/FloatValue$Builder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/FloatValue.class b/java/kotlin-lite/target/classes/com/google/protobuf/FloatValue.class new file mode 100644 index 0000000000000..9fa301c8c6667 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/FloatValue.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/FloatValueOrBuilder.class b/java/kotlin-lite/target/classes/com/google/protobuf/FloatValueOrBuilder.class new file mode 100644 index 0000000000000..08b00d480e9d8 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/FloatValueOrBuilder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/GeneratedMessageInfoFactory.class b/java/kotlin-lite/target/classes/com/google/protobuf/GeneratedMessageInfoFactory.class new file mode 100644 index 0000000000000..ef5aac3a4d657 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/GeneratedMessageInfoFactory.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/GeneratedMessageLite$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/GeneratedMessageLite$1.class new file mode 100644 index 0000000000000..904c99e867cbe Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/GeneratedMessageLite$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/GeneratedMessageLite$Builder.class b/java/kotlin-lite/target/classes/com/google/protobuf/GeneratedMessageLite$Builder.class new file mode 100644 index 0000000000000..53c1cffff8b3d Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/GeneratedMessageLite$Builder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/GeneratedMessageLite$DefaultInstanceBasedParser.class b/java/kotlin-lite/target/classes/com/google/protobuf/GeneratedMessageLite$DefaultInstanceBasedParser.class new file mode 100644 index 0000000000000..4a15fe4942f80 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/GeneratedMessageLite$DefaultInstanceBasedParser.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/GeneratedMessageLite$ExtendableBuilder.class b/java/kotlin-lite/target/classes/com/google/protobuf/GeneratedMessageLite$ExtendableBuilder.class new file mode 100644 index 0000000000000..4f9cc8208db4a Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/GeneratedMessageLite$ExtendableBuilder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/GeneratedMessageLite$ExtendableMessage$ExtensionWriter.class b/java/kotlin-lite/target/classes/com/google/protobuf/GeneratedMessageLite$ExtendableMessage$ExtensionWriter.class new file mode 100644 index 0000000000000..9fb00ba9ff99b Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/GeneratedMessageLite$ExtendableMessage$ExtensionWriter.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/GeneratedMessageLite$ExtendableMessage.class b/java/kotlin-lite/target/classes/com/google/protobuf/GeneratedMessageLite$ExtendableMessage.class new file mode 100644 index 0000000000000..948ce73860699 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/GeneratedMessageLite$ExtendableMessage.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/GeneratedMessageLite$ExtendableMessageOrBuilder.class b/java/kotlin-lite/target/classes/com/google/protobuf/GeneratedMessageLite$ExtendableMessageOrBuilder.class new file mode 100644 index 0000000000000..c463262e29a64 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/GeneratedMessageLite$ExtendableMessageOrBuilder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/GeneratedMessageLite$ExtensionDescriptor.class b/java/kotlin-lite/target/classes/com/google/protobuf/GeneratedMessageLite$ExtensionDescriptor.class new file mode 100644 index 0000000000000..868f536c99511 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/GeneratedMessageLite$ExtensionDescriptor.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/GeneratedMessageLite$GeneratedExtension.class b/java/kotlin-lite/target/classes/com/google/protobuf/GeneratedMessageLite$GeneratedExtension.class new file mode 100644 index 0000000000000..709ccec63eda9 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/GeneratedMessageLite$GeneratedExtension.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/GeneratedMessageLite$MethodToInvoke.class b/java/kotlin-lite/target/classes/com/google/protobuf/GeneratedMessageLite$MethodToInvoke.class new file mode 100644 index 0000000000000..72d3a4c5027f4 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/GeneratedMessageLite$MethodToInvoke.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/GeneratedMessageLite$SerializedForm.class b/java/kotlin-lite/target/classes/com/google/protobuf/GeneratedMessageLite$SerializedForm.class new file mode 100644 index 0000000000000..60924d7323ad0 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/GeneratedMessageLite$SerializedForm.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/GeneratedMessageLite.class b/java/kotlin-lite/target/classes/com/google/protobuf/GeneratedMessageLite.class new file mode 100644 index 0000000000000..64a5c3fcf571d Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/GeneratedMessageLite.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Int32Value$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/Int32Value$1.class new file mode 100644 index 0000000000000..df5936fd12117 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Int32Value$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Int32Value$Builder.class b/java/kotlin-lite/target/classes/com/google/protobuf/Int32Value$Builder.class new file mode 100644 index 0000000000000..dc3862fa66ffb Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Int32Value$Builder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Int32Value.class b/java/kotlin-lite/target/classes/com/google/protobuf/Int32Value.class new file mode 100644 index 0000000000000..a12434eb1198a Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Int32Value.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Int32ValueOrBuilder.class b/java/kotlin-lite/target/classes/com/google/protobuf/Int32ValueOrBuilder.class new file mode 100644 index 0000000000000..a01ff795ed73d Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Int32ValueOrBuilder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Int64Value$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/Int64Value$1.class new file mode 100644 index 0000000000000..758c783b1e36f Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Int64Value$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Int64Value$Builder.class b/java/kotlin-lite/target/classes/com/google/protobuf/Int64Value$Builder.class new file mode 100644 index 0000000000000..fe2f2f77fb3e9 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Int64Value$Builder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Int64Value.class b/java/kotlin-lite/target/classes/com/google/protobuf/Int64Value.class new file mode 100644 index 0000000000000..fa12966eccade Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Int64Value.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Int64ValueOrBuilder.class b/java/kotlin-lite/target/classes/com/google/protobuf/Int64ValueOrBuilder.class new file mode 100644 index 0000000000000..06611c6895dfb Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Int64ValueOrBuilder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/IntArrayList.class b/java/kotlin-lite/target/classes/com/google/protobuf/IntArrayList.class new file mode 100644 index 0000000000000..95a07a45b5abf Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/IntArrayList.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Internal$BooleanList.class b/java/kotlin-lite/target/classes/com/google/protobuf/Internal$BooleanList.class new file mode 100644 index 0000000000000..c9905519f3fd1 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Internal$BooleanList.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Internal$DoubleList.class b/java/kotlin-lite/target/classes/com/google/protobuf/Internal$DoubleList.class new file mode 100644 index 0000000000000..20213cce7e9ed Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Internal$DoubleList.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Internal$EnumLite.class b/java/kotlin-lite/target/classes/com/google/protobuf/Internal$EnumLite.class new file mode 100644 index 0000000000000..f7529a726654b Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Internal$EnumLite.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Internal$EnumLiteMap.class b/java/kotlin-lite/target/classes/com/google/protobuf/Internal$EnumLiteMap.class new file mode 100644 index 0000000000000..8926294adf1b3 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Internal$EnumLiteMap.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Internal$EnumVerifier.class b/java/kotlin-lite/target/classes/com/google/protobuf/Internal$EnumVerifier.class new file mode 100644 index 0000000000000..4f5168440c0b1 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Internal$EnumVerifier.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Internal$FloatList.class b/java/kotlin-lite/target/classes/com/google/protobuf/Internal$FloatList.class new file mode 100644 index 0000000000000..94c893e481881 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Internal$FloatList.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Internal$IntList.class b/java/kotlin-lite/target/classes/com/google/protobuf/Internal$IntList.class new file mode 100644 index 0000000000000..411446b95d468 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Internal$IntList.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Internal$ListAdapter$Converter.class b/java/kotlin-lite/target/classes/com/google/protobuf/Internal$ListAdapter$Converter.class new file mode 100644 index 0000000000000..d55d0213c1ddc Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Internal$ListAdapter$Converter.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Internal$ListAdapter.class b/java/kotlin-lite/target/classes/com/google/protobuf/Internal$ListAdapter.class new file mode 100644 index 0000000000000..022c33d730c32 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Internal$ListAdapter.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Internal$LongList.class b/java/kotlin-lite/target/classes/com/google/protobuf/Internal$LongList.class new file mode 100644 index 0000000000000..a39f9cd4aa79c Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Internal$LongList.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Internal$MapAdapter$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/Internal$MapAdapter$1.class new file mode 100644 index 0000000000000..27b93fdc146cf Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Internal$MapAdapter$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Internal$MapAdapter$Converter.class b/java/kotlin-lite/target/classes/com/google/protobuf/Internal$MapAdapter$Converter.class new file mode 100644 index 0000000000000..758e651f4ca6d Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Internal$MapAdapter$Converter.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Internal$MapAdapter$EntryAdapter.class b/java/kotlin-lite/target/classes/com/google/protobuf/Internal$MapAdapter$EntryAdapter.class new file mode 100644 index 0000000000000..45ba6edcfef62 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Internal$MapAdapter$EntryAdapter.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Internal$MapAdapter$IteratorAdapter.class b/java/kotlin-lite/target/classes/com/google/protobuf/Internal$MapAdapter$IteratorAdapter.class new file mode 100644 index 0000000000000..2db85e391056d Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Internal$MapAdapter$IteratorAdapter.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Internal$MapAdapter$SetAdapter.class b/java/kotlin-lite/target/classes/com/google/protobuf/Internal$MapAdapter$SetAdapter.class new file mode 100644 index 0000000000000..601ab08ea0e0f Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Internal$MapAdapter$SetAdapter.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Internal$MapAdapter.class b/java/kotlin-lite/target/classes/com/google/protobuf/Internal$MapAdapter.class new file mode 100644 index 0000000000000..a9d70d06077cd Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Internal$MapAdapter.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Internal$ProtobufList.class b/java/kotlin-lite/target/classes/com/google/protobuf/Internal$ProtobufList.class new file mode 100644 index 0000000000000..26b6d47dd1ca2 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Internal$ProtobufList.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Internal.class b/java/kotlin-lite/target/classes/com/google/protobuf/Internal.class new file mode 100644 index 0000000000000..f62d009ff939c Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Internal.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/InvalidProtocolBufferException$InvalidWireTypeException.class b/java/kotlin-lite/target/classes/com/google/protobuf/InvalidProtocolBufferException$InvalidWireTypeException.class new file mode 100644 index 0000000000000..d2c6bef3c68db Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/InvalidProtocolBufferException$InvalidWireTypeException.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/InvalidProtocolBufferException.class b/java/kotlin-lite/target/classes/com/google/protobuf/InvalidProtocolBufferException.class new file mode 100644 index 0000000000000..e83d6e2a095e7 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/InvalidProtocolBufferException.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/IterableByteBufferInputStream.class b/java/kotlin-lite/target/classes/com/google/protobuf/IterableByteBufferInputStream.class new file mode 100644 index 0000000000000..81e0fe4394680 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/IterableByteBufferInputStream.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/JavaType.class b/java/kotlin-lite/target/classes/com/google/protobuf/JavaType.class new file mode 100644 index 0000000000000..656ff6c05b327 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/JavaType.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/LazyField$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/LazyField$1.class new file mode 100644 index 0000000000000..36f5db8958232 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/LazyField$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/LazyField$LazyEntry.class b/java/kotlin-lite/target/classes/com/google/protobuf/LazyField$LazyEntry.class new file mode 100644 index 0000000000000..fc22a989e8c95 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/LazyField$LazyEntry.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/LazyField$LazyIterator.class b/java/kotlin-lite/target/classes/com/google/protobuf/LazyField$LazyIterator.class new file mode 100644 index 0000000000000..f96db166d6158 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/LazyField$LazyIterator.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/LazyField.class b/java/kotlin-lite/target/classes/com/google/protobuf/LazyField.class new file mode 100644 index 0000000000000..64ef415812427 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/LazyField.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/LazyFieldLite.class b/java/kotlin-lite/target/classes/com/google/protobuf/LazyFieldLite.class new file mode 100644 index 0000000000000..af95471c0969f Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/LazyFieldLite.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/LazyStringArrayList$ByteArrayListView.class b/java/kotlin-lite/target/classes/com/google/protobuf/LazyStringArrayList$ByteArrayListView.class new file mode 100644 index 0000000000000..904e5b1301470 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/LazyStringArrayList$ByteArrayListView.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/LazyStringArrayList$ByteStringListView.class b/java/kotlin-lite/target/classes/com/google/protobuf/LazyStringArrayList$ByteStringListView.class new file mode 100644 index 0000000000000..5404ef0197e0e Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/LazyStringArrayList$ByteStringListView.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/LazyStringArrayList.class b/java/kotlin-lite/target/classes/com/google/protobuf/LazyStringArrayList.class new file mode 100644 index 0000000000000..6973bcd39f523 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/LazyStringArrayList.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/LazyStringList.class b/java/kotlin-lite/target/classes/com/google/protobuf/LazyStringList.class new file mode 100644 index 0000000000000..d906bc907d4eb Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/LazyStringList.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/ListFieldSchema$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/ListFieldSchema$1.class new file mode 100644 index 0000000000000..3a187a24d5985 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/ListFieldSchema$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/ListFieldSchema$ListFieldSchemaFull.class b/java/kotlin-lite/target/classes/com/google/protobuf/ListFieldSchema$ListFieldSchemaFull.class new file mode 100644 index 0000000000000..589fb2ca43a54 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/ListFieldSchema$ListFieldSchemaFull.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/ListFieldSchema$ListFieldSchemaLite.class b/java/kotlin-lite/target/classes/com/google/protobuf/ListFieldSchema$ListFieldSchemaLite.class new file mode 100644 index 0000000000000..6822eebd15142 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/ListFieldSchema$ListFieldSchemaLite.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/ListFieldSchema.class b/java/kotlin-lite/target/classes/com/google/protobuf/ListFieldSchema.class new file mode 100644 index 0000000000000..b439b86604323 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/ListFieldSchema.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/ListValue$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/ListValue$1.class new file mode 100644 index 0000000000000..3f1ec2f01fbff Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/ListValue$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/ListValue$Builder.class b/java/kotlin-lite/target/classes/com/google/protobuf/ListValue$Builder.class new file mode 100644 index 0000000000000..03f255210ccde Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/ListValue$Builder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/ListValue.class b/java/kotlin-lite/target/classes/com/google/protobuf/ListValue.class new file mode 100644 index 0000000000000..b078bc98201d2 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/ListValue.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/ListValueOrBuilder.class b/java/kotlin-lite/target/classes/com/google/protobuf/ListValueOrBuilder.class new file mode 100644 index 0000000000000..8dacb4af96ccd Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/ListValueOrBuilder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/LongArrayList.class b/java/kotlin-lite/target/classes/com/google/protobuf/LongArrayList.class new file mode 100644 index 0000000000000..53c7de3fdba8f Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/LongArrayList.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/ManifestSchemaFactory$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/ManifestSchemaFactory$1.class new file mode 100644 index 0000000000000..909b938b32223 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/ManifestSchemaFactory$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/ManifestSchemaFactory$CompositeMessageInfoFactory.class b/java/kotlin-lite/target/classes/com/google/protobuf/ManifestSchemaFactory$CompositeMessageInfoFactory.class new file mode 100644 index 0000000000000..e82186a956782 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/ManifestSchemaFactory$CompositeMessageInfoFactory.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/ManifestSchemaFactory.class b/java/kotlin-lite/target/classes/com/google/protobuf/ManifestSchemaFactory.class new file mode 100644 index 0000000000000..007f21701593b Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/ManifestSchemaFactory.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/MapEntryLite$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/MapEntryLite$1.class new file mode 100644 index 0000000000000..bc1bb3db60eb9 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/MapEntryLite$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/MapEntryLite$Metadata.class b/java/kotlin-lite/target/classes/com/google/protobuf/MapEntryLite$Metadata.class new file mode 100644 index 0000000000000..3b69598a25d7b Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/MapEntryLite$Metadata.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/MapEntryLite.class b/java/kotlin-lite/target/classes/com/google/protobuf/MapEntryLite.class new file mode 100644 index 0000000000000..a57cd8976268d Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/MapEntryLite.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/MapFieldLite.class b/java/kotlin-lite/target/classes/com/google/protobuf/MapFieldLite.class new file mode 100644 index 0000000000000..42129d7d6ae72 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/MapFieldLite.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/MapFieldSchema.class b/java/kotlin-lite/target/classes/com/google/protobuf/MapFieldSchema.class new file mode 100644 index 0000000000000..8ef7502c53ff9 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/MapFieldSchema.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/MapFieldSchemaLite.class b/java/kotlin-lite/target/classes/com/google/protobuf/MapFieldSchemaLite.class new file mode 100644 index 0000000000000..9ace23ce22a29 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/MapFieldSchemaLite.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/MapFieldSchemas.class b/java/kotlin-lite/target/classes/com/google/protobuf/MapFieldSchemas.class new file mode 100644 index 0000000000000..0e5c9001a8ed7 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/MapFieldSchemas.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/MessageInfo.class b/java/kotlin-lite/target/classes/com/google/protobuf/MessageInfo.class new file mode 100644 index 0000000000000..93c461ae1a3e7 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/MessageInfo.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/MessageInfoFactory.class b/java/kotlin-lite/target/classes/com/google/protobuf/MessageInfoFactory.class new file mode 100644 index 0000000000000..65128b130de66 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/MessageInfoFactory.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/MessageLite$Builder.class b/java/kotlin-lite/target/classes/com/google/protobuf/MessageLite$Builder.class new file mode 100644 index 0000000000000..5148c02195dc3 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/MessageLite$Builder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/MessageLite.class b/java/kotlin-lite/target/classes/com/google/protobuf/MessageLite.class new file mode 100644 index 0000000000000..a309e33b8aba0 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/MessageLite.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/MessageLiteOrBuilder.class b/java/kotlin-lite/target/classes/com/google/protobuf/MessageLiteOrBuilder.class new file mode 100644 index 0000000000000..33413d44935d5 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/MessageLiteOrBuilder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/MessageLiteToString.class b/java/kotlin-lite/target/classes/com/google/protobuf/MessageLiteToString.class new file mode 100644 index 0000000000000..f3db2d2311e94 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/MessageLiteToString.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/MessageSchema$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/MessageSchema$1.class new file mode 100644 index 0000000000000..2595bc095b708 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/MessageSchema$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/MessageSchema.class b/java/kotlin-lite/target/classes/com/google/protobuf/MessageSchema.class new file mode 100644 index 0000000000000..5ca3358984872 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/MessageSchema.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/MessageSetSchema.class b/java/kotlin-lite/target/classes/com/google/protobuf/MessageSetSchema.class new file mode 100644 index 0000000000000..16a0e46f73fcd Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/MessageSetSchema.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Method$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/Method$1.class new file mode 100644 index 0000000000000..4792b4718a559 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Method$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Method$Builder.class b/java/kotlin-lite/target/classes/com/google/protobuf/Method$Builder.class new file mode 100644 index 0000000000000..d9daf9ec2d41a Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Method$Builder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Method.class b/java/kotlin-lite/target/classes/com/google/protobuf/Method.class new file mode 100644 index 0000000000000..ab48753ca9510 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Method.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/MethodOrBuilder.class b/java/kotlin-lite/target/classes/com/google/protobuf/MethodOrBuilder.class new file mode 100644 index 0000000000000..89984a2eb5534 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/MethodOrBuilder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Mixin$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/Mixin$1.class new file mode 100644 index 0000000000000..4600fd3116e09 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Mixin$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Mixin$Builder.class b/java/kotlin-lite/target/classes/com/google/protobuf/Mixin$Builder.class new file mode 100644 index 0000000000000..46c3454fe8d82 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Mixin$Builder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Mixin.class b/java/kotlin-lite/target/classes/com/google/protobuf/Mixin.class new file mode 100644 index 0000000000000..a261772776a5e Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Mixin.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/MixinOrBuilder.class b/java/kotlin-lite/target/classes/com/google/protobuf/MixinOrBuilder.class new file mode 100644 index 0000000000000..6c7471254283f Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/MixinOrBuilder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/MutabilityOracle$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/MutabilityOracle$1.class new file mode 100644 index 0000000000000..5e32301b5cae9 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/MutabilityOracle$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/MutabilityOracle.class b/java/kotlin-lite/target/classes/com/google/protobuf/MutabilityOracle.class new file mode 100644 index 0000000000000..cc3f3d42b841c Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/MutabilityOracle.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/NewInstanceSchema.class b/java/kotlin-lite/target/classes/com/google/protobuf/NewInstanceSchema.class new file mode 100644 index 0000000000000..bf08e42827e21 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/NewInstanceSchema.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/NewInstanceSchemaLite.class b/java/kotlin-lite/target/classes/com/google/protobuf/NewInstanceSchemaLite.class new file mode 100644 index 0000000000000..14c004ebb31af Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/NewInstanceSchemaLite.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/NewInstanceSchemas.class b/java/kotlin-lite/target/classes/com/google/protobuf/NewInstanceSchemas.class new file mode 100644 index 0000000000000..0ab924bb13a97 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/NewInstanceSchemas.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/NioByteString$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/NioByteString$1.class new file mode 100644 index 0000000000000..fad72ce3d63f1 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/NioByteString$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/NioByteString.class b/java/kotlin-lite/target/classes/com/google/protobuf/NioByteString.class new file mode 100644 index 0000000000000..974b819d6781a Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/NioByteString.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/NullValue$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/NullValue$1.class new file mode 100644 index 0000000000000..89fbf74ed451b Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/NullValue$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/NullValue$NullValueVerifier.class b/java/kotlin-lite/target/classes/com/google/protobuf/NullValue$NullValueVerifier.class new file mode 100644 index 0000000000000..82c3899df8951 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/NullValue$NullValueVerifier.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/NullValue.class b/java/kotlin-lite/target/classes/com/google/protobuf/NullValue.class new file mode 100644 index 0000000000000..79a7e0d5524cb Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/NullValue.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/OneofInfo.class b/java/kotlin-lite/target/classes/com/google/protobuf/OneofInfo.class new file mode 100644 index 0000000000000..7dccf4f61d8bc Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/OneofInfo.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Option$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/Option$1.class new file mode 100644 index 0000000000000..75b81003c9c42 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Option$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Option$Builder.class b/java/kotlin-lite/target/classes/com/google/protobuf/Option$Builder.class new file mode 100644 index 0000000000000..716c9afe75e7f Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Option$Builder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Option.class b/java/kotlin-lite/target/classes/com/google/protobuf/Option.class new file mode 100644 index 0000000000000..e62aa843e3f57 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Option.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/OptionOrBuilder.class b/java/kotlin-lite/target/classes/com/google/protobuf/OptionOrBuilder.class new file mode 100644 index 0000000000000..9194a114daa0f Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/OptionOrBuilder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Parser.class b/java/kotlin-lite/target/classes/com/google/protobuf/Parser.class new file mode 100644 index 0000000000000..df716106a80da Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Parser.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/PrimitiveNonBoxingCollection.class b/java/kotlin-lite/target/classes/com/google/protobuf/PrimitiveNonBoxingCollection.class new file mode 100644 index 0000000000000..fd32754e2893f Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/PrimitiveNonBoxingCollection.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/ProtoSyntax.class b/java/kotlin-lite/target/classes/com/google/protobuf/ProtoSyntax.class new file mode 100644 index 0000000000000..84042d4275a75 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/ProtoSyntax.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Protobuf.class b/java/kotlin-lite/target/classes/com/google/protobuf/Protobuf.class new file mode 100644 index 0000000000000..1411d9a9a43f1 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Protobuf.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/ProtobufArrayList.class b/java/kotlin-lite/target/classes/com/google/protobuf/ProtobufArrayList.class new file mode 100644 index 0000000000000..52359f74e860e Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/ProtobufArrayList.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/ProtobufLists.class b/java/kotlin-lite/target/classes/com/google/protobuf/ProtobufLists.class new file mode 100644 index 0000000000000..3ba32bcafb069 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/ProtobufLists.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/ProtocolStringList.class b/java/kotlin-lite/target/classes/com/google/protobuf/ProtocolStringList.class new file mode 100644 index 0000000000000..616fe69765ec3 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/ProtocolStringList.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/RawMessageInfo.class b/java/kotlin-lite/target/classes/com/google/protobuf/RawMessageInfo.class new file mode 100644 index 0000000000000..b0eb2a338d5a4 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/RawMessageInfo.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Reader.class b/java/kotlin-lite/target/classes/com/google/protobuf/Reader.class new file mode 100644 index 0000000000000..487ed182fb980 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Reader.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/RopeByteString$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/RopeByteString$1.class new file mode 100644 index 0000000000000..b8f9d2516fcc4 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/RopeByteString$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/RopeByteString$Balancer.class b/java/kotlin-lite/target/classes/com/google/protobuf/RopeByteString$Balancer.class new file mode 100644 index 0000000000000..da3ca01bdccc5 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/RopeByteString$Balancer.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/RopeByteString$PieceIterator.class b/java/kotlin-lite/target/classes/com/google/protobuf/RopeByteString$PieceIterator.class new file mode 100644 index 0000000000000..83c53262c6dee Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/RopeByteString$PieceIterator.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/RopeByteString$RopeInputStream.class b/java/kotlin-lite/target/classes/com/google/protobuf/RopeByteString$RopeInputStream.class new file mode 100644 index 0000000000000..745194248836f Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/RopeByteString$RopeInputStream.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/RopeByteString.class b/java/kotlin-lite/target/classes/com/google/protobuf/RopeByteString.class new file mode 100644 index 0000000000000..c74704904a5a7 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/RopeByteString.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Schema.class b/java/kotlin-lite/target/classes/com/google/protobuf/Schema.class new file mode 100644 index 0000000000000..d5e03494bb555 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Schema.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/SchemaFactory.class b/java/kotlin-lite/target/classes/com/google/protobuf/SchemaFactory.class new file mode 100644 index 0000000000000..d219235879c59 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/SchemaFactory.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/SchemaUtil.class b/java/kotlin-lite/target/classes/com/google/protobuf/SchemaUtil.class new file mode 100644 index 0000000000000..34d1cadac2fef Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/SchemaUtil.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/SmallSortedMap$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/SmallSortedMap$1.class new file mode 100644 index 0000000000000..9b101db5db62a Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/SmallSortedMap$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/SmallSortedMap$DescendingEntryIterator.class b/java/kotlin-lite/target/classes/com/google/protobuf/SmallSortedMap$DescendingEntryIterator.class new file mode 100644 index 0000000000000..b22a66b05b646 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/SmallSortedMap$DescendingEntryIterator.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/SmallSortedMap$DescendingEntrySet.class b/java/kotlin-lite/target/classes/com/google/protobuf/SmallSortedMap$DescendingEntrySet.class new file mode 100644 index 0000000000000..229f8510d201c Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/SmallSortedMap$DescendingEntrySet.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/SmallSortedMap$EmptySet$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/SmallSortedMap$EmptySet$1.class new file mode 100644 index 0000000000000..940145c1096cb Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/SmallSortedMap$EmptySet$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/SmallSortedMap$EmptySet$2.class b/java/kotlin-lite/target/classes/com/google/protobuf/SmallSortedMap$EmptySet$2.class new file mode 100644 index 0000000000000..a4d440e79b0b2 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/SmallSortedMap$EmptySet$2.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/SmallSortedMap$EmptySet.class b/java/kotlin-lite/target/classes/com/google/protobuf/SmallSortedMap$EmptySet.class new file mode 100644 index 0000000000000..e177d2e8a6703 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/SmallSortedMap$EmptySet.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/SmallSortedMap$Entry.class b/java/kotlin-lite/target/classes/com/google/protobuf/SmallSortedMap$Entry.class new file mode 100644 index 0000000000000..1ee612a47160b Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/SmallSortedMap$Entry.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/SmallSortedMap$EntryIterator.class b/java/kotlin-lite/target/classes/com/google/protobuf/SmallSortedMap$EntryIterator.class new file mode 100644 index 0000000000000..1339a5e4c4ce9 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/SmallSortedMap$EntryIterator.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/SmallSortedMap$EntrySet.class b/java/kotlin-lite/target/classes/com/google/protobuf/SmallSortedMap$EntrySet.class new file mode 100644 index 0000000000000..8c083265b65e4 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/SmallSortedMap$EntrySet.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/SmallSortedMap.class b/java/kotlin-lite/target/classes/com/google/protobuf/SmallSortedMap.class new file mode 100644 index 0000000000000..8d2d436e66783 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/SmallSortedMap.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/SourceContext$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/SourceContext$1.class new file mode 100644 index 0000000000000..62d24b93245d4 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/SourceContext$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/SourceContext$Builder.class b/java/kotlin-lite/target/classes/com/google/protobuf/SourceContext$Builder.class new file mode 100644 index 0000000000000..c4b18f1305af4 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/SourceContext$Builder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/SourceContext.class b/java/kotlin-lite/target/classes/com/google/protobuf/SourceContext.class new file mode 100644 index 0000000000000..966d8978c0e06 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/SourceContext.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/SourceContextOrBuilder.class b/java/kotlin-lite/target/classes/com/google/protobuf/SourceContextOrBuilder.class new file mode 100644 index 0000000000000..887236cbedee9 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/SourceContextOrBuilder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/SourceContextProto.class b/java/kotlin-lite/target/classes/com/google/protobuf/SourceContextProto.class new file mode 100644 index 0000000000000..186aa09fd92a1 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/SourceContextProto.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/StringValue$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/StringValue$1.class new file mode 100644 index 0000000000000..80c991240b35a Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/StringValue$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/StringValue$Builder.class b/java/kotlin-lite/target/classes/com/google/protobuf/StringValue$Builder.class new file mode 100644 index 0000000000000..ca4e0f3c05316 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/StringValue$Builder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/StringValue.class b/java/kotlin-lite/target/classes/com/google/protobuf/StringValue.class new file mode 100644 index 0000000000000..380d44ec49527 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/StringValue.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/StringValueOrBuilder.class b/java/kotlin-lite/target/classes/com/google/protobuf/StringValueOrBuilder.class new file mode 100644 index 0000000000000..1e70a31995eb7 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/StringValueOrBuilder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Struct$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/Struct$1.class new file mode 100644 index 0000000000000..2b7a198b7938c Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Struct$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Struct$Builder.class b/java/kotlin-lite/target/classes/com/google/protobuf/Struct$Builder.class new file mode 100644 index 0000000000000..05a692649f413 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Struct$Builder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Struct$FieldsDefaultEntryHolder.class b/java/kotlin-lite/target/classes/com/google/protobuf/Struct$FieldsDefaultEntryHolder.class new file mode 100644 index 0000000000000..e0f59867fbd0b Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Struct$FieldsDefaultEntryHolder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Struct.class b/java/kotlin-lite/target/classes/com/google/protobuf/Struct.class new file mode 100644 index 0000000000000..fc878ce9e697b Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Struct.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/StructOrBuilder.class b/java/kotlin-lite/target/classes/com/google/protobuf/StructOrBuilder.class new file mode 100644 index 0000000000000..3d39498e62699 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/StructOrBuilder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/StructProto.class b/java/kotlin-lite/target/classes/com/google/protobuf/StructProto.class new file mode 100644 index 0000000000000..310ddc82f5ee2 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/StructProto.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/StructuralMessageInfo$Builder.class b/java/kotlin-lite/target/classes/com/google/protobuf/StructuralMessageInfo$Builder.class new file mode 100644 index 0000000000000..d0daed9e1fa70 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/StructuralMessageInfo$Builder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/StructuralMessageInfo.class b/java/kotlin-lite/target/classes/com/google/protobuf/StructuralMessageInfo.class new file mode 100644 index 0000000000000..637bcec2c0808 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/StructuralMessageInfo.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Syntax$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/Syntax$1.class new file mode 100644 index 0000000000000..a16278afb4174 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Syntax$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Syntax$SyntaxVerifier.class b/java/kotlin-lite/target/classes/com/google/protobuf/Syntax$SyntaxVerifier.class new file mode 100644 index 0000000000000..c43c1e2431f36 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Syntax$SyntaxVerifier.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Syntax.class b/java/kotlin-lite/target/classes/com/google/protobuf/Syntax.class new file mode 100644 index 0000000000000..1fa405e4b28cc Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Syntax.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/TextFormatEscaper$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/TextFormatEscaper$1.class new file mode 100644 index 0000000000000..67e33cf221ad1 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/TextFormatEscaper$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/TextFormatEscaper$2.class b/java/kotlin-lite/target/classes/com/google/protobuf/TextFormatEscaper$2.class new file mode 100644 index 0000000000000..e3a88b1f2adab Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/TextFormatEscaper$2.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/TextFormatEscaper$ByteSequence.class b/java/kotlin-lite/target/classes/com/google/protobuf/TextFormatEscaper$ByteSequence.class new file mode 100644 index 0000000000000..c354dfd7e5426 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/TextFormatEscaper$ByteSequence.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/TextFormatEscaper.class b/java/kotlin-lite/target/classes/com/google/protobuf/TextFormatEscaper.class new file mode 100644 index 0000000000000..36714cd9f187c Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/TextFormatEscaper.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Timestamp$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/Timestamp$1.class new file mode 100644 index 0000000000000..74148618559b8 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Timestamp$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Timestamp$Builder.class b/java/kotlin-lite/target/classes/com/google/protobuf/Timestamp$Builder.class new file mode 100644 index 0000000000000..2f0239e02d601 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Timestamp$Builder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Timestamp.class b/java/kotlin-lite/target/classes/com/google/protobuf/Timestamp.class new file mode 100644 index 0000000000000..157cf7dc1d1ad Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Timestamp.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/TimestampOrBuilder.class b/java/kotlin-lite/target/classes/com/google/protobuf/TimestampOrBuilder.class new file mode 100644 index 0000000000000..c83b78f1fac01 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/TimestampOrBuilder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/TimestampProto.class b/java/kotlin-lite/target/classes/com/google/protobuf/TimestampProto.class new file mode 100644 index 0000000000000..6b37ace0b5ff5 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/TimestampProto.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Type$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/Type$1.class new file mode 100644 index 0000000000000..ae52233fad7be Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Type$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Type$Builder.class b/java/kotlin-lite/target/classes/com/google/protobuf/Type$Builder.class new file mode 100644 index 0000000000000..dc2c6ca4c2a0a Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Type$Builder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Type.class b/java/kotlin-lite/target/classes/com/google/protobuf/Type.class new file mode 100644 index 0000000000000..41b6a5f77f149 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Type.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/TypeOrBuilder.class b/java/kotlin-lite/target/classes/com/google/protobuf/TypeOrBuilder.class new file mode 100644 index 0000000000000..4c86fc99fc09d Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/TypeOrBuilder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/TypeProto.class b/java/kotlin-lite/target/classes/com/google/protobuf/TypeProto.class new file mode 100644 index 0000000000000..546c0c49a5f26 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/TypeProto.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/UInt32Value$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/UInt32Value$1.class new file mode 100644 index 0000000000000..4a73da7a39fc7 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/UInt32Value$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/UInt32Value$Builder.class b/java/kotlin-lite/target/classes/com/google/protobuf/UInt32Value$Builder.class new file mode 100644 index 0000000000000..e7607bdd5be58 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/UInt32Value$Builder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/UInt32Value.class b/java/kotlin-lite/target/classes/com/google/protobuf/UInt32Value.class new file mode 100644 index 0000000000000..754c10c0be584 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/UInt32Value.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/UInt32ValueOrBuilder.class b/java/kotlin-lite/target/classes/com/google/protobuf/UInt32ValueOrBuilder.class new file mode 100644 index 0000000000000..f7764ed7c3f9f Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/UInt32ValueOrBuilder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/UInt64Value$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/UInt64Value$1.class new file mode 100644 index 0000000000000..70e9efe646f28 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/UInt64Value$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/UInt64Value$Builder.class b/java/kotlin-lite/target/classes/com/google/protobuf/UInt64Value$Builder.class new file mode 100644 index 0000000000000..c028aab77114d Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/UInt64Value$Builder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/UInt64Value.class b/java/kotlin-lite/target/classes/com/google/protobuf/UInt64Value.class new file mode 100644 index 0000000000000..1c0e31f4bc374 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/UInt64Value.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/UInt64ValueOrBuilder.class b/java/kotlin-lite/target/classes/com/google/protobuf/UInt64ValueOrBuilder.class new file mode 100644 index 0000000000000..1a23c8e94ccf7 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/UInt64ValueOrBuilder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/UninitializedMessageException.class b/java/kotlin-lite/target/classes/com/google/protobuf/UninitializedMessageException.class new file mode 100644 index 0000000000000..f5f1bff9b3b79 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/UninitializedMessageException.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/UnknownFieldSchema.class b/java/kotlin-lite/target/classes/com/google/protobuf/UnknownFieldSchema.class new file mode 100644 index 0000000000000..1e6d5bf281309 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/UnknownFieldSchema.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/UnknownFieldSetLite.class b/java/kotlin-lite/target/classes/com/google/protobuf/UnknownFieldSetLite.class new file mode 100644 index 0000000000000..bfc35a9a1f23b Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/UnknownFieldSetLite.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/UnknownFieldSetLiteSchema.class b/java/kotlin-lite/target/classes/com/google/protobuf/UnknownFieldSetLiteSchema.class new file mode 100644 index 0000000000000..39cfb4cf27f38 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/UnknownFieldSetLiteSchema.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/UnmodifiableLazyStringList$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/UnmodifiableLazyStringList$1.class new file mode 100644 index 0000000000000..1121583986e0f Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/UnmodifiableLazyStringList$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/UnmodifiableLazyStringList$2.class b/java/kotlin-lite/target/classes/com/google/protobuf/UnmodifiableLazyStringList$2.class new file mode 100644 index 0000000000000..dec60746ff5de Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/UnmodifiableLazyStringList$2.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/UnmodifiableLazyStringList.class b/java/kotlin-lite/target/classes/com/google/protobuf/UnmodifiableLazyStringList.class new file mode 100644 index 0000000000000..be251bd2d2ac5 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/UnmodifiableLazyStringList.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/UnsafeUtil$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/UnsafeUtil$1.class new file mode 100644 index 0000000000000..11babcfae6d1f Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/UnsafeUtil$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/UnsafeUtil$Android32MemoryAccessor.class b/java/kotlin-lite/target/classes/com/google/protobuf/UnsafeUtil$Android32MemoryAccessor.class new file mode 100644 index 0000000000000..1dbe6daf476e9 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/UnsafeUtil$Android32MemoryAccessor.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/UnsafeUtil$Android64MemoryAccessor.class b/java/kotlin-lite/target/classes/com/google/protobuf/UnsafeUtil$Android64MemoryAccessor.class new file mode 100644 index 0000000000000..832f148b37ae1 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/UnsafeUtil$Android64MemoryAccessor.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/UnsafeUtil$JvmMemoryAccessor.class b/java/kotlin-lite/target/classes/com/google/protobuf/UnsafeUtil$JvmMemoryAccessor.class new file mode 100644 index 0000000000000..011bec8c1e317 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/UnsafeUtil$JvmMemoryAccessor.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/UnsafeUtil$MemoryAccessor.class b/java/kotlin-lite/target/classes/com/google/protobuf/UnsafeUtil$MemoryAccessor.class new file mode 100644 index 0000000000000..2ad937911496d Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/UnsafeUtil$MemoryAccessor.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/UnsafeUtil.class b/java/kotlin-lite/target/classes/com/google/protobuf/UnsafeUtil.class new file mode 100644 index 0000000000000..c9ed08b15fa75 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/UnsafeUtil.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Utf8$DecodeUtil.class b/java/kotlin-lite/target/classes/com/google/protobuf/Utf8$DecodeUtil.class new file mode 100644 index 0000000000000..652fc27cd8498 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Utf8$DecodeUtil.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Utf8$Processor.class b/java/kotlin-lite/target/classes/com/google/protobuf/Utf8$Processor.class new file mode 100644 index 0000000000000..2b4dde60af0b7 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Utf8$Processor.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Utf8$SafeProcessor.class b/java/kotlin-lite/target/classes/com/google/protobuf/Utf8$SafeProcessor.class new file mode 100644 index 0000000000000..e103d0eecd033 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Utf8$SafeProcessor.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Utf8$UnpairedSurrogateException.class b/java/kotlin-lite/target/classes/com/google/protobuf/Utf8$UnpairedSurrogateException.class new file mode 100644 index 0000000000000..85975ea9aaad0 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Utf8$UnpairedSurrogateException.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Utf8$UnsafeProcessor.class b/java/kotlin-lite/target/classes/com/google/protobuf/Utf8$UnsafeProcessor.class new file mode 100644 index 0000000000000..194eb156f1a29 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Utf8$UnsafeProcessor.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Utf8.class b/java/kotlin-lite/target/classes/com/google/protobuf/Utf8.class new file mode 100644 index 0000000000000..85afc8a21e439 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Utf8.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Value$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/Value$1.class new file mode 100644 index 0000000000000..a959a8f640c9a Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Value$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Value$Builder.class b/java/kotlin-lite/target/classes/com/google/protobuf/Value$Builder.class new file mode 100644 index 0000000000000..81d609e5c4e2f Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Value$Builder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Value$KindCase.class b/java/kotlin-lite/target/classes/com/google/protobuf/Value$KindCase.class new file mode 100644 index 0000000000000..0431e1ac4d485 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Value$KindCase.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Value.class b/java/kotlin-lite/target/classes/com/google/protobuf/Value.class new file mode 100644 index 0000000000000..c7285757f997f Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Value.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/ValueOrBuilder.class b/java/kotlin-lite/target/classes/com/google/protobuf/ValueOrBuilder.class new file mode 100644 index 0000000000000..24bdfe5ae1b1d Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/ValueOrBuilder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/WireFormat$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/WireFormat$1.class new file mode 100644 index 0000000000000..012fda3014440 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/WireFormat$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/WireFormat$FieldType$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/WireFormat$FieldType$1.class new file mode 100644 index 0000000000000..cb6bf52a6bc7b Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/WireFormat$FieldType$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/WireFormat$FieldType$2.class b/java/kotlin-lite/target/classes/com/google/protobuf/WireFormat$FieldType$2.class new file mode 100644 index 0000000000000..e01c8464ca406 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/WireFormat$FieldType$2.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/WireFormat$FieldType$3.class b/java/kotlin-lite/target/classes/com/google/protobuf/WireFormat$FieldType$3.class new file mode 100644 index 0000000000000..37ecf4a2e5c5a Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/WireFormat$FieldType$3.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/WireFormat$FieldType$4.class b/java/kotlin-lite/target/classes/com/google/protobuf/WireFormat$FieldType$4.class new file mode 100644 index 0000000000000..0b51691fc5aa1 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/WireFormat$FieldType$4.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/WireFormat$FieldType.class b/java/kotlin-lite/target/classes/com/google/protobuf/WireFormat$FieldType.class new file mode 100644 index 0000000000000..036dddf863558 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/WireFormat$FieldType.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/WireFormat$JavaType.class b/java/kotlin-lite/target/classes/com/google/protobuf/WireFormat$JavaType.class new file mode 100644 index 0000000000000..122f9a187bb49 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/WireFormat$JavaType.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/WireFormat$Utf8Validation$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/WireFormat$Utf8Validation$1.class new file mode 100644 index 0000000000000..30a65a7e0446b Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/WireFormat$Utf8Validation$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/WireFormat$Utf8Validation$2.class b/java/kotlin-lite/target/classes/com/google/protobuf/WireFormat$Utf8Validation$2.class new file mode 100644 index 0000000000000..5c91de8a6ab0e Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/WireFormat$Utf8Validation$2.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/WireFormat$Utf8Validation$3.class b/java/kotlin-lite/target/classes/com/google/protobuf/WireFormat$Utf8Validation$3.class new file mode 100644 index 0000000000000..34d9cb4126edf Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/WireFormat$Utf8Validation$3.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/WireFormat$Utf8Validation.class b/java/kotlin-lite/target/classes/com/google/protobuf/WireFormat$Utf8Validation.class new file mode 100644 index 0000000000000..89770813fc266 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/WireFormat$Utf8Validation.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/WireFormat.class b/java/kotlin-lite/target/classes/com/google/protobuf/WireFormat.class new file mode 100644 index 0000000000000..f8352eba23bd9 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/WireFormat.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/WrappersProto.class b/java/kotlin-lite/target/classes/com/google/protobuf/WrappersProto.class new file mode 100644 index 0000000000000..9ded53320bb1a Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/WrappersProto.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Writer$FieldOrder.class b/java/kotlin-lite/target/classes/com/google/protobuf/Writer$FieldOrder.class new file mode 100644 index 0000000000000..78ccae0925927 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Writer$FieldOrder.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/Writer.class b/java/kotlin-lite/target/classes/com/google/protobuf/Writer.class new file mode 100644 index 0000000000000..f0e353436044c Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/Writer.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/kotlin/DslList.class b/java/kotlin-lite/target/classes/com/google/protobuf/kotlin/DslList.class new file mode 100644 index 0000000000000..0b2690fac96ad Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/kotlin/DslList.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/kotlin/DslMap.class b/java/kotlin-lite/target/classes/com/google/protobuf/kotlin/DslMap.class new file mode 100644 index 0000000000000..fb484d0e8ccbc Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/kotlin/DslMap.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/kotlin/DslProxy.class b/java/kotlin-lite/target/classes/com/google/protobuf/kotlin/DslProxy.class new file mode 100644 index 0000000000000..4dce33a1c6f28 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/kotlin/DslProxy.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/kotlin/ExtendableMessageLiteExtensionsKt.class b/java/kotlin-lite/target/classes/com/google/protobuf/kotlin/ExtendableMessageLiteExtensionsKt.class new file mode 100644 index 0000000000000..d410852055824 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/kotlin/ExtendableMessageLiteExtensionsKt.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/kotlin/ExtensionList.class b/java/kotlin-lite/target/classes/com/google/protobuf/kotlin/ExtensionList.class new file mode 100644 index 0000000000000..f299c88a54176 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/kotlin/ExtensionList.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/kotlin/OnlyForUseByGeneratedProtoCode.class b/java/kotlin-lite/target/classes/com/google/protobuf/kotlin/OnlyForUseByGeneratedProtoCode.class new file mode 100644 index 0000000000000..a70b0fc63a13e Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/kotlin/OnlyForUseByGeneratedProtoCode.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/kotlin/ProtoDslMarker.class b/java/kotlin-lite/target/classes/com/google/protobuf/kotlin/ProtoDslMarker.class new file mode 100644 index 0000000000000..3ed7d634c1d34 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/kotlin/ProtoDslMarker.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/kotlin/UnmodifiableCollection.class b/java/kotlin-lite/target/classes/com/google/protobuf/kotlin/UnmodifiableCollection.class new file mode 100644 index 0000000000000..3391fdf42dee2 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/kotlin/UnmodifiableCollection.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/kotlin/UnmodifiableIterator.class b/java/kotlin-lite/target/classes/com/google/protobuf/kotlin/UnmodifiableIterator.class new file mode 100644 index 0000000000000..fbaa709e3139e Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/kotlin/UnmodifiableIterator.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/kotlin/UnmodifiableListIterator.class b/java/kotlin-lite/target/classes/com/google/protobuf/kotlin/UnmodifiableListIterator.class new file mode 100644 index 0000000000000..40fee0d21811a Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/kotlin/UnmodifiableListIterator.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/kotlin/UnmodifiableMapEntries$iterator$1.class b/java/kotlin-lite/target/classes/com/google/protobuf/kotlin/UnmodifiableMapEntries$iterator$1.class new file mode 100644 index 0000000000000..e2670a80b614d Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/kotlin/UnmodifiableMapEntries$iterator$1.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/kotlin/UnmodifiableMapEntries.class b/java/kotlin-lite/target/classes/com/google/protobuf/kotlin/UnmodifiableMapEntries.class new file mode 100644 index 0000000000000..e634a02859dfe Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/kotlin/UnmodifiableMapEntries.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/kotlin/UnmodifiableMapEntry.class b/java/kotlin-lite/target/classes/com/google/protobuf/kotlin/UnmodifiableMapEntry.class new file mode 100644 index 0000000000000..0103112c47442 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/kotlin/UnmodifiableMapEntry.class differ diff --git a/java/kotlin-lite/target/classes/com/google/protobuf/kotlin/UnmodifiableSet.class b/java/kotlin-lite/target/classes/com/google/protobuf/kotlin/UnmodifiableSet.class new file mode 100644 index 0000000000000..fb968437f40e1 Binary files /dev/null and b/java/kotlin-lite/target/classes/com/google/protobuf/kotlin/UnmodifiableSet.class differ diff --git a/java/kotlin-lite/target/classes/google/protobuf/any.proto b/java/kotlin-lite/target/classes/google/protobuf/any.proto new file mode 100644 index 0000000000000..6ed8a23cf5a30 --- /dev/null +++ b/java/kotlin-lite/target/classes/google/protobuf/any.proto @@ -0,0 +1,158 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package google.protobuf; + +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; +option go_package = "google.golang.org/protobuf/types/known/anypb"; +option java_package = "com.google.protobuf"; +option java_outer_classname = "AnyProto"; +option java_multiple_files = true; +option objc_class_prefix = "GPB"; + +// `Any` contains an arbitrary serialized protocol buffer message along with a +// URL that describes the type of the serialized message. +// +// Protobuf library provides support to pack/unpack Any values in the form +// of utility functions or additional generated methods of the Any type. +// +// Example 1: Pack and unpack a message in C++. +// +// Foo foo = ...; +// Any any; +// any.PackFrom(foo); +// ... +// if (any.UnpackTo(&foo)) { +// ... +// } +// +// Example 2: Pack and unpack a message in Java. +// +// Foo foo = ...; +// Any any = Any.pack(foo); +// ... +// if (any.is(Foo.class)) { +// foo = any.unpack(Foo.class); +// } +// +// Example 3: Pack and unpack a message in Python. +// +// foo = Foo(...) +// any = Any() +// any.Pack(foo) +// ... +// if any.Is(Foo.DESCRIPTOR): +// any.Unpack(foo) +// ... +// +// Example 4: Pack and unpack a message in Go +// +// foo := &pb.Foo{...} +// any, err := anypb.New(foo) +// if err != nil { +// ... +// } +// ... +// foo := &pb.Foo{} +// if err := any.UnmarshalTo(foo); err != nil { +// ... +// } +// +// The pack methods provided by protobuf library will by default use +// 'type.googleapis.com/full.type.name' as the type URL and the unpack +// methods only use the fully qualified type name after the last '/' +// in the type URL, for example "foo.bar.com/x/y.z" will yield type +// name "y.z". +// +// +// JSON +// ==== +// The JSON representation of an `Any` value uses the regular +// representation of the deserialized, embedded message, with an +// additional field `@type` which contains the type URL. Example: +// +// package google.profile; +// message Person { +// string first_name = 1; +// string last_name = 2; +// } +// +// { +// "@type": "type.googleapis.com/google.profile.Person", +// "firstName": , +// "lastName": +// } +// +// If the embedded message type is well-known and has a custom JSON +// representation, that representation will be embedded adding a field +// `value` which holds the custom JSON in addition to the `@type` +// field. Example (for message [google.protobuf.Duration][]): +// +// { +// "@type": "type.googleapis.com/google.protobuf.Duration", +// "value": "1.212s" +// } +// +message Any { + // A URL/resource name that uniquely identifies the type of the serialized + // protocol buffer message. This string must contain at least + // one "/" character. The last segment of the URL's path must represent + // the fully qualified name of the type (as in + // `path/google.protobuf.Duration`). The name should be in a canonical form + // (e.g., leading "." is not accepted). + // + // In practice, teams usually precompile into the binary all types that they + // expect it to use in the context of Any. However, for URLs which use the + // scheme `http`, `https`, or no scheme, one can optionally set up a type + // server that maps type URLs to message definitions as follows: + // + // * If no scheme is provided, `https` is assumed. + // * An HTTP GET on the URL must yield a [google.protobuf.Type][] + // value in binary format, or produce an error. + // * Applications are allowed to cache lookup results based on the + // URL, or have them precompiled into a binary to avoid any + // lookup. Therefore, binary compatibility needs to be preserved + // on changes to types. (Use versioned type names to manage + // breaking changes.) + // + // Note: this functionality is not currently available in the official + // protobuf release, and it is not used for type URLs beginning with + // type.googleapis.com. + // + // Schemes other than `http`, `https` (or the empty scheme) might be + // used with implementation specific semantics. + // + string type_url = 1; + + // Must be a valid serialized protocol buffer of the above specified type. + bytes value = 2; +} diff --git a/java/kotlin-lite/target/classes/google/protobuf/api.proto b/java/kotlin-lite/target/classes/google/protobuf/api.proto new file mode 100644 index 0000000000000..3d598fc8590e7 --- /dev/null +++ b/java/kotlin-lite/target/classes/google/protobuf/api.proto @@ -0,0 +1,208 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package google.protobuf; + +import "google/protobuf/source_context.proto"; +import "google/protobuf/type.proto"; + +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; +option java_package = "com.google.protobuf"; +option java_outer_classname = "ApiProto"; +option java_multiple_files = true; +option objc_class_prefix = "GPB"; +option go_package = "google.golang.org/protobuf/types/known/apipb"; + +// Api is a light-weight descriptor for an API Interface. +// +// Interfaces are also described as "protocol buffer services" in some contexts, +// such as by the "service" keyword in a .proto file, but they are different +// from API Services, which represent a concrete implementation of an interface +// as opposed to simply a description of methods and bindings. They are also +// sometimes simply referred to as "APIs" in other contexts, such as the name of +// this message itself. See https://cloud.google.com/apis/design/glossary for +// detailed terminology. +message Api { + // The fully qualified name of this interface, including package name + // followed by the interface's simple name. + string name = 1; + + // The methods of this interface, in unspecified order. + repeated Method methods = 2; + + // Any metadata attached to the interface. + repeated Option options = 3; + + // A version string for this interface. If specified, must have the form + // `major-version.minor-version`, as in `1.10`. If the minor version is + // omitted, it defaults to zero. If the entire version field is empty, the + // major version is derived from the package name, as outlined below. If the + // field is not empty, the version in the package name will be verified to be + // consistent with what is provided here. + // + // The versioning schema uses [semantic + // versioning](http://semver.org) where the major version number + // indicates a breaking change and the minor version an additive, + // non-breaking change. Both version numbers are signals to users + // what to expect from different versions, and should be carefully + // chosen based on the product plan. + // + // The major version is also reflected in the package name of the + // interface, which must end in `v`, as in + // `google.feature.v1`. For major versions 0 and 1, the suffix can + // be omitted. Zero major versions must only be used for + // experimental, non-GA interfaces. + // + // + string version = 4; + + // Source context for the protocol buffer service represented by this + // message. + SourceContext source_context = 5; + + // Included interfaces. See [Mixin][]. + repeated Mixin mixins = 6; + + // The source syntax of the service. + Syntax syntax = 7; +} + +// Method represents a method of an API interface. +message Method { + // The simple name of this method. + string name = 1; + + // A URL of the input message type. + string request_type_url = 2; + + // If true, the request is streamed. + bool request_streaming = 3; + + // The URL of the output message type. + string response_type_url = 4; + + // If true, the response is streamed. + bool response_streaming = 5; + + // Any metadata attached to the method. + repeated Option options = 6; + + // The source syntax of this method. + Syntax syntax = 7; +} + +// Declares an API Interface to be included in this interface. The including +// interface must redeclare all the methods from the included interface, but +// documentation and options are inherited as follows: +// +// - If after comment and whitespace stripping, the documentation +// string of the redeclared method is empty, it will be inherited +// from the original method. +// +// - Each annotation belonging to the service config (http, +// visibility) which is not set in the redeclared method will be +// inherited. +// +// - If an http annotation is inherited, the path pattern will be +// modified as follows. Any version prefix will be replaced by the +// version of the including interface plus the [root][] path if +// specified. +// +// Example of a simple mixin: +// +// package google.acl.v1; +// service AccessControl { +// // Get the underlying ACL object. +// rpc GetAcl(GetAclRequest) returns (Acl) { +// option (google.api.http).get = "/v1/{resource=**}:getAcl"; +// } +// } +// +// package google.storage.v2; +// service Storage { +// rpc GetAcl(GetAclRequest) returns (Acl); +// +// // Get a data record. +// rpc GetData(GetDataRequest) returns (Data) { +// option (google.api.http).get = "/v2/{resource=**}"; +// } +// } +// +// Example of a mixin configuration: +// +// apis: +// - name: google.storage.v2.Storage +// mixins: +// - name: google.acl.v1.AccessControl +// +// The mixin construct implies that all methods in `AccessControl` are +// also declared with same name and request/response types in +// `Storage`. A documentation generator or annotation processor will +// see the effective `Storage.GetAcl` method after inheriting +// documentation and annotations as follows: +// +// service Storage { +// // Get the underlying ACL object. +// rpc GetAcl(GetAclRequest) returns (Acl) { +// option (google.api.http).get = "/v2/{resource=**}:getAcl"; +// } +// ... +// } +// +// Note how the version in the path pattern changed from `v1` to `v2`. +// +// If the `root` field in the mixin is specified, it should be a +// relative path under which inherited HTTP paths are placed. Example: +// +// apis: +// - name: google.storage.v2.Storage +// mixins: +// - name: google.acl.v1.AccessControl +// root: acls +// +// This implies the following inherited HTTP annotation: +// +// service Storage { +// // Get the underlying ACL object. +// rpc GetAcl(GetAclRequest) returns (Acl) { +// option (google.api.http).get = "/v2/acls/{resource=**}:getAcl"; +// } +// ... +// } +message Mixin { + // The fully qualified name of the interface which is included. + string name = 1; + + // If non-empty specifies a path under which inherited HTTP paths + // are rooted. + string root = 2; +} diff --git a/java/kotlin-lite/target/classes/google/protobuf/duration.proto b/java/kotlin-lite/target/classes/google/protobuf/duration.proto new file mode 100644 index 0000000000000..81c3e369fd130 --- /dev/null +++ b/java/kotlin-lite/target/classes/google/protobuf/duration.proto @@ -0,0 +1,116 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package google.protobuf; + +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; +option cc_enable_arenas = true; +option go_package = "google.golang.org/protobuf/types/known/durationpb"; +option java_package = "com.google.protobuf"; +option java_outer_classname = "DurationProto"; +option java_multiple_files = true; +option objc_class_prefix = "GPB"; + +// A Duration represents a signed, fixed-length span of time represented +// as a count of seconds and fractions of seconds at nanosecond +// resolution. It is independent of any calendar and concepts like "day" +// or "month". It is related to Timestamp in that the difference between +// two Timestamp values is a Duration and it can be added or subtracted +// from a Timestamp. Range is approximately +-10,000 years. +// +// # Examples +// +// Example 1: Compute Duration from two Timestamps in pseudo code. +// +// Timestamp start = ...; +// Timestamp end = ...; +// Duration duration = ...; +// +// duration.seconds = end.seconds - start.seconds; +// duration.nanos = end.nanos - start.nanos; +// +// if (duration.seconds < 0 && duration.nanos > 0) { +// duration.seconds += 1; +// duration.nanos -= 1000000000; +// } else if (duration.seconds > 0 && duration.nanos < 0) { +// duration.seconds -= 1; +// duration.nanos += 1000000000; +// } +// +// Example 2: Compute Timestamp from Timestamp + Duration in pseudo code. +// +// Timestamp start = ...; +// Duration duration = ...; +// Timestamp end = ...; +// +// end.seconds = start.seconds + duration.seconds; +// end.nanos = start.nanos + duration.nanos; +// +// if (end.nanos < 0) { +// end.seconds -= 1; +// end.nanos += 1000000000; +// } else if (end.nanos >= 1000000000) { +// end.seconds += 1; +// end.nanos -= 1000000000; +// } +// +// Example 3: Compute Duration from datetime.timedelta in Python. +// +// td = datetime.timedelta(days=3, minutes=10) +// duration = Duration() +// duration.FromTimedelta(td) +// +// # JSON Mapping +// +// In JSON format, the Duration type is encoded as a string rather than an +// object, where the string ends in the suffix "s" (indicating seconds) and +// is preceded by the number of seconds, with nanoseconds expressed as +// fractional seconds. For example, 3 seconds with 0 nanoseconds should be +// encoded in JSON format as "3s", while 3 seconds and 1 nanosecond should +// be expressed in JSON format as "3.000000001s", and 3 seconds and 1 +// microsecond should be expressed in JSON format as "3.000001s". +// +// +message Duration { + // Signed seconds of the span of time. Must be from -315,576,000,000 + // to +315,576,000,000 inclusive. Note: these bounds are computed from: + // 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years + int64 seconds = 1; + + // Signed fractions of a second at nanosecond resolution of the span + // of time. Durations less than one second are represented with a 0 + // `seconds` field and a positive or negative `nanos` field. For durations + // of one second or more, a non-zero value for the `nanos` field must be + // of the same sign as the `seconds` field. Must be from -999,999,999 + // to +999,999,999 inclusive. + int32 nanos = 2; +} diff --git a/java/kotlin-lite/target/classes/google/protobuf/empty.proto b/java/kotlin-lite/target/classes/google/protobuf/empty.proto new file mode 100644 index 0000000000000..5f992de94ab46 --- /dev/null +++ b/java/kotlin-lite/target/classes/google/protobuf/empty.proto @@ -0,0 +1,52 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package google.protobuf; + +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; +option go_package = "google.golang.org/protobuf/types/known/emptypb"; +option java_package = "com.google.protobuf"; +option java_outer_classname = "EmptyProto"; +option java_multiple_files = true; +option objc_class_prefix = "GPB"; +option cc_enable_arenas = true; + +// A generic empty message that you can re-use to avoid defining duplicated +// empty messages in your APIs. A typical example is to use it as the request +// or the response type of an API method. For instance: +// +// service Foo { +// rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); +// } +// +// The JSON representation for `Empty` is empty JSON object `{}`. +message Empty {} diff --git a/java/kotlin-lite/target/classes/google/protobuf/field_mask.proto b/java/kotlin-lite/target/classes/google/protobuf/field_mask.proto new file mode 100644 index 0000000000000..6b5104f188aa7 --- /dev/null +++ b/java/kotlin-lite/target/classes/google/protobuf/field_mask.proto @@ -0,0 +1,245 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package google.protobuf; + +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; +option java_package = "com.google.protobuf"; +option java_outer_classname = "FieldMaskProto"; +option java_multiple_files = true; +option objc_class_prefix = "GPB"; +option go_package = "google.golang.org/protobuf/types/known/fieldmaskpb"; +option cc_enable_arenas = true; + +// `FieldMask` represents a set of symbolic field paths, for example: +// +// paths: "f.a" +// paths: "f.b.d" +// +// Here `f` represents a field in some root message, `a` and `b` +// fields in the message found in `f`, and `d` a field found in the +// message in `f.b`. +// +// Field masks are used to specify a subset of fields that should be +// returned by a get operation or modified by an update operation. +// Field masks also have a custom JSON encoding (see below). +// +// # Field Masks in Projections +// +// When used in the context of a projection, a response message or +// sub-message is filtered by the API to only contain those fields as +// specified in the mask. For example, if the mask in the previous +// example is applied to a response message as follows: +// +// f { +// a : 22 +// b { +// d : 1 +// x : 2 +// } +// y : 13 +// } +// z: 8 +// +// The result will not contain specific values for fields x,y and z +// (their value will be set to the default, and omitted in proto text +// output): +// +// +// f { +// a : 22 +// b { +// d : 1 +// } +// } +// +// A repeated field is not allowed except at the last position of a +// paths string. +// +// If a FieldMask object is not present in a get operation, the +// operation applies to all fields (as if a FieldMask of all fields +// had been specified). +// +// Note that a field mask does not necessarily apply to the +// top-level response message. In case of a REST get operation, the +// field mask applies directly to the response, but in case of a REST +// list operation, the mask instead applies to each individual message +// in the returned resource list. In case of a REST custom method, +// other definitions may be used. Where the mask applies will be +// clearly documented together with its declaration in the API. In +// any case, the effect on the returned resource/resources is required +// behavior for APIs. +// +// # Field Masks in Update Operations +// +// A field mask in update operations specifies which fields of the +// targeted resource are going to be updated. The API is required +// to only change the values of the fields as specified in the mask +// and leave the others untouched. If a resource is passed in to +// describe the updated values, the API ignores the values of all +// fields not covered by the mask. +// +// If a repeated field is specified for an update operation, new values will +// be appended to the existing repeated field in the target resource. Note that +// a repeated field is only allowed in the last position of a `paths` string. +// +// If a sub-message is specified in the last position of the field mask for an +// update operation, then new value will be merged into the existing sub-message +// in the target resource. +// +// For example, given the target message: +// +// f { +// b { +// d: 1 +// x: 2 +// } +// c: [1] +// } +// +// And an update message: +// +// f { +// b { +// d: 10 +// } +// c: [2] +// } +// +// then if the field mask is: +// +// paths: ["f.b", "f.c"] +// +// then the result will be: +// +// f { +// b { +// d: 10 +// x: 2 +// } +// c: [1, 2] +// } +// +// An implementation may provide options to override this default behavior for +// repeated and message fields. +// +// In order to reset a field's value to the default, the field must +// be in the mask and set to the default value in the provided resource. +// Hence, in order to reset all fields of a resource, provide a default +// instance of the resource and set all fields in the mask, or do +// not provide a mask as described below. +// +// If a field mask is not present on update, the operation applies to +// all fields (as if a field mask of all fields has been specified). +// Note that in the presence of schema evolution, this may mean that +// fields the client does not know and has therefore not filled into +// the request will be reset to their default. If this is unwanted +// behavior, a specific service may require a client to always specify +// a field mask, producing an error if not. +// +// As with get operations, the location of the resource which +// describes the updated values in the request message depends on the +// operation kind. In any case, the effect of the field mask is +// required to be honored by the API. +// +// ## Considerations for HTTP REST +// +// The HTTP kind of an update operation which uses a field mask must +// be set to PATCH instead of PUT in order to satisfy HTTP semantics +// (PUT must only be used for full updates). +// +// # JSON Encoding of Field Masks +// +// In JSON, a field mask is encoded as a single string where paths are +// separated by a comma. Fields name in each path are converted +// to/from lower-camel naming conventions. +// +// As an example, consider the following message declarations: +// +// message Profile { +// User user = 1; +// Photo photo = 2; +// } +// message User { +// string display_name = 1; +// string address = 2; +// } +// +// In proto a field mask for `Profile` may look as such: +// +// mask { +// paths: "user.display_name" +// paths: "photo" +// } +// +// In JSON, the same mask is represented as below: +// +// { +// mask: "user.displayName,photo" +// } +// +// # Field Masks and Oneof Fields +// +// Field masks treat fields in oneofs just as regular fields. Consider the +// following message: +// +// message SampleMessage { +// oneof test_oneof { +// string name = 4; +// SubMessage sub_message = 9; +// } +// } +// +// The field mask can be: +// +// mask { +// paths: "name" +// } +// +// Or: +// +// mask { +// paths: "sub_message" +// } +// +// Note that oneof type names ("test_oneof" in this case) cannot be used in +// paths. +// +// ## Field Mask Verification +// +// The implementation of any API method which has a FieldMask type field in the +// request should verify the included field paths, and return an +// `INVALID_ARGUMENT` error if any path is unmappable. +message FieldMask { + // The set of field mask paths. + repeated string paths = 1; +} diff --git a/java/kotlin-lite/target/classes/google/protobuf/source_context.proto b/java/kotlin-lite/target/classes/google/protobuf/source_context.proto new file mode 100644 index 0000000000000..06bfc43a78ec8 --- /dev/null +++ b/java/kotlin-lite/target/classes/google/protobuf/source_context.proto @@ -0,0 +1,48 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package google.protobuf; + +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; +option java_package = "com.google.protobuf"; +option java_outer_classname = "SourceContextProto"; +option java_multiple_files = true; +option objc_class_prefix = "GPB"; +option go_package = "google.golang.org/protobuf/types/known/sourcecontextpb"; + +// `SourceContext` represents information about the source of a +// protobuf element, like the file in which it is defined. +message SourceContext { + // The path-qualified name of the .proto file that contained the associated + // protobuf element. For example: `"google/protobuf/source_context.proto"`. + string file_name = 1; +} diff --git a/java/kotlin-lite/target/classes/google/protobuf/struct.proto b/java/kotlin-lite/target/classes/google/protobuf/struct.proto new file mode 100644 index 0000000000000..545215c25276c --- /dev/null +++ b/java/kotlin-lite/target/classes/google/protobuf/struct.proto @@ -0,0 +1,95 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package google.protobuf; + +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; +option cc_enable_arenas = true; +option go_package = "google.golang.org/protobuf/types/known/structpb"; +option java_package = "com.google.protobuf"; +option java_outer_classname = "StructProto"; +option java_multiple_files = true; +option objc_class_prefix = "GPB"; + +// `Struct` represents a structured data value, consisting of fields +// which map to dynamically typed values. In some languages, `Struct` +// might be supported by a native representation. For example, in +// scripting languages like JS a struct is represented as an +// object. The details of that representation are described together +// with the proto support for the language. +// +// The JSON representation for `Struct` is JSON object. +message Struct { + // Unordered map of dynamically typed values. + map fields = 1; +} + +// `Value` represents a dynamically typed value which can be either +// null, a number, a string, a boolean, a recursive struct value, or a +// list of values. A producer of value is expected to set one of that +// variants, absence of any variant indicates an error. +// +// The JSON representation for `Value` is JSON value. +message Value { + // The kind of value. + oneof kind { + // Represents a null value. + NullValue null_value = 1; + // Represents a double value. + double number_value = 2; + // Represents a string value. + string string_value = 3; + // Represents a boolean value. + bool bool_value = 4; + // Represents a structured value. + Struct struct_value = 5; + // Represents a repeated `Value`. + ListValue list_value = 6; + } +} + +// `NullValue` is a singleton enumeration to represent the null value for the +// `Value` type union. +// +// The JSON representation for `NullValue` is JSON `null`. +enum NullValue { + // Null value. + NULL_VALUE = 0; +} + +// `ListValue` is a wrapper around a repeated field of values. +// +// The JSON representation for `ListValue` is JSON array. +message ListValue { + // Repeated field of dynamically typed values. + repeated Value values = 1; +} diff --git a/java/kotlin-lite/target/classes/google/protobuf/timestamp.proto b/java/kotlin-lite/target/classes/google/protobuf/timestamp.proto new file mode 100644 index 0000000000000..3b2df6d91168e --- /dev/null +++ b/java/kotlin-lite/target/classes/google/protobuf/timestamp.proto @@ -0,0 +1,147 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package google.protobuf; + +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; +option cc_enable_arenas = true; +option go_package = "google.golang.org/protobuf/types/known/timestamppb"; +option java_package = "com.google.protobuf"; +option java_outer_classname = "TimestampProto"; +option java_multiple_files = true; +option objc_class_prefix = "GPB"; + +// A Timestamp represents a point in time independent of any time zone or local +// calendar, encoded as a count of seconds and fractions of seconds at +// nanosecond resolution. The count is relative to an epoch at UTC midnight on +// January 1, 1970, in the proleptic Gregorian calendar which extends the +// Gregorian calendar backwards to year one. +// +// All minutes are 60 seconds long. Leap seconds are "smeared" so that no leap +// second table is needed for interpretation, using a [24-hour linear +// smear](https://developers.google.com/time/smear). +// +// The range is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. By +// restricting to that range, we ensure that we can convert to and from [RFC +// 3339](https://www.ietf.org/rfc/rfc3339.txt) date strings. +// +// # Examples +// +// Example 1: Compute Timestamp from POSIX `time()`. +// +// Timestamp timestamp; +// timestamp.set_seconds(time(NULL)); +// timestamp.set_nanos(0); +// +// Example 2: Compute Timestamp from POSIX `gettimeofday()`. +// +// struct timeval tv; +// gettimeofday(&tv, NULL); +// +// Timestamp timestamp; +// timestamp.set_seconds(tv.tv_sec); +// timestamp.set_nanos(tv.tv_usec * 1000); +// +// Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`. +// +// FILETIME ft; +// GetSystemTimeAsFileTime(&ft); +// UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime; +// +// // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z +// // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z. +// Timestamp timestamp; +// timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL)); +// timestamp.set_nanos((INT32) ((ticks % 10000000) * 100)); +// +// Example 4: Compute Timestamp from Java `System.currentTimeMillis()`. +// +// long millis = System.currentTimeMillis(); +// +// Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000) +// .setNanos((int) ((millis % 1000) * 1000000)).build(); +// +// +// Example 5: Compute Timestamp from Java `Instant.now()`. +// +// Instant now = Instant.now(); +// +// Timestamp timestamp = +// Timestamp.newBuilder().setSeconds(now.getEpochSecond()) +// .setNanos(now.getNano()).build(); +// +// +// Example 6: Compute Timestamp from current time in Python. +// +// timestamp = Timestamp() +// timestamp.GetCurrentTime() +// +// # JSON Mapping +// +// In JSON format, the Timestamp type is encoded as a string in the +// [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the +// format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z" +// where {year} is always expressed using four digits while {month}, {day}, +// {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional +// seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution), +// are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone +// is required. A proto3 JSON serializer should always use UTC (as indicated by +// "Z") when printing the Timestamp type and a proto3 JSON parser should be +// able to accept both UTC and other timezones (as indicated by an offset). +// +// For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past +// 01:30 UTC on January 15, 2017. +// +// In JavaScript, one can convert a Date object to this format using the +// standard +// [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString) +// method. In Python, a standard `datetime.datetime` object can be converted +// to this format using +// [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) with +// the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one can use +// the Joda Time's [`ISODateTimeFormat.dateTime()`]( +// http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime%2D%2D +// ) to obtain a formatter capable of generating timestamps in this format. +// +// +message Timestamp { + // Represents seconds of UTC time since Unix epoch + // 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to + // 9999-12-31T23:59:59Z inclusive. + int64 seconds = 1; + + // Non-negative fractions of a second at nanosecond resolution. Negative + // second values with fractions must still have non-negative nanos values + // that count forward in time. Must be from 0 to 999,999,999 + // inclusive. + int32 nanos = 2; +} diff --git a/java/kotlin-lite/target/classes/google/protobuf/type.proto b/java/kotlin-lite/target/classes/google/protobuf/type.proto new file mode 100644 index 0000000000000..d3f6a68b83981 --- /dev/null +++ b/java/kotlin-lite/target/classes/google/protobuf/type.proto @@ -0,0 +1,187 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package google.protobuf; + +import "google/protobuf/any.proto"; +import "google/protobuf/source_context.proto"; + +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; +option cc_enable_arenas = true; +option java_package = "com.google.protobuf"; +option java_outer_classname = "TypeProto"; +option java_multiple_files = true; +option objc_class_prefix = "GPB"; +option go_package = "google.golang.org/protobuf/types/known/typepb"; + +// A protocol buffer message type. +message Type { + // The fully qualified message name. + string name = 1; + // The list of fields. + repeated Field fields = 2; + // The list of types appearing in `oneof` definitions in this type. + repeated string oneofs = 3; + // The protocol buffer options. + repeated Option options = 4; + // The source context. + SourceContext source_context = 5; + // The source syntax. + Syntax syntax = 6; +} + +// A single field of a message type. +message Field { + // Basic field types. + enum Kind { + // Field type unknown. + TYPE_UNKNOWN = 0; + // Field type double. + TYPE_DOUBLE = 1; + // Field type float. + TYPE_FLOAT = 2; + // Field type int64. + TYPE_INT64 = 3; + // Field type uint64. + TYPE_UINT64 = 4; + // Field type int32. + TYPE_INT32 = 5; + // Field type fixed64. + TYPE_FIXED64 = 6; + // Field type fixed32. + TYPE_FIXED32 = 7; + // Field type bool. + TYPE_BOOL = 8; + // Field type string. + TYPE_STRING = 9; + // Field type group. Proto2 syntax only, and deprecated. + TYPE_GROUP = 10; + // Field type message. + TYPE_MESSAGE = 11; + // Field type bytes. + TYPE_BYTES = 12; + // Field type uint32. + TYPE_UINT32 = 13; + // Field type enum. + TYPE_ENUM = 14; + // Field type sfixed32. + TYPE_SFIXED32 = 15; + // Field type sfixed64. + TYPE_SFIXED64 = 16; + // Field type sint32. + TYPE_SINT32 = 17; + // Field type sint64. + TYPE_SINT64 = 18; + } + + // Whether a field is optional, required, or repeated. + enum Cardinality { + // For fields with unknown cardinality. + CARDINALITY_UNKNOWN = 0; + // For optional fields. + CARDINALITY_OPTIONAL = 1; + // For required fields. Proto2 syntax only. + CARDINALITY_REQUIRED = 2; + // For repeated fields. + CARDINALITY_REPEATED = 3; + } + + // The field type. + Kind kind = 1; + // The field cardinality. + Cardinality cardinality = 2; + // The field number. + int32 number = 3; + // The field name. + string name = 4; + // The field type URL, without the scheme, for message or enumeration + // types. Example: `"type.googleapis.com/google.protobuf.Timestamp"`. + string type_url = 6; + // The index of the field type in `Type.oneofs`, for message or enumeration + // types. The first type has index 1; zero means the type is not in the list. + int32 oneof_index = 7; + // Whether to use alternative packed wire representation. + bool packed = 8; + // The protocol buffer options. + repeated Option options = 9; + // The field JSON name. + string json_name = 10; + // The string value of the default value of this field. Proto2 syntax only. + string default_value = 11; +} + +// Enum type definition. +message Enum { + // Enum type name. + string name = 1; + // Enum value definitions. + repeated EnumValue enumvalue = 2; + // Protocol buffer options. + repeated Option options = 3; + // The source context. + SourceContext source_context = 4; + // The source syntax. + Syntax syntax = 5; +} + +// Enum value definition. +message EnumValue { + // Enum value name. + string name = 1; + // Enum value number. + int32 number = 2; + // Protocol buffer options. + repeated Option options = 3; +} + +// A protocol buffer option, which can be attached to a message, field, +// enumeration, etc. +message Option { + // The option's name. For protobuf built-in options (options defined in + // descriptor.proto), this is the short name. For example, `"map_entry"`. + // For custom options, it should be the fully-qualified name. For example, + // `"google.api.http"`. + string name = 1; + // The option's value packed in an Any message. If the value is a primitive, + // the corresponding wrapper type defined in google/protobuf/wrappers.proto + // should be used. If the value is an enum, it should be stored as an int32 + // value using the google.protobuf.Int32Value type. + Any value = 2; +} + +// The syntax in which a protocol buffer element is defined. +enum Syntax { + // Syntax `proto2`. + SYNTAX_PROTO2 = 0; + // Syntax `proto3`. + SYNTAX_PROTO3 = 1; +} diff --git a/java/kotlin-lite/target/classes/google/protobuf/wrappers.proto b/java/kotlin-lite/target/classes/google/protobuf/wrappers.proto new file mode 100644 index 0000000000000..d49dd53c8d8f3 --- /dev/null +++ b/java/kotlin-lite/target/classes/google/protobuf/wrappers.proto @@ -0,0 +1,123 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Wrappers for primitive (non-message) types. These types are useful +// for embedding primitives in the `google.protobuf.Any` type and for places +// where we need to distinguish between the absence of a primitive +// typed field and its default value. +// +// These wrappers have no meaningful use within repeated fields as they lack +// the ability to detect presence on individual elements. +// These wrappers have no meaningful use within a map or a oneof since +// individual entries of a map or fields of a oneof can already detect presence. + +syntax = "proto3"; + +package google.protobuf; + +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; +option cc_enable_arenas = true; +option go_package = "google.golang.org/protobuf/types/known/wrapperspb"; +option java_package = "com.google.protobuf"; +option java_outer_classname = "WrappersProto"; +option java_multiple_files = true; +option objc_class_prefix = "GPB"; + +// Wrapper message for `double`. +// +// The JSON representation for `DoubleValue` is JSON number. +message DoubleValue { + // The double value. + double value = 1; +} + +// Wrapper message for `float`. +// +// The JSON representation for `FloatValue` is JSON number. +message FloatValue { + // The float value. + float value = 1; +} + +// Wrapper message for `int64`. +// +// The JSON representation for `Int64Value` is JSON string. +message Int64Value { + // The int64 value. + int64 value = 1; +} + +// Wrapper message for `uint64`. +// +// The JSON representation for `UInt64Value` is JSON string. +message UInt64Value { + // The uint64 value. + uint64 value = 1; +} + +// Wrapper message for `int32`. +// +// The JSON representation for `Int32Value` is JSON number. +message Int32Value { + // The int32 value. + int32 value = 1; +} + +// Wrapper message for `uint32`. +// +// The JSON representation for `UInt32Value` is JSON number. +message UInt32Value { + // The uint32 value. + uint32 value = 1; +} + +// Wrapper message for `bool`. +// +// The JSON representation for `BoolValue` is JSON `true` and `false`. +message BoolValue { + // The bool value. + bool value = 1; +} + +// Wrapper message for `string`. +// +// The JSON representation for `StringValue` is JSON string. +message StringValue { + // The string value. + string value = 1; +} + +// Wrapper message for `bytes`. +// +// The JSON representation for `BytesValue` is JSON string. +message BytesValue { + // The bytes value. + bytes value = 1; +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/AbstractMessageLite.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/AbstractMessageLite.java new file mode 100644 index 0000000000000..4e3cf427184a1 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/AbstractMessageLite.java @@ -0,0 +1,439 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +import static com.google.protobuf.Internal.checkNotNull; + +import java.io.FilterInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +/** + * A partial implementation of the {@link MessageLite} 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 AbstractMessageLite< + MessageType extends AbstractMessageLite, + BuilderType extends AbstractMessageLite.Builder> + implements MessageLite { + 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.computeRawVarint32Size(serialized) + serialized); + final CodedOutputStream codedOutput = CodedOutputStream.newInstance(output, bufferSize); + codedOutput.writeRawVarint32(serialized); + writeTo(codedOutput); + codedOutput.flush(); + } + + // We'd like these to be abstract but some folks are extending this class directly. They shouldn't + // be doing that and they should feel bad. + int getMemoizedSerializedSize() { + throw new UnsupportedOperationException(); + } + + void setMemoizedSerializedSize(int size) { + throw new UnsupportedOperationException(); + } + + + int getSerializedSize(Schema schema) { + int memoizedSerializedSize = getMemoizedSerializedSize(); + if (memoizedSerializedSize == -1) { + memoizedSerializedSize = schema.getSerializedSize(this); + setMemoizedSerializedSize(memoizedSerializedSize); + } + return memoizedSerializedSize; + } + + /** Package private helper method for AbstractParser to create UninitializedMessageException. */ + UninitializedMessageException newUninitializedMessageException() { + return new UninitializedMessageException(this); + } + + 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."); + } + } + + // For binary compatibility + @Deprecated + protected static void addAll(final Iterable values, final Collection list) { + Builder.addAll(values, (List) list); + } + + protected static void addAll(final Iterable values, final List list) { + Builder.addAll(values, list); + } + + /** 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(); + } + + /** + * 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< + MessageType extends AbstractMessageLite, + BuilderType extends Builder> + implements MessageLite.Builder { + // The compiler produces an error if this is not declared explicitly. + @Override + public abstract BuilderType clone(); + + @Override + public BuilderType mergeFrom(final CodedInputStream input) throws IOException { + return mergeFrom(input, ExtensionRegistryLite.getEmptyRegistry()); + } + + // Re-defined here for return type covariance. + @Override + public abstract BuilderType mergeFrom( + final CodedInputStream input, final ExtensionRegistryLite extensionRegistry) + throws IOException; + + @Override + 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); + } + } + + @Override + 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); + } + } + + @Override + public BuilderType mergeFrom(final byte[] data) throws InvalidProtocolBufferException { + return mergeFrom(data, 0, data.length); + } + + @Override + 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); + } + } + + @Override + public BuilderType mergeFrom(final byte[] data, final ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + return mergeFrom(data, 0, data.length, extensionRegistry); + } + + @Override + 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); + } + } + + @Override + public BuilderType mergeFrom(final InputStream input) throws IOException { + final CodedInputStream codedInput = CodedInputStream.newInstance(input); + mergeFrom(codedInput); + codedInput.checkLastTagWas(0); + return (BuilderType) this; + } + + @Override + 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; + } + + /** + * 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 { + final long result = super.skip(Math.min(n, limit)); + if (result >= 0) { + 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 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((MessageType) other); + } + + protected abstract BuilderType internalMergeFrom(MessageType message); + + 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(dweis): 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); + } + } + } + } +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/AbstractParser.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/AbstractParser.java new file mode 100644 index 0000000000000..abfaca8cd8b1f --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/AbstractParser.java @@ -0,0 +1,274 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +import com.google.protobuf.AbstractMessageLite.Builder.LimitedInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.ByteBuffer; + +/** + * A partial implementation of the {@link Parser} interface which implements as many methods of that + * interface as possible in terms of other methods. + * + *

Note: This class implements all the convenience methods in the {@link Parser} interface. See + * {@link Parser} for related javadocs. Subclasses need to implement {@link + * Parser#parsePartialFrom(CodedInputStream, ExtensionRegistryLite)} + * + * @author liujisi@google.com (Pherl Liu) + */ +public abstract class AbstractParser + implements Parser { + /** Creates an UninitializedMessageException for MessageType. */ + private UninitializedMessageException newUninitializedMessageException(MessageType message) { + if (message instanceof AbstractMessageLite) { + return ((AbstractMessageLite) message).newUninitializedMessageException(); + } + return new UninitializedMessageException(message); + } + + /** + * Helper method to check if message is initialized. + * + * @throws InvalidProtocolBufferException if it is not initialized. + * @return The message to check. + */ + private MessageType checkMessageInitialized(MessageType message) + throws InvalidProtocolBufferException { + if (message != null && !message.isInitialized()) { + throw newUninitializedMessageException(message) + .asInvalidProtocolBufferException() + .setUnfinishedMessage(message); + } + return message; + } + + private static final ExtensionRegistryLite EMPTY_REGISTRY = + ExtensionRegistryLite.getEmptyRegistry(); + + @Override + public MessageType parsePartialFrom(CodedInputStream input) + throws InvalidProtocolBufferException { + return parsePartialFrom(input, EMPTY_REGISTRY); + } + + @Override + public MessageType parseFrom(CodedInputStream input, ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + return checkMessageInitialized(parsePartialFrom(input, extensionRegistry)); + } + + @Override + public MessageType parseFrom(CodedInputStream input) throws InvalidProtocolBufferException { + return parseFrom(input, EMPTY_REGISTRY); + } + + @Override + public MessageType parsePartialFrom(ByteString data, ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + MessageType message; + try { + CodedInputStream input = data.newCodedInput(); + message = parsePartialFrom(input, extensionRegistry); + try { + input.checkLastTagWas(0); + } catch (InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(message); + } + return message; + } catch (InvalidProtocolBufferException e) { + throw e; + } + } + + @Override + public MessageType parsePartialFrom(ByteString data) throws InvalidProtocolBufferException { + return parsePartialFrom(data, EMPTY_REGISTRY); + } + + @Override + public MessageType parseFrom(ByteString data, ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + return checkMessageInitialized(parsePartialFrom(data, extensionRegistry)); + } + + @Override + public MessageType parseFrom(ByteString data) throws InvalidProtocolBufferException { + return parseFrom(data, EMPTY_REGISTRY); + } + + @Override + public MessageType parseFrom(ByteBuffer data, ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + MessageType message; + try { + CodedInputStream input = CodedInputStream.newInstance(data); + message = parsePartialFrom(input, extensionRegistry); + try { + input.checkLastTagWas(0); + } catch (InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(message); + } + } catch (InvalidProtocolBufferException e) { + throw e; + } + + return checkMessageInitialized(message); + } + + @Override + public MessageType parseFrom(ByteBuffer data) throws InvalidProtocolBufferException { + return parseFrom(data, EMPTY_REGISTRY); + } + + @Override + public MessageType parsePartialFrom( + byte[] data, int off, int len, ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + try { + CodedInputStream input = CodedInputStream.newInstance(data, off, len); + MessageType message = parsePartialFrom(input, extensionRegistry); + try { + input.checkLastTagWas(0); + } catch (InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(message); + } + return message; + } catch (InvalidProtocolBufferException e) { + throw e; + } + } + + @Override + public MessageType parsePartialFrom(byte[] data, int off, int len) + throws InvalidProtocolBufferException { + return parsePartialFrom(data, off, len, EMPTY_REGISTRY); + } + + @Override + public MessageType parsePartialFrom(byte[] data, ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + return parsePartialFrom(data, 0, data.length, extensionRegistry); + } + + @Override + public MessageType parsePartialFrom(byte[] data) throws InvalidProtocolBufferException { + return parsePartialFrom(data, 0, data.length, EMPTY_REGISTRY); + } + + @Override + public MessageType parseFrom( + byte[] data, int off, int len, ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + return checkMessageInitialized(parsePartialFrom(data, off, len, extensionRegistry)); + } + + @Override + public MessageType parseFrom(byte[] data, int off, int len) + throws InvalidProtocolBufferException { + return parseFrom(data, off, len, EMPTY_REGISTRY); + } + + @Override + public MessageType parseFrom(byte[] data, ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + return parseFrom(data, 0, data.length, extensionRegistry); + } + + @Override + public MessageType parseFrom(byte[] data) throws InvalidProtocolBufferException { + return parseFrom(data, EMPTY_REGISTRY); + } + + @Override + public MessageType parsePartialFrom(InputStream input, ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + CodedInputStream codedInput = CodedInputStream.newInstance(input); + MessageType message = parsePartialFrom(codedInput, extensionRegistry); + try { + codedInput.checkLastTagWas(0); + } catch (InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(message); + } + return message; + } + + @Override + public MessageType parsePartialFrom(InputStream input) throws InvalidProtocolBufferException { + return parsePartialFrom(input, EMPTY_REGISTRY); + } + + @Override + public MessageType parseFrom(InputStream input, ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + return checkMessageInitialized(parsePartialFrom(input, extensionRegistry)); + } + + @Override + public MessageType parseFrom(InputStream input) throws InvalidProtocolBufferException { + return parseFrom(input, EMPTY_REGISTRY); + } + + @Override + public MessageType parsePartialDelimitedFrom( + InputStream input, ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + int size; + try { + int firstByte = input.read(); + if (firstByte == -1) { + return null; + } + size = CodedInputStream.readRawVarint32(firstByte, input); + } catch (IOException e) { + throw new InvalidProtocolBufferException(e); + } + InputStream limitedInput = new LimitedInputStream(input, size); + return parsePartialFrom(limitedInput, extensionRegistry); + } + + @Override + public MessageType parsePartialDelimitedFrom(InputStream input) + throws InvalidProtocolBufferException { + return parsePartialDelimitedFrom(input, EMPTY_REGISTRY); + } + + @Override + public MessageType parseDelimitedFrom(InputStream input, ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + return checkMessageInitialized(parsePartialDelimitedFrom(input, extensionRegistry)); + } + + @Override + public MessageType parseDelimitedFrom(InputStream input) throws InvalidProtocolBufferException { + return parseDelimitedFrom(input, EMPTY_REGISTRY); + } +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/AbstractProtobufList.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/AbstractProtobufList.java new file mode 100644 index 0000000000000..e792d7d981198 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/AbstractProtobufList.java @@ -0,0 +1,180 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +import com.google.protobuf.Internal.ProtobufList; +import java.util.AbstractList; +import java.util.Collection; +import java.util.List; +import java.util.RandomAccess; + +/** + * An abstract implementation of {@link ProtobufList} which manages mutability semantics. All mutate + * methods must check if the list is mutable before proceeding. Subclasses must invoke {@link + * #ensureIsMutable()} manually when overriding those methods. + * + *

This implementation assumes all subclasses are array based, supporting random access. + */ +abstract class AbstractProtobufList extends AbstractList implements ProtobufList { + + protected static final int DEFAULT_CAPACITY = 10; + + /** Whether or not this list is modifiable. */ + private boolean isMutable; + + /** Constructs a mutable list by default. */ + AbstractProtobufList() { + isMutable = true; + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (!(o instanceof List)) { + return false; + } + // Handle lists that do not support RandomAccess as efficiently as possible by using an iterator + // based approach in our super class. Otherwise our index based approach will avoid those + // allocations. + if (!(o instanceof RandomAccess)) { + return super.equals(o); + } + + List other = (List) o; + final int size = size(); + if (size != other.size()) { + return false; + } + for (int i = 0; i < size; i++) { + if (!get(i).equals(other.get(i))) { + return false; + } + } + return true; + } + + @Override + public int hashCode() { + final int size = size(); + int hashCode = 1; + for (int i = 0; i < size; i++) { + hashCode = (31 * hashCode) + get(i).hashCode(); + } + return hashCode; + } + + @Override + public boolean add(E e) { + ensureIsMutable(); + return super.add(e); + } + + @Override + public void add(int index, E element) { + ensureIsMutable(); + super.add(index, element); + } + + @Override + public boolean addAll(Collection c) { + ensureIsMutable(); + return super.addAll(c); + } + + @Override + public boolean addAll(int index, Collection c) { + ensureIsMutable(); + return super.addAll(index, c); + } + + @Override + public void clear() { + ensureIsMutable(); + super.clear(); + } + + @Override + public boolean isModifiable() { + return isMutable; + } + + @Override + public final void makeImmutable() { + isMutable = false; + } + + @Override + public E remove(int index) { + ensureIsMutable(); + return super.remove(index); + } + + @Override + public boolean remove(Object o) { + ensureIsMutable(); + int index = indexOf(o); + if (index == -1) { + return false; + } + remove(index); + return true; + } + + @Override + public boolean removeAll(Collection c) { + ensureIsMutable(); + return super.removeAll(c); + } + + @Override + public boolean retainAll(Collection c) { + ensureIsMutable(); + return super.retainAll(c); + } + + @Override + public E set(int index, E element) { + ensureIsMutable(); + return super.set(index, element); + } + + /** + * Throws an {@link UnsupportedOperationException} if the list is immutable. Subclasses are + * responsible for invoking this method on mutate operations. + */ + protected void ensureIsMutable() { + if (!isMutable) { + throw new UnsupportedOperationException(); + } + } +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/AllocatedBuffer.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/AllocatedBuffer.java new file mode 100644 index 0000000000000..a01a6c1a8b75f --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/AllocatedBuffer.java @@ -0,0 +1,263 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +import static com.google.protobuf.Internal.checkNotNull; + +import java.nio.ByteBuffer; + +/** + * A buffer that was allocated by a {@link BufferAllocator}. For every buffer, it is guaranteed that + * at least one of {@link #hasArray()} or {@link #hasNioBuffer()} will be {@code true}. + */ +@ExperimentalApi +abstract class AllocatedBuffer { + /** + * Indicates whether this buffer contains a backing {@link ByteBuffer} (i.e. it is safe to call + * {@link #nioBuffer()}). + */ + public abstract boolean hasNioBuffer(); + + /** + * Indicates whether this buffer contains a backing array (i.e. it is safe to call {@link + * #array()}). + */ + public abstract boolean hasArray(); + + /** + * Returns the {@link ByteBuffer} that backs this buffer (optional operation). + * + *

Call {@link #hasNioBuffer()} before invoking this method in order to ensure that this buffer + * has a backing {@link ByteBuffer}. + * + * @return The {@link ByteBuffer} that backs this buffer + * @throws UnsupportedOperationException If this buffer is not backed by a {@link ByteBuffer}. + */ + public abstract ByteBuffer nioBuffer(); + + /** + * Returns the byte array that backs this buffer (optional operation). + * + *

Call {@link #hasArray()} before invoking this method in order to ensure that this buffer has + * an accessible backing array. + * + * @return The array that backs this buffer + * @throws java.nio.ReadOnlyBufferException If this buffer is backed by an array but is read-only + * @throws UnsupportedOperationException If this buffer is not backed by an accessible array + */ + public abstract byte[] array(); + + /** + * Returns the offset within this buffer's backing array of the first element of the buffer + * (optional operation). + * + *

If this buffer is backed by an array then {@link #position()} corresponds to the array index + * {@link #position()} {@code +} {@link #arrayOffset()}. + * + *

Invoke the {@link #hasArray hasArray} method before invoking this method in order to ensure + * that this buffer has an accessible backing array. + * + * @return The offset within this buffer's array of the first element of the buffer + * @throws java.nio.ReadOnlyBufferException If this buffer is backed by an array but is read-only + * @throws UnsupportedOperationException If this buffer is not backed by an accessible array + */ + public abstract int arrayOffset(); + + /** + * Returns this buffer's position. + * + * @return The position of this buffer + */ + public abstract int position(); + + /** + * Sets this buffer's position. + * + * @param position The new position value; must be non-negative and no larger than the current + * limit + * @return This buffer + * @throws IllegalArgumentException If the preconditions on {@code position} do not hold + */ + public abstract AllocatedBuffer position(int position); + + /** + * Returns this buffer's limit. + * + * @return The limit of this buffer + */ + public abstract int limit(); + + /** + * Returns the number of elements between the current {@link #position()} and the {@link #limit()} + * . + * + * @return The number of elements remaining in this buffer + */ + public abstract int remaining(); + + /** + * Creates a new {@link AllocatedBuffer} that is backed by the given array. The returned buffer + * will have {@link #hasArray} == {@code true}, {@link #arrayOffset()} == {@code 0}, {@link + * #position()} == {@code 0} and {@link #limit()} equal to the length of {@code bytes}. + */ + public static AllocatedBuffer wrap(byte[] bytes) { + return wrapNoCheck(bytes, 0, bytes.length); + } + + /** + * Creates a new {@link AllocatedBuffer} that is backed by the given array. The returned buffer + * will have {@link #hasArray} == {@code true}, {@link #arrayOffset()} == {@code offset}, {@link + * #position()} == {@code 0} and {@link #limit()} == {@code length}. + */ + public static AllocatedBuffer wrap(final byte[] bytes, final int offset, final int length) { + if (offset < 0 || length < 0 || (offset + length) > bytes.length) { + throw new IndexOutOfBoundsException( + String.format("bytes.length=%d, offset=%d, length=%d", bytes.length, offset, length)); + } + + return wrapNoCheck(bytes, offset, length); + } + + /** + * Creates a new {@link AllocatedBuffer} that is backed by the given {@link ByteBuffer}. The + * returned buffer will have {@link #hasNioBuffer} == {@code true}. + */ + public static AllocatedBuffer wrap(final ByteBuffer buffer) { + checkNotNull(buffer, "buffer"); + + return new AllocatedBuffer() { + + @Override + public boolean hasNioBuffer() { + return true; + } + + @Override + public ByteBuffer nioBuffer() { + return buffer; + } + + @Override + public boolean hasArray() { + return buffer.hasArray(); + } + + @Override + public byte[] array() { + return buffer.array(); + } + + @Override + public int arrayOffset() { + return buffer.arrayOffset(); + } + + @Override + public int position() { + return buffer.position(); + } + + @Override + public AllocatedBuffer position(int position) { + buffer.position(position); + return this; + } + + @Override + public int limit() { + return buffer.limit(); + } + + @Override + public int remaining() { + return buffer.remaining(); + } + }; + } + + private static AllocatedBuffer wrapNoCheck( + final byte[] bytes, final int offset, final int length) { + return new AllocatedBuffer() { + // Relative to offset. + private int position; + + @Override + public boolean hasNioBuffer() { + return false; + } + + @Override + public ByteBuffer nioBuffer() { + throw new UnsupportedOperationException(); + } + + @Override + public boolean hasArray() { + return true; + } + + @Override + public byte[] array() { + return bytes; + } + + @Override + public int arrayOffset() { + return offset; + } + + @Override + public int position() { + return position; + } + + @Override + public AllocatedBuffer position(int position) { + if (position < 0 || position > length) { + throw new IllegalArgumentException("Invalid position: " + position); + } + this.position = position; + return this; + } + + @Override + public int limit() { + // Relative to offset. + return length; + } + + @Override + public int remaining() { + return length - position; + } + }; + } +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/Android.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/Android.java new file mode 100644 index 0000000000000..5a7ce9e581acc --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/Android.java @@ -0,0 +1,64 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +final class Android { + private Android() { + } + + // Set to true in lite_proguard_android.pgcfg. + @SuppressWarnings("ConstantField") + private static boolean ASSUME_ANDROID; + + private static final Class MEMORY_CLASS = getClassForName("libcore.io.Memory"); + + private static final boolean IS_ROBOLECTRIC = + !ASSUME_ANDROID && getClassForName("org.robolectric.Robolectric") != null; + + /** Returns {@code true} if running on an Android device. */ + static boolean isOnAndroidDevice() { + return ASSUME_ANDROID || (MEMORY_CLASS != null && !IS_ROBOLECTRIC); + } + + /** Returns the memory class or {@code null} if not on Android device. */ + static Class getMemoryClass() { + return MEMORY_CLASS; + } + + @SuppressWarnings("unchecked") + private static Class getClassForName(String name) { + try { + return (Class) Class.forName(name); + } catch (Throwable e) { + return null; + } + } +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/Any.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/Any.java new file mode 100644 index 0000000000000..70ab047b4ff0d --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/Any.java @@ -0,0 +1,761 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/any.proto + +package com.google.protobuf; + +/** + *

+ * `Any` contains an arbitrary serialized protocol buffer message along with a
+ * URL that describes the type of the serialized message.
+ * Protobuf library provides support to pack/unpack Any values in the form
+ * of utility functions or additional generated methods of the Any type.
+ * Example 1: Pack and unpack a message in C++.
+ *     Foo foo = ...;
+ *     Any any;
+ *     any.PackFrom(foo);
+ *     ...
+ *     if (any.UnpackTo(&foo)) {
+ *       ...
+ *     }
+ * Example 2: Pack and unpack a message in Java.
+ *     Foo foo = ...;
+ *     Any any = Any.pack(foo);
+ *     ...
+ *     if (any.is(Foo.class)) {
+ *       foo = any.unpack(Foo.class);
+ *     }
+ *  Example 3: Pack and unpack a message in Python.
+ *     foo = Foo(...)
+ *     any = Any()
+ *     any.Pack(foo)
+ *     ...
+ *     if any.Is(Foo.DESCRIPTOR):
+ *       any.Unpack(foo)
+ *       ...
+ *  Example 4: Pack and unpack a message in Go
+ *      foo := &pb.Foo{...}
+ *      any, err := anypb.New(foo)
+ *      if err != nil {
+ *        ...
+ *      }
+ *      ...
+ *      foo := &pb.Foo{}
+ *      if err := any.UnmarshalTo(foo); err != nil {
+ *        ...
+ *      }
+ * The pack methods provided by protobuf library will by default use
+ * 'type.googleapis.com/full.type.name' as the type URL and the unpack
+ * methods only use the fully qualified type name after the last '/'
+ * in the type URL, for example "foo.bar.com/x/y.z" will yield type
+ * name "y.z".
+ * JSON
+ * ====
+ * The JSON representation of an `Any` value uses the regular
+ * representation of the deserialized, embedded message, with an
+ * additional field `@type` which contains the type URL. Example:
+ *     package google.profile;
+ *     message Person {
+ *       string first_name = 1;
+ *       string last_name = 2;
+ *     }
+ *     {
+ *       "@type": "type.googleapis.com/google.profile.Person",
+ *       "firstName": <string>,
+ *       "lastName": <string>
+ *     }
+ * If the embedded message type is well-known and has a custom JSON
+ * representation, that representation will be embedded adding a field
+ * `value` which holds the custom JSON in addition to the `@type`
+ * field. Example (for message [google.protobuf.Duration][]):
+ *     {
+ *       "@type": "type.googleapis.com/google.protobuf.Duration",
+ *       "value": "1.212s"
+ *     }
+ * 
+ * + * Protobuf type {@code google.protobuf.Any} + */ +public final class Any extends + com.google.protobuf.GeneratedMessageLite< + Any, Any.Builder> implements + // @@protoc_insertion_point(message_implements:google.protobuf.Any) + AnyOrBuilder { + private Any() { + typeUrl_ = ""; + value_ = com.google.protobuf.ByteString.EMPTY; + } + public static final int TYPE_URL_FIELD_NUMBER = 1; + private java.lang.String typeUrl_; + /** + *
+   * A URL/resource name that uniquely identifies the type of the serialized
+   * protocol buffer message. This string must contain at least
+   * one "/" character. The last segment of the URL's path must represent
+   * the fully qualified name of the type (as in
+   * `path/google.protobuf.Duration`). The name should be in a canonical form
+   * (e.g., leading "." is not accepted).
+   * In practice, teams usually precompile into the binary all types that they
+   * expect it to use in the context of Any. However, for URLs which use the
+   * scheme `http`, `https`, or no scheme, one can optionally set up a type
+   * server that maps type URLs to message definitions as follows:
+   * * If no scheme is provided, `https` is assumed.
+   * * An HTTP GET on the URL must yield a [google.protobuf.Type][]
+   *   value in binary format, or produce an error.
+   * * Applications are allowed to cache lookup results based on the
+   *   URL, or have them precompiled into a binary to avoid any
+   *   lookup. Therefore, binary compatibility needs to be preserved
+   *   on changes to types. (Use versioned type names to manage
+   *   breaking changes.)
+   * Note: this functionality is not currently available in the official
+   * protobuf release, and it is not used for type URLs beginning with
+   * type.googleapis.com.
+   * Schemes other than `http`, `https` (or the empty scheme) might be
+   * used with implementation specific semantics.
+   * 
+ * + * string type_url = 1; + * @return The typeUrl. + */ + @java.lang.Override + public java.lang.String getTypeUrl() { + return typeUrl_; + } + /** + *
+   * A URL/resource name that uniquely identifies the type of the serialized
+   * protocol buffer message. This string must contain at least
+   * one "/" character. The last segment of the URL's path must represent
+   * the fully qualified name of the type (as in
+   * `path/google.protobuf.Duration`). The name should be in a canonical form
+   * (e.g., leading "." is not accepted).
+   * In practice, teams usually precompile into the binary all types that they
+   * expect it to use in the context of Any. However, for URLs which use the
+   * scheme `http`, `https`, or no scheme, one can optionally set up a type
+   * server that maps type URLs to message definitions as follows:
+   * * If no scheme is provided, `https` is assumed.
+   * * An HTTP GET on the URL must yield a [google.protobuf.Type][]
+   *   value in binary format, or produce an error.
+   * * Applications are allowed to cache lookup results based on the
+   *   URL, or have them precompiled into a binary to avoid any
+   *   lookup. Therefore, binary compatibility needs to be preserved
+   *   on changes to types. (Use versioned type names to manage
+   *   breaking changes.)
+   * Note: this functionality is not currently available in the official
+   * protobuf release, and it is not used for type URLs beginning with
+   * type.googleapis.com.
+   * Schemes other than `http`, `https` (or the empty scheme) might be
+   * used with implementation specific semantics.
+   * 
+ * + * string type_url = 1; + * @return The bytes for typeUrl. + */ + @java.lang.Override + public com.google.protobuf.ByteString + getTypeUrlBytes() { + return com.google.protobuf.ByteString.copyFromUtf8(typeUrl_); + } + /** + *
+   * A URL/resource name that uniquely identifies the type of the serialized
+   * protocol buffer message. This string must contain at least
+   * one "/" character. The last segment of the URL's path must represent
+   * the fully qualified name of the type (as in
+   * `path/google.protobuf.Duration`). The name should be in a canonical form
+   * (e.g., leading "." is not accepted).
+   * In practice, teams usually precompile into the binary all types that they
+   * expect it to use in the context of Any. However, for URLs which use the
+   * scheme `http`, `https`, or no scheme, one can optionally set up a type
+   * server that maps type URLs to message definitions as follows:
+   * * If no scheme is provided, `https` is assumed.
+   * * An HTTP GET on the URL must yield a [google.protobuf.Type][]
+   *   value in binary format, or produce an error.
+   * * Applications are allowed to cache lookup results based on the
+   *   URL, or have them precompiled into a binary to avoid any
+   *   lookup. Therefore, binary compatibility needs to be preserved
+   *   on changes to types. (Use versioned type names to manage
+   *   breaking changes.)
+   * Note: this functionality is not currently available in the official
+   * protobuf release, and it is not used for type URLs beginning with
+   * type.googleapis.com.
+   * Schemes other than `http`, `https` (or the empty scheme) might be
+   * used with implementation specific semantics.
+   * 
+ * + * string type_url = 1; + * @param value The typeUrl to set. + */ + private void setTypeUrl( + java.lang.String value) { + value.getClass(); + + typeUrl_ = value; + } + /** + *
+   * A URL/resource name that uniquely identifies the type of the serialized
+   * protocol buffer message. This string must contain at least
+   * one "/" character. The last segment of the URL's path must represent
+   * the fully qualified name of the type (as in
+   * `path/google.protobuf.Duration`). The name should be in a canonical form
+   * (e.g., leading "." is not accepted).
+   * In practice, teams usually precompile into the binary all types that they
+   * expect it to use in the context of Any. However, for URLs which use the
+   * scheme `http`, `https`, or no scheme, one can optionally set up a type
+   * server that maps type URLs to message definitions as follows:
+   * * If no scheme is provided, `https` is assumed.
+   * * An HTTP GET on the URL must yield a [google.protobuf.Type][]
+   *   value in binary format, or produce an error.
+   * * Applications are allowed to cache lookup results based on the
+   *   URL, or have them precompiled into a binary to avoid any
+   *   lookup. Therefore, binary compatibility needs to be preserved
+   *   on changes to types. (Use versioned type names to manage
+   *   breaking changes.)
+   * Note: this functionality is not currently available in the official
+   * protobuf release, and it is not used for type URLs beginning with
+   * type.googleapis.com.
+   * Schemes other than `http`, `https` (or the empty scheme) might be
+   * used with implementation specific semantics.
+   * 
+ * + * string type_url = 1; + */ + private void clearTypeUrl() { + + typeUrl_ = getDefaultInstance().getTypeUrl(); + } + /** + *
+   * A URL/resource name that uniquely identifies the type of the serialized
+   * protocol buffer message. This string must contain at least
+   * one "/" character. The last segment of the URL's path must represent
+   * the fully qualified name of the type (as in
+   * `path/google.protobuf.Duration`). The name should be in a canonical form
+   * (e.g., leading "." is not accepted).
+   * In practice, teams usually precompile into the binary all types that they
+   * expect it to use in the context of Any. However, for URLs which use the
+   * scheme `http`, `https`, or no scheme, one can optionally set up a type
+   * server that maps type URLs to message definitions as follows:
+   * * If no scheme is provided, `https` is assumed.
+   * * An HTTP GET on the URL must yield a [google.protobuf.Type][]
+   *   value in binary format, or produce an error.
+   * * Applications are allowed to cache lookup results based on the
+   *   URL, or have them precompiled into a binary to avoid any
+   *   lookup. Therefore, binary compatibility needs to be preserved
+   *   on changes to types. (Use versioned type names to manage
+   *   breaking changes.)
+   * Note: this functionality is not currently available in the official
+   * protobuf release, and it is not used for type URLs beginning with
+   * type.googleapis.com.
+   * Schemes other than `http`, `https` (or the empty scheme) might be
+   * used with implementation specific semantics.
+   * 
+ * + * string type_url = 1; + * @param value The bytes for typeUrl to set. + */ + private void setTypeUrlBytes( + com.google.protobuf.ByteString value) { + checkByteStringIsUtf8(value); + typeUrl_ = value.toStringUtf8(); + + } + + public static final int VALUE_FIELD_NUMBER = 2; + private com.google.protobuf.ByteString value_; + /** + *
+   * Must be a valid serialized protocol buffer of the above specified type.
+   * 
+ * + * bytes value = 2; + * @return The value. + */ + @java.lang.Override + public com.google.protobuf.ByteString getValue() { + return value_; + } + /** + *
+   * Must be a valid serialized protocol buffer of the above specified type.
+   * 
+ * + * bytes value = 2; + * @param value The value to set. + */ + private void setValue(com.google.protobuf.ByteString value) { + value.getClass(); + + value_ = value; + } + /** + *
+   * Must be a valid serialized protocol buffer of the above specified type.
+   * 
+ * + * bytes value = 2; + */ + private void clearValue() { + + value_ = getDefaultInstance().getValue(); + } + + public static com.google.protobuf.Any parseFrom( + java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.Any parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.Any parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.Any parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.Any parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.Any parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.Any parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, 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.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, input, extensionRegistry); + } + public static com.google.protobuf.Any parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return parseDelimitedFrom(DEFAULT_INSTANCE, input); + } + public static com.google.protobuf.Any parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return parseDelimitedFrom(DEFAULT_INSTANCE, input, extensionRegistry); + } + public static com.google.protobuf.Any parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, 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.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, input, extensionRegistry); + } + + public static Builder newBuilder() { + return (Builder) DEFAULT_INSTANCE.createBuilder(); + } + public static Builder newBuilder(com.google.protobuf.Any prototype) { + return (Builder) DEFAULT_INSTANCE.createBuilder(prototype); + } + + /** + *
+   * `Any` contains an arbitrary serialized protocol buffer message along with a
+   * URL that describes the type of the serialized message.
+   * Protobuf library provides support to pack/unpack Any values in the form
+   * of utility functions or additional generated methods of the Any type.
+   * Example 1: Pack and unpack a message in C++.
+   *     Foo foo = ...;
+   *     Any any;
+   *     any.PackFrom(foo);
+   *     ...
+   *     if (any.UnpackTo(&foo)) {
+   *       ...
+   *     }
+   * Example 2: Pack and unpack a message in Java.
+   *     Foo foo = ...;
+   *     Any any = Any.pack(foo);
+   *     ...
+   *     if (any.is(Foo.class)) {
+   *       foo = any.unpack(Foo.class);
+   *     }
+   *  Example 3: Pack and unpack a message in Python.
+   *     foo = Foo(...)
+   *     any = Any()
+   *     any.Pack(foo)
+   *     ...
+   *     if any.Is(Foo.DESCRIPTOR):
+   *       any.Unpack(foo)
+   *       ...
+   *  Example 4: Pack and unpack a message in Go
+   *      foo := &pb.Foo{...}
+   *      any, err := anypb.New(foo)
+   *      if err != nil {
+   *        ...
+   *      }
+   *      ...
+   *      foo := &pb.Foo{}
+   *      if err := any.UnmarshalTo(foo); err != nil {
+   *        ...
+   *      }
+   * The pack methods provided by protobuf library will by default use
+   * 'type.googleapis.com/full.type.name' as the type URL and the unpack
+   * methods only use the fully qualified type name after the last '/'
+   * in the type URL, for example "foo.bar.com/x/y.z" will yield type
+   * name "y.z".
+   * JSON
+   * ====
+   * The JSON representation of an `Any` value uses the regular
+   * representation of the deserialized, embedded message, with an
+   * additional field `@type` which contains the type URL. Example:
+   *     package google.profile;
+   *     message Person {
+   *       string first_name = 1;
+   *       string last_name = 2;
+   *     }
+   *     {
+   *       "@type": "type.googleapis.com/google.profile.Person",
+   *       "firstName": <string>,
+   *       "lastName": <string>
+   *     }
+   * If the embedded message type is well-known and has a custom JSON
+   * representation, that representation will be embedded adding a field
+   * `value` which holds the custom JSON in addition to the `@type`
+   * field. Example (for message [google.protobuf.Duration][]):
+   *     {
+   *       "@type": "type.googleapis.com/google.protobuf.Duration",
+   *       "value": "1.212s"
+   *     }
+   * 
+ * + * Protobuf type {@code google.protobuf.Any} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessageLite.Builder< + com.google.protobuf.Any, Builder> implements + // @@protoc_insertion_point(builder_implements:google.protobuf.Any) + com.google.protobuf.AnyOrBuilder { + // Construct using com.google.protobuf.Any.newBuilder() + private Builder() { + super(DEFAULT_INSTANCE); + } + + + /** + *
+     * A URL/resource name that uniquely identifies the type of the serialized
+     * protocol buffer message. This string must contain at least
+     * one "/" character. The last segment of the URL's path must represent
+     * the fully qualified name of the type (as in
+     * `path/google.protobuf.Duration`). The name should be in a canonical form
+     * (e.g., leading "." is not accepted).
+     * In practice, teams usually precompile into the binary all types that they
+     * expect it to use in the context of Any. However, for URLs which use the
+     * scheme `http`, `https`, or no scheme, one can optionally set up a type
+     * server that maps type URLs to message definitions as follows:
+     * * If no scheme is provided, `https` is assumed.
+     * * An HTTP GET on the URL must yield a [google.protobuf.Type][]
+     *   value in binary format, or produce an error.
+     * * Applications are allowed to cache lookup results based on the
+     *   URL, or have them precompiled into a binary to avoid any
+     *   lookup. Therefore, binary compatibility needs to be preserved
+     *   on changes to types. (Use versioned type names to manage
+     *   breaking changes.)
+     * Note: this functionality is not currently available in the official
+     * protobuf release, and it is not used for type URLs beginning with
+     * type.googleapis.com.
+     * Schemes other than `http`, `https` (or the empty scheme) might be
+     * used with implementation specific semantics.
+     * 
+ * + * string type_url = 1; + * @return The typeUrl. + */ + @java.lang.Override + public java.lang.String getTypeUrl() { + return instance.getTypeUrl(); + } + /** + *
+     * A URL/resource name that uniquely identifies the type of the serialized
+     * protocol buffer message. This string must contain at least
+     * one "/" character. The last segment of the URL's path must represent
+     * the fully qualified name of the type (as in
+     * `path/google.protobuf.Duration`). The name should be in a canonical form
+     * (e.g., leading "." is not accepted).
+     * In practice, teams usually precompile into the binary all types that they
+     * expect it to use in the context of Any. However, for URLs which use the
+     * scheme `http`, `https`, or no scheme, one can optionally set up a type
+     * server that maps type URLs to message definitions as follows:
+     * * If no scheme is provided, `https` is assumed.
+     * * An HTTP GET on the URL must yield a [google.protobuf.Type][]
+     *   value in binary format, or produce an error.
+     * * Applications are allowed to cache lookup results based on the
+     *   URL, or have them precompiled into a binary to avoid any
+     *   lookup. Therefore, binary compatibility needs to be preserved
+     *   on changes to types. (Use versioned type names to manage
+     *   breaking changes.)
+     * Note: this functionality is not currently available in the official
+     * protobuf release, and it is not used for type URLs beginning with
+     * type.googleapis.com.
+     * Schemes other than `http`, `https` (or the empty scheme) might be
+     * used with implementation specific semantics.
+     * 
+ * + * string type_url = 1; + * @return The bytes for typeUrl. + */ + @java.lang.Override + public com.google.protobuf.ByteString + getTypeUrlBytes() { + return instance.getTypeUrlBytes(); + } + /** + *
+     * A URL/resource name that uniquely identifies the type of the serialized
+     * protocol buffer message. This string must contain at least
+     * one "/" character. The last segment of the URL's path must represent
+     * the fully qualified name of the type (as in
+     * `path/google.protobuf.Duration`). The name should be in a canonical form
+     * (e.g., leading "." is not accepted).
+     * In practice, teams usually precompile into the binary all types that they
+     * expect it to use in the context of Any. However, for URLs which use the
+     * scheme `http`, `https`, or no scheme, one can optionally set up a type
+     * server that maps type URLs to message definitions as follows:
+     * * If no scheme is provided, `https` is assumed.
+     * * An HTTP GET on the URL must yield a [google.protobuf.Type][]
+     *   value in binary format, or produce an error.
+     * * Applications are allowed to cache lookup results based on the
+     *   URL, or have them precompiled into a binary to avoid any
+     *   lookup. Therefore, binary compatibility needs to be preserved
+     *   on changes to types. (Use versioned type names to manage
+     *   breaking changes.)
+     * Note: this functionality is not currently available in the official
+     * protobuf release, and it is not used for type URLs beginning with
+     * type.googleapis.com.
+     * Schemes other than `http`, `https` (or the empty scheme) might be
+     * used with implementation specific semantics.
+     * 
+ * + * string type_url = 1; + * @param value The typeUrl to set. + * @return This builder for chaining. + */ + public Builder setTypeUrl( + java.lang.String value) { + copyOnWrite(); + instance.setTypeUrl(value); + return this; + } + /** + *
+     * A URL/resource name that uniquely identifies the type of the serialized
+     * protocol buffer message. This string must contain at least
+     * one "/" character. The last segment of the URL's path must represent
+     * the fully qualified name of the type (as in
+     * `path/google.protobuf.Duration`). The name should be in a canonical form
+     * (e.g., leading "." is not accepted).
+     * In practice, teams usually precompile into the binary all types that they
+     * expect it to use in the context of Any. However, for URLs which use the
+     * scheme `http`, `https`, or no scheme, one can optionally set up a type
+     * server that maps type URLs to message definitions as follows:
+     * * If no scheme is provided, `https` is assumed.
+     * * An HTTP GET on the URL must yield a [google.protobuf.Type][]
+     *   value in binary format, or produce an error.
+     * * Applications are allowed to cache lookup results based on the
+     *   URL, or have them precompiled into a binary to avoid any
+     *   lookup. Therefore, binary compatibility needs to be preserved
+     *   on changes to types. (Use versioned type names to manage
+     *   breaking changes.)
+     * Note: this functionality is not currently available in the official
+     * protobuf release, and it is not used for type URLs beginning with
+     * type.googleapis.com.
+     * Schemes other than `http`, `https` (or the empty scheme) might be
+     * used with implementation specific semantics.
+     * 
+ * + * string type_url = 1; + * @return This builder for chaining. + */ + public Builder clearTypeUrl() { + copyOnWrite(); + instance.clearTypeUrl(); + return this; + } + /** + *
+     * A URL/resource name that uniquely identifies the type of the serialized
+     * protocol buffer message. This string must contain at least
+     * one "/" character. The last segment of the URL's path must represent
+     * the fully qualified name of the type (as in
+     * `path/google.protobuf.Duration`). The name should be in a canonical form
+     * (e.g., leading "." is not accepted).
+     * In practice, teams usually precompile into the binary all types that they
+     * expect it to use in the context of Any. However, for URLs which use the
+     * scheme `http`, `https`, or no scheme, one can optionally set up a type
+     * server that maps type URLs to message definitions as follows:
+     * * If no scheme is provided, `https` is assumed.
+     * * An HTTP GET on the URL must yield a [google.protobuf.Type][]
+     *   value in binary format, or produce an error.
+     * * Applications are allowed to cache lookup results based on the
+     *   URL, or have them precompiled into a binary to avoid any
+     *   lookup. Therefore, binary compatibility needs to be preserved
+     *   on changes to types. (Use versioned type names to manage
+     *   breaking changes.)
+     * Note: this functionality is not currently available in the official
+     * protobuf release, and it is not used for type URLs beginning with
+     * type.googleapis.com.
+     * Schemes other than `http`, `https` (or the empty scheme) might be
+     * used with implementation specific semantics.
+     * 
+ * + * string type_url = 1; + * @param value The bytes for typeUrl to set. + * @return This builder for chaining. + */ + public Builder setTypeUrlBytes( + com.google.protobuf.ByteString value) { + copyOnWrite(); + instance.setTypeUrlBytes(value); + return this; + } + + /** + *
+     * Must be a valid serialized protocol buffer of the above specified type.
+     * 
+ * + * bytes value = 2; + * @return The value. + */ + @java.lang.Override + public com.google.protobuf.ByteString getValue() { + return instance.getValue(); + } + /** + *
+     * Must be a valid serialized protocol buffer of the above specified type.
+     * 
+ * + * bytes value = 2; + * @param value The value to set. + * @return This builder for chaining. + */ + public Builder setValue(com.google.protobuf.ByteString value) { + copyOnWrite(); + instance.setValue(value); + return this; + } + /** + *
+     * Must be a valid serialized protocol buffer of the above specified type.
+     * 
+ * + * bytes value = 2; + * @return This builder for chaining. + */ + public Builder clearValue() { + copyOnWrite(); + instance.clearValue(); + return this; + } + + // @@protoc_insertion_point(builder_scope:google.protobuf.Any) + } + @java.lang.Override + @java.lang.SuppressWarnings({"unchecked", "fallthrough"}) + protected final java.lang.Object dynamicMethod( + com.google.protobuf.GeneratedMessageLite.MethodToInvoke method, + java.lang.Object arg0, java.lang.Object arg1) { + switch (method) { + case NEW_MUTABLE_INSTANCE: { + return new com.google.protobuf.Any(); + } + case NEW_BUILDER: { + return new Builder(); + } + case BUILD_MESSAGE_INFO: { + java.lang.Object[] objects = new java.lang.Object[] { + "typeUrl_", + "value_", + }; + java.lang.String info = + "\u0000\u0002\u0000\u0000\u0001\u0002\u0002\u0000\u0000\u0000\u0001\u0208\u0002\n" + + ""; + return newMessageInfo(DEFAULT_INSTANCE, info, objects); + } + // fall through + case GET_DEFAULT_INSTANCE: { + return DEFAULT_INSTANCE; + } + case GET_PARSER: { + com.google.protobuf.Parser parser = PARSER; + if (parser == null) { + synchronized (com.google.protobuf.Any.class) { + parser = PARSER; + if (parser == null) { + parser = + new DefaultInstanceBasedParser( + DEFAULT_INSTANCE); + PARSER = parser; + } + } + } + return parser; + } + case GET_MEMOIZED_IS_INITIALIZED: { + return (byte) 1; + } + case SET_MEMOIZED_IS_INITIALIZED: { + return null; + } + } + throw new UnsupportedOperationException(); + } + + + // @@protoc_insertion_point(class_scope:google.protobuf.Any) + private static final com.google.protobuf.Any DEFAULT_INSTANCE; + static { + Any defaultInstance = new Any(); + // New instances are implicitly immutable so no need to make + // immutable. + DEFAULT_INSTANCE = defaultInstance; + com.google.protobuf.GeneratedMessageLite.registerDefaultInstance( + Any.class, defaultInstance); + } + + public static com.google.protobuf.Any getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static volatile com.google.protobuf.Parser PARSER; + + public static com.google.protobuf.Parser parser() { + return DEFAULT_INSTANCE.getParserForType(); + } +} + diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/AnyOrBuilder.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/AnyOrBuilder.java new file mode 100644 index 0000000000000..5fcd84c842ea7 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/AnyOrBuilder.java @@ -0,0 +1,83 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/any.proto + +package com.google.protobuf; + +public interface AnyOrBuilder extends + // @@protoc_insertion_point(interface_extends:google.protobuf.Any) + com.google.protobuf.MessageLiteOrBuilder { + + /** + *
+   * A URL/resource name that uniquely identifies the type of the serialized
+   * protocol buffer message. This string must contain at least
+   * one "/" character. The last segment of the URL's path must represent
+   * the fully qualified name of the type (as in
+   * `path/google.protobuf.Duration`). The name should be in a canonical form
+   * (e.g., leading "." is not accepted).
+   * In practice, teams usually precompile into the binary all types that they
+   * expect it to use in the context of Any. However, for URLs which use the
+   * scheme `http`, `https`, or no scheme, one can optionally set up a type
+   * server that maps type URLs to message definitions as follows:
+   * * If no scheme is provided, `https` is assumed.
+   * * An HTTP GET on the URL must yield a [google.protobuf.Type][]
+   *   value in binary format, or produce an error.
+   * * Applications are allowed to cache lookup results based on the
+   *   URL, or have them precompiled into a binary to avoid any
+   *   lookup. Therefore, binary compatibility needs to be preserved
+   *   on changes to types. (Use versioned type names to manage
+   *   breaking changes.)
+   * Note: this functionality is not currently available in the official
+   * protobuf release, and it is not used for type URLs beginning with
+   * type.googleapis.com.
+   * Schemes other than `http`, `https` (or the empty scheme) might be
+   * used with implementation specific semantics.
+   * 
+ * + * string type_url = 1; + * @return The typeUrl. + */ + java.lang.String getTypeUrl(); + /** + *
+   * A URL/resource name that uniquely identifies the type of the serialized
+   * protocol buffer message. This string must contain at least
+   * one "/" character. The last segment of the URL's path must represent
+   * the fully qualified name of the type (as in
+   * `path/google.protobuf.Duration`). The name should be in a canonical form
+   * (e.g., leading "." is not accepted).
+   * In practice, teams usually precompile into the binary all types that they
+   * expect it to use in the context of Any. However, for URLs which use the
+   * scheme `http`, `https`, or no scheme, one can optionally set up a type
+   * server that maps type URLs to message definitions as follows:
+   * * If no scheme is provided, `https` is assumed.
+   * * An HTTP GET on the URL must yield a [google.protobuf.Type][]
+   *   value in binary format, or produce an error.
+   * * Applications are allowed to cache lookup results based on the
+   *   URL, or have them precompiled into a binary to avoid any
+   *   lookup. Therefore, binary compatibility needs to be preserved
+   *   on changes to types. (Use versioned type names to manage
+   *   breaking changes.)
+   * Note: this functionality is not currently available in the official
+   * protobuf release, and it is not used for type URLs beginning with
+   * type.googleapis.com.
+   * Schemes other than `http`, `https` (or the empty scheme) might be
+   * used with implementation specific semantics.
+   * 
+ * + * string type_url = 1; + * @return The bytes for typeUrl. + */ + com.google.protobuf.ByteString + getTypeUrlBytes(); + + /** + *
+   * Must be a valid serialized protocol buffer of the above specified type.
+   * 
+ * + * bytes value = 2; + * @return The value. + */ + com.google.protobuf.ByteString getValue(); +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/AnyProto.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/AnyProto.java new file mode 100644 index 0000000000000..f6dc68bb5034c --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/AnyProto.java @@ -0,0 +1,16 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/any.proto + +package com.google.protobuf; + +public final class AnyProto { + private AnyProto() {} + public static void registerAllExtensions( + com.google.protobuf.ExtensionRegistryLite registry) { + } + + static { + } + + // @@protoc_insertion_point(outer_class_scope) +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/Api.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/Api.java new file mode 100644 index 0000000000000..00be720e761d5 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/Api.java @@ -0,0 +1,1803 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/api.proto + +package com.google.protobuf; + +/** + *
+ * Api is a light-weight descriptor for an API Interface.
+ * Interfaces are also described as "protocol buffer services" in some contexts,
+ * such as by the "service" keyword in a .proto file, but they are different
+ * from API Services, which represent a concrete implementation of an interface
+ * as opposed to simply a description of methods and bindings. They are also
+ * sometimes simply referred to as "APIs" in other contexts, such as the name of
+ * this message itself. See https://cloud.google.com/apis/design/glossary for
+ * detailed terminology.
+ * 
+ * + * Protobuf type {@code google.protobuf.Api} + */ +public final class Api extends + com.google.protobuf.GeneratedMessageLite< + Api, Api.Builder> implements + // @@protoc_insertion_point(message_implements:google.protobuf.Api) + ApiOrBuilder { + private Api() { + name_ = ""; + methods_ = emptyProtobufList(); + options_ = emptyProtobufList(); + version_ = ""; + mixins_ = emptyProtobufList(); + } + public static final int NAME_FIELD_NUMBER = 1; + private java.lang.String name_; + /** + *
+   * The fully qualified name of this interface, including package name
+   * followed by the interface's simple name.
+   * 
+ * + * string name = 1; + * @return The name. + */ + @java.lang.Override + public java.lang.String getName() { + return name_; + } + /** + *
+   * The fully qualified name of this interface, including package name
+   * followed by the interface's simple name.
+   * 
+ * + * string name = 1; + * @return The bytes for name. + */ + @java.lang.Override + public com.google.protobuf.ByteString + getNameBytes() { + return com.google.protobuf.ByteString.copyFromUtf8(name_); + } + /** + *
+   * The fully qualified name of this interface, including package name
+   * followed by the interface's simple name.
+   * 
+ * + * string name = 1; + * @param value The name to set. + */ + private void setName( + java.lang.String value) { + value.getClass(); + + name_ = value; + } + /** + *
+   * The fully qualified name of this interface, including package name
+   * followed by the interface's simple name.
+   * 
+ * + * string name = 1; + */ + private void clearName() { + + name_ = getDefaultInstance().getName(); + } + /** + *
+   * The fully qualified name of this interface, including package name
+   * followed by the interface's simple name.
+   * 
+ * + * string name = 1; + * @param value The bytes for name to set. + */ + private void setNameBytes( + com.google.protobuf.ByteString value) { + checkByteStringIsUtf8(value); + name_ = value.toStringUtf8(); + + } + + public static final int METHODS_FIELD_NUMBER = 2; + private com.google.protobuf.Internal.ProtobufList methods_; + /** + *
+   * The methods of this interface, in unspecified order.
+   * 
+ * + * repeated .google.protobuf.Method methods = 2; + */ + @java.lang.Override + public java.util.List getMethodsList() { + return methods_; + } + /** + *
+   * The methods of this interface, in unspecified order.
+   * 
+ * + * repeated .google.protobuf.Method methods = 2; + */ + public java.util.List + getMethodsOrBuilderList() { + return methods_; + } + /** + *
+   * The methods of this interface, in unspecified order.
+   * 
+ * + * repeated .google.protobuf.Method methods = 2; + */ + @java.lang.Override + public int getMethodsCount() { + return methods_.size(); + } + /** + *
+   * The methods of this interface, in unspecified order.
+   * 
+ * + * repeated .google.protobuf.Method methods = 2; + */ + @java.lang.Override + public com.google.protobuf.Method getMethods(int index) { + return methods_.get(index); + } + /** + *
+   * The methods of this interface, in unspecified order.
+   * 
+ * + * repeated .google.protobuf.Method methods = 2; + */ + public com.google.protobuf.MethodOrBuilder getMethodsOrBuilder( + int index) { + return methods_.get(index); + } + private void ensureMethodsIsMutable() { + com.google.protobuf.Internal.ProtobufList tmp = methods_; + if (!tmp.isModifiable()) { + methods_ = + com.google.protobuf.GeneratedMessageLite.mutableCopy(tmp); + } + } + + /** + *
+   * The methods of this interface, in unspecified order.
+   * 
+ * + * repeated .google.protobuf.Method methods = 2; + */ + private void setMethods( + int index, com.google.protobuf.Method value) { + value.getClass(); + ensureMethodsIsMutable(); + methods_.set(index, value); + } + /** + *
+   * The methods of this interface, in unspecified order.
+   * 
+ * + * repeated .google.protobuf.Method methods = 2; + */ + private void addMethods(com.google.protobuf.Method value) { + value.getClass(); + ensureMethodsIsMutable(); + methods_.add(value); + } + /** + *
+   * The methods of this interface, in unspecified order.
+   * 
+ * + * repeated .google.protobuf.Method methods = 2; + */ + private void addMethods( + int index, com.google.protobuf.Method value) { + value.getClass(); + ensureMethodsIsMutable(); + methods_.add(index, value); + } + /** + *
+   * The methods of this interface, in unspecified order.
+   * 
+ * + * repeated .google.protobuf.Method methods = 2; + */ + private void addAllMethods( + java.lang.Iterable values) { + ensureMethodsIsMutable(); + com.google.protobuf.AbstractMessageLite.addAll( + values, methods_); + } + /** + *
+   * The methods of this interface, in unspecified order.
+   * 
+ * + * repeated .google.protobuf.Method methods = 2; + */ + private void clearMethods() { + methods_ = emptyProtobufList(); + } + /** + *
+   * The methods of this interface, in unspecified order.
+   * 
+ * + * repeated .google.protobuf.Method methods = 2; + */ + private void removeMethods(int index) { + ensureMethodsIsMutable(); + methods_.remove(index); + } + + public static final int OPTIONS_FIELD_NUMBER = 3; + private com.google.protobuf.Internal.ProtobufList options_; + /** + *
+   * Any metadata attached to the interface.
+   * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + @java.lang.Override + public java.util.List getOptionsList() { + return options_; + } + /** + *
+   * Any metadata attached to the interface.
+   * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + public java.util.List + getOptionsOrBuilderList() { + return options_; + } + /** + *
+   * Any metadata attached to the interface.
+   * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + @java.lang.Override + public int getOptionsCount() { + return options_.size(); + } + /** + *
+   * Any metadata attached to the interface.
+   * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + @java.lang.Override + public com.google.protobuf.Option getOptions(int index) { + return options_.get(index); + } + /** + *
+   * Any metadata attached to the interface.
+   * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + public com.google.protobuf.OptionOrBuilder getOptionsOrBuilder( + int index) { + return options_.get(index); + } + private void ensureOptionsIsMutable() { + com.google.protobuf.Internal.ProtobufList tmp = options_; + if (!tmp.isModifiable()) { + options_ = + com.google.protobuf.GeneratedMessageLite.mutableCopy(tmp); + } + } + + /** + *
+   * Any metadata attached to the interface.
+   * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + private void setOptions( + int index, com.google.protobuf.Option value) { + value.getClass(); + ensureOptionsIsMutable(); + options_.set(index, value); + } + /** + *
+   * Any metadata attached to the interface.
+   * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + private void addOptions(com.google.protobuf.Option value) { + value.getClass(); + ensureOptionsIsMutable(); + options_.add(value); + } + /** + *
+   * Any metadata attached to the interface.
+   * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + private void addOptions( + int index, com.google.protobuf.Option value) { + value.getClass(); + ensureOptionsIsMutable(); + options_.add(index, value); + } + /** + *
+   * Any metadata attached to the interface.
+   * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + private void addAllOptions( + java.lang.Iterable values) { + ensureOptionsIsMutable(); + com.google.protobuf.AbstractMessageLite.addAll( + values, options_); + } + /** + *
+   * Any metadata attached to the interface.
+   * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + private void clearOptions() { + options_ = emptyProtobufList(); + } + /** + *
+   * Any metadata attached to the interface.
+   * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + private void removeOptions(int index) { + ensureOptionsIsMutable(); + options_.remove(index); + } + + public static final int VERSION_FIELD_NUMBER = 4; + private java.lang.String version_; + /** + *
+   * A version string for this interface. If specified, must have the form
+   * `major-version.minor-version`, as in `1.10`. If the minor version is
+   * omitted, it defaults to zero. If the entire version field is empty, the
+   * major version is derived from the package name, as outlined below. If the
+   * field is not empty, the version in the package name will be verified to be
+   * consistent with what is provided here.
+   * The versioning schema uses [semantic
+   * versioning](http://semver.org) where the major version number
+   * indicates a breaking change and the minor version an additive,
+   * non-breaking change. Both version numbers are signals to users
+   * what to expect from different versions, and should be carefully
+   * chosen based on the product plan.
+   * The major version is also reflected in the package name of the
+   * interface, which must end in `v<major-version>`, as in
+   * `google.feature.v1`. For major versions 0 and 1, the suffix can
+   * be omitted. Zero major versions must only be used for
+   * experimental, non-GA interfaces.
+   * 
+ * + * string version = 4; + * @return The version. + */ + @java.lang.Override + public java.lang.String getVersion() { + return version_; + } + /** + *
+   * A version string for this interface. If specified, must have the form
+   * `major-version.minor-version`, as in `1.10`. If the minor version is
+   * omitted, it defaults to zero. If the entire version field is empty, the
+   * major version is derived from the package name, as outlined below. If the
+   * field is not empty, the version in the package name will be verified to be
+   * consistent with what is provided here.
+   * The versioning schema uses [semantic
+   * versioning](http://semver.org) where the major version number
+   * indicates a breaking change and the minor version an additive,
+   * non-breaking change. Both version numbers are signals to users
+   * what to expect from different versions, and should be carefully
+   * chosen based on the product plan.
+   * The major version is also reflected in the package name of the
+   * interface, which must end in `v<major-version>`, as in
+   * `google.feature.v1`. For major versions 0 and 1, the suffix can
+   * be omitted. Zero major versions must only be used for
+   * experimental, non-GA interfaces.
+   * 
+ * + * string version = 4; + * @return The bytes for version. + */ + @java.lang.Override + public com.google.protobuf.ByteString + getVersionBytes() { + return com.google.protobuf.ByteString.copyFromUtf8(version_); + } + /** + *
+   * A version string for this interface. If specified, must have the form
+   * `major-version.minor-version`, as in `1.10`. If the minor version is
+   * omitted, it defaults to zero. If the entire version field is empty, the
+   * major version is derived from the package name, as outlined below. If the
+   * field is not empty, the version in the package name will be verified to be
+   * consistent with what is provided here.
+   * The versioning schema uses [semantic
+   * versioning](http://semver.org) where the major version number
+   * indicates a breaking change and the minor version an additive,
+   * non-breaking change. Both version numbers are signals to users
+   * what to expect from different versions, and should be carefully
+   * chosen based on the product plan.
+   * The major version is also reflected in the package name of the
+   * interface, which must end in `v<major-version>`, as in
+   * `google.feature.v1`. For major versions 0 and 1, the suffix can
+   * be omitted. Zero major versions must only be used for
+   * experimental, non-GA interfaces.
+   * 
+ * + * string version = 4; + * @param value The version to set. + */ + private void setVersion( + java.lang.String value) { + value.getClass(); + + version_ = value; + } + /** + *
+   * A version string for this interface. If specified, must have the form
+   * `major-version.minor-version`, as in `1.10`. If the minor version is
+   * omitted, it defaults to zero. If the entire version field is empty, the
+   * major version is derived from the package name, as outlined below. If the
+   * field is not empty, the version in the package name will be verified to be
+   * consistent with what is provided here.
+   * The versioning schema uses [semantic
+   * versioning](http://semver.org) where the major version number
+   * indicates a breaking change and the minor version an additive,
+   * non-breaking change. Both version numbers are signals to users
+   * what to expect from different versions, and should be carefully
+   * chosen based on the product plan.
+   * The major version is also reflected in the package name of the
+   * interface, which must end in `v<major-version>`, as in
+   * `google.feature.v1`. For major versions 0 and 1, the suffix can
+   * be omitted. Zero major versions must only be used for
+   * experimental, non-GA interfaces.
+   * 
+ * + * string version = 4; + */ + private void clearVersion() { + + version_ = getDefaultInstance().getVersion(); + } + /** + *
+   * A version string for this interface. If specified, must have the form
+   * `major-version.minor-version`, as in `1.10`. If the minor version is
+   * omitted, it defaults to zero. If the entire version field is empty, the
+   * major version is derived from the package name, as outlined below. If the
+   * field is not empty, the version in the package name will be verified to be
+   * consistent with what is provided here.
+   * The versioning schema uses [semantic
+   * versioning](http://semver.org) where the major version number
+   * indicates a breaking change and the minor version an additive,
+   * non-breaking change. Both version numbers are signals to users
+   * what to expect from different versions, and should be carefully
+   * chosen based on the product plan.
+   * The major version is also reflected in the package name of the
+   * interface, which must end in `v<major-version>`, as in
+   * `google.feature.v1`. For major versions 0 and 1, the suffix can
+   * be omitted. Zero major versions must only be used for
+   * experimental, non-GA interfaces.
+   * 
+ * + * string version = 4; + * @param value The bytes for version to set. + */ + private void setVersionBytes( + com.google.protobuf.ByteString value) { + checkByteStringIsUtf8(value); + version_ = value.toStringUtf8(); + + } + + public static final int SOURCE_CONTEXT_FIELD_NUMBER = 5; + private com.google.protobuf.SourceContext sourceContext_; + /** + *
+   * Source context for the protocol buffer service represented by this
+   * message.
+   * 
+ * + * .google.protobuf.SourceContext source_context = 5; + */ + @java.lang.Override + public boolean hasSourceContext() { + return sourceContext_ != null; + } + /** + *
+   * Source context for the protocol buffer service represented by this
+   * message.
+   * 
+ * + * .google.protobuf.SourceContext source_context = 5; + */ + @java.lang.Override + public com.google.protobuf.SourceContext getSourceContext() { + return sourceContext_ == null ? com.google.protobuf.SourceContext.getDefaultInstance() : sourceContext_; + } + /** + *
+   * Source context for the protocol buffer service represented by this
+   * message.
+   * 
+ * + * .google.protobuf.SourceContext source_context = 5; + */ + private void setSourceContext(com.google.protobuf.SourceContext value) { + value.getClass(); + sourceContext_ = value; + + } + /** + *
+   * Source context for the protocol buffer service represented by this
+   * message.
+   * 
+ * + * .google.protobuf.SourceContext source_context = 5; + */ + @java.lang.SuppressWarnings({"ReferenceEquality"}) + private void mergeSourceContext(com.google.protobuf.SourceContext value) { + value.getClass(); + if (sourceContext_ != null && + sourceContext_ != com.google.protobuf.SourceContext.getDefaultInstance()) { + sourceContext_ = + com.google.protobuf.SourceContext.newBuilder(sourceContext_).mergeFrom(value).buildPartial(); + } else { + sourceContext_ = value; + } + + } + /** + *
+   * Source context for the protocol buffer service represented by this
+   * message.
+   * 
+ * + * .google.protobuf.SourceContext source_context = 5; + */ + private void clearSourceContext() { sourceContext_ = null; + + } + + public static final int MIXINS_FIELD_NUMBER = 6; + private com.google.protobuf.Internal.ProtobufList mixins_; + /** + *
+   * Included interfaces. See [Mixin][].
+   * 
+ * + * repeated .google.protobuf.Mixin mixins = 6; + */ + @java.lang.Override + public java.util.List getMixinsList() { + return mixins_; + } + /** + *
+   * Included interfaces. See [Mixin][].
+   * 
+ * + * repeated .google.protobuf.Mixin mixins = 6; + */ + public java.util.List + getMixinsOrBuilderList() { + return mixins_; + } + /** + *
+   * Included interfaces. See [Mixin][].
+   * 
+ * + * repeated .google.protobuf.Mixin mixins = 6; + */ + @java.lang.Override + public int getMixinsCount() { + return mixins_.size(); + } + /** + *
+   * Included interfaces. See [Mixin][].
+   * 
+ * + * repeated .google.protobuf.Mixin mixins = 6; + */ + @java.lang.Override + public com.google.protobuf.Mixin getMixins(int index) { + return mixins_.get(index); + } + /** + *
+   * Included interfaces. See [Mixin][].
+   * 
+ * + * repeated .google.protobuf.Mixin mixins = 6; + */ + public com.google.protobuf.MixinOrBuilder getMixinsOrBuilder( + int index) { + return mixins_.get(index); + } + private void ensureMixinsIsMutable() { + com.google.protobuf.Internal.ProtobufList tmp = mixins_; + if (!tmp.isModifiable()) { + mixins_ = + com.google.protobuf.GeneratedMessageLite.mutableCopy(tmp); + } + } + + /** + *
+   * Included interfaces. See [Mixin][].
+   * 
+ * + * repeated .google.protobuf.Mixin mixins = 6; + */ + private void setMixins( + int index, com.google.protobuf.Mixin value) { + value.getClass(); + ensureMixinsIsMutable(); + mixins_.set(index, value); + } + /** + *
+   * Included interfaces. See [Mixin][].
+   * 
+ * + * repeated .google.protobuf.Mixin mixins = 6; + */ + private void addMixins(com.google.protobuf.Mixin value) { + value.getClass(); + ensureMixinsIsMutable(); + mixins_.add(value); + } + /** + *
+   * Included interfaces. See [Mixin][].
+   * 
+ * + * repeated .google.protobuf.Mixin mixins = 6; + */ + private void addMixins( + int index, com.google.protobuf.Mixin value) { + value.getClass(); + ensureMixinsIsMutable(); + mixins_.add(index, value); + } + /** + *
+   * Included interfaces. See [Mixin][].
+   * 
+ * + * repeated .google.protobuf.Mixin mixins = 6; + */ + private void addAllMixins( + java.lang.Iterable values) { + ensureMixinsIsMutable(); + com.google.protobuf.AbstractMessageLite.addAll( + values, mixins_); + } + /** + *
+   * Included interfaces. See [Mixin][].
+   * 
+ * + * repeated .google.protobuf.Mixin mixins = 6; + */ + private void clearMixins() { + mixins_ = emptyProtobufList(); + } + /** + *
+   * Included interfaces. See [Mixin][].
+   * 
+ * + * repeated .google.protobuf.Mixin mixins = 6; + */ + private void removeMixins(int index) { + ensureMixinsIsMutable(); + mixins_.remove(index); + } + + public static final int SYNTAX_FIELD_NUMBER = 7; + private int syntax_; + /** + *
+   * The source syntax of the service.
+   * 
+ * + * .google.protobuf.Syntax syntax = 7; + * @return The enum numeric value on the wire for syntax. + */ + @java.lang.Override + public int getSyntaxValue() { + return syntax_; + } + /** + *
+   * The source syntax of the service.
+   * 
+ * + * .google.protobuf.Syntax syntax = 7; + * @return The syntax. + */ + @java.lang.Override + public com.google.protobuf.Syntax getSyntax() { + com.google.protobuf.Syntax result = com.google.protobuf.Syntax.forNumber(syntax_); + return result == null ? com.google.protobuf.Syntax.UNRECOGNIZED : result; + } + /** + *
+   * The source syntax of the service.
+   * 
+ * + * .google.protobuf.Syntax syntax = 7; + * @param value The enum numeric value on the wire for syntax to set. + */ + private void setSyntaxValue(int value) { + syntax_ = value; + } + /** + *
+   * The source syntax of the service.
+   * 
+ * + * .google.protobuf.Syntax syntax = 7; + * @param value The syntax to set. + */ + private void setSyntax(com.google.protobuf.Syntax value) { + syntax_ = value.getNumber(); + + } + /** + *
+   * The source syntax of the service.
+   * 
+ * + * .google.protobuf.Syntax syntax = 7; + */ + private void clearSyntax() { + + syntax_ = 0; + } + + public static com.google.protobuf.Api parseFrom( + java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.Api parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.Api parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.Api parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.Api parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.Api parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.Api parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, 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.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, input, extensionRegistry); + } + public static com.google.protobuf.Api parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return parseDelimitedFrom(DEFAULT_INSTANCE, input); + } + public static com.google.protobuf.Api parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return parseDelimitedFrom(DEFAULT_INSTANCE, input, extensionRegistry); + } + public static com.google.protobuf.Api parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, 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.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, input, extensionRegistry); + } + + public static Builder newBuilder() { + return (Builder) DEFAULT_INSTANCE.createBuilder(); + } + public static Builder newBuilder(com.google.protobuf.Api prototype) { + return (Builder) DEFAULT_INSTANCE.createBuilder(prototype); + } + + /** + *
+   * Api is a light-weight descriptor for an API Interface.
+   * Interfaces are also described as "protocol buffer services" in some contexts,
+   * such as by the "service" keyword in a .proto file, but they are different
+   * from API Services, which represent a concrete implementation of an interface
+   * as opposed to simply a description of methods and bindings. They are also
+   * sometimes simply referred to as "APIs" in other contexts, such as the name of
+   * this message itself. See https://cloud.google.com/apis/design/glossary for
+   * detailed terminology.
+   * 
+ * + * Protobuf type {@code google.protobuf.Api} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessageLite.Builder< + com.google.protobuf.Api, Builder> implements + // @@protoc_insertion_point(builder_implements:google.protobuf.Api) + com.google.protobuf.ApiOrBuilder { + // Construct using com.google.protobuf.Api.newBuilder() + private Builder() { + super(DEFAULT_INSTANCE); + } + + + /** + *
+     * The fully qualified name of this interface, including package name
+     * followed by the interface's simple name.
+     * 
+ * + * string name = 1; + * @return The name. + */ + @java.lang.Override + public java.lang.String getName() { + return instance.getName(); + } + /** + *
+     * The fully qualified name of this interface, including package name
+     * followed by the interface's simple name.
+     * 
+ * + * string name = 1; + * @return The bytes for name. + */ + @java.lang.Override + public com.google.protobuf.ByteString + getNameBytes() { + return instance.getNameBytes(); + } + /** + *
+     * The fully qualified name of this interface, including package name
+     * followed by the interface's simple name.
+     * 
+ * + * string name = 1; + * @param value The name to set. + * @return This builder for chaining. + */ + public Builder setName( + java.lang.String value) { + copyOnWrite(); + instance.setName(value); + return this; + } + /** + *
+     * The fully qualified name of this interface, including package name
+     * followed by the interface's simple name.
+     * 
+ * + * string name = 1; + * @return This builder for chaining. + */ + public Builder clearName() { + copyOnWrite(); + instance.clearName(); + return this; + } + /** + *
+     * The fully qualified name of this interface, including package name
+     * followed by the interface's simple name.
+     * 
+ * + * string name = 1; + * @param value The bytes for name to set. + * @return This builder for chaining. + */ + public Builder setNameBytes( + com.google.protobuf.ByteString value) { + copyOnWrite(); + instance.setNameBytes(value); + return this; + } + + /** + *
+     * The methods of this interface, in unspecified order.
+     * 
+ * + * repeated .google.protobuf.Method methods = 2; + */ + @java.lang.Override + public java.util.List getMethodsList() { + return java.util.Collections.unmodifiableList( + instance.getMethodsList()); + } + /** + *
+     * The methods of this interface, in unspecified order.
+     * 
+ * + * repeated .google.protobuf.Method methods = 2; + */ + @java.lang.Override + public int getMethodsCount() { + return instance.getMethodsCount(); + }/** + *
+     * The methods of this interface, in unspecified order.
+     * 
+ * + * repeated .google.protobuf.Method methods = 2; + */ + @java.lang.Override + public com.google.protobuf.Method getMethods(int index) { + return instance.getMethods(index); + } + /** + *
+     * The methods of this interface, in unspecified order.
+     * 
+ * + * repeated .google.protobuf.Method methods = 2; + */ + public Builder setMethods( + int index, com.google.protobuf.Method value) { + copyOnWrite(); + instance.setMethods(index, value); + return this; + } + /** + *
+     * The methods of this interface, in unspecified order.
+     * 
+ * + * repeated .google.protobuf.Method methods = 2; + */ + public Builder setMethods( + int index, com.google.protobuf.Method.Builder builderForValue) { + copyOnWrite(); + instance.setMethods(index, + builderForValue.build()); + return this; + } + /** + *
+     * The methods of this interface, in unspecified order.
+     * 
+ * + * repeated .google.protobuf.Method methods = 2; + */ + public Builder addMethods(com.google.protobuf.Method value) { + copyOnWrite(); + instance.addMethods(value); + return this; + } + /** + *
+     * The methods of this interface, in unspecified order.
+     * 
+ * + * repeated .google.protobuf.Method methods = 2; + */ + public Builder addMethods( + int index, com.google.protobuf.Method value) { + copyOnWrite(); + instance.addMethods(index, value); + return this; + } + /** + *
+     * The methods of this interface, in unspecified order.
+     * 
+ * + * repeated .google.protobuf.Method methods = 2; + */ + public Builder addMethods( + com.google.protobuf.Method.Builder builderForValue) { + copyOnWrite(); + instance.addMethods(builderForValue.build()); + return this; + } + /** + *
+     * The methods of this interface, in unspecified order.
+     * 
+ * + * repeated .google.protobuf.Method methods = 2; + */ + public Builder addMethods( + int index, com.google.protobuf.Method.Builder builderForValue) { + copyOnWrite(); + instance.addMethods(index, + builderForValue.build()); + return this; + } + /** + *
+     * The methods of this interface, in unspecified order.
+     * 
+ * + * repeated .google.protobuf.Method methods = 2; + */ + public Builder addAllMethods( + java.lang.Iterable values) { + copyOnWrite(); + instance.addAllMethods(values); + return this; + } + /** + *
+     * The methods of this interface, in unspecified order.
+     * 
+ * + * repeated .google.protobuf.Method methods = 2; + */ + public Builder clearMethods() { + copyOnWrite(); + instance.clearMethods(); + return this; + } + /** + *
+     * The methods of this interface, in unspecified order.
+     * 
+ * + * repeated .google.protobuf.Method methods = 2; + */ + public Builder removeMethods(int index) { + copyOnWrite(); + instance.removeMethods(index); + return this; + } + + /** + *
+     * Any metadata attached to the interface.
+     * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + @java.lang.Override + public java.util.List getOptionsList() { + return java.util.Collections.unmodifiableList( + instance.getOptionsList()); + } + /** + *
+     * Any metadata attached to the interface.
+     * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + @java.lang.Override + public int getOptionsCount() { + return instance.getOptionsCount(); + }/** + *
+     * Any metadata attached to the interface.
+     * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + @java.lang.Override + public com.google.protobuf.Option getOptions(int index) { + return instance.getOptions(index); + } + /** + *
+     * Any metadata attached to the interface.
+     * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + public Builder setOptions( + int index, com.google.protobuf.Option value) { + copyOnWrite(); + instance.setOptions(index, value); + return this; + } + /** + *
+     * Any metadata attached to the interface.
+     * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + public Builder setOptions( + int index, com.google.protobuf.Option.Builder builderForValue) { + copyOnWrite(); + instance.setOptions(index, + builderForValue.build()); + return this; + } + /** + *
+     * Any metadata attached to the interface.
+     * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + public Builder addOptions(com.google.protobuf.Option value) { + copyOnWrite(); + instance.addOptions(value); + return this; + } + /** + *
+     * Any metadata attached to the interface.
+     * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + public Builder addOptions( + int index, com.google.protobuf.Option value) { + copyOnWrite(); + instance.addOptions(index, value); + return this; + } + /** + *
+     * Any metadata attached to the interface.
+     * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + public Builder addOptions( + com.google.protobuf.Option.Builder builderForValue) { + copyOnWrite(); + instance.addOptions(builderForValue.build()); + return this; + } + /** + *
+     * Any metadata attached to the interface.
+     * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + public Builder addOptions( + int index, com.google.protobuf.Option.Builder builderForValue) { + copyOnWrite(); + instance.addOptions(index, + builderForValue.build()); + return this; + } + /** + *
+     * Any metadata attached to the interface.
+     * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + public Builder addAllOptions( + java.lang.Iterable values) { + copyOnWrite(); + instance.addAllOptions(values); + return this; + } + /** + *
+     * Any metadata attached to the interface.
+     * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + public Builder clearOptions() { + copyOnWrite(); + instance.clearOptions(); + return this; + } + /** + *
+     * Any metadata attached to the interface.
+     * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + public Builder removeOptions(int index) { + copyOnWrite(); + instance.removeOptions(index); + return this; + } + + /** + *
+     * A version string for this interface. If specified, must have the form
+     * `major-version.minor-version`, as in `1.10`. If the minor version is
+     * omitted, it defaults to zero. If the entire version field is empty, the
+     * major version is derived from the package name, as outlined below. If the
+     * field is not empty, the version in the package name will be verified to be
+     * consistent with what is provided here.
+     * The versioning schema uses [semantic
+     * versioning](http://semver.org) where the major version number
+     * indicates a breaking change and the minor version an additive,
+     * non-breaking change. Both version numbers are signals to users
+     * what to expect from different versions, and should be carefully
+     * chosen based on the product plan.
+     * The major version is also reflected in the package name of the
+     * interface, which must end in `v<major-version>`, as in
+     * `google.feature.v1`. For major versions 0 and 1, the suffix can
+     * be omitted. Zero major versions must only be used for
+     * experimental, non-GA interfaces.
+     * 
+ * + * string version = 4; + * @return The version. + */ + @java.lang.Override + public java.lang.String getVersion() { + return instance.getVersion(); + } + /** + *
+     * A version string for this interface. If specified, must have the form
+     * `major-version.minor-version`, as in `1.10`. If the minor version is
+     * omitted, it defaults to zero. If the entire version field is empty, the
+     * major version is derived from the package name, as outlined below. If the
+     * field is not empty, the version in the package name will be verified to be
+     * consistent with what is provided here.
+     * The versioning schema uses [semantic
+     * versioning](http://semver.org) where the major version number
+     * indicates a breaking change and the minor version an additive,
+     * non-breaking change. Both version numbers are signals to users
+     * what to expect from different versions, and should be carefully
+     * chosen based on the product plan.
+     * The major version is also reflected in the package name of the
+     * interface, which must end in `v<major-version>`, as in
+     * `google.feature.v1`. For major versions 0 and 1, the suffix can
+     * be omitted. Zero major versions must only be used for
+     * experimental, non-GA interfaces.
+     * 
+ * + * string version = 4; + * @return The bytes for version. + */ + @java.lang.Override + public com.google.protobuf.ByteString + getVersionBytes() { + return instance.getVersionBytes(); + } + /** + *
+     * A version string for this interface. If specified, must have the form
+     * `major-version.minor-version`, as in `1.10`. If the minor version is
+     * omitted, it defaults to zero. If the entire version field is empty, the
+     * major version is derived from the package name, as outlined below. If the
+     * field is not empty, the version in the package name will be verified to be
+     * consistent with what is provided here.
+     * The versioning schema uses [semantic
+     * versioning](http://semver.org) where the major version number
+     * indicates a breaking change and the minor version an additive,
+     * non-breaking change. Both version numbers are signals to users
+     * what to expect from different versions, and should be carefully
+     * chosen based on the product plan.
+     * The major version is also reflected in the package name of the
+     * interface, which must end in `v<major-version>`, as in
+     * `google.feature.v1`. For major versions 0 and 1, the suffix can
+     * be omitted. Zero major versions must only be used for
+     * experimental, non-GA interfaces.
+     * 
+ * + * string version = 4; + * @param value The version to set. + * @return This builder for chaining. + */ + public Builder setVersion( + java.lang.String value) { + copyOnWrite(); + instance.setVersion(value); + return this; + } + /** + *
+     * A version string for this interface. If specified, must have the form
+     * `major-version.minor-version`, as in `1.10`. If the minor version is
+     * omitted, it defaults to zero. If the entire version field is empty, the
+     * major version is derived from the package name, as outlined below. If the
+     * field is not empty, the version in the package name will be verified to be
+     * consistent with what is provided here.
+     * The versioning schema uses [semantic
+     * versioning](http://semver.org) where the major version number
+     * indicates a breaking change and the minor version an additive,
+     * non-breaking change. Both version numbers are signals to users
+     * what to expect from different versions, and should be carefully
+     * chosen based on the product plan.
+     * The major version is also reflected in the package name of the
+     * interface, which must end in `v<major-version>`, as in
+     * `google.feature.v1`. For major versions 0 and 1, the suffix can
+     * be omitted. Zero major versions must only be used for
+     * experimental, non-GA interfaces.
+     * 
+ * + * string version = 4; + * @return This builder for chaining. + */ + public Builder clearVersion() { + copyOnWrite(); + instance.clearVersion(); + return this; + } + /** + *
+     * A version string for this interface. If specified, must have the form
+     * `major-version.minor-version`, as in `1.10`. If the minor version is
+     * omitted, it defaults to zero. If the entire version field is empty, the
+     * major version is derived from the package name, as outlined below. If the
+     * field is not empty, the version in the package name will be verified to be
+     * consistent with what is provided here.
+     * The versioning schema uses [semantic
+     * versioning](http://semver.org) where the major version number
+     * indicates a breaking change and the minor version an additive,
+     * non-breaking change. Both version numbers are signals to users
+     * what to expect from different versions, and should be carefully
+     * chosen based on the product plan.
+     * The major version is also reflected in the package name of the
+     * interface, which must end in `v<major-version>`, as in
+     * `google.feature.v1`. For major versions 0 and 1, the suffix can
+     * be omitted. Zero major versions must only be used for
+     * experimental, non-GA interfaces.
+     * 
+ * + * string version = 4; + * @param value The bytes for version to set. + * @return This builder for chaining. + */ + public Builder setVersionBytes( + com.google.protobuf.ByteString value) { + copyOnWrite(); + instance.setVersionBytes(value); + return this; + } + + /** + *
+     * Source context for the protocol buffer service represented by this
+     * message.
+     * 
+ * + * .google.protobuf.SourceContext source_context = 5; + */ + @java.lang.Override + public boolean hasSourceContext() { + return instance.hasSourceContext(); + } + /** + *
+     * Source context for the protocol buffer service represented by this
+     * message.
+     * 
+ * + * .google.protobuf.SourceContext source_context = 5; + */ + @java.lang.Override + public com.google.protobuf.SourceContext getSourceContext() { + return instance.getSourceContext(); + } + /** + *
+     * Source context for the protocol buffer service represented by this
+     * message.
+     * 
+ * + * .google.protobuf.SourceContext source_context = 5; + */ + public Builder setSourceContext(com.google.protobuf.SourceContext value) { + copyOnWrite(); + instance.setSourceContext(value); + return this; + } + /** + *
+     * Source context for the protocol buffer service represented by this
+     * message.
+     * 
+ * + * .google.protobuf.SourceContext source_context = 5; + */ + public Builder setSourceContext( + com.google.protobuf.SourceContext.Builder builderForValue) { + copyOnWrite(); + instance.setSourceContext(builderForValue.build()); + return this; + } + /** + *
+     * Source context for the protocol buffer service represented by this
+     * message.
+     * 
+ * + * .google.protobuf.SourceContext source_context = 5; + */ + public Builder mergeSourceContext(com.google.protobuf.SourceContext value) { + copyOnWrite(); + instance.mergeSourceContext(value); + return this; + } + /** + *
+     * Source context for the protocol buffer service represented by this
+     * message.
+     * 
+ * + * .google.protobuf.SourceContext source_context = 5; + */ + public Builder clearSourceContext() { copyOnWrite(); + instance.clearSourceContext(); + return this; + } + + /** + *
+     * Included interfaces. See [Mixin][].
+     * 
+ * + * repeated .google.protobuf.Mixin mixins = 6; + */ + @java.lang.Override + public java.util.List getMixinsList() { + return java.util.Collections.unmodifiableList( + instance.getMixinsList()); + } + /** + *
+     * Included interfaces. See [Mixin][].
+     * 
+ * + * repeated .google.protobuf.Mixin mixins = 6; + */ + @java.lang.Override + public int getMixinsCount() { + return instance.getMixinsCount(); + }/** + *
+     * Included interfaces. See [Mixin][].
+     * 
+ * + * repeated .google.protobuf.Mixin mixins = 6; + */ + @java.lang.Override + public com.google.protobuf.Mixin getMixins(int index) { + return instance.getMixins(index); + } + /** + *
+     * Included interfaces. See [Mixin][].
+     * 
+ * + * repeated .google.protobuf.Mixin mixins = 6; + */ + public Builder setMixins( + int index, com.google.protobuf.Mixin value) { + copyOnWrite(); + instance.setMixins(index, value); + return this; + } + /** + *
+     * Included interfaces. See [Mixin][].
+     * 
+ * + * repeated .google.protobuf.Mixin mixins = 6; + */ + public Builder setMixins( + int index, com.google.protobuf.Mixin.Builder builderForValue) { + copyOnWrite(); + instance.setMixins(index, + builderForValue.build()); + return this; + } + /** + *
+     * Included interfaces. See [Mixin][].
+     * 
+ * + * repeated .google.protobuf.Mixin mixins = 6; + */ + public Builder addMixins(com.google.protobuf.Mixin value) { + copyOnWrite(); + instance.addMixins(value); + return this; + } + /** + *
+     * Included interfaces. See [Mixin][].
+     * 
+ * + * repeated .google.protobuf.Mixin mixins = 6; + */ + public Builder addMixins( + int index, com.google.protobuf.Mixin value) { + copyOnWrite(); + instance.addMixins(index, value); + return this; + } + /** + *
+     * Included interfaces. See [Mixin][].
+     * 
+ * + * repeated .google.protobuf.Mixin mixins = 6; + */ + public Builder addMixins( + com.google.protobuf.Mixin.Builder builderForValue) { + copyOnWrite(); + instance.addMixins(builderForValue.build()); + return this; + } + /** + *
+     * Included interfaces. See [Mixin][].
+     * 
+ * + * repeated .google.protobuf.Mixin mixins = 6; + */ + public Builder addMixins( + int index, com.google.protobuf.Mixin.Builder builderForValue) { + copyOnWrite(); + instance.addMixins(index, + builderForValue.build()); + return this; + } + /** + *
+     * Included interfaces. See [Mixin][].
+     * 
+ * + * repeated .google.protobuf.Mixin mixins = 6; + */ + public Builder addAllMixins( + java.lang.Iterable values) { + copyOnWrite(); + instance.addAllMixins(values); + return this; + } + /** + *
+     * Included interfaces. See [Mixin][].
+     * 
+ * + * repeated .google.protobuf.Mixin mixins = 6; + */ + public Builder clearMixins() { + copyOnWrite(); + instance.clearMixins(); + return this; + } + /** + *
+     * Included interfaces. See [Mixin][].
+     * 
+ * + * repeated .google.protobuf.Mixin mixins = 6; + */ + public Builder removeMixins(int index) { + copyOnWrite(); + instance.removeMixins(index); + return this; + } + + /** + *
+     * The source syntax of the service.
+     * 
+ * + * .google.protobuf.Syntax syntax = 7; + * @return The enum numeric value on the wire for syntax. + */ + @java.lang.Override + public int getSyntaxValue() { + return instance.getSyntaxValue(); + } + /** + *
+     * The source syntax of the service.
+     * 
+ * + * .google.protobuf.Syntax syntax = 7; + * @param value The syntax to set. + * @return This builder for chaining. + */ + public Builder setSyntaxValue(int value) { + copyOnWrite(); + instance.setSyntaxValue(value); + return this; + } + /** + *
+     * The source syntax of the service.
+     * 
+ * + * .google.protobuf.Syntax syntax = 7; + * @return The syntax. + */ + @java.lang.Override + public com.google.protobuf.Syntax getSyntax() { + return instance.getSyntax(); + } + /** + *
+     * The source syntax of the service.
+     * 
+ * + * .google.protobuf.Syntax syntax = 7; + * @param value The enum numeric value on the wire for syntax to set. + * @return This builder for chaining. + */ + public Builder setSyntax(com.google.protobuf.Syntax value) { + copyOnWrite(); + instance.setSyntax(value); + return this; + } + /** + *
+     * The source syntax of the service.
+     * 
+ * + * .google.protobuf.Syntax syntax = 7; + * @return This builder for chaining. + */ + public Builder clearSyntax() { + copyOnWrite(); + instance.clearSyntax(); + return this; + } + + // @@protoc_insertion_point(builder_scope:google.protobuf.Api) + } + @java.lang.Override + @java.lang.SuppressWarnings({"unchecked", "fallthrough"}) + protected final java.lang.Object dynamicMethod( + com.google.protobuf.GeneratedMessageLite.MethodToInvoke method, + java.lang.Object arg0, java.lang.Object arg1) { + switch (method) { + case NEW_MUTABLE_INSTANCE: { + return new com.google.protobuf.Api(); + } + case NEW_BUILDER: { + return new Builder(); + } + case BUILD_MESSAGE_INFO: { + java.lang.Object[] objects = new java.lang.Object[] { + "name_", + "methods_", + com.google.protobuf.Method.class, + "options_", + com.google.protobuf.Option.class, + "version_", + "sourceContext_", + "mixins_", + com.google.protobuf.Mixin.class, + "syntax_", + }; + java.lang.String info = + "\u0000\u0007\u0000\u0000\u0001\u0007\u0007\u0000\u0003\u0000\u0001\u0208\u0002\u001b" + + "\u0003\u001b\u0004\u0208\u0005\t\u0006\u001b\u0007\f"; + return newMessageInfo(DEFAULT_INSTANCE, info, objects); + } + // fall through + case GET_DEFAULT_INSTANCE: { + return DEFAULT_INSTANCE; + } + case GET_PARSER: { + com.google.protobuf.Parser parser = PARSER; + if (parser == null) { + synchronized (com.google.protobuf.Api.class) { + parser = PARSER; + if (parser == null) { + parser = + new DefaultInstanceBasedParser( + DEFAULT_INSTANCE); + PARSER = parser; + } + } + } + return parser; + } + case GET_MEMOIZED_IS_INITIALIZED: { + return (byte) 1; + } + case SET_MEMOIZED_IS_INITIALIZED: { + return null; + } + } + throw new UnsupportedOperationException(); + } + + + // @@protoc_insertion_point(class_scope:google.protobuf.Api) + private static final com.google.protobuf.Api DEFAULT_INSTANCE; + static { + Api defaultInstance = new Api(); + // New instances are implicitly immutable so no need to make + // immutable. + DEFAULT_INSTANCE = defaultInstance; + com.google.protobuf.GeneratedMessageLite.registerDefaultInstance( + Api.class, defaultInstance); + } + + public static com.google.protobuf.Api getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static volatile com.google.protobuf.Parser PARSER; + + public static com.google.protobuf.Parser parser() { + return DEFAULT_INSTANCE.getParserForType(); + } +} + diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/ApiOrBuilder.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/ApiOrBuilder.java new file mode 100644 index 0000000000000..e663aa94661a4 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/ApiOrBuilder.java @@ -0,0 +1,201 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/api.proto + +package com.google.protobuf; + +public interface ApiOrBuilder extends + // @@protoc_insertion_point(interface_extends:google.protobuf.Api) + com.google.protobuf.MessageLiteOrBuilder { + + /** + *
+   * The fully qualified name of this interface, including package name
+   * followed by the interface's simple name.
+   * 
+ * + * string name = 1; + * @return The name. + */ + java.lang.String getName(); + /** + *
+   * The fully qualified name of this interface, including package name
+   * followed by the interface's simple name.
+   * 
+ * + * string name = 1; + * @return The bytes for name. + */ + com.google.protobuf.ByteString + getNameBytes(); + + /** + *
+   * The methods of this interface, in unspecified order.
+   * 
+ * + * repeated .google.protobuf.Method methods = 2; + */ + java.util.List + getMethodsList(); + /** + *
+   * The methods of this interface, in unspecified order.
+   * 
+ * + * repeated .google.protobuf.Method methods = 2; + */ + com.google.protobuf.Method getMethods(int index); + /** + *
+   * The methods of this interface, in unspecified order.
+   * 
+ * + * repeated .google.protobuf.Method methods = 2; + */ + int getMethodsCount(); + + /** + *
+   * Any metadata attached to the interface.
+   * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + java.util.List + getOptionsList(); + /** + *
+   * Any metadata attached to the interface.
+   * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + com.google.protobuf.Option getOptions(int index); + /** + *
+   * Any metadata attached to the interface.
+   * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + int getOptionsCount(); + + /** + *
+   * A version string for this interface. If specified, must have the form
+   * `major-version.minor-version`, as in `1.10`. If the minor version is
+   * omitted, it defaults to zero. If the entire version field is empty, the
+   * major version is derived from the package name, as outlined below. If the
+   * field is not empty, the version in the package name will be verified to be
+   * consistent with what is provided here.
+   * The versioning schema uses [semantic
+   * versioning](http://semver.org) where the major version number
+   * indicates a breaking change and the minor version an additive,
+   * non-breaking change. Both version numbers are signals to users
+   * what to expect from different versions, and should be carefully
+   * chosen based on the product plan.
+   * The major version is also reflected in the package name of the
+   * interface, which must end in `v<major-version>`, as in
+   * `google.feature.v1`. For major versions 0 and 1, the suffix can
+   * be omitted. Zero major versions must only be used for
+   * experimental, non-GA interfaces.
+   * 
+ * + * string version = 4; + * @return The version. + */ + java.lang.String getVersion(); + /** + *
+   * A version string for this interface. If specified, must have the form
+   * `major-version.minor-version`, as in `1.10`. If the minor version is
+   * omitted, it defaults to zero. If the entire version field is empty, the
+   * major version is derived from the package name, as outlined below. If the
+   * field is not empty, the version in the package name will be verified to be
+   * consistent with what is provided here.
+   * The versioning schema uses [semantic
+   * versioning](http://semver.org) where the major version number
+   * indicates a breaking change and the minor version an additive,
+   * non-breaking change. Both version numbers are signals to users
+   * what to expect from different versions, and should be carefully
+   * chosen based on the product plan.
+   * The major version is also reflected in the package name of the
+   * interface, which must end in `v<major-version>`, as in
+   * `google.feature.v1`. For major versions 0 and 1, the suffix can
+   * be omitted. Zero major versions must only be used for
+   * experimental, non-GA interfaces.
+   * 
+ * + * string version = 4; + * @return The bytes for version. + */ + com.google.protobuf.ByteString + getVersionBytes(); + + /** + *
+   * Source context for the protocol buffer service represented by this
+   * message.
+   * 
+ * + * .google.protobuf.SourceContext source_context = 5; + * @return Whether the sourceContext field is set. + */ + boolean hasSourceContext(); + /** + *
+   * Source context for the protocol buffer service represented by this
+   * message.
+   * 
+ * + * .google.protobuf.SourceContext source_context = 5; + * @return The sourceContext. + */ + com.google.protobuf.SourceContext getSourceContext(); + + /** + *
+   * Included interfaces. See [Mixin][].
+   * 
+ * + * repeated .google.protobuf.Mixin mixins = 6; + */ + java.util.List + getMixinsList(); + /** + *
+   * Included interfaces. See [Mixin][].
+   * 
+ * + * repeated .google.protobuf.Mixin mixins = 6; + */ + com.google.protobuf.Mixin getMixins(int index); + /** + *
+   * Included interfaces. See [Mixin][].
+   * 
+ * + * repeated .google.protobuf.Mixin mixins = 6; + */ + int getMixinsCount(); + + /** + *
+   * The source syntax of the service.
+   * 
+ * + * .google.protobuf.Syntax syntax = 7; + * @return The enum numeric value on the wire for syntax. + */ + int getSyntaxValue(); + /** + *
+   * The source syntax of the service.
+   * 
+ * + * .google.protobuf.Syntax syntax = 7; + * @return The syntax. + */ + com.google.protobuf.Syntax getSyntax(); +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/ApiProto.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/ApiProto.java new file mode 100644 index 0000000000000..79a9b3da72fd4 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/ApiProto.java @@ -0,0 +1,16 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/api.proto + +package com.google.protobuf; + +public final class ApiProto { + private ApiProto() {} + public static void registerAllExtensions( + com.google.protobuf.ExtensionRegistryLite registry) { + } + + static { + } + + // @@protoc_insertion_point(outer_class_scope) +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/ArrayDecoders.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/ArrayDecoders.java new file mode 100644 index 0000000000000..1217e112e0cef --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/ArrayDecoders.java @@ -0,0 +1,1076 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +import static com.google.protobuf.MessageSchema.getMutableUnknownFields; + +import com.google.protobuf.Internal.ProtobufList; +import java.io.IOException; + +/** + * Helper functions to decode protobuf wire format from a byte array. + * + *

Note that these functions don't do boundary check on the byte array but instead rely on Java + * VM to check it. That means parsing routines utilizing these functions must catch + * IndexOutOfBoundsException and convert it to protobuf's InvalidProtocolBufferException when + * crossing protobuf public API boundaries. + */ +final class ArrayDecoders { + /** + * A helper used to return multiple values in a Java function. Java doesn't natively support + * returning multiple values in a function. Creating a new Object to hold the return values will + * be too expensive. Instead, we pass a Registers instance to functions that want to return + * multiple values and let the function set the return value in this Registers instance instead. + * + *

TODO(xiaofeng): This could be merged into CodedInputStream or CodedInputStreamReader which + * is already being passed through all the parsing routines. + */ + static final class Registers { + public int int1; + public long long1; + public Object object1; + public final ExtensionRegistryLite extensionRegistry; + + Registers() { + this.extensionRegistry = ExtensionRegistryLite.getEmptyRegistry(); + } + + Registers(ExtensionRegistryLite extensionRegistry) { + if (extensionRegistry == null) { + throw new NullPointerException(); + } + this.extensionRegistry = extensionRegistry; + } + } + + /** + * Decodes a varint. Returns the position after the varint. The decoded varint is stored in + * registers.int1. + */ + static int decodeVarint32(byte[] data, int position, Registers registers) { + int value = data[position++]; + if (value >= 0) { + registers.int1 = value; + return position; + } + return decodeVarint32(value, data, position, registers); + } + + /** Like decodeVarint32 except that the first byte is already read. */ + static int decodeVarint32(int firstByte, byte[] data, int position, Registers registers) { + int value = firstByte & 0x7F; + final byte b2 = data[position++]; + if (b2 >= 0) { + registers.int1 = value | ((int) b2 << 7); + return position; + } + value |= (b2 & 0x7F) << 7; + + final byte b3 = data[position++]; + if (b3 >= 0) { + registers.int1 = value | ((int) b3 << 14); + return position; + } + value |= (b3 & 0x7F) << 14; + + final byte b4 = data[position++]; + if (b4 >= 0) { + registers.int1 = value | ((int) b4 << 21); + return position; + } + value |= (b4 & 0x7F) << 21; + + final byte b5 = data[position++]; + if (b5 >= 0) { + registers.int1 = value | ((int) b5 << 28); + return position; + } + value |= (b5 & 0x7F) << 28; + + while (data[position++] < 0) {} + + registers.int1 = value; + return position; + } + + /** + * Decodes a varint. Returns the position after the varint. The decoded varint is stored in + * registers.long1. + */ + static int decodeVarint64(byte[] data, int position, Registers registers) { + long value = data[position++]; + if (value >= 0) { + registers.long1 = value; + return position; + } else { + return decodeVarint64(value, data, position, registers); + } + } + + /** Like decodeVarint64 except that the first byte is already read. */ + static int decodeVarint64(long firstByte, byte[] data, int position, Registers registers) { + long value = firstByte & 0x7F; + byte next = data[position++]; + int shift = 7; + value |= (long) (next & 0x7F) << 7; + while (next < 0) { + next = data[position++]; + shift += 7; + value |= (long) (next & 0x7F) << shift; + } + registers.long1 = value; + return position; + } + + /** Decodes and returns a fixed32 value. */ + static int decodeFixed32(byte[] data, int position) { + return (data[position] & 0xff) + | ((data[position + 1] & 0xff) << 8) + | ((data[position + 2] & 0xff) << 16) + | ((data[position + 3] & 0xff) << 24); + } + + /** Decodes and returns a fixed64 value. */ + static long decodeFixed64(byte[] data, int position) { + return (data[position] & 0xffL) + | ((data[position + 1] & 0xffL) << 8) + | ((data[position + 2] & 0xffL) << 16) + | ((data[position + 3] & 0xffL) << 24) + | ((data[position + 4] & 0xffL) << 32) + | ((data[position + 5] & 0xffL) << 40) + | ((data[position + 6] & 0xffL) << 48) + | ((data[position + 7] & 0xffL) << 56); + } + + /** Decodes and returns a double value. */ + static double decodeDouble(byte[] data, int position) { + return Double.longBitsToDouble(decodeFixed64(data, position)); + } + + /** Decodes and returns a float value. */ + static float decodeFloat(byte[] data, int position) { + return Float.intBitsToFloat(decodeFixed32(data, position)); + } + + /** Decodes a string value. */ + static int decodeString(byte[] data, int position, Registers registers) + throws InvalidProtocolBufferException { + position = decodeVarint32(data, position, registers); + final int length = registers.int1; + if (length < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } else if (length == 0) { + registers.object1 = ""; + return position; + } else { + registers.object1 = new String(data, position, length, Internal.UTF_8); + return position + length; + } + } + + /** Decodes a string value with utf8 check. */ + static int decodeStringRequireUtf8(byte[] data, int position, Registers registers) + throws InvalidProtocolBufferException { + position = decodeVarint32(data, position, registers); + final int length = registers.int1; + if (length < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } else if (length == 0) { + registers.object1 = ""; + return position; + } else { + registers.object1 = Utf8.decodeUtf8(data, position, length); + return position + length; + } + } + + /** Decodes a bytes value. */ + static int decodeBytes(byte[] data, int position, Registers registers) + throws InvalidProtocolBufferException { + position = decodeVarint32(data, position, registers); + final int length = registers.int1; + if (length < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } else if (length > data.length - position) { + throw InvalidProtocolBufferException.truncatedMessage(); + } else if (length == 0) { + registers.object1 = ByteString.EMPTY; + return position; + } else { + registers.object1 = ByteString.copyFrom(data, position, length); + return position + length; + } + } + + /** Decodes a message value. */ + @SuppressWarnings({"unchecked", "rawtypes"}) + static int decodeMessageField( + Schema schema, byte[] data, int position, int limit, Registers registers) throws IOException { + int length = data[position++]; + if (length < 0) { + position = decodeVarint32(length, data, position, registers); + length = registers.int1; + } + if (length < 0 || length > limit - position) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + Object result = schema.newInstance(); + schema.mergeFrom(result, data, position, position + length, registers); + schema.makeImmutable(result); + registers.object1 = result; + return position + length; + } + + /** Decodes a group value. */ + @SuppressWarnings({"unchecked", "rawtypes"}) + static int decodeGroupField( + Schema schema, byte[] data, int position, int limit, int endGroup, Registers registers) + throws IOException { + // A group field must has a MessageSchema (the only other subclass of Schema is MessageSetSchema + // and it can't be used in group fields). + final MessageSchema messageSchema = (MessageSchema) schema; + Object result = messageSchema.newInstance(); + // It's OK to directly use parseProto2Message since proto3 doesn't have group. + final int endPosition = + messageSchema.parseProto2Message(result, data, position, limit, endGroup, registers); + messageSchema.makeImmutable(result); + registers.object1 = result; + return endPosition; + } + + /** Decodes a repeated 32-bit varint field. Returns the position after all read values. */ + static int decodeVarint32List( + int tag, byte[] data, int position, int limit, ProtobufList list, Registers registers) { + final IntArrayList output = (IntArrayList) list; + position = decodeVarint32(data, position, registers); + output.addInt(registers.int1); + while (position < limit) { + int nextPosition = decodeVarint32(data, position, registers); + if (tag != registers.int1) { + break; + } + position = decodeVarint32(data, nextPosition, registers); + output.addInt(registers.int1); + } + return position; + } + + /** Decodes a repeated 64-bit varint field. Returns the position after all read values. */ + static int decodeVarint64List( + int tag, byte[] data, int position, int limit, ProtobufList list, Registers registers) { + final LongArrayList output = (LongArrayList) list; + position = decodeVarint64(data, position, registers); + output.addLong(registers.long1); + while (position < limit) { + int nextPosition = decodeVarint32(data, position, registers); + if (tag != registers.int1) { + break; + } + position = decodeVarint64(data, nextPosition, registers); + output.addLong(registers.long1); + } + return position; + } + + /** Decodes a repeated fixed32 field. Returns the position after all read values. */ + static int decodeFixed32List( + int tag, byte[] data, int position, int limit, ProtobufList list, Registers registers) { + final IntArrayList output = (IntArrayList) list; + output.addInt(decodeFixed32(data, position)); + position += 4; + while (position < limit) { + int nextPosition = decodeVarint32(data, position, registers); + if (tag != registers.int1) { + break; + } + output.addInt(decodeFixed32(data, nextPosition)); + position = nextPosition + 4; + } + return position; + } + + /** Decodes a repeated fixed64 field. Returns the position after all read values. */ + static int decodeFixed64List( + int tag, byte[] data, int position, int limit, ProtobufList list, Registers registers) { + final LongArrayList output = (LongArrayList) list; + output.addLong(decodeFixed64(data, position)); + position += 8; + while (position < limit) { + int nextPosition = decodeVarint32(data, position, registers); + if (tag != registers.int1) { + break; + } + output.addLong(decodeFixed64(data, nextPosition)); + position = nextPosition + 8; + } + return position; + } + + /** Decodes a repeated float field. Returns the position after all read values. */ + static int decodeFloatList( + int tag, byte[] data, int position, int limit, ProtobufList list, Registers registers) { + final FloatArrayList output = (FloatArrayList) list; + output.addFloat(decodeFloat(data, position)); + position += 4; + while (position < limit) { + int nextPosition = decodeVarint32(data, position, registers); + if (tag != registers.int1) { + break; + } + output.addFloat(decodeFloat(data, nextPosition)); + position = nextPosition + 4; + } + return position; + } + + /** Decodes a repeated double field. Returns the position after all read values. */ + static int decodeDoubleList( + int tag, byte[] data, int position, int limit, ProtobufList list, Registers registers) { + final DoubleArrayList output = (DoubleArrayList) list; + output.addDouble(decodeDouble(data, position)); + position += 8; + while (position < limit) { + int nextPosition = decodeVarint32(data, position, registers); + if (tag != registers.int1) { + break; + } + output.addDouble(decodeDouble(data, nextPosition)); + position = nextPosition + 8; + } + return position; + } + + /** Decodes a repeated boolean field. Returns the position after all read values. */ + static int decodeBoolList( + int tag, byte[] data, int position, int limit, ProtobufList list, Registers registers) { + final BooleanArrayList output = (BooleanArrayList) list; + position = decodeVarint64(data, position, registers); + output.addBoolean(registers.long1 != 0); + while (position < limit) { + int nextPosition = decodeVarint32(data, position, registers); + if (tag != registers.int1) { + break; + } + position = decodeVarint64(data, nextPosition, registers); + output.addBoolean(registers.long1 != 0); + } + return position; + } + + /** Decodes a repeated sint32 field. Returns the position after all read values. */ + static int decodeSInt32List( + int tag, byte[] data, int position, int limit, ProtobufList list, Registers registers) { + final IntArrayList output = (IntArrayList) list; + position = decodeVarint32(data, position, registers); + output.addInt(CodedInputStream.decodeZigZag32(registers.int1)); + while (position < limit) { + int nextPosition = decodeVarint32(data, position, registers); + if (tag != registers.int1) { + break; + } + position = decodeVarint32(data, nextPosition, registers); + output.addInt(CodedInputStream.decodeZigZag32(registers.int1)); + } + return position; + } + + /** Decodes a repeated sint64 field. Returns the position after all read values. */ + static int decodeSInt64List( + int tag, byte[] data, int position, int limit, ProtobufList list, Registers registers) { + final LongArrayList output = (LongArrayList) list; + position = decodeVarint64(data, position, registers); + output.addLong(CodedInputStream.decodeZigZag64(registers.long1)); + while (position < limit) { + int nextPosition = decodeVarint32(data, position, registers); + if (tag != registers.int1) { + break; + } + position = decodeVarint64(data, nextPosition, registers); + output.addLong(CodedInputStream.decodeZigZag64(registers.long1)); + } + return position; + } + + /** Decodes a packed 32-bit varint field. Returns the position after all read values. */ + static int decodePackedVarint32List( + byte[] data, int position, ProtobufList list, Registers registers) throws IOException { + final IntArrayList output = (IntArrayList) list; + position = decodeVarint32(data, position, registers); + final int fieldLimit = position + registers.int1; + while (position < fieldLimit) { + position = decodeVarint32(data, position, registers); + output.addInt(registers.int1); + } + if (position != fieldLimit) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + return position; + } + + /** Decodes a packed 64-bit varint field. Returns the position after all read values. */ + static int decodePackedVarint64List( + byte[] data, int position, ProtobufList list, Registers registers) throws IOException { + final LongArrayList output = (LongArrayList) list; + position = decodeVarint32(data, position, registers); + final int fieldLimit = position + registers.int1; + while (position < fieldLimit) { + position = decodeVarint64(data, position, registers); + output.addLong(registers.long1); + } + if (position != fieldLimit) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + return position; + } + + /** Decodes a packed fixed32 field. Returns the position after all read values. */ + static int decodePackedFixed32List( + byte[] data, int position, ProtobufList list, Registers registers) throws IOException { + final IntArrayList output = (IntArrayList) list; + position = decodeVarint32(data, position, registers); + final int fieldLimit = position + registers.int1; + while (position < fieldLimit) { + output.addInt(decodeFixed32(data, position)); + position += 4; + } + if (position != fieldLimit) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + return position; + } + + /** Decodes a packed fixed64 field. Returns the position after all read values. */ + static int decodePackedFixed64List( + byte[] data, int position, ProtobufList list, Registers registers) throws IOException { + final LongArrayList output = (LongArrayList) list; + position = decodeVarint32(data, position, registers); + final int fieldLimit = position + registers.int1; + while (position < fieldLimit) { + output.addLong(decodeFixed64(data, position)); + position += 8; + } + if (position != fieldLimit) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + return position; + } + + /** Decodes a packed float field. Returns the position after all read values. */ + static int decodePackedFloatList( + byte[] data, int position, ProtobufList list, Registers registers) throws IOException { + final FloatArrayList output = (FloatArrayList) list; + position = decodeVarint32(data, position, registers); + final int fieldLimit = position + registers.int1; + while (position < fieldLimit) { + output.addFloat(decodeFloat(data, position)); + position += 4; + } + if (position != fieldLimit) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + return position; + } + + /** Decodes a packed double field. Returns the position after all read values. */ + static int decodePackedDoubleList( + byte[] data, int position, ProtobufList list, Registers registers) throws IOException { + final DoubleArrayList output = (DoubleArrayList) list; + position = decodeVarint32(data, position, registers); + final int fieldLimit = position + registers.int1; + while (position < fieldLimit) { + output.addDouble(decodeDouble(data, position)); + position += 8; + } + if (position != fieldLimit) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + return position; + } + + /** Decodes a packed boolean field. Returns the position after all read values. */ + static int decodePackedBoolList( + byte[] data, int position, ProtobufList list, Registers registers) throws IOException { + final BooleanArrayList output = (BooleanArrayList) list; + position = decodeVarint32(data, position, registers); + final int fieldLimit = position + registers.int1; + while (position < fieldLimit) { + position = decodeVarint64(data, position, registers); + output.addBoolean(registers.long1 != 0); + } + if (position != fieldLimit) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + return position; + } + + /** Decodes a packed sint32 field. Returns the position after all read values. */ + static int decodePackedSInt32List( + byte[] data, int position, ProtobufList list, Registers registers) throws IOException { + final IntArrayList output = (IntArrayList) list; + position = decodeVarint32(data, position, registers); + final int fieldLimit = position + registers.int1; + while (position < fieldLimit) { + position = decodeVarint32(data, position, registers); + output.addInt(CodedInputStream.decodeZigZag32(registers.int1)); + } + if (position != fieldLimit) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + return position; + } + + /** Decodes a packed sint64 field. Returns the position after all read values. */ + @SuppressWarnings("unchecked") + static int decodePackedSInt64List( + byte[] data, int position, ProtobufList list, Registers registers) throws IOException { + final LongArrayList output = (LongArrayList) list; + position = decodeVarint32(data, position, registers); + final int fieldLimit = position + registers.int1; + while (position < fieldLimit) { + position = decodeVarint64(data, position, registers); + output.addLong(CodedInputStream.decodeZigZag64(registers.long1)); + } + if (position != fieldLimit) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + return position; + } + + /** Decodes a repeated string field. Returns the position after all read values. */ + @SuppressWarnings("unchecked") + static int decodeStringList( + int tag, byte[] data, int position, int limit, ProtobufList list, Registers registers) + throws InvalidProtocolBufferException { + final ProtobufList output = (ProtobufList) list; + position = decodeVarint32(data, position, registers); + final int length = registers.int1; + if (length < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } else if (length == 0) { + output.add(""); + } else { + String value = new String(data, position, length, Internal.UTF_8); + output.add(value); + position += length; + } + while (position < limit) { + int nextPosition = decodeVarint32(data, position, registers); + if (tag != registers.int1) { + break; + } + position = decodeVarint32(data, nextPosition, registers); + final int nextLength = registers.int1; + if (nextLength < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } else if (nextLength == 0) { + output.add(""); + } else { + String value = new String(data, position, nextLength, Internal.UTF_8); + output.add(value); + position += nextLength; + } + } + return position; + } + + /** + * Decodes a repeated string field with utf8 check. Returns the position after all read values. + */ + @SuppressWarnings("unchecked") + static int decodeStringListRequireUtf8( + int tag, byte[] data, int position, int limit, ProtobufList list, Registers registers) + throws InvalidProtocolBufferException { + final ProtobufList output = (ProtobufList) list; + position = decodeVarint32(data, position, registers); + final int length = registers.int1; + if (length < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } else if (length == 0) { + output.add(""); + } else { + if (!Utf8.isValidUtf8(data, position, position + length)) { + throw InvalidProtocolBufferException.invalidUtf8(); + } + String value = new String(data, position, length, Internal.UTF_8); + output.add(value); + position += length; + } + while (position < limit) { + int nextPosition = decodeVarint32(data, position, registers); + if (tag != registers.int1) { + break; + } + position = decodeVarint32(data, nextPosition, registers); + final int nextLength = registers.int1; + if (nextLength < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } else if (nextLength == 0) { + output.add(""); + } else { + if (!Utf8.isValidUtf8(data, position, position + nextLength)) { + throw InvalidProtocolBufferException.invalidUtf8(); + } + String value = new String(data, position, nextLength, Internal.UTF_8); + output.add(value); + position += nextLength; + } + } + return position; + } + + /** Decodes a repeated bytes field. Returns the position after all read values. */ + @SuppressWarnings("unchecked") + static int decodeBytesList( + int tag, byte[] data, int position, int limit, ProtobufList list, Registers registers) + throws InvalidProtocolBufferException { + final ProtobufList output = (ProtobufList) list; + position = decodeVarint32(data, position, registers); + final int length = registers.int1; + if (length < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } else if (length > data.length - position) { + throw InvalidProtocolBufferException.truncatedMessage(); + } else if (length == 0) { + output.add(ByteString.EMPTY); + } else { + output.add(ByteString.copyFrom(data, position, length)); + position += length; + } + while (position < limit) { + int nextPosition = decodeVarint32(data, position, registers); + if (tag != registers.int1) { + break; + } + position = decodeVarint32(data, nextPosition, registers); + final int nextLength = registers.int1; + if (nextLength < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } else if (nextLength > data.length - position) { + throw InvalidProtocolBufferException.truncatedMessage(); + } else if (nextLength == 0) { + output.add(ByteString.EMPTY); + } else { + output.add(ByteString.copyFrom(data, position, nextLength)); + position += nextLength; + } + } + return position; + } + + /** + * Decodes a repeated message field + * + * @return The position of after read all messages + */ + @SuppressWarnings({"unchecked"}) + static int decodeMessageList( + Schema schema, + int tag, + byte[] data, + int position, + int limit, + ProtobufList list, + Registers registers) + throws IOException { + final ProtobufList output = (ProtobufList) list; + position = decodeMessageField(schema, data, position, limit, registers); + output.add(registers.object1); + while (position < limit) { + int nextPosition = decodeVarint32(data, position, registers); + if (tag != registers.int1) { + break; + } + position = decodeMessageField(schema, data, nextPosition, limit, registers); + output.add(registers.object1); + } + return position; + } + + /** + * Decodes a repeated group field + * + * @return The position of after read all groups + */ + @SuppressWarnings({"unchecked", "rawtypes"}) + static int decodeGroupList( + Schema schema, + int tag, + byte[] data, + int position, + int limit, + ProtobufList list, + Registers registers) + throws IOException { + final ProtobufList output = (ProtobufList) list; + final int endgroup = (tag & ~0x7) | WireFormat.WIRETYPE_END_GROUP; + position = decodeGroupField(schema, data, position, limit, endgroup, registers); + output.add(registers.object1); + while (position < limit) { + int nextPosition = decodeVarint32(data, position, registers); + if (tag != registers.int1) { + break; + } + position = decodeGroupField(schema, data, nextPosition, limit, endgroup, registers); + output.add(registers.object1); + } + return position; + } + + static int decodeExtensionOrUnknownField( + int tag, byte[] data, int position, int limit, + Object message, + MessageLite defaultInstance, + UnknownFieldSchema unknownFieldSchema, + Registers registers) + throws IOException { + final int number = tag >>> 3; + GeneratedMessageLite.GeneratedExtension extension = + registers.extensionRegistry.findLiteExtensionByNumber(defaultInstance, number); + if (extension == null) { + return decodeUnknownField( + tag, data, position, limit, getMutableUnknownFields(message), registers); + } else { + ((GeneratedMessageLite.ExtendableMessage) message).ensureExtensionsAreMutable(); + return decodeExtension( + tag, data, position, limit, (GeneratedMessageLite.ExtendableMessage) message, + extension, unknownFieldSchema, registers); + } + } + + static int decodeExtension( + int tag, + byte[] data, + int position, + int limit, + GeneratedMessageLite.ExtendableMessage message, + GeneratedMessageLite.GeneratedExtension extension, + UnknownFieldSchema unknownFieldSchema, + Registers registers) + throws IOException { + final FieldSet extensions = message.extensions; + final int fieldNumber = tag >>> 3; + if (extension.descriptor.isRepeated() && extension.descriptor.isPacked()) { + switch (extension.getLiteType()) { + case DOUBLE: + { + DoubleArrayList list = new DoubleArrayList(); + position = decodePackedDoubleList(data, position, list, registers); + extensions.setField(extension.descriptor, list); + break; + } + case FLOAT: + { + FloatArrayList list = new FloatArrayList(); + position = decodePackedFloatList(data, position, list, registers); + extensions.setField(extension.descriptor, list); + break; + } + case INT64: + case UINT64: + { + LongArrayList list = new LongArrayList(); + position = decodePackedVarint64List(data, position, list, registers); + extensions.setField(extension.descriptor, list); + break; + } + case INT32: + case UINT32: + { + IntArrayList list = new IntArrayList(); + position = decodePackedVarint32List(data, position, list, registers); + extensions.setField(extension.descriptor, list); + break; + } + case FIXED64: + case SFIXED64: + { + LongArrayList list = new LongArrayList(); + position = decodePackedFixed64List(data, position, list, registers); + extensions.setField(extension.descriptor, list); + break; + } + case FIXED32: + case SFIXED32: + { + IntArrayList list = new IntArrayList(); + position = decodePackedFixed32List(data, position, list, registers); + extensions.setField(extension.descriptor, list); + break; + } + case BOOL: + { + BooleanArrayList list = new BooleanArrayList(); + position = decodePackedBoolList(data, position, list, registers); + extensions.setField(extension.descriptor, list); + break; + } + case SINT32: + { + IntArrayList list = new IntArrayList(); + position = decodePackedSInt32List(data, position, list, registers); + extensions.setField(extension.descriptor, list); + break; + } + case SINT64: + { + LongArrayList list = new LongArrayList(); + position = decodePackedSInt64List(data, position, list, registers); + extensions.setField(extension.descriptor, list); + break; + } + case ENUM: + { + IntArrayList list = new IntArrayList(); + position = decodePackedVarint32List(data, position, list, registers); + UnknownFieldSetLite unknownFields = message.unknownFields; + if (unknownFields == UnknownFieldSetLite.getDefaultInstance()) { + unknownFields = null; + } + unknownFields = + SchemaUtil.filterUnknownEnumList( + fieldNumber, + list, + extension.descriptor.getEnumType(), + unknownFields, + unknownFieldSchema); + if (unknownFields != null) { + message.unknownFields = unknownFields; + } + extensions.setField(extension.descriptor, list); + break; + } + default: + throw new IllegalStateException( + "Type cannot be packed: " + extension.descriptor.getLiteType()); + } + } else { + Object value = null; + // Enum is a special case because unknown enum values will be put into UnknownFieldSetLite. + if (extension.getLiteType() == WireFormat.FieldType.ENUM) { + position = decodeVarint32(data, position, registers); + Object enumValue = extension.descriptor.getEnumType().findValueByNumber(registers.int1); + if (enumValue == null) { + UnknownFieldSetLite unknownFields = ((GeneratedMessageLite) message).unknownFields; + if (unknownFields == UnknownFieldSetLite.getDefaultInstance()) { + unknownFields = UnknownFieldSetLite.newInstance(); + ((GeneratedMessageLite) message).unknownFields = unknownFields; + } + SchemaUtil.storeUnknownEnum( + fieldNumber, registers.int1, unknownFields, unknownFieldSchema); + return position; + } + // Note, we store the integer value instead of the actual enum object in FieldSet. + // This is also different from full-runtime where we store EnumValueDescriptor. + value = registers.int1; + } else { + switch (extension.getLiteType()) { + case DOUBLE: + value = decodeDouble(data, position); + position += 8; + break; + case FLOAT: + value = decodeFloat(data, position); + position += 4; + break; + case INT64: + case UINT64: + position = decodeVarint64(data, position, registers); + value = registers.long1; + break; + case INT32: + case UINT32: + position = decodeVarint32(data, position, registers); + value = registers.int1; + break; + case FIXED64: + case SFIXED64: + value = decodeFixed64(data, position); + position += 8; + break; + case FIXED32: + case SFIXED32: + value = decodeFixed32(data, position); + position += 4; + break; + case BOOL: + position = decodeVarint64(data, position, registers); + value = (registers.long1 != 0); + break; + case BYTES: + position = decodeBytes(data, position, registers); + value = registers.object1; + break; + case SINT32: + position = decodeVarint32(data, position, registers); + value = CodedInputStream.decodeZigZag32(registers.int1); + break; + case SINT64: + position = decodeVarint64(data, position, registers); + value = CodedInputStream.decodeZigZag64(registers.long1); + break; + case STRING: + position = decodeString(data, position, registers); + value = registers.object1; + break; + case GROUP: + final int endTag = (fieldNumber << 3) | WireFormat.WIRETYPE_END_GROUP; + position = decodeGroupField( + Protobuf.getInstance().schemaFor(extension.getMessageDefaultInstance().getClass()), + data, position, limit, endTag, registers); + value = registers.object1; + break; + + case MESSAGE: + position = decodeMessageField( + Protobuf.getInstance().schemaFor(extension.getMessageDefaultInstance().getClass()), + data, position, limit, registers); + value = registers.object1; + break; + + case ENUM: + throw new IllegalStateException("Shouldn't reach here."); + } + } + if (extension.isRepeated()) { + extensions.addRepeatedField(extension.descriptor, value); + } else { + switch (extension.getLiteType()) { + case MESSAGE: + case GROUP: + Object oldValue = extensions.getField(extension.descriptor); + if (oldValue != null) { + value = Internal.mergeMessage(oldValue, value); + } + break; + default: + break; + } + extensions.setField(extension.descriptor, value); + } + } + return position; + } + + /** Decodes an unknown field. */ + static int decodeUnknownField( + int tag, + byte[] data, + int position, + int limit, + UnknownFieldSetLite unknownFields, + Registers registers) + throws InvalidProtocolBufferException { + if (WireFormat.getTagFieldNumber(tag) == 0) { + throw InvalidProtocolBufferException.invalidTag(); + } + switch (WireFormat.getTagWireType(tag)) { + case WireFormat.WIRETYPE_VARINT: + position = decodeVarint64(data, position, registers); + unknownFields.storeField(tag, registers.long1); + return position; + case WireFormat.WIRETYPE_FIXED32: + unknownFields.storeField(tag, decodeFixed32(data, position)); + return position + 4; + case WireFormat.WIRETYPE_FIXED64: + unknownFields.storeField(tag, decodeFixed64(data, position)); + return position + 8; + case WireFormat.WIRETYPE_LENGTH_DELIMITED: + position = decodeVarint32(data, position, registers); + final int length = registers.int1; + if (length < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } else if (length > data.length - position) { + throw InvalidProtocolBufferException.truncatedMessage(); + } else if (length == 0) { + unknownFields.storeField(tag, ByteString.EMPTY); + } else { + unknownFields.storeField(tag, ByteString.copyFrom(data, position, length)); + } + return position + length; + case WireFormat.WIRETYPE_START_GROUP: + final UnknownFieldSetLite child = UnknownFieldSetLite.newInstance(); + final int endGroup = (tag & ~0x7) | WireFormat.WIRETYPE_END_GROUP; + int lastTag = 0; + while (position < limit) { + position = decodeVarint32(data, position, registers); + lastTag = registers.int1; + if (lastTag == endGroup) { + break; + } + position = decodeUnknownField(lastTag, data, position, limit, child, registers); + } + if (position > limit || lastTag != endGroup) { + throw InvalidProtocolBufferException.parseFailure(); + } + unknownFields.storeField(tag, child); + return position; + default: + throw InvalidProtocolBufferException.invalidTag(); + } + } + + /** Skips an unknown field. */ + static int skipField(int tag, byte[] data, int position, int limit, Registers registers) + throws InvalidProtocolBufferException { + if (WireFormat.getTagFieldNumber(tag) == 0) { + throw InvalidProtocolBufferException.invalidTag(); + } + switch (WireFormat.getTagWireType(tag)) { + case WireFormat.WIRETYPE_VARINT: + position = decodeVarint64(data, position, registers); + return position; + case WireFormat.WIRETYPE_FIXED32: + return position + 4; + case WireFormat.WIRETYPE_FIXED64: + return position + 8; + case WireFormat.WIRETYPE_LENGTH_DELIMITED: + position = decodeVarint32(data, position, registers); + return position + registers.int1; + case WireFormat.WIRETYPE_START_GROUP: + final int endGroup = (tag & ~0x7) | WireFormat.WIRETYPE_END_GROUP; + int lastTag = 0; + while (position < limit) { + position = decodeVarint32(data, position, registers); + lastTag = registers.int1; + if (lastTag == endGroup) { + break; + } + position = skipField(lastTag, data, position, limit, registers); + } + if (position > limit || lastTag != endGroup) { + throw InvalidProtocolBufferException.parseFailure(); + } + return position; + default: + throw InvalidProtocolBufferException.invalidTag(); + } + } +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/BinaryReader.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/BinaryReader.java new file mode 100644 index 0000000000000..d64574c2a581e --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/BinaryReader.java @@ -0,0 +1,1729 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +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.WIRETYPE_END_GROUP; +import static com.google.protobuf.WireFormat.WIRETYPE_FIXED32; +import static com.google.protobuf.WireFormat.WIRETYPE_FIXED64; +import static com.google.protobuf.WireFormat.WIRETYPE_LENGTH_DELIMITED; +import static com.google.protobuf.WireFormat.WIRETYPE_START_GROUP; +import static com.google.protobuf.WireFormat.WIRETYPE_VARINT; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.List; +import java.util.Map; + +/** + * A {@link Reader} that reads from a buffer containing a message serialized with the binary + * protocol. + */ +@ExperimentalApi +abstract class BinaryReader implements Reader { + private static final int FIXED32_MULTIPLE_MASK = FIXED32_SIZE - 1; + private static final int FIXED64_MULTIPLE_MASK = FIXED64_SIZE - 1; + + /** + * Creates a new reader using the given {@code buffer} as input. + * + * @param buffer the input buffer. The buffer (including position, limit, etc.) will not be + * modified. To increment the buffer position after the read completes, use the value returned + * by {@link #getTotalBytesRead()}. + * @param bufferIsImmutable if {@code true} the reader assumes that the content of {@code buffer} + * will never change and any allocated {@link ByteString} instances will by directly wrap + * slices of {@code buffer}. + * @return the reader + */ + public static BinaryReader newInstance(ByteBuffer buffer, boolean bufferIsImmutable) { + if (buffer.hasArray()) { + // TODO(nathanmittler): Add support for unsafe operations. + return new SafeHeapReader(buffer, bufferIsImmutable); + } + // TODO(nathanmittler): Add support for direct buffers + throw new IllegalArgumentException("Direct buffers not yet supported"); + } + + /** Only allow subclassing for inner classes. */ + private BinaryReader() {} + + /** Returns the total number of bytes read so far from the input buffer. */ + public abstract int getTotalBytesRead(); + + @Override + public boolean shouldDiscardUnknownFields() { + return false; + } + + /** + * A {@link BinaryReader} implementation that operates on a heap {@link ByteBuffer}. Uses only + * safe operations on the underlying array. + */ + private static final class SafeHeapReader extends BinaryReader { + private final boolean bufferIsImmutable; + private final byte[] buffer; + private int pos; + private final int initialPos; + private int limit; + private int tag; + private int endGroupTag; + + public SafeHeapReader(ByteBuffer bytebuf, boolean bufferIsImmutable) { + this.bufferIsImmutable = bufferIsImmutable; + buffer = bytebuf.array(); + initialPos = pos = bytebuf.arrayOffset() + bytebuf.position(); + limit = bytebuf.arrayOffset() + bytebuf.limit(); + } + + private boolean isAtEnd() { + return pos == limit; + } + + @Override + public int getTotalBytesRead() { + return pos - initialPos; + } + + @Override + public int getFieldNumber() throws IOException { + if (isAtEnd()) { + return Reader.READ_DONE; + } + tag = readVarint32(); + if (tag == endGroupTag) { + return Reader.READ_DONE; + } + return WireFormat.getTagFieldNumber(tag); + } + + @Override + public int getTag() { + return tag; + } + + @Override + public boolean skipField() throws IOException { + if (isAtEnd() || tag == endGroupTag) { + return false; + } + + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_VARINT: + skipVarint(); + return true; + case WIRETYPE_FIXED64: + skipBytes(FIXED64_SIZE); + return true; + case WIRETYPE_LENGTH_DELIMITED: + skipBytes(readVarint32()); + return true; + case WIRETYPE_FIXED32: + skipBytes(FIXED32_SIZE); + return true; + case WIRETYPE_START_GROUP: + skipGroup(); + return true; + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + + @Override + public double readDouble() throws IOException { + requireWireType(WIRETYPE_FIXED64); + return Double.longBitsToDouble(readLittleEndian64()); + } + + @Override + public float readFloat() throws IOException { + requireWireType(WIRETYPE_FIXED32); + return Float.intBitsToFloat(readLittleEndian32()); + } + + @Override + public long readUInt64() throws IOException { + requireWireType(WIRETYPE_VARINT); + return readVarint64(); + } + + @Override + public long readInt64() throws IOException { + requireWireType(WIRETYPE_VARINT); + return readVarint64(); + } + + @Override + public int readInt32() throws IOException { + requireWireType(WIRETYPE_VARINT); + return readVarint32(); + } + + @Override + public long readFixed64() throws IOException { + requireWireType(WIRETYPE_FIXED64); + return readLittleEndian64(); + } + + @Override + public int readFixed32() throws IOException { + requireWireType(WIRETYPE_FIXED32); + return readLittleEndian32(); + } + + @Override + public boolean readBool() throws IOException { + requireWireType(WIRETYPE_VARINT); + return readVarint32() != 0; + } + + @Override + public String readString() throws IOException { + return readStringInternal(false); + } + + @Override + public String readStringRequireUtf8() throws IOException { + return readStringInternal(true); + } + + public String readStringInternal(boolean requireUtf8) throws IOException { + requireWireType(WIRETYPE_LENGTH_DELIMITED); + final int size = readVarint32(); + if (size == 0) { + return ""; + } + + requireBytes(size); + if (requireUtf8 && !Utf8.isValidUtf8(buffer, pos, pos + size)) { + throw InvalidProtocolBufferException.invalidUtf8(); + } + String result = new String(buffer, pos, size, Internal.UTF_8); + pos += size; + return result; + } + + @Override + public T readMessage(Class clazz, ExtensionRegistryLite extensionRegistry) + throws IOException { + requireWireType(WIRETYPE_LENGTH_DELIMITED); + return readMessage(Protobuf.getInstance().schemaFor(clazz), extensionRegistry); + } + + @Override + public T readMessageBySchemaWithCheck( + Schema schema, ExtensionRegistryLite extensionRegistry) throws IOException { + requireWireType(WIRETYPE_LENGTH_DELIMITED); + return readMessage(schema, extensionRegistry); + } + + private T readMessage(Schema schema, ExtensionRegistryLite extensionRegistry) + throws IOException { + int size = readVarint32(); + requireBytes(size); + + // Update the limit. + int prevLimit = limit; + int newLimit = pos + size; + limit = newLimit; + + try { + // Allocate and read the message. + T message = schema.newInstance(); + schema.mergeFrom(message, this, extensionRegistry); + schema.makeImmutable(message); + + if (pos != newLimit) { + throw InvalidProtocolBufferException.parseFailure(); + } + return message; + } finally { + // Restore the limit. + limit = prevLimit; + } + } + + @Override + public T readGroup(Class clazz, ExtensionRegistryLite extensionRegistry) + throws IOException { + requireWireType(WIRETYPE_START_GROUP); + return readGroup(Protobuf.getInstance().schemaFor(clazz), extensionRegistry); + } + + @Override + public T readGroupBySchemaWithCheck( + Schema schema, ExtensionRegistryLite extensionRegistry) throws IOException { + requireWireType(WIRETYPE_START_GROUP); + return readGroup(schema, extensionRegistry); + } + + private T readGroup(Schema schema, ExtensionRegistryLite extensionRegistry) + throws IOException { + int prevEndGroupTag = endGroupTag; + endGroupTag = WireFormat.makeTag(WireFormat.getTagFieldNumber(tag), WIRETYPE_END_GROUP); + + try { + // Allocate and read the message. + T message = schema.newInstance(); + schema.mergeFrom(message, this, extensionRegistry); + schema.makeImmutable(message); + + if (tag != endGroupTag) { + throw InvalidProtocolBufferException.parseFailure(); + } + return message; + } finally { + // Restore the old end group tag. + endGroupTag = prevEndGroupTag; + } + } + + @Override + public ByteString readBytes() throws IOException { + requireWireType(WIRETYPE_LENGTH_DELIMITED); + int size = readVarint32(); + if (size == 0) { + return ByteString.EMPTY; + } + + requireBytes(size); + ByteString bytes = + bufferIsImmutable + ? ByteString.wrap(buffer, pos, size) + : ByteString.copyFrom(buffer, pos, size); + pos += size; + return bytes; + } + + @Override + public int readUInt32() throws IOException { + requireWireType(WIRETYPE_VARINT); + return readVarint32(); + } + + @Override + public int readEnum() throws IOException { + requireWireType(WIRETYPE_VARINT); + return readVarint32(); + } + + @Override + public int readSFixed32() throws IOException { + requireWireType(WIRETYPE_FIXED32); + return readLittleEndian32(); + } + + @Override + public long readSFixed64() throws IOException { + requireWireType(WIRETYPE_FIXED64); + return readLittleEndian64(); + } + + @Override + public int readSInt32() throws IOException { + requireWireType(WIRETYPE_VARINT); + return CodedInputStream.decodeZigZag32(readVarint32()); + } + + @Override + public long readSInt64() throws IOException { + requireWireType(WIRETYPE_VARINT); + return CodedInputStream.decodeZigZag64(readVarint64()); + } + + @Override + public void readDoubleList(List target) throws IOException { + if (target instanceof DoubleArrayList) { + DoubleArrayList plist = (DoubleArrayList) target; + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = readVarint32(); + verifyPackedFixed64Length(bytes); + final int fieldEndPos = pos + bytes; + while (pos < fieldEndPos) { + plist.addDouble(Double.longBitsToDouble(readLittleEndian64_NoCheck())); + } + break; + case WIRETYPE_FIXED64: + while (true) { + plist.addDouble(readDouble()); + + if (isAtEnd()) { + return; + } + int prevPos = pos; + int nextTag = readVarint32(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Rewind the buffer position to before + // the new tag. + pos = prevPos; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } else { + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = readVarint32(); + verifyPackedFixed64Length(bytes); + final int fieldEndPos = pos + bytes; + while (pos < fieldEndPos) { + target.add(Double.longBitsToDouble(readLittleEndian64_NoCheck())); + } + break; + case WIRETYPE_FIXED64: + while (true) { + target.add(readDouble()); + + if (isAtEnd()) { + return; + } + int prevPos = pos; + int nextTag = readVarint32(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Rewind the buffer position to before + // the new tag. + pos = prevPos; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + } + + @Override + public void readFloatList(List target) throws IOException { + if (target instanceof FloatArrayList) { + FloatArrayList plist = (FloatArrayList) target; + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = readVarint32(); + verifyPackedFixed32Length(bytes); + final int fieldEndPos = pos + bytes; + while (pos < fieldEndPos) { + plist.addFloat(Float.intBitsToFloat(readLittleEndian32_NoCheck())); + } + break; + case WIRETYPE_FIXED32: + while (true) { + plist.addFloat(readFloat()); + + if (isAtEnd()) { + return; + } + int prevPos = pos; + int nextTag = readVarint32(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Rewind the buffer position to before + // the new tag. + pos = prevPos; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } else { + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = readVarint32(); + verifyPackedFixed32Length(bytes); + final int fieldEndPos = pos + bytes; + while (pos < fieldEndPos) { + target.add(Float.intBitsToFloat(readLittleEndian32_NoCheck())); + } + break; + case WIRETYPE_FIXED32: + while (true) { + target.add(readFloat()); + + if (isAtEnd()) { + return; + } + int prevPos = pos; + int nextTag = readVarint32(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Rewind the buffer position to before + // the new tag. + pos = prevPos; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + } + + @Override + public void readUInt64List(List target) throws IOException { + if (target instanceof LongArrayList) { + LongArrayList plist = (LongArrayList) target; + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = readVarint32(); + final int fieldEndPos = pos + bytes; + while (pos < fieldEndPos) { + plist.addLong(readVarint64()); + } + requirePosition(fieldEndPos); + break; + case WIRETYPE_VARINT: + while (true) { + plist.addLong(readUInt64()); + + if (isAtEnd()) { + return; + } + int prevPos = pos; + int nextTag = readVarint32(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Rewind the buffer position to before + // the new tag. + pos = prevPos; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } else { + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = readVarint32(); + final int fieldEndPos = pos + bytes; + while (pos < fieldEndPos) { + target.add(readVarint64()); + } + requirePosition(fieldEndPos); + break; + case WIRETYPE_VARINT: + while (true) { + target.add(readUInt64()); + + if (isAtEnd()) { + return; + } + int prevPos = pos; + int nextTag = readVarint32(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Rewind the buffer position to before + // the new tag. + pos = prevPos; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + } + + @Override + public void readInt64List(List target) throws IOException { + if (target instanceof LongArrayList) { + LongArrayList plist = (LongArrayList) target; + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = readVarint32(); + final int fieldEndPos = pos + bytes; + while (pos < fieldEndPos) { + plist.addLong(readVarint64()); + } + requirePosition(fieldEndPos); + break; + case WIRETYPE_VARINT: + while (true) { + plist.addLong(readInt64()); + + if (isAtEnd()) { + return; + } + int prevPos = pos; + int nextTag = readVarint32(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Rewind the buffer position to before + // the new tag. + pos = prevPos; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } else { + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = readVarint32(); + final int fieldEndPos = pos + bytes; + while (pos < fieldEndPos) { + target.add(readVarint64()); + } + requirePosition(fieldEndPos); + break; + case WIRETYPE_VARINT: + while (true) { + target.add(readInt64()); + + if (isAtEnd()) { + return; + } + int prevPos = pos; + int nextTag = readVarint32(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Rewind the buffer position to before + // the new tag. + pos = prevPos; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + } + + @Override + public void readInt32List(List target) throws IOException { + if (target instanceof IntArrayList) { + IntArrayList plist = (IntArrayList) target; + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = readVarint32(); + final int fieldEndPos = pos + bytes; + while (pos < fieldEndPos) { + plist.addInt(readVarint32()); + } + requirePosition(fieldEndPos); + break; + case WIRETYPE_VARINT: + while (true) { + plist.addInt(readInt32()); + + if (isAtEnd()) { + return; + } + int prevPos = pos; + int nextTag = readVarint32(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Rewind the buffer position to before + // the new tag. + pos = prevPos; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } else { + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = readVarint32(); + final int fieldEndPos = pos + bytes; + while (pos < fieldEndPos) { + target.add(readVarint32()); + } + requirePosition(fieldEndPos); + break; + case WIRETYPE_VARINT: + while (true) { + target.add(readInt32()); + + if (isAtEnd()) { + return; + } + int prevPos = pos; + int nextTag = readVarint32(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Rewind the buffer position to before + // the new tag. + pos = prevPos; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + } + + @Override + public void readFixed64List(List target) throws IOException { + if (target instanceof LongArrayList) { + LongArrayList plist = (LongArrayList) target; + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = readVarint32(); + verifyPackedFixed64Length(bytes); + final int fieldEndPos = pos + bytes; + while (pos < fieldEndPos) { + plist.addLong(readLittleEndian64_NoCheck()); + } + break; + case WIRETYPE_FIXED64: + while (true) { + plist.addLong(readFixed64()); + + if (isAtEnd()) { + return; + } + int prevPos = pos; + int nextTag = readVarint32(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Rewind the buffer position to before + // the new tag. + pos = prevPos; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } else { + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = readVarint32(); + verifyPackedFixed64Length(bytes); + final int fieldEndPos = pos + bytes; + while (pos < fieldEndPos) { + target.add(readLittleEndian64_NoCheck()); + } + break; + case WIRETYPE_FIXED64: + while (true) { + target.add(readFixed64()); + + if (isAtEnd()) { + return; + } + int prevPos = pos; + int nextTag = readVarint32(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Rewind the buffer position to before + // the new tag. + pos = prevPos; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + } + + @Override + public void readFixed32List(List target) throws IOException { + if (target instanceof IntArrayList) { + IntArrayList plist = (IntArrayList) target; + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = readVarint32(); + verifyPackedFixed32Length(bytes); + final int fieldEndPos = pos + bytes; + while (pos < fieldEndPos) { + plist.addInt(readLittleEndian32_NoCheck()); + } + break; + case WIRETYPE_FIXED32: + while (true) { + plist.addInt(readFixed32()); + + if (isAtEnd()) { + return; + } + int prevPos = pos; + int nextTag = readVarint32(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Rewind the buffer position to before + // the new tag. + pos = prevPos; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } else { + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = readVarint32(); + verifyPackedFixed32Length(bytes); + final int fieldEndPos = pos + bytes; + while (pos < fieldEndPos) { + target.add(readLittleEndian32_NoCheck()); + } + break; + case WIRETYPE_FIXED32: + while (true) { + target.add(readFixed32()); + + if (isAtEnd()) { + return; + } + int prevPos = pos; + int nextTag = readVarint32(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Rewind the buffer position to before + // the new tag. + pos = prevPos; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + } + + @Override + public void readBoolList(List target) throws IOException { + if (target instanceof BooleanArrayList) { + BooleanArrayList plist = (BooleanArrayList) target; + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = readVarint32(); + final int fieldEndPos = pos + bytes; + while (pos < fieldEndPos) { + plist.addBoolean(readVarint32() != 0); + } + requirePosition(fieldEndPos); + break; + case WIRETYPE_VARINT: + while (true) { + plist.addBoolean(readBool()); + + if (isAtEnd()) { + return; + } + int prevPos = pos; + int nextTag = readVarint32(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Rewind the buffer position to before + // the new tag. + pos = prevPos; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } else { + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = readVarint32(); + final int fieldEndPos = pos + bytes; + while (pos < fieldEndPos) { + target.add(readVarint32() != 0); + } + requirePosition(fieldEndPos); + break; + case WIRETYPE_VARINT: + while (true) { + target.add(readBool()); + + if (isAtEnd()) { + return; + } + int prevPos = pos; + int nextTag = readVarint32(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Rewind the buffer position to before + // the new tag. + pos = prevPos; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + } + + @Override + public void readStringList(List target) throws IOException { + readStringListInternal(target, false); + } + + @Override + public void readStringListRequireUtf8(List target) throws IOException { + readStringListInternal(target, true); + } + + public void readStringListInternal(List target, boolean requireUtf8) + throws IOException { + if (WireFormat.getTagWireType(tag) != WIRETYPE_LENGTH_DELIMITED) { + throw InvalidProtocolBufferException.invalidWireType(); + } + + if (target instanceof LazyStringList && !requireUtf8) { + LazyStringList lazyList = (LazyStringList) target; + while (true) { + lazyList.add(readBytes()); + + if (isAtEnd()) { + return; + } + int prevPos = pos; + int nextTag = readVarint32(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Rewind the buffer position to before + // the new tag. + pos = prevPos; + return; + } + } + } else { + while (true) { + target.add(readStringInternal(requireUtf8)); + + if (isAtEnd()) { + return; + } + int prevPos = pos; + int nextTag = readVarint32(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Rewind the buffer position to before + // the new tag. + pos = prevPos; + return; + } + } + } + } + + @Override + public void readMessageList( + List target, Class targetType, ExtensionRegistryLite extensionRegistry) + throws IOException { + final Schema schema = Protobuf.getInstance().schemaFor(targetType); + readMessageList(target, schema, extensionRegistry); + } + + @Override + public void readMessageList( + List target, Schema schema, ExtensionRegistryLite extensionRegistry) + throws IOException { + if (WireFormat.getTagWireType(tag) != WIRETYPE_LENGTH_DELIMITED) { + throw InvalidProtocolBufferException.invalidWireType(); + } + final int listTag = tag; + while (true) { + target.add(readMessage(schema, extensionRegistry)); + + if (isAtEnd()) { + return; + } + int prevPos = pos; + int nextTag = readVarint32(); + if (nextTag != listTag) { + // We've reached the end of the repeated field. Rewind the buffer position to before + // the new tag. + pos = prevPos; + return; + } + } + } + + @Override + public void readGroupList( + List target, Class targetType, ExtensionRegistryLite extensionRegistry) + throws IOException { + final Schema schema = Protobuf.getInstance().schemaFor(targetType); + readGroupList(target, schema, extensionRegistry); + } + + @Override + public void readGroupList( + List target, Schema schema, ExtensionRegistryLite extensionRegistry) + throws IOException { + if (WireFormat.getTagWireType(tag) != WIRETYPE_START_GROUP) { + throw InvalidProtocolBufferException.invalidWireType(); + } + final int listTag = tag; + while (true) { + target.add(readGroup(schema, extensionRegistry)); + + if (isAtEnd()) { + return; + } + int prevPos = pos; + int nextTag = readVarint32(); + if (nextTag != listTag) { + // We've reached the end of the repeated field. Rewind the buffer position to before + // the new tag. + pos = prevPos; + return; + } + } + } + + @Override + public void readBytesList(List target) throws IOException { + if (WireFormat.getTagWireType(tag) != WIRETYPE_LENGTH_DELIMITED) { + throw InvalidProtocolBufferException.invalidWireType(); + } + + while (true) { + target.add(readBytes()); + + if (isAtEnd()) { + return; + } + int prevPos = pos; + int nextTag = readVarint32(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Rewind the buffer position to before + // the new tag. + pos = prevPos; + return; + } + } + } + + @Override + public void readUInt32List(List target) throws IOException { + if (target instanceof IntArrayList) { + IntArrayList plist = (IntArrayList) target; + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = readVarint32(); + final int fieldEndPos = pos + bytes; + while (pos < fieldEndPos) { + plist.addInt(readVarint32()); + } + break; + case WIRETYPE_VARINT: + while (true) { + plist.addInt(readUInt32()); + + if (isAtEnd()) { + return; + } + int prevPos = pos; + int nextTag = readVarint32(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Rewind the buffer position to before + // the new tag. + pos = prevPos; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } else { + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = readVarint32(); + final int fieldEndPos = pos + bytes; + while (pos < fieldEndPos) { + target.add(readVarint32()); + } + break; + case WIRETYPE_VARINT: + while (true) { + target.add(readUInt32()); + + if (isAtEnd()) { + return; + } + int prevPos = pos; + int nextTag = readVarint32(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Rewind the buffer position to before + // the new tag. + pos = prevPos; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + } + + @Override + public void readEnumList(List target) throws IOException { + if (target instanceof IntArrayList) { + IntArrayList plist = (IntArrayList) target; + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = readVarint32(); + final int fieldEndPos = pos + bytes; + while (pos < fieldEndPos) { + plist.addInt(readVarint32()); + } + break; + case WIRETYPE_VARINT: + while (true) { + plist.addInt(readEnum()); + + if (isAtEnd()) { + return; + } + int prevPos = pos; + int nextTag = readVarint32(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Rewind the buffer position to before + // the new tag. + pos = prevPos; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } else { + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = readVarint32(); + final int fieldEndPos = pos + bytes; + while (pos < fieldEndPos) { + target.add(readVarint32()); + } + break; + case WIRETYPE_VARINT: + while (true) { + target.add(readEnum()); + + if (isAtEnd()) { + return; + } + int prevPos = pos; + int nextTag = readVarint32(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Rewind the buffer position to before + // the new tag. + pos = prevPos; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + } + + @Override + public void readSFixed32List(List target) throws IOException { + if (target instanceof IntArrayList) { + IntArrayList plist = (IntArrayList) target; + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = readVarint32(); + verifyPackedFixed32Length(bytes); + final int fieldEndPos = pos + bytes; + while (pos < fieldEndPos) { + plist.addInt(readLittleEndian32_NoCheck()); + } + break; + case WIRETYPE_FIXED32: + while (true) { + plist.addInt(readSFixed32()); + + if (isAtEnd()) { + return; + } + int prevPos = pos; + int nextTag = readVarint32(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Rewind the buffer position to before + // the new tag. + pos = prevPos; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } else { + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = readVarint32(); + verifyPackedFixed32Length(bytes); + final int fieldEndPos = pos + bytes; + while (pos < fieldEndPos) { + target.add(readLittleEndian32_NoCheck()); + } + break; + case WIRETYPE_FIXED32: + while (true) { + target.add(readSFixed32()); + + if (isAtEnd()) { + return; + } + int prevPos = pos; + int nextTag = readVarint32(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Rewind the buffer position to before + // the new tag. + pos = prevPos; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + } + + @Override + public void readSFixed64List(List target) throws IOException { + if (target instanceof LongArrayList) { + LongArrayList plist = (LongArrayList) target; + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = readVarint32(); + verifyPackedFixed64Length(bytes); + final int fieldEndPos = pos + bytes; + while (pos < fieldEndPos) { + plist.addLong(readLittleEndian64_NoCheck()); + } + break; + case WIRETYPE_FIXED64: + while (true) { + plist.addLong(readSFixed64()); + + if (isAtEnd()) { + return; + } + int prevPos = pos; + int nextTag = readVarint32(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Rewind the buffer position to before + // the new tag. + pos = prevPos; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } else { + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = readVarint32(); + verifyPackedFixed64Length(bytes); + final int fieldEndPos = pos + bytes; + while (pos < fieldEndPos) { + target.add(readLittleEndian64_NoCheck()); + } + break; + case WIRETYPE_FIXED64: + while (true) { + target.add(readSFixed64()); + + if (isAtEnd()) { + return; + } + int prevPos = pos; + int nextTag = readVarint32(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Rewind the buffer position to before + // the new tag. + pos = prevPos; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + } + + @Override + public void readSInt32List(List target) throws IOException { + if (target instanceof IntArrayList) { + IntArrayList plist = (IntArrayList) target; + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = readVarint32(); + final int fieldEndPos = pos + bytes; + while (pos < fieldEndPos) { + plist.addInt(CodedInputStream.decodeZigZag32(readVarint32())); + } + break; + case WIRETYPE_VARINT: + while (true) { + plist.addInt(readSInt32()); + + if (isAtEnd()) { + return; + } + int prevPos = pos; + int nextTag = readVarint32(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Rewind the buffer position to before + // the new tag. + pos = prevPos; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } else { + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = readVarint32(); + final int fieldEndPos = pos + bytes; + while (pos < fieldEndPos) { + target.add(CodedInputStream.decodeZigZag32(readVarint32())); + } + break; + case WIRETYPE_VARINT: + while (true) { + target.add(readSInt32()); + + if (isAtEnd()) { + return; + } + int prevPos = pos; + int nextTag = readVarint32(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Rewind the buffer position to before + // the new tag. + pos = prevPos; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + } + + @Override + public void readSInt64List(List target) throws IOException { + if (target instanceof LongArrayList) { + LongArrayList plist = (LongArrayList) target; + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = readVarint32(); + final int fieldEndPos = pos + bytes; + while (pos < fieldEndPos) { + plist.addLong(CodedInputStream.decodeZigZag64(readVarint64())); + } + break; + case WIRETYPE_VARINT: + while (true) { + plist.addLong(readSInt64()); + + if (isAtEnd()) { + return; + } + int prevPos = pos; + int nextTag = readVarint32(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Rewind the buffer position to before + // the new tag. + pos = prevPos; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } else { + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = readVarint32(); + final int fieldEndPos = pos + bytes; + while (pos < fieldEndPos) { + target.add(CodedInputStream.decodeZigZag64(readVarint64())); + } + break; + case WIRETYPE_VARINT: + while (true) { + target.add(readSInt64()); + + if (isAtEnd()) { + return; + } + int prevPos = pos; + int nextTag = readVarint32(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Rewind the buffer position to before + // the new tag. + pos = prevPos; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + } + + @SuppressWarnings("unchecked") + @Override + public void readMap( + Map target, + MapEntryLite.Metadata metadata, + ExtensionRegistryLite extensionRegistry) + throws IOException { + requireWireType(WIRETYPE_LENGTH_DELIMITED); + int size = readVarint32(); + requireBytes(size); + + // Update the limit. + int prevLimit = limit; + int newLimit = pos + size; + limit = newLimit; + + try { + K key = metadata.defaultKey; + V value = metadata.defaultValue; + while (true) { + int number = getFieldNumber(); + if (number == READ_DONE) { + break; + } + try { + switch (number) { + case 1: + key = (K) readField(metadata.keyType, null, null); + break; + case 2: + value = + (V) + readField( + metadata.valueType, + metadata.defaultValue.getClass(), + extensionRegistry); + break; + default: + if (!skipField()) { + throw new InvalidProtocolBufferException("Unable to parse map entry."); + } + break; + } + } catch (InvalidProtocolBufferException.InvalidWireTypeException ignore) { + // the type doesn't match, skip the field. + if (!skipField()) { + throw new InvalidProtocolBufferException("Unable to parse map entry."); + } + } + } + target.put(key, value); + } finally { + // Restore the limit. + limit = prevLimit; + } + } + + private Object readField( + WireFormat.FieldType fieldType, + Class messageType, + ExtensionRegistryLite extensionRegistry) + throws IOException { + switch (fieldType) { + case BOOL: + return readBool(); + case BYTES: + return readBytes(); + case DOUBLE: + return readDouble(); + case ENUM: + return readEnum(); + case FIXED32: + return readFixed32(); + case FIXED64: + return readFixed64(); + case FLOAT: + return readFloat(); + case INT32: + return readInt32(); + case INT64: + return readInt64(); + case MESSAGE: + return readMessage(messageType, extensionRegistry); + case SFIXED32: + return readSFixed32(); + case SFIXED64: + return readSFixed64(); + case SINT32: + return readSInt32(); + case SINT64: + return readSInt64(); + case STRING: + return readStringRequireUtf8(); + case UINT32: + return readUInt32(); + case UINT64: + return readUInt64(); + default: + throw new RuntimeException("unsupported field type."); + } + } + + /** Read a raw Varint from the stream. If larger than 32 bits, discard the upper bits. */ + private int readVarint32() throws IOException { + // See implementation notes for readRawVarint64 + int i = pos; + + if (limit == pos) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + + int x; + if ((x = buffer[i++]) >= 0) { + pos = i; + return x; + } else if (limit - i < 9) { + return (int) readVarint64SlowPath(); + } else if ((x ^= (buffer[i++] << 7)) < 0) { + x ^= (~0 << 7); + } else if ((x ^= (buffer[i++] << 14)) >= 0) { + x ^= (~0 << 7) ^ (~0 << 14); + } else if ((x ^= (buffer[i++] << 21)) < 0) { + x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21); + } else { + int y = buffer[i++]; + x ^= y << 28; + x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21) ^ (~0 << 28); + if (y < 0 + && buffer[i++] < 0 + && buffer[i++] < 0 + && buffer[i++] < 0 + && buffer[i++] < 0 + && buffer[i++] < 0) { + throw InvalidProtocolBufferException.malformedVarint(); + } + } + pos = i; + return x; + } + + public long readVarint64() 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. + int i = pos; + + if (limit == i) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + + final byte[] buffer = this.buffer; + long x; + int y; + if ((y = buffer[i++]) >= 0) { + pos = i; + return y; + } else if (limit - i < 9) { + return readVarint64SlowPath(); + } else if ((y ^= (buffer[i++] << 7)) < 0) { + x = y ^ (~0 << 7); + } else if ((y ^= (buffer[i++] << 14)) >= 0) { + x = y ^ ((~0 << 7) ^ (~0 << 14)); + } else if ((y ^= (buffer[i++] << 21)) < 0) { + x = y ^ ((~0 << 7) ^ (~0 << 14) ^ (~0 << 21)); + } else if ((x = y ^ ((long) buffer[i++] << 28)) >= 0L) { + x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28); + } else if ((x ^= ((long) buffer[i++] << 35)) < 0L) { + x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35); + } else if ((x ^= ((long) buffer[i++] << 42)) >= 0L) { + x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35) ^ (~0L << 42); + } else if ((x ^= ((long) buffer[i++] << 49)) < 0L) { + x ^= + (~0L << 7) + ^ (~0L << 14) + ^ (~0L << 21) + ^ (~0L << 28) + ^ (~0L << 35) + ^ (~0L << 42) + ^ (~0L << 49); + } else { + x ^= ((long) buffer[i++] << 56); + x ^= + (~0L << 7) + ^ (~0L << 14) + ^ (~0L << 21) + ^ (~0L << 28) + ^ (~0L << 35) + ^ (~0L << 42) + ^ (~0L << 49) + ^ (~0L << 56); + if (x < 0L) { + if (buffer[i++] < 0L) { + throw InvalidProtocolBufferException.malformedVarint(); + } + } + } + pos = i; + return x; + } + + private long readVarint64SlowPath() throws IOException { + long result = 0; + for (int shift = 0; shift < 64; shift += 7) { + final byte b = readByte(); + result |= (long) (b & 0x7F) << shift; + if ((b & 0x80) == 0) { + return result; + } + } + throw InvalidProtocolBufferException.malformedVarint(); + } + + private byte readByte() throws IOException { + if (pos == limit) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + return buffer[pos++]; + } + + private int readLittleEndian32() throws IOException { + requireBytes(FIXED32_SIZE); + return readLittleEndian32_NoCheck(); + } + + private long readLittleEndian64() throws IOException { + requireBytes(FIXED64_SIZE); + return readLittleEndian64_NoCheck(); + } + + private int readLittleEndian32_NoCheck() { + int p = pos; + final byte[] buffer = this.buffer; + pos = p + FIXED32_SIZE; + return (((buffer[p] & 0xff)) + | ((buffer[p + 1] & 0xff) << 8) + | ((buffer[p + 2] & 0xff) << 16) + | ((buffer[p + 3] & 0xff) << 24)); + } + + private long readLittleEndian64_NoCheck() { + int p = pos; + final byte[] buffer = this.buffer; + pos = p + FIXED64_SIZE; + return (((buffer[p] & 0xffL)) + | ((buffer[p + 1] & 0xffL) << 8) + | ((buffer[p + 2] & 0xffL) << 16) + | ((buffer[p + 3] & 0xffL) << 24) + | ((buffer[p + 4] & 0xffL) << 32) + | ((buffer[p + 5] & 0xffL) << 40) + | ((buffer[p + 6] & 0xffL) << 48) + | ((buffer[p + 7] & 0xffL) << 56)); + } + + private void skipVarint() throws IOException { + if (limit - pos >= 10) { + final byte[] buffer = this.buffer; + int p = pos; + for (int i = 0; i < 10; i++) { + if (buffer[p++] >= 0) { + pos = p; + return; + } + } + } + skipVarintSlowPath(); + } + + private void skipVarintSlowPath() throws IOException { + for (int i = 0; i < 10; i++) { + if (readByte() >= 0) { + return; + } + } + throw InvalidProtocolBufferException.malformedVarint(); + } + + private void skipBytes(final int size) throws IOException { + requireBytes(size); + + pos += size; + } + + private void skipGroup() throws IOException { + int prevEndGroupTag = endGroupTag; + endGroupTag = WireFormat.makeTag(WireFormat.getTagFieldNumber(tag), WIRETYPE_END_GROUP); + while (true) { + if (getFieldNumber() == READ_DONE || !skipField()) { + break; + } + } + if (tag != endGroupTag) { + throw InvalidProtocolBufferException.parseFailure(); + } + endGroupTag = prevEndGroupTag; + } + + private void requireBytes(int size) throws IOException { + if (size < 0 || size > (limit - pos)) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + } + + private void requireWireType(int requiredWireType) throws IOException { + if (WireFormat.getTagWireType(tag) != requiredWireType) { + throw InvalidProtocolBufferException.invalidWireType(); + } + } + + private void verifyPackedFixed64Length(int bytes) throws IOException { + requireBytes(bytes); + if ((bytes & FIXED64_MULTIPLE_MASK) != 0) { + // Require that the number of bytes be a multiple of 8. + throw InvalidProtocolBufferException.parseFailure(); + } + } + + private void verifyPackedFixed32Length(int bytes) throws IOException { + requireBytes(bytes); + if ((bytes & FIXED32_MULTIPLE_MASK) != 0) { + // Require that the number of bytes be a multiple of 4. + throw InvalidProtocolBufferException.parseFailure(); + } + } + + private void requirePosition(int expectedPosition) throws IOException { + if (pos != expectedPosition) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + } + } +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/BinaryWriter.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/BinaryWriter.java new file mode 100644 index 0000000000000..94259ecd32bba --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/BinaryWriter.java @@ -0,0 +1,3071 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +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_VARINT32_SIZE; +import static com.google.protobuf.WireFormat.MAX_VARINT64_SIZE; +import static com.google.protobuf.WireFormat.MESSAGE_SET_ITEM; +import static com.google.protobuf.WireFormat.MESSAGE_SET_MESSAGE; +import static com.google.protobuf.WireFormat.MESSAGE_SET_TYPE_ID; +import static com.google.protobuf.WireFormat.WIRETYPE_END_GROUP; +import static com.google.protobuf.WireFormat.WIRETYPE_FIXED32; +import static com.google.protobuf.WireFormat.WIRETYPE_FIXED64; +import static com.google.protobuf.WireFormat.WIRETYPE_LENGTH_DELIMITED; +import static com.google.protobuf.WireFormat.WIRETYPE_START_GROUP; +import static com.google.protobuf.WireFormat.WIRETYPE_VARINT; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.util.ArrayDeque; +import java.util.List; +import java.util.Map; +import java.util.Queue; + +/** + * A protobuf writer that serializes messages in their binary form. Messages are serialized in + * reverse in order to avoid calculating the serialized size of each nested message. Since the + * message size is not known in advance, the writer employs a strategy of chunking and buffer + * chaining. Buffers are allocated as-needed by a provided {@link BufferAllocator}. Once writing is + * finished, the application can access the buffers in forward-writing order by calling {@link + * #complete()}. + * + *

Once {@link #complete()} has been called, the writer can not be reused for additional writes. + * The {@link #getTotalBytesWritten()} will continue to reflect the total of the write and will not + * be reset. + */ +@ExperimentalApi +abstract class BinaryWriter extends ByteOutput implements Writer { + public static final int DEFAULT_CHUNK_SIZE = 4096; + + private final BufferAllocator alloc; + private final int chunkSize; + + final ArrayDeque buffers = new ArrayDeque(4); + int totalDoneBytes; + + /** + * Creates a new {@link BinaryWriter} that will allocate heap buffers of {@link + * #DEFAULT_CHUNK_SIZE} as necessary. + */ + public static BinaryWriter newHeapInstance(BufferAllocator alloc) { + return newHeapInstance(alloc, DEFAULT_CHUNK_SIZE); + } + + /** + * Creates a new {@link BinaryWriter} that will allocate heap buffers of {@code chunkSize} as + * necessary. + */ + public static BinaryWriter newHeapInstance(BufferAllocator alloc, int chunkSize) { + return isUnsafeHeapSupported() + ? newUnsafeHeapInstance(alloc, chunkSize) + : newSafeHeapInstance(alloc, chunkSize); + } + + /** + * Creates a new {@link BinaryWriter} that will allocate direct (i.e. non-heap) buffers of {@link + * #DEFAULT_CHUNK_SIZE} as necessary. + */ + public static BinaryWriter newDirectInstance(BufferAllocator alloc) { + return newDirectInstance(alloc, DEFAULT_CHUNK_SIZE); + } + + /** + * Creates a new {@link BinaryWriter} that will allocate direct (i.e. non-heap) buffers of {@code + * chunkSize} as necessary. + */ + public static BinaryWriter newDirectInstance(BufferAllocator alloc, int chunkSize) { + return isUnsafeDirectSupported() + ? newUnsafeDirectInstance(alloc, chunkSize) + : newSafeDirectInstance(alloc, chunkSize); + } + + static boolean isUnsafeHeapSupported() { + return UnsafeHeapWriter.isSupported(); + } + + static boolean isUnsafeDirectSupported() { + return UnsafeDirectWriter.isSupported(); + } + + static BinaryWriter newSafeHeapInstance(BufferAllocator alloc, int chunkSize) { + return new SafeHeapWriter(alloc, chunkSize); + } + + static BinaryWriter newUnsafeHeapInstance(BufferAllocator alloc, int chunkSize) { + if (!isUnsafeHeapSupported()) { + throw new UnsupportedOperationException("Unsafe operations not supported"); + } + return new UnsafeHeapWriter(alloc, chunkSize); + } + + static BinaryWriter newSafeDirectInstance(BufferAllocator alloc, int chunkSize) { + return new SafeDirectWriter(alloc, chunkSize); + } + + static BinaryWriter newUnsafeDirectInstance(BufferAllocator alloc, int chunkSize) { + if (!isUnsafeDirectSupported()) { + throw new UnsupportedOperationException("Unsafe operations not supported"); + } + return new UnsafeDirectWriter(alloc, chunkSize); + } + + /** Only allow subclassing for inner classes. */ + private BinaryWriter(BufferAllocator alloc, int chunkSize) { + if (chunkSize <= 0) { + throw new IllegalArgumentException("chunkSize must be > 0"); + } + this.alloc = checkNotNull(alloc, "alloc"); + this.chunkSize = chunkSize; + } + + @Override + public final FieldOrder fieldOrder() { + return FieldOrder.DESCENDING; + } + + /** + * Completes the write operation and returns a queue of {@link AllocatedBuffer} objects in + * forward-writing order. This method should only be called once. + * + *

After calling this method, the writer can not be reused. Create a new writer for future + * writes. + */ + public final Queue complete() { + finishCurrentBuffer(); + return buffers; + } + + @Override + public final void writeSFixed32(int fieldNumber, int value) throws IOException { + writeFixed32(fieldNumber, value); + } + + @Override + public final void writeInt64(int fieldNumber, long value) throws IOException { + writeUInt64(fieldNumber, value); + } + + @Override + public final void writeSFixed64(int fieldNumber, long value) throws IOException { + writeFixed64(fieldNumber, value); + } + + @Override + public final void writeFloat(int fieldNumber, float value) throws IOException { + writeFixed32(fieldNumber, Float.floatToRawIntBits(value)); + } + + @Override + public final void writeDouble(int fieldNumber, double value) throws IOException { + writeFixed64(fieldNumber, Double.doubleToRawLongBits(value)); + } + + @Override + public final void writeEnum(int fieldNumber, int value) throws IOException { + writeInt32(fieldNumber, value); + } + + @Override + public final void writeInt32List(int fieldNumber, List list, boolean packed) + throws IOException { + if (list instanceof IntArrayList) { + writeInt32List_Internal(fieldNumber, (IntArrayList) list, packed); + } else { + writeInt32List_Internal(fieldNumber, list, packed); + } + } + + private final void writeInt32List_Internal(int fieldNumber, List list, boolean packed) + throws IOException { + if (packed) { + requireSpace((MAX_VARINT32_SIZE * 2) + (list.size() * MAX_VARINT64_SIZE)); + int prevBytes = getTotalBytesWritten(); + for (int i = list.size() - 1; i >= 0; --i) { + writeInt32(list.get(i)); + } + int length = getTotalBytesWritten() - prevBytes; + writeVarint32(length); + writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + } else { + for (int i = list.size() - 1; i >= 0; --i) { + writeInt32(fieldNumber, list.get(i)); + } + } + } + + private final void writeInt32List_Internal(int fieldNumber, IntArrayList list, boolean packed) + throws IOException { + if (packed) { + requireSpace((MAX_VARINT32_SIZE * 2) + (list.size() * MAX_VARINT64_SIZE)); + int prevBytes = getTotalBytesWritten(); + for (int i = list.size() - 1; i >= 0; --i) { + writeInt32(list.getInt(i)); + } + int length = getTotalBytesWritten() - prevBytes; + writeVarint32(length); + writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + } else { + for (int i = list.size() - 1; i >= 0; --i) { + writeInt32(fieldNumber, list.getInt(i)); + } + } + } + + @Override + public final void writeFixed32List(int fieldNumber, List list, boolean packed) + throws IOException { + if (list instanceof IntArrayList) { + writeFixed32List_Internal(fieldNumber, (IntArrayList) list, packed); + } else { + writeFixed32List_Internal(fieldNumber, list, packed); + } + } + + private final void writeFixed32List_Internal(int fieldNumber, List list, boolean packed) + throws IOException { + if (packed) { + requireSpace((MAX_VARINT32_SIZE * 2) + (list.size() * FIXED32_SIZE)); + int prevBytes = getTotalBytesWritten(); + for (int i = list.size() - 1; i >= 0; --i) { + writeFixed32(list.get(i)); + } + int length = getTotalBytesWritten() - prevBytes; + writeVarint32(length); + writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + } else { + for (int i = list.size() - 1; i >= 0; --i) { + writeFixed32(fieldNumber, list.get(i)); + } + } + } + + private final void writeFixed32List_Internal(int fieldNumber, IntArrayList list, boolean packed) + throws IOException { + if (packed) { + requireSpace((MAX_VARINT32_SIZE * 2) + (list.size() * FIXED32_SIZE)); + int prevBytes = getTotalBytesWritten(); + for (int i = list.size() - 1; i >= 0; --i) { + writeFixed32(list.getInt(i)); + } + int length = getTotalBytesWritten() - prevBytes; + writeVarint32(length); + writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + } else { + for (int i = list.size() - 1; i >= 0; --i) { + writeFixed32(fieldNumber, list.getInt(i)); + } + } + } + + @Override + public final void writeInt64List(int fieldNumber, List list, boolean packed) + throws IOException { + writeUInt64List(fieldNumber, list, packed); + } + + @Override + public final void writeUInt64List(int fieldNumber, List list, boolean packed) + throws IOException { + if (list instanceof LongArrayList) { + writeUInt64List_Internal(fieldNumber, (LongArrayList) list, packed); + } else { + writeUInt64List_Internal(fieldNumber, list, packed); + } + } + + private final void writeUInt64List_Internal(int fieldNumber, List list, boolean packed) + throws IOException { + if (packed) { + requireSpace((MAX_VARINT32_SIZE * 2) + (list.size() * MAX_VARINT64_SIZE)); + int prevBytes = getTotalBytesWritten(); + for (int i = list.size() - 1; i >= 0; --i) { + writeVarint64(list.get(i)); + } + int length = getTotalBytesWritten() - prevBytes; + writeVarint32(length); + writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + } else { + for (int i = list.size() - 1; i >= 0; --i) { + writeUInt64(fieldNumber, list.get(i)); + } + } + } + + private final void writeUInt64List_Internal(int fieldNumber, LongArrayList list, boolean packed) + throws IOException { + if (packed) { + requireSpace((MAX_VARINT32_SIZE * 2) + (list.size() * MAX_VARINT64_SIZE)); + int prevBytes = getTotalBytesWritten(); + for (int i = list.size() - 1; i >= 0; --i) { + writeVarint64(list.getLong(i)); + } + int length = getTotalBytesWritten() - prevBytes; + writeVarint32(length); + writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + } else { + for (int i = list.size() - 1; i >= 0; --i) { + writeUInt64(fieldNumber, list.getLong(i)); + } + } + } + + @Override + public final void writeFixed64List(int fieldNumber, List list, boolean packed) + throws IOException { + if (list instanceof LongArrayList) { + writeFixed64List_Internal(fieldNumber, (LongArrayList) list, packed); + } else { + writeFixed64List_Internal(fieldNumber, list, packed); + } + } + + private final void writeFixed64List_Internal(int fieldNumber, List list, boolean packed) + throws IOException { + if (packed) { + requireSpace((MAX_VARINT32_SIZE * 2) + (list.size() * FIXED64_SIZE)); + int prevBytes = getTotalBytesWritten(); + for (int i = list.size() - 1; i >= 0; --i) { + writeFixed64(list.get(i)); + } + int length = getTotalBytesWritten() - prevBytes; + writeVarint32(length); + writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + } else { + for (int i = list.size() - 1; i >= 0; --i) { + writeFixed64(fieldNumber, list.get(i)); + } + } + } + + private final void writeFixed64List_Internal(int fieldNumber, LongArrayList list, boolean packed) + throws IOException { + if (packed) { + requireSpace((MAX_VARINT32_SIZE * 2) + (list.size() * FIXED64_SIZE)); + int prevBytes = getTotalBytesWritten(); + for (int i = list.size() - 1; i >= 0; --i) { + writeFixed64(list.getLong(i)); + } + int length = getTotalBytesWritten() - prevBytes; + writeVarint32(length); + writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + } else { + for (int i = list.size() - 1; i >= 0; --i) { + writeFixed64(fieldNumber, list.getLong(i)); + } + } + } + + @Override + public final void writeFloatList(int fieldNumber, List list, boolean packed) + throws IOException { + if (list instanceof FloatArrayList) { + writeFloatList_Internal(fieldNumber, (FloatArrayList) list, packed); + } else { + writeFloatList_Internal(fieldNumber, list, packed); + } + } + + private final void writeFloatList_Internal(int fieldNumber, List list, boolean packed) + throws IOException { + if (packed) { + requireSpace((MAX_VARINT32_SIZE * 2) + (list.size() * FIXED32_SIZE)); + int prevBytes = getTotalBytesWritten(); + for (int i = list.size() - 1; i >= 0; --i) { + writeFixed32(Float.floatToRawIntBits(list.get(i))); + } + int length = getTotalBytesWritten() - prevBytes; + writeVarint32(length); + writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + } else { + for (int i = list.size() - 1; i >= 0; --i) { + writeFloat(fieldNumber, list.get(i)); + } + } + } + + private final void writeFloatList_Internal(int fieldNumber, FloatArrayList list, boolean packed) + throws IOException { + if (packed) { + requireSpace((MAX_VARINT32_SIZE * 2) + (list.size() * FIXED32_SIZE)); + int prevBytes = getTotalBytesWritten(); + for (int i = list.size() - 1; i >= 0; --i) { + writeFixed32(Float.floatToRawIntBits(list.getFloat(i))); + } + int length = getTotalBytesWritten() - prevBytes; + writeVarint32(length); + writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + } else { + for (int i = list.size() - 1; i >= 0; --i) { + writeFloat(fieldNumber, list.getFloat(i)); + } + } + } + + @Override + public final void writeDoubleList(int fieldNumber, List list, boolean packed) + throws IOException { + if (list instanceof DoubleArrayList) { + writeDoubleList_Internal(fieldNumber, (DoubleArrayList) list, packed); + } else { + writeDoubleList_Internal(fieldNumber, list, packed); + } + } + + private final void writeDoubleList_Internal(int fieldNumber, List list, boolean packed) + throws IOException { + if (packed) { + requireSpace((MAX_VARINT32_SIZE * 2) + (list.size() * FIXED64_SIZE)); + int prevBytes = getTotalBytesWritten(); + for (int i = list.size() - 1; i >= 0; --i) { + writeFixed64(Double.doubleToRawLongBits(list.get(i))); + } + int length = getTotalBytesWritten() - prevBytes; + writeVarint32(length); + writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + } else { + for (int i = list.size() - 1; i >= 0; --i) { + writeDouble(fieldNumber, list.get(i)); + } + } + } + + private final void writeDoubleList_Internal(int fieldNumber, DoubleArrayList list, boolean packed) + throws IOException { + if (packed) { + requireSpace((MAX_VARINT32_SIZE * 2) + (list.size() * FIXED64_SIZE)); + int prevBytes = getTotalBytesWritten(); + for (int i = list.size() - 1; i >= 0; --i) { + writeFixed64(Double.doubleToRawLongBits(list.getDouble(i))); + } + int length = getTotalBytesWritten() - prevBytes; + writeVarint32(length); + writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + } else { + for (int i = list.size() - 1; i >= 0; --i) { + writeDouble(fieldNumber, list.getDouble(i)); + } + } + } + + @Override + public final void writeEnumList(int fieldNumber, List list, boolean packed) + throws IOException { + writeInt32List(fieldNumber, list, packed); + } + + @Override + public final void writeBoolList(int fieldNumber, List list, boolean packed) + throws IOException { + if (list instanceof BooleanArrayList) { + writeBoolList_Internal(fieldNumber, (BooleanArrayList) list, packed); + } else { + writeBoolList_Internal(fieldNumber, list, packed); + } + } + + private final void writeBoolList_Internal(int fieldNumber, List list, boolean packed) + throws IOException { + if (packed) { + requireSpace((MAX_VARINT32_SIZE * 2) + list.size()); + int prevBytes = getTotalBytesWritten(); + for (int i = list.size() - 1; i >= 0; --i) { + writeBool(list.get(i)); + } + int length = getTotalBytesWritten() - prevBytes; + writeVarint32(length); + writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + } else { + for (int i = list.size() - 1; i >= 0; --i) { + writeBool(fieldNumber, list.get(i)); + } + } + } + + private final void writeBoolList_Internal(int fieldNumber, BooleanArrayList list, boolean packed) + throws IOException { + if (packed) { + requireSpace((MAX_VARINT32_SIZE * 2) + list.size()); + int prevBytes = getTotalBytesWritten(); + for (int i = list.size() - 1; i >= 0; --i) { + writeBool(list.getBoolean(i)); + } + int length = getTotalBytesWritten() - prevBytes; + writeVarint32(length); + writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + } else { + for (int i = list.size() - 1; i >= 0; --i) { + writeBool(fieldNumber, list.getBoolean(i)); + } + } + } + + @Override + public final void writeStringList(int fieldNumber, List list) throws IOException { + if (list instanceof LazyStringList) { + final LazyStringList lazyList = (LazyStringList) list; + for (int i = list.size() - 1; i >= 0; i--) { + writeLazyString(fieldNumber, lazyList.getRaw(i)); + } + } else { + for (int i = list.size() - 1; i >= 0; i--) { + writeString(fieldNumber, list.get(i)); + } + } + } + + private void writeLazyString(int fieldNumber, Object value) throws IOException { + if (value instanceof String) { + writeString(fieldNumber, (String) value); + } else { + writeBytes(fieldNumber, (ByteString) value); + } + } + + @Override + public final void writeBytesList(int fieldNumber, List list) throws IOException { + for (int i = list.size() - 1; i >= 0; i--) { + writeBytes(fieldNumber, list.get(i)); + } + } + + @Override + public final void writeUInt32List(int fieldNumber, List list, boolean packed) + throws IOException { + if (list instanceof IntArrayList) { + writeUInt32List_Internal(fieldNumber, (IntArrayList) list, packed); + } else { + writeUInt32List_Internal(fieldNumber, list, packed); + } + } + + private final void writeUInt32List_Internal(int fieldNumber, List list, boolean packed) + throws IOException { + if (packed) { + requireSpace((MAX_VARINT32_SIZE * 2) + (list.size() * MAX_VARINT32_SIZE)); + int prevBytes = getTotalBytesWritten(); + for (int i = list.size() - 1; i >= 0; --i) { + writeVarint32(list.get(i)); + } + int length = getTotalBytesWritten() - prevBytes; + writeVarint32(length); + writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + } else { + for (int i = list.size() - 1; i >= 0; --i) { + writeUInt32(fieldNumber, list.get(i)); + } + } + } + + private final void writeUInt32List_Internal(int fieldNumber, IntArrayList list, boolean packed) + throws IOException { + if (packed) { + requireSpace((MAX_VARINT32_SIZE * 2) + (list.size() * MAX_VARINT32_SIZE)); + int prevBytes = getTotalBytesWritten(); + for (int i = list.size() - 1; i >= 0; --i) { + writeVarint32(list.getInt(i)); + } + int length = getTotalBytesWritten() - prevBytes; + writeVarint32(length); + writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + } else { + for (int i = list.size() - 1; i >= 0; --i) { + writeUInt32(fieldNumber, list.getInt(i)); + } + } + } + + @Override + public final void writeSFixed32List(int fieldNumber, List list, boolean packed) + throws IOException { + writeFixed32List(fieldNumber, list, packed); + } + + @Override + public final void writeSFixed64List(int fieldNumber, List list, boolean packed) + throws IOException { + writeFixed64List(fieldNumber, list, packed); + } + + @Override + public final void writeSInt32List(int fieldNumber, List list, boolean packed) + throws IOException { + if (list instanceof IntArrayList) { + writeSInt32List_Internal(fieldNumber, (IntArrayList) list, packed); + } else { + writeSInt32List_Internal(fieldNumber, list, packed); + } + } + + private final void writeSInt32List_Internal(int fieldNumber, List list, boolean packed) + throws IOException { + if (packed) { + requireSpace((MAX_VARINT32_SIZE * 2) + (list.size() * MAX_VARINT32_SIZE)); + int prevBytes = getTotalBytesWritten(); + for (int i = list.size() - 1; i >= 0; --i) { + writeSInt32(list.get(i)); + } + int length = getTotalBytesWritten() - prevBytes; + writeVarint32(length); + writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + } else { + for (int i = list.size() - 1; i >= 0; --i) { + writeSInt32(fieldNumber, list.get(i)); + } + } + } + + private final void writeSInt32List_Internal(int fieldNumber, IntArrayList list, boolean packed) + throws IOException { + if (packed) { + requireSpace((MAX_VARINT32_SIZE * 2) + (list.size() * MAX_VARINT32_SIZE)); + int prevBytes = getTotalBytesWritten(); + for (int i = list.size() - 1; i >= 0; --i) { + writeSInt32(list.getInt(i)); + } + int length = getTotalBytesWritten() - prevBytes; + writeVarint32(length); + writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + } else { + for (int i = list.size() - 1; i >= 0; --i) { + writeSInt32(fieldNumber, list.getInt(i)); + } + } + } + + @Override + public final void writeSInt64List(int fieldNumber, List list, boolean packed) + throws IOException { + if (list instanceof LongArrayList) { + writeSInt64List_Internal(fieldNumber, (LongArrayList) list, packed); + } else { + writeSInt64List_Internal(fieldNumber, list, packed); + } + } + + private static final int MAP_KEY_NUMBER = 1; + private static final int MAP_VALUE_NUMBER = 2; + + @Override + public void writeMap(int fieldNumber, MapEntryLite.Metadata metadata, Map map) + throws IOException { + // TODO(liujisi): Reverse write those entries. + for (Map.Entry entry : map.entrySet()) { + int prevBytes = getTotalBytesWritten(); + writeMapEntryField(this, MAP_VALUE_NUMBER, metadata.valueType, entry.getValue()); + writeMapEntryField(this, MAP_KEY_NUMBER, metadata.keyType, entry.getKey()); + int length = getTotalBytesWritten() - prevBytes; + writeVarint32(length); + writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + } + } + + static final void writeMapEntryField( + Writer writer, int fieldNumber, WireFormat.FieldType fieldType, Object object) + throws IOException { + switch (fieldType) { + case BOOL: + writer.writeBool(fieldNumber, (Boolean) object); + break; + case FIXED32: + writer.writeFixed32(fieldNumber, (Integer) object); + break; + case FIXED64: + writer.writeFixed64(fieldNumber, (Long) object); + break; + case INT32: + writer.writeInt32(fieldNumber, (Integer) object); + break; + case INT64: + writer.writeInt64(fieldNumber, (Long) object); + break; + case SFIXED32: + writer.writeSFixed32(fieldNumber, (Integer) object); + break; + case SFIXED64: + writer.writeSFixed64(fieldNumber, (Long) object); + break; + case SINT32: + writer.writeSInt32(fieldNumber, (Integer) object); + break; + case SINT64: + writer.writeSInt64(fieldNumber, (Long) object); + break; + case STRING: + writer.writeString(fieldNumber, (String) object); + break; + case UINT32: + writer.writeUInt32(fieldNumber, (Integer) object); + break; + case UINT64: + writer.writeUInt64(fieldNumber, (Long) object); + break; + case FLOAT: + writer.writeFloat(fieldNumber, (Float) object); + break; + case DOUBLE: + writer.writeDouble(fieldNumber, (Double) object); + break; + case MESSAGE: + writer.writeMessage(fieldNumber, object); + break; + case BYTES: + writer.writeBytes(fieldNumber, (ByteString) object); + break; + case ENUM: + if (object instanceof Internal.EnumLite) { + writer.writeEnum(fieldNumber, ((Internal.EnumLite) object).getNumber()); + } else if (object instanceof Integer) { + writer.writeEnum(fieldNumber, (Integer) object); + } else { + throw new IllegalArgumentException("Unexpected type for enum in map."); + } + break; + default: + throw new IllegalArgumentException("Unsupported map value type for: " + fieldType); + } + } + + private final void writeSInt64List_Internal(int fieldNumber, List list, boolean packed) + throws IOException { + if (packed) { + requireSpace((MAX_VARINT32_SIZE * 2) + (list.size() * MAX_VARINT64_SIZE)); + int prevBytes = getTotalBytesWritten(); + for (int i = list.size() - 1; i >= 0; --i) { + writeSInt64(list.get(i)); + } + int length = getTotalBytesWritten() - prevBytes; + writeVarint32(length); + writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + } else { + for (int i = list.size() - 1; i >= 0; --i) { + writeSInt64(fieldNumber, list.get(i)); + } + } + } + + private final void writeSInt64List_Internal(int fieldNumber, LongArrayList list, boolean packed) + throws IOException { + if (packed) { + requireSpace((MAX_VARINT32_SIZE * 2) + (list.size() * MAX_VARINT64_SIZE)); + int prevBytes = getTotalBytesWritten(); + for (int i = list.size() - 1; i >= 0; --i) { + writeSInt64(list.getLong(i)); + } + int length = getTotalBytesWritten() - prevBytes; + writeVarint32(length); + writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + } else { + for (int i = list.size() - 1; i >= 0; --i) { + writeSInt64(fieldNumber, list.getLong(i)); + } + } + } + + @Override + public final void writeMessageList(int fieldNumber, List list) throws IOException { + for (int i = list.size() - 1; i >= 0; i--) { + writeMessage(fieldNumber, list.get(i)); + } + } + + @Override + public final void writeMessageList(int fieldNumber, List list, Schema schema) + throws IOException { + for (int i = list.size() - 1; i >= 0; i--) { + writeMessage(fieldNumber, list.get(i), schema); + } + } + + @Override + public final void writeGroupList(int fieldNumber, List list) throws IOException { + for (int i = list.size() - 1; i >= 0; i--) { + writeGroup(fieldNumber, list.get(i)); + } + } + + @Override + public final void writeGroupList(int fieldNumber, List list, Schema schema) + throws IOException { + for (int i = list.size() - 1; i >= 0; i--) { + writeGroup(fieldNumber, list.get(i), schema); + } + } + + @Override + public final void writeMessageSetItem(int fieldNumber, Object value) throws IOException { + writeTag(MESSAGE_SET_ITEM, WIRETYPE_END_GROUP); + if (value instanceof ByteString) { + writeBytes(MESSAGE_SET_MESSAGE, (ByteString) value); + } else { + writeMessage(MESSAGE_SET_MESSAGE, value); + } + writeUInt32(MESSAGE_SET_TYPE_ID, fieldNumber); + writeTag(MESSAGE_SET_ITEM, WIRETYPE_START_GROUP); + } + + final AllocatedBuffer newHeapBuffer() { + return alloc.allocateHeapBuffer(chunkSize); + } + + final AllocatedBuffer newHeapBuffer(int capacity) { + return alloc.allocateHeapBuffer(Math.max(capacity, chunkSize)); + } + + final AllocatedBuffer newDirectBuffer() { + return alloc.allocateDirectBuffer(chunkSize); + } + + final AllocatedBuffer newDirectBuffer(int capacity) { + return alloc.allocateDirectBuffer(Math.max(capacity, chunkSize)); + } + + /** + * Gets the total number of bytes that have been written. This will not be reset by a call to + * {@link #complete()}. + */ + public abstract int getTotalBytesWritten(); + + abstract void requireSpace(int size); + + abstract void finishCurrentBuffer(); + + abstract void writeTag(int fieldNumber, int wireType); + + abstract void writeVarint32(int value); + + abstract void writeInt32(int value); + + abstract void writeSInt32(int value); + + abstract void writeFixed32(int value); + + abstract void writeVarint64(long value); + + abstract void writeSInt64(long value); + + abstract void writeFixed64(long value); + + abstract void writeBool(boolean value); + + abstract void writeString(String in); + + /** + * Not using the version in CodedOutputStream due to the fact that benchmarks have shown a + * performance improvement when returning a byte (rather than an int). + */ + private static byte computeUInt64SizeNoTag(long value) { + // handle two popular special cases up front ... + if ((value & (~0L << 7)) == 0L) { + // Byte 1 + return 1; + } + if (value < 0L) { + // Byte 10 + return 10; + } + // ... leaving us with 8 remaining, which we can divide and conquer + byte n = 2; + if ((value & (~0L << 35)) != 0L) { + // Byte 6-9 + n += 4; // + (value >>> 63); + value >>>= 28; + } + if ((value & (~0L << 21)) != 0L) { + // Byte 4-5 or 8-9 + n += 2; + value >>>= 14; + } + if ((value & (~0L << 14)) != 0L) { + // Byte 3 or 7 + n += 1; + } + return n; + } + + /** Writer that uses safe operations on target array. */ + private static final class SafeHeapWriter extends BinaryWriter { + private AllocatedBuffer allocatedBuffer; + private byte[] buffer; + private int offset; + private int limit; + private int offsetMinusOne; + private int limitMinusOne; + private int pos; + + SafeHeapWriter(BufferAllocator alloc, int chunkSize) { + super(alloc, chunkSize); + nextBuffer(); + } + + @Override + void finishCurrentBuffer() { + if (allocatedBuffer != null) { + totalDoneBytes += bytesWrittenToCurrentBuffer(); + allocatedBuffer.position((pos - allocatedBuffer.arrayOffset()) + 1); + allocatedBuffer = null; + pos = 0; + limitMinusOne = 0; + } + } + + private void nextBuffer() { + nextBuffer(newHeapBuffer()); + } + + private void nextBuffer(int capacity) { + nextBuffer(newHeapBuffer(capacity)); + } + + private void nextBuffer(AllocatedBuffer allocatedBuffer) { + if (!allocatedBuffer.hasArray()) { + throw new RuntimeException("Allocator returned non-heap buffer"); + } + + finishCurrentBuffer(); + + buffers.addFirst(allocatedBuffer); + + this.allocatedBuffer = allocatedBuffer; + this.buffer = allocatedBuffer.array(); + int arrayOffset = allocatedBuffer.arrayOffset(); + this.limit = arrayOffset + allocatedBuffer.limit(); + this.offset = arrayOffset + allocatedBuffer.position(); + this.offsetMinusOne = offset - 1; + this.limitMinusOne = limit - 1; + this.pos = limitMinusOne; + } + + @Override + public int getTotalBytesWritten() { + return totalDoneBytes + bytesWrittenToCurrentBuffer(); + } + + int bytesWrittenToCurrentBuffer() { + return limitMinusOne - pos; + } + + int spaceLeft() { + return pos - offsetMinusOne; + } + + @Override + public void writeUInt32(int fieldNumber, int value) throws IOException { + requireSpace(MAX_VARINT32_SIZE * 2); + writeVarint32(value); + writeTag(fieldNumber, WIRETYPE_VARINT); + } + + @Override + public void writeInt32(int fieldNumber, int value) throws IOException { + requireSpace(MAX_VARINT32_SIZE + MAX_VARINT64_SIZE); + writeInt32(value); + writeTag(fieldNumber, WIRETYPE_VARINT); + } + + @Override + public void writeSInt32(int fieldNumber, int value) throws IOException { + requireSpace(MAX_VARINT32_SIZE * 2); + writeSInt32(value); + writeTag(fieldNumber, WIRETYPE_VARINT); + } + + @Override + public void writeFixed32(int fieldNumber, int value) throws IOException { + requireSpace(MAX_VARINT32_SIZE + FIXED32_SIZE); + writeFixed32(value); + writeTag(fieldNumber, WIRETYPE_FIXED32); + } + + @Override + public void writeUInt64(int fieldNumber, long value) throws IOException { + requireSpace(MAX_VARINT32_SIZE + MAX_VARINT64_SIZE); + writeVarint64(value); + writeTag(fieldNumber, WIRETYPE_VARINT); + } + + @Override + public void writeSInt64(int fieldNumber, long value) throws IOException { + requireSpace(MAX_VARINT32_SIZE + MAX_VARINT64_SIZE); + writeSInt64(value); + writeTag(fieldNumber, WIRETYPE_VARINT); + } + + @Override + public void writeFixed64(int fieldNumber, long value) throws IOException { + requireSpace(MAX_VARINT32_SIZE + FIXED64_SIZE); + writeFixed64(value); + writeTag(fieldNumber, WIRETYPE_FIXED64); + } + + @Override + public void writeBool(int fieldNumber, boolean value) throws IOException { + requireSpace(MAX_VARINT32_SIZE + 1); + write((byte) (value ? 1 : 0)); + writeTag(fieldNumber, WIRETYPE_VARINT); + } + + @Override + public void writeString(int fieldNumber, String value) throws IOException { + int prevBytes = getTotalBytesWritten(); + writeString(value); + int length = getTotalBytesWritten() - prevBytes; + requireSpace(2 * MAX_VARINT32_SIZE); + writeVarint32(length); + writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + } + + @Override + public void writeBytes(int fieldNumber, ByteString value) throws IOException { + try { + value.writeToReverse(this); + } catch (IOException e) { + // Should never happen since the writer does not throw. + throw new RuntimeException(e); + } + + requireSpace(MAX_VARINT32_SIZE * 2); + writeVarint32(value.size()); + writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + } + + @Override + public void writeMessage(int fieldNumber, Object value) throws IOException { + int prevBytes = getTotalBytesWritten(); + Protobuf.getInstance().writeTo(value, this); + int length = getTotalBytesWritten() - prevBytes; + requireSpace(MAX_VARINT32_SIZE * 2); + writeVarint32(length); + writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + } + + @Override + public void writeMessage(int fieldNumber, Object value, Schema schema) throws IOException { + int prevBytes = getTotalBytesWritten(); + schema.writeTo(value, this); + int length = getTotalBytesWritten() - prevBytes; + requireSpace(MAX_VARINT32_SIZE * 2); + writeVarint32(length); + writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + } + + @Override + public void writeGroup(int fieldNumber, Object value) throws IOException { + writeTag(fieldNumber, WIRETYPE_END_GROUP); + Protobuf.getInstance().writeTo(value, this); + writeTag(fieldNumber, WIRETYPE_START_GROUP); + } + + @Override + public void writeGroup(int fieldNumber, Object value, Schema schema) throws IOException { + writeTag(fieldNumber, WIRETYPE_END_GROUP); + schema.writeTo(value, this); + writeTag(fieldNumber, WIRETYPE_START_GROUP); + } + + @Override + public void writeStartGroup(int fieldNumber) { + writeTag(fieldNumber, WIRETYPE_START_GROUP); + } + + @Override + public void writeEndGroup(int fieldNumber) { + writeTag(fieldNumber, WIRETYPE_END_GROUP); + } + + @Override + void writeInt32(int value) { + if (value >= 0) { + writeVarint32(value); + } else { + writeVarint64(value); + } + } + + @Override + void writeSInt32(int value) { + writeVarint32(CodedOutputStream.encodeZigZag32(value)); + } + + @Override + void writeSInt64(long value) { + writeVarint64(CodedOutputStream.encodeZigZag64(value)); + } + + @Override + void writeBool(boolean value) { + write((byte) (value ? 1 : 0)); + } + + @Override + void writeTag(int fieldNumber, int wireType) { + writeVarint32(WireFormat.makeTag(fieldNumber, wireType)); + } + + @Override + void writeVarint32(int value) { + if ((value & (~0 << 7)) == 0) { + writeVarint32OneByte(value); + } else if ((value & (~0 << 14)) == 0) { + writeVarint32TwoBytes(value); + } else if ((value & (~0 << 21)) == 0) { + writeVarint32ThreeBytes(value); + } else if ((value & (~0 << 28)) == 0) { + writeVarint32FourBytes(value); + } else { + writeVarint32FiveBytes(value); + } + } + + private void writeVarint32OneByte(int value) { + buffer[pos--] = (byte) value; + } + + private void writeVarint32TwoBytes(int value) { + buffer[pos--] = (byte) (value >>> 7); + buffer[pos--] = (byte) ((value & 0x7F) | 0x80); + } + + private void writeVarint32ThreeBytes(int value) { + buffer[pos--] = (byte) (value >>> 14); + buffer[pos--] = (byte) (((value >>> 7) & 0x7F) | 0x80); + buffer[pos--] = (byte) ((value & 0x7F) | 0x80); + } + + private void writeVarint32FourBytes(int value) { + buffer[pos--] = (byte) (value >>> 21); + buffer[pos--] = (byte) (((value >>> 14) & 0x7F) | 0x80); + buffer[pos--] = (byte) (((value >>> 7) & 0x7F) | 0x80); + buffer[pos--] = (byte) ((value & 0x7F) | 0x80); + } + + private void writeVarint32FiveBytes(int value) { + buffer[pos--] = (byte) (value >>> 28); + buffer[pos--] = (byte) (((value >>> 21) & 0x7F) | 0x80); + buffer[pos--] = (byte) (((value >>> 14) & 0x7F) | 0x80); + buffer[pos--] = (byte) (((value >>> 7) & 0x7F) | 0x80); + buffer[pos--] = (byte) ((value & 0x7F) | 0x80); + } + + @Override + void writeVarint64(long value) { + switch (computeUInt64SizeNoTag(value)) { + case 1: + writeVarint64OneByte(value); + break; + case 2: + writeVarint64TwoBytes(value); + break; + case 3: + writeVarint64ThreeBytes(value); + break; + case 4: + writeVarint64FourBytes(value); + break; + case 5: + writeVarint64FiveBytes(value); + break; + case 6: + writeVarint64SixBytes(value); + break; + case 7: + writeVarint64SevenBytes(value); + break; + case 8: + writeVarint64EightBytes(value); + break; + case 9: + writeVarint64NineBytes(value); + break; + case 10: + writeVarint64TenBytes(value); + break; + } + } + + private void writeVarint64OneByte(long value) { + buffer[pos--] = (byte) value; + } + + private void writeVarint64TwoBytes(long value) { + buffer[pos--] = (byte) (value >>> 7); + buffer[pos--] = (byte) (((int) value & 0x7F) | 0x80); + } + + private void writeVarint64ThreeBytes(long value) { + buffer[pos--] = (byte) (((int) value) >>> 14); + buffer[pos--] = (byte) (((value >>> 7) & 0x7F) | 0x80); + buffer[pos--] = (byte) ((value & 0x7F) | 0x80); + } + + private void writeVarint64FourBytes(long value) { + buffer[pos--] = (byte) (value >>> 21); + buffer[pos--] = (byte) (((value >>> 14) & 0x7F) | 0x80); + buffer[pos--] = (byte) (((value >>> 7) & 0x7F) | 0x80); + buffer[pos--] = (byte) ((value & 0x7F) | 0x80); + } + + private void writeVarint64FiveBytes(long value) { + buffer[pos--] = (byte) (value >>> 28); + buffer[pos--] = (byte) (((value >>> 21) & 0x7F) | 0x80); + buffer[pos--] = (byte) (((value >>> 14) & 0x7F) | 0x80); + buffer[pos--] = (byte) (((value >>> 7) & 0x7F) | 0x80); + buffer[pos--] = (byte) ((value & 0x7F) | 0x80); + } + + private void writeVarint64SixBytes(long value) { + buffer[pos--] = (byte) (value >>> 35); + buffer[pos--] = (byte) (((value >>> 28) & 0x7F) | 0x80); + buffer[pos--] = (byte) (((value >>> 21) & 0x7F) | 0x80); + buffer[pos--] = (byte) (((value >>> 14) & 0x7F) | 0x80); + buffer[pos--] = (byte) (((value >>> 7) & 0x7F) | 0x80); + buffer[pos--] = (byte) ((value & 0x7F) | 0x80); + } + + private void writeVarint64SevenBytes(long value) { + buffer[pos--] = (byte) (value >>> 42); + buffer[pos--] = (byte) (((value >>> 35) & 0x7F) | 0x80); + buffer[pos--] = (byte) (((value >>> 28) & 0x7F) | 0x80); + buffer[pos--] = (byte) (((value >>> 21) & 0x7F) | 0x80); + buffer[pos--] = (byte) (((value >>> 14) & 0x7F) | 0x80); + buffer[pos--] = (byte) (((value >>> 7) & 0x7F) | 0x80); + buffer[pos--] = (byte) ((value & 0x7F) | 0x80); + } + + private void writeVarint64EightBytes(long value) { + buffer[pos--] = (byte) (value >>> 49); + buffer[pos--] = (byte) (((value >>> 42) & 0x7F) | 0x80); + buffer[pos--] = (byte) (((value >>> 35) & 0x7F) | 0x80); + buffer[pos--] = (byte) (((value >>> 28) & 0x7F) | 0x80); + buffer[pos--] = (byte) (((value >>> 21) & 0x7F) | 0x80); + buffer[pos--] = (byte) (((value >>> 14) & 0x7F) | 0x80); + buffer[pos--] = (byte) (((value >>> 7) & 0x7F) | 0x80); + buffer[pos--] = (byte) ((value & 0x7F) | 0x80); + } + + private void writeVarint64NineBytes(long value) { + buffer[pos--] = (byte) (value >>> 56); + buffer[pos--] = (byte) (((value >>> 49) & 0x7F) | 0x80); + buffer[pos--] = (byte) (((value >>> 42) & 0x7F) | 0x80); + buffer[pos--] = (byte) (((value >>> 35) & 0x7F) | 0x80); + buffer[pos--] = (byte) (((value >>> 28) & 0x7F) | 0x80); + buffer[pos--] = (byte) (((value >>> 21) & 0x7F) | 0x80); + buffer[pos--] = (byte) (((value >>> 14) & 0x7F) | 0x80); + buffer[pos--] = (byte) (((value >>> 7) & 0x7F) | 0x80); + buffer[pos--] = (byte) ((value & 0x7F) | 0x80); + } + + private void writeVarint64TenBytes(long value) { + buffer[pos--] = (byte) (value >>> 63); + buffer[pos--] = (byte) (((value >>> 56) & 0x7F) | 0x80); + buffer[pos--] = (byte) (((value >>> 49) & 0x7F) | 0x80); + buffer[pos--] = (byte) (((value >>> 42) & 0x7F) | 0x80); + buffer[pos--] = (byte) (((value >>> 35) & 0x7F) | 0x80); + buffer[pos--] = (byte) (((value >>> 28) & 0x7F) | 0x80); + buffer[pos--] = (byte) (((value >>> 21) & 0x7F) | 0x80); + buffer[pos--] = (byte) (((value >>> 14) & 0x7F) | 0x80); + buffer[pos--] = (byte) (((value >>> 7) & 0x7F) | 0x80); + buffer[pos--] = (byte) ((value & 0x7F) | 0x80); + } + + @Override + void writeFixed32(int value) { + buffer[pos--] = (byte) ((value >> 24) & 0xFF); + buffer[pos--] = (byte) ((value >> 16) & 0xFF); + buffer[pos--] = (byte) ((value >> 8) & 0xFF); + buffer[pos--] = (byte) (value & 0xFF); + } + + @Override + void writeFixed64(long value) { + buffer[pos--] = (byte) ((int) (value >> 56) & 0xFF); + buffer[pos--] = (byte) ((int) (value >> 48) & 0xFF); + buffer[pos--] = (byte) ((int) (value >> 40) & 0xFF); + buffer[pos--] = (byte) ((int) (value >> 32) & 0xFF); + buffer[pos--] = (byte) ((int) (value >> 24) & 0xFF); + buffer[pos--] = (byte) ((int) (value >> 16) & 0xFF); + buffer[pos--] = (byte) ((int) (value >> 8) & 0xFF); + buffer[pos--] = (byte) ((int) (value) & 0xFF); + } + + @Override + void writeString(String in) { + // Request enough space to write the ASCII string. + requireSpace(in.length()); + + // We know the buffer is big enough... + int i = in.length() - 1; + // Set pos to the start of the ASCII string. + pos -= i; + // Designed to take advantage of + // https://wiki.openjdk.java.net/display/HotSpotInternals/RangeCheckElimination + for (char c; i >= 0 && (c = in.charAt(i)) < 0x80; i--) { + buffer[pos + i] = (byte) c; + } + if (i == -1) { + // Move pos past the String. + pos -= 1; + return; + } + pos += i; + for (char c; i >= 0; i--) { + c = in.charAt(i); + if (c < 0x80 && pos > offsetMinusOne) { + buffer[pos--] = (byte) c; + } else if (c < 0x800 && pos > offset) { // 11 bits, two UTF-8 bytes + buffer[pos--] = (byte) (0x80 | (0x3F & c)); + buffer[pos--] = (byte) ((0xF << 6) | (c >>> 6)); + } else if ((c < Character.MIN_SURROGATE || Character.MAX_SURROGATE < c) + && pos > (offset + 1)) { + // Maximum single-char code point is 0xFFFF, 16 bits, three UTF-8 bytes + buffer[pos--] = (byte) (0x80 | (0x3F & c)); + buffer[pos--] = (byte) (0x80 | (0x3F & (c >>> 6))); + buffer[pos--] = (byte) ((0xF << 5) | (c >>> 12)); + } else if (pos > (offset + 2)) { + // Minimum code point represented by a surrogate pair is 0x10000, 17 bits, + // four UTF-8 bytes + char high = 0; + if (i == 0 || !Character.isSurrogatePair(high = in.charAt(i - 1), c)) { + throw new Utf8.UnpairedSurrogateException(i - 1, i); + } + i--; + int codePoint = Character.toCodePoint(high, c); + buffer[pos--] = (byte) (0x80 | (0x3F & codePoint)); + buffer[pos--] = (byte) (0x80 | (0x3F & (codePoint >>> 6))); + buffer[pos--] = (byte) (0x80 | (0x3F & (codePoint >>> 12))); + buffer[pos--] = (byte) ((0xF << 4) | (codePoint >>> 18)); + } else { + // Buffer is full - allocate a new one and revisit the current character. + requireSpace(i); + i++; + } + } + } + + @Override + public void write(byte value) { + buffer[pos--] = value; + } + + @Override + public void write(byte[] value, int offset, int length) { + if (spaceLeft() < length) { + nextBuffer(length); + } + + pos -= length; + System.arraycopy(value, offset, buffer, pos + 1, length); + } + + @Override + public void writeLazy(byte[] value, int offset, int length) { + if (spaceLeft() < length) { + // We consider the value to be immutable (likely the internals of a ByteString). Just + // wrap it in a Netty buffer and add it to the output buffer. + totalDoneBytes += length; + buffers.addFirst(AllocatedBuffer.wrap(value, offset, length)); + + // Advance the writer to the next buffer. + // TODO(nathanmittler): Consider slicing if space available above some threshold. + nextBuffer(); + return; + } + + pos -= length; + System.arraycopy(value, offset, buffer, pos + 1, length); + } + + @Override + public void write(ByteBuffer value) { + int length = value.remaining(); + if (spaceLeft() < length) { + nextBuffer(length); + } + + pos -= length; + value.get(buffer, pos + 1, length); + } + + @Override + public void writeLazy(ByteBuffer value) { + int length = value.remaining(); + if (spaceLeft() < length) { + // We consider the value to be immutable (likely the internals of a ByteString). Just + // wrap it in a Netty buffer and add it to the output buffer. + totalDoneBytes += length; + buffers.addFirst(AllocatedBuffer.wrap(value)); + + // Advance the writer to the next buffer. + // TODO(nathanmittler): Consider slicing if space available above some threshold. + nextBuffer(); + } + + pos -= length; + value.get(buffer, pos + 1, length); + } + + @Override + void requireSpace(int size) { + if (spaceLeft() < size) { + nextBuffer(size); + } + } + } + + /** Writer that uses unsafe operations on a target array. */ + private static final class UnsafeHeapWriter extends BinaryWriter { + private AllocatedBuffer allocatedBuffer; + private byte[] buffer; + private long offset; + private long limit; + private long offsetMinusOne; + private long limitMinusOne; + private long pos; + + UnsafeHeapWriter(BufferAllocator alloc, int chunkSize) { + super(alloc, chunkSize); + nextBuffer(); + } + + /** Indicates whether the required unsafe operations are supported on this platform. */ + static boolean isSupported() { + return UnsafeUtil.hasUnsafeArrayOperations(); + } + + @Override + void finishCurrentBuffer() { + if (allocatedBuffer != null) { + totalDoneBytes += bytesWrittenToCurrentBuffer(); + allocatedBuffer.position((arrayPos() - allocatedBuffer.arrayOffset()) + 1); + allocatedBuffer = null; + pos = 0; + limitMinusOne = 0; + } + } + + private int arrayPos() { + return (int) pos; + } + + private void nextBuffer() { + nextBuffer(newHeapBuffer()); + } + + private void nextBuffer(int capacity) { + nextBuffer(newHeapBuffer(capacity)); + } + + private void nextBuffer(AllocatedBuffer allocatedBuffer) { + if (!allocatedBuffer.hasArray()) { + throw new RuntimeException("Allocator returned non-heap buffer"); + } + + finishCurrentBuffer(); + buffers.addFirst(allocatedBuffer); + + this.allocatedBuffer = allocatedBuffer; + this.buffer = allocatedBuffer.array(); + int arrayOffset = allocatedBuffer.arrayOffset(); + this.limit = arrayOffset + allocatedBuffer.limit(); + this.offset = arrayOffset + allocatedBuffer.position(); + this.offsetMinusOne = offset - 1; + this.limitMinusOne = limit - 1; + this.pos = limitMinusOne; + } + + @Override + public int getTotalBytesWritten() { + return totalDoneBytes + bytesWrittenToCurrentBuffer(); + } + + int bytesWrittenToCurrentBuffer() { + return (int) (limitMinusOne - pos); + } + + int spaceLeft() { + return (int) (pos - offsetMinusOne); + } + + @Override + public void writeUInt32(int fieldNumber, int value) { + requireSpace(MAX_VARINT32_SIZE * 2); + writeVarint32(value); + writeTag(fieldNumber, WIRETYPE_VARINT); + } + + @Override + public void writeInt32(int fieldNumber, int value) { + requireSpace(MAX_VARINT32_SIZE + MAX_VARINT64_SIZE); + writeInt32(value); + writeTag(fieldNumber, WIRETYPE_VARINT); + } + + @Override + public void writeSInt32(int fieldNumber, int value) { + requireSpace(MAX_VARINT32_SIZE * 2); + writeSInt32(value); + writeTag(fieldNumber, WIRETYPE_VARINT); + } + + @Override + public void writeFixed32(int fieldNumber, int value) { + requireSpace(MAX_VARINT32_SIZE + FIXED32_SIZE); + writeFixed32(value); + writeTag(fieldNumber, WIRETYPE_FIXED32); + } + + @Override + public void writeUInt64(int fieldNumber, long value) { + requireSpace(MAX_VARINT32_SIZE + MAX_VARINT64_SIZE); + writeVarint64(value); + writeTag(fieldNumber, WIRETYPE_VARINT); + } + + @Override + public void writeSInt64(int fieldNumber, long value) { + requireSpace(MAX_VARINT32_SIZE + MAX_VARINT64_SIZE); + writeSInt64(value); + writeTag(fieldNumber, WIRETYPE_VARINT); + } + + @Override + public void writeFixed64(int fieldNumber, long value) { + requireSpace(MAX_VARINT32_SIZE + FIXED64_SIZE); + writeFixed64(value); + writeTag(fieldNumber, WIRETYPE_FIXED64); + } + + @Override + public void writeBool(int fieldNumber, boolean value) { + requireSpace(MAX_VARINT32_SIZE + 1); + write((byte) (value ? 1 : 0)); + writeTag(fieldNumber, WIRETYPE_VARINT); + } + + @Override + public void writeString(int fieldNumber, String value) { + int prevBytes = getTotalBytesWritten(); + writeString(value); + int length = getTotalBytesWritten() - prevBytes; + requireSpace(2 * MAX_VARINT32_SIZE); + writeVarint32(length); + writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + } + + @Override + public void writeBytes(int fieldNumber, ByteString value) { + try { + value.writeToReverse(this); + } catch (IOException e) { + // Should never happen since the writer does not throw. + throw new RuntimeException(e); + } + + requireSpace(MAX_VARINT32_SIZE * 2); + writeVarint32(value.size()); + writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + } + + @Override + public void writeMessage(int fieldNumber, Object value) throws IOException { + int prevBytes = getTotalBytesWritten(); + Protobuf.getInstance().writeTo(value, this); + int length = getTotalBytesWritten() - prevBytes; + requireSpace(MAX_VARINT32_SIZE * 2); + writeVarint32(length); + writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + } + + @Override + public void writeMessage(int fieldNumber, Object value, Schema schema) throws IOException { + int prevBytes = getTotalBytesWritten(); + schema.writeTo(value, this); + int length = getTotalBytesWritten() - prevBytes; + requireSpace(MAX_VARINT32_SIZE * 2); + writeVarint32(length); + writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + } + + @Override + public void writeGroup(int fieldNumber, Object value) throws IOException { + writeTag(fieldNumber, WIRETYPE_END_GROUP); + Protobuf.getInstance().writeTo(value, this); + writeTag(fieldNumber, WIRETYPE_START_GROUP); + } + + @Override + public void writeGroup(int fieldNumber, Object value, Schema schema) throws IOException { + writeTag(fieldNumber, WIRETYPE_END_GROUP); + schema.writeTo(value, this); + writeTag(fieldNumber, WIRETYPE_START_GROUP); + } + + @Override + public void writeStartGroup(int fieldNumber) { + writeTag(fieldNumber, WIRETYPE_START_GROUP); + } + + @Override + public void writeEndGroup(int fieldNumber) { + writeTag(fieldNumber, WIRETYPE_END_GROUP); + } + + @Override + void writeInt32(int value) { + if (value >= 0) { + writeVarint32(value); + } else { + writeVarint64(value); + } + } + + @Override + void writeSInt32(int value) { + writeVarint32(CodedOutputStream.encodeZigZag32(value)); + } + + @Override + void writeSInt64(long value) { + writeVarint64(CodedOutputStream.encodeZigZag64(value)); + } + + @Override + void writeBool(boolean value) { + write((byte) (value ? 1 : 0)); + } + + @Override + void writeTag(int fieldNumber, int wireType) { + writeVarint32(WireFormat.makeTag(fieldNumber, wireType)); + } + + @Override + void writeVarint32(int value) { + if ((value & (~0 << 7)) == 0) { + writeVarint32OneByte(value); + } else if ((value & (~0 << 14)) == 0) { + writeVarint32TwoBytes(value); + } else if ((value & (~0 << 21)) == 0) { + writeVarint32ThreeBytes(value); + } else if ((value & (~0 << 28)) == 0) { + writeVarint32FourBytes(value); + } else { + writeVarint32FiveBytes(value); + } + } + + private void writeVarint32OneByte(int value) { + UnsafeUtil.putByte(buffer, pos--, (byte) value); + } + + private void writeVarint32TwoBytes(int value) { + UnsafeUtil.putByte(buffer, pos--, (byte) (value >>> 7)); + UnsafeUtil.putByte(buffer, pos--, (byte) ((value & 0x7F) | 0x80)); + } + + private void writeVarint32ThreeBytes(int value) { + UnsafeUtil.putByte(buffer, pos--, (byte) (value >>> 14)); + UnsafeUtil.putByte(buffer, pos--, (byte) (((value >>> 7) & 0x7F) | 0x80)); + UnsafeUtil.putByte(buffer, pos--, (byte) ((value & 0x7F) | 0x80)); + } + + private void writeVarint32FourBytes(int value) { + UnsafeUtil.putByte(buffer, pos--, (byte) (value >>> 21)); + UnsafeUtil.putByte(buffer, pos--, (byte) (((value >>> 14) & 0x7F) | 0x80)); + UnsafeUtil.putByte(buffer, pos--, (byte) (((value >>> 7) & 0x7F) | 0x80)); + UnsafeUtil.putByte(buffer, pos--, (byte) ((value & 0x7F) | 0x80)); + } + + private void writeVarint32FiveBytes(int value) { + UnsafeUtil.putByte(buffer, pos--, (byte) (value >>> 28)); + UnsafeUtil.putByte(buffer, pos--, (byte) (((value >>> 21) & 0x7F) | 0x80)); + UnsafeUtil.putByte(buffer, pos--, (byte) (((value >>> 14) & 0x7F) | 0x80)); + UnsafeUtil.putByte(buffer, pos--, (byte) (((value >>> 7) & 0x7F) | 0x80)); + UnsafeUtil.putByte(buffer, pos--, (byte) ((value & 0x7F) | 0x80)); + } + + @Override + void writeVarint64(long value) { + switch (computeUInt64SizeNoTag(value)) { + case 1: + writeVarint64OneByte(value); + break; + case 2: + writeVarint64TwoBytes(value); + break; + case 3: + writeVarint64ThreeBytes(value); + break; + case 4: + writeVarint64FourBytes(value); + break; + case 5: + writeVarint64FiveBytes(value); + break; + case 6: + writeVarint64SixBytes(value); + break; + case 7: + writeVarint64SevenBytes(value); + break; + case 8: + writeVarint64EightBytes(value); + break; + case 9: + writeVarint64NineBytes(value); + break; + case 10: + writeVarint64TenBytes(value); + break; + } + } + + private void writeVarint64OneByte(long value) { + UnsafeUtil.putByte(buffer, pos--, (byte) value); + } + + private void writeVarint64TwoBytes(long value) { + UnsafeUtil.putByte(buffer, pos--, (byte) (value >>> 7)); + UnsafeUtil.putByte(buffer, pos--, (byte) (((int) value & 0x7F) | 0x80)); + } + + private void writeVarint64ThreeBytes(long value) { + UnsafeUtil.putByte(buffer, pos--, (byte) (((int) value) >>> 14)); + UnsafeUtil.putByte(buffer, pos--, (byte) (((value >>> 7) & 0x7F) | 0x80)); + UnsafeUtil.putByte(buffer, pos--, (byte) ((value & 0x7F) | 0x80)); + } + + private void writeVarint64FourBytes(long value) { + UnsafeUtil.putByte(buffer, pos--, (byte) (value >>> 21)); + UnsafeUtil.putByte(buffer, pos--, (byte) (((value >>> 14) & 0x7F) | 0x80)); + UnsafeUtil.putByte(buffer, pos--, (byte) (((value >>> 7) & 0x7F) | 0x80)); + UnsafeUtil.putByte(buffer, pos--, (byte) ((value & 0x7F) | 0x80)); + } + + private void writeVarint64FiveBytes(long value) { + UnsafeUtil.putByte(buffer, pos--, (byte) (value >>> 28)); + UnsafeUtil.putByte(buffer, pos--, (byte) (((value >>> 21) & 0x7F) | 0x80)); + UnsafeUtil.putByte(buffer, pos--, (byte) (((value >>> 14) & 0x7F) | 0x80)); + UnsafeUtil.putByte(buffer, pos--, (byte) (((value >>> 7) & 0x7F) | 0x80)); + UnsafeUtil.putByte(buffer, pos--, (byte) ((value & 0x7F) | 0x80)); + } + + private void writeVarint64SixBytes(long value) { + UnsafeUtil.putByte(buffer, pos--, (byte) (value >>> 35)); + UnsafeUtil.putByte(buffer, pos--, (byte) (((value >>> 28) & 0x7F) | 0x80)); + UnsafeUtil.putByte(buffer, pos--, (byte) (((value >>> 21) & 0x7F) | 0x80)); + UnsafeUtil.putByte(buffer, pos--, (byte) (((value >>> 14) & 0x7F) | 0x80)); + UnsafeUtil.putByte(buffer, pos--, (byte) (((value >>> 7) & 0x7F) | 0x80)); + UnsafeUtil.putByte(buffer, pos--, (byte) ((value & 0x7F) | 0x80)); + } + + private void writeVarint64SevenBytes(long value) { + UnsafeUtil.putByte(buffer, pos--, (byte) (value >>> 42)); + UnsafeUtil.putByte(buffer, pos--, (byte) (((value >>> 35) & 0x7F) | 0x80)); + UnsafeUtil.putByte(buffer, pos--, (byte) (((value >>> 28) & 0x7F) | 0x80)); + UnsafeUtil.putByte(buffer, pos--, (byte) (((value >>> 21) & 0x7F) | 0x80)); + UnsafeUtil.putByte(buffer, pos--, (byte) (((value >>> 14) & 0x7F) | 0x80)); + UnsafeUtil.putByte(buffer, pos--, (byte) (((value >>> 7) & 0x7F) | 0x80)); + UnsafeUtil.putByte(buffer, pos--, (byte) ((value & 0x7F) | 0x80)); + } + + private void writeVarint64EightBytes(long value) { + UnsafeUtil.putByte(buffer, pos--, (byte) (value >>> 49)); + UnsafeUtil.putByte(buffer, pos--, (byte) (((value >>> 42) & 0x7F) | 0x80)); + UnsafeUtil.putByte(buffer, pos--, (byte) (((value >>> 35) & 0x7F) | 0x80)); + UnsafeUtil.putByte(buffer, pos--, (byte) (((value >>> 28) & 0x7F) | 0x80)); + UnsafeUtil.putByte(buffer, pos--, (byte) (((value >>> 21) & 0x7F) | 0x80)); + UnsafeUtil.putByte(buffer, pos--, (byte) (((value >>> 14) & 0x7F) | 0x80)); + UnsafeUtil.putByte(buffer, pos--, (byte) (((value >>> 7) & 0x7F) | 0x80)); + UnsafeUtil.putByte(buffer, pos--, (byte) ((value & 0x7F) | 0x80)); + } + + private void writeVarint64NineBytes(long value) { + UnsafeUtil.putByte(buffer, pos--, (byte) (value >>> 56)); + UnsafeUtil.putByte(buffer, pos--, (byte) (((value >>> 49) & 0x7F) | 0x80)); + UnsafeUtil.putByte(buffer, pos--, (byte) (((value >>> 42) & 0x7F) | 0x80)); + UnsafeUtil.putByte(buffer, pos--, (byte) (((value >>> 35) & 0x7F) | 0x80)); + UnsafeUtil.putByte(buffer, pos--, (byte) (((value >>> 28) & 0x7F) | 0x80)); + UnsafeUtil.putByte(buffer, pos--, (byte) (((value >>> 21) & 0x7F) | 0x80)); + UnsafeUtil.putByte(buffer, pos--, (byte) (((value >>> 14) & 0x7F) | 0x80)); + UnsafeUtil.putByte(buffer, pos--, (byte) (((value >>> 7) & 0x7F) | 0x80)); + UnsafeUtil.putByte(buffer, pos--, (byte) ((value & 0x7F) | 0x80)); + } + + private void writeVarint64TenBytes(long value) { + UnsafeUtil.putByte(buffer, pos--, (byte) (value >>> 63)); + UnsafeUtil.putByte(buffer, pos--, (byte) (((value >>> 56) & 0x7F) | 0x80)); + UnsafeUtil.putByte(buffer, pos--, (byte) (((value >>> 49) & 0x7F) | 0x80)); + UnsafeUtil.putByte(buffer, pos--, (byte) (((value >>> 42) & 0x7F) | 0x80)); + UnsafeUtil.putByte(buffer, pos--, (byte) (((value >>> 35) & 0x7F) | 0x80)); + UnsafeUtil.putByte(buffer, pos--, (byte) (((value >>> 28) & 0x7F) | 0x80)); + UnsafeUtil.putByte(buffer, pos--, (byte) (((value >>> 21) & 0x7F) | 0x80)); + UnsafeUtil.putByte(buffer, pos--, (byte) (((value >>> 14) & 0x7F) | 0x80)); + UnsafeUtil.putByte(buffer, pos--, (byte) (((value >>> 7) & 0x7F) | 0x80)); + UnsafeUtil.putByte(buffer, pos--, (byte) ((value & 0x7F) | 0x80)); + } + + @Override + void writeFixed32(int value) { + UnsafeUtil.putByte(buffer, pos--, (byte) ((value >> 24) & 0xFF)); + UnsafeUtil.putByte(buffer, pos--, (byte) ((value >> 16) & 0xFF)); + UnsafeUtil.putByte(buffer, pos--, (byte) ((value >> 8) & 0xFF)); + UnsafeUtil.putByte(buffer, pos--, (byte) (value & 0xFF)); + } + + @Override + void writeFixed64(long value) { + UnsafeUtil.putByte(buffer, pos--, (byte) ((int) (value >> 56) & 0xFF)); + UnsafeUtil.putByte(buffer, pos--, (byte) ((int) (value >> 48) & 0xFF)); + UnsafeUtil.putByte(buffer, pos--, (byte) ((int) (value >> 40) & 0xFF)); + UnsafeUtil.putByte(buffer, pos--, (byte) ((int) (value >> 32) & 0xFF)); + UnsafeUtil.putByte(buffer, pos--, (byte) ((int) (value >> 24) & 0xFF)); + UnsafeUtil.putByte(buffer, pos--, (byte) ((int) (value >> 16) & 0xFF)); + UnsafeUtil.putByte(buffer, pos--, (byte) ((int) (value >> 8) & 0xFF)); + UnsafeUtil.putByte(buffer, pos--, (byte) ((int) (value) & 0xFF)); + } + + @Override + void writeString(String in) { + // Request enough space to write the ASCII string. + requireSpace(in.length()); + + // We know the buffer is big enough... + int i = in.length() - 1; + // Set pos to the start of the ASCII string. + // pos -= i; + // Designed to take advantage of + // https://wiki.openjdk.java.net/display/HotSpotInternals/RangeCheckElimination + for (char c; i >= 0 && (c = in.charAt(i)) < 0x80; i--) { + UnsafeUtil.putByte(buffer, pos--, (byte) c); + } + if (i == -1) { + // Move pos past the String. + return; + } + for (char c; i >= 0; i--) { + c = in.charAt(i); + if (c < 0x80 && pos > offsetMinusOne) { + UnsafeUtil.putByte(buffer, pos--, (byte) c); + } else if (c < 0x800 && pos > offset) { // 11 bits, two UTF-8 bytes + UnsafeUtil.putByte(buffer, pos--, (byte) (0x80 | (0x3F & c))); + UnsafeUtil.putByte(buffer, pos--, (byte) ((0xF << 6) | (c >>> 6))); + } else if ((c < Character.MIN_SURROGATE || Character.MAX_SURROGATE < c) + && pos > offset + 1) { + // Maximum single-char code point is 0xFFFF, 16 bits, three UTF-8 bytes + UnsafeUtil.putByte(buffer, pos--, (byte) (0x80 | (0x3F & c))); + UnsafeUtil.putByte(buffer, pos--, (byte) (0x80 | (0x3F & (c >>> 6)))); + UnsafeUtil.putByte(buffer, pos--, (byte) ((0xF << 5) | (c >>> 12))); + } else if (pos > offset + 2) { + // Minimum code point represented by a surrogate pair is 0x10000, 17 bits, + // four UTF-8 bytes + final char high; + if (i == 0 || !Character.isSurrogatePair(high = in.charAt(i - 1), c)) { + throw new Utf8.UnpairedSurrogateException(i - 1, i); + } + i--; + int codePoint = Character.toCodePoint(high, c); + UnsafeUtil.putByte(buffer, pos--, (byte) (0x80 | (0x3F & codePoint))); + UnsafeUtil.putByte(buffer, pos--, (byte) (0x80 | (0x3F & (codePoint >>> 6)))); + UnsafeUtil.putByte(buffer, pos--, (byte) (0x80 | (0x3F & (codePoint >>> 12)))); + UnsafeUtil.putByte(buffer, pos--, (byte) ((0xF << 4) | (codePoint >>> 18))); + } else { + // Buffer is full - allocate a new one and revisit the current character. + requireSpace(i); + i++; + } + } + } + + @Override + public void write(byte value) { + UnsafeUtil.putByte(buffer, pos--, value); + } + + @Override + public void write(byte[] value, int offset, int length) { + if (offset < 0 || offset + length > value.length) { + throw new ArrayIndexOutOfBoundsException( + String.format("value.length=%d, offset=%d, length=%d", value.length, offset, length)); + } + requireSpace(length); + + pos -= length; + System.arraycopy(value, offset, buffer, arrayPos() + 1, length); + } + + @Override + public void writeLazy(byte[] value, int offset, int length) { + if (offset < 0 || offset + length > value.length) { + throw new ArrayIndexOutOfBoundsException( + String.format("value.length=%d, offset=%d, length=%d", value.length, offset, length)); + } + if (spaceLeft() < length) { + // We consider the value to be immutable (likely the internals of a ByteString). Just + // wrap it in a Netty buffer and add it to the output buffer. + totalDoneBytes += length; + buffers.addFirst(AllocatedBuffer.wrap(value, offset, length)); + + // Advance the writer to the next buffer. + // TODO(nathanmittler): Consider slicing if space available above some threshold. + nextBuffer(); + return; + } + + pos -= length; + System.arraycopy(value, offset, buffer, arrayPos() + 1, length); + } + + @Override + public void write(ByteBuffer value) { + int length = value.remaining(); + requireSpace(length); + + pos -= length; + value.get(buffer, arrayPos() + 1, length); + } + + @Override + public void writeLazy(ByteBuffer value) { + int length = value.remaining(); + if (spaceLeft() < length) { + // We consider the value to be immutable (likely the internals of a ByteString). Just + // wrap it in a Netty buffer and add it to the output buffer. + totalDoneBytes += length; + buffers.addFirst(AllocatedBuffer.wrap(value)); + + // Advance the writer to the next buffer. + // TODO(nathanmittler): Consider slicing if space available above some threshold. + nextBuffer(); + } + + pos -= length; + value.get(buffer, arrayPos() + 1, length); + } + + @Override + void requireSpace(int size) { + if (spaceLeft() < size) { + nextBuffer(size); + } + } + } + + /** Writer that uses safe operations on a target {@link ByteBuffer}. */ + private static final class SafeDirectWriter extends BinaryWriter { + private ByteBuffer buffer; + private int limitMinusOne; + private int pos; + + SafeDirectWriter(BufferAllocator alloc, int chunkSize) { + super(alloc, chunkSize); + nextBuffer(); + } + + private void nextBuffer() { + nextBuffer(newDirectBuffer()); + } + + private void nextBuffer(int capacity) { + nextBuffer(newDirectBuffer(capacity)); + } + + private void nextBuffer(AllocatedBuffer allocatedBuffer) { + if (!allocatedBuffer.hasNioBuffer()) { + throw new RuntimeException("Allocated buffer does not have NIO buffer"); + } + ByteBuffer nioBuffer = allocatedBuffer.nioBuffer(); + if (!nioBuffer.isDirect()) { + throw new RuntimeException("Allocator returned non-direct buffer"); + } + + finishCurrentBuffer(); + buffers.addFirst(allocatedBuffer); + + buffer = nioBuffer; + buffer.limit(buffer.capacity()); + buffer.position(0); + // Set byte order to little endian for fast writing of fixed 32/64. + buffer.order(ByteOrder.LITTLE_ENDIAN); + + limitMinusOne = buffer.limit() - 1; + pos = limitMinusOne; + } + + @Override + public int getTotalBytesWritten() { + return totalDoneBytes + bytesWrittenToCurrentBuffer(); + } + + private int bytesWrittenToCurrentBuffer() { + return limitMinusOne - pos; + } + + private int spaceLeft() { + return pos + 1; + } + + @Override + void finishCurrentBuffer() { + if (buffer != null) { + totalDoneBytes += bytesWrittenToCurrentBuffer(); + // Update the indices on the netty buffer. + buffer.position(pos + 1); + buffer = null; + pos = 0; + limitMinusOne = 0; + } + } + + @Override + public void writeUInt32(int fieldNumber, int value) { + requireSpace(MAX_VARINT32_SIZE * 2); + writeVarint32(value); + writeTag(fieldNumber, WIRETYPE_VARINT); + } + + @Override + public void writeInt32(int fieldNumber, int value) { + requireSpace(MAX_VARINT32_SIZE + MAX_VARINT64_SIZE); + writeInt32(value); + writeTag(fieldNumber, WIRETYPE_VARINT); + } + + @Override + public void writeSInt32(int fieldNumber, int value) { + requireSpace(MAX_VARINT32_SIZE * 2); + writeSInt32(value); + writeTag(fieldNumber, WIRETYPE_VARINT); + } + + @Override + public void writeFixed32(int fieldNumber, int value) { + requireSpace(MAX_VARINT32_SIZE + FIXED32_SIZE); + writeFixed32(value); + writeTag(fieldNumber, WIRETYPE_FIXED32); + } + + @Override + public void writeUInt64(int fieldNumber, long value) { + requireSpace(MAX_VARINT32_SIZE + MAX_VARINT64_SIZE); + writeVarint64(value); + writeTag(fieldNumber, WIRETYPE_VARINT); + } + + @Override + public void writeSInt64(int fieldNumber, long value) { + requireSpace(MAX_VARINT32_SIZE + MAX_VARINT64_SIZE); + writeSInt64(value); + writeTag(fieldNumber, WIRETYPE_VARINT); + } + + @Override + public void writeFixed64(int fieldNumber, long value) { + requireSpace(MAX_VARINT32_SIZE + FIXED64_SIZE); + writeFixed64(value); + writeTag(fieldNumber, WIRETYPE_FIXED64); + } + + @Override + public void writeBool(int fieldNumber, boolean value) { + requireSpace(MAX_VARINT32_SIZE + 1); + write((byte) (value ? 1 : 0)); + writeTag(fieldNumber, WIRETYPE_VARINT); + } + + @Override + public void writeString(int fieldNumber, String value) { + int prevBytes = getTotalBytesWritten(); + writeString(value); + int length = getTotalBytesWritten() - prevBytes; + requireSpace(2 * MAX_VARINT32_SIZE); + writeVarint32(length); + writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + } + + @Override + public void writeBytes(int fieldNumber, ByteString value) { + try { + value.writeToReverse(this); + } catch (IOException e) { + // Should never happen since the writer does not throw. + throw new RuntimeException(e); + } + + requireSpace(MAX_VARINT32_SIZE * 2); + writeVarint32(value.size()); + writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + } + + @Override + public void writeMessage(int fieldNumber, Object value) throws IOException { + int prevBytes = getTotalBytesWritten(); + Protobuf.getInstance().writeTo(value, this); + int length = getTotalBytesWritten() - prevBytes; + requireSpace(MAX_VARINT32_SIZE * 2); + writeVarint32(length); + writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + } + + @Override + public void writeMessage(int fieldNumber, Object value, Schema schema) throws IOException { + int prevBytes = getTotalBytesWritten(); + schema.writeTo(value, this); + int length = getTotalBytesWritten() - prevBytes; + requireSpace(MAX_VARINT32_SIZE * 2); + writeVarint32(length); + writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + } + + @Override + public void writeGroup(int fieldNumber, Object value) throws IOException { + writeTag(fieldNumber, WIRETYPE_END_GROUP); + Protobuf.getInstance().writeTo(value, this); + writeTag(fieldNumber, WIRETYPE_START_GROUP); + } + + @Override + public void writeGroup(int fieldNumber, Object value, Schema schema) throws IOException { + writeTag(fieldNumber, WIRETYPE_END_GROUP); + schema.writeTo(value, this); + writeTag(fieldNumber, WIRETYPE_START_GROUP); + } + + @Override + public void writeStartGroup(int fieldNumber) { + writeTag(fieldNumber, WIRETYPE_START_GROUP); + } + + @Override + public void writeEndGroup(int fieldNumber) { + writeTag(fieldNumber, WIRETYPE_END_GROUP); + } + + @Override + void writeInt32(int value) { + if (value >= 0) { + writeVarint32(value); + } else { + writeVarint64(value); + } + } + + @Override + void writeSInt32(int value) { + writeVarint32(CodedOutputStream.encodeZigZag32(value)); + } + + @Override + void writeSInt64(long value) { + writeVarint64(CodedOutputStream.encodeZigZag64(value)); + } + + @Override + void writeBool(boolean value) { + write((byte) (value ? 1 : 0)); + } + + @Override + void writeTag(int fieldNumber, int wireType) { + writeVarint32(WireFormat.makeTag(fieldNumber, wireType)); + } + + @Override + void writeVarint32(int value) { + if ((value & (~0 << 7)) == 0) { + writeVarint32OneByte(value); + } else if ((value & (~0 << 14)) == 0) { + writeVarint32TwoBytes(value); + } else if ((value & (~0 << 21)) == 0) { + writeVarint32ThreeBytes(value); + } else if ((value & (~0 << 28)) == 0) { + writeVarint32FourBytes(value); + } else { + writeVarint32FiveBytes(value); + } + } + + private void writeVarint32OneByte(int value) { + buffer.put(pos--, (byte) value); + } + + private void writeVarint32TwoBytes(int value) { + // Byte order is little-endian. + pos -= 2; + buffer.putShort(pos + 1, (short) (((value & (0x7F << 7)) << 1) | ((value & 0x7F) | 0x80))); + } + + private void writeVarint32ThreeBytes(int value) { + // Byte order is little-endian. + pos -= 3; + buffer.putInt( + pos, + ((value & (0x7F << 14)) << 10) + | (((value & (0x7F << 7)) | (0x80 << 7)) << 9) + | ((value & 0x7F) | 0x80) << 8); + } + + private void writeVarint32FourBytes(int value) { + // Byte order is little-endian. + pos -= 4; + buffer.putInt( + pos + 1, + ((value & (0x7F << 21)) << 3) + | (((value & (0x7F << 14)) | (0x80 << 14)) << 2) + | (((value & (0x7F << 7)) | (0x80 << 7)) << 1) + | ((value & 0x7F) | 0x80)); + } + + private void writeVarint32FiveBytes(int value) { + // Byte order is little-endian. + buffer.put(pos--, (byte) (value >>> 28)); + pos -= 4; + buffer.putInt( + pos + 1, + ((((value >>> 21) & 0x7F) | 0x80) << 24) + | ((((value >>> 14) & 0x7F) | 0x80) << 16) + | ((((value >>> 7) & 0x7F) | 0x80) << 8) + | ((value & 0x7F) | 0x80)); + } + + @Override + void writeVarint64(long value) { + switch (computeUInt64SizeNoTag(value)) { + case 1: + writeVarint64OneByte(value); + break; + case 2: + writeVarint64TwoBytes(value); + break; + case 3: + writeVarint64ThreeBytes(value); + break; + case 4: + writeVarint64FourBytes(value); + break; + case 5: + writeVarint64FiveBytes(value); + break; + case 6: + writeVarint64SixBytes(value); + break; + case 7: + writeVarint64SevenBytes(value); + break; + case 8: + writeVarint64EightBytes(value); + break; + case 9: + writeVarint64NineBytes(value); + break; + case 10: + writeVarint64TenBytes(value); + break; + } + } + + private void writeVarint64OneByte(long value) { + writeVarint32OneByte((int) value); + } + + private void writeVarint64TwoBytes(long value) { + writeVarint32TwoBytes((int) value); + } + + private void writeVarint64ThreeBytes(long value) { + writeVarint32ThreeBytes((int) value); + } + + private void writeVarint64FourBytes(long value) { + writeVarint32FourBytes((int) value); + } + + private void writeVarint64FiveBytes(long value) { + // Byte order is little-endian. + pos -= 5; + buffer.putLong( + pos - 2, + ((value & (0x7FL << 28)) << 28) + | (((value & (0x7F << 21)) | (0x80 << 21)) << 27) + | (((value & (0x7F << 14)) | (0x80 << 14)) << 26) + | (((value & (0x7F << 7)) | (0x80 << 7)) << 25) + | (((value & 0x7F) | 0x80)) << 24); + } + + private void writeVarint64SixBytes(long value) { + // Byte order is little-endian. + pos -= 6; + buffer.putLong( + pos - 1, + ((value & (0x7FL << 35)) << 21) + | (((value & (0x7FL << 28)) | (0x80L << 28)) << 20) + | (((value & (0x7F << 21)) | (0x80 << 21)) << 19) + | (((value & (0x7F << 14)) | (0x80 << 14)) << 18) + | (((value & (0x7F << 7)) | (0x80 << 7)) << 17) + | (((value & 0x7F) | 0x80)) << 16); + } + + private void writeVarint64SevenBytes(long value) { + // Byte order is little-endian. + pos -= 7; + buffer.putLong( + pos, + ((value & (0x7FL << 42)) << 14) + | (((value & (0x7FL << 35)) | (0x80L << 35)) << 13) + | (((value & (0x7FL << 28)) | (0x80L << 28)) << 12) + | (((value & (0x7F << 21)) | (0x80 << 21)) << 11) + | (((value & (0x7F << 14)) | (0x80 << 14)) << 10) + | (((value & (0x7F << 7)) | (0x80 << 7)) << 9) + | (((value & 0x7F) | 0x80)) << 8); + } + + private void writeVarint64EightBytes(long value) { + // Byte order is little-endian. + pos -= 8; + buffer.putLong( + pos + 1, + ((value & (0x7FL << 49)) << 7) + | (((value & (0x7FL << 42)) | (0x80L << 42)) << 6) + | (((value & (0x7FL << 35)) | (0x80L << 35)) << 5) + | (((value & (0x7FL << 28)) | (0x80L << 28)) << 4) + | (((value & (0x7F << 21)) | (0x80 << 21)) << 3) + | (((value & (0x7F << 14)) | (0x80 << 14)) << 2) + | (((value & (0x7F << 7)) | (0x80 << 7)) << 1) + | ((value & 0x7F) | 0x80)); + } + + private void writeVarint64EightBytesWithSign(long value) { + // Byte order is little-endian. + pos -= 8; + buffer.putLong( + pos + 1, + (((value & (0x7FL << 49)) | (0x80L << 49)) << 7) + | (((value & (0x7FL << 42)) | (0x80L << 42)) << 6) + | (((value & (0x7FL << 35)) | (0x80L << 35)) << 5) + | (((value & (0x7FL << 28)) | (0x80L << 28)) << 4) + | (((value & (0x7F << 21)) | (0x80 << 21)) << 3) + | (((value & (0x7F << 14)) | (0x80 << 14)) << 2) + | (((value & (0x7F << 7)) | (0x80 << 7)) << 1) + | ((value & 0x7F) | 0x80)); + } + + private void writeVarint64NineBytes(long value) { + buffer.put(pos--, (byte) (value >>> 56)); + writeVarint64EightBytesWithSign(value & 0xFFFFFFFFFFFFFFL); + } + + private void writeVarint64TenBytes(long value) { + buffer.put(pos--, (byte) (value >>> 63)); + buffer.put(pos--, (byte) (((value >>> 56) & 0x7F) | 0x80)); + writeVarint64EightBytesWithSign(value & 0xFFFFFFFFFFFFFFL); + } + + @Override + void writeFixed32(int value) { + pos -= 4; + buffer.putInt(pos + 1, value); + } + + @Override + void writeFixed64(long value) { + pos -= 8; + buffer.putLong(pos + 1, value); + } + + @Override + void writeString(String in) { + // Request enough space to write the ASCII string. + requireSpace(in.length()); + + // We know the buffer is big enough... + int i = in.length() - 1; + pos -= i; + // Designed to take advantage of + // https://wiki.openjdk.java.net/display/HotSpotInternals/RangeCheckElimination + for (char c; i >= 0 && (c = in.charAt(i)) < 0x80; i--) { + buffer.put(pos + i, (byte) c); + } + if (i == -1) { + // Move the position past the ASCII string. + pos -= 1; + return; + } + pos += i; + for (char c; i >= 0; i--) { + c = in.charAt(i); + if (c < 0x80 && pos >= 0) { + buffer.put(pos--, (byte) c); + } else if (c < 0x800 && pos > 0) { // 11 bits, two UTF-8 bytes + buffer.put(pos--, (byte) (0x80 | (0x3F & c))); + buffer.put(pos--, (byte) ((0xF << 6) | (c >>> 6))); + } else if ((c < Character.MIN_SURROGATE || Character.MAX_SURROGATE < c) && pos > 1) { + // Maximum single-char code point is 0xFFFF, 16 bits, three UTF-8 bytes + buffer.put(pos--, (byte) (0x80 | (0x3F & c))); + buffer.put(pos--, (byte) (0x80 | (0x3F & (c >>> 6)))); + buffer.put(pos--, (byte) ((0xF << 5) | (c >>> 12))); + } else if (pos > 2) { + // Minimum code point represented by a surrogate pair is 0x10000, 17 bits, + // four UTF-8 bytes + char high = 0; + if (i == 0 || !Character.isSurrogatePair(high = in.charAt(i - 1), c)) { + throw new Utf8.UnpairedSurrogateException(i - 1, i); + } + i--; + int codePoint = Character.toCodePoint(high, c); + buffer.put(pos--, (byte) (0x80 | (0x3F & codePoint))); + buffer.put(pos--, (byte) (0x80 | (0x3F & (codePoint >>> 6)))); + buffer.put(pos--, (byte) (0x80 | (0x3F & (codePoint >>> 12)))); + buffer.put(pos--, (byte) ((0xF << 4) | (codePoint >>> 18))); + } else { + // Buffer is full - allocate a new one and revisit the current character. + requireSpace(i); + i++; + } + } + } + + @Override + public void write(byte value) { + buffer.put(pos--, value); + } + + @Override + public void write(byte[] value, int offset, int length) { + if (spaceLeft() < length) { + nextBuffer(length); + } + + pos -= length; + buffer.position(pos + 1); + buffer.put(value, offset, length); + } + + @Override + public void writeLazy(byte[] value, int offset, int length) { + if (spaceLeft() < length) { + // We consider the value to be immutable (likely the internals of a ByteString). Just + // wrap it in a Netty buffer and add it to the output buffer. + totalDoneBytes += length; + buffers.addFirst(AllocatedBuffer.wrap(value, offset, length)); + + // Advance the writer to the next buffer. + // TODO(nathanmittler): Consider slicing if space available above some threshold. + nextBuffer(); + return; + } + + pos -= length; + buffer.position(pos + 1); + buffer.put(value, offset, length); + } + + @Override + public void write(ByteBuffer value) { + int length = value.remaining(); + if (spaceLeft() < length) { + nextBuffer(length); + } + + pos -= length; + buffer.position(pos + 1); + buffer.put(value); + } + + @Override + public void writeLazy(ByteBuffer value) { + int length = value.remaining(); + if (spaceLeft() < length) { + // We consider the value to be immutable (likely the internals of a ByteString). Just + // wrap it in a Netty buffer and add it to the output buffer. + totalDoneBytes += length; + buffers.addFirst(AllocatedBuffer.wrap(value)); + + // Advance the writer to the next buffer. + // TODO(nathanmittler): Consider slicing if space available above some threshold. + nextBuffer(); + return; + } + + pos -= length; + buffer.position(pos + 1); + buffer.put(value); + } + + @Override + void requireSpace(int size) { + if (spaceLeft() < size) { + nextBuffer(size); + } + } + } + + /** Writer that uses unsafe operations on a target {@link ByteBuffer}. */ + private static final class UnsafeDirectWriter extends BinaryWriter { + private ByteBuffer buffer; + private long bufferOffset; + private long limitMinusOne; + private long pos; + + UnsafeDirectWriter(BufferAllocator alloc, int chunkSize) { + super(alloc, chunkSize); + nextBuffer(); + } + + /** Indicates whether the required unsafe operations are supported on this platform. */ + private static boolean isSupported() { + return UnsafeUtil.hasUnsafeByteBufferOperations(); + } + + private void nextBuffer() { + nextBuffer(newDirectBuffer()); + } + + private void nextBuffer(int capacity) { + nextBuffer(newDirectBuffer(capacity)); + } + + private void nextBuffer(AllocatedBuffer allocatedBuffer) { + if (!allocatedBuffer.hasNioBuffer()) { + throw new RuntimeException("Allocated buffer does not have NIO buffer"); + } + ByteBuffer nioBuffer = allocatedBuffer.nioBuffer(); + if (!nioBuffer.isDirect()) { + throw new RuntimeException("Allocator returned non-direct buffer"); + } + + finishCurrentBuffer(); + buffers.addFirst(allocatedBuffer); + + buffer = nioBuffer; + buffer.limit(buffer.capacity()); + buffer.position(0); + + bufferOffset = UnsafeUtil.addressOffset(buffer); + limitMinusOne = bufferOffset + (buffer.limit() - 1); + pos = limitMinusOne; + } + + @Override + public int getTotalBytesWritten() { + return totalDoneBytes + bytesWrittenToCurrentBuffer(); + } + + private int bytesWrittenToCurrentBuffer() { + return (int) (limitMinusOne - pos); + } + + private int spaceLeft() { + return bufferPos() + 1; + } + + @Override + void finishCurrentBuffer() { + if (buffer != null) { + totalDoneBytes += bytesWrittenToCurrentBuffer(); + // Update the indices on the netty buffer. + buffer.position(bufferPos() + 1); + buffer = null; + pos = 0; + limitMinusOne = 0; + } + } + + private int bufferPos() { + return (int) (pos - bufferOffset); + } + + @Override + public void writeUInt32(int fieldNumber, int value) { + requireSpace(MAX_VARINT32_SIZE * 2); + writeVarint32(value); + writeTag(fieldNumber, WIRETYPE_VARINT); + } + + @Override + public void writeInt32(int fieldNumber, int value) { + requireSpace(MAX_VARINT32_SIZE + MAX_VARINT64_SIZE); + writeInt32(value); + writeTag(fieldNumber, WIRETYPE_VARINT); + } + + @Override + public void writeSInt32(int fieldNumber, int value) { + requireSpace(MAX_VARINT32_SIZE * 2); + writeSInt32(value); + writeTag(fieldNumber, WIRETYPE_VARINT); + } + + @Override + public void writeFixed32(int fieldNumber, int value) { + requireSpace(MAX_VARINT32_SIZE + FIXED32_SIZE); + writeFixed32(value); + writeTag(fieldNumber, WIRETYPE_FIXED32); + } + + @Override + public void writeUInt64(int fieldNumber, long value) { + requireSpace(MAX_VARINT32_SIZE + MAX_VARINT64_SIZE); + writeVarint64(value); + writeTag(fieldNumber, WIRETYPE_VARINT); + } + + @Override + public void writeSInt64(int fieldNumber, long value) { + requireSpace(MAX_VARINT32_SIZE + MAX_VARINT64_SIZE); + writeSInt64(value); + writeTag(fieldNumber, WIRETYPE_VARINT); + } + + @Override + public void writeFixed64(int fieldNumber, long value) { + requireSpace(MAX_VARINT32_SIZE + FIXED64_SIZE); + writeFixed64(value); + writeTag(fieldNumber, WIRETYPE_FIXED64); + } + + @Override + public void writeBool(int fieldNumber, boolean value) { + requireSpace(MAX_VARINT32_SIZE + 1); + write((byte) (value ? 1 : 0)); + writeTag(fieldNumber, WIRETYPE_VARINT); + } + + @Override + public void writeString(int fieldNumber, String value) { + int prevBytes = getTotalBytesWritten(); + writeString(value); + int length = getTotalBytesWritten() - prevBytes; + requireSpace(2 * MAX_VARINT32_SIZE); + writeVarint32(length); + writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + } + + @Override + public void writeBytes(int fieldNumber, ByteString value) { + try { + value.writeToReverse(this); + } catch (IOException e) { + // Should never happen since the writer does not throw. + throw new RuntimeException(e); + } + + requireSpace(MAX_VARINT32_SIZE * 2); + writeVarint32(value.size()); + writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + } + + @Override + public void writeMessage(int fieldNumber, Object value) throws IOException { + int prevBytes = getTotalBytesWritten(); + Protobuf.getInstance().writeTo(value, this); + int length = getTotalBytesWritten() - prevBytes; + requireSpace(MAX_VARINT32_SIZE * 2); + writeVarint32(length); + writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + } + + @Override + public void writeMessage(int fieldNumber, Object value, Schema schema) throws IOException { + int prevBytes = getTotalBytesWritten(); + schema.writeTo(value, this); + int length = getTotalBytesWritten() - prevBytes; + requireSpace(MAX_VARINT32_SIZE * 2); + writeVarint32(length); + writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + } + + @Override + public void writeGroup(int fieldNumber, Object value) throws IOException { + writeTag(fieldNumber, WIRETYPE_END_GROUP); + Protobuf.getInstance().writeTo(value, this); + writeTag(fieldNumber, WIRETYPE_START_GROUP); + } + + @Override + public void writeGroup(int fieldNumber, Object value, Schema schema) throws IOException { + writeTag(fieldNumber, WIRETYPE_END_GROUP); + schema.writeTo(value, this); + writeTag(fieldNumber, WIRETYPE_START_GROUP); + } + + @Override + public void writeStartGroup(int fieldNumber) { + writeTag(fieldNumber, WIRETYPE_START_GROUP); + } + + @Override + public void writeEndGroup(int fieldNumber) { + writeTag(fieldNumber, WIRETYPE_END_GROUP); + } + + @Override + void writeInt32(int value) { + if (value >= 0) { + writeVarint32(value); + } else { + writeVarint64(value); + } + } + + @Override + void writeSInt32(int value) { + writeVarint32(CodedOutputStream.encodeZigZag32(value)); + } + + @Override + void writeSInt64(long value) { + writeVarint64(CodedOutputStream.encodeZigZag64(value)); + } + + @Override + void writeBool(boolean value) { + write((byte) (value ? 1 : 0)); + } + + @Override + void writeTag(int fieldNumber, int wireType) { + writeVarint32(WireFormat.makeTag(fieldNumber, wireType)); + } + + @Override + void writeVarint32(int value) { + if ((value & (~0 << 7)) == 0) { + writeVarint32OneByte(value); + } else if ((value & (~0 << 14)) == 0) { + writeVarint32TwoBytes(value); + } else if ((value & (~0 << 21)) == 0) { + writeVarint32ThreeBytes(value); + } else if ((value & (~0 << 28)) == 0) { + writeVarint32FourBytes(value); + } else { + writeVarint32FiveBytes(value); + } + } + + private void writeVarint32OneByte(int value) { + UnsafeUtil.putByte(pos--, (byte) value); + } + + private void writeVarint32TwoBytes(int value) { + UnsafeUtil.putByte(pos--, (byte) (value >>> 7)); + UnsafeUtil.putByte(pos--, (byte) ((value & 0x7F) | 0x80)); + } + + private void writeVarint32ThreeBytes(int value) { + UnsafeUtil.putByte(pos--, (byte) (value >>> 14)); + UnsafeUtil.putByte(pos--, (byte) (((value >>> 7) & 0x7F) | 0x80)); + UnsafeUtil.putByte(pos--, (byte) ((value & 0x7F) | 0x80)); + } + + private void writeVarint32FourBytes(int value) { + UnsafeUtil.putByte(pos--, (byte) (value >>> 21)); + UnsafeUtil.putByte(pos--, (byte) (((value >>> 14) & 0x7F) | 0x80)); + UnsafeUtil.putByte(pos--, (byte) (((value >>> 7) & 0x7F) | 0x80)); + UnsafeUtil.putByte(pos--, (byte) ((value & 0x7F) | 0x80)); + } + + private void writeVarint32FiveBytes(int value) { + UnsafeUtil.putByte(pos--, (byte) (value >>> 28)); + UnsafeUtil.putByte(pos--, (byte) (((value >>> 21) & 0x7F) | 0x80)); + UnsafeUtil.putByte(pos--, (byte) (((value >>> 14) & 0x7F) | 0x80)); + UnsafeUtil.putByte(pos--, (byte) (((value >>> 7) & 0x7F) | 0x80)); + UnsafeUtil.putByte(pos--, (byte) ((value & 0x7F) | 0x80)); + } + + @Override + void writeVarint64(long value) { + switch (computeUInt64SizeNoTag(value)) { + case 1: + writeVarint64OneByte(value); + break; + case 2: + writeVarint64TwoBytes(value); + break; + case 3: + writeVarint64ThreeBytes(value); + break; + case 4: + writeVarint64FourBytes(value); + break; + case 5: + writeVarint64FiveBytes(value); + break; + case 6: + writeVarint64SixBytes(value); + break; + case 7: + writeVarint64SevenBytes(value); + break; + case 8: + writeVarint64EightBytes(value); + break; + case 9: + writeVarint64NineBytes(value); + break; + case 10: + writeVarint64TenBytes(value); + break; + } + } + + private void writeVarint64OneByte(long value) { + UnsafeUtil.putByte(pos--, (byte) value); + } + + private void writeVarint64TwoBytes(long value) { + UnsafeUtil.putByte(pos--, (byte) (value >>> 7)); + UnsafeUtil.putByte(pos--, (byte) (((int) value & 0x7F) | 0x80)); + } + + private void writeVarint64ThreeBytes(long value) { + UnsafeUtil.putByte(pos--, (byte) (((int) value) >>> 14)); + UnsafeUtil.putByte(pos--, (byte) (((value >>> 7) & 0x7F) | 0x80)); + UnsafeUtil.putByte(pos--, (byte) ((value & 0x7F) | 0x80)); + } + + private void writeVarint64FourBytes(long value) { + UnsafeUtil.putByte(pos--, (byte) (value >>> 21)); + UnsafeUtil.putByte(pos--, (byte) (((value >>> 14) & 0x7F) | 0x80)); + UnsafeUtil.putByte(pos--, (byte) (((value >>> 7) & 0x7F) | 0x80)); + UnsafeUtil.putByte(pos--, (byte) ((value & 0x7F) | 0x80)); + } + + private void writeVarint64FiveBytes(long value) { + UnsafeUtil.putByte(pos--, (byte) (value >>> 28)); + UnsafeUtil.putByte(pos--, (byte) (((value >>> 21) & 0x7F) | 0x80)); + UnsafeUtil.putByte(pos--, (byte) (((value >>> 14) & 0x7F) | 0x80)); + UnsafeUtil.putByte(pos--, (byte) (((value >>> 7) & 0x7F) | 0x80)); + UnsafeUtil.putByte(pos--, (byte) ((value & 0x7F) | 0x80)); + } + + private void writeVarint64SixBytes(long value) { + UnsafeUtil.putByte(pos--, (byte) (value >>> 35)); + UnsafeUtil.putByte(pos--, (byte) (((value >>> 28) & 0x7F) | 0x80)); + UnsafeUtil.putByte(pos--, (byte) (((value >>> 21) & 0x7F) | 0x80)); + UnsafeUtil.putByte(pos--, (byte) (((value >>> 14) & 0x7F) | 0x80)); + UnsafeUtil.putByte(pos--, (byte) (((value >>> 7) & 0x7F) | 0x80)); + UnsafeUtil.putByte(pos--, (byte) ((value & 0x7F) | 0x80)); + } + + private void writeVarint64SevenBytes(long value) { + UnsafeUtil.putByte(pos--, (byte) (value >>> 42)); + UnsafeUtil.putByte(pos--, (byte) (((value >>> 35) & 0x7F) | 0x80)); + UnsafeUtil.putByte(pos--, (byte) (((value >>> 28) & 0x7F) | 0x80)); + UnsafeUtil.putByte(pos--, (byte) (((value >>> 21) & 0x7F) | 0x80)); + UnsafeUtil.putByte(pos--, (byte) (((value >>> 14) & 0x7F) | 0x80)); + UnsafeUtil.putByte(pos--, (byte) (((value >>> 7) & 0x7F) | 0x80)); + UnsafeUtil.putByte(pos--, (byte) ((value & 0x7F) | 0x80)); + } + + private void writeVarint64EightBytes(long value) { + UnsafeUtil.putByte(pos--, (byte) (value >>> 49)); + UnsafeUtil.putByte(pos--, (byte) (((value >>> 42) & 0x7F) | 0x80)); + UnsafeUtil.putByte(pos--, (byte) (((value >>> 35) & 0x7F) | 0x80)); + UnsafeUtil.putByte(pos--, (byte) (((value >>> 28) & 0x7F) | 0x80)); + UnsafeUtil.putByte(pos--, (byte) (((value >>> 21) & 0x7F) | 0x80)); + UnsafeUtil.putByte(pos--, (byte) (((value >>> 14) & 0x7F) | 0x80)); + UnsafeUtil.putByte(pos--, (byte) (((value >>> 7) & 0x7F) | 0x80)); + UnsafeUtil.putByte(pos--, (byte) ((value & 0x7F) | 0x80)); + } + + private void writeVarint64NineBytes(long value) { + UnsafeUtil.putByte(pos--, (byte) (value >>> 56)); + UnsafeUtil.putByte(pos--, (byte) (((value >>> 49) & 0x7F) | 0x80)); + UnsafeUtil.putByte(pos--, (byte) (((value >>> 42) & 0x7F) | 0x80)); + UnsafeUtil.putByte(pos--, (byte) (((value >>> 35) & 0x7F) | 0x80)); + UnsafeUtil.putByte(pos--, (byte) (((value >>> 28) & 0x7F) | 0x80)); + UnsafeUtil.putByte(pos--, (byte) (((value >>> 21) & 0x7F) | 0x80)); + UnsafeUtil.putByte(pos--, (byte) (((value >>> 14) & 0x7F) | 0x80)); + UnsafeUtil.putByte(pos--, (byte) (((value >>> 7) & 0x7F) | 0x80)); + UnsafeUtil.putByte(pos--, (byte) ((value & 0x7F) | 0x80)); + } + + private void writeVarint64TenBytes(long value) { + UnsafeUtil.putByte(pos--, (byte) (value >>> 63)); + UnsafeUtil.putByte(pos--, (byte) (((value >>> 56) & 0x7F) | 0x80)); + UnsafeUtil.putByte(pos--, (byte) (((value >>> 49) & 0x7F) | 0x80)); + UnsafeUtil.putByte(pos--, (byte) (((value >>> 42) & 0x7F) | 0x80)); + UnsafeUtil.putByte(pos--, (byte) (((value >>> 35) & 0x7F) | 0x80)); + UnsafeUtil.putByte(pos--, (byte) (((value >>> 28) & 0x7F) | 0x80)); + UnsafeUtil.putByte(pos--, (byte) (((value >>> 21) & 0x7F) | 0x80)); + UnsafeUtil.putByte(pos--, (byte) (((value >>> 14) & 0x7F) | 0x80)); + UnsafeUtil.putByte(pos--, (byte) (((value >>> 7) & 0x7F) | 0x80)); + UnsafeUtil.putByte(pos--, (byte) ((value & 0x7F) | 0x80)); + } + + @Override + void writeFixed32(int value) { + UnsafeUtil.putByte(pos--, (byte) ((value >> 24) & 0xFF)); + UnsafeUtil.putByte(pos--, (byte) ((value >> 16) & 0xFF)); + UnsafeUtil.putByte(pos--, (byte) ((value >> 8) & 0xFF)); + UnsafeUtil.putByte(pos--, (byte) (value & 0xFF)); + } + + @Override + void writeFixed64(long value) { + UnsafeUtil.putByte(pos--, (byte) ((int) (value >> 56) & 0xFF)); + UnsafeUtil.putByte(pos--, (byte) ((int) (value >> 48) & 0xFF)); + UnsafeUtil.putByte(pos--, (byte) ((int) (value >> 40) & 0xFF)); + UnsafeUtil.putByte(pos--, (byte) ((int) (value >> 32) & 0xFF)); + UnsafeUtil.putByte(pos--, (byte) ((int) (value >> 24) & 0xFF)); + UnsafeUtil.putByte(pos--, (byte) ((int) (value >> 16) & 0xFF)); + UnsafeUtil.putByte(pos--, (byte) ((int) (value >> 8) & 0xFF)); + UnsafeUtil.putByte(pos--, (byte) ((int) (value) & 0xFF)); + } + + @Override + void writeString(String in) { + // Request enough space to write the ASCII string. + requireSpace(in.length()); + + // We know the buffer is big enough... + int i = in.length() - 1; + // Designed to take advantage of + // https://wiki.openjdk.java.net/display/HotSpotInternals/RangeCheckElimination + for (char c; i >= 0 && (c = in.charAt(i)) < 0x80; i--) { + UnsafeUtil.putByte(pos--, (byte) c); + } + if (i == -1) { + // ASCII. + return; + } + for (char c; i >= 0; i--) { + c = in.charAt(i); + if (c < 0x80 && pos >= bufferOffset) { + UnsafeUtil.putByte(pos--, (byte) c); + } else if (c < 0x800 && pos > bufferOffset) { // 11 bits, two UTF-8 bytes + UnsafeUtil.putByte(pos--, (byte) (0x80 | (0x3F & c))); + UnsafeUtil.putByte(pos--, (byte) ((0xF << 6) | (c >>> 6))); + } else if ((c < Character.MIN_SURROGATE || Character.MAX_SURROGATE < c) + && pos > bufferOffset + 1) { + // Maximum single-char code point is 0xFFFF, 16 bits, three UTF-8 bytes + UnsafeUtil.putByte(pos--, (byte) (0x80 | (0x3F & c))); + UnsafeUtil.putByte(pos--, (byte) (0x80 | (0x3F & (c >>> 6)))); + UnsafeUtil.putByte(pos--, (byte) ((0xF << 5) | (c >>> 12))); + } else if (pos > bufferOffset + 2) { + // Minimum code point represented by a surrogate pair is 0x10000, 17 bits, + // four UTF-8 bytes + final char high; + if (i == 0 || !Character.isSurrogatePair(high = in.charAt(i - 1), c)) { + throw new Utf8.UnpairedSurrogateException(i - 1, i); + } + i--; + int codePoint = Character.toCodePoint(high, c); + UnsafeUtil.putByte(pos--, (byte) (0x80 | (0x3F & codePoint))); + UnsafeUtil.putByte(pos--, (byte) (0x80 | (0x3F & (codePoint >>> 6)))); + UnsafeUtil.putByte(pos--, (byte) (0x80 | (0x3F & (codePoint >>> 12)))); + UnsafeUtil.putByte(pos--, (byte) ((0xF << 4) | (codePoint >>> 18))); + } else { + // Buffer is full - allocate a new one and revisit the current character. + requireSpace(i); + i++; + } + } + } + + @Override + public void write(byte value) { + UnsafeUtil.putByte(pos--, value); + } + + @Override + public void write(byte[] value, int offset, int length) { + if (spaceLeft() < length) { + nextBuffer(length); + } + + pos -= length; + buffer.position(bufferPos() + 1); + buffer.put(value, offset, length); + } + + @Override + public void writeLazy(byte[] value, int offset, int length) { + if (spaceLeft() < length) { + // We consider the value to be immutable (likely the internals of a ByteString). Just + // wrap it in a Netty buffer and add it to the output buffer. + totalDoneBytes += length; + buffers.addFirst(AllocatedBuffer.wrap(value, offset, length)); + + // Advance the writer to the next buffer. + // TODO(nathanmittler): Consider slicing if space available above some threshold. + nextBuffer(); + return; + } + + pos -= length; + buffer.position(bufferPos() + 1); + buffer.put(value, offset, length); + } + + @Override + public void write(ByteBuffer value) { + int length = value.remaining(); + if (spaceLeft() < length) { + nextBuffer(length); + } + + pos -= length; + buffer.position(bufferPos() + 1); + buffer.put(value); + } + + @Override + public void writeLazy(ByteBuffer value) { + int length = value.remaining(); + if (spaceLeft() < length) { + // We consider the value to be immutable (likely the internals of a ByteString). Just + // wrap it in a Netty buffer and add it to the output buffer. + totalDoneBytes += length; + buffers.addFirst(AllocatedBuffer.wrap(value)); + + // Advance the writer to the next buffer. + // TODO(nathanmittler): Consider slicing if space available above some threshold. + nextBuffer(); + return; + } + + pos -= length; + buffer.position(bufferPos() + 1); + buffer.put(value); + } + + @Override + void requireSpace(int size) { + if (spaceLeft() < size) { + nextBuffer(size); + } + } + } +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/BoolValue.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/BoolValue.java new file mode 100644 index 0000000000000..280f56ea29c79 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/BoolValue.java @@ -0,0 +1,276 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/wrappers.proto + +package com.google.protobuf; + +/** + *

+ * Wrapper message for `bool`.
+ * The JSON representation for `BoolValue` is JSON `true` and `false`.
+ * 
+ * + * Protobuf type {@code google.protobuf.BoolValue} + */ +public final class BoolValue extends + com.google.protobuf.GeneratedMessageLite< + BoolValue, BoolValue.Builder> implements + // @@protoc_insertion_point(message_implements:google.protobuf.BoolValue) + BoolValueOrBuilder { + private BoolValue() { + } + public static final int VALUE_FIELD_NUMBER = 1; + private boolean value_; + /** + *
+   * The bool value.
+   * 
+ * + * bool value = 1; + * @return The value. + */ + @java.lang.Override + public boolean getValue() { + return value_; + } + /** + *
+   * The bool value.
+   * 
+ * + * bool value = 1; + * @param value The value to set. + */ + private void setValue(boolean value) { + + value_ = value; + } + /** + *
+   * The bool value.
+   * 
+ * + * bool value = 1; + */ + private void clearValue() { + + value_ = false; + } + + public static com.google.protobuf.BoolValue parseFrom( + java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.BoolValue parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.BoolValue parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.BoolValue parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.BoolValue parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.BoolValue parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.BoolValue parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, 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.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, input, extensionRegistry); + } + public static com.google.protobuf.BoolValue parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return parseDelimitedFrom(DEFAULT_INSTANCE, input); + } + public static com.google.protobuf.BoolValue parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return parseDelimitedFrom(DEFAULT_INSTANCE, input, extensionRegistry); + } + public static com.google.protobuf.BoolValue parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, 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.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, input, extensionRegistry); + } + + public static Builder newBuilder() { + return (Builder) DEFAULT_INSTANCE.createBuilder(); + } + public static Builder newBuilder(com.google.protobuf.BoolValue prototype) { + return (Builder) DEFAULT_INSTANCE.createBuilder(prototype); + } + + /** + *
+   * Wrapper message for `bool`.
+   * The JSON representation for `BoolValue` is JSON `true` and `false`.
+   * 
+ * + * Protobuf type {@code google.protobuf.BoolValue} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessageLite.Builder< + com.google.protobuf.BoolValue, Builder> implements + // @@protoc_insertion_point(builder_implements:google.protobuf.BoolValue) + com.google.protobuf.BoolValueOrBuilder { + // Construct using com.google.protobuf.BoolValue.newBuilder() + private Builder() { + super(DEFAULT_INSTANCE); + } + + + /** + *
+     * The bool value.
+     * 
+ * + * bool value = 1; + * @return The value. + */ + @java.lang.Override + public boolean getValue() { + return instance.getValue(); + } + /** + *
+     * The bool value.
+     * 
+ * + * bool value = 1; + * @param value The value to set. + * @return This builder for chaining. + */ + public Builder setValue(boolean value) { + copyOnWrite(); + instance.setValue(value); + return this; + } + /** + *
+     * The bool value.
+     * 
+ * + * bool value = 1; + * @return This builder for chaining. + */ + public Builder clearValue() { + copyOnWrite(); + instance.clearValue(); + return this; + } + + // @@protoc_insertion_point(builder_scope:google.protobuf.BoolValue) + } + @java.lang.Override + @java.lang.SuppressWarnings({"unchecked", "fallthrough"}) + protected final java.lang.Object dynamicMethod( + com.google.protobuf.GeneratedMessageLite.MethodToInvoke method, + java.lang.Object arg0, java.lang.Object arg1) { + switch (method) { + case NEW_MUTABLE_INSTANCE: { + return new com.google.protobuf.BoolValue(); + } + case NEW_BUILDER: { + return new Builder(); + } + case BUILD_MESSAGE_INFO: { + java.lang.Object[] objects = new java.lang.Object[] { + "value_", + }; + java.lang.String info = + "\u0000\u0001\u0000\u0000\u0001\u0001\u0001\u0000\u0000\u0000\u0001\u0007"; + return newMessageInfo(DEFAULT_INSTANCE, info, objects); + } + // fall through + case GET_DEFAULT_INSTANCE: { + return DEFAULT_INSTANCE; + } + case GET_PARSER: { + com.google.protobuf.Parser parser = PARSER; + if (parser == null) { + synchronized (com.google.protobuf.BoolValue.class) { + parser = PARSER; + if (parser == null) { + parser = + new DefaultInstanceBasedParser( + DEFAULT_INSTANCE); + PARSER = parser; + } + } + } + return parser; + } + case GET_MEMOIZED_IS_INITIALIZED: { + return (byte) 1; + } + case SET_MEMOIZED_IS_INITIALIZED: { + return null; + } + } + throw new UnsupportedOperationException(); + } + + + // @@protoc_insertion_point(class_scope:google.protobuf.BoolValue) + private static final com.google.protobuf.BoolValue DEFAULT_INSTANCE; + static { + BoolValue defaultInstance = new BoolValue(); + // New instances are implicitly immutable so no need to make + // immutable. + DEFAULT_INSTANCE = defaultInstance; + com.google.protobuf.GeneratedMessageLite.registerDefaultInstance( + BoolValue.class, defaultInstance); + } + + public static com.google.protobuf.BoolValue getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + public static com.google.protobuf.BoolValue of(boolean value) { + return newBuilder().setValue(value).build(); + } + + private static volatile com.google.protobuf.Parser PARSER; + + public static com.google.protobuf.Parser parser() { + return DEFAULT_INSTANCE.getParserForType(); + } +} + diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/BoolValueOrBuilder.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/BoolValueOrBuilder.java new file mode 100644 index 0000000000000..c51d2a7ba336d --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/BoolValueOrBuilder.java @@ -0,0 +1,19 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/wrappers.proto + +package com.google.protobuf; + +public interface BoolValueOrBuilder extends + // @@protoc_insertion_point(interface_extends:google.protobuf.BoolValue) + com.google.protobuf.MessageLiteOrBuilder { + + /** + *
+   * The bool value.
+   * 
+ * + * bool value = 1; + * @return The value. + */ + boolean getValue(); +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/BooleanArrayList.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/BooleanArrayList.java new file mode 100644 index 0000000000000..451fce1e84992 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/BooleanArrayList.java @@ -0,0 +1,298 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +import static com.google.protobuf.Internal.checkNotNull; + +import com.google.protobuf.Internal.BooleanList; +import java.util.Arrays; +import java.util.Collection; +import java.util.RandomAccess; + +/** + * An implementation of {@link BooleanList} on top of a primitive array. + * + * @author dweis@google.com (Daniel Weis) + */ +final class BooleanArrayList extends AbstractProtobufList + implements BooleanList, RandomAccess, PrimitiveNonBoxingCollection { + + private static final BooleanArrayList EMPTY_LIST = new BooleanArrayList(new boolean[0], 0); + static { + EMPTY_LIST.makeImmutable(); + } + + public static BooleanArrayList emptyList() { + return EMPTY_LIST; + } + + /** The backing store for the list. */ + private boolean[] array; + + /** + * The size of the list distinct from the length of the array. That is, it is the number of + * elements set in the list. + */ + private int size; + + /** Constructs a new mutable {@code BooleanArrayList} with default capacity. */ + BooleanArrayList() { + this(new boolean[DEFAULT_CAPACITY], 0); + } + + /** + * Constructs a new mutable {@code BooleanArrayList} containing the same elements as {@code + * other}. + */ + private BooleanArrayList(boolean[] other, int size) { + array = other; + this.size = size; + } + + @Override + protected void removeRange(int fromIndex, int toIndex) { + ensureIsMutable(); + if (toIndex < fromIndex) { + throw new IndexOutOfBoundsException("toIndex < fromIndex"); + } + + System.arraycopy(array, toIndex, array, fromIndex, size - toIndex); + size -= (toIndex - fromIndex); + modCount++; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof BooleanArrayList)) { + return super.equals(o); + } + BooleanArrayList other = (BooleanArrayList) o; + if (size != other.size) { + return false; + } + + final boolean[] arr = other.array; + for (int i = 0; i < size; i++) { + if (array[i] != arr[i]) { + return false; + } + } + + return true; + } + + @Override + public int hashCode() { + int result = 1; + for (int i = 0; i < size; i++) { + result = (31 * result) + Internal.hashBoolean(array[i]); + } + return result; + } + + @Override + public BooleanList mutableCopyWithCapacity(int capacity) { + if (capacity < size) { + throw new IllegalArgumentException(); + } + return new BooleanArrayList(Arrays.copyOf(array, capacity), size); + } + + @Override + public Boolean get(int index) { + return getBoolean(index); + } + + @Override + public boolean getBoolean(int index) { + ensureIndexInRange(index); + return array[index]; + } + + @Override + public int indexOf(Object element) { + if (!(element instanceof Boolean)) { + return -1; + } + boolean unboxedElement = (Boolean) element; + int numElems = size(); + for (int i = 0; i < numElems; i++) { + if (array[i] == unboxedElement) { + return i; + } + } + return -1; + } + + @Override + public boolean contains(Object element) { + return indexOf(element) != -1; + } + + @Override + public int size() { + return size; + } + + @Override + public Boolean set(int index, Boolean element) { + return setBoolean(index, element); + } + + @Override + public boolean setBoolean(int index, boolean element) { + ensureIsMutable(); + ensureIndexInRange(index); + boolean previousValue = array[index]; + array[index] = element; + return previousValue; + } + + @Override + public boolean add(Boolean element) { + addBoolean(element); + return true; + } + + @Override + public void add(int index, Boolean element) { + addBoolean(index, element); + } + + /** Like {@link #add(Boolean)} but more efficient in that it doesn't box the element. */ + @Override + public void addBoolean(boolean element) { + ensureIsMutable(); + if (size == array.length) { + // Resize to 1.5x the size + int length = ((size * 3) / 2) + 1; + boolean[] newArray = new boolean[length]; + + System.arraycopy(array, 0, newArray, 0, size); + array = newArray; + } + + array[size++] = element; + } + + /** Like {@link #add(int, Boolean)} but more efficient in that it doesn't box the element. */ + private void addBoolean(int index, boolean element) { + ensureIsMutable(); + if (index < 0 || index > size) { + throw new IndexOutOfBoundsException(makeOutOfBoundsExceptionMessage(index)); + } + + if (size < array.length) { + // Shift everything over to make room + System.arraycopy(array, index, array, index + 1, size - index); + } else { + // Resize to 1.5x the size + int length = ((size * 3) / 2) + 1; + boolean[] newArray = new boolean[length]; + + // Copy the first part directly + System.arraycopy(array, 0, newArray, 0, index); + + // Copy the rest shifted over by one to make room + System.arraycopy(array, index, newArray, index + 1, size - index); + array = newArray; + } + + array[index] = element; + size++; + modCount++; + } + + @Override + public boolean addAll(Collection collection) { + ensureIsMutable(); + + checkNotNull(collection); + + // We specialize when adding another BooleanArrayList to avoid boxing elements. + if (!(collection instanceof BooleanArrayList)) { + return super.addAll(collection); + } + + BooleanArrayList list = (BooleanArrayList) collection; + if (list.size == 0) { + return false; + } + + int overflow = Integer.MAX_VALUE - size; + if (overflow < list.size) { + // We can't actually represent a list this large. + throw new OutOfMemoryError(); + } + + int newSize = size + list.size; + if (newSize > array.length) { + array = Arrays.copyOf(array, newSize); + } + + System.arraycopy(list.array, 0, array, size, list.size); + size = newSize; + modCount++; + return true; + } + + @Override + public Boolean remove(int index) { + ensureIsMutable(); + ensureIndexInRange(index); + boolean value = array[index]; + if (index < size - 1) { + System.arraycopy(array, index + 1, array, index, size - index - 1); + } + size--; + modCount++; + return value; + } + + /** + * Ensures that the provided {@code index} is within the range of {@code [0, size]}. Throws an + * {@link IndexOutOfBoundsException} if it is not. + * + * @param index the index to verify is in range + */ + private void ensureIndexInRange(int index) { + if (index < 0 || index >= size) { + throw new IndexOutOfBoundsException(makeOutOfBoundsExceptionMessage(index)); + } + } + + private String makeOutOfBoundsExceptionMessage(int index) { + return "Index:" + index + ", Size:" + size; + } +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/BufferAllocator.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/BufferAllocator.java new file mode 100644 index 0000000000000..bfd9c7237c0e2 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/BufferAllocator.java @@ -0,0 +1,64 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +import java.nio.ByteBuffer; + +/** + * An object responsible for allocation of buffers. This is an extension point to enable buffer + * pooling within an application. + */ +@ExperimentalApi +abstract class BufferAllocator { + private static final BufferAllocator UNPOOLED = + new BufferAllocator() { + @Override + public AllocatedBuffer allocateHeapBuffer(int capacity) { + return AllocatedBuffer.wrap(new byte[capacity]); + } + + @Override + public AllocatedBuffer allocateDirectBuffer(int capacity) { + return AllocatedBuffer.wrap(ByteBuffer.allocateDirect(capacity)); + } + }; + + /** Returns an unpooled buffer allocator, which will create a new buffer for each request. */ + public static BufferAllocator unpooled() { + return UNPOOLED; + } + + /** Allocates a buffer with the given capacity that is backed by an array on the heap. */ + public abstract AllocatedBuffer allocateHeapBuffer(int capacity); + + /** Allocates a direct (i.e. non-heap) buffer with the given capacity. */ + public abstract AllocatedBuffer allocateDirectBuffer(int capacity); +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/ByteBufferWriter.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/ByteBufferWriter.java new file mode 100644 index 0000000000000..2cb3ada67fb6b --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/ByteBufferWriter.java @@ -0,0 +1,181 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +import static java.lang.Math.max; +import static java.lang.Math.min; + +import java.io.IOException; +import java.io.OutputStream; +import java.lang.ref.SoftReference; +import java.lang.reflect.Field; +import java.nio.ByteBuffer; +import java.nio.channels.WritableByteChannel; + +/** Utility class to provide efficient writing of {@link ByteBuffer}s to {@link OutputStream}s. */ +final class ByteBufferWriter { + private ByteBufferWriter() {} + + /** + * Minimum size for a cached buffer. This prevents us from allocating buffers that are too small + * to be easily reused. + */ + // TODO(nathanmittler): tune this property or allow configuration? + private static final int MIN_CACHED_BUFFER_SIZE = 1024; + + /** + * Maximum size for a cached buffer. If a larger buffer is required, it will be allocated but not + * cached. + */ + // TODO(nathanmittler): tune this property or allow configuration? + private static final int MAX_CACHED_BUFFER_SIZE = 16 * 1024; + + /** The fraction of the requested buffer size under which the buffer will be reallocated. */ + // TODO(nathanmittler): tune this property or allow configuration? + private static final float BUFFER_REALLOCATION_THRESHOLD = 0.5f; + + /** + * Keeping a soft reference to a thread-local buffer. This buffer is used for writing a {@link + * ByteBuffer} to an {@link OutputStream} when no zero-copy alternative was available. Using a + * "soft" reference since VMs may keep this reference around longer than "weak" (e.g. HotSpot will + * maintain soft references until memory pressure warrants collection). + */ + private static final ThreadLocal> BUFFER = + new ThreadLocal>(); + + /** This is a hack for GAE, where {@code FileOutputStream} is unavailable. */ + private static final Class FILE_OUTPUT_STREAM_CLASS = safeGetClass("java.io.FileOutputStream"); + + private static final long CHANNEL_FIELD_OFFSET = getChannelFieldOffset(FILE_OUTPUT_STREAM_CLASS); + + /** + * For testing purposes only. Clears the cached buffer to force a new allocation on the next + * invocation. + */ + static void clearCachedBuffer() { + BUFFER.set(null); + } + + /** + * Writes the remaining content of the buffer to the given stream. The buffer {@code position} + * will remain unchanged by this method. + */ + static void write(ByteBuffer buffer, OutputStream output) throws IOException { + final int initialPos = buffer.position(); + try { + if (buffer.hasArray()) { + // Optimized write for array-backed buffers. + // Note that we're taking the risk that a malicious OutputStream could modify the array. + output.write(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining()); + } else if (!writeToChannel(buffer, output)) { + // Read all of the data from the buffer to an array. + // TODO(nathanmittler): Consider performance improvements for other "known" stream types. + final byte[] array = getOrCreateBuffer(buffer.remaining()); + while (buffer.hasRemaining()) { + int length = min(buffer.remaining(), array.length); + buffer.get(array, 0, length); + output.write(array, 0, length); + } + } + } finally { + // Restore the initial position. + buffer.position(initialPos); + } + } + + private static byte[] getOrCreateBuffer(int requestedSize) { + requestedSize = max(requestedSize, MIN_CACHED_BUFFER_SIZE); + + byte[] buffer = getBuffer(); + // Only allocate if we need to. + if (buffer == null || needToReallocate(requestedSize, buffer.length)) { + buffer = new byte[requestedSize]; + + // Only cache the buffer if it's not too big. + if (requestedSize <= MAX_CACHED_BUFFER_SIZE) { + setBuffer(buffer); + } + } + return buffer; + } + + private static boolean needToReallocate(int requestedSize, int bufferLength) { + // First check against just the requested length to avoid the multiply. + return bufferLength < requestedSize + && bufferLength < requestedSize * BUFFER_REALLOCATION_THRESHOLD; + } + + private static byte[] getBuffer() { + SoftReference sr = BUFFER.get(); + return sr == null ? null : sr.get(); + } + + private static void setBuffer(byte[] value) { + BUFFER.set(new SoftReference(value)); + } + + private static boolean writeToChannel(ByteBuffer buffer, OutputStream output) throws IOException { + if (CHANNEL_FIELD_OFFSET >= 0 && FILE_OUTPUT_STREAM_CLASS.isInstance(output)) { + // Use a channel to write out the ByteBuffer. This will automatically empty the buffer. + WritableByteChannel channel = null; + try { + channel = (WritableByteChannel) UnsafeUtil.getObject(output, CHANNEL_FIELD_OFFSET); + } catch (ClassCastException e) { + // Absorb. + } + if (channel != null) { + channel.write(buffer); + return true; + } + } + return false; + } + + private static Class safeGetClass(String className) { + try { + return Class.forName(className); + } catch (ClassNotFoundException e) { + return null; + } + } + + private static long getChannelFieldOffset(Class clazz) { + try { + if (clazz != null && UnsafeUtil.hasUnsafeArrayOperations()) { + Field field = clazz.getDeclaredField("channel"); + return UnsafeUtil.objectFieldOffset(field); + } + } catch (Throwable e) { + // Absorb + } + return -1; + } +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/ByteOutput.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/ByteOutput.java new file mode 100644 index 0000000000000..dba7a379f8f33 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/ByteOutput.java @@ -0,0 +1,116 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +import java.io.IOException; +import java.nio.ByteBuffer; + +/** + * An output target for raw bytes. This interface provides semantics that support two types of + * writing: + * + *

Traditional write operations: (as defined by {@link java.io.OutputStream}) where the + * target method is responsible for either copying the data or completing the write before returning + * from the method call. + * + *

Lazy write operations: where the caller guarantees that it will never modify the + * provided buffer and it can therefore be considered immutable. The target method is free to + * maintain a reference to the buffer beyond the scope of the method call (e.g. until the write + * operation completes). + */ +@ExperimentalApi +public abstract class ByteOutput { + /** + * Writes a single byte. + * + * @param value the byte to be written + * @throws IOException thrown if an error occurred while writing + */ + public abstract void write(byte value) throws IOException; + + /** + * Writes a sequence of bytes. The {@link ByteOutput} must copy {@code value} if it will not be + * processed prior to the return of this method call, since {@code value} may be reused/altered by + * the caller. + * + *

NOTE: This method MUST NOT modify the {@code value}. Doing so is a + * programming error and will lead to data corruption which will be difficult to debug. + * + * @param value the bytes to be written + * @param offset the offset of the start of the writable range + * @param length the number of bytes to write starting from {@code offset} + * @throws IOException thrown if an error occurred while writing + */ + public abstract void write(byte[] value, int offset, int length) throws IOException; + + /** + * Writes a sequence of bytes. The {@link ByteOutput} is free to retain a reference to the value + * beyond the scope of this method call (e.g. write later) since it is considered immutable and is + * guaranteed not to change by the caller. + * + *

NOTE: This method MUST NOT modify the {@code value}. Doing so is a + * programming error and will lead to data corruption which will be difficult to debug. + * + * @param value the bytes to be written + * @param offset the offset of the start of the writable range + * @param length the number of bytes to write starting from {@code offset} + * @throws IOException thrown if an error occurred while writing + */ + public abstract void writeLazy(byte[] value, int offset, int length) throws IOException; + + /** + * Writes a sequence of bytes. The {@link ByteOutput} must copy {@code value} if it will not be + * processed prior to the return of this method call, since {@code value} may be reused/altered by + * the caller. + * + *

NOTE: This method MUST NOT modify the {@code value}. Doing so is a + * programming error and will lead to data corruption which will be difficult to debug. + * + * @param value the bytes to be written. Upon returning from this call, the {@code position} of + * this buffer will be set to the {@code limit} + * @throws IOException thrown if an error occurred while writing + */ + public abstract void write(ByteBuffer value) throws IOException; + + /** + * Writes a sequence of bytes. The {@link ByteOutput} is free to retain a reference to the value + * beyond the scope of this method call (e.g. write later) since it is considered immutable and is + * guaranteed not to change by the caller. + * + *

NOTE: This method MUST NOT modify the {@code value}. Doing so is a + * programming error and will lead to data corruption which will be difficult to debug. + * + * @param value the bytes to be written. Upon returning from this call, the {@code position} of + * this buffer will be set to the {@code limit} + * @throws IOException thrown if an error occurred while writing + */ + public abstract void writeLazy(ByteBuffer value) throws IOException; +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/ByteString.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/ByteString.java new file mode 100644 index 0000000000000..74c9a71b6c541 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/ByteString.java @@ -0,0 +1,1615 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +import static com.google.protobuf.TextFormatEscaper.escapeBytes; +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.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; +import java.util.Locale; +import java.util.NoSuchElementException; + +/** + * Immutable sequence of bytes. Provides conversions to and from {@code byte[]}, {@link + * java.lang.String}, {@link ByteBuffer}, {@link InputStream}, {@link OutputStream}. Also provides a + * conversion to {@link CodedInputStream}. + * + *

Like {@link String}, the contents of a {@link ByteString} can never be observed to change, not + * even in the presence of a data race or incorrect API usage in the client code. + * + *

Substring is supported by sharing the reference to the immutable underlying bytes. + * Concatenation is likewise supported without copying (long strings) by building a tree of pieces + * in {@link RopeByteString}. + * + * @author crazybob@google.com Bob Lee + * @author kenton@google.com Kenton Varda + * @author carlanton@google.com Carl Haverl + * @author martinrb@google.com Martin Buchholz + */ +public abstract class ByteString implements Iterable, Serializable { + + /** + * When two strings to be concatenated have a combined length shorter than this, we just copy + * their bytes on {@link #concat(ByteString)}. The trade-off is copy size versus the overhead of + * creating tree nodes in {@link RopeByteString}. + */ + static final int CONCATENATE_BY_COPY_SIZE = 128; + + /** + * When copying an InputStream into a ByteString with .readFrom(), the chunks in the underlying + * rope start at 256 bytes, but double each iteration up to 8192 bytes. + */ + static final int MIN_READ_FROM_CHUNK_SIZE = 0x100; // 256b + + static final int MAX_READ_FROM_CHUNK_SIZE = 0x2000; // 8k + + /** Empty {@code ByteString}. */ + public static final ByteString EMPTY = new LiteralByteString(Internal.EMPTY_BYTE_ARRAY); + + /** + * An interface to efficiently copy {@code byte[]}. + * + *

One of the noticeable costs of copying a byte[] into a new array using {@code + * System.arraycopy} is nullification of a new buffer before the copy. It has been shown the + * Hotspot VM is capable to intrisicfy {@code Arrays.copyOfRange} operation to avoid this + * expensive nullification and provide substantial performance gain. Unfortunately this does not + * hold on Android runtimes and could make the copy slightly slower due to additional code in the + * {@code Arrays.copyOfRange}. Thus we provide two different implementation for array copier for + * Hotspot and Android runtimes. + */ + private interface ByteArrayCopier { + /** Copies the specified range of the specified array into a new array */ + byte[] copyFrom(byte[] bytes, int offset, int size); + } + + /** Implementation of {@code ByteArrayCopier} which uses {@link System#arraycopy}. */ + private static final class SystemByteArrayCopier implements ByteArrayCopier { + @Override + public byte[] copyFrom(byte[] bytes, int offset, int size) { + byte[] copy = new byte[size]; + System.arraycopy(bytes, offset, copy, 0, size); + return copy; + } + } + + /** Implementation of {@code ByteArrayCopier} which uses {@link Arrays#copyOfRange}. */ + private static final class ArraysByteArrayCopier implements ByteArrayCopier { + @Override + public byte[] copyFrom(byte[] bytes, int offset, int size) { + return Arrays.copyOfRange(bytes, offset, offset + size); + } + } + + private static final ByteArrayCopier byteArrayCopier; + + static { + byteArrayCopier = + Android.isOnAndroidDevice() ? new SystemByteArrayCopier() : new ArraysByteArrayCopier(); + } + + /** + * Cached hash value. Intentionally accessed via a data race, which is safe because of the Java + * Memory Model's "no out-of-thin-air values" guarantees for ints. A value of 0 implies that the + * hash has not been set. + */ + private int hash = 0; + + // This constructor is here to prevent subclassing outside of this package, + ByteString() {} + + /** + * Gets the byte at the given index. This method should be used only for random access to + * individual bytes. To access bytes sequentially, use the {@link ByteIterator} returned by {@link + * #iterator()}, and call {@link #substring(int, int)} first if necessary. + * + * @param index index of byte + * @return the value + * @throws IndexOutOfBoundsException {@code index < 0 or index >= size} + */ + public abstract byte byteAt(int index); + + /** + * Gets the byte at the given index, assumes bounds checking has already been performed. + * + * @param index index of byte + * @return the value + * @throws IndexOutOfBoundsException {@code index < 0 or index >= size} + */ + abstract byte internalByteAt(int index); + + /** + * Return a {@link ByteString.ByteIterator} over the bytes in the ByteString. To avoid + * auto-boxing, you may get the iterator manually and call {@link ByteIterator#nextByte()}. + * + * @return the iterator + */ + @Override + public ByteIterator iterator() { + return new AbstractByteIterator() { + private int position = 0; + private final int limit = size(); + + @Override + public boolean hasNext() { + return position < limit; + } + + @Override + public byte nextByte() { + int currentPos = position; + if (currentPos >= limit) { + throw new NoSuchElementException(); + } + position = currentPos + 1; + return internalByteAt(currentPos); + } + }; + } + + /** + * This interface extends {@code Iterator}, so that we can return an unboxed {@code byte}. + */ + public interface ByteIterator extends Iterator { + /** + * An alternative to {@link Iterator#next()} that returns an unboxed primitive {@code byte}. + * + * @return the next {@code byte} in the iteration + * @throws NoSuchElementException if the iteration has no more elements + */ + byte nextByte(); + } + + abstract static class AbstractByteIterator implements ByteIterator { + @Override + public final Byte next() { + // Boxing calls Byte.valueOf(byte), which does not instantiate. + return nextByte(); + } + + @Override + public final void remove() { + throw new UnsupportedOperationException(); + } + } + + /** + * Gets the number of bytes. + * + * @return size in bytes + */ + public abstract int size(); + + /** + * Returns {@code true} if the size is {@code 0}, {@code false} otherwise. + * + * @return true if this is zero bytes long + */ + public final boolean isEmpty() { + return size() == 0; + } + + // ================================================================= + // Comparison + + private static final int UNSIGNED_BYTE_MASK = 0xFF; + + /** + * Returns the value of the given byte as an integer, interpreting the byte as an unsigned value. + * That is, returns {@code value + 256} if {@code value} is negative; {@code value} itself + * otherwise. + * + *

Note: This code was copied from {@link com.google.common.primitives.UnsignedBytes#toInt}, as + * Guava libraries cannot be used in the {@code com.google.protobuf} package. + */ + private static int toInt(byte value) { + return value & UNSIGNED_BYTE_MASK; + } + + /** + * Compares two {@link ByteString}s lexicographically, treating their contents as unsigned byte + * values between 0 and 255 (inclusive). + * + *

For example, {@code (byte) -1} is considered to be greater than {@code (byte) 1} because it + * is interpreted as an unsigned value, {@code 255}. + */ + private static final Comparator UNSIGNED_LEXICOGRAPHICAL_COMPARATOR = + new Comparator() { + @Override + public int compare(ByteString former, ByteString latter) { + ByteIterator formerBytes = former.iterator(); + ByteIterator latterBytes = latter.iterator(); + + while (formerBytes.hasNext() && latterBytes.hasNext()) { + // Note: This code was copied from com.google.common.primitives.UnsignedBytes#compare, + // as Guava libraries cannot be used in the {@code com.google.protobuf} package. + int result = + Integer.compare(toInt(formerBytes.nextByte()), toInt(latterBytes.nextByte())); + if (result != 0) { + return result; + } + } + + return Integer.compare(former.size(), latter.size()); + } + }; + + /** + * Returns a {@link Comparator} which compares {@link ByteString}-s lexicographically + * as sequences of unsigned bytes (i.e. values between 0 and 255, inclusive). + * + *

For example, {@code (byte) -1} is considered to be greater than {@code (byte) 1} because it + * is interpreted as an unsigned value, {@code 255}: + * + *

    + *
  • {@code `-1` -> 0b11111111 (two's complement) -> 255} + *
  • {@code `1` -> 0b00000001 -> 1} + *
+ */ + public static Comparator unsignedLexicographicalComparator() { + return UNSIGNED_LEXICOGRAPHICAL_COMPARATOR; + } + + // ================================================================= + // ByteString -> substring + + /** + * Return the substring from {@code beginIndex}, inclusive, to the end of the string. + * + * @param beginIndex start at this index + * @return substring sharing underlying data + * @throws IndexOutOfBoundsException if {@code beginIndex < 0} or {@code beginIndex > size()}. + */ + public final ByteString substring(int beginIndex) { + return substring(beginIndex, size()); + } + + /** + * Return the substring from {@code beginIndex}, inclusive, to {@code endIndex}, exclusive. + * + * @param beginIndex start at this index + * @param endIndex the last character is the one before this index + * @return substring sharing underlying data + * @throws IndexOutOfBoundsException if {@code beginIndex < 0}, {@code endIndex > size()}, or + * {@code beginIndex > endIndex}. + */ + public abstract ByteString substring(int beginIndex, int endIndex); + + /** + * Tests if this bytestring starts with the specified prefix. Similar to {@link + * String#startsWith(String)} + * + * @param prefix the prefix. + * @return true if the byte sequence represented by the argument is a prefix of the + * byte sequence represented by this string; false otherwise. + */ + public final boolean startsWith(ByteString prefix) { + return size() >= prefix.size() && substring(0, prefix.size()).equals(prefix); + } + + /** + * Tests if this bytestring ends with the specified suffix. Similar to {@link + * String#endsWith(String)} + * + * @param suffix the suffix. + * @return true if the byte sequence represented by the argument is a suffix of the + * byte sequence represented by this string; false otherwise. + */ + public final boolean endsWith(ByteString suffix) { + return size() >= suffix.size() && substring(size() - suffix.size()).equals(suffix); + } + + // ================================================================= + // byte[] -> ByteString + + /** + * Copies the given bytes into a {@code ByteString}. + * + * @param bytes source array + * @param offset offset in source array + * @param size number of bytes to copy + * @return new {@code ByteString} + * @throws IndexOutOfBoundsException if {@code offset} or {@code size} are out of bounds + */ + public static ByteString copyFrom(byte[] bytes, int offset, int size) { + checkRange(offset, offset + size, bytes.length); + return new LiteralByteString(byteArrayCopier.copyFrom(bytes, offset, size)); + } + + /** + * Copies the given bytes into a {@code ByteString}. + * + * @param bytes to copy + * @return new {@code ByteString} + */ + public static ByteString copyFrom(byte[] bytes) { + return copyFrom(bytes, 0, bytes.length); + } + + /** Wraps the given bytes into a {@code ByteString}. Intended for internal only usage. */ + static ByteString wrap(ByteBuffer buffer) { + if (buffer.hasArray()) { + final int offset = buffer.arrayOffset(); + return ByteString.wrap(buffer.array(), offset + buffer.position(), buffer.remaining()); + } else { + return new NioByteString(buffer); + } + } + + /** + * Wraps the given bytes into a {@code ByteString}. Intended for internal only usage to force a + * classload of ByteString before LiteralByteString. + */ + static ByteString wrap(byte[] bytes) { + // TODO(dweis): Return EMPTY when bytes are empty to reduce allocations? + return new LiteralByteString(bytes); + } + + /** + * Wraps the given bytes into a {@code ByteString}. Intended for internal only usage 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); + } + + /** + * Copies the next {@code size} bytes from a {@code java.nio.ByteBuffer} into a {@code + * ByteString}. + * + * @param bytes source buffer + * @param size number of bytes to copy + * @return new {@code ByteString} + * @throws IndexOutOfBoundsException if {@code size > bytes.remaining()} + */ + 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); + } + + /** + * Copies the remaining bytes from a {@code java.nio.ByteBuffer} into a {@code ByteString}. + * + * @param bytes sourceBuffer + * @return new {@code ByteString} + */ + public static ByteString copyFrom(ByteBuffer bytes) { + return copyFrom(bytes, bytes.remaining()); + } + + /** + * Encodes {@code text} into a sequence of bytes using the named charset and returns the result as + * a {@code ByteString}. + * + * @param text source string + * @param charsetName encoding to use + * @return new {@code ByteString} + * @throws UnsupportedEncodingException if the encoding isn't found + */ + public static ByteString copyFrom(String text, String charsetName) + throws UnsupportedEncodingException { + return new LiteralByteString(text.getBytes(charsetName)); + } + + /** + * Encodes {@code text} into a sequence of bytes using the named charset and returns the result as + * a {@code ByteString}. + * + * @param text source string + * @param charset encode using this charset + * @return new {@code ByteString} + */ + public static ByteString copyFrom(String text, Charset charset) { + return new LiteralByteString(text.getBytes(charset)); + } + + /** + * Encodes {@code text} into a sequence of UTF-8 bytes and returns the result as a {@code + * ByteString}. + * + * @param text source string + * @return new {@code ByteString} + */ + public static ByteString copyFromUtf8(String text) { + return new LiteralByteString(text.getBytes(Internal.UTF_8)); + } + + // ================================================================= + // InputStream -> ByteString + + /** + * Completely reads the given stream's bytes into a {@code ByteString}, blocking if necessary + * until all bytes are read through to the end of the stream. + * + *

Performance notes: The returned {@code ByteString} is an immutable tree of byte + * arrays ("chunks") of the stream data. The first chunk is small, with subsequent chunks each + * being double the size, up to 8K. + * + *

Each byte read from the input stream will be copied twice to ensure that the resulting + * ByteString is truly immutable. + * + * @param streamToDrain The source stream, which is read completely but not closed. + * @return A new {@code ByteString} which is made up of chunks of various sizes, depending on the + * behavior of the underlying stream. + * @throws IOException IOException is thrown if there is a problem reading the underlying stream. + */ + public static ByteString readFrom(InputStream streamToDrain) throws IOException { + return readFrom(streamToDrain, MIN_READ_FROM_CHUNK_SIZE, MAX_READ_FROM_CHUNK_SIZE); + } + + /** + * Completely reads the given stream's bytes into a {@code ByteString}, blocking if necessary + * until all bytes are read through to the end of the stream. + * + *

Performance notes: The returned {@code ByteString} is an immutable tree of byte + * arrays ("chunks") of the stream data. The chunkSize parameter sets the size of these byte + * arrays. + * + *

Each byte read from the input stream will be copied twice to ensure that the resulting + * ByteString is truly immutable. + * + * @param streamToDrain The source stream, which is read completely but not closed. + * @param chunkSize The size of the chunks in which to read the stream. + * @return A new {@code ByteString} which is made up of chunks of the given size. + * @throws IOException IOException is thrown if there is a problem reading the underlying stream. + */ + public static ByteString readFrom(InputStream streamToDrain, int chunkSize) throws IOException { + return readFrom(streamToDrain, chunkSize, chunkSize); + } + + // Helper method that takes the chunk size range as a parameter. + public static ByteString readFrom(InputStream streamToDrain, int minChunkSize, int maxChunkSize) + throws IOException { + Collection results = new ArrayList(); + + // copy the inbound bytes into a list of chunks; the chunk size + // grows exponentially to support both short and long streams. + int chunkSize = minChunkSize; + while (true) { + ByteString chunk = readChunk(streamToDrain, chunkSize); + if (chunk == null) { + break; + } + results.add(chunk); + chunkSize = Math.min(chunkSize * 2, maxChunkSize); + } + + return ByteString.copyFrom(results); + } + + /** + * Blocks until a chunk of the given size can be made from the stream, or EOF is reached. Calls + * read() repeatedly in case the given stream implementation doesn't completely fill the given + * buffer in one read() call. + * + * @return A chunk of the desired size, or else a chunk as large as was available when end of + * stream was reached. Returns null if the given stream had no more data in it. + */ + private static ByteString readChunk(InputStream in, final int chunkSize) throws IOException { + final byte[] buf = new byte[chunkSize]; + int bytesRead = 0; + while (bytesRead < chunkSize) { + final int count = in.read(buf, bytesRead, chunkSize - bytesRead); + if (count == -1) { + break; + } + bytesRead += count; + } + + if (bytesRead == 0) { + return null; + } + + // Always make a copy since InputStream could steal a reference to buf. + return ByteString.copyFrom(buf, 0, bytesRead); + } + + // ================================================================= + // Multiple ByteStrings -> One ByteString + + /** + * Concatenate the given {@code ByteString} to this one. Short concatenations, of total size + * smaller than {@link ByteString#CONCATENATE_BY_COPY_SIZE}, are produced by copying the + * underlying bytes (as per Rope.java, + * BAP95 . In general, the concatenate involves no copying. + * + * @param other string to concatenate + * @return a new {@code ByteString} instance + */ + public final ByteString concat(ByteString other) { + if (Integer.MAX_VALUE - size() < other.size()) { + throw new IllegalArgumentException( + "ByteString would be too long: " + size() + "+" + other.size()); + } + + return RopeByteString.concatenate(this, other); + } + + /** + * Concatenates all byte strings in the iterable and returns the result. This is designed to run + * in O(list size), not O(total bytes). + * + *

The returned {@code ByteString} is not necessarily a unique object. If the list is empty, + * the returned object is the singleton empty {@code ByteString}. If the list has only one + * element, that {@code ByteString} will be returned without copying. + * + * @param byteStrings strings to be concatenated + * @return new {@code ByteString} + */ + public static ByteString copyFrom(Iterable byteStrings) { + // Determine the size; + final int size; + if (!(byteStrings instanceof Collection)) { + int tempSize = 0; + for (Iterator iter = byteStrings.iterator(); + iter.hasNext(); + iter.next(), ++tempSize) {} + size = tempSize; + } else { + size = ((Collection) byteStrings).size(); + } + + if (size == 0) { + return EMPTY; + } + + return balancedConcat(byteStrings.iterator(), size); + } + + // Internal function used by copyFrom(Iterable). + // Create a balanced concatenation of the next "length" elements from the + // iterable. + private static ByteString balancedConcat(Iterator iterator, int length) { + if (length < 1) { + throw new IllegalArgumentException(String.format("length (%s) must be >= 1", length)); + } + ByteString result; + if (length == 1) { + result = iterator.next(); + } else { + int halfLength = length >>> 1; + ByteString left = balancedConcat(iterator, halfLength); + ByteString right = balancedConcat(iterator, length - halfLength); + result = left.concat(right); + } + return result; + } + + // ================================================================= + // ByteString -> byte[] + + /** + * Copies bytes into a buffer at the given offset. + * + *

To copy a subset of bytes, you call this method on the return value of {@link + * #substring(int, int)}. Example: {@code byteString.substring(start, end).copyTo(target, offset)} + * + * @param target buffer to copy into + * @param offset in the target buffer + * @throws IndexOutOfBoundsException if the offset is negative or too large + */ + public void copyTo(byte[] target, int offset) { + copyTo(target, 0, offset, size()); + } + + /** + * Copies bytes into a buffer. + * + * @param target buffer to copy into + * @param sourceOffset offset within these bytes + * @param targetOffset offset within the target buffer + * @param numberToCopy number of bytes to copy + * @throws IndexOutOfBoundsException if an offset or size is negative or too large + * @deprecated Instead, call {@code byteString.substring(sourceOffset, sourceOffset + + * numberToCopy).copyTo(target, targetOffset)} + */ + @Deprecated + public final void copyTo(byte[] target, int sourceOffset, int targetOffset, int numberToCopy) { + checkRange(sourceOffset, sourceOffset + numberToCopy, size()); + checkRange(targetOffset, targetOffset + numberToCopy, target.length); + if (numberToCopy > 0) { + copyToInternal(target, sourceOffset, targetOffset, numberToCopy); + } + } + + /** + * Internal (package private) implementation of {@link #copyTo(byte[],int,int,int)}. It assumes + * that all error checking has already been performed and that {@code numberToCopy > 0}. + */ + protected abstract void copyToInternal( + byte[] target, int sourceOffset, int targetOffset, int numberToCopy); + + /** + * Copies bytes into a ByteBuffer. + * + *

To copy a subset of bytes, you call this method on the return value of {@link + * #substring(int, int)}. Example: {@code byteString.substring(start, end).copyTo(target)} + * + * @param target ByteBuffer to copy into. + * @throws java.nio.ReadOnlyBufferException if the {@code target} is read-only + * @throws java.nio.BufferOverflowException if the {@code target}'s remaining() space is not large + * enough to hold the data. + */ + public abstract void copyTo(ByteBuffer target); + + /** + * Copies bytes to a {@code byte[]}. + * + * @return copied bytes + */ + public final byte[] toByteArray() { + final int size = size(); + if (size == 0) { + return Internal.EMPTY_BYTE_ARRAY; + } + byte[] result = new byte[size]; + copyToInternal(result, 0, 0, size); + return result; + } + + /** + * Writes a copy of the contents of this byte string to the specified output stream argument. + * + * @param out the output stream to which to write the data. + * @throws IOException if an I/O error occurs. + */ + public abstract void writeTo(OutputStream out) throws IOException; + + /** + * Writes a specified part of this byte string to an output stream. + * + * @param out the output stream to which to write the data. + * @param sourceOffset offset within these bytes + * @param numberToWrite number of bytes to write + * @throws IOException if an I/O error occurs. + * @throws IndexOutOfBoundsException if an offset or size is negative or too large + */ + final void writeTo(OutputStream out, int sourceOffset, int numberToWrite) throws IOException { + checkRange(sourceOffset, sourceOffset + numberToWrite, size()); + if (numberToWrite > 0) { + writeToInternal(out, sourceOffset, numberToWrite); + } + } + + /** + * Internal version of {@link #writeTo(OutputStream,int,int)} that assumes all error checking has + * already been done. + */ + abstract void writeToInternal(OutputStream out, int sourceOffset, int numberToWrite) + throws IOException; + + /** + * Writes this {@link ByteString} to the provided {@link ByteOutput}. Calling this method may + * result in multiple operations on the target {@link ByteOutput}. + * + *

This method may expose internal backing buffers of the {@link ByteString} to the {@link + * ByteOutput} in order to avoid additional copying overhead. It would be possible for a malicious + * {@link ByteOutput} to corrupt the {@link ByteString}. Use with caution! + * + * @param byteOutput the output target to receive the bytes + * @throws IOException if an I/O error occurs + * @see UnsafeByteOperations#unsafeWriteTo(ByteString, ByteOutput) + */ + abstract void writeTo(ByteOutput byteOutput) throws IOException; + + /** + * This method behaves exactly the same as {@link #writeTo(ByteOutput)} unless the {@link + * ByteString} is a rope. For ropes, the leaf nodes are written in reverse order to the {@code + * byteOutput}. + * + * @param byteOutput the output target to receive the bytes + * @throws IOException if an I/O error occurs + * @see UnsafeByteOperations#unsafeWriteToReverse(ByteString, ByteOutput) + */ + abstract void writeToReverse(ByteOutput byteOutput) throws IOException; + + /** + * Constructs a read-only {@code java.nio.ByteBuffer} whose content is equal to the contents of + * this byte string. The result uses the same backing array as the byte string, if possible. + * + * @return wrapped bytes + */ + public abstract ByteBuffer asReadOnlyByteBuffer(); + + /** + * Constructs a list of read-only {@code java.nio.ByteBuffer} objects such that the concatenation + * of their contents is equal to the contents of this byte string. The result uses the same + * backing arrays as the byte string. + * + *

By returning a list, implementations of this method may be able to avoid copying even when + * there are multiple backing arrays. + * + * @return a list of wrapped bytes + */ + public abstract List asReadOnlyByteBufferList(); + + /** + * Constructs a new {@code String} by decoding the bytes using the specified charset. + * + * @param charsetName encode using this charset + * @return new string + * @throws UnsupportedEncodingException if charset isn't recognized + */ + public final String toString(String charsetName) throws UnsupportedEncodingException { + try { + return toString(Charset.forName(charsetName)); + } catch (UnsupportedCharsetException e) { + UnsupportedEncodingException exception = new UnsupportedEncodingException(charsetName); + exception.initCause(e); + throw exception; + } + } + + /** + * Constructs a new {@code String} by decoding the bytes using the specified charset. Returns the + * same empty String if empty. + * + * @param charset encode using this charset + * @return new string + */ + public final String toString(Charset charset) { + return size() == 0 ? "" : toStringInternal(charset); + } + + /** + * Constructs a new {@code String} by decoding the bytes using the specified charset. + * + * @param charset encode using this charset + * @return new string + */ + protected abstract String toStringInternal(Charset charset); + + // ================================================================= + // UTF-8 decoding + + /** + * Constructs a new {@code String} by decoding the bytes as UTF-8. + * + * @return new string using UTF-8 encoding + */ + public final String toStringUtf8() { + return toString(Internal.UTF_8); + } + + /** + * Tells whether this {@code ByteString} represents a well-formed UTF-8 byte sequence, such that + * the original bytes can be converted to a String object and then round tripped back to bytes + * without loss. + * + *

More precisely, returns {@code true} whenever: + * + *

{@code
+   * Arrays.equals(byteString.toByteArray(),
+   *     new String(byteString.toByteArray(), "UTF-8").getBytes("UTF-8"))
+   * }
+ * + *

This method returns {@code false} for "overlong" byte sequences, as well as for 3-byte + * sequences that would map to a surrogate character, in accordance with the restricted definition + * of UTF-8 introduced in Unicode 3.1. Note that the UTF-8 decoder included in Oracle's JDK has + * been modified to also reject "overlong" byte sequences, but (as of 2011) still accepts 3-byte + * surrogate character byte sequences. + * + *

See the Unicode Standard,
+ * Table 3-6. UTF-8 Bit Distribution,
+ * Table 3-7. Well Formed UTF-8 Byte Sequences. + * + * @return whether the bytes in this {@code ByteString} are a well-formed UTF-8 byte sequence + */ + public abstract boolean isValidUtf8(); + + /** + * Tells whether the given byte sequence is a well-formed, malformed, or incomplete UTF-8 byte + * sequence. This method accepts and returns a partial state result, allowing the bytes for a + * complete UTF-8 byte sequence to be composed from multiple {@code ByteString} segments. + * + * @param state either {@code 0} (if this is the initial decoding operation) or the value returned + * from a call to a partial decoding method for the previous bytes + * @param offset offset of the first byte to check + * @param length number of bytes to check + * @return {@code -1} if the partial byte sequence is definitely malformed, {@code 0} if it is + * well-formed (no additional input needed), or, if the byte sequence is "incomplete", i.e. + * apparently terminated in the middle of a character, an opaque integer "state" value + * containing enough information to decode the character when passed to a subsequent + * invocation of a partial decoding method. + */ + protected abstract int partialIsValidUtf8(int state, int offset, int length); + + // ================================================================= + // equals() and hashCode() + + @Override + public abstract boolean equals(Object o); + + /** Base class for leaf {@link ByteString}s (i.e. non-ropes). */ + abstract static class LeafByteString extends ByteString { + @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}. + * + * @return hashCode value + */ + @Override + public final int hashCode() { + int h = hash; + + if (h == 0) { + int size = size(); + h = partialHash(size, 0, size); + if (h == 0) { + h = 1; + } + hash = h; + } + return h; + } + + // ================================================================= + // Input stream + + /** + * Creates an {@code InputStream} which can be used to read the bytes. + * + *

The {@link InputStream} returned by this method is guaranteed to be completely non-blocking. + * The method {@link InputStream#available()} returns the number of bytes remaining in the stream. + * The methods {@link InputStream#read(byte[])}, {@link InputStream#read(byte[],int,int)} and + * {@link InputStream#skip(long)} will read/skip as many bytes as are available. The method {@link + * InputStream#markSupported()} returns {@code true}. + * + *

The methods in the returned {@link InputStream} might not be thread safe. + * + * @return an input stream that returns the bytes of this byte string. + */ + public abstract InputStream newInput(); + + /** + * Creates a {@link CodedInputStream} which can be used to read the bytes. Using this is often + * more efficient than creating a {@link CodedInputStream} that wraps the result of {@link + * #newInput()}. + * + * @return stream based on wrapped data + */ + public abstract CodedInputStream newCodedInput(); + + // ================================================================= + // Output stream + + /** + * Creates a new {@link Output} with the given initial capacity. Call {@link + * Output#toByteString()} to create the {@code ByteString} instance. + * + *

A {@link ByteString.Output} offers the same functionality as a {@link + * ByteArrayOutputStream}, except that it returns a {@link ByteString} rather than a {@code byte} + * array. + * + * @param initialCapacity estimate of number of bytes to be written + * @return {@code OutputStream} for building a {@code ByteString} + */ + public static Output newOutput(int initialCapacity) { + return new Output(initialCapacity); + } + + /** + * Creates a new {@link Output}. Call {@link Output#toByteString()} to create the {@code + * ByteString} instance. + * + *

A {@link ByteString.Output} offers the same functionality as a {@link + * ByteArrayOutputStream}, except that it returns a {@link ByteString} rather than a {@code byte + * array}. + * + * @return {@code OutputStream} for building a {@code ByteString} + */ + public static Output newOutput() { + return new Output(CONCATENATE_BY_COPY_SIZE); + } + + /** + * Outputs to a {@code ByteString} instance. Call {@link #toByteString()} to create the {@code + * ByteString} instance. + */ + public static final class Output extends OutputStream { + // Implementation note. + // The public methods of this class must be synchronized. ByteStrings + // are guaranteed to be immutable. Without some sort of locking, it could + // be possible for one thread to call toByteSring(), while another thread + // is still modifying the underlying byte array. + + private static final byte[] EMPTY_BYTE_ARRAY = new byte[0]; + // argument passed by user, indicating initial capacity. + private final int initialCapacity; + // ByteStrings to be concatenated to create the result + private final ArrayList flushedBuffers; + // Total number of bytes in the ByteStrings of flushedBuffers + private int flushedBuffersTotalBytes; + // Current buffer to which we are writing + private byte[] buffer; + // Location in buffer[] to which we write the next byte. + private int bufferPos; + + /** + * Creates a new ByteString output stream with the specified initial capacity. + * + * @param initialCapacity the initial capacity of the output stream. + */ + Output(int initialCapacity) { + if (initialCapacity < 0) { + throw new IllegalArgumentException("Buffer size < 0"); + } + this.initialCapacity = initialCapacity; + this.flushedBuffers = new ArrayList(); + this.buffer = new byte[initialCapacity]; + } + + @Override + public synchronized void write(int b) { + if (bufferPos == buffer.length) { + flushFullBuffer(1); + } + buffer[bufferPos++] = (byte) b; + } + + @Override + public synchronized void write(byte[] b, int offset, int length) { + if (length <= buffer.length - bufferPos) { + // The bytes can fit into the current buffer. + System.arraycopy(b, offset, buffer, bufferPos, length); + bufferPos += length; + } else { + // Use up the current buffer + int copySize = buffer.length - bufferPos; + System.arraycopy(b, offset, buffer, bufferPos, copySize); + offset += copySize; + length -= copySize; + // Flush the buffer, and get a new buffer at least big enough to cover + // what we still need to output + flushFullBuffer(length); + System.arraycopy(b, offset, buffer, /* count= */ 0, length); + bufferPos = length; + } + } + + /** + * Creates a byte string with the size and contents of this output stream. This does not create + * a new copy of the underlying bytes. If the stream size grows dynamically, the runtime is + * O(log n) in respect to the number of bytes written to the {@link Output}. If the stream size + * stays within the initial capacity, the runtime is O(1). + * + * @return the current contents of this output stream, as a byte string. + */ + public synchronized ByteString toByteString() { + flushLastBuffer(); + return ByteString.copyFrom(flushedBuffers); + } + + /** Implement java.util.Arrays.copyOf() for jdk 1.5. */ + private byte[] copyArray(byte[] buffer, int length) { + byte[] result = new byte[length]; + System.arraycopy(buffer, 0, result, 0, Math.min(buffer.length, length)); + return result; + } + + /** + * Writes the complete contents of this byte array output stream to the specified output stream + * argument. + * + * @param out the output stream to which to write the data. + * @throws IOException if an I/O error occurs. + */ + public void writeTo(OutputStream out) throws IOException { + ByteString[] cachedFlushBuffers; + byte[] cachedBuffer; + int cachedBufferPos; + synchronized (this) { + // Copy the information we need into local variables so as to hold + // the lock for as short a time as possible. + cachedFlushBuffers = flushedBuffers.toArray(new ByteString[flushedBuffers.size()]); + cachedBuffer = buffer; + cachedBufferPos = bufferPos; + } + for (ByteString byteString : cachedFlushBuffers) { + byteString.writeTo(out); + } + + out.write(copyArray(cachedBuffer, cachedBufferPos)); + } + + /** + * Returns the current size of the output stream. + * + * @return the current size of the output stream + */ + public synchronized int size() { + return flushedBuffersTotalBytes + bufferPos; + } + + /** + * Resets this stream, so that all currently accumulated output in the output stream is + * discarded. The output stream can be used again, reusing the already allocated buffer space. + */ + public synchronized void reset() { + flushedBuffers.clear(); + flushedBuffersTotalBytes = 0; + bufferPos = 0; + } + + @Override + public String toString() { + return String.format( + "", + Integer.toHexString(System.identityHashCode(this)), size()); + } + + /** + * Internal function used by writers. The current buffer is full, and the writer needs a new + * buffer whose size is at least the specified minimum size. + */ + private void flushFullBuffer(int minSize) { + 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 + // >= initial Capacity. + int newSize = Math.max(initialCapacity, Math.max(minSize, flushedBuffersTotalBytes >>> 1)); + buffer = new byte[newSize]; + bufferPos = 0; + } + + /** + * Internal function used by {@link #toByteString()}. The current buffer may or may not be full, + * but it needs to be flushed. + */ + private void flushLastBuffer() { + if (bufferPos < buffer.length) { + if (bufferPos > 0) { + byte[] bufferCopy = copyArray(buffer, bufferPos); + flushedBuffers.add(new LiteralByteString(bufferCopy)); + } + // We reuse this buffer for further writes. + } else { + // Buffer is completely full. Huzzah. + 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 + // *do* occur, this empty buffer will be flushed and an appropriately + // sized new buffer will be created. + buffer = EMPTY_BYTE_ARRAY; + } + flushedBuffersTotalBytes += bufferPos; + bufferPos = 0; + } + } + + /** + * Constructs a new {@code ByteString} builder, which allows you to efficiently construct a {@code + * ByteString} by writing to a {@link CodedOutputStream}. Using this is much more efficient than + * calling {@code newOutput()} and wrapping that in a {@code CodedOutputStream}. + * + *

This is package-private because it's a somewhat confusing interface. Users can call {@link + * Message#toByteString()} instead of calling this directly. + * + * @param size The target byte size of the {@code ByteString}. You must write exactly this many + * bytes before building the result. + * @return the builder + */ + static CodedBuilder newCodedBuilder(int size) { + return new CodedBuilder(size); + } + + /** See {@link ByteString#newCodedBuilder(int)}. */ + static final class CodedBuilder { + private final CodedOutputStream output; + private final byte[] buffer; + + private CodedBuilder(int size) { + buffer = new byte[size]; + output = CodedOutputStream.newInstance(buffer); + } + + public ByteString build() { + output.checkNoSpaceLeft(); + + // 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); + } + + public CodedOutputStream getCodedOutput() { + return output; + } + } + + // ================================================================= + // Methods {@link RopeByteString} needs on instances, which aren't part of the + // public API. + + /** + * Return the depth of the tree representing this {@code ByteString}, if any, whose root is this + * node. If this is a leaf node, return 0. + * + * @return tree depth or zero + */ + protected abstract int getTreeDepth(); + + /** + * Return {@code true} if this ByteString is literal (a leaf node) or a flat-enough tree in the + * sense of {@link RopeByteString}. + * + * @return true if the tree is flat enough + */ + protected abstract boolean isBalanced(); + + /** + * Return the cached hash code if available. + * + * @return value of cached hash code or 0 if not computed yet + */ + protected final int peekCachedHashCode() { + return hash; + } + + /** + * Compute the hash across the value bytes starting with the given hash, and return the result. + * This is used to compute the hash across strings represented as a set of pieces by allowing the + * hash computation to be continued from piece to piece. + * + * @param h starting hash value + * @param offset offset into this value to start looking at data values + * @param length number of data values to include in the hash computation + * @return ending hash value + */ + protected abstract int partialHash(int h, int offset, int length); + + /** + * Checks that the given index falls within the specified array size. + * + * @param index the index position to be tested + * @param size the length of the array + * @throws IndexOutOfBoundsException if the index does not fall within the array. + */ + static void checkIndex(int index, int size) { + if ((index | (size - (index + 1))) < 0) { + if (index < 0) { + throw new ArrayIndexOutOfBoundsException("Index < 0: " + index); + } + throw new ArrayIndexOutOfBoundsException("Index > length: " + index + ", " + size); + } + } + + /** + * Checks that the given range falls within the bounds of an array + * + * @param startIndex the start index of the range (inclusive) + * @param endIndex the end index of the range (exclusive) + * @param size the size of the array. + * @return the length of the range. + * @throws IndexOutOfBoundsException some or all of the range falls outside of the array. + */ + static int checkRange(int startIndex, int endIndex, int size) { + final int length = endIndex - startIndex; + if ((startIndex | endIndex | length | (size - endIndex)) < 0) { + if (startIndex < 0) { + throw new IndexOutOfBoundsException("Beginning index: " + startIndex + " < 0"); + } + if (endIndex < startIndex) { + throw new IndexOutOfBoundsException( + "Beginning index larger than ending index: " + startIndex + ", " + endIndex); + } + // endIndex >= size + throw new IndexOutOfBoundsException("End index: " + endIndex + " >= " + size); + } + return length; + } + + @Override + public final String toString() { + return String.format( + Locale.ROOT, + "", + toHexString(identityHashCode(this)), + size(), + truncateAndEscapeForDisplay()); + } + + private String truncateAndEscapeForDisplay() { + final int limit = 50; + + 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(nathanmittler): 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/java/kotlin-lite/target/generated-sources/com/google/protobuf/BytesValue.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/BytesValue.java new file mode 100644 index 0000000000000..c8e2c214fc96c --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/BytesValue.java @@ -0,0 +1,278 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/wrappers.proto + +package com.google.protobuf; + +/** + *

+ * Wrapper message for `bytes`.
+ * The JSON representation for `BytesValue` is JSON string.
+ * 
+ * + * Protobuf type {@code google.protobuf.BytesValue} + */ +public final class BytesValue extends + com.google.protobuf.GeneratedMessageLite< + BytesValue, BytesValue.Builder> implements + // @@protoc_insertion_point(message_implements:google.protobuf.BytesValue) + BytesValueOrBuilder { + private BytesValue() { + value_ = com.google.protobuf.ByteString.EMPTY; + } + public static final int VALUE_FIELD_NUMBER = 1; + private com.google.protobuf.ByteString value_; + /** + *
+   * The bytes value.
+   * 
+ * + * bytes value = 1; + * @return The value. + */ + @java.lang.Override + public com.google.protobuf.ByteString getValue() { + return value_; + } + /** + *
+   * The bytes value.
+   * 
+ * + * bytes value = 1; + * @param value The value to set. + */ + private void setValue(com.google.protobuf.ByteString value) { + value.getClass(); + + value_ = value; + } + /** + *
+   * The bytes value.
+   * 
+ * + * bytes value = 1; + */ + private void clearValue() { + + value_ = getDefaultInstance().getValue(); + } + + public static com.google.protobuf.BytesValue parseFrom( + java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.BytesValue parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.BytesValue parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.BytesValue parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.BytesValue parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.BytesValue parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.BytesValue parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, 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.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, input, extensionRegistry); + } + public static com.google.protobuf.BytesValue parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return parseDelimitedFrom(DEFAULT_INSTANCE, input); + } + public static com.google.protobuf.BytesValue parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return parseDelimitedFrom(DEFAULT_INSTANCE, input, extensionRegistry); + } + public static com.google.protobuf.BytesValue parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, 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.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, input, extensionRegistry); + } + + public static Builder newBuilder() { + return (Builder) DEFAULT_INSTANCE.createBuilder(); + } + public static Builder newBuilder(com.google.protobuf.BytesValue prototype) { + return (Builder) DEFAULT_INSTANCE.createBuilder(prototype); + } + + /** + *
+   * Wrapper message for `bytes`.
+   * The JSON representation for `BytesValue` is JSON string.
+   * 
+ * + * Protobuf type {@code google.protobuf.BytesValue} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessageLite.Builder< + com.google.protobuf.BytesValue, Builder> implements + // @@protoc_insertion_point(builder_implements:google.protobuf.BytesValue) + com.google.protobuf.BytesValueOrBuilder { + // Construct using com.google.protobuf.BytesValue.newBuilder() + private Builder() { + super(DEFAULT_INSTANCE); + } + + + /** + *
+     * The bytes value.
+     * 
+ * + * bytes value = 1; + * @return The value. + */ + @java.lang.Override + public com.google.protobuf.ByteString getValue() { + return instance.getValue(); + } + /** + *
+     * The bytes value.
+     * 
+ * + * bytes value = 1; + * @param value The value to set. + * @return This builder for chaining. + */ + public Builder setValue(com.google.protobuf.ByteString value) { + copyOnWrite(); + instance.setValue(value); + return this; + } + /** + *
+     * The bytes value.
+     * 
+ * + * bytes value = 1; + * @return This builder for chaining. + */ + public Builder clearValue() { + copyOnWrite(); + instance.clearValue(); + return this; + } + + // @@protoc_insertion_point(builder_scope:google.protobuf.BytesValue) + } + @java.lang.Override + @java.lang.SuppressWarnings({"unchecked", "fallthrough"}) + protected final java.lang.Object dynamicMethod( + com.google.protobuf.GeneratedMessageLite.MethodToInvoke method, + java.lang.Object arg0, java.lang.Object arg1) { + switch (method) { + case NEW_MUTABLE_INSTANCE: { + return new com.google.protobuf.BytesValue(); + } + case NEW_BUILDER: { + return new Builder(); + } + case BUILD_MESSAGE_INFO: { + java.lang.Object[] objects = new java.lang.Object[] { + "value_", + }; + java.lang.String info = + "\u0000\u0001\u0000\u0000\u0001\u0001\u0001\u0000\u0000\u0000\u0001\n"; + return newMessageInfo(DEFAULT_INSTANCE, info, objects); + } + // fall through + case GET_DEFAULT_INSTANCE: { + return DEFAULT_INSTANCE; + } + case GET_PARSER: { + com.google.protobuf.Parser parser = PARSER; + if (parser == null) { + synchronized (com.google.protobuf.BytesValue.class) { + parser = PARSER; + if (parser == null) { + parser = + new DefaultInstanceBasedParser( + DEFAULT_INSTANCE); + PARSER = parser; + } + } + } + return parser; + } + case GET_MEMOIZED_IS_INITIALIZED: { + return (byte) 1; + } + case SET_MEMOIZED_IS_INITIALIZED: { + return null; + } + } + throw new UnsupportedOperationException(); + } + + + // @@protoc_insertion_point(class_scope:google.protobuf.BytesValue) + private static final com.google.protobuf.BytesValue DEFAULT_INSTANCE; + static { + BytesValue defaultInstance = new BytesValue(); + // New instances are implicitly immutable so no need to make + // immutable. + DEFAULT_INSTANCE = defaultInstance; + com.google.protobuf.GeneratedMessageLite.registerDefaultInstance( + BytesValue.class, defaultInstance); + } + + public static com.google.protobuf.BytesValue getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + public static com.google.protobuf.BytesValue of(com.google.protobuf.ByteString value) { + return newBuilder().setValue(value).build(); + } + + private static volatile com.google.protobuf.Parser PARSER; + + public static com.google.protobuf.Parser parser() { + return DEFAULT_INSTANCE.getParserForType(); + } +} + diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/BytesValueOrBuilder.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/BytesValueOrBuilder.java new file mode 100644 index 0000000000000..3adef62eda878 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/BytesValueOrBuilder.java @@ -0,0 +1,19 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/wrappers.proto + +package com.google.protobuf; + +public interface BytesValueOrBuilder extends + // @@protoc_insertion_point(interface_extends:google.protobuf.BytesValue) + com.google.protobuf.MessageLiteOrBuilder { + + /** + *
+   * The bytes value.
+   * 
+ * + * bytes value = 1; + * @return The value. + */ + com.google.protobuf.ByteString getValue(); +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/CodedInputStream.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/CodedInputStream.java new file mode 100644 index 0000000000000..00be6f004ae5f --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/CodedInputStream.java @@ -0,0 +1,3964 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +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.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; + +/** + * Reads and decodes protocol message fields. + * + *

This class contains two kinds of methods: methods that read specific protocol message + * constructs and field types (e.g. {@link #readTag()} and {@link #readInt32()}) and methods that + * read low-level values (e.g. {@link #readRawVarint32()} and {@link #readRawBytes}). If you are + * reading encoded protocol messages, you should use the former methods, but if you are reading some + * other format of your own design, use the latter. + * + * @author kenton@google.com Kenton Varda + */ +public abstract class CodedInputStream { + private static final int DEFAULT_BUFFER_SIZE = 4096; + private static final int DEFAULT_RECURSION_LIMIT = 100; + // Integer.MAX_VALUE == 0x7FFFFFF == INT_MAX from limits.h + private static final int DEFAULT_SIZE_LIMIT = Integer.MAX_VALUE; + + /** Visible for subclasses. See setRecursionLimit() */ + int recursionDepth; + + int recursionLimit = DEFAULT_RECURSION_LIMIT; + + /** Visible for subclasses. See setSizeLimit() */ + int sizeLimit = DEFAULT_SIZE_LIMIT; + + /** Used to adapt to the experimental {@link Reader} interface. */ + CodedInputStreamReader wrapper; + + /** Create a new CodedInputStream wrapping the given InputStream. */ + public static CodedInputStream newInstance(final InputStream input) { + return newInstance(input, DEFAULT_BUFFER_SIZE); + } + + /** Create a new CodedInputStream wrapping the given InputStream, with a specified buffer size. */ + public static CodedInputStream newInstance(final InputStream input, int bufferSize) { + if (bufferSize <= 0) { + throw new IllegalArgumentException("bufferSize must be > 0"); + } + if (input == null) { + // TODO(nathanmittler): Ideally we should throw here. This is done for backward compatibility. + return newInstance(EMPTY_BYTE_ARRAY); + } + return new StreamDecoder(input, bufferSize); + } + + /** Create a new CodedInputStream wrapping the given {@code Iterable }. */ + public static CodedInputStream newInstance(final Iterable input) { + if (!UnsafeDirectNioDecoder.isSupported()) { + return newInstance(new IterableByteBufferInputStream(input)); + } + return newInstance(input, false); + } + + /** Create a new CodedInputStream wrapping the given {@code Iterable }. */ + static CodedInputStream newInstance( + final Iterable bufs, final boolean bufferIsImmutable) { + // flag is to check the type of input's ByteBuffers. + // flag equals 1: all ByteBuffers have array. + // flag equals 2: all ByteBuffers are direct ByteBuffers. + // flag equals 3: some ByteBuffers are direct and some have array. + // flag greater than 3: other cases. + int flag = 0; + // Total size of the input + int totalSize = 0; + for (ByteBuffer buf : bufs) { + totalSize += buf.remaining(); + if (buf.hasArray()) { + flag |= 1; + } else if (buf.isDirect()) { + flag |= 2; + } else { + flag |= 4; + } + } + if (flag == 2) { + return new IterableDirectByteBufferDecoder(bufs, totalSize, bufferIsImmutable); + } else { + // TODO(yilunchong): add another decoders to deal case 1 and 3. + return newInstance(new IterableByteBufferInputStream(bufs)); + } + } + + /** Create a new CodedInputStream wrapping the given byte array. */ + public static CodedInputStream newInstance(final byte[] buf) { + return newInstance(buf, 0, buf.length); + } + + /** Create a new CodedInputStream wrapping the given byte array slice. */ + public static CodedInputStream newInstance(final byte[] buf, final int off, final int len) { + return newInstance(buf, off, len, /* bufferIsImmutable= */ false); + } + + /** 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); + 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); + } 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 + // wire, so it's important to catch exceptions in case of corrupt or + // malicious data. However, in this case, we expect that len is not a + // user-supplied value, so we can assume that it being negative indicates + // a programming error. Therefore, throwing an unchecked exception is + // appropriate. + throw new IllegalArgumentException(ex); + } + return result; + } + + /** + * Create a new CodedInputStream wrapping the given ByteBuffer. The data starting from the + * ByteBuffer's current position to its limit will be read. The returned CodedInputStream may or + * may not share the underlying data in the ByteBuffer, therefore the ByteBuffer cannot be changed + * while the CodedInputStream is in use. Note that the ByteBuffer's position won't be changed by + * this function. Concurrent calls with the same ByteBuffer object are safe if no other thread is + * trying to alter the ByteBuffer's status. + */ + public static CodedInputStream newInstance(ByteBuffer buf) { + return newInstance(buf, /* bufferIsImmutable= */ false); + } + + /** Create a new CodedInputStream wrapping the given buffer. */ + static CodedInputStream newInstance(ByteBuffer buf, boolean bufferIsImmutable) { + if (buf.hasArray()) { + return newInstance( + buf.array(), buf.arrayOffset() + buf.position(), buf.remaining(), bufferIsImmutable); + } + + 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 + // to access individual bytes is very slow, so just copy the buffer to an array. + // TODO(nathanmittler): Re-evaluate with Java 9 + byte[] buffer = new byte[buf.remaining()]; + buf.duplicate().get(buffer); + return newInstance(buffer, 0, buffer.length, true); + } + + /** Disable construction/inheritance outside of this class. */ + private CodedInputStream() {} + + // ----------------------------------------------------------------- + + /** + * Attempt to read a field tag, returning zero if we have reached EOF. Protocol message parsers + * use this to read tags, since a protocol message may legally end wherever a tag occurs, and zero + * is not a valid tag number. + */ + public abstract int readTag() throws IOException; + + /** + * Verifies that the last call to readTag() returned the given tag value. This is used to verify + * that a nested group ended with the correct end tag. + * + * @throws InvalidProtocolBufferException {@code value} does not match the last tag. + */ + public abstract void checkLastTagWas(final int value) throws InvalidProtocolBufferException; + + public abstract int getLastTag(); + + /** + * Reads and discards a single field, given its tag value. + * + * @return {@code false} if the tag is an endgroup tag, in which case nothing is skipped. + * Otherwise, returns {@code true}. + */ + public abstract boolean skipField(final int tag) throws IOException; + + /** + * Reads a single field and writes it to output in wire format, given its tag value. + * + * @return {@code false} if the tag is an endgroup tag, in which case nothing is skipped. + * Otherwise, returns {@code true}. + * @deprecated use {@code UnknownFieldSet} or {@code UnknownFieldSetLite} to skip to an output + * stream. + */ + @Deprecated + public abstract boolean skipField(final int tag, final CodedOutputStream output) + throws IOException; + + /** + * Reads and discards an entire message. This will read either until EOF or until an endgroup tag, + * whichever comes first. + */ + public abstract void skipMessage() throws IOException; + + /** + * Reads an entire message and writes it to output in wire format. This will read either until EOF + * or until an endgroup tag, whichever comes first. + */ + public abstract void skipMessage(CodedOutputStream output) throws IOException; + + + // ----------------------------------------------------------------- + + /** Read a {@code double} field value from the stream. */ + public abstract double readDouble() throws IOException; + + /** Read a {@code float} field value from the stream. */ + public abstract float readFloat() throws IOException; + + /** Read a {@code uint64} field value from the stream. */ + public abstract long readUInt64() throws IOException; + + /** Read an {@code int64} field value from the stream. */ + public abstract long readInt64() throws IOException; + + /** Read an {@code int32} field value from the stream. */ + public abstract int readInt32() throws IOException; + + /** Read a {@code fixed64} field value from the stream. */ + public abstract long readFixed64() throws IOException; + + /** Read a {@code fixed32} field value from the stream. */ + public abstract int readFixed32() throws IOException; + + /** Read a {@code bool} field value from the stream. */ + public abstract boolean readBool() throws IOException; + + /** + * Read a {@code string} field value from the stream. If the stream contains malformed UTF-8, + * replace the offending bytes with the standard UTF-8 replacement character. + */ + public abstract String readString() throws IOException; + + /** + * Read a {@code string} field value from the stream. If the stream contains malformed UTF-8, + * throw exception {@link InvalidProtocolBufferException}. + */ + public abstract String readStringRequireUtf8() throws IOException; + + /** Read a {@code group} field value from the stream. */ + public abstract void readGroup( + final int fieldNumber, + final MessageLite.Builder builder, + final ExtensionRegistryLite extensionRegistry) + throws IOException; + + + /** Read a {@code group} field value from the stream. */ + public abstract T readGroup( + final int fieldNumber, final Parser parser, final ExtensionRegistryLite extensionRegistry) + throws IOException; + + /** + * Reads a {@code group} field value from the stream and merges it into the given {@link + * UnknownFieldSet}. + * + * @deprecated UnknownFieldSet.Builder now implements MessageLite.Builder, so you can just call + * {@link #readGroup}. + */ + @Deprecated + public abstract void readUnknownGroup(final int fieldNumber, final MessageLite.Builder builder) + throws IOException; + + /** Read an embedded message field value from the stream. */ + public abstract void readMessage( + final MessageLite.Builder builder, final ExtensionRegistryLite extensionRegistry) + throws IOException; + + + /** Read an embedded message field value from the stream. */ + public abstract T readMessage( + final Parser parser, final ExtensionRegistryLite extensionRegistry) throws IOException; + + /** Read a {@code bytes} field value from the stream. */ + public abstract ByteString readBytes() throws IOException; + + /** Read a {@code bytes} field value from the stream. */ + public abstract byte[] readByteArray() throws IOException; + + /** Read a {@code bytes} field value from the stream. */ + public abstract ByteBuffer readByteBuffer() throws IOException; + + /** Read a {@code uint32} field value from the stream. */ + public abstract int readUInt32() throws IOException; + + /** + * Read an enum field value from the stream. Caller is responsible for converting the numeric + * value to an actual enum. + */ + public abstract int readEnum() throws IOException; + + /** Read an {@code sfixed32} field value from the stream. */ + public abstract int readSFixed32() throws IOException; + + /** Read an {@code sfixed64} field value from the stream. */ + public abstract long readSFixed64() throws IOException; + + /** Read an {@code sint32} field value from the stream. */ + public abstract int readSInt32() throws IOException; + + /** Read an {@code sint64} field value from the stream. */ + public abstract long readSInt64() throws IOException; + + // ================================================================= + + /** Read a raw Varint from the stream. If larger than 32 bits, discard the upper bits. */ + public abstract int readRawVarint32() throws IOException; + + /** Read a raw Varint from the stream. */ + public abstract long readRawVarint64() throws IOException; + + /** Variant of readRawVarint64 for when uncomfortably close to the limit. */ + /* Visible for testing */ + abstract long readRawVarint64SlowPath() throws IOException; + + /** Read a 32-bit little-endian integer from the stream. */ + public abstract int readRawLittleEndian32() throws IOException; + + /** Read a 64-bit little-endian integer from the stream. */ + public abstract long readRawLittleEndian64() throws IOException; + + // ----------------------------------------------------------------- + + /** + * Enables {@link ByteString} aliasing of the underlying buffer, trading off on buffer pinning for + * data copies. Only valid for buffer-backed streams. + */ + public abstract void enableAliasing(boolean enabled); + + /** + * Set the maximum message recursion depth. In order to prevent malicious messages from causing + * stack overflows, {@code CodedInputStream} limits how deeply messages may be nested. The default + * limit is 100. + * + * @return the old limit. + */ + public final int setRecursionLimit(final int limit) { + if (limit < 0) { + throw new IllegalArgumentException("Recursion limit cannot be negative: " + limit); + } + final int oldLimit = recursionLimit; + recursionLimit = limit; + return oldLimit; + } + + /** + * Only valid for {@link InputStream}-backed streams. + * + *

Set the maximum message size. In order to prevent malicious messages from exhausting memory + * or causing integer overflows, {@code CodedInputStream} limits how large a message may be. The + * default limit is {@code Integer.MAX_INT}. You should set this limit as small as you can without + * harming your app's functionality. Note that size limits only apply when reading from an {@code + * InputStream}, not when constructed around a raw byte array. + * + *

If you want to read several messages from a single CodedInputStream, you could call {@link + * #resetSizeCounter()} after each one to avoid hitting the size limit. + * + * @return the old limit. + */ + public final int setSizeLimit(final int limit) { + if (limit < 0) { + throw new IllegalArgumentException("Size limit cannot be negative: " + limit); + } + final int oldLimit = sizeLimit; + sizeLimit = limit; + return oldLimit; + } + + private boolean shouldDiscardUnknownFields = false; + + /** + * Sets this {@code CodedInputStream} to discard unknown fields. Only applies to full runtime + * messages; lite messages will always preserve unknowns. + * + *

Note calling this function alone will have NO immediate effect on the underlying input data. + * The unknown fields will be discarded during parsing. This affects both Proto2 and Proto3 full + * runtime. + */ + final void discardUnknownFields() { + shouldDiscardUnknownFields = true; + } + + /** + * Reverts the unknown fields preservation behavior for Proto2 and Proto3 full runtime to their + * default. + */ + final void unsetDiscardUnknownFields() { + shouldDiscardUnknownFields = false; + } + + /** + * Whether unknown fields in this input stream should be discarded during parsing into full + * runtime messages. + */ + final boolean shouldDiscardUnknownFields() { + return shouldDiscardUnknownFields; + } + + /** + * Resets the current size counter to zero (see {@link #setSizeLimit(int)}). Only valid for {@link + * InputStream}-backed streams. + */ + public abstract void resetSizeCounter(); + + /** + * Sets {@code currentLimit} to (current position) + {@code byteLimit}. This is called when + * descending into a length-delimited embedded message. + * + *

Note that {@code pushLimit()} does NOT affect how many bytes the {@code CodedInputStream} + * reads from an underlying {@code InputStream} when refreshing its buffer. If you need to prevent + * reading past a certain point in the underlying {@code InputStream} (e.g. because you expect it + * to contain more data after the end of the message which you need to handle differently) then + * you must place a wrapper around your {@code InputStream} which limits the amount of data that + * can be read from it. + * + * @return the old limit. + */ + public abstract int pushLimit(int byteLimit) throws InvalidProtocolBufferException; + + /** + * Discards the current limit, returning to the previous limit. + * + * @param oldLimit The old limit, as returned by {@code pushLimit}. + */ + public abstract void popLimit(final int oldLimit); + + /** + * Returns the number of bytes to be read before the current limit. If no limit is set, returns + * -1. + */ + public abstract int getBytesUntilLimit(); + + /** + * Returns true if the stream has reached the end of the input. This is the case if either the end + * of the underlying input source has been reached or if the stream has reached a limit created + * using {@link #pushLimit(int)}. This function may get blocked when using StreamDecoder as it + * invokes {@link StreamDecoder#tryRefillBuffer(int)} in this function which will try to read + * bytes from input. + */ + public abstract boolean isAtEnd() throws IOException; + + /** + * The total bytes read up to the current position. Calling {@link #resetSizeCounter()} resets + * this value to zero. + */ + public abstract int getTotalBytesRead(); + + /** + * Read one byte from the input. + * + * @throws InvalidProtocolBufferException The end of the stream or the current limit was reached. + */ + public abstract byte readRawByte() throws IOException; + + /** + * Read a fixed size of bytes from the input. + * + * @throws InvalidProtocolBufferException The end of the stream or the current limit was reached. + */ + public abstract byte[] readRawBytes(final int size) throws IOException; + + /** + * Reads and discards {@code size} bytes. + * + * @throws InvalidProtocolBufferException The end of the stream or the current limit was reached. + */ + public abstract void skipRawBytes(final int size) throws IOException; + + /** + * Decode a ZigZag-encoded 32-bit value. ZigZag encodes signed integers into values that can be + * efficiently encoded with varint. (Otherwise, negative values must be sign-extended to 64 bits + * to be varint encoded, thus always taking 10 bytes on the wire.) + * + * @param n An unsigned 32-bit integer, stored in a signed int because Java has no explicit + * unsigned support. + * @return A signed 32-bit integer. + */ + public static int decodeZigZag32(final int n) { + return (n >>> 1) ^ -(n & 1); + } + + /** + * Decode a ZigZag-encoded 64-bit value. ZigZag encodes signed integers into values that can be + * efficiently encoded with varint. (Otherwise, negative values must be sign-extended to 64 bits + * to be varint encoded, thus always taking 10 bytes on the wire.) + * + * @param n An unsigned 64-bit integer, stored in a signed int because Java has no explicit + * unsigned support. + * @return A signed 64-bit integer. + */ + public static long decodeZigZag64(final long n) { + return (n >>> 1) ^ -(n & 1); + } + + /** + * Like {@link #readRawVarint32(InputStream)}, but expects that the caller has already read one + * byte. This allows the caller to determine if EOF has been reached before attempting to read. + */ + public static int readRawVarint32(final int firstByte, final InputStream input) + throws IOException { + if ((firstByte & 0x80) == 0) { + return firstByte; + } + + int result = firstByte & 0x7f; + int offset = 7; + for (; offset < 32; offset += 7) { + final int b = input.read(); + if (b == -1) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + result |= (b & 0x7f) << offset; + if ((b & 0x80) == 0) { + return result; + } + } + // Keep reading up to 64 bits. + for (; offset < 64; offset += 7) { + final int b = input.read(); + if (b == -1) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + if ((b & 0x80) == 0) { + return result; + } + } + throw InvalidProtocolBufferException.malformedVarint(); + } + + /** + * Reads a varint from the input one byte at a time, so that it does not read any bytes after the + * end of the varint. If you simply wrapped the stream in a CodedInputStream and used {@link + * #readRawVarint32(InputStream)} then you would probably end up reading past the end of the + * varint since CodedInputStream buffers its input. + */ + static int readRawVarint32(final InputStream input) throws IOException { + final int firstByte = input.read(); + if (firstByte == -1) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + 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.writeRawVarint32(tag); + output.writeUInt64NoTag(value); + return true; + } + case WireFormat.WIRETYPE_FIXED64: + { + long value = readRawLittleEndian64(); + output.writeRawVarint32(tag); + output.writeFixed64NoTag(value); + return true; + } + case WireFormat.WIRETYPE_LENGTH_DELIMITED: + { + ByteString value = readBytes(); + output.writeRawVarint32(tag); + output.writeBytesNoTag(value); + return true; + } + case WireFormat.WIRETYPE_START_GROUP: + { + output.writeRawVarint32(tag); + skipMessage(output); + int endtag = + WireFormat.makeTag( + WireFormat.getTagFieldNumber(tag), WireFormat.WIRETYPE_END_GROUP); + checkLastTagWas(endtag); + output.writeRawVarint32(endtag); + return true; + } + case WireFormat.WIRETYPE_END_GROUP: + { + return false; + } + case WireFormat.WIRETYPE_FIXED32: + { + int value = readRawLittleEndian32(); + output.writeRawVarint32(tag); + output.writeFixed32NoTag(value); + return true; + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + + @Override + public void skipMessage() throws IOException { + while (true) { + final int tag = readTag(); + if (tag == 0 || !skipField(tag)) { + return; + } + } + } + + @Override + public void skipMessage(CodedOutputStream output) throws IOException { + while (true) { + final int tag = readTag(); + if (tag == 0 || !skipField(tag, output)) { + return; + } + } + } + + + // ----------------------------------------------------------------- + + @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 { + if (recursionDepth >= recursionLimit) { + throw InvalidProtocolBufferException.recursionLimitExceeded(); + } + ++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 { + if (recursionDepth >= recursionLimit) { + throw InvalidProtocolBufferException.recursionLimitExceeded(); + } + ++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(); + if (recursionDepth >= recursionLimit) { + throw InvalidProtocolBufferException.recursionLimitExceeded(); + } + final int oldLimit = pushLimit(length); + ++recursionDepth; + builder.mergeFrom(this, extensionRegistry); + checkLastTagWas(0); + --recursionDepth; + popLimit(oldLimit); + } + + + @Override + public T readMessage( + final Parser parser, final ExtensionRegistryLite extensionRegistry) throws IOException { + int length = readRawVarint32(); + if (recursionDepth >= recursionLimit) { + throw InvalidProtocolBufferException.recursionLimitExceeded(); + } + final int oldLimit = pushLimit(length); + ++recursionDepth; + T result = parser.parsePartialFrom(this, extensionRegistry); + checkLastTagWas(0); + --recursionDepth; + 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(nathanmittler): 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(); + 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.writeRawVarint32(tag); + output.writeUInt64NoTag(value); + return true; + } + case WireFormat.WIRETYPE_FIXED64: + { + long value = readRawLittleEndian64(); + output.writeRawVarint32(tag); + output.writeFixed64NoTag(value); + return true; + } + case WireFormat.WIRETYPE_LENGTH_DELIMITED: + { + ByteString value = readBytes(); + output.writeRawVarint32(tag); + output.writeBytesNoTag(value); + return true; + } + case WireFormat.WIRETYPE_START_GROUP: + { + output.writeRawVarint32(tag); + skipMessage(output); + int endtag = + WireFormat.makeTag( + WireFormat.getTagFieldNumber(tag), WireFormat.WIRETYPE_END_GROUP); + checkLastTagWas(endtag); + output.writeRawVarint32(endtag); + return true; + } + case WireFormat.WIRETYPE_END_GROUP: + { + return false; + } + case WireFormat.WIRETYPE_FIXED32: + { + int value = readRawLittleEndian32(); + output.writeRawVarint32(tag); + output.writeFixed32NoTag(value); + return true; + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + + @Override + public void skipMessage() throws IOException { + while (true) { + final int tag = readTag(); + if (tag == 0 || !skipField(tag)) { + return; + } + } + } + + @Override + public void skipMessage(CodedOutputStream output) throws IOException { + while (true) { + final int tag = readTag(); + if (tag == 0 || !skipField(tag, output)) { + return; + } + } + } + + + // ----------------------------------------------------------------- + + @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(nathanmittler): Is there a way to avoid this copy? + // TODO(anuraaga): 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 { + if (recursionDepth >= recursionLimit) { + throw InvalidProtocolBufferException.recursionLimitExceeded(); + } + ++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 { + if (recursionDepth >= recursionLimit) { + throw InvalidProtocolBufferException.recursionLimitExceeded(); + } + ++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(); + if (recursionDepth >= recursionLimit) { + throw InvalidProtocolBufferException.recursionLimitExceeded(); + } + final int oldLimit = pushLimit(length); + ++recursionDepth; + builder.mergeFrom(this, extensionRegistry); + checkLastTagWas(0); + --recursionDepth; + popLimit(oldLimit); + } + + + @Override + public T readMessage( + final Parser parser, final ExtensionRegistryLite extensionRegistry) throws IOException { + int length = readRawVarint32(); + if (recursionDepth >= recursionLimit) { + throw InvalidProtocolBufferException.recursionLimitExceeded(); + } + final int oldLimit = pushLimit(length); + ++recursionDepth; + T result = parser.parsePartialFrom(this, extensionRegistry); + checkLastTagWas(0); + --recursionDepth; + 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(nathanmittler): 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(); + try { + ((Buffer) buffer).position(bufferPos(begin)); + ((Buffer) buffer).limit(bufferPos(end)); + return buffer.slice(); + } catch (IllegalArgumentException e) { + throw InvalidProtocolBufferException.truncatedMessage(); + } finally { + ((Buffer) buffer).position(prevPos); + ((Buffer) buffer).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.writeRawVarint32(tag); + output.writeUInt64NoTag(value); + return true; + } + case WireFormat.WIRETYPE_FIXED64: + { + long value = readRawLittleEndian64(); + output.writeRawVarint32(tag); + output.writeFixed64NoTag(value); + return true; + } + case WireFormat.WIRETYPE_LENGTH_DELIMITED: + { + ByteString value = readBytes(); + output.writeRawVarint32(tag); + output.writeBytesNoTag(value); + return true; + } + case WireFormat.WIRETYPE_START_GROUP: + { + output.writeRawVarint32(tag); + skipMessage(output); + int endtag = + WireFormat.makeTag( + WireFormat.getTagFieldNumber(tag), WireFormat.WIRETYPE_END_GROUP); + checkLastTagWas(endtag); + output.writeRawVarint32(endtag); + return true; + } + case WireFormat.WIRETYPE_END_GROUP: + { + return false; + } + case WireFormat.WIRETYPE_FIXED32: + { + int value = readRawLittleEndian32(); + output.writeRawVarint32(tag); + output.writeFixed32NoTag(value); + return true; + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + + @Override + public void skipMessage() throws IOException { + while (true) { + final int tag = readTag(); + if (tag == 0 || !skipField(tag)) { + return; + } + } + } + + @Override + public void skipMessage(CodedOutputStream output) throws IOException { + while (true) { + final int tag = readTag(); + if (tag == 0 || !skipField(tag, output)) { + return; + } + } + } + + /** 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 <= 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 <= 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 { + if (recursionDepth >= recursionLimit) { + throw InvalidProtocolBufferException.recursionLimitExceeded(); + } + ++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 { + if (recursionDepth >= recursionLimit) { + throw InvalidProtocolBufferException.recursionLimitExceeded(); + } + ++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(); + if (recursionDepth >= recursionLimit) { + throw InvalidProtocolBufferException.recursionLimitExceeded(); + } + final int oldLimit = pushLimit(length); + ++recursionDepth; + builder.mergeFrom(this, extensionRegistry); + checkLastTagWas(0); + --recursionDepth; + popLimit(oldLimit); + } + + + @Override + public T readMessage( + final Parser parser, final ExtensionRegistryLite extensionRegistry) throws IOException { + int length = readRawVarint32(); + if (recursionDepth >= recursionLimit) { + throw InvalidProtocolBufferException.recursionLimitExceeded(); + } + final int oldLimit = pushLimit(length); + ++recursionDepth; + T result = parser.parsePartialFrom(this, extensionRegistry); + checkLastTagWas(0); + --recursionDepth; + 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; + } + 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 { + // Slow path: Build a byte array first then copy it. + // TODO(dweis): 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; + } + // 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(nathanmittler): 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(dweis): 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(nathanmittler): 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(nathanmittler): 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 Iterable input; + /** The {@link Iterator} with type {@link ByteBuffer} of {@code input} */ + private Iterator iterator; + /** The current ByteBuffer; */ + private ByteBuffer currentByteBuffer; + /** + * If {@code true}, indicates that all the buffer are backing a {@link ByteString} and are + * therefore considered to be an immutable input source. + */ + private 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.writeRawVarint32(tag); + output.writeUInt64NoTag(value); + return true; + } + case WireFormat.WIRETYPE_FIXED64: + { + long value = readRawLittleEndian64(); + output.writeRawVarint32(tag); + output.writeFixed64NoTag(value); + return true; + } + case WireFormat.WIRETYPE_LENGTH_DELIMITED: + { + ByteString value = readBytes(); + output.writeRawVarint32(tag); + output.writeBytesNoTag(value); + return true; + } + case WireFormat.WIRETYPE_START_GROUP: + { + output.writeRawVarint32(tag); + skipMessage(output); + int endtag = + WireFormat.makeTag( + WireFormat.getTagFieldNumber(tag), WireFormat.WIRETYPE_END_GROUP); + checkLastTagWas(endtag); + output.writeRawVarint32(endtag); + return true; + } + case WireFormat.WIRETYPE_END_GROUP: + { + return false; + } + case WireFormat.WIRETYPE_FIXED32: + { + int value = readRawLittleEndian32(); + output.writeRawVarint32(tag); + output.writeFixed32NoTag(value); + return true; + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + + @Override + public void skipMessage() throws IOException { + while (true) { + final int tag = readTag(); + if (tag == 0 || !skipField(tag)) { + return; + } + } + } + + @Override + public void skipMessage(CodedOutputStream output) throws IOException { + while (true) { + final int tag = readTag(); + if (tag == 0 || !skipField(tag, output)) { + return; + } + } + } + + // ----------------------------------------------------------------- + + @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(yilunchong): 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 { + if (recursionDepth >= recursionLimit) { + throw InvalidProtocolBufferException.recursionLimitExceeded(); + } + ++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 { + if (recursionDepth >= recursionLimit) { + throw InvalidProtocolBufferException.recursionLimitExceeded(); + } + ++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(); + if (recursionDepth >= recursionLimit) { + throw InvalidProtocolBufferException.recursionLimitExceeded(); + } + final int oldLimit = pushLimit(length); + ++recursionDepth; + builder.mergeFrom(this, extensionRegistry); + checkLastTagWas(0); + --recursionDepth; + popLimit(oldLimit); + } + + + @Override + public T readMessage( + final Parser parser, final ExtensionRegistryLite extensionRegistry) throws IOException { + int length = readRawVarint32(); + if (recursionDepth >= recursionLimit) { + throw InvalidProtocolBufferException.recursionLimitExceeded(); + } + final int oldLimit = pushLimit(length); + ++recursionDepth; + T result = parser.parsePartialFrom(this, extensionRegistry); + checkLastTagWas(0); + --recursionDepth; + 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; + bytes = new byte[size]; + UnsafeUtil.copyMemory(currentByteBufferPos, bytes, 0, size); + currentByteBufferPos += size; + return ByteString.wrap(bytes); + } + } else if (size > 0 && size <= remaining()) { + 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. + * + * @param bytes + * @param offset + * @param length + * @throws IOException + */ + 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(); + try { + ((Buffer) currentByteBuffer).position(begin); + ((Buffer) currentByteBuffer).limit(end); + return currentByteBuffer.slice(); + } catch (IllegalArgumentException e) { + throw InvalidProtocolBufferException.truncatedMessage(); + } finally { + ((Buffer) currentByteBuffer).position(prevPos); + ((Buffer) currentByteBuffer).limit(prevLimit); + } + } + } +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/CodedInputStreamReader.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/CodedInputStreamReader.java new file mode 100644 index 0000000000000..7658f629d3717 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/CodedInputStreamReader.java @@ -0,0 +1,1333 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +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.WIRETYPE_END_GROUP; +import static com.google.protobuf.WireFormat.WIRETYPE_FIXED32; +import static com.google.protobuf.WireFormat.WIRETYPE_FIXED64; +import static com.google.protobuf.WireFormat.WIRETYPE_LENGTH_DELIMITED; +import static com.google.protobuf.WireFormat.WIRETYPE_START_GROUP; +import static com.google.protobuf.WireFormat.WIRETYPE_VARINT; + +import java.io.IOException; +import java.util.List; +import java.util.Map; + +/** An adapter between the {@link Reader} interface and {@link CodedInputStream}. */ +@ExperimentalApi +final class CodedInputStreamReader implements Reader { + private static final int FIXED32_MULTIPLE_MASK = FIXED32_SIZE - 1; + private static final int FIXED64_MULTIPLE_MASK = FIXED64_SIZE - 1; + private static final int NEXT_TAG_UNSET = 0; + + private final CodedInputStream input; + private int tag; + private int endGroupTag; + private int nextTag = NEXT_TAG_UNSET; + + public static CodedInputStreamReader forCodedInput(CodedInputStream input) { + if (input.wrapper != null) { + return input.wrapper; + } + return new CodedInputStreamReader(input); + } + + private CodedInputStreamReader(CodedInputStream input) { + this.input = Internal.checkNotNull(input, "input"); + this.input.wrapper = this; + } + + @Override + public boolean shouldDiscardUnknownFields() { + return input.shouldDiscardUnknownFields(); + } + + @Override + public int getFieldNumber() throws IOException { + if (nextTag != NEXT_TAG_UNSET) { + tag = nextTag; + nextTag = NEXT_TAG_UNSET; + } else { + tag = input.readTag(); + } + if (tag == 0 || tag == endGroupTag) { + return Reader.READ_DONE; + } + return WireFormat.getTagFieldNumber(tag); + } + + @Override + public int getTag() { + return tag; + } + + @Override + public boolean skipField() throws IOException { + if (input.isAtEnd() || tag == endGroupTag) { + return false; + } + return input.skipField(tag); + } + + private void requireWireType(int requiredWireType) throws IOException { + if (WireFormat.getTagWireType(tag) != requiredWireType) { + throw InvalidProtocolBufferException.invalidWireType(); + } + } + + @Override + public double readDouble() throws IOException { + requireWireType(WIRETYPE_FIXED64); + return input.readDouble(); + } + + @Override + public float readFloat() throws IOException { + requireWireType(WIRETYPE_FIXED32); + return input.readFloat(); + } + + @Override + public long readUInt64() throws IOException { + requireWireType(WIRETYPE_VARINT); + return input.readUInt64(); + } + + @Override + public long readInt64() throws IOException { + requireWireType(WIRETYPE_VARINT); + return input.readInt64(); + } + + @Override + public int readInt32() throws IOException { + requireWireType(WIRETYPE_VARINT); + return input.readInt32(); + } + + @Override + public long readFixed64() throws IOException { + requireWireType(WIRETYPE_FIXED64); + return input.readFixed64(); + } + + @Override + public int readFixed32() throws IOException { + requireWireType(WIRETYPE_FIXED32); + return input.readFixed32(); + } + + @Override + public boolean readBool() throws IOException { + requireWireType(WIRETYPE_VARINT); + return input.readBool(); + } + + @Override + public String readString() throws IOException { + requireWireType(WIRETYPE_LENGTH_DELIMITED); + return input.readString(); + } + + @Override + public String readStringRequireUtf8() throws IOException { + requireWireType(WIRETYPE_LENGTH_DELIMITED); + return input.readStringRequireUtf8(); + } + + @SuppressWarnings("unchecked") + @Override + public T readMessage(Class clazz, ExtensionRegistryLite extensionRegistry) + throws IOException { + requireWireType(WIRETYPE_LENGTH_DELIMITED); + return readMessage(Protobuf.getInstance().schemaFor(clazz), extensionRegistry); + } + + @SuppressWarnings("unchecked") + @Override + public T readMessageBySchemaWithCheck( + Schema schema, ExtensionRegistryLite extensionRegistry) throws IOException { + requireWireType(WIRETYPE_LENGTH_DELIMITED); + return readMessage(schema, extensionRegistry); + } + + @SuppressWarnings("unchecked") + @Override + public T readGroup(Class clazz, ExtensionRegistryLite extensionRegistry) + throws IOException { + requireWireType(WIRETYPE_START_GROUP); + return readGroup(Protobuf.getInstance().schemaFor(clazz), extensionRegistry); + } + + @SuppressWarnings("unchecked") + @Override + public T readGroupBySchemaWithCheck(Schema schema, ExtensionRegistryLite extensionRegistry) + throws IOException { + requireWireType(WIRETYPE_START_GROUP); + return readGroup(schema, extensionRegistry); + } + + // Should have the same semantics of CodedInputStream#readMessage() + private T readMessage(Schema schema, ExtensionRegistryLite extensionRegistry) + throws IOException { + int size = input.readUInt32(); + if (input.recursionDepth >= input.recursionLimit) { + throw InvalidProtocolBufferException.recursionLimitExceeded(); + } + + // Push the new limit. + final int prevLimit = input.pushLimit(size); + // Allocate and read the message. + T message = schema.newInstance(); + ++input.recursionDepth; + schema.mergeFrom(message, this, extensionRegistry); + schema.makeImmutable(message); + input.checkLastTagWas(0); + --input.recursionDepth; + // Restore the previous limit. + input.popLimit(prevLimit); + return message; + } + + private T readGroup(Schema schema, ExtensionRegistryLite extensionRegistry) + throws IOException { + int prevEndGroupTag = endGroupTag; + endGroupTag = WireFormat.makeTag(WireFormat.getTagFieldNumber(tag), WIRETYPE_END_GROUP); + + try { + // Allocate and read the message. + T message = schema.newInstance(); + schema.mergeFrom(message, this, extensionRegistry); + schema.makeImmutable(message); + + if (tag != endGroupTag) { + throw InvalidProtocolBufferException.parseFailure(); + } + return message; + } finally { + // Restore the old end group tag. + endGroupTag = prevEndGroupTag; + } + } + + @Override + public ByteString readBytes() throws IOException { + requireWireType(WIRETYPE_LENGTH_DELIMITED); + return input.readBytes(); + } + + @Override + public int readUInt32() throws IOException { + requireWireType(WIRETYPE_VARINT); + return input.readUInt32(); + } + + @Override + public int readEnum() throws IOException { + requireWireType(WIRETYPE_VARINT); + return input.readEnum(); + } + + @Override + public int readSFixed32() throws IOException { + requireWireType(WIRETYPE_FIXED32); + return input.readSFixed32(); + } + + @Override + public long readSFixed64() throws IOException { + requireWireType(WIRETYPE_FIXED64); + return input.readSFixed64(); + } + + @Override + public int readSInt32() throws IOException { + requireWireType(WIRETYPE_VARINT); + return input.readSInt32(); + } + + @Override + public long readSInt64() throws IOException { + requireWireType(WIRETYPE_VARINT); + return input.readSInt64(); + } + + @Override + public void readDoubleList(List target) throws IOException { + if (target instanceof DoubleArrayList) { + DoubleArrayList plist = (DoubleArrayList) target; + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = input.readUInt32(); + verifyPackedFixed64Length(bytes); + int endPos = input.getTotalBytesRead() + bytes; + do { + plist.addDouble(input.readDouble()); + } while (input.getTotalBytesRead() < endPos); + break; + case WIRETYPE_FIXED64: + while (true) { + plist.addDouble(input.readDouble()); + if (input.isAtEnd()) { + return; + } + int nextTag = input.readTag(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Save the next tag value. + this.nextTag = nextTag; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } else { + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = input.readUInt32(); + verifyPackedFixed64Length(bytes); + int endPos = input.getTotalBytesRead() + bytes; + do { + target.add(input.readDouble()); + } while (input.getTotalBytesRead() < endPos); + break; + case WIRETYPE_FIXED64: + while (true) { + target.add(input.readDouble()); + if (input.isAtEnd()) { + return; + } + int nextTag = input.readTag(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Save the next tag value. + this.nextTag = nextTag; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + } + + @Override + public void readFloatList(List target) throws IOException { + if (target instanceof FloatArrayList) { + FloatArrayList plist = (FloatArrayList) target; + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = input.readUInt32(); + verifyPackedFixed32Length(bytes); + int endPos = input.getTotalBytesRead() + bytes; + do { + plist.addFloat(input.readFloat()); + } while (input.getTotalBytesRead() < endPos); + break; + case WIRETYPE_FIXED32: + while (true) { + plist.addFloat(input.readFloat()); + if (input.isAtEnd()) { + return; + } + int nextTag = input.readTag(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Save the next tag value. + this.nextTag = nextTag; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } else { + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = input.readUInt32(); + verifyPackedFixed32Length(bytes); + int endPos = input.getTotalBytesRead() + bytes; + do { + target.add(input.readFloat()); + } while (input.getTotalBytesRead() < endPos); + break; + case WIRETYPE_FIXED32: + while (true) { + target.add(input.readFloat()); + if (input.isAtEnd()) { + return; + } + int nextTag = input.readTag(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Save the next tag value. + this.nextTag = nextTag; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + } + + @Override + public void readUInt64List(List target) throws IOException { + if (target instanceof LongArrayList) { + LongArrayList plist = (LongArrayList) target; + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = input.readUInt32(); + int endPos = input.getTotalBytesRead() + bytes; + do { + plist.addLong(input.readUInt64()); + } while (input.getTotalBytesRead() < endPos); + requirePosition(endPos); + break; + case WIRETYPE_VARINT: + while (true) { + plist.addLong(input.readUInt64()); + if (input.isAtEnd()) { + return; + } + int nextTag = input.readTag(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Save the next tag value. + this.nextTag = nextTag; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } else { + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = input.readUInt32(); + int endPos = input.getTotalBytesRead() + bytes; + do { + target.add(input.readUInt64()); + } while (input.getTotalBytesRead() < endPos); + requirePosition(endPos); + break; + case WIRETYPE_VARINT: + while (true) { + target.add(input.readUInt64()); + if (input.isAtEnd()) { + return; + } + int nextTag = input.readTag(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Save the next tag value. + this.nextTag = nextTag; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + } + + @Override + public void readInt64List(List target) throws IOException { + if (target instanceof LongArrayList) { + LongArrayList plist = (LongArrayList) target; + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = input.readUInt32(); + int endPos = input.getTotalBytesRead() + bytes; + do { + plist.addLong(input.readInt64()); + } while (input.getTotalBytesRead() < endPos); + requirePosition(endPos); + break; + case WIRETYPE_VARINT: + while (true) { + plist.addLong(input.readInt64()); + if (input.isAtEnd()) { + return; + } + int nextTag = input.readTag(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Save the next tag value. + this.nextTag = nextTag; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } else { + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = input.readUInt32(); + int endPos = input.getTotalBytesRead() + bytes; + do { + target.add(input.readInt64()); + } while (input.getTotalBytesRead() < endPos); + requirePosition(endPos); + break; + case WIRETYPE_VARINT: + while (true) { + target.add(input.readInt64()); + if (input.isAtEnd()) { + return; + } + int nextTag = input.readTag(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Save the next tag value. + this.nextTag = nextTag; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + } + + @Override + public void readInt32List(List target) throws IOException { + if (target instanceof IntArrayList) { + IntArrayList plist = (IntArrayList) target; + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = input.readUInt32(); + int endPos = input.getTotalBytesRead() + bytes; + do { + plist.addInt(input.readInt32()); + } while (input.getTotalBytesRead() < endPos); + requirePosition(endPos); + break; + case WIRETYPE_VARINT: + while (true) { + plist.addInt(input.readInt32()); + if (input.isAtEnd()) { + return; + } + int nextTag = input.readTag(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Save the next tag value. + this.nextTag = nextTag; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } else { + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = input.readUInt32(); + int endPos = input.getTotalBytesRead() + bytes; + do { + target.add(input.readInt32()); + } while (input.getTotalBytesRead() < endPos); + requirePosition(endPos); + break; + case WIRETYPE_VARINT: + while (true) { + target.add(input.readInt32()); + if (input.isAtEnd()) { + return; + } + int nextTag = input.readTag(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Save the next tag value. + this.nextTag = nextTag; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + } + + @Override + public void readFixed64List(List target) throws IOException { + if (target instanceof LongArrayList) { + LongArrayList plist = (LongArrayList) target; + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = input.readUInt32(); + verifyPackedFixed64Length(bytes); + int endPos = input.getTotalBytesRead() + bytes; + do { + plist.addLong(input.readFixed64()); + } while (input.getTotalBytesRead() < endPos); + break; + case WIRETYPE_FIXED64: + while (true) { + plist.addLong(input.readFixed64()); + if (input.isAtEnd()) { + return; + } + int nextTag = input.readTag(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Save the next tag value. + this.nextTag = nextTag; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } else { + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = input.readUInt32(); + verifyPackedFixed64Length(bytes); + int endPos = input.getTotalBytesRead() + bytes; + do { + target.add(input.readFixed64()); + } while (input.getTotalBytesRead() < endPos); + break; + case WIRETYPE_FIXED64: + while (true) { + target.add(input.readFixed64()); + if (input.isAtEnd()) { + return; + } + int nextTag = input.readTag(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Save the next tag value. + this.nextTag = nextTag; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + } + + @Override + public void readFixed32List(List target) throws IOException { + if (target instanceof IntArrayList) { + IntArrayList plist = (IntArrayList) target; + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = input.readUInt32(); + verifyPackedFixed32Length(bytes); + int endPos = input.getTotalBytesRead() + bytes; + do { + plist.addInt(input.readFixed32()); + } while (input.getTotalBytesRead() < endPos); + break; + case WIRETYPE_FIXED32: + while (true) { + plist.addInt(input.readFixed32()); + if (input.isAtEnd()) { + return; + } + int nextTag = input.readTag(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Save the next tag value. + this.nextTag = nextTag; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } else { + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = input.readUInt32(); + verifyPackedFixed32Length(bytes); + int endPos = input.getTotalBytesRead() + bytes; + do { + target.add(input.readFixed32()); + } while (input.getTotalBytesRead() < endPos); + break; + case WIRETYPE_FIXED32: + while (true) { + target.add(input.readFixed32()); + if (input.isAtEnd()) { + return; + } + int nextTag = input.readTag(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Save the next tag value. + this.nextTag = nextTag; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + } + + @Override + public void readBoolList(List target) throws IOException { + if (target instanceof BooleanArrayList) { + BooleanArrayList plist = (BooleanArrayList) target; + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = input.readUInt32(); + int endPos = input.getTotalBytesRead() + bytes; + do { + plist.addBoolean(input.readBool()); + } while (input.getTotalBytesRead() < endPos); + requirePosition(endPos); + break; + case WIRETYPE_VARINT: + while (true) { + plist.addBoolean(input.readBool()); + if (input.isAtEnd()) { + return; + } + int nextTag = input.readTag(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Save the next tag value. + this.nextTag = nextTag; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } else { + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = input.readUInt32(); + int endPos = input.getTotalBytesRead() + bytes; + do { + target.add(input.readBool()); + } while (input.getTotalBytesRead() < endPos); + requirePosition(endPos); + break; + case WIRETYPE_VARINT: + while (true) { + target.add(input.readBool()); + if (input.isAtEnd()) { + return; + } + int nextTag = input.readTag(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Save the next tag value. + this.nextTag = nextTag; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + } + + @Override + public void readStringList(List target) throws IOException { + readStringListInternal(target, false); + } + + @Override + public void readStringListRequireUtf8(List target) throws IOException { + readStringListInternal(target, true); + } + + public void readStringListInternal(List target, boolean requireUtf8) throws IOException { + if (WireFormat.getTagWireType(tag) != WIRETYPE_LENGTH_DELIMITED) { + throw InvalidProtocolBufferException.invalidWireType(); + } + + if (target instanceof LazyStringList && !requireUtf8) { + LazyStringList lazyList = (LazyStringList) target; + while (true) { + lazyList.add(readBytes()); + if (input.isAtEnd()) { + return; + } + int nextTag = input.readTag(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Save the next tag value. + this.nextTag = nextTag; + return; + } + } + } else { + while (true) { + target.add(requireUtf8 ? readStringRequireUtf8() : readString()); + if (input.isAtEnd()) { + return; + } + int nextTag = input.readTag(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Save the next tag value. + this.nextTag = nextTag; + return; + } + } + } + } + + @Override + public void readMessageList( + List target, Class targetType, ExtensionRegistryLite extensionRegistry) + throws IOException { + final Schema schema = Protobuf.getInstance().schemaFor(targetType); + readMessageList(target, schema, extensionRegistry); + } + + @Override + public void readMessageList( + List target, Schema schema, ExtensionRegistryLite extensionRegistry) + throws IOException { + if (WireFormat.getTagWireType(tag) != WIRETYPE_LENGTH_DELIMITED) { + throw InvalidProtocolBufferException.invalidWireType(); + } + final int listTag = tag; + while (true) { + target.add(readMessage(schema, extensionRegistry)); + if (input.isAtEnd() || nextTag != NEXT_TAG_UNSET) { + return; + } + int nextTag = input.readTag(); + if (nextTag != listTag) { + // We've reached the end of the repeated field. Save the next tag value. + this.nextTag = nextTag; + return; + } + } + } + + @Override + public void readGroupList( + List target, Class targetType, ExtensionRegistryLite extensionRegistry) + throws IOException { + final Schema schema = Protobuf.getInstance().schemaFor(targetType); + readGroupList(target, schema, extensionRegistry); + } + + @Override + public void readGroupList( + List target, Schema schema, ExtensionRegistryLite extensionRegistry) + throws IOException { + if (WireFormat.getTagWireType(tag) != WIRETYPE_START_GROUP) { + throw InvalidProtocolBufferException.invalidWireType(); + } + final int listTag = tag; + while (true) { + target.add(readGroup(schema, extensionRegistry)); + if (input.isAtEnd() || nextTag != NEXT_TAG_UNSET) { + return; + } + int nextTag = input.readTag(); + if (nextTag != listTag) { + // We've reached the end of the repeated field. Save the next tag value. + this.nextTag = nextTag; + return; + } + } + } + + @Override + public void readBytesList(List target) throws IOException { + if (WireFormat.getTagWireType(tag) != WIRETYPE_LENGTH_DELIMITED) { + throw InvalidProtocolBufferException.invalidWireType(); + } + + while (true) { + target.add(readBytes()); + if (input.isAtEnd()) { + return; + } + int nextTag = input.readTag(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Save the next tag value. + this.nextTag = nextTag; + return; + } + } + } + + @Override + public void readUInt32List(List target) throws IOException { + if (target instanceof IntArrayList) { + IntArrayList plist = (IntArrayList) target; + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = input.readUInt32(); + int endPos = input.getTotalBytesRead() + bytes; + do { + plist.addInt(input.readUInt32()); + } while (input.getTotalBytesRead() < endPos); + requirePosition(endPos); + break; + case WIRETYPE_VARINT: + while (true) { + plist.addInt(input.readUInt32()); + if (input.isAtEnd()) { + return; + } + int nextTag = input.readTag(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Save the next tag value. + this.nextTag = nextTag; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } else { + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = input.readUInt32(); + int endPos = input.getTotalBytesRead() + bytes; + do { + target.add(input.readUInt32()); + } while (input.getTotalBytesRead() < endPos); + requirePosition(endPos); + break; + case WIRETYPE_VARINT: + while (true) { + target.add(input.readUInt32()); + if (input.isAtEnd()) { + return; + } + int nextTag = input.readTag(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Save the next tag value. + this.nextTag = nextTag; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + } + + @Override + public void readEnumList(List target) throws IOException { + if (target instanceof IntArrayList) { + IntArrayList plist = (IntArrayList) target; + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = input.readUInt32(); + int endPos = input.getTotalBytesRead() + bytes; + do { + plist.addInt(input.readEnum()); + } while (input.getTotalBytesRead() < endPos); + requirePosition(endPos); + break; + case WIRETYPE_VARINT: + while (true) { + plist.addInt(input.readEnum()); + if (input.isAtEnd()) { + return; + } + int nextTag = input.readTag(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Save the next tag value. + this.nextTag = nextTag; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } else { + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = input.readUInt32(); + int endPos = input.getTotalBytesRead() + bytes; + do { + target.add(input.readEnum()); + } while (input.getTotalBytesRead() < endPos); + requirePosition(endPos); + break; + case WIRETYPE_VARINT: + while (true) { + target.add(input.readEnum()); + if (input.isAtEnd()) { + return; + } + int nextTag = input.readTag(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Save the next tag value. + this.nextTag = nextTag; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + } + + @Override + public void readSFixed32List(List target) throws IOException { + if (target instanceof IntArrayList) { + IntArrayList plist = (IntArrayList) target; + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = input.readUInt32(); + verifyPackedFixed32Length(bytes); + int endPos = input.getTotalBytesRead() + bytes; + do { + plist.addInt(input.readSFixed32()); + } while (input.getTotalBytesRead() < endPos); + break; + case WIRETYPE_FIXED32: + while (true) { + plist.addInt(input.readSFixed32()); + if (input.isAtEnd()) { + return; + } + int nextTag = input.readTag(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Save the next tag value. + this.nextTag = nextTag; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } else { + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = input.readUInt32(); + verifyPackedFixed32Length(bytes); + int endPos = input.getTotalBytesRead() + bytes; + do { + target.add(input.readSFixed32()); + } while (input.getTotalBytesRead() < endPos); + break; + case WIRETYPE_FIXED32: + while (true) { + target.add(input.readSFixed32()); + if (input.isAtEnd()) { + return; + } + int nextTag = input.readTag(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Save the next tag value. + this.nextTag = nextTag; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + } + + @Override + public void readSFixed64List(List target) throws IOException { + if (target instanceof LongArrayList) { + LongArrayList plist = (LongArrayList) target; + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = input.readUInt32(); + verifyPackedFixed64Length(bytes); + int endPos = input.getTotalBytesRead() + bytes; + do { + plist.addLong(input.readSFixed64()); + } while (input.getTotalBytesRead() < endPos); + break; + case WIRETYPE_FIXED64: + while (true) { + plist.addLong(input.readSFixed64()); + if (input.isAtEnd()) { + return; + } + int nextTag = input.readTag(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Save the next tag value. + this.nextTag = nextTag; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } else { + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = input.readUInt32(); + verifyPackedFixed64Length(bytes); + int endPos = input.getTotalBytesRead() + bytes; + do { + target.add(input.readSFixed64()); + } while (input.getTotalBytesRead() < endPos); + break; + case WIRETYPE_FIXED64: + while (true) { + target.add(input.readSFixed64()); + if (input.isAtEnd()) { + return; + } + int nextTag = input.readTag(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Save the next tag value. + this.nextTag = nextTag; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + } + + @Override + public void readSInt32List(List target) throws IOException { + if (target instanceof IntArrayList) { + IntArrayList plist = (IntArrayList) target; + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = input.readUInt32(); + int endPos = input.getTotalBytesRead() + bytes; + do { + plist.addInt(input.readSInt32()); + } while (input.getTotalBytesRead() < endPos); + requirePosition(endPos); + break; + case WIRETYPE_VARINT: + while (true) { + plist.addInt(input.readSInt32()); + if (input.isAtEnd()) { + return; + } + int nextTag = input.readTag(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Save the next tag value. + this.nextTag = nextTag; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } else { + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = input.readUInt32(); + int endPos = input.getTotalBytesRead() + bytes; + do { + target.add(input.readSInt32()); + } while (input.getTotalBytesRead() < endPos); + requirePosition(endPos); + break; + case WIRETYPE_VARINT: + while (true) { + target.add(input.readSInt32()); + if (input.isAtEnd()) { + return; + } + int nextTag = input.readTag(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Save the next tag value. + this.nextTag = nextTag; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + } + + @Override + public void readSInt64List(List target) throws IOException { + if (target instanceof LongArrayList) { + LongArrayList plist = (LongArrayList) target; + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = input.readUInt32(); + int endPos = input.getTotalBytesRead() + bytes; + do { + plist.addLong(input.readSInt64()); + } while (input.getTotalBytesRead() < endPos); + requirePosition(endPos); + break; + case WIRETYPE_VARINT: + while (true) { + plist.addLong(input.readSInt64()); + if (input.isAtEnd()) { + return; + } + int nextTag = input.readTag(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Save the next tag value. + this.nextTag = nextTag; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } else { + switch (WireFormat.getTagWireType(tag)) { + case WIRETYPE_LENGTH_DELIMITED: + final int bytes = input.readUInt32(); + int endPos = input.getTotalBytesRead() + bytes; + do { + target.add(input.readSInt64()); + } while (input.getTotalBytesRead() < endPos); + requirePosition(endPos); + break; + case WIRETYPE_VARINT: + while (true) { + target.add(input.readSInt64()); + if (input.isAtEnd()) { + return; + } + int nextTag = input.readTag(); + if (nextTag != tag) { + // We've reached the end of the repeated field. Save the next tag value. + this.nextTag = nextTag; + return; + } + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + } + + private void verifyPackedFixed64Length(int bytes) throws IOException { + if ((bytes & FIXED64_MULTIPLE_MASK) != 0) { + // Require that the number of bytes be a multiple of 8. + throw InvalidProtocolBufferException.parseFailure(); + } + } + + @SuppressWarnings("unchecked") + @Override + public void readMap( + Map target, + MapEntryLite.Metadata metadata, + ExtensionRegistryLite extensionRegistry) + throws IOException { + requireWireType(WIRETYPE_LENGTH_DELIMITED); + int size = input.readUInt32(); + final int prevLimit = input.pushLimit(size); + K key = metadata.defaultKey; + V value = metadata.defaultValue; + try { + while (true) { + int number = getFieldNumber(); + if (number == READ_DONE || input.isAtEnd()) { + break; + } + try { + switch (number) { + case 1: + key = (K) readField(metadata.keyType, null, null); + break; + case 2: + value = + (V) + readField( + metadata.valueType, metadata.defaultValue.getClass(), extensionRegistry); + break; + default: + if (!skipField()) { + throw new InvalidProtocolBufferException("Unable to parse map entry."); + } + break; + } + } catch (InvalidProtocolBufferException.InvalidWireTypeException ignore) { + // the type doesn't match, skip the field. + if (!skipField()) { + throw new InvalidProtocolBufferException("Unable to parse map entry."); + } + } + } + target.put(key, value); + } finally { + // Restore the previous limit. + input.popLimit(prevLimit); + } + } + + private Object readField( + WireFormat.FieldType fieldType, Class messageType, ExtensionRegistryLite extensionRegistry) + throws IOException { + switch (fieldType) { + case BOOL: + return readBool(); + case BYTES: + return readBytes(); + case DOUBLE: + return readDouble(); + case ENUM: + return readEnum(); + case FIXED32: + return readFixed32(); + case FIXED64: + return readFixed64(); + case FLOAT: + return readFloat(); + case INT32: + return readInt32(); + case INT64: + return readInt64(); + case MESSAGE: + return readMessage(messageType, extensionRegistry); + case SFIXED32: + return readSFixed32(); + case SFIXED64: + return readSFixed64(); + case SINT32: + return readSInt32(); + case SINT64: + return readSInt64(); + case STRING: + return readStringRequireUtf8(); + case UINT32: + return readUInt32(); + case UINT64: + return readUInt64(); + default: + throw new RuntimeException("unsupported field type."); + } + } + + private void verifyPackedFixed32Length(int bytes) throws IOException { + if ((bytes & FIXED32_MULTIPLE_MASK) != 0) { + // Require that the number of bytes be a multiple of 4. + throw InvalidProtocolBufferException.parseFailure(); + } + } + + private void requirePosition(int expectedPosition) throws IOException { + if (input.getTotalBytesRead() != expectedPosition) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + } +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/CodedOutputStream.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/CodedOutputStream.java new file mode 100644 index 0000000000000..a9192d33e44af --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/CodedOutputStream.java @@ -0,0 +1,3066 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +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.nio.BufferOverflowException; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * Encodes and writes protocol message fields. + * + *

This class contains two kinds of methods: methods that write specific protocol message + * constructs and field types (e.g. {@link #writeTag} and {@link #writeInt32}) and methods that + * write low-level values (e.g. {@link #writeRawVarint32} and {@link #writeRawBytes}). If you are + * writing encoded protocol messages, you should use the former methods, but if you are writing some + * other format of your own design, use the latter. + * + *

This class is totally unsynchronized. + */ +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(); + + /** Used to adapt to the experimental {@link Writer} interface. */ + CodedOutputStreamWriter wrapper; + + /** @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; + + /** + * Returns the buffer size to efficiently write dataLength bytes to this CodedOutputStream. Used + * by AbstractMessageLite. + * + * @return the buffer size to efficiently write dataLength bytes to this CodedOutputStream. + */ + static int computePreferredBufferSize(int dataLength) { + if (dataLength > DEFAULT_BUFFER_SIZE) { + return DEFAULT_BUFFER_SIZE; + } + return dataLength; + } + + /** + * Create a new {@code CodedOutputStream} wrapping the given {@code OutputStream}. + * + *

NOTE: The provided {@link OutputStream} MUST NOT retain access or modify + * the provided byte arrays. Doing so may result in corrupted data, which would be difficult to + * debug. + */ + public static CodedOutputStream newInstance(final OutputStream output) { + return newInstance(output, DEFAULT_BUFFER_SIZE); + } + + /** + * Create a new {@code CodedOutputStream} wrapping the given {@code OutputStream} with a given + * buffer size. + * + *

NOTE: The provided {@link OutputStream} MUST NOT retain access or modify + * the provided byte arrays. Doing so may result in corrupted data, which would be difficult to + * debug. + */ + public static CodedOutputStream newInstance(final OutputStream output, final int bufferSize) { + return new OutputStreamEncoder(output, bufferSize); + } + + /** + * Create a new {@code CodedOutputStream} that writes directly to the given byte array. If more + * bytes are written than fit in the array, {@link OutOfSpaceException} will be thrown. Writing + * directly to a flat array is faster than writing to an {@code OutputStream}. See also {@link + * ByteString#newCodedBuilder}. + */ + public static CodedOutputStream newInstance(final byte[] flatArray) { + return newInstance(flatArray, 0, flatArray.length); + } + + /** + * Create a new {@code CodedOutputStream} that writes directly to the given byte array slice. If + * more bytes are written than fit in the slice, {@link OutOfSpaceException} will be thrown. + * Writing directly to a flat array is faster than writing to an {@code OutputStream}. See also + * {@link ByteString#newCodedBuilder}. + */ + public static CodedOutputStream newInstance( + final byte[] flatArray, final int offset, final int length) { + 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()) { + return new HeapNioEncoder(buffer); + } + if (buffer.isDirect() && !buffer.isReadOnly()) { + return UnsafeDirectNioEncoder.isSupported() + ? newUnsafeInstance(buffer) + : newSafeInstance(buffer); + } + throw new IllegalArgumentException("ByteBuffer is read-only"); + } + + /** For testing purposes only. */ + static CodedOutputStream newUnsafeInstance(ByteBuffer buffer) { + return new UnsafeDirectNioEncoder(buffer); + } + + /** For testing purposes only. */ + static CodedOutputStream newSafeInstance(ByteBuffer buffer) { + return new SafeDirectNioEncoder(buffer); + } + + /** + * Configures serialization to be deterministic. + * + *

The deterministic serialization guarantees that for a given binary, equal (defined by the + * {@code equals()} methods in protos) messages will always be serialized to the same bytes. This + * implies: + * + *

    + *
  • repeated serialization of a message will return the same bytes + *
  • different processes of the same binary (which may be executing on different machines) + * will serialize equal messages to the same bytes. + *
+ * + *

Note the deterministic serialization is NOT canonical across languages; it is also unstable + * across different builds with schema changes due to unknown fields. Users who need canonical + * serialization, e.g. persistent storage in a canonical form, fingerprinting, etc, should define + * their own canonicalization specification and implement the serializer using reflection APIs + * rather than relying on this API. + * + *

Once set, the serializer will: (Note this is an implementation detail and may subject to + * change in the future) + * + *

    + *
  • sort map entries by keys in lexicographical order or numerical order. Note: For string + * keys, the order is based on comparing the Unicode value of each character in the strings. + * The order may be different from the deterministic serialization in other languages where + * maps are sorted on the lexicographical order of the UTF8 encoded keys. + *
+ */ + public void useDeterministicSerialization() { + serializationDeterministic = true; + } + + boolean isSerializationDeterministic() { + return serializationDeterministic; + } + + private boolean serializationDeterministic; + + /** + * Create a new {@code CodedOutputStream} that writes to the given {@link ByteBuffer}. + * + * @deprecated the size parameter is no longer used since use of an internal buffer is useless + * (and wasteful) when writing to a {@link ByteBuffer}. Use {@link #newInstance(ByteBuffer)} + * instead. + */ + @Deprecated + public static CodedOutputStream newInstance( + ByteBuffer byteBuffer, @SuppressWarnings("unused") int unused) { + return newInstance(byteBuffer); + } + + /** + * Create a new {@code CodedOutputStream} that writes to the provided {@link ByteOutput}. + * + *

NOTE: The {@link ByteOutput} MUST NOT modify the provided buffers. Doing so + * may result in corrupted data, which would be difficult to debug. + * + * @param byteOutput the output target for encoded bytes. + * @param bufferSize the size of the internal scratch buffer to be used for string encoding. + * Setting this to {@code 0} will disable buffering, requiring an allocation for each encoded + * string. + */ + static CodedOutputStream newInstance(ByteOutput byteOutput, int bufferSize) { + if (bufferSize < 0) { + throw new IllegalArgumentException("bufferSize must be positive"); + } + + return new ByteOutputEncoder(byteOutput, bufferSize); + } + + // Disallow construction outside of this class. + private CodedOutputStream() {} + + // ----------------------------------------------------------------- + + /** Encode and write a tag. */ + // Abstract to avoid overhead of additional virtual method calls. + public abstract void writeTag(int fieldNumber, int wireType) throws IOException; + + /** Write an {@code int32} field, including tag, to the stream. */ + // Abstract to avoid overhead of additional virtual method calls. + public abstract void writeInt32(int fieldNumber, int value) throws IOException; + + /** Write a {@code uint32} field, including tag, to the stream. */ + // Abstract to avoid overhead of additional virtual method calls. + public abstract void writeUInt32(int fieldNumber, int value) throws IOException; + + /** Write a {@code sint32} field, including tag, to the stream. */ + public final void writeSInt32(final int fieldNumber, final int value) throws IOException { + writeUInt32(fieldNumber, encodeZigZag32(value)); + } + + /** Write a {@code fixed32} field, including tag, to the stream. */ + // Abstract to avoid overhead of additional virtual method calls. + public abstract void writeFixed32(int fieldNumber, int value) throws IOException; + + /** Write an {@code sfixed32} field, including tag, to the stream. */ + public final void writeSFixed32(final int fieldNumber, final int value) throws IOException { + writeFixed32(fieldNumber, value); + } + + /** Write an {@code int64} field, including tag, to the stream. */ + public final void writeInt64(final int fieldNumber, final long value) throws IOException { + writeUInt64(fieldNumber, value); + } + + /** Write a {@code uint64} field, including tag, to the stream. */ + // Abstract to avoid overhead of additional virtual method calls. + public abstract void writeUInt64(int fieldNumber, long value) throws IOException; + + /** Write an {@code sint64} field, including tag, to the stream. */ + public final void writeSInt64(final int fieldNumber, final long value) throws IOException { + writeUInt64(fieldNumber, encodeZigZag64(value)); + } + + /** Write a {@code fixed64} field, including tag, to the stream. */ + // Abstract to avoid overhead of additional virtual method calls. + public abstract void writeFixed64(int fieldNumber, long value) throws IOException; + + /** Write an {@code sfixed64} field, including tag, to the stream. */ + public final void writeSFixed64(final int fieldNumber, final long value) throws IOException { + writeFixed64(fieldNumber, value); + } + + /** Write a {@code float} field, including tag, to the stream. */ + public final void writeFloat(final int fieldNumber, final float value) throws IOException { + writeFixed32(fieldNumber, Float.floatToRawIntBits(value)); + } + + /** Write a {@code double} field, including tag, to the stream. */ + public final void writeDouble(final int fieldNumber, final double value) throws IOException { + writeFixed64(fieldNumber, Double.doubleToRawLongBits(value)); + } + + /** Write a {@code bool} field, including tag, to the stream. */ + // Abstract to avoid overhead of additional virtual method calls. + public abstract void writeBool(int fieldNumber, boolean value) throws IOException; + + /** + * Write an enum field, including tag, to the stream. The provided value is the numeric value used + * to represent the enum value on the wire (not the enum ordinal value). + */ + public final void writeEnum(final int fieldNumber, final int value) throws IOException { + writeInt32(fieldNumber, value); + } + + /** Write a {@code string} field, including tag, to the stream. */ + // Abstract to avoid overhead of additional virtual method calls. + public abstract void writeString(int fieldNumber, String value) throws IOException; + + /** Write a {@code bytes} field, including tag, to the stream. */ + // Abstract to avoid overhead of additional virtual method calls. + public abstract void writeBytes(int fieldNumber, ByteString value) throws IOException; + + /** Write a {@code bytes} field, including tag, to the stream. */ + // Abstract to avoid overhead of additional virtual method calls. + public abstract void writeByteArray(int fieldNumber, byte[] value) throws IOException; + + /** Write a {@code bytes} field, including tag, to the stream. */ + // Abstract to avoid overhead of additional virtual method calls. + public abstract void writeByteArray(int fieldNumber, byte[] value, int offset, int length) + throws IOException; + + /** + * Write a {@code bytes} field, including tag, to the stream. This method will write all content + * of the ByteBuffer regardless of the current position and limit (i.e., the number of bytes to be + * written is value.capacity(), not value.remaining()). Furthermore, this method doesn't alter the + * state of the passed-in ByteBuffer. Its position, limit, mark, etc. will remain unchanged. If + * you only want to write the remaining bytes of a ByteBuffer, you can call {@code + * writeByteBuffer(fieldNumber, byteBuffer.slice())}. + */ + // Abstract to avoid overhead of additional virtual method calls. + public abstract void writeByteBuffer(int fieldNumber, ByteBuffer value) throws IOException; + + /** Write a single byte. */ + public final void writeRawByte(final byte value) throws IOException { + write(value); + } + + /** Write a single byte, represented by an integer value. */ + public final void writeRawByte(final int value) throws IOException { + write((byte) value); + } + + /** Write an array of bytes. */ + public final void writeRawBytes(final byte[] value) throws IOException { + write(value, 0, value.length); + } + + /** Write part of an array of bytes. */ + public final void writeRawBytes(final byte[] value, int offset, int length) throws IOException { + write(value, offset, length); + } + + /** Write a byte string. */ + public final void writeRawBytes(final ByteString value) throws IOException { + value.writeTo(this); + } + + /** + * Write a ByteBuffer. This method will write all content of the ByteBuffer regardless of the + * current position and limit (i.e., the number of bytes to be written is value.capacity(), not + * value.remaining()). Furthermore, this method doesn't alter the state of the passed-in + * ByteBuffer. Its position, limit, mark, etc. will remain unchanged. If you only want to write + * the remaining bytes of a ByteBuffer, you can call {@code writeRawBytes(byteBuffer.slice())}. + */ + // Abstract to avoid overhead of additional virtual method calls. + public abstract void writeRawBytes(final ByteBuffer value) throws IOException; + + /** Write an embedded message field, including tag, to the stream. */ + // Abstract to avoid overhead of additional virtual method calls. + public abstract void writeMessage(final int fieldNumber, final MessageLite value) + throws IOException; + + /** Write an embedded message field, including tag, to the stream. */ + // Abstract to avoid overhead of additional virtual method calls. + abstract void writeMessage(final int fieldNumber, final MessageLite value, Schema schema) + throws IOException; + + /** + * Write a MessageSet extension field to the stream. For historical reasons, the wire format + * differs from normal fields. + */ + // Abstract to avoid overhead of additional virtual method calls. + public abstract void writeMessageSetExtension(final int fieldNumber, final MessageLite value) + throws IOException; + + /** + * Write an unparsed MessageSet extension field to the stream. For historical reasons, the wire + * format differs from normal fields. + */ + // Abstract to avoid overhead of additional virtual method calls. + public abstract void writeRawMessageSetExtension(final int fieldNumber, final ByteString value) + throws IOException; + + // ----------------------------------------------------------------- + + /** Write an {@code int32} field to the stream. */ + // Abstract to avoid overhead of additional virtual method calls. + public abstract void writeInt32NoTag(final int value) throws IOException; + + /** Write a {@code uint32} field to the stream. */ + // Abstract to avoid overhead of additional virtual method calls. + public abstract void writeUInt32NoTag(int value) throws IOException; + + /** Write a {@code sint32} field to the stream. */ + public final void writeSInt32NoTag(final int value) throws IOException { + writeUInt32NoTag(encodeZigZag32(value)); + } + + /** Write a {@code fixed32} field to the stream. */ + // Abstract to avoid overhead of additional virtual method calls. + public abstract void writeFixed32NoTag(int value) throws IOException; + + /** Write a {@code sfixed32} field to the stream. */ + public final void writeSFixed32NoTag(final int value) throws IOException { + writeFixed32NoTag(value); + } + + /** Write an {@code int64} field to the stream. */ + public final void writeInt64NoTag(final long value) throws IOException { + writeUInt64NoTag(value); + } + + /** Write a {@code uint64} field to the stream. */ + // Abstract to avoid overhead of additional virtual method calls. + public abstract void writeUInt64NoTag(long value) throws IOException; + + /** Write a {@code sint64} field to the stream. */ + public final void writeSInt64NoTag(final long value) throws IOException { + writeUInt64NoTag(encodeZigZag64(value)); + } + + /** Write a {@code fixed64} field to the stream. */ + // Abstract to avoid overhead of additional virtual method calls. + public abstract void writeFixed64NoTag(long value) throws IOException; + + /** Write a {@code sfixed64} field to the stream. */ + public final void writeSFixed64NoTag(final long value) throws IOException { + writeFixed64NoTag(value); + } + + /** Write a {@code float} field to the stream. */ + public final void writeFloatNoTag(final float value) throws IOException { + writeFixed32NoTag(Float.floatToRawIntBits(value)); + } + + /** Write a {@code double} field to the stream. */ + public final void writeDoubleNoTag(final double value) throws IOException { + writeFixed64NoTag(Double.doubleToRawLongBits(value)); + } + + /** Write a {@code bool} field to the stream. */ + public final void writeBoolNoTag(final boolean value) throws IOException { + write((byte) (value ? 1 : 0)); + } + + /** + * Write an enum field to the stream. The provided value is the numeric value used to represent + * the enum value on the wire (not the enum ordinal value). + */ + public final void writeEnumNoTag(final int value) throws IOException { + writeInt32NoTag(value); + } + + /** Write a {@code string} field to the stream. */ + // TODO(dweis): Document behavior on ill-formed UTF-16 input. + // Abstract to avoid overhead of additional virtual method calls. + public abstract void writeStringNoTag(String value) throws IOException; + + /** Write a {@code bytes} field to the stream. */ + // Abstract to avoid overhead of additional virtual method calls. + public abstract void writeBytesNoTag(final ByteString value) throws IOException; + + /** Write a {@code bytes} field to the stream. */ + public final void writeByteArrayNoTag(final byte[] value) throws IOException { + writeByteArrayNoTag(value, 0, value.length); + } + + /** Write an embedded message field to the stream. */ + // Abstract to avoid overhead of additional virtual method calls. + public abstract void writeMessageNoTag(final MessageLite value) throws IOException; + + /** Write an embedded message field to the stream. */ + // Abstract to avoid overhead of additional virtual method calls. + abstract void writeMessageNoTag(final MessageLite value, Schema schema) throws IOException; + + // ================================================================= + + @ExperimentalApi + @Override + public abstract void write(byte value) throws IOException; + + @ExperimentalApi + @Override + public abstract void write(byte[] value, int offset, int length) throws IOException; + + @ExperimentalApi + @Override + public abstract void writeLazy(byte[] value, int offset, int length) throws IOException; + + @Override + public abstract void write(ByteBuffer value) throws IOException; + + @ExperimentalApi + @Override + public abstract void writeLazy(ByteBuffer value) throws IOException; + + // ================================================================= + // ================================================================= + + /** + * Compute the number of bytes that would be needed to encode an {@code int32} field, including + * tag. + */ + public static int computeInt32Size(final int fieldNumber, final int value) { + return computeTagSize(fieldNumber) + computeInt32SizeNoTag(value); + } + + /** + * Compute the number of bytes that would be needed to encode a {@code uint32} field, including + * tag. + */ + public static int computeUInt32Size(final int fieldNumber, final int value) { + return computeTagSize(fieldNumber) + computeUInt32SizeNoTag(value); + } + + /** + * Compute the number of bytes that would be needed to encode an {@code sint32} field, including + * tag. + */ + public static int computeSInt32Size(final int fieldNumber, final int value) { + return computeTagSize(fieldNumber) + computeSInt32SizeNoTag(value); + } + + /** + * Compute the number of bytes that would be needed to encode a {@code fixed32} field, including + * tag. + */ + public static int computeFixed32Size(final int fieldNumber, final int value) { + return computeTagSize(fieldNumber) + computeFixed32SizeNoTag(value); + } + + /** + * Compute the number of bytes that would be needed to encode an {@code sfixed32} field, including + * tag. + */ + public static int computeSFixed32Size(final int fieldNumber, final int value) { + return computeTagSize(fieldNumber) + computeSFixed32SizeNoTag(value); + } + + /** + * Compute the number of bytes that would be needed to encode an {@code int64} field, including + * tag. + */ + public static int computeInt64Size(final int fieldNumber, final long value) { + return computeTagSize(fieldNumber) + computeInt64SizeNoTag(value); + } + + /** + * Compute the number of bytes that would be needed to encode a {@code uint64} field, including + * tag. + */ + public static int computeUInt64Size(final int fieldNumber, final long value) { + return computeTagSize(fieldNumber) + computeUInt64SizeNoTag(value); + } + + /** + * Compute the number of bytes that would be needed to encode an {@code sint64} field, including + * tag. + */ + public static int computeSInt64Size(final int fieldNumber, final long value) { + return computeTagSize(fieldNumber) + computeSInt64SizeNoTag(value); + } + + /** + * Compute the number of bytes that would be needed to encode a {@code fixed64} field, including + * tag. + */ + public static int computeFixed64Size(final int fieldNumber, final long value) { + return computeTagSize(fieldNumber) + computeFixed64SizeNoTag(value); + } + + /** + * Compute the number of bytes that would be needed to encode an {@code sfixed64} field, including + * tag. + */ + public static int computeSFixed64Size(final int fieldNumber, final long value) { + return computeTagSize(fieldNumber) + computeSFixed64SizeNoTag(value); + } + + /** + * Compute the number of bytes that would be needed to encode a {@code float} field, including + * tag. + */ + public static int computeFloatSize(final int fieldNumber, final float value) { + return computeTagSize(fieldNumber) + computeFloatSizeNoTag(value); + } + + /** + * Compute the number of bytes that would be needed to encode a {@code double} field, including + * tag. + */ + public static int computeDoubleSize(final int fieldNumber, final double value) { + return computeTagSize(fieldNumber) + computeDoubleSizeNoTag(value); + } + + /** + * Compute the number of bytes that would be needed to encode a {@code bool} field, including tag. + */ + public static int computeBoolSize(final int fieldNumber, final boolean value) { + return computeTagSize(fieldNumber) + computeBoolSizeNoTag(value); + } + + /** + * Compute the number of bytes that would be needed to encode an enum field, including tag. The + * provided value is the numeric value used to represent the enum value on the wire (not the enum + * ordinal value). + */ + public static int computeEnumSize(final int fieldNumber, final int value) { + return computeTagSize(fieldNumber) + computeEnumSizeNoTag(value); + } + + /** + * Compute the number of bytes that would be needed to encode a {@code string} field, including + * tag. + */ + public static int computeStringSize(final int fieldNumber, final String value) { + return computeTagSize(fieldNumber) + computeStringSizeNoTag(value); + } + + /** + * Compute the number of bytes that would be needed to encode a {@code bytes} field, including + * tag. + */ + public static int computeBytesSize(final int fieldNumber, final ByteString value) { + return computeTagSize(fieldNumber) + computeBytesSizeNoTag(value); + } + + /** + * Compute the number of bytes that would be needed to encode a {@code bytes} field, including + * tag. + */ + public static int computeByteArraySize(final int fieldNumber, final byte[] value) { + return computeTagSize(fieldNumber) + computeByteArraySizeNoTag(value); + } + + /** + * Compute the number of bytes that would be needed to encode a {@code bytes} field, including + * tag. + */ + public static int computeByteBufferSize(final int fieldNumber, final ByteBuffer value) { + return computeTagSize(fieldNumber) + computeByteBufferSizeNoTag(value); + } + + /** + * Compute the number of bytes that would be needed to encode an embedded message in lazy field, + * including tag. + */ + public static int computeLazyFieldSize(final int fieldNumber, final LazyFieldLite value) { + return computeTagSize(fieldNumber) + computeLazyFieldSizeNoTag(value); + } + + /** + * Compute the number of bytes that would be needed to encode an embedded message field, including + * tag. + */ + public static int computeMessageSize(final int fieldNumber, final MessageLite value) { + return computeTagSize(fieldNumber) + computeMessageSizeNoTag(value); + } + + /** + * Compute the number of bytes that would be needed to encode an embedded message field, including + * tag. + */ + static int computeMessageSize( + final int fieldNumber, final MessageLite value, final Schema schema) { + return computeTagSize(fieldNumber) + computeMessageSizeNoTag(value, schema); + } + + /** + * Compute the number of bytes that would be needed to encode a MessageSet extension to the + * 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); + } + + /** + * Compute the number of bytes that would be needed to encode an unparsed MessageSet extension + * field to the stream. For historical reasons, the wire format differs from normal fields. + */ + 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); + } + + /** + * Compute the number of bytes that would be needed to encode an lazily parsed MessageSet + * extension field to the stream. For historical reasons, the wire format differs from normal + * fields. + */ + 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); + } + + // ----------------------------------------------------------------- + + /** 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)); + } + + /** + * Compute the number of bytes that would be needed to encode an {@code int32} field, including + * tag. + */ + public static int computeInt32SizeNoTag(final int value) { + if (value >= 0) { + return computeUInt32SizeNoTag(value); + } else { + // Must sign-extend. + return MAX_VARINT_SIZE; + } + } + + /** Compute the number of bytes that would be needed to encode a {@code uint32} field. */ + public static int computeUInt32SizeNoTag(final int value) { + if ((value & (~0 << 7)) == 0) { + return 1; + } + if ((value & (~0 << 14)) == 0) { + return 2; + } + if ((value & (~0 << 21)) == 0) { + return 3; + } + if ((value & (~0 << 28)) == 0) { + return 4; + } + return 5; + } + + /** Compute the number of bytes that would be needed to encode an {@code sint32} field. */ + public static int computeSInt32SizeNoTag(final int value) { + return computeUInt32SizeNoTag(encodeZigZag32(value)); + } + + /** Compute the number of bytes that would be needed to encode a {@code fixed32} field. */ + public static int computeFixed32SizeNoTag(@SuppressWarnings("unused") final int unused) { + return FIXED32_SIZE; + } + + /** Compute the number of bytes that would be needed to encode an {@code sfixed32} field. */ + public static int computeSFixed32SizeNoTag(@SuppressWarnings("unused") final int unused) { + return FIXED32_SIZE; + } + + /** + * Compute the number of bytes that would be needed to encode an {@code int64} field, including + * tag. + */ + public static int computeInt64SizeNoTag(final long value) { + return computeUInt64SizeNoTag(value); + } + + /** + * Compute the number of bytes that would be needed to encode a {@code uint64} field, including + * tag. + */ + public static int computeUInt64SizeNoTag(long value) { + // handle two popular special cases up front ... + if ((value & (~0L << 7)) == 0L) { + return 1; + } + if (value < 0L) { + return 10; + } + // ... leaving us with 8 remaining, which we can divide and conquer + int n = 2; + if ((value & (~0L << 35)) != 0L) { + n += 4; + value >>>= 28; + } + if ((value & (~0L << 21)) != 0L) { + n += 2; + value >>>= 14; + } + if ((value & (~0L << 14)) != 0L) { + n += 1; + } + return n; + } + + /** Compute the number of bytes that would be needed to encode an {@code sint64} field. */ + public static int computeSInt64SizeNoTag(final long value) { + return computeUInt64SizeNoTag(encodeZigZag64(value)); + } + + /** Compute the number of bytes that would be needed to encode a {@code fixed64} field. */ + public static int computeFixed64SizeNoTag(@SuppressWarnings("unused") final long unused) { + return FIXED64_SIZE; + } + + /** Compute the number of bytes that would be needed to encode an {@code sfixed64} field. */ + public static int computeSFixed64SizeNoTag(@SuppressWarnings("unused") final long unused) { + return FIXED64_SIZE; + } + + /** + * Compute the number of bytes that would be needed to encode a {@code float} field, including + * tag. + */ + public static int computeFloatSizeNoTag(@SuppressWarnings("unused") final float unused) { + return FIXED32_SIZE; + } + + /** + * Compute the number of bytes that would be needed to encode a {@code double} field, including + * tag. + */ + public static int computeDoubleSizeNoTag(@SuppressWarnings("unused") final double unused) { + return FIXED64_SIZE; + } + + /** Compute the number of bytes that would be needed to encode a {@code bool} field. */ + public static int computeBoolSizeNoTag(@SuppressWarnings("unused") final boolean unused) { + return 1; + } + + /** + * Compute the number of bytes that would be needed to encode an enum field. The provided value is + * the numeric value used to represent the enum value on the wire (not the enum ordinal value). + */ + public static int computeEnumSizeNoTag(final int value) { + return computeInt32SizeNoTag(value); + } + + /** Compute the number of bytes that would be needed to encode a {@code string} field. */ + public static int computeStringSizeNoTag(final String value) { + int length; + try { + length = Utf8.encodedLength(value); + } catch (UnpairedSurrogateException e) { + // TODO(dweis): Consider using nio Charset methods instead. + final byte[] bytes = value.getBytes(Internal.UTF_8); + length = bytes.length; + } + + return computeLengthDelimitedFieldSize(length); + } + + /** + * Compute the number of bytes that would be needed to encode an embedded message stored in lazy + * field. + */ + public static int computeLazyFieldSizeNoTag(final LazyFieldLite value) { + return computeLengthDelimitedFieldSize(value.getSerializedSize()); + } + + /** Compute the number of bytes that would be needed to encode a {@code bytes} field. */ + public static int computeBytesSizeNoTag(final ByteString value) { + return computeLengthDelimitedFieldSize(value.size()); + } + + /** Compute the number of bytes that would be needed to encode a {@code bytes} field. */ + public static int computeByteArraySizeNoTag(final byte[] value) { + return computeLengthDelimitedFieldSize(value.length); + } + + /** Compute the number of bytes that would be needed to encode a {@code bytes} field. */ + public static int computeByteBufferSizeNoTag(final ByteBuffer value) { + return computeLengthDelimitedFieldSize(value.capacity()); + } + + /** Compute the number of bytes that would be needed to encode an embedded message field. */ + public static int computeMessageSizeNoTag(final MessageLite value) { + return computeLengthDelimitedFieldSize(value.getSerializedSize()); + } + + /** 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)); + } + + static int computeLengthDelimitedFieldSize(int fieldLength) { + return computeUInt32SizeNoTag(fieldLength) + fieldLength; + } + + /** + * Encode a ZigZag-encoded 32-bit value. ZigZag encodes signed integers into values that can be + * efficiently encoded with varint. (Otherwise, negative values must be sign-extended to 64 bits + * to be varint encoded, thus always taking 10 bytes on the wire.) + * + * @param n A signed 32-bit integer. + * @return An unsigned 32-bit integer, stored in a signed int because Java has no explicit + * unsigned support. + */ + public static int encodeZigZag32(final int n) { + // Note: the right-shift must be arithmetic + return (n << 1) ^ (n >> 31); + } + + /** + * Encode a ZigZag-encoded 64-bit value. ZigZag encodes signed integers into values that can be + * efficiently encoded with varint. (Otherwise, negative values must be sign-extended to 64 bits + * to be varint encoded, thus always taking 10 bytes on the wire.) + * + * @param n A signed 64-bit integer. + * @return An unsigned 64-bit integer, stored in a signed int because Java has no explicit + * unsigned support. + */ + public static long encodeZigZag64(final long n) { + // Note: the right-shift must be arithmetic + return (n << 1) ^ (n >> 63); + } + + // ================================================================= + + /** + * Flushes the stream and forces any buffered bytes to be written. This does not flush the + * underlying OutputStream. + */ + public abstract void flush() throws IOException; + + /** + * If writing to a flat array, return the space left in the array. Otherwise, throws {@code + * UnsupportedOperationException}. + */ + public abstract int spaceLeft(); + + /** + * Verifies that {@link #spaceLeft()} returns zero. It's common to create a byte array that is + * exactly big enough to hold a message, then write to it with a {@code CodedOutputStream}. + * Calling {@code checkNoSpaceLeft()} after writing verifies that the message was actually as big + * as expected, which can help catch bugs. + */ + public final void checkNoSpaceLeft() { + if (spaceLeft() != 0) { + throw new IllegalStateException("Did not write as much data as expected."); + } + } + + /** + * If you create a CodedOutputStream around a simple flat array, you must not attempt to write + * more bytes than the array has space. Otherwise, this exception will be thrown. + */ + public static class OutOfSpaceException extends IOException { + private static final long serialVersionUID = -6947486886997889499L; + + private static final String MESSAGE = + "CodedOutputStream was writing to a flat byte array and ran out of space."; + + OutOfSpaceException() { + super(MESSAGE); + } + + OutOfSpaceException(String explanationMessage) { + super(MESSAGE + ": " + explanationMessage); + } + + OutOfSpaceException(Throwable cause) { + super(MESSAGE, cause); + } + + OutOfSpaceException(String explanationMessage, Throwable cause) { + super(MESSAGE + ": " + explanationMessage, cause); + } + } + + /** + * Get the total number of bytes successfully written to this stream. The returned value is not + * guaranteed to be accurate if exceptions have been found in the middle of writing. + */ + public abstract int getTotalBytesWritten(); + + // ================================================================= + + /** Write a {@code bytes} field to the stream. Visible for testing. */ + abstract void writeByteArrayNoTag(final byte[] value, final int offset, final int length) + throws IOException; + + final void inefficientWriteStringNoTag(String value, UnpairedSurrogateException cause) + throws IOException { + logger.log( + Level.WARNING, + "Converting ill-formed UTF-16. Your Protocol Buffer will not round trip correctly!", + cause); + + // Unfortunately there does not appear to be any way to tell Java to encode + // UTF-8 directly into our buffer, so we have to let it create its own byte + // array and then copy. + // TODO(dweis): Consider using nio Charset methods instead. + final byte[] bytes = value.getBytes(Internal.UTF_8); + try { + writeUInt32NoTag(bytes.length); + writeLazy(bytes, 0, bytes.length); + } catch (IndexOutOfBoundsException e) { + throw new OutOfSpaceException(e); + } catch (OutOfSpaceException e) { + throw e; + } + } + + // ================================================================= + + /** + * Write a {@code group} field, including tag, to the stream. + * + * @deprecated groups are deprecated. + */ + @Deprecated + public final void writeGroup(final int fieldNumber, final MessageLite value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_START_GROUP); + writeGroupNoTag(value); + writeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP); + } + + /** + * Write a {@code group} field, including tag, to the stream. + * + * @deprecated groups are deprecated. + */ + @Deprecated + final void writeGroup(final int fieldNumber, final MessageLite value, Schema schema) + throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_START_GROUP); + writeGroupNoTag(value, schema); + writeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP); + } + + /** + * Write a {@code group} field to the stream. + * + * @deprecated groups are deprecated. + */ + @Deprecated + public final void writeGroupNoTag(final MessageLite value) throws IOException { + value.writeTo(this); + } + + /** + * Write a {@code group} field to the stream. + * + * @deprecated groups are deprecated. + */ + @Deprecated + final void writeGroupNoTag(final MessageLite value, Schema schema) throws IOException { + schema.writeTo(value, wrapper); + } + + /** + * Compute the number of bytes that would be needed to encode a {@code group} field, including + * tag. + * + * @deprecated groups are deprecated. + */ + @Deprecated + public static int computeGroupSize(final int fieldNumber, final MessageLite value) { + return computeTagSize(fieldNumber) * 2 + computeGroupSizeNoTag(value); + } + + /** + * Compute the number of bytes that would be needed to encode a {@code group} field, including + * tag. + * + * @deprecated groups are deprecated. + */ + @Deprecated + static int computeGroupSize(final int fieldNumber, final MessageLite value, Schema schema) { + return computeTagSize(fieldNumber) * 2 + computeGroupSizeNoTag(value, schema); + } + + /** Compute the number of bytes that would be needed to encode a {@code group} field. */ + @Deprecated + public static int computeGroupSizeNoTag(final MessageLite value) { + return value.getSerializedSize(); + } + + /** 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); + } + + /** + * Encode and write a varint. {@code value} is treated as unsigned, so it won't be sign-extended + * if negative. + * + * @deprecated use {@link #writeUInt32NoTag} instead. + */ + @Deprecated + public final void writeRawVarint32(int value) throws IOException { + writeUInt32NoTag(value); + } + + /** + * Encode and write a varint. + * + * @deprecated use {@link #writeUInt64NoTag} instead. + */ + @Deprecated + public final void writeRawVarint64(long value) throws IOException { + writeUInt64NoTag(value); + } + + /** + * Compute the number of bytes that would be needed to encode a varint. {@code value} is treated + * as unsigned, so it won't be sign-extended if negative. + * + * @deprecated use {@link #computeUInt32SizeNoTag(int)} instead. + */ + @Deprecated + public static int computeRawVarint32Size(final int value) { + return computeUInt32SizeNoTag(value); + } + + /** + * Compute the number of bytes that would be needed to encode a varint. + * + * @deprecated use {@link #computeUInt64SizeNoTag(long)} instead. + */ + @Deprecated + public static int computeRawVarint64Size(long value) { + return computeUInt64SizeNoTag(value); + } + + /** + * Write a little-endian 32-bit integer. + * + * @deprecated Use {@link #writeFixed32NoTag} instead. + */ + @Deprecated + public final void writeRawLittleEndian32(final int value) throws IOException { + writeFixed32NoTag(value); + } + + /** + * Write a little-endian 64-bit integer. + * + * @deprecated Use {@link #writeFixed64NoTag} instead. + */ + @Deprecated + 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(); + duplicated.clear(); + 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 { + if (HAS_UNSAFE_ARRAY_OPERATIONS + && !Android.isOnAndroidDevice() + && spaceLeft() >= MAX_VARINT32_SIZE) { + if ((value & ~0x7F) == 0) { + UnsafeUtil.putByte(buffer, position++, (byte) value); + return; + } + UnsafeUtil.putByte(buffer, position++, (byte) (value | 0x80)); + value >>>= 7; + if ((value & ~0x7F) == 0) { + UnsafeUtil.putByte(buffer, position++, (byte) value); + return; + } + UnsafeUtil.putByte(buffer, position++, (byte) (value | 0x80)); + value >>>= 7; + if ((value & ~0x7F) == 0) { + UnsafeUtil.putByte(buffer, position++, (byte) value); + return; + } + UnsafeUtil.putByte(buffer, position++, (byte) (value | 0x80)); + value >>>= 7; + if ((value & ~0x7F) == 0) { + UnsafeUtil.putByte(buffer, position++, (byte) value); + return; + } + UnsafeUtil.putByte(buffer, position++, (byte) (value | 0x80)); + value >>>= 7; + UnsafeUtil.putByte(buffer, position++, (byte) value); + } else { + 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(nathanmittler): 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. + byteBuffer.position(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(); + duplicated.clear(); + 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; + buffer.position(startOfBytes); + + // Encode the string. + encode(value); + + // Now go back to the beginning and write the length. + int endOfBytes = buffer.position(); + buffer.position(startPos); + writeUInt32NoTag(endOfBytes - startOfBytes); + + // Reposition the buffer past the written data. + buffer.position(endOfBytes); + } else { + final int length = Utf8.encodedLength(value); + writeUInt32NoTag(length); + encode(value); + } + } catch (UnpairedSurrogateException e) { + // Roll back the change and convert to an IOException. + buffer.position(startPos); + + // TODO(nathanmittler): 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. + originalBuffer.position(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(); + duplicated.clear(); + 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; + buffer.position(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(nathanmittler): 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. + originalBuffer.position(bufferPos(position)); + } + + @Override + public int spaceLeft() { + return (int) (limit - position); + } + + @Override + public int getTotalBytesWritten() { + return (int) (position - initialPosition); + } + + private void repositionBuffer(long pos) { + buffer.position(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(); + duplicated.clear(); + 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(nathanmittler): 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(); + duplicated.clear(); + 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/java/kotlin-lite/target/generated-sources/com/google/protobuf/CodedOutputStreamWriter.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/CodedOutputStreamWriter.java new file mode 100644 index 0000000000000..0d1983cb07b1c --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/CodedOutputStreamWriter.java @@ -0,0 +1,691 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +import static com.google.protobuf.Internal.checkNotNull; +import static com.google.protobuf.WireFormat.WIRETYPE_LENGTH_DELIMITED; + +import java.io.IOException; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +/** An adapter between the {@link Writer} interface and {@link CodedOutputStream}. */ +@ExperimentalApi +final class CodedOutputStreamWriter implements Writer { + private final CodedOutputStream output; + + public static CodedOutputStreamWriter forCodedOutput(CodedOutputStream output) { + if (output.wrapper != null) { + return output.wrapper; + } + return new CodedOutputStreamWriter(output); + } + + private CodedOutputStreamWriter(CodedOutputStream output) { + this.output = checkNotNull(output, "output"); + this.output.wrapper = this; + } + + @Override + public FieldOrder fieldOrder() { + return FieldOrder.ASCENDING; + } + + public int getTotalBytesWritten() { + return output.getTotalBytesWritten(); + } + + @Override + public void writeSFixed32(int fieldNumber, int value) throws IOException { + output.writeSFixed32(fieldNumber, value); + } + + @Override + public void writeInt64(int fieldNumber, long value) throws IOException { + output.writeInt64(fieldNumber, value); + } + + @Override + public void writeSFixed64(int fieldNumber, long value) throws IOException { + output.writeSFixed64(fieldNumber, value); + } + + @Override + public void writeFloat(int fieldNumber, float value) throws IOException { + output.writeFloat(fieldNumber, value); + } + + @Override + public void writeDouble(int fieldNumber, double value) throws IOException { + output.writeDouble(fieldNumber, value); + } + + @Override + public void writeEnum(int fieldNumber, int value) throws IOException { + output.writeEnum(fieldNumber, value); + } + + @Override + public void writeUInt64(int fieldNumber, long value) throws IOException { + output.writeUInt64(fieldNumber, value); + } + + @Override + public void writeInt32(int fieldNumber, int value) throws IOException { + output.writeInt32(fieldNumber, value); + } + + @Override + public void writeFixed64(int fieldNumber, long value) throws IOException { + output.writeFixed64(fieldNumber, value); + } + + @Override + public void writeFixed32(int fieldNumber, int value) throws IOException { + output.writeFixed32(fieldNumber, value); + } + + @Override + public void writeBool(int fieldNumber, boolean value) throws IOException { + output.writeBool(fieldNumber, value); + } + + @Override + public void writeString(int fieldNumber, String value) throws IOException { + output.writeString(fieldNumber, value); + } + + @Override + public void writeBytes(int fieldNumber, ByteString value) throws IOException { + output.writeBytes(fieldNumber, value); + } + + @Override + public void writeUInt32(int fieldNumber, int value) throws IOException { + output.writeUInt32(fieldNumber, value); + } + + @Override + public void writeSInt32(int fieldNumber, int value) throws IOException { + output.writeSInt32(fieldNumber, value); + } + + @Override + public void writeSInt64(int fieldNumber, long value) throws IOException { + output.writeSInt64(fieldNumber, value); + } + + @Override + public void writeMessage(int fieldNumber, Object value) throws IOException { + output.writeMessage(fieldNumber, (MessageLite) value); + } + + @Override + public void writeMessage(int fieldNumber, Object value, Schema schema) throws IOException { + output.writeMessage(fieldNumber, (MessageLite) value, schema); + } + + @Override + public void writeGroup(int fieldNumber, Object value) throws IOException { + output.writeGroup(fieldNumber, (MessageLite) value); + } + + @Override + public void writeGroup(int fieldNumber, Object value, Schema schema) throws IOException { + output.writeGroup(fieldNumber, (MessageLite) value, schema); + } + + @Override + public void writeStartGroup(int fieldNumber) throws IOException { + output.writeTag(fieldNumber, WireFormat.WIRETYPE_START_GROUP); + } + + @Override + public void writeEndGroup(int fieldNumber) throws IOException { + output.writeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP); + } + + @Override + public final void writeMessageSetItem(int fieldNumber, Object value) throws IOException { + if (value instanceof ByteString) { + output.writeRawMessageSetExtension(fieldNumber, (ByteString) value); + } else { + output.writeMessageSetExtension(fieldNumber, (MessageLite) value); + } + } + + @Override + public void writeInt32List(int fieldNumber, List value, boolean packed) + throws IOException { + if (packed) { + output.writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + + // Compute and write the length of the data. + int dataSize = 0; + for (int i = 0; i < value.size(); ++i) { + dataSize += CodedOutputStream.computeInt32SizeNoTag(value.get(i)); + } + output.writeUInt32NoTag(dataSize); + + // Write the data itself, without any tags. + for (int i = 0; i < value.size(); ++i) { + output.writeInt32NoTag(value.get(i)); + } + } else { + for (int i = 0; i < value.size(); ++i) { + output.writeInt32(fieldNumber, value.get(i)); + } + } + } + + @Override + public void writeFixed32List(int fieldNumber, List value, boolean packed) + throws IOException { + if (packed) { + output.writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + + // Compute and write the length of the data. + int dataSize = 0; + for (int i = 0; i < value.size(); ++i) { + dataSize += CodedOutputStream.computeFixed32SizeNoTag(value.get(i)); + } + output.writeUInt32NoTag(dataSize); + + // Write the data itself, without any tags. + for (int i = 0; i < value.size(); ++i) { + output.writeFixed32NoTag(value.get(i)); + } + } else { + for (int i = 0; i < value.size(); ++i) { + output.writeFixed32(fieldNumber, value.get(i)); + } + } + } + + @Override + public void writeInt64List(int fieldNumber, List value, boolean packed) throws IOException { + if (packed) { + output.writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + + // Compute and write the length of the data. + int dataSize = 0; + for (int i = 0; i < value.size(); ++i) { + dataSize += CodedOutputStream.computeInt64SizeNoTag(value.get(i)); + } + output.writeUInt32NoTag(dataSize); + + // Write the data itself, without any tags. + for (int i = 0; i < value.size(); ++i) { + output.writeInt64NoTag(value.get(i)); + } + } else { + for (int i = 0; i < value.size(); ++i) { + output.writeInt64(fieldNumber, value.get(i)); + } + } + } + + @Override + public void writeUInt64List(int fieldNumber, List value, boolean packed) + throws IOException { + if (packed) { + output.writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + + // Compute and write the length of the data. + int dataSize = 0; + for (int i = 0; i < value.size(); ++i) { + dataSize += CodedOutputStream.computeUInt64SizeNoTag(value.get(i)); + } + output.writeUInt32NoTag(dataSize); + + // Write the data itself, without any tags. + for (int i = 0; i < value.size(); ++i) { + output.writeUInt64NoTag(value.get(i)); + } + } else { + for (int i = 0; i < value.size(); ++i) { + output.writeUInt64(fieldNumber, value.get(i)); + } + } + } + + @Override + public void writeFixed64List(int fieldNumber, List value, boolean packed) + throws IOException { + if (packed) { + output.writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + + // Compute and write the length of the data. + int dataSize = 0; + for (int i = 0; i < value.size(); ++i) { + dataSize += CodedOutputStream.computeFixed64SizeNoTag(value.get(i)); + } + output.writeUInt32NoTag(dataSize); + + // Write the data itself, without any tags. + for (int i = 0; i < value.size(); ++i) { + output.writeFixed64NoTag(value.get(i)); + } + } else { + for (int i = 0; i < value.size(); ++i) { + output.writeFixed64(fieldNumber, value.get(i)); + } + } + } + + @Override + public void writeFloatList(int fieldNumber, List value, boolean packed) + throws IOException { + if (packed) { + output.writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + + // Compute and write the length of the data. + int dataSize = 0; + for (int i = 0; i < value.size(); ++i) { + dataSize += CodedOutputStream.computeFloatSizeNoTag(value.get(i)); + } + output.writeUInt32NoTag(dataSize); + + // Write the data itself, without any tags. + for (int i = 0; i < value.size(); ++i) { + output.writeFloatNoTag(value.get(i)); + } + } else { + for (int i = 0; i < value.size(); ++i) { + output.writeFloat(fieldNumber, value.get(i)); + } + } + } + + @Override + public void writeDoubleList(int fieldNumber, List value, boolean packed) + throws IOException { + if (packed) { + output.writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + + // Compute and write the length of the data. + int dataSize = 0; + for (int i = 0; i < value.size(); ++i) { + dataSize += CodedOutputStream.computeDoubleSizeNoTag(value.get(i)); + } + output.writeUInt32NoTag(dataSize); + + // Write the data itself, without any tags. + for (int i = 0; i < value.size(); ++i) { + output.writeDoubleNoTag(value.get(i)); + } + } else { + for (int i = 0; i < value.size(); ++i) { + output.writeDouble(fieldNumber, value.get(i)); + } + } + } + + @Override + public void writeEnumList(int fieldNumber, List value, boolean packed) + throws IOException { + if (packed) { + output.writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + + // Compute and write the length of the data. + int dataSize = 0; + for (int i = 0; i < value.size(); ++i) { + dataSize += CodedOutputStream.computeEnumSizeNoTag(value.get(i)); + } + output.writeUInt32NoTag(dataSize); + + // Write the data itself, without any tags. + for (int i = 0; i < value.size(); ++i) { + output.writeEnumNoTag(value.get(i)); + } + } else { + for (int i = 0; i < value.size(); ++i) { + output.writeEnum(fieldNumber, value.get(i)); + } + } + } + + @Override + public void writeBoolList(int fieldNumber, List value, boolean packed) + throws IOException { + if (packed) { + output.writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + + // Compute and write the length of the data. + int dataSize = 0; + for (int i = 0; i < value.size(); ++i) { + dataSize += CodedOutputStream.computeBoolSizeNoTag(value.get(i)); + } + output.writeUInt32NoTag(dataSize); + + // Write the data itself, without any tags. + for (int i = 0; i < value.size(); ++i) { + output.writeBoolNoTag(value.get(i)); + } + } else { + for (int i = 0; i < value.size(); ++i) { + output.writeBool(fieldNumber, value.get(i)); + } + } + } + + @Override + public void writeStringList(int fieldNumber, List value) throws IOException { + if (value instanceof LazyStringList) { + final LazyStringList lazyList = (LazyStringList) value; + for (int i = 0; i < value.size(); ++i) { + writeLazyString(fieldNumber, lazyList.getRaw(i)); + } + } else { + for (int i = 0; i < value.size(); ++i) { + output.writeString(fieldNumber, value.get(i)); + } + } + } + + private void writeLazyString(int fieldNumber, Object value) throws IOException { + if (value instanceof String) { + output.writeString(fieldNumber, (String) value); + } else { + output.writeBytes(fieldNumber, (ByteString) value); + } + } + + @Override + public void writeBytesList(int fieldNumber, List value) throws IOException { + for (int i = 0; i < value.size(); ++i) { + output.writeBytes(fieldNumber, value.get(i)); + } + } + + @Override + public void writeUInt32List(int fieldNumber, List value, boolean packed) + throws IOException { + if (packed) { + output.writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + + // Compute and write the length of the data. + int dataSize = 0; + for (int i = 0; i < value.size(); ++i) { + dataSize += CodedOutputStream.computeUInt32SizeNoTag(value.get(i)); + } + output.writeUInt32NoTag(dataSize); + + // Write the data itself, without any tags. + for (int i = 0; i < value.size(); ++i) { + output.writeUInt32NoTag(value.get(i)); + } + } else { + for (int i = 0; i < value.size(); ++i) { + output.writeUInt32(fieldNumber, value.get(i)); + } + } + } + + @Override + public void writeSFixed32List(int fieldNumber, List value, boolean packed) + throws IOException { + if (packed) { + output.writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + + // Compute and write the length of the data. + int dataSize = 0; + for (int i = 0; i < value.size(); ++i) { + dataSize += CodedOutputStream.computeSFixed32SizeNoTag(value.get(i)); + } + output.writeUInt32NoTag(dataSize); + + // Write the data itself, without any tags. + for (int i = 0; i < value.size(); ++i) { + output.writeSFixed32NoTag(value.get(i)); + } + } else { + for (int i = 0; i < value.size(); ++i) { + output.writeSFixed32(fieldNumber, value.get(i)); + } + } + } + + @Override + public void writeSFixed64List(int fieldNumber, List value, boolean packed) + throws IOException { + if (packed) { + output.writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + + // Compute and write the length of the data. + int dataSize = 0; + for (int i = 0; i < value.size(); ++i) { + dataSize += CodedOutputStream.computeSFixed64SizeNoTag(value.get(i)); + } + output.writeUInt32NoTag(dataSize); + + // Write the data itself, without any tags. + for (int i = 0; i < value.size(); ++i) { + output.writeSFixed64NoTag(value.get(i)); + } + } else { + for (int i = 0; i < value.size(); ++i) { + output.writeSFixed64(fieldNumber, value.get(i)); + } + } + } + + @Override + public void writeSInt32List(int fieldNumber, List value, boolean packed) + throws IOException { + if (packed) { + output.writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + + // Compute and write the length of the data. + int dataSize = 0; + for (int i = 0; i < value.size(); ++i) { + dataSize += CodedOutputStream.computeSInt32SizeNoTag(value.get(i)); + } + output.writeUInt32NoTag(dataSize); + + // Write the data itself, without any tags. + for (int i = 0; i < value.size(); ++i) { + output.writeSInt32NoTag(value.get(i)); + } + } else { + for (int i = 0; i < value.size(); ++i) { + output.writeSInt32(fieldNumber, value.get(i)); + } + } + } + + @Override + public void writeSInt64List(int fieldNumber, List value, boolean packed) + throws IOException { + if (packed) { + output.writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + + // Compute and write the length of the data. + int dataSize = 0; + for (int i = 0; i < value.size(); ++i) { + dataSize += CodedOutputStream.computeSInt64SizeNoTag(value.get(i)); + } + output.writeUInt32NoTag(dataSize); + + // Write the data itself, without any tags. + for (int i = 0; i < value.size(); ++i) { + output.writeSInt64NoTag(value.get(i)); + } + } else { + for (int i = 0; i < value.size(); ++i) { + output.writeSInt64(fieldNumber, value.get(i)); + } + } + } + + @Override + public void writeMessageList(int fieldNumber, List value) throws IOException { + for (int i = 0; i < value.size(); ++i) { + writeMessage(fieldNumber, value.get(i)); + } + } + + @Override + public void writeMessageList(int fieldNumber, List value, Schema schema) throws IOException { + for (int i = 0; i < value.size(); ++i) { + writeMessage(fieldNumber, value.get(i), schema); + } + } + + @Override + public void writeGroupList(int fieldNumber, List value) throws IOException { + for (int i = 0; i < value.size(); ++i) { + writeGroup(fieldNumber, value.get(i)); + } + } + + @Override + public void writeGroupList(int fieldNumber, List value, Schema schema) throws IOException { + for (int i = 0; i < value.size(); ++i) { + writeGroup(fieldNumber, value.get(i), schema); + } + } + + @Override + public void writeMap(int fieldNumber, MapEntryLite.Metadata metadata, Map map) + throws IOException { + if (output.isSerializationDeterministic()) { + writeDeterministicMap(fieldNumber, metadata, map); + return; + } + for (Map.Entry entry : map.entrySet()) { + output.writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + output.writeUInt32NoTag( + MapEntryLite.computeSerializedSize(metadata, entry.getKey(), entry.getValue())); + MapEntryLite.writeTo(output, metadata, entry.getKey(), entry.getValue()); + } + } + + @SuppressWarnings("unchecked") + private void writeDeterministicMap( + int fieldNumber, MapEntryLite.Metadata metadata, Map map) throws IOException { + switch (metadata.keyType) { + case BOOL: + V value; + if ((value = map.get(Boolean.FALSE)) != null) { + writeDeterministicBooleanMapEntry( + fieldNumber, /* key= */ false, value, (MapEntryLite.Metadata) metadata); + } + if ((value = map.get(Boolean.TRUE)) != null) { + writeDeterministicBooleanMapEntry( + fieldNumber, /* key= */ true, value, (MapEntryLite.Metadata) metadata); + } + break; + case FIXED32: + case INT32: + case SFIXED32: + case SINT32: + case UINT32: + writeDeterministicIntegerMap( + fieldNumber, (MapEntryLite.Metadata) metadata, (Map) map); + break; + case FIXED64: + case INT64: + case SFIXED64: + case SINT64: + case UINT64: + writeDeterministicLongMap( + fieldNumber, (MapEntryLite.Metadata) metadata, (Map) map); + break; + case STRING: + writeDeterministicStringMap( + fieldNumber, (MapEntryLite.Metadata) metadata, (Map) map); + break; + default: + throw new IllegalArgumentException("does not support key type: " + metadata.keyType); + } + } + + private void writeDeterministicBooleanMapEntry( + int fieldNumber, boolean key, V value, MapEntryLite.Metadata metadata) + throws IOException { + output.writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + output.writeUInt32NoTag(MapEntryLite.computeSerializedSize(metadata, key, value)); + MapEntryLite.writeTo(output, metadata, key, value); + } + + private void writeDeterministicIntegerMap( + int fieldNumber, MapEntryLite.Metadata metadata, Map map) + throws IOException { + int[] keys = new int[map.size()]; + int index = 0; + for (int k : map.keySet()) { + keys[index++] = k; + } + Arrays.sort(keys); + for (int key : keys) { + V value = map.get(key); + output.writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + output.writeUInt32NoTag(MapEntryLite.computeSerializedSize(metadata, key, value)); + MapEntryLite.writeTo(output, metadata, key, value); + } + } + + private void writeDeterministicLongMap( + int fieldNumber, MapEntryLite.Metadata metadata, Map map) + throws IOException { + long[] keys = new long[map.size()]; + int index = 0; + for (long k : map.keySet()) { + keys[index++] = k; + } + Arrays.sort(keys); + for (long key : keys) { + V value = map.get(key); + output.writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + output.writeUInt32NoTag(MapEntryLite.computeSerializedSize(metadata, key, value)); + MapEntryLite.writeTo(output, metadata, key, value); + } + } + + private void writeDeterministicStringMap( + int fieldNumber, MapEntryLite.Metadata metadata, Map map) + throws IOException { + String[] keys = new String[map.size()]; + int index = 0; + for (String k : map.keySet()) { + keys[index++] = k; + } + Arrays.sort(keys); + for (String key : keys) { + V value = map.get(key); + output.writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); + output.writeUInt32NoTag(MapEntryLite.computeSerializedSize(metadata, key, value)); + MapEntryLite.writeTo(output, metadata, key, value); + } + } +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/DoubleArrayList.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/DoubleArrayList.java new file mode 100644 index 0000000000000..408565343720d --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/DoubleArrayList.java @@ -0,0 +1,298 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +import static com.google.protobuf.Internal.checkNotNull; + +import com.google.protobuf.Internal.DoubleList; +import java.util.Arrays; +import java.util.Collection; +import java.util.RandomAccess; + +/** + * An implementation of {@link DoubleList} on top of a primitive array. + * + * @author dweis@google.com (Daniel Weis) + */ +final class DoubleArrayList extends AbstractProtobufList + implements DoubleList, RandomAccess, PrimitiveNonBoxingCollection { + + private static final DoubleArrayList EMPTY_LIST = new DoubleArrayList(new double[0], 0); + static { + EMPTY_LIST.makeImmutable(); + } + + public static DoubleArrayList emptyList() { + return EMPTY_LIST; + } + + /** The backing store for the list. */ + private double[] array; + + /** + * The size of the list distinct from the length of the array. That is, it is the number of + * elements set in the list. + */ + private int size; + + /** Constructs a new mutable {@code DoubleArrayList} with default capacity. */ + DoubleArrayList() { + this(new double[DEFAULT_CAPACITY], 0); + } + + /** + * Constructs a new mutable {@code DoubleArrayList} containing the same elements as {@code other}. + */ + private DoubleArrayList(double[] other, int size) { + array = other; + this.size = size; + } + + @Override + protected void removeRange(int fromIndex, int toIndex) { + ensureIsMutable(); + if (toIndex < fromIndex) { + throw new IndexOutOfBoundsException("toIndex < fromIndex"); + } + + System.arraycopy(array, toIndex, array, fromIndex, size - toIndex); + size -= (toIndex - fromIndex); + modCount++; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof DoubleArrayList)) { + return super.equals(o); + } + DoubleArrayList other = (DoubleArrayList) o; + if (size != other.size) { + return false; + } + + final double[] arr = other.array; + for (int i = 0; i < size; i++) { + if (Double.doubleToLongBits(array[i]) != Double.doubleToLongBits(arr[i])) { + return false; + } + } + + return true; + } + + @Override + public int hashCode() { + int result = 1; + for (int i = 0; i < size; i++) { + long bits = Double.doubleToLongBits(array[i]); + result = (31 * result) + Internal.hashLong(bits); + } + return result; + } + + @Override + public DoubleList mutableCopyWithCapacity(int capacity) { + if (capacity < size) { + throw new IllegalArgumentException(); + } + return new DoubleArrayList(Arrays.copyOf(array, capacity), size); + } + + @Override + public Double get(int index) { + return getDouble(index); + } + + @Override + public double getDouble(int index) { + ensureIndexInRange(index); + return array[index]; + } + + @Override + public int indexOf(Object element) { + if (!(element instanceof Double)) { + return -1; + } + double unboxedElement = (Double) element; + int numElems = size(); + for (int i = 0; i < numElems; i++) { + if (array[i] == unboxedElement) { + return i; + } + } + return -1; + } + + @Override + public boolean contains(Object element) { + return indexOf(element) != -1; + } + + @Override + public int size() { + return size; + } + + @Override + public Double set(int index, Double element) { + return setDouble(index, element); + } + + @Override + public double setDouble(int index, double element) { + ensureIsMutable(); + ensureIndexInRange(index); + double previousValue = array[index]; + array[index] = element; + return previousValue; + } + + @Override + public boolean add(Double element) { + addDouble(element); + return true; + } + + @Override + public void add(int index, Double element) { + addDouble(index, element); + } + + /** Like {@link #add(Double)} but more efficient in that it doesn't box the element. */ + @Override + public void addDouble(double element) { + ensureIsMutable(); + if (size == array.length) { + // Resize to 1.5x the size + int length = ((size * 3) / 2) + 1; + double[] newArray = new double[length]; + + System.arraycopy(array, 0, newArray, 0, size); + array = newArray; + } + + array[size++] = element; + } + + /** Like {@link #add(int, Double)} but more efficient in that it doesn't box the element. */ + private void addDouble(int index, double element) { + ensureIsMutable(); + if (index < 0 || index > size) { + throw new IndexOutOfBoundsException(makeOutOfBoundsExceptionMessage(index)); + } + + if (size < array.length) { + // Shift everything over to make room + System.arraycopy(array, index, array, index + 1, size - index); + } else { + // Resize to 1.5x the size + int length = ((size * 3) / 2) + 1; + double[] newArray = new double[length]; + + // Copy the first part directly + System.arraycopy(array, 0, newArray, 0, index); + + // Copy the rest shifted over by one to make room + System.arraycopy(array, index, newArray, index + 1, size - index); + array = newArray; + } + + array[index] = element; + size++; + modCount++; + } + + @Override + public boolean addAll(Collection collection) { + ensureIsMutable(); + + checkNotNull(collection); + + // We specialize when adding another DoubleArrayList to avoid boxing elements. + if (!(collection instanceof DoubleArrayList)) { + return super.addAll(collection); + } + + DoubleArrayList list = (DoubleArrayList) collection; + if (list.size == 0) { + return false; + } + + int overflow = Integer.MAX_VALUE - size; + if (overflow < list.size) { + // We can't actually represent a list this large. + throw new OutOfMemoryError(); + } + + int newSize = size + list.size; + if (newSize > array.length) { + array = Arrays.copyOf(array, newSize); + } + + System.arraycopy(list.array, 0, array, size, list.size); + size = newSize; + modCount++; + return true; + } + + @Override + public Double remove(int index) { + ensureIsMutable(); + ensureIndexInRange(index); + double value = array[index]; + if (index < size - 1) { + System.arraycopy(array, index + 1, array, index, size - index - 1); + } + size--; + modCount++; + return value; + } + + /** + * Ensures that the provided {@code index} is within the range of {@code [0, size]}. Throws an + * {@link IndexOutOfBoundsException} if it is not. + * + * @param index the index to verify is in range + */ + private void ensureIndexInRange(int index) { + if (index < 0 || index >= size) { + throw new IndexOutOfBoundsException(makeOutOfBoundsExceptionMessage(index)); + } + } + + private String makeOutOfBoundsExceptionMessage(int index) { + return "Index:" + index + ", Size:" + size; + } +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/DoubleValue.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/DoubleValue.java new file mode 100644 index 0000000000000..bf645825a3562 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/DoubleValue.java @@ -0,0 +1,276 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/wrappers.proto + +package com.google.protobuf; + +/** + *

+ * Wrapper message for `double`.
+ * The JSON representation for `DoubleValue` is JSON number.
+ * 
+ * + * Protobuf type {@code google.protobuf.DoubleValue} + */ +public final class DoubleValue extends + com.google.protobuf.GeneratedMessageLite< + DoubleValue, DoubleValue.Builder> implements + // @@protoc_insertion_point(message_implements:google.protobuf.DoubleValue) + DoubleValueOrBuilder { + private DoubleValue() { + } + public static final int VALUE_FIELD_NUMBER = 1; + private double value_; + /** + *
+   * The double value.
+   * 
+ * + * double value = 1; + * @return The value. + */ + @java.lang.Override + public double getValue() { + return value_; + } + /** + *
+   * The double value.
+   * 
+ * + * double value = 1; + * @param value The value to set. + */ + private void setValue(double value) { + + value_ = value; + } + /** + *
+   * The double value.
+   * 
+ * + * double value = 1; + */ + private void clearValue() { + + value_ = 0D; + } + + public static com.google.protobuf.DoubleValue parseFrom( + java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.DoubleValue parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.DoubleValue parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.DoubleValue parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.DoubleValue parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.DoubleValue parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.DoubleValue parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, 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.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, input, extensionRegistry); + } + public static com.google.protobuf.DoubleValue parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return parseDelimitedFrom(DEFAULT_INSTANCE, input); + } + public static com.google.protobuf.DoubleValue parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return parseDelimitedFrom(DEFAULT_INSTANCE, input, extensionRegistry); + } + public static com.google.protobuf.DoubleValue parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, 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.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, input, extensionRegistry); + } + + public static Builder newBuilder() { + return (Builder) DEFAULT_INSTANCE.createBuilder(); + } + public static Builder newBuilder(com.google.protobuf.DoubleValue prototype) { + return (Builder) DEFAULT_INSTANCE.createBuilder(prototype); + } + + /** + *
+   * Wrapper message for `double`.
+   * The JSON representation for `DoubleValue` is JSON number.
+   * 
+ * + * Protobuf type {@code google.protobuf.DoubleValue} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessageLite.Builder< + com.google.protobuf.DoubleValue, Builder> implements + // @@protoc_insertion_point(builder_implements:google.protobuf.DoubleValue) + com.google.protobuf.DoubleValueOrBuilder { + // Construct using com.google.protobuf.DoubleValue.newBuilder() + private Builder() { + super(DEFAULT_INSTANCE); + } + + + /** + *
+     * The double value.
+     * 
+ * + * double value = 1; + * @return The value. + */ + @java.lang.Override + public double getValue() { + return instance.getValue(); + } + /** + *
+     * The double value.
+     * 
+ * + * double value = 1; + * @param value The value to set. + * @return This builder for chaining. + */ + public Builder setValue(double value) { + copyOnWrite(); + instance.setValue(value); + return this; + } + /** + *
+     * The double value.
+     * 
+ * + * double value = 1; + * @return This builder for chaining. + */ + public Builder clearValue() { + copyOnWrite(); + instance.clearValue(); + return this; + } + + // @@protoc_insertion_point(builder_scope:google.protobuf.DoubleValue) + } + @java.lang.Override + @java.lang.SuppressWarnings({"unchecked", "fallthrough"}) + protected final java.lang.Object dynamicMethod( + com.google.protobuf.GeneratedMessageLite.MethodToInvoke method, + java.lang.Object arg0, java.lang.Object arg1) { + switch (method) { + case NEW_MUTABLE_INSTANCE: { + return new com.google.protobuf.DoubleValue(); + } + case NEW_BUILDER: { + return new Builder(); + } + case BUILD_MESSAGE_INFO: { + java.lang.Object[] objects = new java.lang.Object[] { + "value_", + }; + java.lang.String info = + "\u0000\u0001\u0000\u0000\u0001\u0001\u0001\u0000\u0000\u0000\u0001\u0000"; + return newMessageInfo(DEFAULT_INSTANCE, info, objects); + } + // fall through + case GET_DEFAULT_INSTANCE: { + return DEFAULT_INSTANCE; + } + case GET_PARSER: { + com.google.protobuf.Parser parser = PARSER; + if (parser == null) { + synchronized (com.google.protobuf.DoubleValue.class) { + parser = PARSER; + if (parser == null) { + parser = + new DefaultInstanceBasedParser( + DEFAULT_INSTANCE); + PARSER = parser; + } + } + } + return parser; + } + case GET_MEMOIZED_IS_INITIALIZED: { + return (byte) 1; + } + case SET_MEMOIZED_IS_INITIALIZED: { + return null; + } + } + throw new UnsupportedOperationException(); + } + + + // @@protoc_insertion_point(class_scope:google.protobuf.DoubleValue) + private static final com.google.protobuf.DoubleValue DEFAULT_INSTANCE; + static { + DoubleValue defaultInstance = new DoubleValue(); + // New instances are implicitly immutable so no need to make + // immutable. + DEFAULT_INSTANCE = defaultInstance; + com.google.protobuf.GeneratedMessageLite.registerDefaultInstance( + DoubleValue.class, defaultInstance); + } + + public static com.google.protobuf.DoubleValue getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + public static com.google.protobuf.DoubleValue of(double value) { + return newBuilder().setValue(value).build(); + } + + private static volatile com.google.protobuf.Parser PARSER; + + public static com.google.protobuf.Parser parser() { + return DEFAULT_INSTANCE.getParserForType(); + } +} + diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/DoubleValueOrBuilder.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/DoubleValueOrBuilder.java new file mode 100644 index 0000000000000..21562f483adab --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/DoubleValueOrBuilder.java @@ -0,0 +1,19 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/wrappers.proto + +package com.google.protobuf; + +public interface DoubleValueOrBuilder extends + // @@protoc_insertion_point(interface_extends:google.protobuf.DoubleValue) + com.google.protobuf.MessageLiteOrBuilder { + + /** + *
+   * The double value.
+   * 
+ * + * double value = 1; + * @return The value. + */ + double getValue(); +} diff --git a/java/core/src/main/kotlin/com/google/protobuf/DslList.kt b/java/kotlin-lite/target/generated-sources/com/google/protobuf/DslList.kt similarity index 100% rename from java/core/src/main/kotlin/com/google/protobuf/DslList.kt rename to java/kotlin-lite/target/generated-sources/com/google/protobuf/DslList.kt diff --git a/java/core/src/main/kotlin/com/google/protobuf/DslMap.kt b/java/kotlin-lite/target/generated-sources/com/google/protobuf/DslMap.kt similarity index 100% rename from java/core/src/main/kotlin/com/google/protobuf/DslMap.kt rename to java/kotlin-lite/target/generated-sources/com/google/protobuf/DslMap.kt diff --git a/java/core/src/main/kotlin/com/google/protobuf/DslProxy.kt b/java/kotlin-lite/target/generated-sources/com/google/protobuf/DslProxy.kt similarity index 100% rename from java/core/src/main/kotlin/com/google/protobuf/DslProxy.kt rename to java/kotlin-lite/target/generated-sources/com/google/protobuf/DslProxy.kt diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/Duration.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/Duration.java new file mode 100644 index 0000000000000..e59f2ad32b9a3 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/Duration.java @@ -0,0 +1,480 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/duration.proto + +package com.google.protobuf; + +/** + *
+ * A Duration represents a signed, fixed-length span of time represented
+ * as a count of seconds and fractions of seconds at nanosecond
+ * resolution. It is independent of any calendar and concepts like "day"
+ * or "month". It is related to Timestamp in that the difference between
+ * two Timestamp values is a Duration and it can be added or subtracted
+ * from a Timestamp. Range is approximately +-10,000 years.
+ * # Examples
+ * Example 1: Compute Duration from two Timestamps in pseudo code.
+ *     Timestamp start = ...;
+ *     Timestamp end = ...;
+ *     Duration duration = ...;
+ *     duration.seconds = end.seconds - start.seconds;
+ *     duration.nanos = end.nanos - start.nanos;
+ *     if (duration.seconds < 0 && duration.nanos > 0) {
+ *       duration.seconds += 1;
+ *       duration.nanos -= 1000000000;
+ *     } else if (duration.seconds > 0 && duration.nanos < 0) {
+ *       duration.seconds -= 1;
+ *       duration.nanos += 1000000000;
+ *     }
+ * Example 2: Compute Timestamp from Timestamp + Duration in pseudo code.
+ *     Timestamp start = ...;
+ *     Duration duration = ...;
+ *     Timestamp end = ...;
+ *     end.seconds = start.seconds + duration.seconds;
+ *     end.nanos = start.nanos + duration.nanos;
+ *     if (end.nanos < 0) {
+ *       end.seconds -= 1;
+ *       end.nanos += 1000000000;
+ *     } else if (end.nanos >= 1000000000) {
+ *       end.seconds += 1;
+ *       end.nanos -= 1000000000;
+ *     }
+ * Example 3: Compute Duration from datetime.timedelta in Python.
+ *     td = datetime.timedelta(days=3, minutes=10)
+ *     duration = Duration()
+ *     duration.FromTimedelta(td)
+ * # JSON Mapping
+ * In JSON format, the Duration type is encoded as a string rather than an
+ * object, where the string ends in the suffix "s" (indicating seconds) and
+ * is preceded by the number of seconds, with nanoseconds expressed as
+ * fractional seconds. For example, 3 seconds with 0 nanoseconds should be
+ * encoded in JSON format as "3s", while 3 seconds and 1 nanosecond should
+ * be expressed in JSON format as "3.000000001s", and 3 seconds and 1
+ * microsecond should be expressed in JSON format as "3.000001s".
+ * 
+ * + * Protobuf type {@code google.protobuf.Duration} + */ +public final class Duration extends + com.google.protobuf.GeneratedMessageLite< + Duration, Duration.Builder> implements + // @@protoc_insertion_point(message_implements:google.protobuf.Duration) + DurationOrBuilder { + private Duration() { + } + public static final int SECONDS_FIELD_NUMBER = 1; + private long seconds_; + /** + *
+   * Signed seconds of the span of time. Must be from -315,576,000,000
+   * to +315,576,000,000 inclusive. Note: these bounds are computed from:
+   * 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years
+   * 
+ * + * int64 seconds = 1; + * @return The seconds. + */ + @java.lang.Override + public long getSeconds() { + return seconds_; + } + /** + *
+   * Signed seconds of the span of time. Must be from -315,576,000,000
+   * to +315,576,000,000 inclusive. Note: these bounds are computed from:
+   * 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years
+   * 
+ * + * int64 seconds = 1; + * @param value The seconds to set. + */ + private void setSeconds(long value) { + + seconds_ = value; + } + /** + *
+   * Signed seconds of the span of time. Must be from -315,576,000,000
+   * to +315,576,000,000 inclusive. Note: these bounds are computed from:
+   * 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years
+   * 
+ * + * int64 seconds = 1; + */ + private void clearSeconds() { + + seconds_ = 0L; + } + + public static final int NANOS_FIELD_NUMBER = 2; + private int nanos_; + /** + *
+   * Signed fractions of a second at nanosecond resolution of the span
+   * of time. Durations less than one second are represented with a 0
+   * `seconds` field and a positive or negative `nanos` field. For durations
+   * of one second or more, a non-zero value for the `nanos` field must be
+   * of the same sign as the `seconds` field. Must be from -999,999,999
+   * to +999,999,999 inclusive.
+   * 
+ * + * int32 nanos = 2; + * @return The nanos. + */ + @java.lang.Override + public int getNanos() { + return nanos_; + } + /** + *
+   * Signed fractions of a second at nanosecond resolution of the span
+   * of time. Durations less than one second are represented with a 0
+   * `seconds` field and a positive or negative `nanos` field. For durations
+   * of one second or more, a non-zero value for the `nanos` field must be
+   * of the same sign as the `seconds` field. Must be from -999,999,999
+   * to +999,999,999 inclusive.
+   * 
+ * + * int32 nanos = 2; + * @param value The nanos to set. + */ + private void setNanos(int value) { + + nanos_ = value; + } + /** + *
+   * Signed fractions of a second at nanosecond resolution of the span
+   * of time. Durations less than one second are represented with a 0
+   * `seconds` field and a positive or negative `nanos` field. For durations
+   * of one second or more, a non-zero value for the `nanos` field must be
+   * of the same sign as the `seconds` field. Must be from -999,999,999
+   * to +999,999,999 inclusive.
+   * 
+ * + * int32 nanos = 2; + */ + private void clearNanos() { + + nanos_ = 0; + } + + public static com.google.protobuf.Duration parseFrom( + java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.Duration parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.Duration parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.Duration parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.Duration parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.Duration parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.Duration parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, 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.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, input, extensionRegistry); + } + public static com.google.protobuf.Duration parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return parseDelimitedFrom(DEFAULT_INSTANCE, input); + } + public static com.google.protobuf.Duration parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return parseDelimitedFrom(DEFAULT_INSTANCE, input, extensionRegistry); + } + public static com.google.protobuf.Duration parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, 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.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, input, extensionRegistry); + } + + public static Builder newBuilder() { + return (Builder) DEFAULT_INSTANCE.createBuilder(); + } + public static Builder newBuilder(com.google.protobuf.Duration prototype) { + return (Builder) DEFAULT_INSTANCE.createBuilder(prototype); + } + + /** + *
+   * A Duration represents a signed, fixed-length span of time represented
+   * as a count of seconds and fractions of seconds at nanosecond
+   * resolution. It is independent of any calendar and concepts like "day"
+   * or "month". It is related to Timestamp in that the difference between
+   * two Timestamp values is a Duration and it can be added or subtracted
+   * from a Timestamp. Range is approximately +-10,000 years.
+   * # Examples
+   * Example 1: Compute Duration from two Timestamps in pseudo code.
+   *     Timestamp start = ...;
+   *     Timestamp end = ...;
+   *     Duration duration = ...;
+   *     duration.seconds = end.seconds - start.seconds;
+   *     duration.nanos = end.nanos - start.nanos;
+   *     if (duration.seconds < 0 && duration.nanos > 0) {
+   *       duration.seconds += 1;
+   *       duration.nanos -= 1000000000;
+   *     } else if (duration.seconds > 0 && duration.nanos < 0) {
+   *       duration.seconds -= 1;
+   *       duration.nanos += 1000000000;
+   *     }
+   * Example 2: Compute Timestamp from Timestamp + Duration in pseudo code.
+   *     Timestamp start = ...;
+   *     Duration duration = ...;
+   *     Timestamp end = ...;
+   *     end.seconds = start.seconds + duration.seconds;
+   *     end.nanos = start.nanos + duration.nanos;
+   *     if (end.nanos < 0) {
+   *       end.seconds -= 1;
+   *       end.nanos += 1000000000;
+   *     } else if (end.nanos >= 1000000000) {
+   *       end.seconds += 1;
+   *       end.nanos -= 1000000000;
+   *     }
+   * Example 3: Compute Duration from datetime.timedelta in Python.
+   *     td = datetime.timedelta(days=3, minutes=10)
+   *     duration = Duration()
+   *     duration.FromTimedelta(td)
+   * # JSON Mapping
+   * In JSON format, the Duration type is encoded as a string rather than an
+   * object, where the string ends in the suffix "s" (indicating seconds) and
+   * is preceded by the number of seconds, with nanoseconds expressed as
+   * fractional seconds. For example, 3 seconds with 0 nanoseconds should be
+   * encoded in JSON format as "3s", while 3 seconds and 1 nanosecond should
+   * be expressed in JSON format as "3.000000001s", and 3 seconds and 1
+   * microsecond should be expressed in JSON format as "3.000001s".
+   * 
+ * + * Protobuf type {@code google.protobuf.Duration} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessageLite.Builder< + com.google.protobuf.Duration, Builder> implements + // @@protoc_insertion_point(builder_implements:google.protobuf.Duration) + com.google.protobuf.DurationOrBuilder { + // Construct using com.google.protobuf.Duration.newBuilder() + private Builder() { + super(DEFAULT_INSTANCE); + } + + + /** + *
+     * Signed seconds of the span of time. Must be from -315,576,000,000
+     * to +315,576,000,000 inclusive. Note: these bounds are computed from:
+     * 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years
+     * 
+ * + * int64 seconds = 1; + * @return The seconds. + */ + @java.lang.Override + public long getSeconds() { + return instance.getSeconds(); + } + /** + *
+     * Signed seconds of the span of time. Must be from -315,576,000,000
+     * to +315,576,000,000 inclusive. Note: these bounds are computed from:
+     * 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years
+     * 
+ * + * int64 seconds = 1; + * @param value The seconds to set. + * @return This builder for chaining. + */ + public Builder setSeconds(long value) { + copyOnWrite(); + instance.setSeconds(value); + return this; + } + /** + *
+     * Signed seconds of the span of time. Must be from -315,576,000,000
+     * to +315,576,000,000 inclusive. Note: these bounds are computed from:
+     * 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years
+     * 
+ * + * int64 seconds = 1; + * @return This builder for chaining. + */ + public Builder clearSeconds() { + copyOnWrite(); + instance.clearSeconds(); + return this; + } + + /** + *
+     * Signed fractions of a second at nanosecond resolution of the span
+     * of time. Durations less than one second are represented with a 0
+     * `seconds` field and a positive or negative `nanos` field. For durations
+     * of one second or more, a non-zero value for the `nanos` field must be
+     * of the same sign as the `seconds` field. Must be from -999,999,999
+     * to +999,999,999 inclusive.
+     * 
+ * + * int32 nanos = 2; + * @return The nanos. + */ + @java.lang.Override + public int getNanos() { + return instance.getNanos(); + } + /** + *
+     * Signed fractions of a second at nanosecond resolution of the span
+     * of time. Durations less than one second are represented with a 0
+     * `seconds` field and a positive or negative `nanos` field. For durations
+     * of one second or more, a non-zero value for the `nanos` field must be
+     * of the same sign as the `seconds` field. Must be from -999,999,999
+     * to +999,999,999 inclusive.
+     * 
+ * + * int32 nanos = 2; + * @param value The nanos to set. + * @return This builder for chaining. + */ + public Builder setNanos(int value) { + copyOnWrite(); + instance.setNanos(value); + return this; + } + /** + *
+     * Signed fractions of a second at nanosecond resolution of the span
+     * of time. Durations less than one second are represented with a 0
+     * `seconds` field and a positive or negative `nanos` field. For durations
+     * of one second or more, a non-zero value for the `nanos` field must be
+     * of the same sign as the `seconds` field. Must be from -999,999,999
+     * to +999,999,999 inclusive.
+     * 
+ * + * int32 nanos = 2; + * @return This builder for chaining. + */ + public Builder clearNanos() { + copyOnWrite(); + instance.clearNanos(); + return this; + } + + // @@protoc_insertion_point(builder_scope:google.protobuf.Duration) + } + @java.lang.Override + @java.lang.SuppressWarnings({"unchecked", "fallthrough"}) + protected final java.lang.Object dynamicMethod( + com.google.protobuf.GeneratedMessageLite.MethodToInvoke method, + java.lang.Object arg0, java.lang.Object arg1) { + switch (method) { + case NEW_MUTABLE_INSTANCE: { + return new com.google.protobuf.Duration(); + } + case NEW_BUILDER: { + return new Builder(); + } + case BUILD_MESSAGE_INFO: { + java.lang.Object[] objects = new java.lang.Object[] { + "seconds_", + "nanos_", + }; + java.lang.String info = + "\u0000\u0002\u0000\u0000\u0001\u0002\u0002\u0000\u0000\u0000\u0001\u0002\u0002\u0004" + + ""; + return newMessageInfo(DEFAULT_INSTANCE, info, objects); + } + // fall through + case GET_DEFAULT_INSTANCE: { + return DEFAULT_INSTANCE; + } + case GET_PARSER: { + com.google.protobuf.Parser parser = PARSER; + if (parser == null) { + synchronized (com.google.protobuf.Duration.class) { + parser = PARSER; + if (parser == null) { + parser = + new DefaultInstanceBasedParser( + DEFAULT_INSTANCE); + PARSER = parser; + } + } + } + return parser; + } + case GET_MEMOIZED_IS_INITIALIZED: { + return (byte) 1; + } + case SET_MEMOIZED_IS_INITIALIZED: { + return null; + } + } + throw new UnsupportedOperationException(); + } + + + // @@protoc_insertion_point(class_scope:google.protobuf.Duration) + private static final com.google.protobuf.Duration DEFAULT_INSTANCE; + static { + Duration defaultInstance = new Duration(); + // New instances are implicitly immutable so no need to make + // immutable. + DEFAULT_INSTANCE = defaultInstance; + com.google.protobuf.GeneratedMessageLite.registerDefaultInstance( + Duration.class, defaultInstance); + } + + public static com.google.protobuf.Duration getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static volatile com.google.protobuf.Parser PARSER; + + public static com.google.protobuf.Parser parser() { + return DEFAULT_INSTANCE.getParserForType(); + } +} + diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/DurationOrBuilder.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/DurationOrBuilder.java new file mode 100644 index 0000000000000..2716dcb98636c --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/DurationOrBuilder.java @@ -0,0 +1,36 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/duration.proto + +package com.google.protobuf; + +public interface DurationOrBuilder extends + // @@protoc_insertion_point(interface_extends:google.protobuf.Duration) + com.google.protobuf.MessageLiteOrBuilder { + + /** + *
+   * Signed seconds of the span of time. Must be from -315,576,000,000
+   * to +315,576,000,000 inclusive. Note: these bounds are computed from:
+   * 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years
+   * 
+ * + * int64 seconds = 1; + * @return The seconds. + */ + long getSeconds(); + + /** + *
+   * Signed fractions of a second at nanosecond resolution of the span
+   * of time. Durations less than one second are represented with a 0
+   * `seconds` field and a positive or negative `nanos` field. For durations
+   * of one second or more, a non-zero value for the `nanos` field must be
+   * of the same sign as the `seconds` field. Must be from -999,999,999
+   * to +999,999,999 inclusive.
+   * 
+ * + * int32 nanos = 2; + * @return The nanos. + */ + int getNanos(); +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/DurationProto.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/DurationProto.java new file mode 100644 index 0000000000000..dcdd86ae74183 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/DurationProto.java @@ -0,0 +1,16 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/duration.proto + +package com.google.protobuf; + +public final class DurationProto { + private DurationProto() {} + public static void registerAllExtensions( + com.google.protobuf.ExtensionRegistryLite registry) { + } + + static { + } + + // @@protoc_insertion_point(outer_class_scope) +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/Empty.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/Empty.java new file mode 100644 index 0000000000000..92f0834f70f77 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/Empty.java @@ -0,0 +1,201 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/empty.proto + +package com.google.protobuf; + +/** + *
+ * A generic empty message that you can re-use to avoid defining duplicated
+ * empty messages in your APIs. A typical example is to use it as the request
+ * or the response type of an API method. For instance:
+ *     service Foo {
+ *       rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty);
+ *     }
+ * The JSON representation for `Empty` is empty JSON object `{}`.
+ * 
+ * + * Protobuf type {@code google.protobuf.Empty} + */ +public final class Empty extends + com.google.protobuf.GeneratedMessageLite< + Empty, Empty.Builder> implements + // @@protoc_insertion_point(message_implements:google.protobuf.Empty) + EmptyOrBuilder { + private Empty() { + } + public static com.google.protobuf.Empty parseFrom( + java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.Empty parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.Empty parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.Empty parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.Empty parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.Empty parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.Empty parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, 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.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, input, extensionRegistry); + } + public static com.google.protobuf.Empty parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return parseDelimitedFrom(DEFAULT_INSTANCE, input); + } + public static com.google.protobuf.Empty parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return parseDelimitedFrom(DEFAULT_INSTANCE, input, extensionRegistry); + } + public static com.google.protobuf.Empty parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, 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.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, input, extensionRegistry); + } + + public static Builder newBuilder() { + return (Builder) DEFAULT_INSTANCE.createBuilder(); + } + public static Builder newBuilder(com.google.protobuf.Empty prototype) { + return (Builder) DEFAULT_INSTANCE.createBuilder(prototype); + } + + /** + *
+   * A generic empty message that you can re-use to avoid defining duplicated
+   * empty messages in your APIs. A typical example is to use it as the request
+   * or the response type of an API method. For instance:
+   *     service Foo {
+   *       rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty);
+   *     }
+   * The JSON representation for `Empty` is empty JSON object `{}`.
+   * 
+ * + * Protobuf type {@code google.protobuf.Empty} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessageLite.Builder< + com.google.protobuf.Empty, Builder> implements + // @@protoc_insertion_point(builder_implements:google.protobuf.Empty) + com.google.protobuf.EmptyOrBuilder { + // Construct using com.google.protobuf.Empty.newBuilder() + private Builder() { + super(DEFAULT_INSTANCE); + } + + + // @@protoc_insertion_point(builder_scope:google.protobuf.Empty) + } + @java.lang.Override + @java.lang.SuppressWarnings({"unchecked", "fallthrough"}) + protected final java.lang.Object dynamicMethod( + com.google.protobuf.GeneratedMessageLite.MethodToInvoke method, + java.lang.Object arg0, java.lang.Object arg1) { + switch (method) { + case NEW_MUTABLE_INSTANCE: { + return new com.google.protobuf.Empty(); + } + case NEW_BUILDER: { + return new Builder(); + } + case BUILD_MESSAGE_INFO: { + java.lang.Object[] objects = null;java.lang.String info = + "\u0000\u0000"; + return newMessageInfo(DEFAULT_INSTANCE, info, objects); + } + // fall through + case GET_DEFAULT_INSTANCE: { + return DEFAULT_INSTANCE; + } + case GET_PARSER: { + com.google.protobuf.Parser parser = PARSER; + if (parser == null) { + synchronized (com.google.protobuf.Empty.class) { + parser = PARSER; + if (parser == null) { + parser = + new DefaultInstanceBasedParser( + DEFAULT_INSTANCE); + PARSER = parser; + } + } + } + return parser; + } + case GET_MEMOIZED_IS_INITIALIZED: { + return (byte) 1; + } + case SET_MEMOIZED_IS_INITIALIZED: { + return null; + } + } + throw new UnsupportedOperationException(); + } + + + // @@protoc_insertion_point(class_scope:google.protobuf.Empty) + private static final com.google.protobuf.Empty DEFAULT_INSTANCE; + static { + Empty defaultInstance = new Empty(); + // New instances are implicitly immutable so no need to make + // immutable. + DEFAULT_INSTANCE = defaultInstance; + com.google.protobuf.GeneratedMessageLite.registerDefaultInstance( + Empty.class, defaultInstance); + } + + public static com.google.protobuf.Empty getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static volatile com.google.protobuf.Parser PARSER; + + public static com.google.protobuf.Parser parser() { + return DEFAULT_INSTANCE.getParserForType(); + } +} + diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/EmptyOrBuilder.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/EmptyOrBuilder.java new file mode 100644 index 0000000000000..f970a064c0ac3 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/EmptyOrBuilder.java @@ -0,0 +1,9 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/empty.proto + +package com.google.protobuf; + +public interface EmptyOrBuilder extends + // @@protoc_insertion_point(interface_extends:google.protobuf.Empty) + com.google.protobuf.MessageLiteOrBuilder { +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/EmptyProto.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/EmptyProto.java new file mode 100644 index 0000000000000..eeed3bea93169 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/EmptyProto.java @@ -0,0 +1,16 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/empty.proto + +package com.google.protobuf; + +public final class EmptyProto { + private EmptyProto() {} + public static void registerAllExtensions( + com.google.protobuf.ExtensionRegistryLite registry) { + } + + static { + } + + // @@protoc_insertion_point(outer_class_scope) +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/Enum.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/Enum.java new file mode 100644 index 0000000000000..79df3937df768 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/Enum.java @@ -0,0 +1,1179 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/type.proto + +package com.google.protobuf; + +/** + *
+ * Enum type definition.
+ * 
+ * + * Protobuf type {@code google.protobuf.Enum} + */ +public final class Enum extends + com.google.protobuf.GeneratedMessageLite< + Enum, Enum.Builder> implements + // @@protoc_insertion_point(message_implements:google.protobuf.Enum) + EnumOrBuilder { + private Enum() { + name_ = ""; + enumvalue_ = emptyProtobufList(); + options_ = emptyProtobufList(); + } + public static final int NAME_FIELD_NUMBER = 1; + private java.lang.String name_; + /** + *
+   * Enum type name.
+   * 
+ * + * string name = 1; + * @return The name. + */ + @java.lang.Override + public java.lang.String getName() { + return name_; + } + /** + *
+   * Enum type name.
+   * 
+ * + * string name = 1; + * @return The bytes for name. + */ + @java.lang.Override + public com.google.protobuf.ByteString + getNameBytes() { + return com.google.protobuf.ByteString.copyFromUtf8(name_); + } + /** + *
+   * Enum type name.
+   * 
+ * + * string name = 1; + * @param value The name to set. + */ + private void setName( + java.lang.String value) { + value.getClass(); + + name_ = value; + } + /** + *
+   * Enum type name.
+   * 
+ * + * string name = 1; + */ + private void clearName() { + + name_ = getDefaultInstance().getName(); + } + /** + *
+   * Enum type name.
+   * 
+ * + * string name = 1; + * @param value The bytes for name to set. + */ + private void setNameBytes( + com.google.protobuf.ByteString value) { + checkByteStringIsUtf8(value); + name_ = value.toStringUtf8(); + + } + + public static final int ENUMVALUE_FIELD_NUMBER = 2; + private com.google.protobuf.Internal.ProtobufList enumvalue_; + /** + *
+   * Enum value definitions.
+   * 
+ * + * repeated .google.protobuf.EnumValue enumvalue = 2; + */ + @java.lang.Override + public java.util.List getEnumvalueList() { + return enumvalue_; + } + /** + *
+   * Enum value definitions.
+   * 
+ * + * repeated .google.protobuf.EnumValue enumvalue = 2; + */ + public java.util.List + getEnumvalueOrBuilderList() { + return enumvalue_; + } + /** + *
+   * Enum value definitions.
+   * 
+ * + * repeated .google.protobuf.EnumValue enumvalue = 2; + */ + @java.lang.Override + public int getEnumvalueCount() { + return enumvalue_.size(); + } + /** + *
+   * Enum value definitions.
+   * 
+ * + * repeated .google.protobuf.EnumValue enumvalue = 2; + */ + @java.lang.Override + public com.google.protobuf.EnumValue getEnumvalue(int index) { + return enumvalue_.get(index); + } + /** + *
+   * Enum value definitions.
+   * 
+ * + * repeated .google.protobuf.EnumValue enumvalue = 2; + */ + public com.google.protobuf.EnumValueOrBuilder getEnumvalueOrBuilder( + int index) { + return enumvalue_.get(index); + } + private void ensureEnumvalueIsMutable() { + com.google.protobuf.Internal.ProtobufList tmp = enumvalue_; + if (!tmp.isModifiable()) { + enumvalue_ = + com.google.protobuf.GeneratedMessageLite.mutableCopy(tmp); + } + } + + /** + *
+   * Enum value definitions.
+   * 
+ * + * repeated .google.protobuf.EnumValue enumvalue = 2; + */ + private void setEnumvalue( + int index, com.google.protobuf.EnumValue value) { + value.getClass(); + ensureEnumvalueIsMutable(); + enumvalue_.set(index, value); + } + /** + *
+   * Enum value definitions.
+   * 
+ * + * repeated .google.protobuf.EnumValue enumvalue = 2; + */ + private void addEnumvalue(com.google.protobuf.EnumValue value) { + value.getClass(); + ensureEnumvalueIsMutable(); + enumvalue_.add(value); + } + /** + *
+   * Enum value definitions.
+   * 
+ * + * repeated .google.protobuf.EnumValue enumvalue = 2; + */ + private void addEnumvalue( + int index, com.google.protobuf.EnumValue value) { + value.getClass(); + ensureEnumvalueIsMutable(); + enumvalue_.add(index, value); + } + /** + *
+   * Enum value definitions.
+   * 
+ * + * repeated .google.protobuf.EnumValue enumvalue = 2; + */ + private void addAllEnumvalue( + java.lang.Iterable values) { + ensureEnumvalueIsMutable(); + com.google.protobuf.AbstractMessageLite.addAll( + values, enumvalue_); + } + /** + *
+   * Enum value definitions.
+   * 
+ * + * repeated .google.protobuf.EnumValue enumvalue = 2; + */ + private void clearEnumvalue() { + enumvalue_ = emptyProtobufList(); + } + /** + *
+   * Enum value definitions.
+   * 
+ * + * repeated .google.protobuf.EnumValue enumvalue = 2; + */ + private void removeEnumvalue(int index) { + ensureEnumvalueIsMutable(); + enumvalue_.remove(index); + } + + public static final int OPTIONS_FIELD_NUMBER = 3; + private com.google.protobuf.Internal.ProtobufList options_; + /** + *
+   * Protocol buffer options.
+   * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + @java.lang.Override + public java.util.List getOptionsList() { + return options_; + } + /** + *
+   * Protocol buffer options.
+   * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + public java.util.List + getOptionsOrBuilderList() { + return options_; + } + /** + *
+   * Protocol buffer options.
+   * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + @java.lang.Override + public int getOptionsCount() { + return options_.size(); + } + /** + *
+   * Protocol buffer options.
+   * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + @java.lang.Override + public com.google.protobuf.Option getOptions(int index) { + return options_.get(index); + } + /** + *
+   * Protocol buffer options.
+   * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + public com.google.protobuf.OptionOrBuilder getOptionsOrBuilder( + int index) { + return options_.get(index); + } + private void ensureOptionsIsMutable() { + com.google.protobuf.Internal.ProtobufList tmp = options_; + if (!tmp.isModifiable()) { + options_ = + com.google.protobuf.GeneratedMessageLite.mutableCopy(tmp); + } + } + + /** + *
+   * Protocol buffer options.
+   * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + private void setOptions( + int index, com.google.protobuf.Option value) { + value.getClass(); + ensureOptionsIsMutable(); + options_.set(index, value); + } + /** + *
+   * Protocol buffer options.
+   * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + private void addOptions(com.google.protobuf.Option value) { + value.getClass(); + ensureOptionsIsMutable(); + options_.add(value); + } + /** + *
+   * Protocol buffer options.
+   * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + private void addOptions( + int index, com.google.protobuf.Option value) { + value.getClass(); + ensureOptionsIsMutable(); + options_.add(index, value); + } + /** + *
+   * Protocol buffer options.
+   * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + private void addAllOptions( + java.lang.Iterable values) { + ensureOptionsIsMutable(); + com.google.protobuf.AbstractMessageLite.addAll( + values, options_); + } + /** + *
+   * Protocol buffer options.
+   * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + private void clearOptions() { + options_ = emptyProtobufList(); + } + /** + *
+   * Protocol buffer options.
+   * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + private void removeOptions(int index) { + ensureOptionsIsMutable(); + options_.remove(index); + } + + public static final int SOURCE_CONTEXT_FIELD_NUMBER = 4; + private com.google.protobuf.SourceContext sourceContext_; + /** + *
+   * The source context.
+   * 
+ * + * .google.protobuf.SourceContext source_context = 4; + */ + @java.lang.Override + public boolean hasSourceContext() { + return sourceContext_ != null; + } + /** + *
+   * The source context.
+   * 
+ * + * .google.protobuf.SourceContext source_context = 4; + */ + @java.lang.Override + public com.google.protobuf.SourceContext getSourceContext() { + return sourceContext_ == null ? com.google.protobuf.SourceContext.getDefaultInstance() : sourceContext_; + } + /** + *
+   * The source context.
+   * 
+ * + * .google.protobuf.SourceContext source_context = 4; + */ + private void setSourceContext(com.google.protobuf.SourceContext value) { + value.getClass(); + sourceContext_ = value; + + } + /** + *
+   * The source context.
+   * 
+ * + * .google.protobuf.SourceContext source_context = 4; + */ + @java.lang.SuppressWarnings({"ReferenceEquality"}) + private void mergeSourceContext(com.google.protobuf.SourceContext value) { + value.getClass(); + if (sourceContext_ != null && + sourceContext_ != com.google.protobuf.SourceContext.getDefaultInstance()) { + sourceContext_ = + com.google.protobuf.SourceContext.newBuilder(sourceContext_).mergeFrom(value).buildPartial(); + } else { + sourceContext_ = value; + } + + } + /** + *
+   * The source context.
+   * 
+ * + * .google.protobuf.SourceContext source_context = 4; + */ + private void clearSourceContext() { sourceContext_ = null; + + } + + public static final int SYNTAX_FIELD_NUMBER = 5; + private int syntax_; + /** + *
+   * The source syntax.
+   * 
+ * + * .google.protobuf.Syntax syntax = 5; + * @return The enum numeric value on the wire for syntax. + */ + @java.lang.Override + public int getSyntaxValue() { + return syntax_; + } + /** + *
+   * The source syntax.
+   * 
+ * + * .google.protobuf.Syntax syntax = 5; + * @return The syntax. + */ + @java.lang.Override + public com.google.protobuf.Syntax getSyntax() { + com.google.protobuf.Syntax result = com.google.protobuf.Syntax.forNumber(syntax_); + return result == null ? com.google.protobuf.Syntax.UNRECOGNIZED : result; + } + /** + *
+   * The source syntax.
+   * 
+ * + * .google.protobuf.Syntax syntax = 5; + * @param value The enum numeric value on the wire for syntax to set. + */ + private void setSyntaxValue(int value) { + syntax_ = value; + } + /** + *
+   * The source syntax.
+   * 
+ * + * .google.protobuf.Syntax syntax = 5; + * @param value The syntax to set. + */ + private void setSyntax(com.google.protobuf.Syntax value) { + syntax_ = value.getNumber(); + + } + /** + *
+   * The source syntax.
+   * 
+ * + * .google.protobuf.Syntax syntax = 5; + */ + private void clearSyntax() { + + syntax_ = 0; + } + + public static com.google.protobuf.Enum parseFrom( + java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.Enum parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.Enum parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.Enum parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.Enum parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.Enum parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.Enum parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, 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.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, input, extensionRegistry); + } + public static com.google.protobuf.Enum parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return parseDelimitedFrom(DEFAULT_INSTANCE, input); + } + public static com.google.protobuf.Enum parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return parseDelimitedFrom(DEFAULT_INSTANCE, input, extensionRegistry); + } + public static com.google.protobuf.Enum parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, 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.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, input, extensionRegistry); + } + + public static Builder newBuilder() { + return (Builder) DEFAULT_INSTANCE.createBuilder(); + } + public static Builder newBuilder(com.google.protobuf.Enum prototype) { + return (Builder) DEFAULT_INSTANCE.createBuilder(prototype); + } + + /** + *
+   * Enum type definition.
+   * 
+ * + * Protobuf type {@code google.protobuf.Enum} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessageLite.Builder< + com.google.protobuf.Enum, Builder> implements + // @@protoc_insertion_point(builder_implements:google.protobuf.Enum) + com.google.protobuf.EnumOrBuilder { + // Construct using com.google.protobuf.Enum.newBuilder() + private Builder() { + super(DEFAULT_INSTANCE); + } + + + /** + *
+     * Enum type name.
+     * 
+ * + * string name = 1; + * @return The name. + */ + @java.lang.Override + public java.lang.String getName() { + return instance.getName(); + } + /** + *
+     * Enum type name.
+     * 
+ * + * string name = 1; + * @return The bytes for name. + */ + @java.lang.Override + public com.google.protobuf.ByteString + getNameBytes() { + return instance.getNameBytes(); + } + /** + *
+     * Enum type name.
+     * 
+ * + * string name = 1; + * @param value The name to set. + * @return This builder for chaining. + */ + public Builder setName( + java.lang.String value) { + copyOnWrite(); + instance.setName(value); + return this; + } + /** + *
+     * Enum type name.
+     * 
+ * + * string name = 1; + * @return This builder for chaining. + */ + public Builder clearName() { + copyOnWrite(); + instance.clearName(); + return this; + } + /** + *
+     * Enum type name.
+     * 
+ * + * string name = 1; + * @param value The bytes for name to set. + * @return This builder for chaining. + */ + public Builder setNameBytes( + com.google.protobuf.ByteString value) { + copyOnWrite(); + instance.setNameBytes(value); + return this; + } + + /** + *
+     * Enum value definitions.
+     * 
+ * + * repeated .google.protobuf.EnumValue enumvalue = 2; + */ + @java.lang.Override + public java.util.List getEnumvalueList() { + return java.util.Collections.unmodifiableList( + instance.getEnumvalueList()); + } + /** + *
+     * Enum value definitions.
+     * 
+ * + * repeated .google.protobuf.EnumValue enumvalue = 2; + */ + @java.lang.Override + public int getEnumvalueCount() { + return instance.getEnumvalueCount(); + }/** + *
+     * Enum value definitions.
+     * 
+ * + * repeated .google.protobuf.EnumValue enumvalue = 2; + */ + @java.lang.Override + public com.google.protobuf.EnumValue getEnumvalue(int index) { + return instance.getEnumvalue(index); + } + /** + *
+     * Enum value definitions.
+     * 
+ * + * repeated .google.protobuf.EnumValue enumvalue = 2; + */ + public Builder setEnumvalue( + int index, com.google.protobuf.EnumValue value) { + copyOnWrite(); + instance.setEnumvalue(index, value); + return this; + } + /** + *
+     * Enum value definitions.
+     * 
+ * + * repeated .google.protobuf.EnumValue enumvalue = 2; + */ + public Builder setEnumvalue( + int index, com.google.protobuf.EnumValue.Builder builderForValue) { + copyOnWrite(); + instance.setEnumvalue(index, + builderForValue.build()); + return this; + } + /** + *
+     * Enum value definitions.
+     * 
+ * + * repeated .google.protobuf.EnumValue enumvalue = 2; + */ + public Builder addEnumvalue(com.google.protobuf.EnumValue value) { + copyOnWrite(); + instance.addEnumvalue(value); + return this; + } + /** + *
+     * Enum value definitions.
+     * 
+ * + * repeated .google.protobuf.EnumValue enumvalue = 2; + */ + public Builder addEnumvalue( + int index, com.google.protobuf.EnumValue value) { + copyOnWrite(); + instance.addEnumvalue(index, value); + return this; + } + /** + *
+     * Enum value definitions.
+     * 
+ * + * repeated .google.protobuf.EnumValue enumvalue = 2; + */ + public Builder addEnumvalue( + com.google.protobuf.EnumValue.Builder builderForValue) { + copyOnWrite(); + instance.addEnumvalue(builderForValue.build()); + return this; + } + /** + *
+     * Enum value definitions.
+     * 
+ * + * repeated .google.protobuf.EnumValue enumvalue = 2; + */ + public Builder addEnumvalue( + int index, com.google.protobuf.EnumValue.Builder builderForValue) { + copyOnWrite(); + instance.addEnumvalue(index, + builderForValue.build()); + return this; + } + /** + *
+     * Enum value definitions.
+     * 
+ * + * repeated .google.protobuf.EnumValue enumvalue = 2; + */ + public Builder addAllEnumvalue( + java.lang.Iterable values) { + copyOnWrite(); + instance.addAllEnumvalue(values); + return this; + } + /** + *
+     * Enum value definitions.
+     * 
+ * + * repeated .google.protobuf.EnumValue enumvalue = 2; + */ + public Builder clearEnumvalue() { + copyOnWrite(); + instance.clearEnumvalue(); + return this; + } + /** + *
+     * Enum value definitions.
+     * 
+ * + * repeated .google.protobuf.EnumValue enumvalue = 2; + */ + public Builder removeEnumvalue(int index) { + copyOnWrite(); + instance.removeEnumvalue(index); + return this; + } + + /** + *
+     * Protocol buffer options.
+     * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + @java.lang.Override + public java.util.List getOptionsList() { + return java.util.Collections.unmodifiableList( + instance.getOptionsList()); + } + /** + *
+     * Protocol buffer options.
+     * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + @java.lang.Override + public int getOptionsCount() { + return instance.getOptionsCount(); + }/** + *
+     * Protocol buffer options.
+     * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + @java.lang.Override + public com.google.protobuf.Option getOptions(int index) { + return instance.getOptions(index); + } + /** + *
+     * Protocol buffer options.
+     * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + public Builder setOptions( + int index, com.google.protobuf.Option value) { + copyOnWrite(); + instance.setOptions(index, value); + return this; + } + /** + *
+     * Protocol buffer options.
+     * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + public Builder setOptions( + int index, com.google.protobuf.Option.Builder builderForValue) { + copyOnWrite(); + instance.setOptions(index, + builderForValue.build()); + return this; + } + /** + *
+     * Protocol buffer options.
+     * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + public Builder addOptions(com.google.protobuf.Option value) { + copyOnWrite(); + instance.addOptions(value); + return this; + } + /** + *
+     * Protocol buffer options.
+     * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + public Builder addOptions( + int index, com.google.protobuf.Option value) { + copyOnWrite(); + instance.addOptions(index, value); + return this; + } + /** + *
+     * Protocol buffer options.
+     * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + public Builder addOptions( + com.google.protobuf.Option.Builder builderForValue) { + copyOnWrite(); + instance.addOptions(builderForValue.build()); + return this; + } + /** + *
+     * Protocol buffer options.
+     * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + public Builder addOptions( + int index, com.google.protobuf.Option.Builder builderForValue) { + copyOnWrite(); + instance.addOptions(index, + builderForValue.build()); + return this; + } + /** + *
+     * Protocol buffer options.
+     * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + public Builder addAllOptions( + java.lang.Iterable values) { + copyOnWrite(); + instance.addAllOptions(values); + return this; + } + /** + *
+     * Protocol buffer options.
+     * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + public Builder clearOptions() { + copyOnWrite(); + instance.clearOptions(); + return this; + } + /** + *
+     * Protocol buffer options.
+     * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + public Builder removeOptions(int index) { + copyOnWrite(); + instance.removeOptions(index); + return this; + } + + /** + *
+     * The source context.
+     * 
+ * + * .google.protobuf.SourceContext source_context = 4; + */ + @java.lang.Override + public boolean hasSourceContext() { + return instance.hasSourceContext(); + } + /** + *
+     * The source context.
+     * 
+ * + * .google.protobuf.SourceContext source_context = 4; + */ + @java.lang.Override + public com.google.protobuf.SourceContext getSourceContext() { + return instance.getSourceContext(); + } + /** + *
+     * The source context.
+     * 
+ * + * .google.protobuf.SourceContext source_context = 4; + */ + public Builder setSourceContext(com.google.protobuf.SourceContext value) { + copyOnWrite(); + instance.setSourceContext(value); + return this; + } + /** + *
+     * The source context.
+     * 
+ * + * .google.protobuf.SourceContext source_context = 4; + */ + public Builder setSourceContext( + com.google.protobuf.SourceContext.Builder builderForValue) { + copyOnWrite(); + instance.setSourceContext(builderForValue.build()); + return this; + } + /** + *
+     * The source context.
+     * 
+ * + * .google.protobuf.SourceContext source_context = 4; + */ + public Builder mergeSourceContext(com.google.protobuf.SourceContext value) { + copyOnWrite(); + instance.mergeSourceContext(value); + return this; + } + /** + *
+     * The source context.
+     * 
+ * + * .google.protobuf.SourceContext source_context = 4; + */ + public Builder clearSourceContext() { copyOnWrite(); + instance.clearSourceContext(); + return this; + } + + /** + *
+     * The source syntax.
+     * 
+ * + * .google.protobuf.Syntax syntax = 5; + * @return The enum numeric value on the wire for syntax. + */ + @java.lang.Override + public int getSyntaxValue() { + return instance.getSyntaxValue(); + } + /** + *
+     * The source syntax.
+     * 
+ * + * .google.protobuf.Syntax syntax = 5; + * @param value The syntax to set. + * @return This builder for chaining. + */ + public Builder setSyntaxValue(int value) { + copyOnWrite(); + instance.setSyntaxValue(value); + return this; + } + /** + *
+     * The source syntax.
+     * 
+ * + * .google.protobuf.Syntax syntax = 5; + * @return The syntax. + */ + @java.lang.Override + public com.google.protobuf.Syntax getSyntax() { + return instance.getSyntax(); + } + /** + *
+     * The source syntax.
+     * 
+ * + * .google.protobuf.Syntax syntax = 5; + * @param value The enum numeric value on the wire for syntax to set. + * @return This builder for chaining. + */ + public Builder setSyntax(com.google.protobuf.Syntax value) { + copyOnWrite(); + instance.setSyntax(value); + return this; + } + /** + *
+     * The source syntax.
+     * 
+ * + * .google.protobuf.Syntax syntax = 5; + * @return This builder for chaining. + */ + public Builder clearSyntax() { + copyOnWrite(); + instance.clearSyntax(); + return this; + } + + // @@protoc_insertion_point(builder_scope:google.protobuf.Enum) + } + @java.lang.Override + @java.lang.SuppressWarnings({"unchecked", "fallthrough"}) + protected final java.lang.Object dynamicMethod( + com.google.protobuf.GeneratedMessageLite.MethodToInvoke method, + java.lang.Object arg0, java.lang.Object arg1) { + switch (method) { + case NEW_MUTABLE_INSTANCE: { + return new com.google.protobuf.Enum(); + } + case NEW_BUILDER: { + return new Builder(); + } + case BUILD_MESSAGE_INFO: { + java.lang.Object[] objects = new java.lang.Object[] { + "name_", + "enumvalue_", + com.google.protobuf.EnumValue.class, + "options_", + com.google.protobuf.Option.class, + "sourceContext_", + "syntax_", + }; + java.lang.String info = + "\u0000\u0005\u0000\u0000\u0001\u0005\u0005\u0000\u0002\u0000\u0001\u0208\u0002\u001b" + + "\u0003\u001b\u0004\t\u0005\f"; + return newMessageInfo(DEFAULT_INSTANCE, info, objects); + } + // fall through + case GET_DEFAULT_INSTANCE: { + return DEFAULT_INSTANCE; + } + case GET_PARSER: { + com.google.protobuf.Parser parser = PARSER; + if (parser == null) { + synchronized (com.google.protobuf.Enum.class) { + parser = PARSER; + if (parser == null) { + parser = + new DefaultInstanceBasedParser( + DEFAULT_INSTANCE); + PARSER = parser; + } + } + } + return parser; + } + case GET_MEMOIZED_IS_INITIALIZED: { + return (byte) 1; + } + case SET_MEMOIZED_IS_INITIALIZED: { + return null; + } + } + throw new UnsupportedOperationException(); + } + + + // @@protoc_insertion_point(class_scope:google.protobuf.Enum) + private static final com.google.protobuf.Enum DEFAULT_INSTANCE; + static { + Enum defaultInstance = new Enum(); + // New instances are implicitly immutable so no need to make + // immutable. + DEFAULT_INSTANCE = defaultInstance; + com.google.protobuf.GeneratedMessageLite.registerDefaultInstance( + Enum.class, defaultInstance); + } + + public static com.google.protobuf.Enum getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static volatile com.google.protobuf.Parser PARSER; + + public static com.google.protobuf.Parser parser() { + return DEFAULT_INSTANCE.getParserForType(); + } +} + diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/EnumOrBuilder.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/EnumOrBuilder.java new file mode 100644 index 0000000000000..80fa317aad9d3 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/EnumOrBuilder.java @@ -0,0 +1,119 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/type.proto + +package com.google.protobuf; + +public interface EnumOrBuilder extends + // @@protoc_insertion_point(interface_extends:google.protobuf.Enum) + com.google.protobuf.MessageLiteOrBuilder { + + /** + *
+   * Enum type name.
+   * 
+ * + * string name = 1; + * @return The name. + */ + java.lang.String getName(); + /** + *
+   * Enum type name.
+   * 
+ * + * string name = 1; + * @return The bytes for name. + */ + com.google.protobuf.ByteString + getNameBytes(); + + /** + *
+   * Enum value definitions.
+   * 
+ * + * repeated .google.protobuf.EnumValue enumvalue = 2; + */ + java.util.List + getEnumvalueList(); + /** + *
+   * Enum value definitions.
+   * 
+ * + * repeated .google.protobuf.EnumValue enumvalue = 2; + */ + com.google.protobuf.EnumValue getEnumvalue(int index); + /** + *
+   * Enum value definitions.
+   * 
+ * + * repeated .google.protobuf.EnumValue enumvalue = 2; + */ + int getEnumvalueCount(); + + /** + *
+   * Protocol buffer options.
+   * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + java.util.List + getOptionsList(); + /** + *
+   * Protocol buffer options.
+   * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + com.google.protobuf.Option getOptions(int index); + /** + *
+   * Protocol buffer options.
+   * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + int getOptionsCount(); + + /** + *
+   * The source context.
+   * 
+ * + * .google.protobuf.SourceContext source_context = 4; + * @return Whether the sourceContext field is set. + */ + boolean hasSourceContext(); + /** + *
+   * The source context.
+   * 
+ * + * .google.protobuf.SourceContext source_context = 4; + * @return The sourceContext. + */ + com.google.protobuf.SourceContext getSourceContext(); + + /** + *
+   * The source syntax.
+   * 
+ * + * .google.protobuf.Syntax syntax = 5; + * @return The enum numeric value on the wire for syntax. + */ + int getSyntaxValue(); + /** + *
+   * The source syntax.
+   * 
+ * + * .google.protobuf.Syntax syntax = 5; + * @return The syntax. + */ + com.google.protobuf.Syntax getSyntax(); +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/EnumValue.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/EnumValue.java new file mode 100644 index 0000000000000..2b278877f91fb --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/EnumValue.java @@ -0,0 +1,700 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/type.proto + +package com.google.protobuf; + +/** + *
+ * Enum value definition.
+ * 
+ * + * Protobuf type {@code google.protobuf.EnumValue} + */ +public final class EnumValue extends + com.google.protobuf.GeneratedMessageLite< + EnumValue, EnumValue.Builder> implements + // @@protoc_insertion_point(message_implements:google.protobuf.EnumValue) + EnumValueOrBuilder { + private EnumValue() { + name_ = ""; + options_ = emptyProtobufList(); + } + public static final int NAME_FIELD_NUMBER = 1; + private java.lang.String name_; + /** + *
+   * Enum value name.
+   * 
+ * + * string name = 1; + * @return The name. + */ + @java.lang.Override + public java.lang.String getName() { + return name_; + } + /** + *
+   * Enum value name.
+   * 
+ * + * string name = 1; + * @return The bytes for name. + */ + @java.lang.Override + public com.google.protobuf.ByteString + getNameBytes() { + return com.google.protobuf.ByteString.copyFromUtf8(name_); + } + /** + *
+   * Enum value name.
+   * 
+ * + * string name = 1; + * @param value The name to set. + */ + private void setName( + java.lang.String value) { + value.getClass(); + + name_ = value; + } + /** + *
+   * Enum value name.
+   * 
+ * + * string name = 1; + */ + private void clearName() { + + name_ = getDefaultInstance().getName(); + } + /** + *
+   * Enum value name.
+   * 
+ * + * string name = 1; + * @param value The bytes for name to set. + */ + private void setNameBytes( + com.google.protobuf.ByteString value) { + checkByteStringIsUtf8(value); + name_ = value.toStringUtf8(); + + } + + public static final int NUMBER_FIELD_NUMBER = 2; + private int number_; + /** + *
+   * Enum value number.
+   * 
+ * + * int32 number = 2; + * @return The number. + */ + @java.lang.Override + public int getNumber() { + return number_; + } + /** + *
+   * Enum value number.
+   * 
+ * + * int32 number = 2; + * @param value The number to set. + */ + private void setNumber(int value) { + + number_ = value; + } + /** + *
+   * Enum value number.
+   * 
+ * + * int32 number = 2; + */ + private void clearNumber() { + + number_ = 0; + } + + public static final int OPTIONS_FIELD_NUMBER = 3; + private com.google.protobuf.Internal.ProtobufList options_; + /** + *
+   * Protocol buffer options.
+   * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + @java.lang.Override + public java.util.List getOptionsList() { + return options_; + } + /** + *
+   * Protocol buffer options.
+   * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + public java.util.List + getOptionsOrBuilderList() { + return options_; + } + /** + *
+   * Protocol buffer options.
+   * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + @java.lang.Override + public int getOptionsCount() { + return options_.size(); + } + /** + *
+   * Protocol buffer options.
+   * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + @java.lang.Override + public com.google.protobuf.Option getOptions(int index) { + return options_.get(index); + } + /** + *
+   * Protocol buffer options.
+   * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + public com.google.protobuf.OptionOrBuilder getOptionsOrBuilder( + int index) { + return options_.get(index); + } + private void ensureOptionsIsMutable() { + com.google.protobuf.Internal.ProtobufList tmp = options_; + if (!tmp.isModifiable()) { + options_ = + com.google.protobuf.GeneratedMessageLite.mutableCopy(tmp); + } + } + + /** + *
+   * Protocol buffer options.
+   * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + private void setOptions( + int index, com.google.protobuf.Option value) { + value.getClass(); + ensureOptionsIsMutable(); + options_.set(index, value); + } + /** + *
+   * Protocol buffer options.
+   * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + private void addOptions(com.google.protobuf.Option value) { + value.getClass(); + ensureOptionsIsMutable(); + options_.add(value); + } + /** + *
+   * Protocol buffer options.
+   * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + private void addOptions( + int index, com.google.protobuf.Option value) { + value.getClass(); + ensureOptionsIsMutable(); + options_.add(index, value); + } + /** + *
+   * Protocol buffer options.
+   * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + private void addAllOptions( + java.lang.Iterable values) { + ensureOptionsIsMutable(); + com.google.protobuf.AbstractMessageLite.addAll( + values, options_); + } + /** + *
+   * Protocol buffer options.
+   * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + private void clearOptions() { + options_ = emptyProtobufList(); + } + /** + *
+   * Protocol buffer options.
+   * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + private void removeOptions(int index) { + ensureOptionsIsMutable(); + options_.remove(index); + } + + public static com.google.protobuf.EnumValue parseFrom( + java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.EnumValue parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.EnumValue parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.EnumValue parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.EnumValue parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.EnumValue parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.EnumValue parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, 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.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, input, extensionRegistry); + } + public static com.google.protobuf.EnumValue parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return parseDelimitedFrom(DEFAULT_INSTANCE, input); + } + public static com.google.protobuf.EnumValue parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return parseDelimitedFrom(DEFAULT_INSTANCE, input, extensionRegistry); + } + public static com.google.protobuf.EnumValue parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, 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.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, input, extensionRegistry); + } + + public static Builder newBuilder() { + return (Builder) DEFAULT_INSTANCE.createBuilder(); + } + public static Builder newBuilder(com.google.protobuf.EnumValue prototype) { + return (Builder) DEFAULT_INSTANCE.createBuilder(prototype); + } + + /** + *
+   * Enum value definition.
+   * 
+ * + * Protobuf type {@code google.protobuf.EnumValue} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessageLite.Builder< + com.google.protobuf.EnumValue, Builder> implements + // @@protoc_insertion_point(builder_implements:google.protobuf.EnumValue) + com.google.protobuf.EnumValueOrBuilder { + // Construct using com.google.protobuf.EnumValue.newBuilder() + private Builder() { + super(DEFAULT_INSTANCE); + } + + + /** + *
+     * Enum value name.
+     * 
+ * + * string name = 1; + * @return The name. + */ + @java.lang.Override + public java.lang.String getName() { + return instance.getName(); + } + /** + *
+     * Enum value name.
+     * 
+ * + * string name = 1; + * @return The bytes for name. + */ + @java.lang.Override + public com.google.protobuf.ByteString + getNameBytes() { + return instance.getNameBytes(); + } + /** + *
+     * Enum value name.
+     * 
+ * + * string name = 1; + * @param value The name to set. + * @return This builder for chaining. + */ + public Builder setName( + java.lang.String value) { + copyOnWrite(); + instance.setName(value); + return this; + } + /** + *
+     * Enum value name.
+     * 
+ * + * string name = 1; + * @return This builder for chaining. + */ + public Builder clearName() { + copyOnWrite(); + instance.clearName(); + return this; + } + /** + *
+     * Enum value name.
+     * 
+ * + * string name = 1; + * @param value The bytes for name to set. + * @return This builder for chaining. + */ + public Builder setNameBytes( + com.google.protobuf.ByteString value) { + copyOnWrite(); + instance.setNameBytes(value); + return this; + } + + /** + *
+     * Enum value number.
+     * 
+ * + * int32 number = 2; + * @return The number. + */ + @java.lang.Override + public int getNumber() { + return instance.getNumber(); + } + /** + *
+     * Enum value number.
+     * 
+ * + * int32 number = 2; + * @param value The number to set. + * @return This builder for chaining. + */ + public Builder setNumber(int value) { + copyOnWrite(); + instance.setNumber(value); + return this; + } + /** + *
+     * Enum value number.
+     * 
+ * + * int32 number = 2; + * @return This builder for chaining. + */ + public Builder clearNumber() { + copyOnWrite(); + instance.clearNumber(); + return this; + } + + /** + *
+     * Protocol buffer options.
+     * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + @java.lang.Override + public java.util.List getOptionsList() { + return java.util.Collections.unmodifiableList( + instance.getOptionsList()); + } + /** + *
+     * Protocol buffer options.
+     * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + @java.lang.Override + public int getOptionsCount() { + return instance.getOptionsCount(); + }/** + *
+     * Protocol buffer options.
+     * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + @java.lang.Override + public com.google.protobuf.Option getOptions(int index) { + return instance.getOptions(index); + } + /** + *
+     * Protocol buffer options.
+     * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + public Builder setOptions( + int index, com.google.protobuf.Option value) { + copyOnWrite(); + instance.setOptions(index, value); + return this; + } + /** + *
+     * Protocol buffer options.
+     * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + public Builder setOptions( + int index, com.google.protobuf.Option.Builder builderForValue) { + copyOnWrite(); + instance.setOptions(index, + builderForValue.build()); + return this; + } + /** + *
+     * Protocol buffer options.
+     * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + public Builder addOptions(com.google.protobuf.Option value) { + copyOnWrite(); + instance.addOptions(value); + return this; + } + /** + *
+     * Protocol buffer options.
+     * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + public Builder addOptions( + int index, com.google.protobuf.Option value) { + copyOnWrite(); + instance.addOptions(index, value); + return this; + } + /** + *
+     * Protocol buffer options.
+     * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + public Builder addOptions( + com.google.protobuf.Option.Builder builderForValue) { + copyOnWrite(); + instance.addOptions(builderForValue.build()); + return this; + } + /** + *
+     * Protocol buffer options.
+     * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + public Builder addOptions( + int index, com.google.protobuf.Option.Builder builderForValue) { + copyOnWrite(); + instance.addOptions(index, + builderForValue.build()); + return this; + } + /** + *
+     * Protocol buffer options.
+     * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + public Builder addAllOptions( + java.lang.Iterable values) { + copyOnWrite(); + instance.addAllOptions(values); + return this; + } + /** + *
+     * Protocol buffer options.
+     * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + public Builder clearOptions() { + copyOnWrite(); + instance.clearOptions(); + return this; + } + /** + *
+     * Protocol buffer options.
+     * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + public Builder removeOptions(int index) { + copyOnWrite(); + instance.removeOptions(index); + return this; + } + + // @@protoc_insertion_point(builder_scope:google.protobuf.EnumValue) + } + @java.lang.Override + @java.lang.SuppressWarnings({"unchecked", "fallthrough"}) + protected final java.lang.Object dynamicMethod( + com.google.protobuf.GeneratedMessageLite.MethodToInvoke method, + java.lang.Object arg0, java.lang.Object arg1) { + switch (method) { + case NEW_MUTABLE_INSTANCE: { + return new com.google.protobuf.EnumValue(); + } + case NEW_BUILDER: { + return new Builder(); + } + case BUILD_MESSAGE_INFO: { + java.lang.Object[] objects = new java.lang.Object[] { + "name_", + "number_", + "options_", + com.google.protobuf.Option.class, + }; + java.lang.String info = + "\u0000\u0003\u0000\u0000\u0001\u0003\u0003\u0000\u0001\u0000\u0001\u0208\u0002\u0004" + + "\u0003\u001b"; + return newMessageInfo(DEFAULT_INSTANCE, info, objects); + } + // fall through + case GET_DEFAULT_INSTANCE: { + return DEFAULT_INSTANCE; + } + case GET_PARSER: { + com.google.protobuf.Parser parser = PARSER; + if (parser == null) { + synchronized (com.google.protobuf.EnumValue.class) { + parser = PARSER; + if (parser == null) { + parser = + new DefaultInstanceBasedParser( + DEFAULT_INSTANCE); + PARSER = parser; + } + } + } + return parser; + } + case GET_MEMOIZED_IS_INITIALIZED: { + return (byte) 1; + } + case SET_MEMOIZED_IS_INITIALIZED: { + return null; + } + } + throw new UnsupportedOperationException(); + } + + + // @@protoc_insertion_point(class_scope:google.protobuf.EnumValue) + private static final com.google.protobuf.EnumValue DEFAULT_INSTANCE; + static { + EnumValue defaultInstance = new EnumValue(); + // New instances are implicitly immutable so no need to make + // immutable. + DEFAULT_INSTANCE = defaultInstance; + com.google.protobuf.GeneratedMessageLite.registerDefaultInstance( + EnumValue.class, defaultInstance); + } + + public static com.google.protobuf.EnumValue getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static volatile com.google.protobuf.Parser PARSER; + + public static com.google.protobuf.Parser parser() { + return DEFAULT_INSTANCE.getParserForType(); + } +} + diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/EnumValueOrBuilder.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/EnumValueOrBuilder.java new file mode 100644 index 0000000000000..bf2eb46dd8e18 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/EnumValueOrBuilder.java @@ -0,0 +1,65 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/type.proto + +package com.google.protobuf; + +public interface EnumValueOrBuilder extends + // @@protoc_insertion_point(interface_extends:google.protobuf.EnumValue) + com.google.protobuf.MessageLiteOrBuilder { + + /** + *
+   * Enum value name.
+   * 
+ * + * string name = 1; + * @return The name. + */ + java.lang.String getName(); + /** + *
+   * Enum value name.
+   * 
+ * + * string name = 1; + * @return The bytes for name. + */ + com.google.protobuf.ByteString + getNameBytes(); + + /** + *
+   * Enum value number.
+   * 
+ * + * int32 number = 2; + * @return The number. + */ + int getNumber(); + + /** + *
+   * Protocol buffer options.
+   * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + java.util.List + getOptionsList(); + /** + *
+   * Protocol buffer options.
+   * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + com.google.protobuf.Option getOptions(int index); + /** + *
+   * Protocol buffer options.
+   * 
+ * + * repeated .google.protobuf.Option options = 3; + */ + int getOptionsCount(); +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/ExperimentalApi.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/ExperimentalApi.java new file mode 100644 index 0000000000000..d55b278c3f2c7 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/ExperimentalApi.java @@ -0,0 +1,65 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Indicates a public API that can change at any time, and has no guarantee of API stability and + * backward-compatibility. + * + *

Usage guidelines: + * + *

    + *
  1. This annotation is used only on public API. Internal interfaces should not use it. + *
  2. This annotation should only be added to new APIs. Adding it to an existing API is + * considered API-breaking. + *
  3. Removing this annotation from an API gives it stable status. + *
+ */ +@Retention(RetentionPolicy.SOURCE) +@Target({ + ElementType.ANNOTATION_TYPE, + ElementType.CONSTRUCTOR, + ElementType.FIELD, + ElementType.METHOD, + ElementType.PACKAGE, + ElementType.TYPE +}) +@Documented +public @interface ExperimentalApi { + /** Context information such as links to discussion thread, tracking issue etc. */ + String value() default ""; +} diff --git a/java/core/src/main/kotlin/com/google/protobuf/ExtendableMessageLiteExtensions.kt b/java/kotlin-lite/target/generated-sources/com/google/protobuf/ExtendableMessageLiteExtensions.kt similarity index 100% rename from java/core/src/main/kotlin/com/google/protobuf/ExtendableMessageLiteExtensions.kt rename to java/kotlin-lite/target/generated-sources/com/google/protobuf/ExtendableMessageLiteExtensions.kt diff --git a/java/core/src/main/kotlin/com/google/protobuf/ExtensionList.kt b/java/kotlin-lite/target/generated-sources/com/google/protobuf/ExtensionList.kt similarity index 100% rename from java/core/src/main/kotlin/com/google/protobuf/ExtensionList.kt rename to java/kotlin-lite/target/generated-sources/com/google/protobuf/ExtensionList.kt diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/ExtensionLite.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/ExtensionLite.java new file mode 100644 index 0000000000000..0fb5f49e983c0 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/ExtensionLite.java @@ -0,0 +1,60 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +/** + * Lite interface that generated extensions implement. + * + *

Methods are for use by generated code only. You can hold a reference to extensions using this + * type name. + */ +public abstract class ExtensionLite { + + /** Returns the field number of the extension. */ + public abstract int getNumber(); + + /** Returns the type of the field. */ + public abstract WireFormat.FieldType getLiteType(); + + /** Returns whether it is a repeated field. */ + public abstract boolean isRepeated(); + + /** Returns the default value of the extension field. */ + public abstract Type getDefaultValue(); + + /** Returns the default instance of the extension field, if it's a message extension. */ + public abstract MessageLite getMessageDefaultInstance(); + + /** Returns whether or not this extension is a Lite Extension. */ + boolean isLite() { + return true; + } +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/ExtensionRegistryFactory.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/ExtensionRegistryFactory.java new file mode 100644 index 0000000000000..0a63fad187e8a --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/ExtensionRegistryFactory.java @@ -0,0 +1,91 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +import static com.google.protobuf.ExtensionRegistryLite.EMPTY_REGISTRY_LITE; + +/** + * A factory object to create instances of {@link ExtensionRegistryLite}. + * + *

This factory detects (via reflection) if the full (non-Lite) protocol buffer libraries are + * available, and if so, the instances returned are actually {@link ExtensionRegistry}. + */ +final class ExtensionRegistryFactory { + + static final String FULL_REGISTRY_CLASS_NAME = "com.google.protobuf.ExtensionRegistry"; + + /* Visible for Testing + @Nullable */ + static final Class EXTENSION_REGISTRY_CLASS = reflectExtensionRegistry(); + + static Class reflectExtensionRegistry() { + try { + return Class.forName(FULL_REGISTRY_CLASS_NAME); + } catch (ClassNotFoundException e) { + // The exception allocation is potentially expensive on Android (where it can be triggered + // many times at start up). Is there a way to ameliorate this? + return null; + } + } + + /** Construct a new, empty instance. */ + public static ExtensionRegistryLite create() { + ExtensionRegistryLite result = invokeSubclassFactory("newInstance"); + + return result != null ? result : new ExtensionRegistryLite(); + } + + /** Get the unmodifiable singleton empty instance. */ + public static ExtensionRegistryLite createEmpty() { + ExtensionRegistryLite result = invokeSubclassFactory("getEmptyRegistry"); + + return result != null ? result : EMPTY_REGISTRY_LITE; + } + + + static boolean isFullRegistry(ExtensionRegistryLite registry) { + return EXTENSION_REGISTRY_CLASS != null + && EXTENSION_REGISTRY_CLASS.isAssignableFrom(registry.getClass()); + } + + private static final ExtensionRegistryLite invokeSubclassFactory(String methodName) { + if (EXTENSION_REGISTRY_CLASS == null) { + return null; + } + + try { + return (ExtensionRegistryLite) + EXTENSION_REGISTRY_CLASS.getDeclaredMethod(methodName).invoke(null); + } catch (Exception e) { + return null; + } + } +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/ExtensionRegistryLite.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/ExtensionRegistryLite.java new file mode 100644 index 0000000000000..caa58e1ada67e --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/ExtensionRegistryLite.java @@ -0,0 +1,238 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +/** + * Equivalent to {@link ExtensionRegistry} but supports only "lite" types. + * + *

If all of your types are lite types, then you only need to use {@code ExtensionRegistryLite}. + * Similarly, if all your types are regular types, then you only need {@link ExtensionRegistry}. + * Typically it does not make sense to mix the two, since if you have any regular types in your + * program, you then require the full runtime and lose all the benefits of the lite runtime, so you + * might as well make all your types be regular types. However, in some cases (e.g. when depending + * on multiple third-party libraries where one uses lite types and one uses regular), you may find + * yourself wanting to mix the two. In this case things get more complicated. + * + *

There are three factors to consider: Whether the type being extended is lite, whether the + * embedded type (in the case of a message-typed extension) is lite, and whether the extension + * itself is lite. Since all three are declared in different files, they could all be different. + * Here are all the combinations and which type of registry to use: + * + *

+ *   Extended type     Inner type    Extension         Use registry
+ *   =======================================================================
+ *   lite              lite          lite              ExtensionRegistryLite
+ *   lite              regular       lite              ExtensionRegistry
+ *   regular           regular       regular           ExtensionRegistry
+ *   all other combinations                            not supported
+ * 
+ * + *

Note that just as regular types are not allowed to contain lite-type fields, they are also not + * allowed to contain lite-type extensions. This is because regular types must be fully accessible + * via reflection, which in turn means that all the inner messages must also support reflection. On + * the other hand, since regular types implement the entire lite interface, there is no problem with + * embedding regular types inside lite types. + * + * @author kenton@google.com Kenton Varda + */ +public class ExtensionRegistryLite { + + // Set true to enable lazy parsing feature for MessageSet. + // + // TODO(xiangl): Now we use a global flag to control whether enable lazy + // parsing feature for MessageSet, which may be too crude for some + // applications. Need to support this feature on smaller granularity. + private static volatile boolean eagerlyParseMessageSets = false; + + // short circuit the ExtensionRegistryFactory via assumevalues trickery + @SuppressWarnings("JavaOptionalSuggestions") + private static boolean doFullRuntimeInheritanceCheck = true; + + // Visible for testing. + static final String EXTENSION_CLASS_NAME = "com.google.protobuf.Extension"; + + private static class ExtensionClassHolder { + static final Class INSTANCE = resolveExtensionClass(); + + static Class resolveExtensionClass() { + try { + return Class.forName(EXTENSION_CLASS_NAME); + } catch (ClassNotFoundException e) { + // See comment in ExtensionRegistryFactory on the potential expense of this. + return null; + } + } + } + + public static boolean isEagerlyParseMessageSets() { + return eagerlyParseMessageSets; + } + + public static void setEagerlyParseMessageSets(boolean isEagerlyParse) { + eagerlyParseMessageSets = isEagerlyParse; + } + + /** + * Construct a new, empty instance. + * + *

This may be an {@code ExtensionRegistry} if the full (non-Lite) proto libraries are + * available. + */ + public static ExtensionRegistryLite newInstance() { + return doFullRuntimeInheritanceCheck + ? ExtensionRegistryFactory.create() + : new ExtensionRegistryLite(); + } + + private static volatile ExtensionRegistryLite emptyRegistry; + + /** + * Get the unmodifiable singleton empty instance of either ExtensionRegistryLite or {@code + * ExtensionRegistry} (if the full (non-Lite) proto libraries are available). + */ + public static ExtensionRegistryLite getEmptyRegistry() { + ExtensionRegistryLite result = emptyRegistry; + if (result == null) { + synchronized (ExtensionRegistryLite.class) { + result = emptyRegistry; + if (result == null) { + result = + emptyRegistry = + doFullRuntimeInheritanceCheck + ? ExtensionRegistryFactory.createEmpty() + : EMPTY_REGISTRY_LITE; + } + } + } + return result; + } + + + /** Returns an unmodifiable view of the registry. */ + public ExtensionRegistryLite getUnmodifiable() { + return new ExtensionRegistryLite(this); + } + + /** + * Find an extension by containing type and field number. + * + * @return Information about the extension if found, or {@code null} otherwise. + */ + @SuppressWarnings("unchecked") + public + GeneratedMessageLite.GeneratedExtension findLiteExtensionByNumber( + final ContainingType containingTypeDefaultInstance, final int 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 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 (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); + } + } + } + + // ================================================================= + // Private stuff. + + // Constructors are package-private so that ExtensionRegistry can subclass + // this. + + ExtensionRegistryLite() { + this.extensionsByNumber = + new HashMap>(); + } + + static final ExtensionRegistryLite EMPTY_REGISTRY_LITE = new ExtensionRegistryLite(true); + + ExtensionRegistryLite(ExtensionRegistryLite other) { + if (other == EMPTY_REGISTRY_LITE) { + this.extensionsByNumber = Collections.emptyMap(); + } else { + this.extensionsByNumber = Collections.unmodifiableMap(other.extensionsByNumber); + } + } + + private final Map> + extensionsByNumber; + + ExtensionRegistryLite(boolean empty) { + this.extensionsByNumber = Collections.emptyMap(); + } + + /** A (Object, int) pair, used as a map key. */ + private static final class ObjectIntPair { + private final Object object; + private final int number; + + ObjectIntPair(final Object object, final int number) { + this.object = object; + this.number = number; + } + + @Override + public int hashCode() { + return System.identityHashCode(object) * ((1 << 16) - 1) + number; + } + + @Override + public boolean equals(final Object obj) { + if (!(obj instanceof ObjectIntPair)) { + return false; + } + final ObjectIntPair other = (ObjectIntPair) obj; + return object == other.object && number == other.number; + } + } +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/ExtensionSchema.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/ExtensionSchema.java new file mode 100644 index 0000000000000..2eae22d26a078 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/ExtensionSchema.java @@ -0,0 +1,98 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +import java.io.IOException; +import java.util.Map; + +abstract class ExtensionSchema> { + + /** Returns true for messages that support extensions. */ + abstract boolean hasExtensions(MessageLite prototype); + + /** Returns the extension {@link FieldSet} for the message instance. */ + abstract FieldSet getExtensions(Object message); + + /** Replaces the extension {@link FieldSet} for the message instance. */ + abstract void setExtensions(Object message, FieldSet extensions); + + /** Returns the extension {@link FieldSet} and ensures it's mutable. */ + abstract FieldSet getMutableExtensions(Object message); + + /** Marks the extension {@link FieldSet} as immutable. */ + abstract void makeImmutable(Object message); + + /** + * Parses an extension. Returns the passed-in unknownFields parameter if no unknown enum value is + * found or a modified unknownFields (a new instance if the passed-in unknownFields is null) + * containing unknown enum values found while parsing. + * + * @param The type used to store unknown fields. It's either UnknownFieldSet in full runtime + * or UnknownFieldSetLite in lite runtime. + */ + abstract UB parseExtension( + Reader reader, + Object extension, + ExtensionRegistryLite extensionRegistry, + FieldSet extensions, + UB unknownFields, + UnknownFieldSchema unknownFieldSchema) + throws IOException; + + /** Gets the field number of an extension entry. */ + abstract int extensionNumber(Map.Entry extension); + + /** Serializes one extension entry. */ + abstract void serializeExtension(Writer writer, Map.Entry extension) throws IOException; + + /** Finds an extension by field number. */ + abstract Object findExtensionByNumber( + ExtensionRegistryLite extensionRegistry, MessageLite defaultInstance, int number); + + /** Parses a length-prefixed MessageSet item from the reader. */ + abstract void parseLengthPrefixedMessageSetItem( + Reader reader, + Object extension, + ExtensionRegistryLite extensionRegistry, + FieldSet extensions) + throws IOException; + + /** + * Parses the entire content of a {@link ByteString} as one MessageSet item. Unlike {@link + * #parseLengthPrefixedMessageSetItem}, there isn't a length-prefix. + */ + abstract void parseMessageSetItem( + ByteString data, + Object extension, + ExtensionRegistryLite extensionRegistry, + FieldSet extensions) + throws IOException; +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/ExtensionSchemaLite.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/ExtensionSchemaLite.java new file mode 100644 index 0000000000000..437cca2d96bdc --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/ExtensionSchemaLite.java @@ -0,0 +1,541 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +import com.google.protobuf.GeneratedMessageLite.ExtensionDescriptor; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +@SuppressWarnings("unchecked") +final class ExtensionSchemaLite extends ExtensionSchema { + + @Override + boolean hasExtensions(MessageLite prototype) { + return prototype instanceof GeneratedMessageLite.ExtendableMessage; + } + + @Override + FieldSet getExtensions(Object message) { + return ((GeneratedMessageLite.ExtendableMessage) message).extensions; + } + + @Override + void setExtensions(Object message, FieldSet extensions) { + ((GeneratedMessageLite.ExtendableMessage) message).extensions = extensions; + } + + @Override + FieldSet getMutableExtensions(Object message) { + return ((GeneratedMessageLite.ExtendableMessage) message).ensureExtensionsAreMutable(); + } + + @Override + void makeImmutable(Object message) { + getExtensions(message).makeImmutable(); + } + + @Override + UB parseExtension( + Reader reader, + Object extensionObject, + ExtensionRegistryLite extensionRegistry, + FieldSet extensions, + UB unknownFields, + UnknownFieldSchema unknownFieldSchema) + throws IOException { + GeneratedMessageLite.GeneratedExtension extension = + (GeneratedMessageLite.GeneratedExtension) extensionObject; + int fieldNumber = extension.getNumber(); + + if (extension.descriptor.isRepeated() && extension.descriptor.isPacked()) { + Object value = null; + switch (extension.getLiteType()) { + case DOUBLE: + { + List list = new ArrayList(); + reader.readDoubleList(list); + value = list; + break; + } + case FLOAT: + { + List list = new ArrayList(); + reader.readFloatList(list); + value = list; + break; + } + case INT64: + { + List list = new ArrayList(); + reader.readInt64List(list); + value = list; + break; + } + case UINT64: + { + List list = new ArrayList(); + reader.readUInt64List(list); + value = list; + break; + } + case INT32: + { + List list = new ArrayList(); + reader.readInt32List(list); + value = list; + break; + } + case FIXED64: + { + List list = new ArrayList(); + reader.readFixed64List(list); + value = list; + break; + } + case FIXED32: + { + List list = new ArrayList(); + reader.readFixed32List(list); + value = list; + break; + } + case BOOL: + { + List list = new ArrayList(); + reader.readBoolList(list); + value = list; + break; + } + case UINT32: + { + List list = new ArrayList(); + reader.readUInt32List(list); + value = list; + break; + } + case SFIXED32: + { + List list = new ArrayList(); + reader.readSFixed32List(list); + value = list; + break; + } + case SFIXED64: + { + List list = new ArrayList(); + reader.readSFixed64List(list); + value = list; + break; + } + case SINT32: + { + List list = new ArrayList(); + reader.readSInt32List(list); + value = list; + break; + } + case SINT64: + { + List list = new ArrayList(); + reader.readSInt64List(list); + value = list; + break; + } + case ENUM: + { + List list = new ArrayList(); + reader.readEnumList(list); + unknownFields = + SchemaUtil.filterUnknownEnumList( + fieldNumber, + list, + extension.descriptor.getEnumType(), + unknownFields, + unknownFieldSchema); + value = list; + break; + } + default: + throw new IllegalStateException( + "Type cannot be packed: " + extension.descriptor.getLiteType()); + } + extensions.setField(extension.descriptor, value); + } else { + Object value = null; + // Enum is a special case because unknown enum values will be put into UnknownFieldSetLite. + if (extension.getLiteType() == WireFormat.FieldType.ENUM) { + int number = reader.readInt32(); + Object enumValue = extension.descriptor.getEnumType().findValueByNumber(number); + if (enumValue == null) { + return SchemaUtil.storeUnknownEnum( + fieldNumber, number, unknownFields, unknownFieldSchema); + } + // Note, we store the integer value instead of the actual enum object in FieldSet. + // This is also different from full-runtime where we store EnumValueDescriptor. + value = number; + } else { + switch (extension.getLiteType()) { + case DOUBLE: + value = reader.readDouble(); + break; + case FLOAT: + value = reader.readFloat(); + break; + case INT64: + value = reader.readInt64(); + break; + case UINT64: + value = reader.readUInt64(); + break; + case INT32: + value = reader.readInt32(); + break; + case FIXED64: + value = reader.readFixed64(); + break; + case FIXED32: + value = reader.readFixed32(); + break; + case BOOL: + value = reader.readBool(); + break; + case BYTES: + value = reader.readBytes(); + break; + case UINT32: + value = reader.readUInt32(); + break; + case SFIXED32: + value = reader.readSFixed32(); + break; + case SFIXED64: + value = reader.readSFixed64(); + break; + case SINT32: + value = reader.readSInt32(); + break; + case SINT64: + value = reader.readSInt64(); + break; + + case STRING: + value = reader.readString(); + break; + case GROUP: + value = + reader.readGroup( + extension.getMessageDefaultInstance().getClass(), extensionRegistry); + break; + + case MESSAGE: + value = + reader.readMessage( + extension.getMessageDefaultInstance().getClass(), extensionRegistry); + break; + + case ENUM: + throw new IllegalStateException("Shouldn't reach here."); + } + } + if (extension.isRepeated()) { + extensions.addRepeatedField(extension.descriptor, value); + } else { + switch (extension.getLiteType()) { + case MESSAGE: + case GROUP: + Object oldValue = extensions.getField(extension.descriptor); + if (oldValue != null) { + value = Internal.mergeMessage(oldValue, value); + } + break; + default: + break; + } + extensions.setField(extension.descriptor, value); + } + } + return unknownFields; + } + + @Override + int extensionNumber(Map.Entry extension) { + GeneratedMessageLite.ExtensionDescriptor descriptor = + (GeneratedMessageLite.ExtensionDescriptor) extension.getKey(); + return descriptor.getNumber(); + } + + @Override + void serializeExtension(Writer writer, Map.Entry extension) throws IOException { + GeneratedMessageLite.ExtensionDescriptor descriptor = + (GeneratedMessageLite.ExtensionDescriptor) extension.getKey(); + if (descriptor.isRepeated()) { + switch (descriptor.getLiteType()) { + case DOUBLE: + SchemaUtil.writeDoubleList( + descriptor.getNumber(), + (List) extension.getValue(), + writer, + descriptor.isPacked()); + break; + case FLOAT: + SchemaUtil.writeFloatList( + descriptor.getNumber(), + (List) extension.getValue(), + writer, + descriptor.isPacked()); + break; + case INT64: + SchemaUtil.writeInt64List( + descriptor.getNumber(), + (List) extension.getValue(), + writer, + descriptor.isPacked()); + break; + case UINT64: + SchemaUtil.writeUInt64List( + descriptor.getNumber(), + (List) extension.getValue(), + writer, + descriptor.isPacked()); + break; + case INT32: + SchemaUtil.writeInt32List( + descriptor.getNumber(), + (List) extension.getValue(), + writer, + descriptor.isPacked()); + break; + case FIXED64: + SchemaUtil.writeFixed64List( + descriptor.getNumber(), + (List) extension.getValue(), + writer, + descriptor.isPacked()); + break; + case FIXED32: + SchemaUtil.writeFixed32List( + descriptor.getNumber(), + (List) extension.getValue(), + writer, + descriptor.isPacked()); + break; + case BOOL: + SchemaUtil.writeBoolList( + descriptor.getNumber(), + (List) extension.getValue(), + writer, + descriptor.isPacked()); + break; + case BYTES: + SchemaUtil.writeBytesList( + descriptor.getNumber(), (List) extension.getValue(), writer); + break; + case UINT32: + SchemaUtil.writeUInt32List( + descriptor.getNumber(), + (List) extension.getValue(), + writer, + descriptor.isPacked()); + break; + case SFIXED32: + SchemaUtil.writeSFixed32List( + descriptor.getNumber(), + (List) extension.getValue(), + writer, + descriptor.isPacked()); + break; + case SFIXED64: + SchemaUtil.writeSFixed64List( + descriptor.getNumber(), + (List) extension.getValue(), + writer, + descriptor.isPacked()); + break; + case SINT32: + SchemaUtil.writeSInt32List( + descriptor.getNumber(), + (List) extension.getValue(), + writer, + descriptor.isPacked()); + break; + case SINT64: + SchemaUtil.writeSInt64List( + descriptor.getNumber(), + (List) extension.getValue(), + writer, + descriptor.isPacked()); + break; + case ENUM: + SchemaUtil.writeInt32List( + descriptor.getNumber(), + (List) extension.getValue(), + writer, + descriptor.isPacked()); + break; + case STRING: + SchemaUtil.writeStringList( + descriptor.getNumber(), (List) extension.getValue(), writer); + break; + case GROUP: + { + List data = (List) extension.getValue(); + if (data != null && !data.isEmpty()) { + SchemaUtil.writeGroupList( + descriptor.getNumber(), + (List) extension.getValue(), + writer, + Protobuf.getInstance().schemaFor(data.get(0).getClass())); + } + } + break; + case MESSAGE: + { + List data = (List) extension.getValue(); + if (data != null && !data.isEmpty()) { + SchemaUtil.writeMessageList( + descriptor.getNumber(), + (List) extension.getValue(), + writer, + Protobuf.getInstance().schemaFor(data.get(0).getClass())); + } + } + break; + } + } else { + switch (descriptor.getLiteType()) { + case DOUBLE: + writer.writeDouble(descriptor.getNumber(), (Double) extension.getValue()); + break; + case FLOAT: + writer.writeFloat(descriptor.getNumber(), (Float) extension.getValue()); + break; + case INT64: + writer.writeInt64(descriptor.getNumber(), (Long) extension.getValue()); + break; + case UINT64: + writer.writeUInt64(descriptor.getNumber(), (Long) extension.getValue()); + break; + case INT32: + writer.writeInt32(descriptor.getNumber(), (Integer) extension.getValue()); + break; + case FIXED64: + writer.writeFixed64(descriptor.getNumber(), (Long) extension.getValue()); + break; + case FIXED32: + writer.writeFixed32(descriptor.getNumber(), (Integer) extension.getValue()); + break; + case BOOL: + writer.writeBool(descriptor.getNumber(), (Boolean) extension.getValue()); + break; + case BYTES: + writer.writeBytes(descriptor.getNumber(), (ByteString) extension.getValue()); + break; + case UINT32: + writer.writeUInt32(descriptor.getNumber(), (Integer) extension.getValue()); + break; + case SFIXED32: + writer.writeSFixed32(descriptor.getNumber(), (Integer) extension.getValue()); + break; + case SFIXED64: + writer.writeSFixed64(descriptor.getNumber(), (Long) extension.getValue()); + break; + case SINT32: + writer.writeSInt32(descriptor.getNumber(), (Integer) extension.getValue()); + break; + case SINT64: + writer.writeSInt64(descriptor.getNumber(), (Long) extension.getValue()); + break; + case ENUM: + writer.writeInt32(descriptor.getNumber(), (Integer) extension.getValue()); + break; + case STRING: + writer.writeString(descriptor.getNumber(), (String) extension.getValue()); + break; + case GROUP: + writer.writeGroup( + descriptor.getNumber(), + extension.getValue(), + Protobuf.getInstance().schemaFor(extension.getValue().getClass())); + break; + case MESSAGE: + writer.writeMessage( + descriptor.getNumber(), + extension.getValue(), + Protobuf.getInstance().schemaFor(extension.getValue().getClass())); + break; + } + } + } + + @Override + Object findExtensionByNumber( + ExtensionRegistryLite extensionRegistry, MessageLite defaultInstance, int number) { + return extensionRegistry.findLiteExtensionByNumber(defaultInstance, number); + } + + @Override + void parseLengthPrefixedMessageSetItem( + Reader reader, + Object extensionObject, + ExtensionRegistryLite extensionRegistry, + FieldSet extensions) + throws IOException { + GeneratedMessageLite.GeneratedExtension extension = + (GeneratedMessageLite.GeneratedExtension) extensionObject; + Object value = + reader.readMessage(extension.getMessageDefaultInstance().getClass(), extensionRegistry); + extensions.setField(extension.descriptor, value); + } + + @Override + void parseMessageSetItem( + ByteString data, + Object extensionObject, + ExtensionRegistryLite extensionRegistry, + FieldSet extensions) + throws IOException { + GeneratedMessageLite.GeneratedExtension extension = + (GeneratedMessageLite.GeneratedExtension) extensionObject; + Object value = extension.getMessageDefaultInstance().newBuilderForType().buildPartial(); + + Reader reader = BinaryReader.newInstance(ByteBuffer.wrap(data.toByteArray()), true); + + Protobuf.getInstance().mergeFrom(value, reader, extensionRegistry); + extensions.setField(extension.descriptor, value); + + if (reader.getFieldNumber() != Reader.READ_DONE) { + throw InvalidProtocolBufferException.invalidEndTag(); + } + } +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/ExtensionSchemas.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/ExtensionSchemas.java new file mode 100644 index 0000000000000..46ce327d133e3 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/ExtensionSchemas.java @@ -0,0 +1,56 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +final class ExtensionSchemas { + private static final ExtensionSchema LITE_SCHEMA = new ExtensionSchemaLite(); + private static final ExtensionSchema FULL_SCHEMA = loadSchemaForFullRuntime(); + + private static ExtensionSchema loadSchemaForFullRuntime() { + try { + Class clazz = Class.forName("com.google.protobuf.ExtensionSchemaFull"); + return (ExtensionSchema) clazz.getDeclaredConstructor().newInstance(); + } catch (Exception e) { + return null; + } + } + + static ExtensionSchema lite() { + return LITE_SCHEMA; + } + + static ExtensionSchema full() { + if (FULL_SCHEMA == null) { + throw new IllegalStateException("Protobuf runtime is not correctly loaded."); + } + return FULL_SCHEMA; + } +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/Field.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/Field.java new file mode 100644 index 0000000000000..b0079c1f0dd7f --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/Field.java @@ -0,0 +1,2087 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/type.proto + +package com.google.protobuf; + +/** + *

+ * A single field of a message type.
+ * 
+ * + * Protobuf type {@code google.protobuf.Field} + */ +public final class Field extends + com.google.protobuf.GeneratedMessageLite< + Field, Field.Builder> implements + // @@protoc_insertion_point(message_implements:google.protobuf.Field) + FieldOrBuilder { + private Field() { + name_ = ""; + typeUrl_ = ""; + options_ = emptyProtobufList(); + jsonName_ = ""; + defaultValue_ = ""; + } + /** + *
+   * Basic field types.
+   * 
+ * + * Protobuf enum {@code google.protobuf.Field.Kind} + */ + public enum Kind + implements com.google.protobuf.Internal.EnumLite { + /** + *
+     * Field type unknown.
+     * 
+ * + * TYPE_UNKNOWN = 0; + */ + TYPE_UNKNOWN(0), + /** + *
+     * Field type double.
+     * 
+ * + * TYPE_DOUBLE = 1; + */ + TYPE_DOUBLE(1), + /** + *
+     * Field type float.
+     * 
+ * + * TYPE_FLOAT = 2; + */ + TYPE_FLOAT(2), + /** + *
+     * Field type int64.
+     * 
+ * + * TYPE_INT64 = 3; + */ + TYPE_INT64(3), + /** + *
+     * Field type uint64.
+     * 
+ * + * TYPE_UINT64 = 4; + */ + TYPE_UINT64(4), + /** + *
+     * Field type int32.
+     * 
+ * + * TYPE_INT32 = 5; + */ + TYPE_INT32(5), + /** + *
+     * Field type fixed64.
+     * 
+ * + * TYPE_FIXED64 = 6; + */ + TYPE_FIXED64(6), + /** + *
+     * Field type fixed32.
+     * 
+ * + * TYPE_FIXED32 = 7; + */ + TYPE_FIXED32(7), + /** + *
+     * Field type bool.
+     * 
+ * + * TYPE_BOOL = 8; + */ + TYPE_BOOL(8), + /** + *
+     * Field type string.
+     * 
+ * + * TYPE_STRING = 9; + */ + TYPE_STRING(9), + /** + *
+     * Field type group. Proto2 syntax only, and deprecated.
+     * 
+ * + * TYPE_GROUP = 10; + */ + TYPE_GROUP(10), + /** + *
+     * Field type message.
+     * 
+ * + * TYPE_MESSAGE = 11; + */ + TYPE_MESSAGE(11), + /** + *
+     * Field type bytes.
+     * 
+ * + * TYPE_BYTES = 12; + */ + TYPE_BYTES(12), + /** + *
+     * Field type uint32.
+     * 
+ * + * TYPE_UINT32 = 13; + */ + TYPE_UINT32(13), + /** + *
+     * Field type enum.
+     * 
+ * + * TYPE_ENUM = 14; + */ + TYPE_ENUM(14), + /** + *
+     * Field type sfixed32.
+     * 
+ * + * TYPE_SFIXED32 = 15; + */ + TYPE_SFIXED32(15), + /** + *
+     * Field type sfixed64.
+     * 
+ * + * TYPE_SFIXED64 = 16; + */ + TYPE_SFIXED64(16), + /** + *
+     * Field type sint32.
+     * 
+ * + * TYPE_SINT32 = 17; + */ + TYPE_SINT32(17), + /** + *
+     * Field type sint64.
+     * 
+ * + * TYPE_SINT64 = 18; + */ + TYPE_SINT64(18), + UNRECOGNIZED(-1), + ; + + /** + *
+     * Field type unknown.
+     * 
+ * + * TYPE_UNKNOWN = 0; + */ + public static final int TYPE_UNKNOWN_VALUE = 0; + /** + *
+     * Field type double.
+     * 
+ * + * TYPE_DOUBLE = 1; + */ + public static final int TYPE_DOUBLE_VALUE = 1; + /** + *
+     * Field type float.
+     * 
+ * + * TYPE_FLOAT = 2; + */ + public static final int TYPE_FLOAT_VALUE = 2; + /** + *
+     * Field type int64.
+     * 
+ * + * TYPE_INT64 = 3; + */ + public static final int TYPE_INT64_VALUE = 3; + /** + *
+     * Field type uint64.
+     * 
+ * + * TYPE_UINT64 = 4; + */ + public static final int TYPE_UINT64_VALUE = 4; + /** + *
+     * Field type int32.
+     * 
+ * + * TYPE_INT32 = 5; + */ + public static final int TYPE_INT32_VALUE = 5; + /** + *
+     * Field type fixed64.
+     * 
+ * + * TYPE_FIXED64 = 6; + */ + public static final int TYPE_FIXED64_VALUE = 6; + /** + *
+     * Field type fixed32.
+     * 
+ * + * TYPE_FIXED32 = 7; + */ + public static final int TYPE_FIXED32_VALUE = 7; + /** + *
+     * Field type bool.
+     * 
+ * + * TYPE_BOOL = 8; + */ + public static final int TYPE_BOOL_VALUE = 8; + /** + *
+     * Field type string.
+     * 
+ * + * TYPE_STRING = 9; + */ + public static final int TYPE_STRING_VALUE = 9; + /** + *
+     * Field type group. Proto2 syntax only, and deprecated.
+     * 
+ * + * TYPE_GROUP = 10; + */ + public static final int TYPE_GROUP_VALUE = 10; + /** + *
+     * Field type message.
+     * 
+ * + * TYPE_MESSAGE = 11; + */ + public static final int TYPE_MESSAGE_VALUE = 11; + /** + *
+     * Field type bytes.
+     * 
+ * + * TYPE_BYTES = 12; + */ + public static final int TYPE_BYTES_VALUE = 12; + /** + *
+     * Field type uint32.
+     * 
+ * + * TYPE_UINT32 = 13; + */ + public static final int TYPE_UINT32_VALUE = 13; + /** + *
+     * Field type enum.
+     * 
+ * + * TYPE_ENUM = 14; + */ + public static final int TYPE_ENUM_VALUE = 14; + /** + *
+     * Field type sfixed32.
+     * 
+ * + * TYPE_SFIXED32 = 15; + */ + public static final int TYPE_SFIXED32_VALUE = 15; + /** + *
+     * Field type sfixed64.
+     * 
+ * + * TYPE_SFIXED64 = 16; + */ + public static final int TYPE_SFIXED64_VALUE = 16; + /** + *
+     * Field type sint32.
+     * 
+ * + * TYPE_SINT32 = 17; + */ + public static final int TYPE_SINT32_VALUE = 17; + /** + *
+     * Field type sint64.
+     * 
+ * + * TYPE_SINT64 = 18; + */ + public static final int TYPE_SINT64_VALUE = 18; + + + @java.lang.Override + public final int getNumber() { + if (this == UNRECOGNIZED) { + throw new java.lang.IllegalArgumentException( + "Can't get the number of an unknown enum value."); + } + return value; + } + + /** + * @param value The number of the enum to look for. + * @return The enum associated with the given number. + * @deprecated Use {@link #forNumber(int)} instead. + */ + @java.lang.Deprecated + public static Kind valueOf(int value) { + return forNumber(value); + } + + public static Kind forNumber(int value) { + switch (value) { + case 0: return TYPE_UNKNOWN; + case 1: return TYPE_DOUBLE; + case 2: return TYPE_FLOAT; + case 3: return TYPE_INT64; + case 4: return TYPE_UINT64; + case 5: return TYPE_INT32; + case 6: return TYPE_FIXED64; + case 7: return TYPE_FIXED32; + case 8: return TYPE_BOOL; + case 9: return TYPE_STRING; + case 10: return TYPE_GROUP; + case 11: return TYPE_MESSAGE; + case 12: return TYPE_BYTES; + case 13: return TYPE_UINT32; + case 14: return TYPE_ENUM; + case 15: return TYPE_SFIXED32; + case 16: return TYPE_SFIXED64; + case 17: return TYPE_SINT32; + case 18: return TYPE_SINT64; + default: return null; + } + } + + public static com.google.protobuf.Internal.EnumLiteMap + internalGetValueMap() { + return internalValueMap; + } + private static final com.google.protobuf.Internal.EnumLiteMap< + Kind> internalValueMap = + new com.google.protobuf.Internal.EnumLiteMap() { + @java.lang.Override + public Kind findValueByNumber(int number) { + return Kind.forNumber(number); + } + }; + + public static com.google.protobuf.Internal.EnumVerifier + internalGetVerifier() { + return KindVerifier.INSTANCE; + } + + private static final class KindVerifier implements + com.google.protobuf.Internal.EnumVerifier { + static final com.google.protobuf.Internal.EnumVerifier INSTANCE = new KindVerifier(); + @java.lang.Override + public boolean isInRange(int number) { + return Kind.forNumber(number) != null; + } + }; + + private final int value; + + private Kind(int value) { + this.value = value; + } + + // @@protoc_insertion_point(enum_scope:google.protobuf.Field.Kind) + } + + /** + *
+   * Whether a field is optional, required, or repeated.
+   * 
+ * + * Protobuf enum {@code google.protobuf.Field.Cardinality} + */ + public enum Cardinality + implements com.google.protobuf.Internal.EnumLite { + /** + *
+     * For fields with unknown cardinality.
+     * 
+ * + * CARDINALITY_UNKNOWN = 0; + */ + CARDINALITY_UNKNOWN(0), + /** + *
+     * For optional fields.
+     * 
+ * + * CARDINALITY_OPTIONAL = 1; + */ + CARDINALITY_OPTIONAL(1), + /** + *
+     * For required fields. Proto2 syntax only.
+     * 
+ * + * CARDINALITY_REQUIRED = 2; + */ + CARDINALITY_REQUIRED(2), + /** + *
+     * For repeated fields.
+     * 
+ * + * CARDINALITY_REPEATED = 3; + */ + CARDINALITY_REPEATED(3), + UNRECOGNIZED(-1), + ; + + /** + *
+     * For fields with unknown cardinality.
+     * 
+ * + * CARDINALITY_UNKNOWN = 0; + */ + public static final int CARDINALITY_UNKNOWN_VALUE = 0; + /** + *
+     * For optional fields.
+     * 
+ * + * CARDINALITY_OPTIONAL = 1; + */ + public static final int CARDINALITY_OPTIONAL_VALUE = 1; + /** + *
+     * For required fields. Proto2 syntax only.
+     * 
+ * + * CARDINALITY_REQUIRED = 2; + */ + public static final int CARDINALITY_REQUIRED_VALUE = 2; + /** + *
+     * For repeated fields.
+     * 
+ * + * CARDINALITY_REPEATED = 3; + */ + public static final int CARDINALITY_REPEATED_VALUE = 3; + + + @java.lang.Override + public final int getNumber() { + if (this == UNRECOGNIZED) { + throw new java.lang.IllegalArgumentException( + "Can't get the number of an unknown enum value."); + } + return value; + } + + /** + * @param value The number of the enum to look for. + * @return The enum associated with the given number. + * @deprecated Use {@link #forNumber(int)} instead. + */ + @java.lang.Deprecated + public static Cardinality valueOf(int value) { + return forNumber(value); + } + + public static Cardinality forNumber(int value) { + switch (value) { + case 0: return CARDINALITY_UNKNOWN; + case 1: return CARDINALITY_OPTIONAL; + case 2: return CARDINALITY_REQUIRED; + case 3: return CARDINALITY_REPEATED; + default: return null; + } + } + + public static com.google.protobuf.Internal.EnumLiteMap + internalGetValueMap() { + return internalValueMap; + } + private static final com.google.protobuf.Internal.EnumLiteMap< + Cardinality> internalValueMap = + new com.google.protobuf.Internal.EnumLiteMap() { + @java.lang.Override + public Cardinality findValueByNumber(int number) { + return Cardinality.forNumber(number); + } + }; + + public static com.google.protobuf.Internal.EnumVerifier + internalGetVerifier() { + return CardinalityVerifier.INSTANCE; + } + + private static final class CardinalityVerifier implements + com.google.protobuf.Internal.EnumVerifier { + static final com.google.protobuf.Internal.EnumVerifier INSTANCE = new CardinalityVerifier(); + @java.lang.Override + public boolean isInRange(int number) { + return Cardinality.forNumber(number) != null; + } + }; + + private final int value; + + private Cardinality(int value) { + this.value = value; + } + + // @@protoc_insertion_point(enum_scope:google.protobuf.Field.Cardinality) + } + + public static final int KIND_FIELD_NUMBER = 1; + private int kind_; + /** + *
+   * The field type.
+   * 
+ * + * .google.protobuf.Field.Kind kind = 1; + * @return The enum numeric value on the wire for kind. + */ + @java.lang.Override + public int getKindValue() { + return kind_; + } + /** + *
+   * The field type.
+   * 
+ * + * .google.protobuf.Field.Kind kind = 1; + * @return The kind. + */ + @java.lang.Override + public com.google.protobuf.Field.Kind getKind() { + com.google.protobuf.Field.Kind result = com.google.protobuf.Field.Kind.forNumber(kind_); + return result == null ? com.google.protobuf.Field.Kind.UNRECOGNIZED : result; + } + /** + *
+   * The field type.
+   * 
+ * + * .google.protobuf.Field.Kind kind = 1; + * @param value The enum numeric value on the wire for kind to set. + */ + private void setKindValue(int value) { + kind_ = value; + } + /** + *
+   * The field type.
+   * 
+ * + * .google.protobuf.Field.Kind kind = 1; + * @param value The kind to set. + */ + private void setKind(com.google.protobuf.Field.Kind value) { + kind_ = value.getNumber(); + + } + /** + *
+   * The field type.
+   * 
+ * + * .google.protobuf.Field.Kind kind = 1; + */ + private void clearKind() { + + kind_ = 0; + } + + public static final int CARDINALITY_FIELD_NUMBER = 2; + private int cardinality_; + /** + *
+   * The field cardinality.
+   * 
+ * + * .google.protobuf.Field.Cardinality cardinality = 2; + * @return The enum numeric value on the wire for cardinality. + */ + @java.lang.Override + public int getCardinalityValue() { + return cardinality_; + } + /** + *
+   * The field cardinality.
+   * 
+ * + * .google.protobuf.Field.Cardinality cardinality = 2; + * @return The cardinality. + */ + @java.lang.Override + public com.google.protobuf.Field.Cardinality getCardinality() { + com.google.protobuf.Field.Cardinality result = com.google.protobuf.Field.Cardinality.forNumber(cardinality_); + return result == null ? com.google.protobuf.Field.Cardinality.UNRECOGNIZED : result; + } + /** + *
+   * The field cardinality.
+   * 
+ * + * .google.protobuf.Field.Cardinality cardinality = 2; + * @param value The enum numeric value on the wire for cardinality to set. + */ + private void setCardinalityValue(int value) { + cardinality_ = value; + } + /** + *
+   * The field cardinality.
+   * 
+ * + * .google.protobuf.Field.Cardinality cardinality = 2; + * @param value The cardinality to set. + */ + private void setCardinality(com.google.protobuf.Field.Cardinality value) { + cardinality_ = value.getNumber(); + + } + /** + *
+   * The field cardinality.
+   * 
+ * + * .google.protobuf.Field.Cardinality cardinality = 2; + */ + private void clearCardinality() { + + cardinality_ = 0; + } + + public static final int NUMBER_FIELD_NUMBER = 3; + private int number_; + /** + *
+   * The field number.
+   * 
+ * + * int32 number = 3; + * @return The number. + */ + @java.lang.Override + public int getNumber() { + return number_; + } + /** + *
+   * The field number.
+   * 
+ * + * int32 number = 3; + * @param value The number to set. + */ + private void setNumber(int value) { + + number_ = value; + } + /** + *
+   * The field number.
+   * 
+ * + * int32 number = 3; + */ + private void clearNumber() { + + number_ = 0; + } + + public static final int NAME_FIELD_NUMBER = 4; + private java.lang.String name_; + /** + *
+   * The field name.
+   * 
+ * + * string name = 4; + * @return The name. + */ + @java.lang.Override + public java.lang.String getName() { + return name_; + } + /** + *
+   * The field name.
+   * 
+ * + * string name = 4; + * @return The bytes for name. + */ + @java.lang.Override + public com.google.protobuf.ByteString + getNameBytes() { + return com.google.protobuf.ByteString.copyFromUtf8(name_); + } + /** + *
+   * The field name.
+   * 
+ * + * string name = 4; + * @param value The name to set. + */ + private void setName( + java.lang.String value) { + value.getClass(); + + name_ = value; + } + /** + *
+   * The field name.
+   * 
+ * + * string name = 4; + */ + private void clearName() { + + name_ = getDefaultInstance().getName(); + } + /** + *
+   * The field name.
+   * 
+ * + * string name = 4; + * @param value The bytes for name to set. + */ + private void setNameBytes( + com.google.protobuf.ByteString value) { + checkByteStringIsUtf8(value); + name_ = value.toStringUtf8(); + + } + + public static final int TYPE_URL_FIELD_NUMBER = 6; + private java.lang.String typeUrl_; + /** + *
+   * The field type URL, without the scheme, for message or enumeration
+   * types. Example: `"type.googleapis.com/google.protobuf.Timestamp"`.
+   * 
+ * + * string type_url = 6; + * @return The typeUrl. + */ + @java.lang.Override + public java.lang.String getTypeUrl() { + return typeUrl_; + } + /** + *
+   * The field type URL, without the scheme, for message or enumeration
+   * types. Example: `"type.googleapis.com/google.protobuf.Timestamp"`.
+   * 
+ * + * string type_url = 6; + * @return The bytes for typeUrl. + */ + @java.lang.Override + public com.google.protobuf.ByteString + getTypeUrlBytes() { + return com.google.protobuf.ByteString.copyFromUtf8(typeUrl_); + } + /** + *
+   * The field type URL, without the scheme, for message or enumeration
+   * types. Example: `"type.googleapis.com/google.protobuf.Timestamp"`.
+   * 
+ * + * string type_url = 6; + * @param value The typeUrl to set. + */ + private void setTypeUrl( + java.lang.String value) { + value.getClass(); + + typeUrl_ = value; + } + /** + *
+   * The field type URL, without the scheme, for message or enumeration
+   * types. Example: `"type.googleapis.com/google.protobuf.Timestamp"`.
+   * 
+ * + * string type_url = 6; + */ + private void clearTypeUrl() { + + typeUrl_ = getDefaultInstance().getTypeUrl(); + } + /** + *
+   * The field type URL, without the scheme, for message or enumeration
+   * types. Example: `"type.googleapis.com/google.protobuf.Timestamp"`.
+   * 
+ * + * string type_url = 6; + * @param value The bytes for typeUrl to set. + */ + private void setTypeUrlBytes( + com.google.protobuf.ByteString value) { + checkByteStringIsUtf8(value); + typeUrl_ = value.toStringUtf8(); + + } + + public static final int ONEOF_INDEX_FIELD_NUMBER = 7; + private int oneofIndex_; + /** + *
+   * The index of the field type in `Type.oneofs`, for message or enumeration
+   * types. The first type has index 1; zero means the type is not in the list.
+   * 
+ * + * int32 oneof_index = 7; + * @return The oneofIndex. + */ + @java.lang.Override + public int getOneofIndex() { + return oneofIndex_; + } + /** + *
+   * The index of the field type in `Type.oneofs`, for message or enumeration
+   * types. The first type has index 1; zero means the type is not in the list.
+   * 
+ * + * int32 oneof_index = 7; + * @param value The oneofIndex to set. + */ + private void setOneofIndex(int value) { + + oneofIndex_ = value; + } + /** + *
+   * The index of the field type in `Type.oneofs`, for message or enumeration
+   * types. The first type has index 1; zero means the type is not in the list.
+   * 
+ * + * int32 oneof_index = 7; + */ + private void clearOneofIndex() { + + oneofIndex_ = 0; + } + + public static final int PACKED_FIELD_NUMBER = 8; + private boolean packed_; + /** + *
+   * Whether to use alternative packed wire representation.
+   * 
+ * + * bool packed = 8; + * @return The packed. + */ + @java.lang.Override + public boolean getPacked() { + return packed_; + } + /** + *
+   * Whether to use alternative packed wire representation.
+   * 
+ * + * bool packed = 8; + * @param value The packed to set. + */ + private void setPacked(boolean value) { + + packed_ = value; + } + /** + *
+   * Whether to use alternative packed wire representation.
+   * 
+ * + * bool packed = 8; + */ + private void clearPacked() { + + packed_ = false; + } + + public static final int OPTIONS_FIELD_NUMBER = 9; + private com.google.protobuf.Internal.ProtobufList options_; + /** + *
+   * The protocol buffer options.
+   * 
+ * + * repeated .google.protobuf.Option options = 9; + */ + @java.lang.Override + public java.util.List getOptionsList() { + return options_; + } + /** + *
+   * The protocol buffer options.
+   * 
+ * + * repeated .google.protobuf.Option options = 9; + */ + public java.util.List + getOptionsOrBuilderList() { + return options_; + } + /** + *
+   * The protocol buffer options.
+   * 
+ * + * repeated .google.protobuf.Option options = 9; + */ + @java.lang.Override + public int getOptionsCount() { + return options_.size(); + } + /** + *
+   * The protocol buffer options.
+   * 
+ * + * repeated .google.protobuf.Option options = 9; + */ + @java.lang.Override + public com.google.protobuf.Option getOptions(int index) { + return options_.get(index); + } + /** + *
+   * The protocol buffer options.
+   * 
+ * + * repeated .google.protobuf.Option options = 9; + */ + public com.google.protobuf.OptionOrBuilder getOptionsOrBuilder( + int index) { + return options_.get(index); + } + private void ensureOptionsIsMutable() { + com.google.protobuf.Internal.ProtobufList tmp = options_; + if (!tmp.isModifiable()) { + options_ = + com.google.protobuf.GeneratedMessageLite.mutableCopy(tmp); + } + } + + /** + *
+   * The protocol buffer options.
+   * 
+ * + * repeated .google.protobuf.Option options = 9; + */ + private void setOptions( + int index, com.google.protobuf.Option value) { + value.getClass(); + ensureOptionsIsMutable(); + options_.set(index, value); + } + /** + *
+   * The protocol buffer options.
+   * 
+ * + * repeated .google.protobuf.Option options = 9; + */ + private void addOptions(com.google.protobuf.Option value) { + value.getClass(); + ensureOptionsIsMutable(); + options_.add(value); + } + /** + *
+   * The protocol buffer options.
+   * 
+ * + * repeated .google.protobuf.Option options = 9; + */ + private void addOptions( + int index, com.google.protobuf.Option value) { + value.getClass(); + ensureOptionsIsMutable(); + options_.add(index, value); + } + /** + *
+   * The protocol buffer options.
+   * 
+ * + * repeated .google.protobuf.Option options = 9; + */ + private void addAllOptions( + java.lang.Iterable values) { + ensureOptionsIsMutable(); + com.google.protobuf.AbstractMessageLite.addAll( + values, options_); + } + /** + *
+   * The protocol buffer options.
+   * 
+ * + * repeated .google.protobuf.Option options = 9; + */ + private void clearOptions() { + options_ = emptyProtobufList(); + } + /** + *
+   * The protocol buffer options.
+   * 
+ * + * repeated .google.protobuf.Option options = 9; + */ + private void removeOptions(int index) { + ensureOptionsIsMutable(); + options_.remove(index); + } + + public static final int JSON_NAME_FIELD_NUMBER = 10; + private java.lang.String jsonName_; + /** + *
+   * The field JSON name.
+   * 
+ * + * string json_name = 10; + * @return The jsonName. + */ + @java.lang.Override + public java.lang.String getJsonName() { + return jsonName_; + } + /** + *
+   * The field JSON name.
+   * 
+ * + * string json_name = 10; + * @return The bytes for jsonName. + */ + @java.lang.Override + public com.google.protobuf.ByteString + getJsonNameBytes() { + return com.google.protobuf.ByteString.copyFromUtf8(jsonName_); + } + /** + *
+   * The field JSON name.
+   * 
+ * + * string json_name = 10; + * @param value The jsonName to set. + */ + private void setJsonName( + java.lang.String value) { + value.getClass(); + + jsonName_ = value; + } + /** + *
+   * The field JSON name.
+   * 
+ * + * string json_name = 10; + */ + private void clearJsonName() { + + jsonName_ = getDefaultInstance().getJsonName(); + } + /** + *
+   * The field JSON name.
+   * 
+ * + * string json_name = 10; + * @param value The bytes for jsonName to set. + */ + private void setJsonNameBytes( + com.google.protobuf.ByteString value) { + checkByteStringIsUtf8(value); + jsonName_ = value.toStringUtf8(); + + } + + public static final int DEFAULT_VALUE_FIELD_NUMBER = 11; + private java.lang.String defaultValue_; + /** + *
+   * The string value of the default value of this field. Proto2 syntax only.
+   * 
+ * + * string default_value = 11; + * @return The defaultValue. + */ + @java.lang.Override + public java.lang.String getDefaultValue() { + return defaultValue_; + } + /** + *
+   * The string value of the default value of this field. Proto2 syntax only.
+   * 
+ * + * string default_value = 11; + * @return The bytes for defaultValue. + */ + @java.lang.Override + public com.google.protobuf.ByteString + getDefaultValueBytes() { + return com.google.protobuf.ByteString.copyFromUtf8(defaultValue_); + } + /** + *
+   * The string value of the default value of this field. Proto2 syntax only.
+   * 
+ * + * string default_value = 11; + * @param value The defaultValue to set. + */ + private void setDefaultValue( + java.lang.String value) { + value.getClass(); + + defaultValue_ = value; + } + /** + *
+   * The string value of the default value of this field. Proto2 syntax only.
+   * 
+ * + * string default_value = 11; + */ + private void clearDefaultValue() { + + defaultValue_ = getDefaultInstance().getDefaultValue(); + } + /** + *
+   * The string value of the default value of this field. Proto2 syntax only.
+   * 
+ * + * string default_value = 11; + * @param value The bytes for defaultValue to set. + */ + private void setDefaultValueBytes( + com.google.protobuf.ByteString value) { + checkByteStringIsUtf8(value); + defaultValue_ = value.toStringUtf8(); + + } + + public static com.google.protobuf.Field parseFrom( + java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.Field parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.Field parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.Field parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.Field parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.Field parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.Field parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, 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.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, input, extensionRegistry); + } + public static com.google.protobuf.Field parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return parseDelimitedFrom(DEFAULT_INSTANCE, input); + } + public static com.google.protobuf.Field parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return parseDelimitedFrom(DEFAULT_INSTANCE, input, extensionRegistry); + } + public static com.google.protobuf.Field parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, 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.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, input, extensionRegistry); + } + + public static Builder newBuilder() { + return (Builder) DEFAULT_INSTANCE.createBuilder(); + } + public static Builder newBuilder(com.google.protobuf.Field prototype) { + return (Builder) DEFAULT_INSTANCE.createBuilder(prototype); + } + + /** + *
+   * A single field of a message type.
+   * 
+ * + * Protobuf type {@code google.protobuf.Field} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessageLite.Builder< + com.google.protobuf.Field, Builder> implements + // @@protoc_insertion_point(builder_implements:google.protobuf.Field) + com.google.protobuf.FieldOrBuilder { + // Construct using com.google.protobuf.Field.newBuilder() + private Builder() { + super(DEFAULT_INSTANCE); + } + + + /** + *
+     * The field type.
+     * 
+ * + * .google.protobuf.Field.Kind kind = 1; + * @return The enum numeric value on the wire for kind. + */ + @java.lang.Override + public int getKindValue() { + return instance.getKindValue(); + } + /** + *
+     * The field type.
+     * 
+ * + * .google.protobuf.Field.Kind kind = 1; + * @param value The kind to set. + * @return This builder for chaining. + */ + public Builder setKindValue(int value) { + copyOnWrite(); + instance.setKindValue(value); + return this; + } + /** + *
+     * The field type.
+     * 
+ * + * .google.protobuf.Field.Kind kind = 1; + * @return The kind. + */ + @java.lang.Override + public com.google.protobuf.Field.Kind getKind() { + return instance.getKind(); + } + /** + *
+     * The field type.
+     * 
+ * + * .google.protobuf.Field.Kind kind = 1; + * @param value The enum numeric value on the wire for kind to set. + * @return This builder for chaining. + */ + public Builder setKind(com.google.protobuf.Field.Kind value) { + copyOnWrite(); + instance.setKind(value); + return this; + } + /** + *
+     * The field type.
+     * 
+ * + * .google.protobuf.Field.Kind kind = 1; + * @return This builder for chaining. + */ + public Builder clearKind() { + copyOnWrite(); + instance.clearKind(); + return this; + } + + /** + *
+     * The field cardinality.
+     * 
+ * + * .google.protobuf.Field.Cardinality cardinality = 2; + * @return The enum numeric value on the wire for cardinality. + */ + @java.lang.Override + public int getCardinalityValue() { + return instance.getCardinalityValue(); + } + /** + *
+     * The field cardinality.
+     * 
+ * + * .google.protobuf.Field.Cardinality cardinality = 2; + * @param value The cardinality to set. + * @return This builder for chaining. + */ + public Builder setCardinalityValue(int value) { + copyOnWrite(); + instance.setCardinalityValue(value); + return this; + } + /** + *
+     * The field cardinality.
+     * 
+ * + * .google.protobuf.Field.Cardinality cardinality = 2; + * @return The cardinality. + */ + @java.lang.Override + public com.google.protobuf.Field.Cardinality getCardinality() { + return instance.getCardinality(); + } + /** + *
+     * The field cardinality.
+     * 
+ * + * .google.protobuf.Field.Cardinality cardinality = 2; + * @param value The enum numeric value on the wire for cardinality to set. + * @return This builder for chaining. + */ + public Builder setCardinality(com.google.protobuf.Field.Cardinality value) { + copyOnWrite(); + instance.setCardinality(value); + return this; + } + /** + *
+     * The field cardinality.
+     * 
+ * + * .google.protobuf.Field.Cardinality cardinality = 2; + * @return This builder for chaining. + */ + public Builder clearCardinality() { + copyOnWrite(); + instance.clearCardinality(); + return this; + } + + /** + *
+     * The field number.
+     * 
+ * + * int32 number = 3; + * @return The number. + */ + @java.lang.Override + public int getNumber() { + return instance.getNumber(); + } + /** + *
+     * The field number.
+     * 
+ * + * int32 number = 3; + * @param value The number to set. + * @return This builder for chaining. + */ + public Builder setNumber(int value) { + copyOnWrite(); + instance.setNumber(value); + return this; + } + /** + *
+     * The field number.
+     * 
+ * + * int32 number = 3; + * @return This builder for chaining. + */ + public Builder clearNumber() { + copyOnWrite(); + instance.clearNumber(); + return this; + } + + /** + *
+     * The field name.
+     * 
+ * + * string name = 4; + * @return The name. + */ + @java.lang.Override + public java.lang.String getName() { + return instance.getName(); + } + /** + *
+     * The field name.
+     * 
+ * + * string name = 4; + * @return The bytes for name. + */ + @java.lang.Override + public com.google.protobuf.ByteString + getNameBytes() { + return instance.getNameBytes(); + } + /** + *
+     * The field name.
+     * 
+ * + * string name = 4; + * @param value The name to set. + * @return This builder for chaining. + */ + public Builder setName( + java.lang.String value) { + copyOnWrite(); + instance.setName(value); + return this; + } + /** + *
+     * The field name.
+     * 
+ * + * string name = 4; + * @return This builder for chaining. + */ + public Builder clearName() { + copyOnWrite(); + instance.clearName(); + return this; + } + /** + *
+     * The field name.
+     * 
+ * + * string name = 4; + * @param value The bytes for name to set. + * @return This builder for chaining. + */ + public Builder setNameBytes( + com.google.protobuf.ByteString value) { + copyOnWrite(); + instance.setNameBytes(value); + return this; + } + + /** + *
+     * The field type URL, without the scheme, for message or enumeration
+     * types. Example: `"type.googleapis.com/google.protobuf.Timestamp"`.
+     * 
+ * + * string type_url = 6; + * @return The typeUrl. + */ + @java.lang.Override + public java.lang.String getTypeUrl() { + return instance.getTypeUrl(); + } + /** + *
+     * The field type URL, without the scheme, for message or enumeration
+     * types. Example: `"type.googleapis.com/google.protobuf.Timestamp"`.
+     * 
+ * + * string type_url = 6; + * @return The bytes for typeUrl. + */ + @java.lang.Override + public com.google.protobuf.ByteString + getTypeUrlBytes() { + return instance.getTypeUrlBytes(); + } + /** + *
+     * The field type URL, without the scheme, for message or enumeration
+     * types. Example: `"type.googleapis.com/google.protobuf.Timestamp"`.
+     * 
+ * + * string type_url = 6; + * @param value The typeUrl to set. + * @return This builder for chaining. + */ + public Builder setTypeUrl( + java.lang.String value) { + copyOnWrite(); + instance.setTypeUrl(value); + return this; + } + /** + *
+     * The field type URL, without the scheme, for message or enumeration
+     * types. Example: `"type.googleapis.com/google.protobuf.Timestamp"`.
+     * 
+ * + * string type_url = 6; + * @return This builder for chaining. + */ + public Builder clearTypeUrl() { + copyOnWrite(); + instance.clearTypeUrl(); + return this; + } + /** + *
+     * The field type URL, without the scheme, for message or enumeration
+     * types. Example: `"type.googleapis.com/google.protobuf.Timestamp"`.
+     * 
+ * + * string type_url = 6; + * @param value The bytes for typeUrl to set. + * @return This builder for chaining. + */ + public Builder setTypeUrlBytes( + com.google.protobuf.ByteString value) { + copyOnWrite(); + instance.setTypeUrlBytes(value); + return this; + } + + /** + *
+     * The index of the field type in `Type.oneofs`, for message or enumeration
+     * types. The first type has index 1; zero means the type is not in the list.
+     * 
+ * + * int32 oneof_index = 7; + * @return The oneofIndex. + */ + @java.lang.Override + public int getOneofIndex() { + return instance.getOneofIndex(); + } + /** + *
+     * The index of the field type in `Type.oneofs`, for message or enumeration
+     * types. The first type has index 1; zero means the type is not in the list.
+     * 
+ * + * int32 oneof_index = 7; + * @param value The oneofIndex to set. + * @return This builder for chaining. + */ + public Builder setOneofIndex(int value) { + copyOnWrite(); + instance.setOneofIndex(value); + return this; + } + /** + *
+     * The index of the field type in `Type.oneofs`, for message or enumeration
+     * types. The first type has index 1; zero means the type is not in the list.
+     * 
+ * + * int32 oneof_index = 7; + * @return This builder for chaining. + */ + public Builder clearOneofIndex() { + copyOnWrite(); + instance.clearOneofIndex(); + return this; + } + + /** + *
+     * Whether to use alternative packed wire representation.
+     * 
+ * + * bool packed = 8; + * @return The packed. + */ + @java.lang.Override + public boolean getPacked() { + return instance.getPacked(); + } + /** + *
+     * Whether to use alternative packed wire representation.
+     * 
+ * + * bool packed = 8; + * @param value The packed to set. + * @return This builder for chaining. + */ + public Builder setPacked(boolean value) { + copyOnWrite(); + instance.setPacked(value); + return this; + } + /** + *
+     * Whether to use alternative packed wire representation.
+     * 
+ * + * bool packed = 8; + * @return This builder for chaining. + */ + public Builder clearPacked() { + copyOnWrite(); + instance.clearPacked(); + return this; + } + + /** + *
+     * The protocol buffer options.
+     * 
+ * + * repeated .google.protobuf.Option options = 9; + */ + @java.lang.Override + public java.util.List getOptionsList() { + return java.util.Collections.unmodifiableList( + instance.getOptionsList()); + } + /** + *
+     * The protocol buffer options.
+     * 
+ * + * repeated .google.protobuf.Option options = 9; + */ + @java.lang.Override + public int getOptionsCount() { + return instance.getOptionsCount(); + }/** + *
+     * The protocol buffer options.
+     * 
+ * + * repeated .google.protobuf.Option options = 9; + */ + @java.lang.Override + public com.google.protobuf.Option getOptions(int index) { + return instance.getOptions(index); + } + /** + *
+     * The protocol buffer options.
+     * 
+ * + * repeated .google.protobuf.Option options = 9; + */ + public Builder setOptions( + int index, com.google.protobuf.Option value) { + copyOnWrite(); + instance.setOptions(index, value); + return this; + } + /** + *
+     * The protocol buffer options.
+     * 
+ * + * repeated .google.protobuf.Option options = 9; + */ + public Builder setOptions( + int index, com.google.protobuf.Option.Builder builderForValue) { + copyOnWrite(); + instance.setOptions(index, + builderForValue.build()); + return this; + } + /** + *
+     * The protocol buffer options.
+     * 
+ * + * repeated .google.protobuf.Option options = 9; + */ + public Builder addOptions(com.google.protobuf.Option value) { + copyOnWrite(); + instance.addOptions(value); + return this; + } + /** + *
+     * The protocol buffer options.
+     * 
+ * + * repeated .google.protobuf.Option options = 9; + */ + public Builder addOptions( + int index, com.google.protobuf.Option value) { + copyOnWrite(); + instance.addOptions(index, value); + return this; + } + /** + *
+     * The protocol buffer options.
+     * 
+ * + * repeated .google.protobuf.Option options = 9; + */ + public Builder addOptions( + com.google.protobuf.Option.Builder builderForValue) { + copyOnWrite(); + instance.addOptions(builderForValue.build()); + return this; + } + /** + *
+     * The protocol buffer options.
+     * 
+ * + * repeated .google.protobuf.Option options = 9; + */ + public Builder addOptions( + int index, com.google.protobuf.Option.Builder builderForValue) { + copyOnWrite(); + instance.addOptions(index, + builderForValue.build()); + return this; + } + /** + *
+     * The protocol buffer options.
+     * 
+ * + * repeated .google.protobuf.Option options = 9; + */ + public Builder addAllOptions( + java.lang.Iterable values) { + copyOnWrite(); + instance.addAllOptions(values); + return this; + } + /** + *
+     * The protocol buffer options.
+     * 
+ * + * repeated .google.protobuf.Option options = 9; + */ + public Builder clearOptions() { + copyOnWrite(); + instance.clearOptions(); + return this; + } + /** + *
+     * The protocol buffer options.
+     * 
+ * + * repeated .google.protobuf.Option options = 9; + */ + public Builder removeOptions(int index) { + copyOnWrite(); + instance.removeOptions(index); + return this; + } + + /** + *
+     * The field JSON name.
+     * 
+ * + * string json_name = 10; + * @return The jsonName. + */ + @java.lang.Override + public java.lang.String getJsonName() { + return instance.getJsonName(); + } + /** + *
+     * The field JSON name.
+     * 
+ * + * string json_name = 10; + * @return The bytes for jsonName. + */ + @java.lang.Override + public com.google.protobuf.ByteString + getJsonNameBytes() { + return instance.getJsonNameBytes(); + } + /** + *
+     * The field JSON name.
+     * 
+ * + * string json_name = 10; + * @param value The jsonName to set. + * @return This builder for chaining. + */ + public Builder setJsonName( + java.lang.String value) { + copyOnWrite(); + instance.setJsonName(value); + return this; + } + /** + *
+     * The field JSON name.
+     * 
+ * + * string json_name = 10; + * @return This builder for chaining. + */ + public Builder clearJsonName() { + copyOnWrite(); + instance.clearJsonName(); + return this; + } + /** + *
+     * The field JSON name.
+     * 
+ * + * string json_name = 10; + * @param value The bytes for jsonName to set. + * @return This builder for chaining. + */ + public Builder setJsonNameBytes( + com.google.protobuf.ByteString value) { + copyOnWrite(); + instance.setJsonNameBytes(value); + return this; + } + + /** + *
+     * The string value of the default value of this field. Proto2 syntax only.
+     * 
+ * + * string default_value = 11; + * @return The defaultValue. + */ + @java.lang.Override + public java.lang.String getDefaultValue() { + return instance.getDefaultValue(); + } + /** + *
+     * The string value of the default value of this field. Proto2 syntax only.
+     * 
+ * + * string default_value = 11; + * @return The bytes for defaultValue. + */ + @java.lang.Override + public com.google.protobuf.ByteString + getDefaultValueBytes() { + return instance.getDefaultValueBytes(); + } + /** + *
+     * The string value of the default value of this field. Proto2 syntax only.
+     * 
+ * + * string default_value = 11; + * @param value The defaultValue to set. + * @return This builder for chaining. + */ + public Builder setDefaultValue( + java.lang.String value) { + copyOnWrite(); + instance.setDefaultValue(value); + return this; + } + /** + *
+     * The string value of the default value of this field. Proto2 syntax only.
+     * 
+ * + * string default_value = 11; + * @return This builder for chaining. + */ + public Builder clearDefaultValue() { + copyOnWrite(); + instance.clearDefaultValue(); + return this; + } + /** + *
+     * The string value of the default value of this field. Proto2 syntax only.
+     * 
+ * + * string default_value = 11; + * @param value The bytes for defaultValue to set. + * @return This builder for chaining. + */ + public Builder setDefaultValueBytes( + com.google.protobuf.ByteString value) { + copyOnWrite(); + instance.setDefaultValueBytes(value); + return this; + } + + // @@protoc_insertion_point(builder_scope:google.protobuf.Field) + } + @java.lang.Override + @java.lang.SuppressWarnings({"unchecked", "fallthrough"}) + protected final java.lang.Object dynamicMethod( + com.google.protobuf.GeneratedMessageLite.MethodToInvoke method, + java.lang.Object arg0, java.lang.Object arg1) { + switch (method) { + case NEW_MUTABLE_INSTANCE: { + return new com.google.protobuf.Field(); + } + case NEW_BUILDER: { + return new Builder(); + } + case BUILD_MESSAGE_INFO: { + java.lang.Object[] objects = new java.lang.Object[] { + "kind_", + "cardinality_", + "number_", + "name_", + "typeUrl_", + "oneofIndex_", + "packed_", + "options_", + com.google.protobuf.Option.class, + "jsonName_", + "defaultValue_", + }; + java.lang.String info = + "\u0000\n\u0000\u0000\u0001\u000b\n\u0000\u0001\u0000\u0001\f\u0002\f\u0003\u0004" + + "\u0004\u0208\u0006\u0208\u0007\u0004\b\u0007\t\u001b\n\u0208\u000b\u0208"; + return newMessageInfo(DEFAULT_INSTANCE, info, objects); + } + // fall through + case GET_DEFAULT_INSTANCE: { + return DEFAULT_INSTANCE; + } + case GET_PARSER: { + com.google.protobuf.Parser parser = PARSER; + if (parser == null) { + synchronized (com.google.protobuf.Field.class) { + parser = PARSER; + if (parser == null) { + parser = + new DefaultInstanceBasedParser( + DEFAULT_INSTANCE); + PARSER = parser; + } + } + } + return parser; + } + case GET_MEMOIZED_IS_INITIALIZED: { + return (byte) 1; + } + case SET_MEMOIZED_IS_INITIALIZED: { + return null; + } + } + throw new UnsupportedOperationException(); + } + + + // @@protoc_insertion_point(class_scope:google.protobuf.Field) + private static final com.google.protobuf.Field DEFAULT_INSTANCE; + static { + Field defaultInstance = new Field(); + // New instances are implicitly immutable so no need to make + // immutable. + DEFAULT_INSTANCE = defaultInstance; + com.google.protobuf.GeneratedMessageLite.registerDefaultInstance( + Field.class, defaultInstance); + } + + public static com.google.protobuf.Field getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static volatile com.google.protobuf.Parser PARSER; + + public static com.google.protobuf.Parser parser() { + return DEFAULT_INSTANCE.getParserForType(); + } +} + diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/FieldInfo.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/FieldInfo.java new file mode 100644 index 0000000000000..71a307a895b60 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/FieldInfo.java @@ -0,0 +1,577 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +import static com.google.protobuf.Internal.checkNotNull; + +import com.google.protobuf.Internal.EnumVerifier; +import java.lang.reflect.Field; + +/** Information for a single field in a protobuf message class. */ +@ExperimentalApi +final class FieldInfo implements Comparable { + private final Field field; + private final FieldType type; + private final Class messageClass; // The message type for repeated message fields. + private final int fieldNumber; + private final Field presenceField; + private final int presenceMask; + private final boolean required; + private final boolean enforceUtf8; + private final OneofInfo oneof; + private final Field cachedSizeField; + /** + * The actual type stored in the oneof value for this field. Since the oneof value is an {@link + * Object}, primitives will store their boxed type. Only valid in conjunction with {@link #oneof} + * (both must be either null or non-null. + */ + private final Class oneofStoredType; + + // TODO(liujisi): make map default entry lazy? + private final Object mapDefaultEntry; + + private final EnumVerifier enumVerifier; + + /** Constructs a new descriptor for a field. */ + public static FieldInfo forField( + Field field, int fieldNumber, FieldType fieldType, boolean enforceUtf8) { + checkFieldNumber(fieldNumber); + checkNotNull(field, "field"); + checkNotNull(fieldType, "fieldType"); + if (fieldType == FieldType.MESSAGE_LIST || fieldType == FieldType.GROUP_LIST) { + throw new IllegalStateException("Shouldn't be called for repeated message fields."); + } + return new FieldInfo( + field, + fieldNumber, + fieldType, + /* messageClass= */ null, + /* presenceField= */ null, + /* presenceMask= */ 0, + /* required= */ false, + enforceUtf8, + /* oneof= */ null, + /* oneofStoredType= */ null, + /* mapDefaultEntry= */ null, + /* enumVerifier= */ null, + /* cachedSizeField= */ null); + } + + /** Constructs a new descriptor for a packed field. */ + public static FieldInfo forPackedField( + Field field, int fieldNumber, FieldType fieldType, Field cachedSizeField) { + checkFieldNumber(fieldNumber); + checkNotNull(field, "field"); + checkNotNull(fieldType, "fieldType"); + if (fieldType == FieldType.MESSAGE_LIST || fieldType == FieldType.GROUP_LIST) { + throw new IllegalStateException("Shouldn't be called for repeated message fields."); + } + return new FieldInfo( + field, + fieldNumber, + fieldType, + /* messageClass= */ null, + /* presenceField= */ null, + /* presenceMask= */ 0, + /* required= */ false, + /* enforceUtf8= */ false, + /* oneof= */ null, + /* oneofStoredType= */ null, + /* mapDefaultEntry= */ null, + /* enumVerifier= */ null, + cachedSizeField); + } + + /** Constructs a new descriptor for a repeated message field. */ + public static FieldInfo forRepeatedMessageField( + Field field, int fieldNumber, FieldType fieldType, Class messageClass) { + checkFieldNumber(fieldNumber); + checkNotNull(field, "field"); + checkNotNull(fieldType, "fieldType"); + checkNotNull(messageClass, "messageClass"); + return new FieldInfo( + field, + fieldNumber, + fieldType, + messageClass, + /* presenceField= */ null, + /* presenceMask= */ 0, + /* required= */ false, + /* enforceUtf8= */ false, + /* oneof= */ null, + /* oneofStoredType= */ null, + /* mapDefaultEntry= */ null, + /* enumVerifier= */ null, + /* cachedSizeField= */ null); + } + + public static FieldInfo forFieldWithEnumVerifier( + Field field, int fieldNumber, FieldType fieldType, EnumVerifier enumVerifier) { + checkFieldNumber(fieldNumber); + checkNotNull(field, "field"); + return new FieldInfo( + field, + fieldNumber, + fieldType, + /* messageClass= */ null, + /* presenceField= */ null, + /* presenceMask= */ 0, + /* required= */ false, + /* enforceUtf8= */ false, + /* oneof= */ null, + /* oneofStoredType= */ null, + /* mapDefaultEntry= */ null, + enumVerifier, + /* cachedSizeField= */ null); + } + + public static FieldInfo forPackedFieldWithEnumVerifier( + Field field, + int fieldNumber, + FieldType fieldType, + EnumVerifier enumVerifier, + Field cachedSizeField) { + checkFieldNumber(fieldNumber); + checkNotNull(field, "field"); + return new FieldInfo( + field, + fieldNumber, + fieldType, + /* messageClass= */ null, + /* presenceField= */ null, + /* presenceMask= */ 0, + /* required= */ false, + /* enforceUtf8= */ false, + /* oneof= */ null, + /* oneofStoredType= */ null, + /* mapDefaultEntry= */ null, + enumVerifier, + cachedSizeField); + } + + /** Constructor for a proto2 optional field. */ + public static FieldInfo forProto2OptionalField( + Field field, + int fieldNumber, + FieldType fieldType, + Field presenceField, + int presenceMask, + boolean enforceUtf8, + EnumVerifier enumVerifier) { + checkFieldNumber(fieldNumber); + checkNotNull(field, "field"); + checkNotNull(fieldType, "fieldType"); + checkNotNull(presenceField, "presenceField"); + if (presenceField != null && !isExactlyOneBitSet(presenceMask)) { + throw new IllegalArgumentException( + "presenceMask must have exactly one bit set: " + presenceMask); + } + return new FieldInfo( + field, + fieldNumber, + fieldType, + /* messageClass= */ null, + presenceField, + presenceMask, + /* required= */ false, + enforceUtf8, + /* oneof= */ null, + /* oneofStoredType= */ null, + /* mapDefaultEntry= */ null, + enumVerifier, + /* cachedSizeField= */ null); + } + + /** + * Constructor for a field that is part of a oneof. + * + * @param fieldNumber the unique field number for this field within the message. + * @param fieldType the type of the field (must be non-null). + * @param oneof the oneof for which this field is associated (must be non-null). + * @param oneofStoredType the actual type stored in the oneof value for this field. Since the + * oneof value is an {@link Object}, primitives will store their boxed type. Must be non-null. + * @param enforceUtf8 Only used for string fields. If {@code true}, will enforce UTF-8 on a string + * field. + * @return the {@link FieldInfo} describing this field. + */ + public static FieldInfo forOneofMemberField( + int fieldNumber, + FieldType fieldType, + OneofInfo oneof, + Class oneofStoredType, + boolean enforceUtf8, + EnumVerifier enumVerifier) { + checkFieldNumber(fieldNumber); + checkNotNull(fieldType, "fieldType"); + checkNotNull(oneof, "oneof"); + checkNotNull(oneofStoredType, "oneofStoredType"); + if (!fieldType.isScalar()) { + throw new IllegalArgumentException( + "Oneof is only supported for scalar fields. Field " + + fieldNumber + + " is of type " + + fieldType); + } + return new FieldInfo( + /* field= */ null, + fieldNumber, + fieldType, + /* messageClass= */ null, + /* presenceField= */ null, + /* presenceMask= */ 0, + /* required= */ false, + enforceUtf8, + oneof, + oneofStoredType, + /* mapDefaultEntry= */ null, + enumVerifier, + /* cachedSizeField= */ null); + } + + private static void checkFieldNumber(int fieldNumber) { + if (fieldNumber <= 0) { + throw new IllegalArgumentException("fieldNumber must be positive: " + fieldNumber); + } + } + + /** Constructor for a proto2 required field. */ + public static FieldInfo forProto2RequiredField( + Field field, + int fieldNumber, + FieldType fieldType, + Field presenceField, + int presenceMask, + boolean enforceUtf8, + EnumVerifier enumVerifier) { + checkFieldNumber(fieldNumber); + checkNotNull(field, "field"); + checkNotNull(fieldType, "fieldType"); + checkNotNull(presenceField, "presenceField"); + if (presenceField != null && !isExactlyOneBitSet(presenceMask)) { + throw new IllegalArgumentException( + "presenceMask must have exactly one bit set: " + presenceMask); + } + return new FieldInfo( + field, + fieldNumber, + fieldType, + /* messageClass= */ null, + presenceField, + presenceMask, + /* required= */ true, + enforceUtf8, + /* oneof= */ null, + /* oneofStoredType= */ null, + /* mapDefaultEntry= */ null, + /* enumVerifier= */ enumVerifier, + /* cachedSizeField= */ null); + } + + public static FieldInfo forMapField( + Field field, int fieldNumber, Object mapDefaultEntry, EnumVerifier enumVerifier) { + checkNotNull(mapDefaultEntry, "mapDefaultEntry"); + checkFieldNumber(fieldNumber); + checkNotNull(field, "field"); + return new FieldInfo( + field, + fieldNumber, + FieldType.MAP, + /* messageClass= */ null, + /* presenceField= */ null, + /* presenceMask= */ 0, + /* required= */ false, + /* enforceUtf8= */ true, + /* oneof= */ null, + /* oneofStoredType= */ null, + mapDefaultEntry, + enumVerifier, + /* cachedSizeField= */ null); + } + + private FieldInfo( + Field field, + int fieldNumber, + FieldType type, + Class messageClass, + Field presenceField, + int presenceMask, + boolean required, + boolean enforceUtf8, + OneofInfo oneof, + Class oneofStoredType, + Object mapDefaultEntry, + EnumVerifier enumVerifier, + Field cachedSizeField) { + this.field = field; + this.type = type; + this.messageClass = messageClass; + this.fieldNumber = fieldNumber; + this.presenceField = presenceField; + this.presenceMask = presenceMask; + this.required = required; + this.enforceUtf8 = enforceUtf8; + this.oneof = oneof; + this.oneofStoredType = oneofStoredType; + this.mapDefaultEntry = mapDefaultEntry; + this.enumVerifier = enumVerifier; + this.cachedSizeField = cachedSizeField; + } + + /** Gets the field number for the field. */ + public int getFieldNumber() { + return fieldNumber; + } + + /** Gets the subject {@link Field} of this descriptor. */ + public Field getField() { + return field; + } + + /** Gets the type information for the field. */ + public FieldType getType() { + return type; + } + + /** Gets the oneof for which this field is a member, or {@code null} if not part of a oneof. */ + public OneofInfo getOneof() { + return oneof; + } + + /** + * Gets the actual type stored in the oneof value by this field. Since the oneof value is an + * {@link Object}, primitives will store their boxed type. For non-oneof fields, this will always + * be {@code null}. + */ + public Class getOneofStoredType() { + return oneofStoredType; + } + + /** Gets the {@code EnumVerifier} if the field is an enum field. */ + public EnumVerifier getEnumVerifier() { + return enumVerifier; + } + + @Override + public int compareTo(FieldInfo o) { + return fieldNumber - o.fieldNumber; + } + + /** + * For repeated message fields, returns the message type of the field. For other fields, returns + * {@code null}. + */ + public Class getListElementType() { + return messageClass; + } + + /** Gets the presence bit field. Only valid for unary fields. For lists, returns {@code null}. */ + public Field getPresenceField() { + return presenceField; + } + + public Object getMapDefaultEntry() { + return mapDefaultEntry; + } + + /** + * If {@link #getPresenceField()} is non-{@code null}, returns the mask used to identify the + * presence bit for this field in the message. + */ + public int getPresenceMask() { + return presenceMask; + } + + /** Whether this is a required field. */ + public boolean isRequired() { + return required; + } + + /** + * Whether a UTF-8 should be enforced on string fields. Only applies to strings and string lists. + */ + public boolean isEnforceUtf8() { + return enforceUtf8; + } + + public Field getCachedSizeField() { + return cachedSizeField; + } + + /** + * For singular or repeated message fields, returns the message type. For other fields, returns + * {@code null}. + */ + public Class getMessageFieldClass() { + switch (type) { + case MESSAGE: + case GROUP: + return field != null ? field.getType() : oneofStoredType; + case MESSAGE_LIST: + case GROUP_LIST: + return messageClass; + default: + return null; + } + } + + public static Builder newBuilder() { + return new Builder(); + } + + /** A builder for {@link FieldInfo} instances. */ + public static final class Builder { + private Field field; + private FieldType type; + private int fieldNumber; + private Field presenceField; + private int presenceMask; + private boolean required; + private boolean enforceUtf8; + private OneofInfo oneof; + private Class oneofStoredType; + private Object mapDefaultEntry; + private EnumVerifier enumVerifier; + private Field cachedSizeField; + + private Builder() {} + + /** + * Specifies the actual field on the message represented by this field. This should not be + * called for oneof member fields. + */ + public Builder withField(Field field) { + if (oneof != null) { + throw new IllegalStateException("Cannot set field when building a oneof."); + } + this.field = field; + return this; + } + + /** Specifies the type of this field. */ + public Builder withType(FieldType type) { + this.type = type; + return this; + } + + /** Specifies the unique field number for this field within the message. */ + public Builder withFieldNumber(int fieldNumber) { + this.fieldNumber = fieldNumber; + return this; + } + + /** Specifies proto2 presence information. This should not be called for oneof fields. */ + public Builder withPresence(Field presenceField, int presenceMask) { + this.presenceField = checkNotNull(presenceField, "presenceField"); + this.presenceMask = presenceMask; + return this; + } + + /** + * Sets the information for building a oneof member field. This is incompatible with {@link + * #withField(Field)} and {@link #withPresence(Field, int)}. + * + * @param oneof the oneof for which this field is associated. + * @param oneofStoredType the actual type stored in the oneof value for this field. Since the + * oneof value is an {@link Object}, primitives will store their boxed type. + */ + public Builder withOneof(OneofInfo oneof, Class oneofStoredType) { + if (field != null || presenceField != null) { + throw new IllegalStateException( + "Cannot set oneof when field or presenceField have been provided"); + } + this.oneof = oneof; + this.oneofStoredType = oneofStoredType; + return this; + } + + public Builder withRequired(boolean required) { + this.required = required; + return this; + } + + public Builder withMapDefaultEntry(Object mapDefaultEntry) { + this.mapDefaultEntry = mapDefaultEntry; + return this; + } + + public Builder withEnforceUtf8(boolean enforceUtf8) { + this.enforceUtf8 = enforceUtf8; + return this; + } + + public Builder withEnumVerifier(EnumVerifier enumVerifier) { + this.enumVerifier = enumVerifier; + return this; + } + + public Builder withCachedSizeField(Field cachedSizeField) { + this.cachedSizeField = cachedSizeField; + return this; + } + + public FieldInfo build() { + if (oneof != null) { + return forOneofMemberField( + fieldNumber, type, oneof, oneofStoredType, enforceUtf8, enumVerifier); + } + if (mapDefaultEntry != null) { + return forMapField(field, fieldNumber, mapDefaultEntry, enumVerifier); + } + if (presenceField != null) { + if (required) { + return forProto2RequiredField( + field, fieldNumber, type, presenceField, presenceMask, enforceUtf8, enumVerifier); + } else { + return forProto2OptionalField( + field, fieldNumber, type, presenceField, presenceMask, enforceUtf8, enumVerifier); + } + } + if (enumVerifier != null) { + if (cachedSizeField == null) { + return forFieldWithEnumVerifier(field, fieldNumber, type, enumVerifier); + } else { + return forPackedFieldWithEnumVerifier( + field, fieldNumber, type, enumVerifier, cachedSizeField); + } + } else { + if (cachedSizeField == null) { + return forField(field, fieldNumber, type, enforceUtf8); + } else { + return forPackedField(field, fieldNumber, type, cachedSizeField); + } + } + } + } + + private static boolean isExactlyOneBitSet(int value) { + return value != 0 && (value & (value - 1)) == 0; + } +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/FieldMask.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/FieldMask.java new file mode 100644 index 0000000000000..1e026629c9706 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/FieldMask.java @@ -0,0 +1,750 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/field_mask.proto + +package com.google.protobuf; + +/** + *
+ * `FieldMask` represents a set of symbolic field paths, for example:
+ *     paths: "f.a"
+ *     paths: "f.b.d"
+ * Here `f` represents a field in some root message, `a` and `b`
+ * fields in the message found in `f`, and `d` a field found in the
+ * message in `f.b`.
+ * Field masks are used to specify a subset of fields that should be
+ * returned by a get operation or modified by an update operation.
+ * Field masks also have a custom JSON encoding (see below).
+ * # Field Masks in Projections
+ * When used in the context of a projection, a response message or
+ * sub-message is filtered by the API to only contain those fields as
+ * specified in the mask. For example, if the mask in the previous
+ * example is applied to a response message as follows:
+ *     f {
+ *       a : 22
+ *       b {
+ *         d : 1
+ *         x : 2
+ *       }
+ *       y : 13
+ *     }
+ *     z: 8
+ * The result will not contain specific values for fields x,y and z
+ * (their value will be set to the default, and omitted in proto text
+ * output):
+ *     f {
+ *       a : 22
+ *       b {
+ *         d : 1
+ *       }
+ *     }
+ * A repeated field is not allowed except at the last position of a
+ * paths string.
+ * If a FieldMask object is not present in a get operation, the
+ * operation applies to all fields (as if a FieldMask of all fields
+ * had been specified).
+ * Note that a field mask does not necessarily apply to the
+ * top-level response message. In case of a REST get operation, the
+ * field mask applies directly to the response, but in case of a REST
+ * list operation, the mask instead applies to each individual message
+ * in the returned resource list. In case of a REST custom method,
+ * other definitions may be used. Where the mask applies will be
+ * clearly documented together with its declaration in the API.  In
+ * any case, the effect on the returned resource/resources is required
+ * behavior for APIs.
+ * # Field Masks in Update Operations
+ * A field mask in update operations specifies which fields of the
+ * targeted resource are going to be updated. The API is required
+ * to only change the values of the fields as specified in the mask
+ * and leave the others untouched. If a resource is passed in to
+ * describe the updated values, the API ignores the values of all
+ * fields not covered by the mask.
+ * If a repeated field is specified for an update operation, new values will
+ * be appended to the existing repeated field in the target resource. Note that
+ * a repeated field is only allowed in the last position of a `paths` string.
+ * If a sub-message is specified in the last position of the field mask for an
+ * update operation, then new value will be merged into the existing sub-message
+ * in the target resource.
+ * For example, given the target message:
+ *     f {
+ *       b {
+ *         d: 1
+ *         x: 2
+ *       }
+ *       c: [1]
+ *     }
+ * And an update message:
+ *     f {
+ *       b {
+ *         d: 10
+ *       }
+ *       c: [2]
+ *     }
+ * then if the field mask is:
+ *  paths: ["f.b", "f.c"]
+ * then the result will be:
+ *     f {
+ *       b {
+ *         d: 10
+ *         x: 2
+ *       }
+ *       c: [1, 2]
+ *     }
+ * An implementation may provide options to override this default behavior for
+ * repeated and message fields.
+ * In order to reset a field's value to the default, the field must
+ * be in the mask and set to the default value in the provided resource.
+ * Hence, in order to reset all fields of a resource, provide a default
+ * instance of the resource and set all fields in the mask, or do
+ * not provide a mask as described below.
+ * If a field mask is not present on update, the operation applies to
+ * all fields (as if a field mask of all fields has been specified).
+ * Note that in the presence of schema evolution, this may mean that
+ * fields the client does not know and has therefore not filled into
+ * the request will be reset to their default. If this is unwanted
+ * behavior, a specific service may require a client to always specify
+ * a field mask, producing an error if not.
+ * As with get operations, the location of the resource which
+ * describes the updated values in the request message depends on the
+ * operation kind. In any case, the effect of the field mask is
+ * required to be honored by the API.
+ * ## Considerations for HTTP REST
+ * The HTTP kind of an update operation which uses a field mask must
+ * be set to PATCH instead of PUT in order to satisfy HTTP semantics
+ * (PUT must only be used for full updates).
+ * # JSON Encoding of Field Masks
+ * In JSON, a field mask is encoded as a single string where paths are
+ * separated by a comma. Fields name in each path are converted
+ * to/from lower-camel naming conventions.
+ * As an example, consider the following message declarations:
+ *     message Profile {
+ *       User user = 1;
+ *       Photo photo = 2;
+ *     }
+ *     message User {
+ *       string display_name = 1;
+ *       string address = 2;
+ *     }
+ * In proto a field mask for `Profile` may look as such:
+ *     mask {
+ *       paths: "user.display_name"
+ *       paths: "photo"
+ *     }
+ * In JSON, the same mask is represented as below:
+ *     {
+ *       mask: "user.displayName,photo"
+ *     }
+ * # Field Masks and Oneof Fields
+ * Field masks treat fields in oneofs just as regular fields. Consider the
+ * following message:
+ *     message SampleMessage {
+ *       oneof test_oneof {
+ *         string name = 4;
+ *         SubMessage sub_message = 9;
+ *       }
+ *     }
+ * The field mask can be:
+ *     mask {
+ *       paths: "name"
+ *     }
+ * Or:
+ *     mask {
+ *       paths: "sub_message"
+ *     }
+ * Note that oneof type names ("test_oneof" in this case) cannot be used in
+ * paths.
+ * ## Field Mask Verification
+ * The implementation of any API method which has a FieldMask type field in the
+ * request should verify the included field paths, and return an
+ * `INVALID_ARGUMENT` error if any path is unmappable.
+ * 
+ * + * Protobuf type {@code google.protobuf.FieldMask} + */ +public final class FieldMask extends + com.google.protobuf.GeneratedMessageLite< + FieldMask, FieldMask.Builder> implements + // @@protoc_insertion_point(message_implements:google.protobuf.FieldMask) + FieldMaskOrBuilder { + private FieldMask() { + paths_ = com.google.protobuf.GeneratedMessageLite.emptyProtobufList(); + } + public static final int PATHS_FIELD_NUMBER = 1; + private com.google.protobuf.Internal.ProtobufList paths_; + /** + *
+   * The set of field mask paths.
+   * 
+ * + * repeated string paths = 1; + * @return A list containing the paths. + */ + @java.lang.Override + public java.util.List getPathsList() { + return paths_; + } + /** + *
+   * The set of field mask paths.
+   * 
+ * + * repeated string paths = 1; + * @return The count of paths. + */ + @java.lang.Override + public int getPathsCount() { + return paths_.size(); + } + /** + *
+   * The set of field mask paths.
+   * 
+ * + * repeated string paths = 1; + * @param index The index of the element to return. + * @return The paths at the given index. + */ + @java.lang.Override + public java.lang.String getPaths(int index) { + return paths_.get(index); + } + /** + *
+   * The set of field mask paths.
+   * 
+ * + * repeated string paths = 1; + * @param index The index of the value to return. + * @return The bytes of the paths at the given index. + */ + @java.lang.Override + public com.google.protobuf.ByteString + getPathsBytes(int index) { + return com.google.protobuf.ByteString.copyFromUtf8( + paths_.get(index)); + } + private void ensurePathsIsMutable() { + com.google.protobuf.Internal.ProtobufList tmp = + paths_; if (!tmp.isModifiable()) { + paths_ = + com.google.protobuf.GeneratedMessageLite.mutableCopy(tmp); + } + } + /** + *
+   * The set of field mask paths.
+   * 
+ * + * repeated string paths = 1; + * @param index The index to set the value at. + * @param value The paths to set. + */ + private void setPaths( + int index, java.lang.String value) { + value.getClass(); + ensurePathsIsMutable(); + paths_.set(index, value); + } + /** + *
+   * The set of field mask paths.
+   * 
+ * + * repeated string paths = 1; + * @param value The paths to add. + */ + private void addPaths( + java.lang.String value) { + value.getClass(); + ensurePathsIsMutable(); + paths_.add(value); + } + /** + *
+   * The set of field mask paths.
+   * 
+ * + * repeated string paths = 1; + * @param values The paths to add. + */ + private void addAllPaths( + java.lang.Iterable values) { + ensurePathsIsMutable(); + com.google.protobuf.AbstractMessageLite.addAll( + values, paths_); + } + /** + *
+   * The set of field mask paths.
+   * 
+ * + * repeated string paths = 1; + */ + private void clearPaths() { + paths_ = com.google.protobuf.GeneratedMessageLite.emptyProtobufList(); + } + /** + *
+   * The set of field mask paths.
+   * 
+ * + * repeated string paths = 1; + * @param value The bytes of the paths to add. + */ + private void addPathsBytes( + com.google.protobuf.ByteString value) { + checkByteStringIsUtf8(value); + ensurePathsIsMutable(); + paths_.add(value.toStringUtf8()); + } + + public static com.google.protobuf.FieldMask parseFrom( + java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.FieldMask parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.FieldMask parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.FieldMask parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.FieldMask parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.FieldMask parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.FieldMask parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, 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.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, input, extensionRegistry); + } + public static com.google.protobuf.FieldMask parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return parseDelimitedFrom(DEFAULT_INSTANCE, input); + } + public static com.google.protobuf.FieldMask parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return parseDelimitedFrom(DEFAULT_INSTANCE, input, extensionRegistry); + } + public static com.google.protobuf.FieldMask parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, 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.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, input, extensionRegistry); + } + + public static Builder newBuilder() { + return (Builder) DEFAULT_INSTANCE.createBuilder(); + } + public static Builder newBuilder(com.google.protobuf.FieldMask prototype) { + return (Builder) DEFAULT_INSTANCE.createBuilder(prototype); + } + + /** + *
+   * `FieldMask` represents a set of symbolic field paths, for example:
+   *     paths: "f.a"
+   *     paths: "f.b.d"
+   * Here `f` represents a field in some root message, `a` and `b`
+   * fields in the message found in `f`, and `d` a field found in the
+   * message in `f.b`.
+   * Field masks are used to specify a subset of fields that should be
+   * returned by a get operation or modified by an update operation.
+   * Field masks also have a custom JSON encoding (see below).
+   * # Field Masks in Projections
+   * When used in the context of a projection, a response message or
+   * sub-message is filtered by the API to only contain those fields as
+   * specified in the mask. For example, if the mask in the previous
+   * example is applied to a response message as follows:
+   *     f {
+   *       a : 22
+   *       b {
+   *         d : 1
+   *         x : 2
+   *       }
+   *       y : 13
+   *     }
+   *     z: 8
+   * The result will not contain specific values for fields x,y and z
+   * (their value will be set to the default, and omitted in proto text
+   * output):
+   *     f {
+   *       a : 22
+   *       b {
+   *         d : 1
+   *       }
+   *     }
+   * A repeated field is not allowed except at the last position of a
+   * paths string.
+   * If a FieldMask object is not present in a get operation, the
+   * operation applies to all fields (as if a FieldMask of all fields
+   * had been specified).
+   * Note that a field mask does not necessarily apply to the
+   * top-level response message. In case of a REST get operation, the
+   * field mask applies directly to the response, but in case of a REST
+   * list operation, the mask instead applies to each individual message
+   * in the returned resource list. In case of a REST custom method,
+   * other definitions may be used. Where the mask applies will be
+   * clearly documented together with its declaration in the API.  In
+   * any case, the effect on the returned resource/resources is required
+   * behavior for APIs.
+   * # Field Masks in Update Operations
+   * A field mask in update operations specifies which fields of the
+   * targeted resource are going to be updated. The API is required
+   * to only change the values of the fields as specified in the mask
+   * and leave the others untouched. If a resource is passed in to
+   * describe the updated values, the API ignores the values of all
+   * fields not covered by the mask.
+   * If a repeated field is specified for an update operation, new values will
+   * be appended to the existing repeated field in the target resource. Note that
+   * a repeated field is only allowed in the last position of a `paths` string.
+   * If a sub-message is specified in the last position of the field mask for an
+   * update operation, then new value will be merged into the existing sub-message
+   * in the target resource.
+   * For example, given the target message:
+   *     f {
+   *       b {
+   *         d: 1
+   *         x: 2
+   *       }
+   *       c: [1]
+   *     }
+   * And an update message:
+   *     f {
+   *       b {
+   *         d: 10
+   *       }
+   *       c: [2]
+   *     }
+   * then if the field mask is:
+   *  paths: ["f.b", "f.c"]
+   * then the result will be:
+   *     f {
+   *       b {
+   *         d: 10
+   *         x: 2
+   *       }
+   *       c: [1, 2]
+   *     }
+   * An implementation may provide options to override this default behavior for
+   * repeated and message fields.
+   * In order to reset a field's value to the default, the field must
+   * be in the mask and set to the default value in the provided resource.
+   * Hence, in order to reset all fields of a resource, provide a default
+   * instance of the resource and set all fields in the mask, or do
+   * not provide a mask as described below.
+   * If a field mask is not present on update, the operation applies to
+   * all fields (as if a field mask of all fields has been specified).
+   * Note that in the presence of schema evolution, this may mean that
+   * fields the client does not know and has therefore not filled into
+   * the request will be reset to their default. If this is unwanted
+   * behavior, a specific service may require a client to always specify
+   * a field mask, producing an error if not.
+   * As with get operations, the location of the resource which
+   * describes the updated values in the request message depends on the
+   * operation kind. In any case, the effect of the field mask is
+   * required to be honored by the API.
+   * ## Considerations for HTTP REST
+   * The HTTP kind of an update operation which uses a field mask must
+   * be set to PATCH instead of PUT in order to satisfy HTTP semantics
+   * (PUT must only be used for full updates).
+   * # JSON Encoding of Field Masks
+   * In JSON, a field mask is encoded as a single string where paths are
+   * separated by a comma. Fields name in each path are converted
+   * to/from lower-camel naming conventions.
+   * As an example, consider the following message declarations:
+   *     message Profile {
+   *       User user = 1;
+   *       Photo photo = 2;
+   *     }
+   *     message User {
+   *       string display_name = 1;
+   *       string address = 2;
+   *     }
+   * In proto a field mask for `Profile` may look as such:
+   *     mask {
+   *       paths: "user.display_name"
+   *       paths: "photo"
+   *     }
+   * In JSON, the same mask is represented as below:
+   *     {
+   *       mask: "user.displayName,photo"
+   *     }
+   * # Field Masks and Oneof Fields
+   * Field masks treat fields in oneofs just as regular fields. Consider the
+   * following message:
+   *     message SampleMessage {
+   *       oneof test_oneof {
+   *         string name = 4;
+   *         SubMessage sub_message = 9;
+   *       }
+   *     }
+   * The field mask can be:
+   *     mask {
+   *       paths: "name"
+   *     }
+   * Or:
+   *     mask {
+   *       paths: "sub_message"
+   *     }
+   * Note that oneof type names ("test_oneof" in this case) cannot be used in
+   * paths.
+   * ## Field Mask Verification
+   * The implementation of any API method which has a FieldMask type field in the
+   * request should verify the included field paths, and return an
+   * `INVALID_ARGUMENT` error if any path is unmappable.
+   * 
+ * + * Protobuf type {@code google.protobuf.FieldMask} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessageLite.Builder< + com.google.protobuf.FieldMask, Builder> implements + // @@protoc_insertion_point(builder_implements:google.protobuf.FieldMask) + com.google.protobuf.FieldMaskOrBuilder { + // Construct using com.google.protobuf.FieldMask.newBuilder() + private Builder() { + super(DEFAULT_INSTANCE); + } + + + /** + *
+     * The set of field mask paths.
+     * 
+ * + * repeated string paths = 1; + * @return A list containing the paths. + */ + @java.lang.Override + public java.util.List + getPathsList() { + return java.util.Collections.unmodifiableList( + instance.getPathsList()); + } + /** + *
+     * The set of field mask paths.
+     * 
+ * + * repeated string paths = 1; + * @return The count of paths. + */ + @java.lang.Override + public int getPathsCount() { + return instance.getPathsCount(); + } + /** + *
+     * The set of field mask paths.
+     * 
+ * + * repeated string paths = 1; + * @param index The index of the element to return. + * @return The paths at the given index. + */ + @java.lang.Override + public java.lang.String getPaths(int index) { + return instance.getPaths(index); + } + /** + *
+     * The set of field mask paths.
+     * 
+ * + * repeated string paths = 1; + * @param index The index of the value to return. + * @return The bytes of the paths at the given index. + */ + @java.lang.Override + public com.google.protobuf.ByteString + getPathsBytes(int index) { + return instance.getPathsBytes(index); + } + /** + *
+     * The set of field mask paths.
+     * 
+ * + * repeated string paths = 1; + * @param index The index to set the value at. + * @param value The paths to set. + * @return This builder for chaining. + */ + public Builder setPaths( + int index, java.lang.String value) { + copyOnWrite(); + instance.setPaths(index, value); + return this; + } + /** + *
+     * The set of field mask paths.
+     * 
+ * + * repeated string paths = 1; + * @param value The paths to add. + * @return This builder for chaining. + */ + public Builder addPaths( + java.lang.String value) { + copyOnWrite(); + instance.addPaths(value); + return this; + } + /** + *
+     * The set of field mask paths.
+     * 
+ * + * repeated string paths = 1; + * @param values The paths to add. + * @return This builder for chaining. + */ + public Builder addAllPaths( + java.lang.Iterable values) { + copyOnWrite(); + instance.addAllPaths(values); + return this; + } + /** + *
+     * The set of field mask paths.
+     * 
+ * + * repeated string paths = 1; + * @return This builder for chaining. + */ + public Builder clearPaths() { + copyOnWrite(); + instance.clearPaths(); + return this; + } + /** + *
+     * The set of field mask paths.
+     * 
+ * + * repeated string paths = 1; + * @param value The bytes of the paths to add. + * @return This builder for chaining. + */ + public Builder addPathsBytes( + com.google.protobuf.ByteString value) { + copyOnWrite(); + instance.addPathsBytes(value); + return this; + } + + // @@protoc_insertion_point(builder_scope:google.protobuf.FieldMask) + } + @java.lang.Override + @java.lang.SuppressWarnings({"unchecked", "fallthrough"}) + protected final java.lang.Object dynamicMethod( + com.google.protobuf.GeneratedMessageLite.MethodToInvoke method, + java.lang.Object arg0, java.lang.Object arg1) { + switch (method) { + case NEW_MUTABLE_INSTANCE: { + return new com.google.protobuf.FieldMask(); + } + case NEW_BUILDER: { + return new Builder(); + } + case BUILD_MESSAGE_INFO: { + java.lang.Object[] objects = new java.lang.Object[] { + "paths_", + }; + java.lang.String info = + "\u0000\u0001\u0000\u0000\u0001\u0001\u0001\u0000\u0001\u0000\u0001\u021a"; + return newMessageInfo(DEFAULT_INSTANCE, info, objects); + } + // fall through + case GET_DEFAULT_INSTANCE: { + return DEFAULT_INSTANCE; + } + case GET_PARSER: { + com.google.protobuf.Parser parser = PARSER; + if (parser == null) { + synchronized (com.google.protobuf.FieldMask.class) { + parser = PARSER; + if (parser == null) { + parser = + new DefaultInstanceBasedParser( + DEFAULT_INSTANCE); + PARSER = parser; + } + } + } + return parser; + } + case GET_MEMOIZED_IS_INITIALIZED: { + return (byte) 1; + } + case SET_MEMOIZED_IS_INITIALIZED: { + return null; + } + } + throw new UnsupportedOperationException(); + } + + + // @@protoc_insertion_point(class_scope:google.protobuf.FieldMask) + private static final com.google.protobuf.FieldMask DEFAULT_INSTANCE; + static { + FieldMask defaultInstance = new FieldMask(); + // New instances are implicitly immutable so no need to make + // immutable. + DEFAULT_INSTANCE = defaultInstance; + com.google.protobuf.GeneratedMessageLite.registerDefaultInstance( + FieldMask.class, defaultInstance); + } + + public static com.google.protobuf.FieldMask getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static volatile com.google.protobuf.Parser PARSER; + + public static com.google.protobuf.Parser parser() { + return DEFAULT_INSTANCE.getParserForType(); + } +} + diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/FieldMaskOrBuilder.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/FieldMaskOrBuilder.java new file mode 100644 index 0000000000000..198f81fe025ba --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/FieldMaskOrBuilder.java @@ -0,0 +1,50 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/field_mask.proto + +package com.google.protobuf; + +public interface FieldMaskOrBuilder extends + // @@protoc_insertion_point(interface_extends:google.protobuf.FieldMask) + com.google.protobuf.MessageLiteOrBuilder { + + /** + *
+   * The set of field mask paths.
+   * 
+ * + * repeated string paths = 1; + * @return A list containing the paths. + */ + java.util.List + getPathsList(); + /** + *
+   * The set of field mask paths.
+   * 
+ * + * repeated string paths = 1; + * @return The count of paths. + */ + int getPathsCount(); + /** + *
+   * The set of field mask paths.
+   * 
+ * + * repeated string paths = 1; + * @param index The index of the element to return. + * @return The paths at the given index. + */ + java.lang.String getPaths(int index); + /** + *
+   * The set of field mask paths.
+   * 
+ * + * repeated string paths = 1; + * @param index The index of the element to return. + * @return The paths at the given index. + */ + com.google.protobuf.ByteString + getPathsBytes(int index); +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/FieldMaskProto.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/FieldMaskProto.java new file mode 100644 index 0000000000000..2970c1601fcd5 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/FieldMaskProto.java @@ -0,0 +1,16 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/field_mask.proto + +package com.google.protobuf; + +public final class FieldMaskProto { + private FieldMaskProto() {} + public static void registerAllExtensions( + com.google.protobuf.ExtensionRegistryLite registry) { + } + + static { + } + + // @@protoc_insertion_point(outer_class_scope) +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/FieldOrBuilder.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/FieldOrBuilder.java new file mode 100644 index 0000000000000..d62250cc7844f --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/FieldOrBuilder.java @@ -0,0 +1,186 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/type.proto + +package com.google.protobuf; + +public interface FieldOrBuilder extends + // @@protoc_insertion_point(interface_extends:google.protobuf.Field) + com.google.protobuf.MessageLiteOrBuilder { + + /** + *
+   * The field type.
+   * 
+ * + * .google.protobuf.Field.Kind kind = 1; + * @return The enum numeric value on the wire for kind. + */ + int getKindValue(); + /** + *
+   * The field type.
+   * 
+ * + * .google.protobuf.Field.Kind kind = 1; + * @return The kind. + */ + com.google.protobuf.Field.Kind getKind(); + + /** + *
+   * The field cardinality.
+   * 
+ * + * .google.protobuf.Field.Cardinality cardinality = 2; + * @return The enum numeric value on the wire for cardinality. + */ + int getCardinalityValue(); + /** + *
+   * The field cardinality.
+   * 
+ * + * .google.protobuf.Field.Cardinality cardinality = 2; + * @return The cardinality. + */ + com.google.protobuf.Field.Cardinality getCardinality(); + + /** + *
+   * The field number.
+   * 
+ * + * int32 number = 3; + * @return The number. + */ + int getNumber(); + + /** + *
+   * The field name.
+   * 
+ * + * string name = 4; + * @return The name. + */ + java.lang.String getName(); + /** + *
+   * The field name.
+   * 
+ * + * string name = 4; + * @return The bytes for name. + */ + com.google.protobuf.ByteString + getNameBytes(); + + /** + *
+   * The field type URL, without the scheme, for message or enumeration
+   * types. Example: `"type.googleapis.com/google.protobuf.Timestamp"`.
+   * 
+ * + * string type_url = 6; + * @return The typeUrl. + */ + java.lang.String getTypeUrl(); + /** + *
+   * The field type URL, without the scheme, for message or enumeration
+   * types. Example: `"type.googleapis.com/google.protobuf.Timestamp"`.
+   * 
+ * + * string type_url = 6; + * @return The bytes for typeUrl. + */ + com.google.protobuf.ByteString + getTypeUrlBytes(); + + /** + *
+   * The index of the field type in `Type.oneofs`, for message or enumeration
+   * types. The first type has index 1; zero means the type is not in the list.
+   * 
+ * + * int32 oneof_index = 7; + * @return The oneofIndex. + */ + int getOneofIndex(); + + /** + *
+   * Whether to use alternative packed wire representation.
+   * 
+ * + * bool packed = 8; + * @return The packed. + */ + boolean getPacked(); + + /** + *
+   * The protocol buffer options.
+   * 
+ * + * repeated .google.protobuf.Option options = 9; + */ + java.util.List + getOptionsList(); + /** + *
+   * The protocol buffer options.
+   * 
+ * + * repeated .google.protobuf.Option options = 9; + */ + com.google.protobuf.Option getOptions(int index); + /** + *
+   * The protocol buffer options.
+   * 
+ * + * repeated .google.protobuf.Option options = 9; + */ + int getOptionsCount(); + + /** + *
+   * The field JSON name.
+   * 
+ * + * string json_name = 10; + * @return The jsonName. + */ + java.lang.String getJsonName(); + /** + *
+   * The field JSON name.
+   * 
+ * + * string json_name = 10; + * @return The bytes for jsonName. + */ + com.google.protobuf.ByteString + getJsonNameBytes(); + + /** + *
+   * The string value of the default value of this field. Proto2 syntax only.
+   * 
+ * + * string default_value = 11; + * @return The defaultValue. + */ + java.lang.String getDefaultValue(); + /** + *
+   * The string value of the default value of this field. Proto2 syntax only.
+   * 
+ * + * string default_value = 11; + * @return The bytes for defaultValue. + */ + com.google.protobuf.ByteString + getDefaultValueBytes(); +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/FieldSet.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/FieldSet.java new file mode 100644 index 0000000000000..f64b50a839ec2 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/FieldSet.java @@ -0,0 +1,1306 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +import static com.google.protobuf.Internal.checkNotNull; + +import com.google.protobuf.LazyField.LazyIterator; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +/** + * A class which represents an arbitrary set of fields of some message type. This is used to + * implement {@link DynamicMessage}, and also to represent extensions in {@link GeneratedMessage}. + * This class is package-private, since outside users should probably be using {@link + * DynamicMessage}. + * + * @author kenton@google.com Kenton Varda + */ +final class FieldSet> { + /** + * Interface for a FieldDescriptor or lite extension descriptor. This prevents FieldSet from + * depending on {@link Descriptors.FieldDescriptor}. + */ + public interface FieldDescriptorLite> extends Comparable { + int getNumber(); + + WireFormat.FieldType getLiteType(); + + WireFormat.JavaType getLiteJavaType(); + + boolean isRepeated(); + + boolean isPacked(); + + Internal.EnumLiteMap getEnumType(); + + // If getLiteJavaType() == MESSAGE, this merges a message object of the + // type into a builder of the type. Returns {@code to}. + MessageLite.Builder internalMergeFrom(MessageLite.Builder to, MessageLite from); + } + + private static final int DEFAULT_FIELD_MAP_ARRAY_SIZE = 16; + + private final SmallSortedMap fields; + private boolean isImmutable; + private boolean hasLazyField; + + /** Construct a new FieldSet. */ + private FieldSet() { + this.fields = SmallSortedMap.newFieldMap(DEFAULT_FIELD_MAP_ARRAY_SIZE); + } + + /** Construct an empty FieldSet. This is only used to initialize DEFAULT_INSTANCE. */ + @SuppressWarnings("unused") + private FieldSet(final boolean dummy) { + this(SmallSortedMap.newFieldMap(0)); + makeImmutable(); + } + + private FieldSet(SmallSortedMap fields) { + this.fields = fields; + makeImmutable(); + } + + /** Construct a new FieldSet. */ + public static > FieldSet newFieldSet() { + return new FieldSet(); + } + + /** Get an immutable empty FieldSet. */ + @SuppressWarnings("unchecked") + public static > FieldSet emptySet() { + return DEFAULT_INSTANCE; + } + + /** Construct a new Builder. */ + public static > Builder newBuilder() { + return new Builder(); + } + + @SuppressWarnings("rawtypes") + private static final FieldSet DEFAULT_INSTANCE = new FieldSet(true); + + /** Returns {@code true} if empty, {@code false} otherwise. */ + boolean isEmpty() { + return fields.isEmpty(); + } + + /** Make this FieldSet immutable from this point forward. */ + public void makeImmutable() { + if (isImmutable) { + return; + } + fields.makeImmutable(); + isImmutable = true; + } + + /** + * Returns whether the FieldSet is immutable. This is true if it is the {@link #emptySet} or if + * {@link #makeImmutable} were called. + * + * @return whether the FieldSet is immutable. + */ + public boolean isImmutable() { + return isImmutable; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + + if (!(o instanceof FieldSet)) { + return false; + } + + FieldSet other = (FieldSet) o; + return fields.equals(other.fields); + } + + @Override + public int hashCode() { + return fields.hashCode(); + } + + /** + * Clones the FieldSet. The returned FieldSet will be mutable even if the original FieldSet was + * immutable. + * + * @return the newly cloned FieldSet + */ + @Override + public FieldSet clone() { + // We can't just call fields.clone because List objects in the map + // should not be shared. + FieldSet clone = FieldSet.newFieldSet(); + for (int i = 0; i < fields.getNumArrayEntries(); i++) { + Map.Entry entry = fields.getArrayEntryAt(i); + clone.setField(entry.getKey(), entry.getValue()); + } + for (Map.Entry entry : fields.getOverflowEntries()) { + clone.setField(entry.getKey(), entry.getValue()); + } + clone.hasLazyField = hasLazyField; + return clone; + } + + + // ================================================================= + + /** See {@link Message.Builder#clear()}. */ + public void clear() { + fields.clear(); + hasLazyField = false; + } + + /** Get a simple map containing all the fields. */ + public Map getAllFields() { + if (hasLazyField) { + SmallSortedMap result = cloneAllFieldsMap(fields, /* copyList */ false); + if (fields.isImmutable()) { + result.makeImmutable(); + } + return result; + } + return fields.isImmutable() ? fields : Collections.unmodifiableMap(fields); + } + + private static > SmallSortedMap cloneAllFieldsMap( + SmallSortedMap fields, boolean copyList) { + SmallSortedMap result = SmallSortedMap.newFieldMap(DEFAULT_FIELD_MAP_ARRAY_SIZE); + for (int i = 0; i < fields.getNumArrayEntries(); i++) { + cloneFieldEntry(result, fields.getArrayEntryAt(i), copyList); + } + for (Map.Entry entry : fields.getOverflowEntries()) { + cloneFieldEntry(result, entry, copyList); + } + return result; + } + + private static > void cloneFieldEntry( + Map map, Map.Entry entry, boolean copyList) { + T key = entry.getKey(); + Object value = entry.getValue(); + if (value instanceof LazyField) { + map.put(key, ((LazyField) value).getValue()); + } else if (copyList && value instanceof List) { + map.put(key, new ArrayList<>((List) value)); + } else { + map.put(key, value); + } + } + + /** + * Get an iterator to the field map. This iterator should not be leaked out of the protobuf + * library as it is not protected from mutation when fields is not immutable. + */ + public Iterator> iterator() { + if (hasLazyField) { + return new LazyIterator(fields.entrySet().iterator()); + } + return fields.entrySet().iterator(); + } + + /** + * Get an iterator over the fields in the map in descending (i.e. reverse) order. This iterator + * should not be leaked out of the protobuf library as it is not protected from mutation when + * fields is not immutable. + */ + Iterator> descendingIterator() { + if (hasLazyField) { + return new LazyIterator(fields.descendingEntrySet().iterator()); + } + return fields.descendingEntrySet().iterator(); + } + + /** Useful for implementing {@link Message#hasField(Descriptors.FieldDescriptor)}. */ + public boolean hasField(final T descriptor) { + if (descriptor.isRepeated()) { + throw new IllegalArgumentException("hasField() can only be called on non-repeated fields."); + } + + return fields.get(descriptor) != null; + } + + /** + * Useful for implementing {@link Message#getField(Descriptors.FieldDescriptor)}. This method + * returns {@code null} if the field is not set; in this case it is up to the caller to fetch the + * field's default value. + */ + public Object getField(final T descriptor) { + Object o = fields.get(descriptor); + if (o instanceof LazyField) { + return ((LazyField) o).getValue(); + } + return o; + } + + /** + * Useful for implementing {@link Message.Builder#setField(Descriptors.FieldDescriptor,Object)}. + */ + @SuppressWarnings({"unchecked", "rawtypes"}) + public void setField(final T descriptor, Object value) { + if (descriptor.isRepeated()) { + if (!(value instanceof List)) { + throw new IllegalArgumentException( + "Wrong object type used with protocol message reflection."); + } + + // Wrap the contents in a new list so that the caller cannot change + // the list's contents after setting it. + final List newList = new ArrayList<>(); + newList.addAll((List) value); + for (final Object element : newList) { + verifyType(descriptor, element); + } + value = newList; + } else { + verifyType(descriptor, value); + } + + if (value instanceof LazyField) { + hasLazyField = true; + } + fields.put(descriptor, value); + } + + /** Useful for implementing {@link Message.Builder#clearField(Descriptors.FieldDescriptor)}. */ + public void clearField(final T descriptor) { + fields.remove(descriptor); + if (fields.isEmpty()) { + hasLazyField = false; + } + } + + /** Useful for implementing {@link Message#getRepeatedFieldCount(Descriptors.FieldDescriptor)}. */ + public int getRepeatedFieldCount(final T descriptor) { + if (!descriptor.isRepeated()) { + throw new IllegalArgumentException( + "getRepeatedField() can only be called on repeated fields."); + } + + final Object value = getField(descriptor); + if (value == null) { + return 0; + } else { + return ((List) value).size(); + } + } + + /** Useful for implementing {@link Message#getRepeatedField(Descriptors.FieldDescriptor,int)}. */ + public Object getRepeatedField(final T descriptor, final int index) { + if (!descriptor.isRepeated()) { + throw new IllegalArgumentException( + "getRepeatedField() can only be called on repeated fields."); + } + + final Object value = getField(descriptor); + + if (value == null) { + throw new IndexOutOfBoundsException(); + } else { + return ((List) value).get(index); + } + } + + /** + * Useful for implementing {@link + * Message.Builder#setRepeatedField(Descriptors.FieldDescriptor,int,Object)}. + */ + @SuppressWarnings("unchecked") + public void setRepeatedField(final T descriptor, final int index, final Object value) { + if (!descriptor.isRepeated()) { + throw new IllegalArgumentException( + "getRepeatedField() can only be called on repeated fields."); + } + + final Object list = getField(descriptor); + if (list == null) { + throw new IndexOutOfBoundsException(); + } + + verifyType(descriptor, value); + ((List) list).set(index, value); + } + + /** + * Useful for implementing {@link + * Message.Builder#addRepeatedField(Descriptors.FieldDescriptor,Object)}. + */ + @SuppressWarnings("unchecked") + public void addRepeatedField(final T descriptor, final Object value) { + if (!descriptor.isRepeated()) { + throw new IllegalArgumentException( + "addRepeatedField() can only be called on repeated fields."); + } + + verifyType(descriptor, value); + + final Object existingValue = getField(descriptor); + List list; + if (existingValue == null) { + list = new ArrayList(); + fields.put(descriptor, list); + } else { + list = (List) existingValue; + } + + list.add(value); + } + + /** + * Verifies that the given object is of the correct type to be a valid value for the given field. + * (For repeated fields, this checks if the object is the right type to be one element of the + * field.) + * + * @throws IllegalArgumentException The value is not of the right type. + */ + private void verifyType(final T descriptor, final Object value) { + if (!isValidType(descriptor.getLiteType(), value)) { + // TODO(kenton): When chaining calls to setField(), it can be hard to + // tell from the stack trace which exact call failed, since the whole + // chain is considered one line of code. It would be nice to print + // more information here, e.g. naming the field. We used to do that. + // But we can't now that FieldSet doesn't use descriptors. Maybe this + // isn't a big deal, though, since it would only really apply when using + // reflection and generally people don't chain reflection setters. + throw new IllegalArgumentException( + String.format( + "Wrong object type used with protocol message reflection.\n" + + "Field number: %d, field java type: %s, value type: %s\n", + descriptor.getNumber(), + descriptor.getLiteType().getJavaType(), + value.getClass().getName())); + } + } + + + private static boolean isValidType(final WireFormat.FieldType type, final Object value) { + checkNotNull(value); + switch (type.getJavaType()) { + case INT: + return value instanceof Integer; + case LONG: + return value instanceof Long; + case FLOAT: + return value instanceof Float; + case DOUBLE: + return value instanceof Double; + case BOOLEAN: + return value instanceof Boolean; + case STRING: + return value instanceof String; + case BYTE_STRING: + return value instanceof ByteString || value instanceof byte[]; + case ENUM: + // TODO(kenton): Caller must do type checking here, I guess. + return (value instanceof Integer || value instanceof Internal.EnumLite); + case MESSAGE: + // TODO(kenton): Caller must do type checking here, I guess. + return (value instanceof MessageLite) || (value instanceof LazyField); + } + return false; + } + + // ================================================================= + // Parsing and serialization + + /** + * See {@link Message#isInitialized()}. Note: Since {@code FieldSet} itself does not have any way + * of knowing about required fields that aren't actually present in the set, it is up to the + * caller to check that all required fields are present. + */ + public boolean isInitialized() { + for (int i = 0; i < fields.getNumArrayEntries(); i++) { + if (!isInitialized(fields.getArrayEntryAt(i))) { + return false; + } + } + for (final Map.Entry entry : fields.getOverflowEntries()) { + if (!isInitialized(entry)) { + return false; + } + } + return true; + } + + @SuppressWarnings("unchecked") + private static > boolean isInitialized( + final Map.Entry entry) { + final T descriptor = entry.getKey(); + if (descriptor.getLiteJavaType() == WireFormat.JavaType.MESSAGE) { + if (descriptor.isRepeated()) { + for (final MessageLite element : (List) entry.getValue()) { + if (!element.isInitialized()) { + return false; + } + } + } else { + Object value = entry.getValue(); + if (value instanceof MessageLite) { + if (!((MessageLite) value).isInitialized()) { + return false; + } + } else if (value instanceof LazyField) { + return true; + } else { + throw new IllegalArgumentException( + "Wrong object type used with protocol message reflection."); + } + } + } + return true; + } + + /** + * Given a field type, return the wire type. + * + * @return One of the {@code WIRETYPE_} constants defined in {@link WireFormat}. + */ + static int getWireFormatForFieldType(final WireFormat.FieldType type, boolean isPacked) { + if (isPacked) { + return WireFormat.WIRETYPE_LENGTH_DELIMITED; + } else { + return type.getWireType(); + } + } + + /** Like {@link Message.Builder#mergeFrom(Message)}, but merges from another {@link FieldSet}. */ + public void mergeFrom(final FieldSet other) { + for (int i = 0; i < other.fields.getNumArrayEntries(); i++) { + mergeFromField(other.fields.getArrayEntryAt(i)); + } + for (final Map.Entry entry : other.fields.getOverflowEntries()) { + mergeFromField(entry); + } + } + + private static Object cloneIfMutable(Object value) { + if (value instanceof byte[]) { + byte[] bytes = (byte[]) value; + byte[] copy = new byte[bytes.length]; + System.arraycopy(bytes, 0, copy, 0, bytes.length); + return copy; + } else { + return value; + } + } + + @SuppressWarnings({"unchecked", "rawtypes"}) + private void mergeFromField(final Map.Entry entry) { + final T descriptor = entry.getKey(); + Object otherValue = entry.getValue(); + if (otherValue instanceof LazyField) { + otherValue = ((LazyField) otherValue).getValue(); + } + + if (descriptor.isRepeated()) { + Object value = getField(descriptor); + if (value == null) { + value = new ArrayList<>(); + } + for (Object element : (List) otherValue) { + ((List) value).add(cloneIfMutable(element)); + } + fields.put(descriptor, value); + } else if (descriptor.getLiteJavaType() == WireFormat.JavaType.MESSAGE) { + Object value = getField(descriptor); + if (value == null) { + fields.put(descriptor, cloneIfMutable(otherValue)); + } else { + // Merge the messages. + value = + descriptor + .internalMergeFrom(((MessageLite) value).toBuilder(), (MessageLite) otherValue) + .build(); + fields.put(descriptor, value); + } + } else { + fields.put(descriptor, cloneIfMutable(otherValue)); + } + } + + // TODO(kenton): Move static parsing and serialization methods into some + // other class. Probably WireFormat. + + /** + * Read a field of any primitive type for immutable messages from a CodedInputStream. Enums, + * groups, and embedded messages are not handled by this method. + * + * @param input The stream from which to read. + * @param type Declared type of the field. + * @param checkUtf8 When true, check that the input is valid utf8. + * @return An object representing the field's value, of the exact type which would be returned by + * {@link Message#getField(Descriptors.FieldDescriptor)} for this field. + */ + public static Object readPrimitiveField( + CodedInputStream input, final WireFormat.FieldType type, boolean checkUtf8) + throws IOException { + if (checkUtf8) { + return WireFormat.readPrimitiveField(input, type, WireFormat.Utf8Validation.STRICT); + } else { + return WireFormat.readPrimitiveField(input, type, WireFormat.Utf8Validation.LOOSE); + } + } + + + /** See {@link Message#writeTo(CodedOutputStream)}. */ + public void writeTo(final CodedOutputStream output) throws IOException { + for (int i = 0; i < fields.getNumArrayEntries(); i++) { + final Map.Entry entry = fields.getArrayEntryAt(i); + writeField(entry.getKey(), entry.getValue(), output); + } + for (final Map.Entry entry : fields.getOverflowEntries()) { + writeField(entry.getKey(), entry.getValue(), output); + } + } + + /** Like {@link #writeTo} but uses MessageSet wire format. */ + public void writeMessageSetTo(final CodedOutputStream output) throws IOException { + for (int i = 0; i < fields.getNumArrayEntries(); i++) { + writeMessageSetTo(fields.getArrayEntryAt(i), output); + } + for (final Map.Entry entry : fields.getOverflowEntries()) { + writeMessageSetTo(entry, output); + } + } + + private void writeMessageSetTo(final Map.Entry entry, final CodedOutputStream output) + throws IOException { + final T descriptor = entry.getKey(); + if (descriptor.getLiteJavaType() == WireFormat.JavaType.MESSAGE + && !descriptor.isRepeated() + && !descriptor.isPacked()) { + Object value = entry.getValue(); + if (value instanceof LazyField) { + value = ((LazyField) value).getValue(); + } + output.writeMessageSetExtension(entry.getKey().getNumber(), (MessageLite) value); + } else { + writeField(descriptor, entry.getValue(), output); + } + } + + /** + * Write a single tag-value pair to the stream. + * + * @param output The output stream. + * @param type The field's type. + * @param number The field's number. + * @param value Object representing the field's value. Must be of the exact type which would be + * returned by {@link Message#getField(Descriptors.FieldDescriptor)} for this field. + */ + static void writeElement( + final CodedOutputStream output, + final WireFormat.FieldType type, + final int number, + final Object value) + throws IOException { + // Special case for groups, which need a start and end tag; other fields + // can just use writeTag() and writeFieldNoTag(). + if (type == WireFormat.FieldType.GROUP) { + output.writeGroup(number, (MessageLite) value); + } else { + output.writeTag(number, getWireFormatForFieldType(type, false)); + writeElementNoTag(output, type, value); + } + } + + /** + * Write a field of arbitrary type, without its tag, to the stream. + * + * @param output The output stream. + * @param type The field's type. + * @param value Object representing the field's value. Must be of the exact type which would be + * returned by {@link Message#getField(Descriptors.FieldDescriptor)} for this field. + */ + static void writeElementNoTag( + final CodedOutputStream output, final WireFormat.FieldType type, final Object value) + throws IOException { + switch (type) { + case DOUBLE: + output.writeDoubleNoTag((Double) value); + break; + case FLOAT: + output.writeFloatNoTag((Float) value); + break; + case INT64: + output.writeInt64NoTag((Long) value); + break; + case UINT64: + output.writeUInt64NoTag((Long) value); + break; + case INT32: + output.writeInt32NoTag((Integer) value); + break; + case FIXED64: + output.writeFixed64NoTag((Long) value); + break; + case FIXED32: + output.writeFixed32NoTag((Integer) value); + break; + case BOOL: + output.writeBoolNoTag((Boolean) value); + break; + case GROUP: + output.writeGroupNoTag((MessageLite) value); + break; + case MESSAGE: + output.writeMessageNoTag((MessageLite) value); + break; + case STRING: + if (value instanceof ByteString) { + output.writeBytesNoTag((ByteString) value); + } else { + output.writeStringNoTag((String) value); + } + break; + case BYTES: + if (value instanceof ByteString) { + output.writeBytesNoTag((ByteString) value); + } else { + output.writeByteArrayNoTag((byte[]) value); + } + break; + case UINT32: + output.writeUInt32NoTag((Integer) value); + break; + case SFIXED32: + output.writeSFixed32NoTag((Integer) value); + break; + case SFIXED64: + output.writeSFixed64NoTag((Long) value); + break; + case SINT32: + output.writeSInt32NoTag((Integer) value); + break; + case SINT64: + output.writeSInt64NoTag((Long) value); + break; + + case ENUM: + if (value instanceof Internal.EnumLite) { + output.writeEnumNoTag(((Internal.EnumLite) value).getNumber()); + } else { + output.writeEnumNoTag(((Integer) value).intValue()); + } + break; + } + } + + /** Write a single field. */ + public static void writeField( + final FieldDescriptorLite descriptor, final Object value, final CodedOutputStream output) + throws IOException { + WireFormat.FieldType type = descriptor.getLiteType(); + int number = descriptor.getNumber(); + if (descriptor.isRepeated()) { + final List valueList = (List) value; + if (descriptor.isPacked()) { + output.writeTag(number, WireFormat.WIRETYPE_LENGTH_DELIMITED); + // Compute the total data size so the length can be written. + int dataSize = 0; + for (final Object element : valueList) { + dataSize += computeElementSizeNoTag(type, element); + } + output.writeRawVarint32(dataSize); + // Write the data itself, without any tags. + for (final Object element : valueList) { + writeElementNoTag(output, type, element); + } + } else { + for (final Object element : valueList) { + writeElement(output, type, number, element); + } + } + } else { + if (value instanceof LazyField) { + writeElement(output, type, number, ((LazyField) value).getValue()); + } else { + writeElement(output, type, number, value); + } + } + } + + /** + * See {@link Message#getSerializedSize()}. It's up to the caller to cache the resulting size if + * desired. + */ + public int getSerializedSize() { + int size = 0; + for (int i = 0; i < fields.getNumArrayEntries(); i++) { + final Map.Entry entry = fields.getArrayEntryAt(i); + size += computeFieldSize(entry.getKey(), entry.getValue()); + } + for (final Map.Entry entry : fields.getOverflowEntries()) { + size += computeFieldSize(entry.getKey(), entry.getValue()); + } + return size; + } + + /** Like {@link #getSerializedSize} but uses MessageSet wire format. */ + public int getMessageSetSerializedSize() { + int size = 0; + for (int i = 0; i < fields.getNumArrayEntries(); i++) { + size += getMessageSetSerializedSize(fields.getArrayEntryAt(i)); + } + for (final Map.Entry entry : fields.getOverflowEntries()) { + size += getMessageSetSerializedSize(entry); + } + return size; + } + + private int getMessageSetSerializedSize(final Map.Entry entry) { + final T descriptor = entry.getKey(); + Object value = entry.getValue(); + if (descriptor.getLiteJavaType() == WireFormat.JavaType.MESSAGE + && !descriptor.isRepeated() + && !descriptor.isPacked()) { + if (value instanceof LazyField) { + return CodedOutputStream.computeLazyFieldMessageSetExtensionSize( + entry.getKey().getNumber(), (LazyField) value); + } else { + return CodedOutputStream.computeMessageSetExtensionSize( + entry.getKey().getNumber(), (MessageLite) value); + } + } else { + return computeFieldSize(descriptor, value); + } + } + + /** + * Compute the number of bytes that would be needed to encode a single tag/value pair of arbitrary + * type. + * + * @param type The field's type. + * @param number The field's number. + * @param value Object representing the field's value. Must be of the exact type which would be + * returned by {@link Message#getField(Descriptors.FieldDescriptor)} for this field. + */ + static int computeElementSize( + final WireFormat.FieldType type, final int number, final Object value) { + int tagSize = CodedOutputStream.computeTagSize(number); + if (type == WireFormat.FieldType.GROUP) { + // Only count the end group tag for proto2 messages as for proto1 the end + // group tag will be counted as a part of getSerializedSize(). + tagSize *= 2; + } + return tagSize + computeElementSizeNoTag(type, value); + } + + /** + * Compute the number of bytes that would be needed to encode a particular value of arbitrary + * type, excluding tag. + * + * @param type The field's type. + * @param value Object representing the field's value. Must be of the exact type which would be + * returned by {@link Message#getField(Descriptors.FieldDescriptor)} for this field. + */ + static int computeElementSizeNoTag(final WireFormat.FieldType type, final Object value) { + switch (type) { + // Note: Minor violation of 80-char limit rule here because this would + // actually be harder to read if we wrapped the lines. + case DOUBLE: + return CodedOutputStream.computeDoubleSizeNoTag((Double) value); + case FLOAT: + return CodedOutputStream.computeFloatSizeNoTag((Float) value); + case INT64: + return CodedOutputStream.computeInt64SizeNoTag((Long) value); + case UINT64: + return CodedOutputStream.computeUInt64SizeNoTag((Long) value); + case INT32: + return CodedOutputStream.computeInt32SizeNoTag((Integer) value); + case FIXED64: + return CodedOutputStream.computeFixed64SizeNoTag((Long) value); + case FIXED32: + return CodedOutputStream.computeFixed32SizeNoTag((Integer) value); + case BOOL: + return CodedOutputStream.computeBoolSizeNoTag((Boolean) value); + case GROUP: + return CodedOutputStream.computeGroupSizeNoTag((MessageLite) value); + case BYTES: + if (value instanceof ByteString) { + return CodedOutputStream.computeBytesSizeNoTag((ByteString) value); + } else { + return CodedOutputStream.computeByteArraySizeNoTag((byte[]) value); + } + case STRING: + if (value instanceof ByteString) { + return CodedOutputStream.computeBytesSizeNoTag((ByteString) value); + } else { + return CodedOutputStream.computeStringSizeNoTag((String) value); + } + case UINT32: + return CodedOutputStream.computeUInt32SizeNoTag((Integer) value); + case SFIXED32: + return CodedOutputStream.computeSFixed32SizeNoTag((Integer) value); + case SFIXED64: + return CodedOutputStream.computeSFixed64SizeNoTag((Long) value); + case SINT32: + return CodedOutputStream.computeSInt32SizeNoTag((Integer) value); + case SINT64: + return CodedOutputStream.computeSInt64SizeNoTag((Long) value); + + case MESSAGE: + if (value instanceof LazyField) { + return CodedOutputStream.computeLazyFieldSizeNoTag((LazyField) value); + } else { + return CodedOutputStream.computeMessageSizeNoTag((MessageLite) value); + } + + case ENUM: + if (value instanceof Internal.EnumLite) { + return CodedOutputStream.computeEnumSizeNoTag(((Internal.EnumLite) value).getNumber()); + } else { + return CodedOutputStream.computeEnumSizeNoTag((Integer) value); + } + } + + throw new RuntimeException("There is no way to get here, but the compiler thinks otherwise."); + } + + /** Compute the number of bytes needed to encode a particular field. */ + public static int computeFieldSize(final FieldDescriptorLite descriptor, final Object value) { + WireFormat.FieldType type = descriptor.getLiteType(); + int number = descriptor.getNumber(); + if (descriptor.isRepeated()) { + if (descriptor.isPacked()) { + int dataSize = 0; + for (final Object element : (List) value) { + dataSize += computeElementSizeNoTag(type, element); + } + return dataSize + + CodedOutputStream.computeTagSize(number) + + CodedOutputStream.computeRawVarint32Size(dataSize); + } else { + int size = 0; + for (final Object element : (List) value) { + size += computeElementSize(type, number, element); + } + return size; + } + } else { + return computeElementSize(type, number, value); + } + } + + /** + * A FieldSet Builder that accept a {@link MessageLite.Builder} as a field value. This is useful + * for implementing methods in {@link MessageLite.Builder}. + */ + static final class Builder> { + + private SmallSortedMap fields; + private boolean hasLazyField; + private boolean isMutable; + private boolean hasNestedBuilders; + + private Builder() { + this(SmallSortedMap.newFieldMap(DEFAULT_FIELD_MAP_ARRAY_SIZE)); + } + + private Builder(SmallSortedMap fields) { + this.fields = fields; + this.isMutable = true; + } + + /** Creates the FieldSet */ + public FieldSet build() { + if (fields.isEmpty()) { + return FieldSet.emptySet(); + } + isMutable = false; + SmallSortedMap fieldsForBuild = fields; + if (hasNestedBuilders) { + // Make a copy of the fields map with all Builders replaced by Message. + fieldsForBuild = cloneAllFieldsMap(fields, /* copyList */ false); + replaceBuilders(fieldsForBuild); + } + FieldSet fieldSet = new FieldSet<>(fieldsForBuild); + fieldSet.hasLazyField = hasLazyField; + return fieldSet; + } + + private static > void replaceBuilders( + SmallSortedMap fieldMap) { + for (int i = 0; i < fieldMap.getNumArrayEntries(); i++) { + replaceBuilders(fieldMap.getArrayEntryAt(i)); + } + for (Map.Entry entry : fieldMap.getOverflowEntries()) { + replaceBuilders(entry); + } + } + + private static > void replaceBuilders( + Map.Entry entry) { + entry.setValue(replaceBuilders(entry.getKey(), entry.getValue())); + } + + private static > Object replaceBuilders( + T descriptor, Object value) { + if (value == null) { + return value; + } + if (descriptor.getLiteJavaType() == WireFormat.JavaType.MESSAGE) { + if (descriptor.isRepeated()) { + if (!(value instanceof List)) { + throw new IllegalStateException( + "Repeated field should contains a List but actually contains type: " + + value.getClass()); + } + @SuppressWarnings("unchecked") // We just check that value is an instance of List above. + List list = (List) value; + for (int i = 0; i < list.size(); i++) { + Object oldElement = list.get(i); + Object newElement = replaceBuilder(oldElement); + if (newElement != oldElement) { + // If the list contains a Message.Builder, then make a copy of that list and then + // modify the Message.Builder into a Message and return the new list. This way, the + // existing Message.Builder will still be able to modify the inner fields of the + // original FieldSet.Builder. + if (list == value) { + list = new ArrayList<>(list); + } + list.set(i, newElement); + } + } + return list; + } else { + return replaceBuilder(value); + } + } + return value; + } + + private static Object replaceBuilder(Object value) { + return (value instanceof MessageLite.Builder) ? ((MessageLite.Builder) value).build() : value; + } + + /** Returns a new Builder using the fields from {@code fieldSet}. */ + public static > Builder fromFieldSet(FieldSet fieldSet) { + Builder builder = new Builder(cloneAllFieldsMap(fieldSet.fields, /* copyList */ true)); + builder.hasLazyField = fieldSet.hasLazyField; + return builder; + } + + // ================================================================= + + /** Get a simple map containing all the fields. */ + public Map getAllFields() { + if (hasLazyField) { + SmallSortedMap result = cloneAllFieldsMap(fields, /* copyList */ false); + if (fields.isImmutable()) { + result.makeImmutable(); + } else { + replaceBuilders(result); + } + return result; + } + return fields.isImmutable() ? fields : Collections.unmodifiableMap(fields); + } + + /** Useful for implementing {@link Message#hasField(Descriptors.FieldDescriptor)}. */ + public boolean hasField(final T descriptor) { + if (descriptor.isRepeated()) { + throw new IllegalArgumentException("hasField() can only be called on non-repeated fields."); + } + + return fields.get(descriptor) != null; + } + + /** + * Useful for implementing {@link Message#getField(Descriptors.FieldDescriptor)}. This method + * returns {@code null} if the field is not set; in this case it is up to the caller to fetch + * the field's default value. + */ + public Object getField(final T descriptor) { + Object value = getFieldAllowBuilders(descriptor); + return replaceBuilders(descriptor, value); + } + + /** Same as {@link #getField(F)}, but allow a {@link MessageLite.Builder} to be returned. */ + Object getFieldAllowBuilders(final T descriptor) { + Object o = fields.get(descriptor); + if (o instanceof LazyField) { + return ((LazyField) o).getValue(); + } + return o; + } + + private void ensureIsMutable() { + if (!isMutable) { + fields = cloneAllFieldsMap(fields, /* copyList */ true); + isMutable = true; + } + } + + /** + * Useful for implementing {@link Message.Builder#setField(Descriptors.FieldDescriptor, + * Object)}. + */ + @SuppressWarnings({"unchecked", "rawtypes"}) + public void setField(final T descriptor, Object value) { + ensureIsMutable(); + if (descriptor.isRepeated()) { + if (!(value instanceof List)) { + throw new IllegalArgumentException( + "Wrong object type used with protocol message reflection."); + } + + // Wrap the contents in a new list so that the caller cannot change + // the list's contents after setting it. + final List newList = new ArrayList(); + newList.addAll((List) value); + for (final Object element : newList) { + verifyType(descriptor, element); + hasNestedBuilders = hasNestedBuilders || element instanceof MessageLite.Builder; + } + value = newList; + } else { + verifyType(descriptor, value); + } + + if (value instanceof LazyField) { + hasLazyField = true; + } + hasNestedBuilders = hasNestedBuilders || value instanceof MessageLite.Builder; + + fields.put(descriptor, value); + } + + /** Useful for implementing {@link Message.Builder#clearField(Descriptors.FieldDescriptor)}. */ + public void clearField(final T descriptor) { + ensureIsMutable(); + fields.remove(descriptor); + if (fields.isEmpty()) { + hasLazyField = false; + } + } + + /** + * Useful for implementing {@link Message#getRepeatedFieldCount(Descriptors.FieldDescriptor)}. + */ + public int getRepeatedFieldCount(final T descriptor) { + if (!descriptor.isRepeated()) { + throw new IllegalArgumentException( + "getRepeatedField() can only be called on repeated fields."); + } + + final Object value = getField(descriptor); + if (value == null) { + return 0; + } else { + return ((List) value).size(); + } + } + + /** + * Useful for implementing {@link Message#getRepeatedField(Descriptors.FieldDescriptor, int)}. + */ + public Object getRepeatedField(final T descriptor, final int index) { + if (hasNestedBuilders) { + ensureIsMutable(); + } + Object value = getRepeatedFieldAllowBuilders(descriptor, index); + return replaceBuilder(value); + } + + /** + * Same as {@link #getRepeatedField(F, int)}, but allow a {@link MessageLite.Builder} to be + * returned. + */ + Object getRepeatedFieldAllowBuilders(final T descriptor, final int index) { + if (!descriptor.isRepeated()) { + throw new IllegalArgumentException( + "getRepeatedField() can only be called on repeated fields."); + } + + final Object value = getFieldAllowBuilders(descriptor); + + if (value == null) { + throw new IndexOutOfBoundsException(); + } else { + return ((List) value).get(index); + } + } + + /** + * Useful for implementing {@link Message.Builder#setRepeatedField(Descriptors.FieldDescriptor, + * int, Object)}. + */ + @SuppressWarnings("unchecked") + public void setRepeatedField(final T descriptor, final int index, final Object value) { + ensureIsMutable(); + if (!descriptor.isRepeated()) { + throw new IllegalArgumentException( + "getRepeatedField() can only be called on repeated fields."); + } + + hasNestedBuilders = hasNestedBuilders || value instanceof MessageLite.Builder; + + final Object list = getField(descriptor); + if (list == null) { + throw new IndexOutOfBoundsException(); + } + + verifyType(descriptor, value); + ((List) list).set(index, value); + } + + /** + * Useful for implementing {@link Message.Builder#addRepeatedField(Descriptors.FieldDescriptor, + * Object)}. + */ + @SuppressWarnings("unchecked") + public void addRepeatedField(final T descriptor, final Object value) { + ensureIsMutable(); + if (!descriptor.isRepeated()) { + throw new IllegalArgumentException( + "addRepeatedField() can only be called on repeated fields."); + } + + hasNestedBuilders = hasNestedBuilders || value instanceof MessageLite.Builder; + + verifyType(descriptor, value); + + final Object existingValue = getField(descriptor); + List list; + if (existingValue == null) { + list = new ArrayList<>(); + fields.put(descriptor, list); + } else { + list = (List) existingValue; + } + + list.add(value); + } + + /** + * Verifies that the given object is of the correct type to be a valid value for the given + * field. (For repeated fields, this checks if the object is the right type to be one element of + * the field.) + * + * @throws IllegalArgumentException The value is not of the right type. + */ + private void verifyType(final T descriptor, final Object value) { + if (!FieldSet.isValidType(descriptor.getLiteType(), value)) { + // Builder can accept Message.Builder values even though FieldSet will reject. + if (descriptor.getLiteType().getJavaType() == WireFormat.JavaType.MESSAGE + && value instanceof MessageLite.Builder) { + return; + } + throw new IllegalArgumentException( + String.format( + "Wrong object type used with protocol message reflection.\n" + + "Field number: %d, field java type: %s, value type: %s\n", + descriptor.getNumber(), + descriptor.getLiteType().getJavaType(), + value.getClass().getName())); + } + } + + /** + * See {@link Message#isInitialized()}. Note: Since {@code FieldSet} itself does not have any + * way of knowing about required fields that aren't actually present in the set, it is up to the + * caller to check that all required fields are present. + */ + public boolean isInitialized() { + for (int i = 0; i < fields.getNumArrayEntries(); i++) { + if (!FieldSet.isInitialized(fields.getArrayEntryAt(i))) { + return false; + } + } + for (final Map.Entry entry : fields.getOverflowEntries()) { + if (!FieldSet.isInitialized(entry)) { + return false; + } + } + return true; + } + + /** + * Like {@link Message.Builder#mergeFrom(Message)}, but merges from another {@link FieldSet}. + */ + public void mergeFrom(final FieldSet other) { + ensureIsMutable(); + for (int i = 0; i < other.fields.getNumArrayEntries(); i++) { + mergeFromField(other.fields.getArrayEntryAt(i)); + } + for (final Map.Entry entry : other.fields.getOverflowEntries()) { + mergeFromField(entry); + } + } + + @SuppressWarnings({"unchecked", "rawtypes"}) + private void mergeFromField(final Map.Entry entry) { + final T descriptor = entry.getKey(); + Object otherValue = entry.getValue(); + if (otherValue instanceof LazyField) { + otherValue = ((LazyField) otherValue).getValue(); + } + + if (descriptor.isRepeated()) { + Object value = getField(descriptor); + if (value == null) { + value = new ArrayList<>(); + } + for (Object element : (List) otherValue) { + ((List) value).add(FieldSet.cloneIfMutable(element)); + } + fields.put(descriptor, value); + } else if (descriptor.getLiteJavaType() == WireFormat.JavaType.MESSAGE) { + Object value = getField(descriptor); + if (value == null) { + fields.put(descriptor, FieldSet.cloneIfMutable(otherValue)); + } else { + // Merge the messages. + if (value instanceof MessageLite.Builder) { + descriptor.internalMergeFrom((MessageLite.Builder) value, (MessageLite) otherValue); + } else { + value = + descriptor + .internalMergeFrom(((MessageLite) value).toBuilder(), (MessageLite) otherValue) + .build(); + fields.put(descriptor, value); + } + } + } else { + fields.put(descriptor, cloneIfMutable(otherValue)); + } + } + } +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/FieldType.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/FieldType.java new file mode 100644 index 0000000000000..72327537fd204 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/FieldType.java @@ -0,0 +1,344 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +import java.lang.reflect.Field; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.lang.reflect.TypeVariable; +import java.util.List; + +/** Enumeration identifying all relevant type information for a protobuf field. */ +@ExperimentalApi +public enum FieldType { + DOUBLE(0, Collection.SCALAR, JavaType.DOUBLE), + FLOAT(1, Collection.SCALAR, JavaType.FLOAT), + INT64(2, Collection.SCALAR, JavaType.LONG), + UINT64(3, Collection.SCALAR, JavaType.LONG), + INT32(4, Collection.SCALAR, JavaType.INT), + FIXED64(5, Collection.SCALAR, JavaType.LONG), + FIXED32(6, Collection.SCALAR, JavaType.INT), + BOOL(7, Collection.SCALAR, JavaType.BOOLEAN), + STRING(8, Collection.SCALAR, JavaType.STRING), + MESSAGE(9, Collection.SCALAR, JavaType.MESSAGE), + BYTES(10, Collection.SCALAR, JavaType.BYTE_STRING), + UINT32(11, Collection.SCALAR, JavaType.INT), + ENUM(12, Collection.SCALAR, JavaType.ENUM), + SFIXED32(13, Collection.SCALAR, JavaType.INT), + SFIXED64(14, Collection.SCALAR, JavaType.LONG), + SINT32(15, Collection.SCALAR, JavaType.INT), + SINT64(16, Collection.SCALAR, JavaType.LONG), + GROUP(17, Collection.SCALAR, JavaType.MESSAGE), + DOUBLE_LIST(18, Collection.VECTOR, JavaType.DOUBLE), + FLOAT_LIST(19, Collection.VECTOR, JavaType.FLOAT), + INT64_LIST(20, Collection.VECTOR, JavaType.LONG), + UINT64_LIST(21, Collection.VECTOR, JavaType.LONG), + INT32_LIST(22, Collection.VECTOR, JavaType.INT), + FIXED64_LIST(23, Collection.VECTOR, JavaType.LONG), + FIXED32_LIST(24, Collection.VECTOR, JavaType.INT), + BOOL_LIST(25, Collection.VECTOR, JavaType.BOOLEAN), + STRING_LIST(26, Collection.VECTOR, JavaType.STRING), + MESSAGE_LIST(27, Collection.VECTOR, JavaType.MESSAGE), + BYTES_LIST(28, Collection.VECTOR, JavaType.BYTE_STRING), + UINT32_LIST(29, Collection.VECTOR, JavaType.INT), + ENUM_LIST(30, Collection.VECTOR, JavaType.ENUM), + SFIXED32_LIST(31, Collection.VECTOR, JavaType.INT), + SFIXED64_LIST(32, Collection.VECTOR, JavaType.LONG), + SINT32_LIST(33, Collection.VECTOR, JavaType.INT), + SINT64_LIST(34, Collection.VECTOR, JavaType.LONG), + DOUBLE_LIST_PACKED(35, Collection.PACKED_VECTOR, JavaType.DOUBLE), + FLOAT_LIST_PACKED(36, Collection.PACKED_VECTOR, JavaType.FLOAT), + INT64_LIST_PACKED(37, Collection.PACKED_VECTOR, JavaType.LONG), + UINT64_LIST_PACKED(38, Collection.PACKED_VECTOR, JavaType.LONG), + INT32_LIST_PACKED(39, Collection.PACKED_VECTOR, JavaType.INT), + FIXED64_LIST_PACKED(40, Collection.PACKED_VECTOR, JavaType.LONG), + FIXED32_LIST_PACKED(41, Collection.PACKED_VECTOR, JavaType.INT), + BOOL_LIST_PACKED(42, Collection.PACKED_VECTOR, JavaType.BOOLEAN), + UINT32_LIST_PACKED(43, Collection.PACKED_VECTOR, JavaType.INT), + ENUM_LIST_PACKED(44, Collection.PACKED_VECTOR, JavaType.ENUM), + SFIXED32_LIST_PACKED(45, Collection.PACKED_VECTOR, JavaType.INT), + SFIXED64_LIST_PACKED(46, Collection.PACKED_VECTOR, JavaType.LONG), + SINT32_LIST_PACKED(47, Collection.PACKED_VECTOR, JavaType.INT), + SINT64_LIST_PACKED(48, Collection.PACKED_VECTOR, JavaType.LONG), + GROUP_LIST(49, Collection.VECTOR, JavaType.MESSAGE), + MAP(50, Collection.MAP, JavaType.VOID); + + private final JavaType javaType; + private final int id; + private final Collection collection; + private final Class elementType; + private final boolean primitiveScalar; + + FieldType(int id, Collection collection, JavaType javaType) { + this.id = id; + this.collection = collection; + this.javaType = javaType; + + switch (collection) { + case MAP: + elementType = javaType.getBoxedType(); + break; + case VECTOR: + elementType = javaType.getBoxedType(); + break; + case SCALAR: + default: + elementType = null; + break; + } + + boolean primitiveScalar = false; + if (collection == Collection.SCALAR) { + switch (javaType) { + case BYTE_STRING: + case MESSAGE: + case STRING: + break; + default: + primitiveScalar = true; + break; + } + } + this.primitiveScalar = primitiveScalar; + } + + /** A reliable unique identifier for this type. */ + public int id() { + return id; + } + + /** + * Gets the {@link JavaType} for this field. For lists, this identifies the type of the elements + * contained within the list. + */ + public JavaType getJavaType() { + return javaType; + } + + /** Indicates whether a list field should be represented on the wire in packed form. */ + public boolean isPacked() { + return Collection.PACKED_VECTOR.equals(collection); + } + + /** + * Indicates whether this field type represents a primitive scalar value. If this is {@code true}, + * then {@link #isScalar()} will also be {@code true}. + */ + public boolean isPrimitiveScalar() { + return primitiveScalar; + } + + /** Indicates whether this field type represents a scalar value. */ + public boolean isScalar() { + return collection == Collection.SCALAR; + } + + /** Indicates whether this field represents a list of values. */ + public boolean isList() { + return collection.isList(); + } + + /** Indicates whether this field represents a map. */ + public boolean isMap() { + return collection == Collection.MAP; + } + + /** Indicates whether or not this {@link FieldType} can be applied to the given {@link Field}. */ + public boolean isValidForField(Field field) { + if (Collection.VECTOR.equals(collection)) { + return isValidForList(field); + } else { + return javaType.getType().isAssignableFrom(field.getType()); + } + } + + private boolean isValidForList(Field field) { + Class clazz = field.getType(); + if (!javaType.getType().isAssignableFrom(clazz)) { + // The field isn't a List type. + return false; + } + Type[] types = EMPTY_TYPES; + Type genericType = field.getGenericType(); + if (genericType instanceof ParameterizedType) { + types = ((ParameterizedType) field.getGenericType()).getActualTypeArguments(); + } + Type listParameter = getListParameter(clazz, types); + if (!(listParameter instanceof Class)) { + // It's a wildcard, we should allow anything in the list. + return true; + } + return elementType.isAssignableFrom((Class) listParameter); + } + + /** + * Looks up the appropriate {@link FieldType} by it's identifier. + * + * @return the {@link FieldType} or {@code null} if not found. + */ + public static FieldType forId(int id) { + if (id < 0 || id >= VALUES.length) { + return null; + } + return VALUES[id]; + } + + private static final FieldType[] VALUES; + private static final Type[] EMPTY_TYPES = new Type[0]; + + static { + FieldType[] values = values(); + VALUES = new FieldType[values.length]; + for (FieldType type : values) { + VALUES[type.id] = type; + } + } + + /** + * Given a class, finds a generic super class or interface that extends {@link List}. + * + * @return the generic super class/interface, or {@code null} if not found. + */ + private static Type getGenericSuperList(Class clazz) { + // First look at interfaces. + Type[] genericInterfaces = clazz.getGenericInterfaces(); + for (Type genericInterface : genericInterfaces) { + if (genericInterface instanceof ParameterizedType) { + ParameterizedType parameterizedType = (ParameterizedType) genericInterface; + Class rawType = (Class) parameterizedType.getRawType(); + if (List.class.isAssignableFrom(rawType)) { + return genericInterface; + } + } + } + + // Try the subclass + Type type = clazz.getGenericSuperclass(); + if (type instanceof ParameterizedType) { + ParameterizedType parameterizedType = (ParameterizedType) type; + Class rawType = (Class) parameterizedType.getRawType(); + if (List.class.isAssignableFrom(rawType)) { + return type; + } + } + + // No super class/interface extends List. + return null; + } + + /** + * Inspects the inheritance hierarchy for the given class and finds the generic type parameter for + * {@link List}. + * + * @param clazz the class to begin the search. + * @param realTypes the array of actual type parameters for {@code clazz}. These will be used to + * substitute generic parameters up the inheritance hierarchy. If {@code clazz} does not have + * any generic parameters, this list should be empty. + * @return the {@link List} parameter. + */ + private static Type getListParameter(Class clazz, Type[] realTypes) { + top: + while (clazz != List.class) { + // First look at generic subclass and interfaces. + Type genericType = getGenericSuperList(clazz); + if (genericType instanceof ParameterizedType) { + // Replace any generic parameters with the real values. + ParameterizedType parameterizedType = (ParameterizedType) genericType; + Type[] superArgs = parameterizedType.getActualTypeArguments(); + for (int i = 0; i < superArgs.length; ++i) { + Type superArg = superArgs[i]; + if (superArg instanceof TypeVariable) { + // Get the type variables for this class so that we can match them to the variables + // used on the super class. + TypeVariable[] clazzParams = clazz.getTypeParameters(); + if (realTypes.length != clazzParams.length) { + throw new RuntimeException("Type array mismatch"); + } + + // Replace the variable parameter with the real type. + boolean foundReplacement = false; + for (int j = 0; j < clazzParams.length; ++j) { + if (superArg == clazzParams[j]) { + Type realType = realTypes[j]; + superArgs[i] = realType; + foundReplacement = true; + break; + } + } + if (!foundReplacement) { + throw new RuntimeException("Unable to find replacement for " + superArg); + } + } + } + + Class parent = (Class) parameterizedType.getRawType(); + + realTypes = superArgs; + clazz = parent; + continue; + } + + // None of the parameterized types inherit List. Just continue up the inheritance hierarchy + // toward the List interface until we can identify the parameters. + realTypes = EMPTY_TYPES; + for (Class iface : clazz.getInterfaces()) { + if (List.class.isAssignableFrom(iface)) { + clazz = iface; + continue top; + } + } + clazz = clazz.getSuperclass(); + } + + if (realTypes.length != 1) { + throw new RuntimeException("Unable to identify parameter type for List"); + } + return realTypes[0]; + } + + enum Collection { + SCALAR(false), + VECTOR(true), + PACKED_VECTOR(true), + MAP(false); + + private final boolean isList; + + Collection(boolean isList) { + this.isList = isList; + } + + /** @return the isList */ + public boolean isList() { + return isList; + } + } +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/FloatArrayList.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/FloatArrayList.java new file mode 100644 index 0000000000000..e6feba8a354c2 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/FloatArrayList.java @@ -0,0 +1,297 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +import static com.google.protobuf.Internal.checkNotNull; + +import com.google.protobuf.Internal.FloatList; +import java.util.Arrays; +import java.util.Collection; +import java.util.RandomAccess; + +/** + * An implementation of {@link FloatList} on top of a primitive array. + * + * @author dweis@google.com (Daniel Weis) + */ +final class FloatArrayList extends AbstractProtobufList + implements FloatList, RandomAccess, PrimitiveNonBoxingCollection { + + private static final FloatArrayList EMPTY_LIST = new FloatArrayList(new float[0], 0); + static { + EMPTY_LIST.makeImmutable(); + } + + public static FloatArrayList emptyList() { + return EMPTY_LIST; + } + + /** The backing store for the list. */ + private float[] array; + + /** + * The size of the list distinct from the length of the array. That is, it is the number of + * elements set in the list. + */ + private int size; + + /** Constructs a new mutable {@code FloatArrayList} with default capacity. */ + FloatArrayList() { + this(new float[DEFAULT_CAPACITY], 0); + } + + /** + * Constructs a new mutable {@code FloatArrayList} containing the same elements as {@code other}. + */ + private FloatArrayList(float[] other, int size) { + array = other; + this.size = size; + } + + @Override + protected void removeRange(int fromIndex, int toIndex) { + ensureIsMutable(); + if (toIndex < fromIndex) { + throw new IndexOutOfBoundsException("toIndex < fromIndex"); + } + + System.arraycopy(array, toIndex, array, fromIndex, size - toIndex); + size -= (toIndex - fromIndex); + modCount++; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof FloatArrayList)) { + return super.equals(o); + } + FloatArrayList other = (FloatArrayList) o; + if (size != other.size) { + return false; + } + + final float[] arr = other.array; + for (int i = 0; i < size; i++) { + if (Float.floatToIntBits(array[i]) != Float.floatToIntBits(arr[i])) { + return false; + } + } + + return true; + } + + @Override + public int hashCode() { + int result = 1; + for (int i = 0; i < size; i++) { + result = (31 * result) + Float.floatToIntBits(array[i]); + } + return result; + } + + @Override + public FloatList mutableCopyWithCapacity(int capacity) { + if (capacity < size) { + throw new IllegalArgumentException(); + } + return new FloatArrayList(Arrays.copyOf(array, capacity), size); + } + + @Override + public Float get(int index) { + return getFloat(index); + } + + @Override + public float getFloat(int index) { + ensureIndexInRange(index); + return array[index]; + } + + @Override + public int indexOf(Object element) { + if (!(element instanceof Float)) { + return -1; + } + float unboxedElement = (Float) element; + int numElems = size(); + for (int i = 0; i < numElems; i++) { + if (array[i] == unboxedElement) { + return i; + } + } + return -1; + } + + @Override + public boolean contains(Object element) { + return indexOf(element) != -1; + } + + @Override + public int size() { + return size; + } + + @Override + public Float set(int index, Float element) { + return setFloat(index, element); + } + + @Override + public float setFloat(int index, float element) { + ensureIsMutable(); + ensureIndexInRange(index); + float previousValue = array[index]; + array[index] = element; + return previousValue; + } + + @Override + public boolean add(Float element) { + addFloat(element); + return true; + } + + @Override + public void add(int index, Float element) { + addFloat(index, element); + } + + /** Like {@link #add(Float)} but more efficient in that it doesn't box the element. */ + @Override + public void addFloat(float element) { + ensureIsMutable(); + if (size == array.length) { + // Resize to 1.5x the size + int length = ((size * 3) / 2) + 1; + float[] newArray = new float[length]; + + System.arraycopy(array, 0, newArray, 0, size); + array = newArray; + } + + array[size++] = element; + } + + /** Like {@link #add(int, Float)} but more efficient in that it doesn't box the element. */ + private void addFloat(int index, float element) { + ensureIsMutable(); + if (index < 0 || index > size) { + throw new IndexOutOfBoundsException(makeOutOfBoundsExceptionMessage(index)); + } + + if (size < array.length) { + // Shift everything over to make room + System.arraycopy(array, index, array, index + 1, size - index); + } else { + // Resize to 1.5x the size + int length = ((size * 3) / 2) + 1; + float[] newArray = new float[length]; + + // Copy the first part directly + System.arraycopy(array, 0, newArray, 0, index); + + // Copy the rest shifted over by one to make room + System.arraycopy(array, index, newArray, index + 1, size - index); + array = newArray; + } + + array[index] = element; + size++; + modCount++; + } + + @Override + public boolean addAll(Collection collection) { + ensureIsMutable(); + + checkNotNull(collection); + + // We specialize when adding another FloatArrayList to avoid boxing elements. + if (!(collection instanceof FloatArrayList)) { + return super.addAll(collection); + } + + FloatArrayList list = (FloatArrayList) collection; + if (list.size == 0) { + return false; + } + + int overflow = Integer.MAX_VALUE - size; + if (overflow < list.size) { + // We can't actually represent a list this large. + throw new OutOfMemoryError(); + } + + int newSize = size + list.size; + if (newSize > array.length) { + array = Arrays.copyOf(array, newSize); + } + + System.arraycopy(list.array, 0, array, size, list.size); + size = newSize; + modCount++; + return true; + } + + @Override + public Float remove(int index) { + ensureIsMutable(); + ensureIndexInRange(index); + float value = array[index]; + if (index < size - 1) { + System.arraycopy(array, index + 1, array, index, size - index - 1); + } + size--; + modCount++; + return value; + } + + /** + * Ensures that the provided {@code index} is within the range of {@code [0, size]}. Throws an + * {@link IndexOutOfBoundsException} if it is not. + * + * @param index the index to verify is in range + */ + private void ensureIndexInRange(int index) { + if (index < 0 || index >= size) { + throw new IndexOutOfBoundsException(makeOutOfBoundsExceptionMessage(index)); + } + } + + private String makeOutOfBoundsExceptionMessage(int index) { + return "Index:" + index + ", Size:" + size; + } +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/FloatValue.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/FloatValue.java new file mode 100644 index 0000000000000..06e8566978184 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/FloatValue.java @@ -0,0 +1,276 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/wrappers.proto + +package com.google.protobuf; + +/** + *
+ * Wrapper message for `float`.
+ * The JSON representation for `FloatValue` is JSON number.
+ * 
+ * + * Protobuf type {@code google.protobuf.FloatValue} + */ +public final class FloatValue extends + com.google.protobuf.GeneratedMessageLite< + FloatValue, FloatValue.Builder> implements + // @@protoc_insertion_point(message_implements:google.protobuf.FloatValue) + FloatValueOrBuilder { + private FloatValue() { + } + public static final int VALUE_FIELD_NUMBER = 1; + private float value_; + /** + *
+   * The float value.
+   * 
+ * + * float value = 1; + * @return The value. + */ + @java.lang.Override + public float getValue() { + return value_; + } + /** + *
+   * The float value.
+   * 
+ * + * float value = 1; + * @param value The value to set. + */ + private void setValue(float value) { + + value_ = value; + } + /** + *
+   * The float value.
+   * 
+ * + * float value = 1; + */ + private void clearValue() { + + value_ = 0F; + } + + public static com.google.protobuf.FloatValue parseFrom( + java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.FloatValue parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.FloatValue parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.FloatValue parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.FloatValue parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.FloatValue parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.FloatValue parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, 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.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, input, extensionRegistry); + } + public static com.google.protobuf.FloatValue parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return parseDelimitedFrom(DEFAULT_INSTANCE, input); + } + public static com.google.protobuf.FloatValue parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return parseDelimitedFrom(DEFAULT_INSTANCE, input, extensionRegistry); + } + public static com.google.protobuf.FloatValue parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, 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.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, input, extensionRegistry); + } + + public static Builder newBuilder() { + return (Builder) DEFAULT_INSTANCE.createBuilder(); + } + public static Builder newBuilder(com.google.protobuf.FloatValue prototype) { + return (Builder) DEFAULT_INSTANCE.createBuilder(prototype); + } + + /** + *
+   * Wrapper message for `float`.
+   * The JSON representation for `FloatValue` is JSON number.
+   * 
+ * + * Protobuf type {@code google.protobuf.FloatValue} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessageLite.Builder< + com.google.protobuf.FloatValue, Builder> implements + // @@protoc_insertion_point(builder_implements:google.protobuf.FloatValue) + com.google.protobuf.FloatValueOrBuilder { + // Construct using com.google.protobuf.FloatValue.newBuilder() + private Builder() { + super(DEFAULT_INSTANCE); + } + + + /** + *
+     * The float value.
+     * 
+ * + * float value = 1; + * @return The value. + */ + @java.lang.Override + public float getValue() { + return instance.getValue(); + } + /** + *
+     * The float value.
+     * 
+ * + * float value = 1; + * @param value The value to set. + * @return This builder for chaining. + */ + public Builder setValue(float value) { + copyOnWrite(); + instance.setValue(value); + return this; + } + /** + *
+     * The float value.
+     * 
+ * + * float value = 1; + * @return This builder for chaining. + */ + public Builder clearValue() { + copyOnWrite(); + instance.clearValue(); + return this; + } + + // @@protoc_insertion_point(builder_scope:google.protobuf.FloatValue) + } + @java.lang.Override + @java.lang.SuppressWarnings({"unchecked", "fallthrough"}) + protected final java.lang.Object dynamicMethod( + com.google.protobuf.GeneratedMessageLite.MethodToInvoke method, + java.lang.Object arg0, java.lang.Object arg1) { + switch (method) { + case NEW_MUTABLE_INSTANCE: { + return new com.google.protobuf.FloatValue(); + } + case NEW_BUILDER: { + return new Builder(); + } + case BUILD_MESSAGE_INFO: { + java.lang.Object[] objects = new java.lang.Object[] { + "value_", + }; + java.lang.String info = + "\u0000\u0001\u0000\u0000\u0001\u0001\u0001\u0000\u0000\u0000\u0001\u0001"; + return newMessageInfo(DEFAULT_INSTANCE, info, objects); + } + // fall through + case GET_DEFAULT_INSTANCE: { + return DEFAULT_INSTANCE; + } + case GET_PARSER: { + com.google.protobuf.Parser parser = PARSER; + if (parser == null) { + synchronized (com.google.protobuf.FloatValue.class) { + parser = PARSER; + if (parser == null) { + parser = + new DefaultInstanceBasedParser( + DEFAULT_INSTANCE); + PARSER = parser; + } + } + } + return parser; + } + case GET_MEMOIZED_IS_INITIALIZED: { + return (byte) 1; + } + case SET_MEMOIZED_IS_INITIALIZED: { + return null; + } + } + throw new UnsupportedOperationException(); + } + + + // @@protoc_insertion_point(class_scope:google.protobuf.FloatValue) + private static final com.google.protobuf.FloatValue DEFAULT_INSTANCE; + static { + FloatValue defaultInstance = new FloatValue(); + // New instances are implicitly immutable so no need to make + // immutable. + DEFAULT_INSTANCE = defaultInstance; + com.google.protobuf.GeneratedMessageLite.registerDefaultInstance( + FloatValue.class, defaultInstance); + } + + public static com.google.protobuf.FloatValue getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + public static com.google.protobuf.FloatValue of(float value) { + return newBuilder().setValue(value).build(); + } + + private static volatile com.google.protobuf.Parser PARSER; + + public static com.google.protobuf.Parser parser() { + return DEFAULT_INSTANCE.getParserForType(); + } +} + diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/FloatValueOrBuilder.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/FloatValueOrBuilder.java new file mode 100644 index 0000000000000..d44feeb1eb621 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/FloatValueOrBuilder.java @@ -0,0 +1,19 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/wrappers.proto + +package com.google.protobuf; + +public interface FloatValueOrBuilder extends + // @@protoc_insertion_point(interface_extends:google.protobuf.FloatValue) + com.google.protobuf.MessageLiteOrBuilder { + + /** + *
+   * The float value.
+   * 
+ * + * float value = 1; + * @return The value. + */ + float getValue(); +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/GeneratedMessageInfoFactory.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/GeneratedMessageInfoFactory.java new file mode 100644 index 0000000000000..3e3efb929bc36 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/GeneratedMessageInfoFactory.java @@ -0,0 +1,65 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +/** A factory for message info that is generated into the message itself. */ +@ExperimentalApi +class GeneratedMessageInfoFactory implements MessageInfoFactory { + + private static final GeneratedMessageInfoFactory instance = new GeneratedMessageInfoFactory(); + + // Disallow construction - it's a singleton. + private GeneratedMessageInfoFactory() {} + + public static GeneratedMessageInfoFactory getInstance() { + return instance; + } + + @Override + public boolean isSupported(Class messageType) { + return GeneratedMessageLite.class.isAssignableFrom(messageType); + } + + @Override + public MessageInfo messageInfoFor(Class messageType) { + if (!GeneratedMessageLite.class.isAssignableFrom(messageType)) { + throw new IllegalArgumentException("Unsupported message type: " + messageType.getName()); + } + + try { + return (MessageInfo) GeneratedMessageLite.getDefaultInstance( + messageType.asSubclass(GeneratedMessageLite.class)) + .buildMessageInfo(); + } catch (Exception e) { + throw new RuntimeException("Unable to get message info for " + messageType.getName(), e); + } + } +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/GeneratedMessageLite.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/GeneratedMessageLite.java new file mode 100644 index 0000000000000..7db8f32ee019a --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/GeneratedMessageLite.java @@ -0,0 +1,1758 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +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; +import com.google.protobuf.Internal.IntList; +import com.google.protobuf.Internal.LongList; +import com.google.protobuf.Internal.ProtobufList; +import com.google.protobuf.WireFormat.FieldType; +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.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * Lite version of {@link GeneratedMessage}. + * + * @author kenton@google.com Kenton Varda + */ +public abstract class GeneratedMessageLite< + MessageType extends GeneratedMessageLite, + BuilderType extends GeneratedMessageLite.Builder> + extends AbstractMessageLite { + + /** For use by generated code only. Lazily initialized to reduce allocations. */ + protected UnknownFieldSetLite unknownFields = UnknownFieldSetLite.getDefaultInstance(); + + /** For use by generated code only. */ + protected int memoizedSerializedSize = -1; + + @Override + @SuppressWarnings("unchecked") // Guaranteed by runtime. + public final Parser getParserForType() { + return (Parser) dynamicMethod(MethodToInvoke.GET_PARSER); + } + + @Override + @SuppressWarnings("unchecked") // Guaranteed by runtime. + public final MessageType getDefaultInstanceForType() { + return (MessageType) dynamicMethod(MethodToInvoke.GET_DEFAULT_INSTANCE); + } + + @Override + @SuppressWarnings("unchecked") // Guaranteed by runtime. + public final BuilderType newBuilderForType() { + return (BuilderType) dynamicMethod(MethodToInvoke.NEW_BUILDER); + } + + /** + * A reflective toString function. This is primarily intended as a developer aid, while keeping + * binary size down. The first line of the {@code toString()} representation includes a commented + * version of {@code super.toString()} to act as an indicator that this should not be relied on + * for comparisons. + * + *

NOTE: This method relies on the field getter methods not being stripped or renamed by + * proguard. If they are, the fields will not be included in the returned string representation. + * + *

NOTE: This implementation is liable to change in the future, and should not be relied on in + * code. + */ + @Override + public String toString() { + return MessageLiteToString.toString(this, super.toString()); + } + + @SuppressWarnings("unchecked") // Guaranteed by runtime + @Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + memoizedHashCode = Protobuf.getInstance().schemaFor(this).hashCode(this); + return memoizedHashCode; + } + + @SuppressWarnings("unchecked") // Guaranteed by isInstance + runtime + @Override + public boolean equals( + Object other) { + if (this == other) { + return true; + } + + if (other == null) { + return false; + } + + if (this.getClass() != other.getClass()) { + return false; + } + + return Protobuf.getInstance().schemaFor(this).equals(this, (MessageType) other); + } + + // The general strategy for unknown fields is to use an UnknownFieldSetLite that is treated as + // mutable during the parsing constructor and immutable after. This allows us to avoid + // any unnecessary intermediary allocations while reducing the generated code size. + + /** Lazily initializes unknown fields. */ + private final void ensureUnknownFieldsInitialized() { + if (unknownFields == UnknownFieldSetLite.getDefaultInstance()) { + unknownFields = UnknownFieldSetLite.newInstance(); + } + } + + /** + * Called by subclasses to parse an unknown field. For use by generated code only. + * + * @return {@code true} unless the tag is an end-group tag. + */ + protected boolean parseUnknownField(int tag, CodedInputStream input) throws IOException { + // This will avoid the allocation of unknown fields when a group tag is encountered. + if (WireFormat.getTagWireType(tag) == WireFormat.WIRETYPE_END_GROUP) { + return false; + } + + ensureUnknownFieldsInitialized(); + return unknownFields.mergeFieldFrom(tag, input); + } + + /** Called by subclasses to parse an unknown field. For use by generated code only. */ + protected void mergeVarintField(int tag, int value) { + ensureUnknownFieldsInitialized(); + unknownFields.mergeVarintField(tag, value); + } + + /** Called by subclasses to parse an unknown field. For use by generated code only. */ + protected void mergeLengthDelimitedField(int fieldNumber, ByteString value) { + ensureUnknownFieldsInitialized(); + unknownFields.mergeLengthDelimitedField(fieldNumber, value); + } + + /** Called by subclasses to complete parsing. For use by generated code only. */ + protected void makeImmutable() { + Protobuf.getInstance().schemaFor(this).makeImmutable(this); + } + + protected final < + MessageType extends GeneratedMessageLite, + BuilderType extends GeneratedMessageLite.Builder> + BuilderType createBuilder() { + return (BuilderType) dynamicMethod(MethodToInvoke.NEW_BUILDER); + } + + protected final < + MessageType extends GeneratedMessageLite, + BuilderType extends GeneratedMessageLite.Builder> + BuilderType createBuilder(MessageType prototype) { + return ((BuilderType) createBuilder()).mergeFrom(prototype); + } + + @Override + public final boolean isInitialized() { + return isInitialized((MessageType) this, Boolean.TRUE); + } + + @Override + @SuppressWarnings("unchecked") + public final BuilderType toBuilder() { + BuilderType builder = (BuilderType) dynamicMethod(MethodToInvoke.NEW_BUILDER); + builder.mergeFrom((MessageType) this); + return builder; + } + + /** + * Defines which method path to invoke in {@link GeneratedMessageLite + * #dynamicMethod(MethodToInvoke, Object...)}. + * + *

For use by generated code only. + */ + public static enum MethodToInvoke { + // Rely on/modify instance state + GET_MEMOIZED_IS_INITIALIZED, + SET_MEMOIZED_IS_INITIALIZED, + + // Rely on static state + BUILD_MESSAGE_INFO, + NEW_MUTABLE_INSTANCE, + NEW_BUILDER, + GET_DEFAULT_INSTANCE, + GET_PARSER; + } + + /** + * A method that implements different types of operations described in {@link MethodToInvoke}. + * These different kinds of operations are required to implement message-level operations for + * builders in the runtime. This method bundles those operations to reduce the generated methods + * count. + * + *

    + *
  • {@code NEW_INSTANCE} returns a new instance of the protocol buffer that has not yet been + * made immutable. See {@code MAKE_IMMUTABLE}. + *
  • {@code IS_INITIALIZED} returns {@code null} for false and the default instance for true. + * It doesn't use or modify any memoized value. + *
  • {@code GET_MEMOIZED_IS_INITIALIZED} returns the memoized {@code isInitialized} byte + * value. + *
  • {@code SET_MEMOIZED_IS_INITIALIZED} sets the memoized {@code isInitialized} byte value to + * 1 if the first parameter is not null, or to 0 if the first parameter is null. + *
  • {@code NEW_BUILDER} returns a {@code BuilderType} instance. + *
+ * + * This method, plus the implementation of the Builder, enables the Builder class to be proguarded + * away entirely on Android. + * + *

For use by generated code only. + */ + protected abstract Object dynamicMethod(MethodToInvoke method, Object arg0, Object arg1); + + /** Same as {@link #dynamicMethod(MethodToInvoke, Object, Object)} with {@code null} padding. */ + protected Object dynamicMethod(MethodToInvoke method, Object arg0) { + return dynamicMethod(method, arg0, null); + } + + /** Same as {@link #dynamicMethod(MethodToInvoke, Object, Object)} with {@code null} padding. */ + protected Object dynamicMethod(MethodToInvoke method) { + return dynamicMethod(method, null, null); + } + + @Override + int getMemoizedSerializedSize() { + return memoizedSerializedSize; + } + + @Override + void setMemoizedSerializedSize(int size) { + memoizedSerializedSize = size; + } + + @Override + public void writeTo(CodedOutputStream output) throws IOException { + Protobuf.getInstance() + .schemaFor(this) + .writeTo(this, CodedOutputStreamWriter.forCodedOutput(output)); + } + + @Override + public int getSerializedSize() { + if (memoizedSerializedSize == -1) { + memoizedSerializedSize = Protobuf.getInstance().schemaFor(this).getSerializedSize(this); + } + return memoizedSerializedSize; + } + + /** Constructs a {@link MessageInfo} for this message type. */ + Object buildMessageInfo() throws Exception { + return dynamicMethod(MethodToInvoke.BUILD_MESSAGE_INFO); + } + + private static Map> defaultInstanceMap = + new ConcurrentHashMap>(); + + @SuppressWarnings("unchecked") + static > T getDefaultInstance(Class clazz) { + T result = (T) defaultInstanceMap.get(clazz); + if (result == null) { + // Foo.class does not initialize the class so we need to force the initialization in order to + // get the default instance registered. + try { + Class.forName(clazz.getName(), true, clazz.getClassLoader()); + } catch (ClassNotFoundException e) { + throw new IllegalStateException("Class initialization cannot fail.", e); + } + result = (T) defaultInstanceMap.get(clazz); + } + if (result == null) { + // On some Samsung devices, this still doesn't return a valid value for some reason. We add a + // reflective fallback to keep the device running. See b/114675342. + result = (T) UnsafeUtil.allocateInstance(clazz).getDefaultInstanceForType(); + // A sanity check to ensure that was actually invoked. + if (result == null) { + throw new IllegalStateException(); + } + defaultInstanceMap.put(clazz, result); + } + return result; + } + + protected static > void registerDefaultInstance( + Class clazz, T defaultInstance) { + defaultInstanceMap.put(clazz, defaultInstance); + } + + protected static Object newMessageInfo( + MessageLite defaultInstance, String info, Object[] objects) { + return new RawMessageInfo(defaultInstance, info, objects); + } + + /** + * Merge some unknown fields into the {@link UnknownFieldSetLite} for this message. + * + *

For use by generated code only. + */ + protected final void mergeUnknownFields(UnknownFieldSetLite unknownFields) { + this.unknownFields = UnknownFieldSetLite.mutableCopyOf(this.unknownFields, unknownFields); + } + + @SuppressWarnings("unchecked") + public abstract static class Builder< + MessageType extends GeneratedMessageLite, + BuilderType extends Builder> + extends AbstractMessageLite.Builder { + + private final MessageType defaultInstance; + protected MessageType instance; + protected boolean isBuilt; + + protected Builder(MessageType defaultInstance) { + this.defaultInstance = defaultInstance; + this.instance = + (MessageType) defaultInstance.dynamicMethod(MethodToInvoke.NEW_MUTABLE_INSTANCE); + isBuilt = false; + } + + /** + * Called before any method that would mutate the builder to ensure that it correctly copies any + * state before the write happens to preserve immutability guarantees. + */ + protected final void copyOnWrite() { + if (isBuilt) { + copyOnWriteInternal(); + isBuilt = false; + } + } + + protected void copyOnWriteInternal() { + MessageType newInstance = + (MessageType) instance.dynamicMethod(MethodToInvoke.NEW_MUTABLE_INSTANCE); + mergeFromInstance(newInstance, instance); + instance = newInstance; + } + + @Override + public final boolean isInitialized() { + return GeneratedMessageLite.isInitialized(instance, /* shouldMemoize= */ false); + } + + @Override + public final BuilderType clear() { + // No need to copy on write since we're dropping the instance anyways. + instance = (MessageType) instance.dynamicMethod(MethodToInvoke.NEW_MUTABLE_INSTANCE); + return (BuilderType) this; + } + + @Override + public BuilderType clone() { + BuilderType builder = (BuilderType) getDefaultInstanceForType().newBuilderForType(); + builder.mergeFrom(buildPartial()); + return builder; + } + + @Override + public MessageType buildPartial() { + if (isBuilt) { + return instance; + } + + instance.makeImmutable(); + + isBuilt = true; + return instance; + } + + @Override + public final MessageType build() { + MessageType result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @Override + protected BuilderType internalMergeFrom(MessageType message) { + return mergeFrom(message); + } + + /** All subclasses implement this. */ + public BuilderType mergeFrom(MessageType message) { + copyOnWrite(); + mergeFromInstance(instance, message); + return (BuilderType) this; + } + + private void mergeFromInstance(MessageType dest, MessageType src) { + Protobuf.getInstance().schemaFor(dest).mergeFrom(dest, src); + } + + @Override + public MessageType getDefaultInstanceForType() { + return defaultInstance; + } + + @Override + public BuilderType mergeFrom( + byte[] input, int offset, int length, ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + copyOnWrite(); + try { + Protobuf.getInstance().schemaFor(instance).mergeFrom( + instance, input, offset, offset + length, + new ArrayDecoders.Registers(extensionRegistry)); + } catch (InvalidProtocolBufferException e) { + throw e; + } catch (IndexOutOfBoundsException e) { + throw InvalidProtocolBufferException.truncatedMessage(); + } catch (IOException e) { + throw new RuntimeException("Reading from byte array should not throw IOException.", e); + } + return (BuilderType) this; + } + + @Override + public BuilderType mergeFrom( + byte[] input, int offset, int length) + throws InvalidProtocolBufferException { + return mergeFrom(input, offset, length, ExtensionRegistryLite.getEmptyRegistry()); + } + + @Override + public BuilderType mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws IOException { + copyOnWrite(); + try { + // TODO(yilunchong): Try to make input with type CodedInputStream.ArrayDecoder use + // fast path. + Protobuf.getInstance().schemaFor(instance).mergeFrom( + instance, CodedInputStreamReader.forCodedInput(input), extensionRegistry); + } catch (RuntimeException e) { + if (e.getCause() instanceof IOException) { + throw (IOException) e.getCause(); + } + throw e; + } + return (BuilderType) this; + } + } + + + // ================================================================= + // Extensions-related stuff + + /** Lite equivalent of {@link com.google.protobuf.GeneratedMessage.ExtendableMessageOrBuilder}. */ + public interface ExtendableMessageOrBuilder< + MessageType extends ExtendableMessage, + BuilderType extends ExtendableBuilder> + extends MessageLiteOrBuilder { + + /** 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); + } + + /** Lite equivalent of {@link GeneratedMessage.ExtendableMessage}. */ + public abstract static class ExtendableMessage< + MessageType extends ExtendableMessage, + BuilderType extends ExtendableBuilder> + extends GeneratedMessageLite + implements ExtendableMessageOrBuilder { + + /** Represents the set of extensions on this message. For use by generated code only. */ + protected FieldSet extensions = FieldSet.emptySet(); + + @SuppressWarnings("unchecked") + protected final void mergeExtensionFields(final MessageType other) { + if (extensions.isImmutable()) { + extensions = extensions.clone(); + } + extensions.mergeFrom(((ExtendableMessage) other).extensions); + } + + /** + * Parse an unknown field or an extension. For use by generated code only. + * + *

For use by generated code only. + * + * @return {@code true} unless the tag is an end-group tag. + */ + protected boolean parseUnknownField( + MessageType defaultInstance, + CodedInputStream input, + ExtensionRegistryLite extensionRegistry, + int tag) + throws IOException { + int fieldNumber = WireFormat.getTagFieldNumber(tag); + + // TODO(dweis): How much bytecode would be saved by not requiring the generated code to + // provide the default instance? + GeneratedExtension extension = + extensionRegistry.findLiteExtensionByNumber(defaultInstance, fieldNumber); + + return parseExtension(input, extensionRegistry, extension, tag, fieldNumber); + } + + private boolean parseExtension( + CodedInputStream input, + ExtensionRegistryLite extensionRegistry, + GeneratedExtension extension, + int tag, + int fieldNumber) + throws IOException { + int wireType = WireFormat.getTagWireType(tag); + boolean unknown = false; + boolean packed = false; + if (extension == null) { + unknown = true; // Unknown field. + } else if (wireType + == FieldSet.getWireFormatForFieldType( + extension.descriptor.getLiteType(), /* isPacked= */ false)) { + packed = false; // Normal, unpacked value. + } else if (extension.descriptor.isRepeated + && extension.descriptor.type.isPackable() + && wireType + == FieldSet.getWireFormatForFieldType( + extension.descriptor.getLiteType(), /* isPacked= */ true)) { + packed = true; // Packed value. + } else { + unknown = true; // Wrong wire type. + } + + if (unknown) { // Unknown field or wrong wire type. Skip. + return parseUnknownField(tag, input); + } + + ensureExtensionsAreMutable(); + + if (packed) { + int length = input.readRawVarint32(); + int limit = input.pushLimit(length); + if (extension.descriptor.getLiteType() == WireFormat.FieldType.ENUM) { + while (input.getBytesUntilLimit() > 0) { + int rawValue = input.readEnum(); + Object value = extension.descriptor.getEnumType().findValueByNumber(rawValue); + if (value == null) { + // If the number isn't recognized as a valid value for this + // enum, drop it (don't even add it to unknownFields). + return true; + } + extensions.addRepeatedField( + extension.descriptor, extension.singularToFieldSetType(value)); + } + } else { + while (input.getBytesUntilLimit() > 0) { + Object value = + FieldSet.readPrimitiveField( + input, extension.descriptor.getLiteType(), /*checkUtf8=*/ false); + extensions.addRepeatedField(extension.descriptor, value); + } + } + input.popLimit(limit); + } else { + Object value; + switch (extension.descriptor.getLiteJavaType()) { + case MESSAGE: + { + MessageLite.Builder subBuilder = null; + if (!extension.descriptor.isRepeated()) { + MessageLite existingValue = (MessageLite) extensions.getField(extension.descriptor); + if (existingValue != null) { + subBuilder = existingValue.toBuilder(); + } + } + if (subBuilder == null) { + subBuilder = extension.getMessageDefaultInstance().newBuilderForType(); + } + if (extension.descriptor.getLiteType() == WireFormat.FieldType.GROUP) { + input.readGroup(extension.getNumber(), subBuilder, extensionRegistry); + } else { + input.readMessage(subBuilder, extensionRegistry); + } + value = subBuilder.build(); + break; + } + case ENUM: + int rawValue = input.readEnum(); + value = extension.descriptor.getEnumType().findValueByNumber(rawValue); + // If the number isn't recognized as a valid value for this enum, + // write it to unknown fields object. + if (value == null) { + mergeVarintField(fieldNumber, rawValue); + return true; + } + break; + default: + value = + FieldSet.readPrimitiveField( + input, extension.descriptor.getLiteType(), /*checkUtf8=*/ false); + break; + } + + if (extension.descriptor.isRepeated()) { + extensions.addRepeatedField( + extension.descriptor, extension.singularToFieldSetType(value)); + } else { + extensions.setField(extension.descriptor, extension.singularToFieldSetType(value)); + } + } + return true; + } + + /** + * Parse an unknown field or an extension. For use by generated code only. + * + *

For use by generated code only. + * + * @return {@code true} unless the tag is an end-group tag. + */ + protected boolean parseUnknownFieldAsMessageSet( + MessageType defaultInstance, + CodedInputStream input, + ExtensionRegistryLite extensionRegistry, + int tag) + throws IOException { + + if (tag == WireFormat.MESSAGE_SET_ITEM_TAG) { + mergeMessageSetExtensionFromCodedStream(defaultInstance, input, extensionRegistry); + return true; + } + + // TODO(dweis): Do we really want to support non message set wire format in message sets? + // Full runtime does... So we do for now. + int wireType = WireFormat.getTagWireType(tag); + if (wireType == WireFormat.WIRETYPE_LENGTH_DELIMITED) { + return parseUnknownField(defaultInstance, input, extensionRegistry, tag); + } else { + // TODO(dweis): Should we throw on invalid input? Full runtime does not... + return input.skipField(tag); + } + } + + /** + * Merges the message set from the input stream; requires message set wire format. + * + * @param defaultInstance the default instance of the containing message we are parsing in + * @param input the stream to parse from + * @param extensionRegistry the registry to use when parsing + */ + private void mergeMessageSetExtensionFromCodedStream( + MessageType defaultInstance, + CodedInputStream input, + ExtensionRegistryLite extensionRegistry) + throws IOException { + // The wire format for MessageSet is: + // message MessageSet { + // repeated group Item = 1 { + // required int32 typeId = 2; + // required bytes message = 3; + // } + // } + // "typeId" is the extension's field number. The extension can only be + // a message type, where "message" contains the encoded bytes of that + // message. + // + // In practice, we will probably never see a MessageSet item in which + // the message appears before the type ID, or where either field does not + // appear exactly once. However, in theory such cases are valid, so we + // should be prepared to accept them. + + int typeId = 0; + ByteString rawBytes = null; // If we encounter "message" before "typeId" + GeneratedExtension extension = null; + + // Read bytes from input, if we get it's type first then parse it eagerly, + // otherwise we store the raw bytes in a local variable. + while (true) { + final int tag = input.readTag(); + if (tag == 0) { + break; + } + + if (tag == WireFormat.MESSAGE_SET_TYPE_ID_TAG) { + typeId = input.readUInt32(); + if (typeId != 0) { + extension = extensionRegistry.findLiteExtensionByNumber(defaultInstance, typeId); + } + + } else if (tag == WireFormat.MESSAGE_SET_MESSAGE_TAG) { + if (typeId != 0) { + if (extension != null) { + // We already know the type, so we can parse directly from the + // input with no copying. Hooray! + eagerlyMergeMessageSetExtension(input, extension, extensionRegistry, typeId); + rawBytes = null; + continue; + } + } + // We haven't seen a type ID yet or we want parse message lazily. + rawBytes = input.readBytes(); + + } else { // Unknown tag. Skip it. + if (!input.skipField(tag)) { + break; // End of group + } + } + } + input.checkLastTagWas(WireFormat.MESSAGE_SET_ITEM_END_TAG); + + // Process the raw bytes. + if (rawBytes != null && typeId != 0) { // Zero is not a valid type ID. + if (extension != null) { // We known the type + mergeMessageSetExtensionFromBytes(rawBytes, extensionRegistry, extension); + } else { // We don't know how to parse this. Ignore it. + if (rawBytes != null) { + mergeLengthDelimitedField(typeId, rawBytes); + } + } + } + } + + private void eagerlyMergeMessageSetExtension( + CodedInputStream input, + GeneratedExtension extension, + ExtensionRegistryLite extensionRegistry, + int typeId) + throws IOException { + int fieldNumber = typeId; + int tag = WireFormat.makeTag(typeId, WireFormat.WIRETYPE_LENGTH_DELIMITED); + parseExtension(input, extensionRegistry, extension, tag, fieldNumber); + } + + private void mergeMessageSetExtensionFromBytes( + ByteString rawBytes, + ExtensionRegistryLite extensionRegistry, + GeneratedExtension extension) + throws IOException { + MessageLite.Builder subBuilder = null; + MessageLite existingValue = (MessageLite) extensions.getField(extension.descriptor); + if (existingValue != null) { + subBuilder = existingValue.toBuilder(); + } + if (subBuilder == null) { + subBuilder = extension.getMessageDefaultInstance().newBuilderForType(); + } + subBuilder.mergeFrom(rawBytes, extensionRegistry); + MessageLite value = subBuilder.build(); + + ensureExtensionsAreMutable() + .setField(extension.descriptor, extension.singularToFieldSetType(value)); + } + + FieldSet ensureExtensionsAreMutable() { + if (extensions.isImmutable()) { + extensions = extensions.clone(); + } + return extensions; + } + + private void verifyExtensionContainingType(final GeneratedExtension extension) { + if (extension.getContainingTypeDefaultInstance() != getDefaultInstanceForType()) { + // This can only happen if someone uses unchecked operations. + throw new IllegalArgumentException( + "This extension is for a different message type. Please make " + + "sure that you are not suppressing any generics type warnings."); + } + } + + /** Check if a singular extension is present. */ + @Override + public final boolean hasExtension(final ExtensionLite extension) { + GeneratedExtension extensionLite = checkIsLite(extension); + + verifyExtensionContainingType(extensionLite); + return extensions.hasField(extensionLite.descriptor); + } + + /** Get the number of elements in a repeated extension. */ + @Override + public final int getExtensionCount( + final ExtensionLite> extension) { + GeneratedExtension> extensionLite = checkIsLite(extension); + + verifyExtensionContainingType(extensionLite); + return extensions.getRepeatedFieldCount(extensionLite.descriptor); + } + + /** Get the value of an extension. */ + @Override + @SuppressWarnings("unchecked") + public final Type getExtension(final ExtensionLite extension) { + GeneratedExtension extensionLite = checkIsLite(extension); + + verifyExtensionContainingType(extensionLite); + final Object value = extensions.getField(extensionLite.descriptor); + if (value == null) { + return extensionLite.defaultValue; + } else { + return (Type) extensionLite.fromFieldSetType(value); + } + } + + /** Get one element of a repeated extension. */ + @Override + @SuppressWarnings("unchecked") + public final Type getExtension( + final ExtensionLite> extension, final int index) { + GeneratedExtension> extensionLite = checkIsLite(extension); + + verifyExtensionContainingType(extensionLite); + return (Type) + extensionLite.singularFromFieldSetType( + extensions.getRepeatedField(extensionLite.descriptor, index)); + } + + /** Called by subclasses to check if all extensions are initialized. */ + protected boolean extensionsAreInitialized() { + return extensions.isInitialized(); + } + + /** + * 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(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) { + ExtensionDescriptor extension = next.getKey(); + if (messageSetWireFormat + && extension.getLiteJavaType() == WireFormat.JavaType.MESSAGE + && !extension.isRepeated()) { + output.writeMessageSetExtension(extension.getNumber(), (MessageLite) next.getValue()); + } else { + FieldSet.writeField(extension, 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(); + } + } + + /** Lite equivalent of {@link GeneratedMessage.ExtendableBuilder}. */ + @SuppressWarnings("unchecked") + public abstract static class ExtendableBuilder< + MessageType extends ExtendableMessage, + BuilderType extends ExtendableBuilder> + extends Builder + implements ExtendableMessageOrBuilder { + protected ExtendableBuilder(MessageType defaultInstance) { + super(defaultInstance); + } + + // For immutable message conversion. + void internalSetExtensionSet(FieldSet extensions) { + copyOnWrite(); + instance.extensions = extensions; + } + + @Override + protected void copyOnWriteInternal() { + super.copyOnWriteInternal(); + instance.extensions = instance.extensions.clone(); + } + + private FieldSet ensureExtensionsAreMutable() { + FieldSet extensions = instance.extensions; + if (extensions.isImmutable()) { + extensions = extensions.clone(); + instance.extensions = extensions; + } + return extensions; + } + + @Override + public final MessageType buildPartial() { + if (isBuilt) { + return instance; + } + + instance.extensions.makeImmutable(); + return super.buildPartial(); + } + + private void verifyExtensionContainingType(final GeneratedExtension extension) { + if (extension.getContainingTypeDefaultInstance() != getDefaultInstanceForType()) { + // This can only happen if someone uses unchecked operations. + throw new IllegalArgumentException( + "This extension is for a different message type. Please make " + + "sure that you are not suppressing any generics type warnings."); + } + } + + /** Check if a singular extension is present. */ + @Override + public final boolean hasExtension(final ExtensionLite extension) { + return instance.hasExtension(extension); + } + + /** Get the number of elements in a repeated extension. */ + @Override + public final int getExtensionCount( + final ExtensionLite> extension) { + return instance.getExtensionCount(extension); + } + + /** Get the value of an extension. */ + @Override + @SuppressWarnings("unchecked") + public final Type getExtension(final ExtensionLite extension) { + return instance.getExtension(extension); + } + + /** Get one element of a repeated extension. */ + @Override + @SuppressWarnings("unchecked") + public final Type getExtension( + final ExtensionLite> extension, final int index) { + return instance.getExtension(extension, index); + } + + /** Set the value of an extension. */ + public final BuilderType setExtension( + final ExtensionLite extension, final Type value) { + GeneratedExtension extensionLite = checkIsLite(extension); + + verifyExtensionContainingType(extensionLite); + copyOnWrite(); + ensureExtensionsAreMutable() + .setField(extensionLite.descriptor, extensionLite.toFieldSetType(value)); + return (BuilderType) this; + } + + /** Set the value of one element of a repeated extension. */ + public final BuilderType setExtension( + final ExtensionLite> extension, final int index, final Type value) { + GeneratedExtension> extensionLite = checkIsLite(extension); + + verifyExtensionContainingType(extensionLite); + copyOnWrite(); + ensureExtensionsAreMutable() + .setRepeatedField( + extensionLite.descriptor, index, extensionLite.singularToFieldSetType(value)); + return (BuilderType) this; + } + + /** Append a value to a repeated extension. */ + public final BuilderType addExtension( + final ExtensionLite> extension, final Type value) { + GeneratedExtension> extensionLite = checkIsLite(extension); + + verifyExtensionContainingType(extensionLite); + copyOnWrite(); + ensureExtensionsAreMutable() + .addRepeatedField(extensionLite.descriptor, extensionLite.singularToFieldSetType(value)); + return (BuilderType) this; + } + + /** Clear an extension. */ + public final BuilderType clearExtension(final ExtensionLite extension) { + GeneratedExtension extensionLite = checkIsLite(extension); + + verifyExtensionContainingType(extensionLite); + copyOnWrite(); + ensureExtensionsAreMutable().clearField(extensionLite.descriptor); + return (BuilderType) this; + } + } + + // ----------------------------------------------------------------- + + /** For use by generated code only. */ + public static + GeneratedExtension newSingularGeneratedExtension( + final ContainingType containingTypeDefaultInstance, + final Type defaultValue, + final MessageLite messageDefaultInstance, + final Internal.EnumLiteMap enumTypeMap, + final int number, + final WireFormat.FieldType type, + final Class singularType) { + return new GeneratedExtension( + containingTypeDefaultInstance, + defaultValue, + messageDefaultInstance, + new ExtensionDescriptor( + enumTypeMap, number, type, /* isRepeated= */ false, /* isPacked= */ false), + singularType); + } + + /** For use by generated code only. */ + public static + GeneratedExtension newRepeatedGeneratedExtension( + final ContainingType containingTypeDefaultInstance, + final MessageLite messageDefaultInstance, + final Internal.EnumLiteMap enumTypeMap, + final int number, + final WireFormat.FieldType type, + final boolean isPacked, + final Class singularType) { + @SuppressWarnings("unchecked") // Subclasses ensure Type is a List + Type emptyList = (Type) Collections.emptyList(); + return new GeneratedExtension( + containingTypeDefaultInstance, + emptyList, + messageDefaultInstance, + new ExtensionDescriptor(enumTypeMap, number, type, /* isRepeated= */ true, isPacked), + singularType); + } + + static final class ExtensionDescriptor + implements FieldSet.FieldDescriptorLite { + ExtensionDescriptor( + final Internal.EnumLiteMap enumTypeMap, + final int number, + final WireFormat.FieldType type, + final boolean isRepeated, + final boolean isPacked) { + this.enumTypeMap = enumTypeMap; + this.number = number; + this.type = type; + this.isRepeated = isRepeated; + this.isPacked = isPacked; + } + + final Internal.EnumLiteMap enumTypeMap; + final int number; + final WireFormat.FieldType type; + final boolean isRepeated; + final boolean isPacked; + + @Override + public int getNumber() { + return number; + } + + @Override + public WireFormat.FieldType getLiteType() { + return type; + } + + @Override + public WireFormat.JavaType getLiteJavaType() { + return type.getJavaType(); + } + + @Override + public boolean isRepeated() { + return isRepeated; + } + + @Override + public boolean isPacked() { + return isPacked; + } + + @Override + public Internal.EnumLiteMap getEnumType() { + return enumTypeMap; + } + + @Override + @SuppressWarnings("unchecked") + public MessageLite.Builder internalMergeFrom(MessageLite.Builder to, MessageLite from) { + return ((Builder) to).mergeFrom((GeneratedMessageLite) from); + } + + + @Override + public int compareTo(ExtensionDescriptor other) { + return number - other.number; + } + } + + // ================================================================= + + /** Calls Class.getMethod and throws a RuntimeException if it fails. */ + @SuppressWarnings("unchecked") + static Method getMethodOrDie(Class clazz, String name, 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. */ + static Object invokeOrDie(Method method, Object object, 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); + } + } + } + + + /** + * Lite equivalent to {@link GeneratedMessage.GeneratedExtension}. + * + *

Users should ignore the contents of this class and only use objects of this type as + * parameters to extension accessors and ExtensionRegistry.add(). + */ + public static class GeneratedExtension + extends ExtensionLite { + + /** + * Create a new instance with the given parameters. + * + *

The last parameter {@code singularType} is only needed for enum types. We store integer + * values for enum types in a {@link ExtendableMessage} and use Java reflection to convert an + * integer value back into a concrete enum object. + */ + GeneratedExtension( + final ContainingType containingTypeDefaultInstance, + final Type defaultValue, + final MessageLite messageDefaultInstance, + final ExtensionDescriptor descriptor, + final Class singularType) { + // Defensive checks to verify the correct initialization order of + // GeneratedExtensions and their related GeneratedMessages. + if (containingTypeDefaultInstance == null) { + throw new IllegalArgumentException("Null containingTypeDefaultInstance"); + } + if (descriptor.getLiteType() == WireFormat.FieldType.MESSAGE + && messageDefaultInstance == null) { + throw new IllegalArgumentException("Null messageDefaultInstance"); + } + this.containingTypeDefaultInstance = containingTypeDefaultInstance; + this.defaultValue = defaultValue; + this.messageDefaultInstance = messageDefaultInstance; + this.descriptor = descriptor; + } + + final ContainingType containingTypeDefaultInstance; + final Type defaultValue; + final MessageLite messageDefaultInstance; + final ExtensionDescriptor descriptor; + + /** Default instance of the type being extended, used to identify that type. */ + public ContainingType getContainingTypeDefaultInstance() { + return containingTypeDefaultInstance; + } + + /** Get the field number. */ + @Override + public int getNumber() { + return descriptor.getNumber(); + } + + /** + * If the extension is an embedded message or group, returns the default instance of the + * message. + */ + @Override + public MessageLite getMessageDefaultInstance() { + return messageDefaultInstance; + } + + @SuppressWarnings("unchecked") + Object fromFieldSetType(final Object value) { + if (descriptor.isRepeated()) { + if (descriptor.getLiteJavaType() == WireFormat.JavaType.ENUM) { + final List result = new ArrayList<>(); + for (final Object element : (List) value) { + result.add(singularFromFieldSetType(element)); + } + return result; + } else { + return value; + } + } else { + return singularFromFieldSetType(value); + } + } + + Object singularFromFieldSetType(final Object value) { + if (descriptor.getLiteJavaType() == WireFormat.JavaType.ENUM) { + return descriptor.enumTypeMap.findValueByNumber((Integer) value); + } else { + return value; + } + } + + @SuppressWarnings("unchecked") + Object toFieldSetType(final Object value) { + if (descriptor.isRepeated()) { + if (descriptor.getLiteJavaType() == WireFormat.JavaType.ENUM) { + final List result = new ArrayList<>(); + for (final Object element : (List) value) { + result.add(singularToFieldSetType(element)); + } + return result; + } else { + return value; + } + } else { + return singularToFieldSetType(value); + } + } + + Object singularToFieldSetType(final Object value) { + if (descriptor.getLiteJavaType() == WireFormat.JavaType.ENUM) { + return ((Internal.EnumLite) value).getNumber(); + } else { + return value; + } + } + + @Override + public FieldType getLiteType() { + return descriptor.getLiteType(); + } + + @Override + public boolean isRepeated() { + return descriptor.isRepeated; + } + + @Override + public Type getDefaultValue() { + return defaultValue; + } + } + + /** + * 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; + // only included for backwards compatibility before messageClass was added + 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 = messageClass.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 + */ + @SuppressWarnings("unchecked") + 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, + BuilderType extends ExtendableBuilder, + T> + GeneratedExtension checkIsLite(ExtensionLite extension) { + if (!extension.isLite()) { + throw new IllegalArgumentException("Expected a lite extension."); + } + + return (GeneratedExtension) extension; + } + + /** + * A static helper method for checking if a message is initialized, optionally memoizing. + * + *

For use by generated code only. + */ + protected static final > boolean isInitialized( + T message, boolean shouldMemoize) { + byte memoizedIsInitialized = + (Byte) message.dynamicMethod(MethodToInvoke.GET_MEMOIZED_IS_INITIALIZED); + if (memoizedIsInitialized == 1) { + return true; + } + if (memoizedIsInitialized == 0) { + return false; + } + boolean isInitialized = Protobuf.getInstance().schemaFor(message).isInitialized(message); + if (shouldMemoize) { + message.dynamicMethod( + MethodToInvoke.SET_MEMOIZED_IS_INITIALIZED, isInitialized ? message : null); + } + return isInitialized; + } + + protected static IntList emptyIntList() { + return IntArrayList.emptyList(); + } + + protected static IntList mutableCopy(IntList list) { + int size = list.size(); + return list.mutableCopyWithCapacity( + size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY : size * 2); + } + + protected static LongList emptyLongList() { + return LongArrayList.emptyList(); + } + + protected static LongList mutableCopy(LongList list) { + int size = list.size(); + return list.mutableCopyWithCapacity( + size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY : size * 2); + } + + protected static FloatList emptyFloatList() { + return FloatArrayList.emptyList(); + } + + protected static FloatList mutableCopy(FloatList list) { + int size = list.size(); + return list.mutableCopyWithCapacity( + size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY : size * 2); + } + + protected static DoubleList emptyDoubleList() { + return DoubleArrayList.emptyList(); + } + + protected static DoubleList mutableCopy(DoubleList list) { + int size = list.size(); + return list.mutableCopyWithCapacity( + size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY : size * 2); + } + + protected static BooleanList emptyBooleanList() { + return BooleanArrayList.emptyList(); + } + + protected static BooleanList mutableCopy(BooleanList list) { + int size = list.size(); + return list.mutableCopyWithCapacity( + size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY : size * 2); + } + + protected static ProtobufList emptyProtobufList() { + return ProtobufArrayList.emptyList(); + } + + protected static ProtobufList mutableCopy(ProtobufList list) { + int size = list.size(); + return list.mutableCopyWithCapacity( + size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY : size * 2); + } + + /** + * A {@link Parser} implementation that delegates to the default instance. + * + *

For use by generated code only. + */ + protected static class DefaultInstanceBasedParser> + extends AbstractParser { + + private final T defaultInstance; + + public DefaultInstanceBasedParser(T defaultInstance) { + this.defaultInstance = defaultInstance; + } + + @Override + public T parsePartialFrom(CodedInputStream input, ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + return GeneratedMessageLite.parsePartialFrom(defaultInstance, input, extensionRegistry); + } + + @Override + public T parsePartialFrom( + byte[] input, int offset, int length, ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + return GeneratedMessageLite.parsePartialFrom( + defaultInstance, input, offset, length, extensionRegistry); + } + } + + /** + * A static helper method for parsing a partial from input using the extension registry and the + * instance. + */ + // TODO(dweis): Should this verify that the last tag was 0? + static > T parsePartialFrom( + T instance, CodedInputStream input, ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + @SuppressWarnings("unchecked") // Guaranteed by protoc + T result = (T) instance.dynamicMethod(MethodToInvoke.NEW_MUTABLE_INSTANCE); + try { + // TODO(yilunchong): Try to make input with type CodedInpuStream.ArrayDecoder use + // fast path. + Schema schema = Protobuf.getInstance().schemaFor(result); + schema.mergeFrom(result, CodedInputStreamReader.forCodedInput(input), extensionRegistry); + schema.makeImmutable(result); + } catch (InvalidProtocolBufferException e) { + if (e.getThrownFromInputStream()) { + e = new InvalidProtocolBufferException(e); + } + throw e.setUnfinishedMessage(result); + } catch (IOException e) { + if (e.getCause() instanceof InvalidProtocolBufferException) { + throw (InvalidProtocolBufferException) e.getCause(); + } + throw new InvalidProtocolBufferException(e).setUnfinishedMessage(result); + } catch (RuntimeException e) { + if (e.getCause() instanceof InvalidProtocolBufferException) { + throw (InvalidProtocolBufferException) e.getCause(); + } + throw e; + } + return result; + } + + /** A static helper method for parsing a partial from byte array. */ + static > T parsePartialFrom( + T instance, byte[] input, int offset, int length, ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + @SuppressWarnings("unchecked") // Guaranteed by protoc + T result = (T) instance.dynamicMethod(MethodToInvoke.NEW_MUTABLE_INSTANCE); + try { + Schema schema = Protobuf.getInstance().schemaFor(result); + schema.mergeFrom( + result, input, offset, offset + length, new ArrayDecoders.Registers(extensionRegistry)); + schema.makeImmutable(result); + if (result.memoizedHashCode != 0) { + throw new RuntimeException(); + } + } catch (InvalidProtocolBufferException e) { + if (e.getThrownFromInputStream()) { + e = new InvalidProtocolBufferException(e); + } + throw e.setUnfinishedMessage(result); + } catch (IOException e) { + if (e.getCause() instanceof InvalidProtocolBufferException) { + throw (InvalidProtocolBufferException) e.getCause(); + } + throw new InvalidProtocolBufferException(e).setUnfinishedMessage(result); + } catch (IndexOutOfBoundsException e) { + throw InvalidProtocolBufferException.truncatedMessage().setUnfinishedMessage(result); + } + return result; + } + + protected static > T parsePartialFrom( + T defaultInstance, CodedInputStream input) throws InvalidProtocolBufferException { + return parsePartialFrom(defaultInstance, input, ExtensionRegistryLite.getEmptyRegistry()); + } + + /** + * Helper method to check if message is initialized. + * + * @throws InvalidProtocolBufferException if it is not initialized. + * @return The message to check. + */ + private static > T checkMessageInitialized(T message) + throws InvalidProtocolBufferException { + if (message != null && !message.isInitialized()) { + throw message + .newUninitializedMessageException() + .asInvalidProtocolBufferException() + .setUnfinishedMessage(message); + } + return message; + } + + // Validates last tag. + protected static > T parseFrom( + T defaultInstance, ByteBuffer data, ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + return checkMessageInitialized( + parseFrom(defaultInstance, CodedInputStream.newInstance(data), extensionRegistry)); + } + + // Validates last tag. + protected static > T parseFrom( + T defaultInstance, ByteBuffer data) throws InvalidProtocolBufferException { + return parseFrom(defaultInstance, data, ExtensionRegistryLite.getEmptyRegistry()); + } + + // Validates last tag. + protected static > T parseFrom( + T defaultInstance, ByteString data) throws InvalidProtocolBufferException { + return checkMessageInitialized( + parseFrom(defaultInstance, data, ExtensionRegistryLite.getEmptyRegistry())); + } + + // Validates last tag. + protected static > T parseFrom( + T defaultInstance, ByteString data, ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + return checkMessageInitialized(parsePartialFrom(defaultInstance, data, extensionRegistry)); + } + + // This is a special case since we want to verify that the last tag is 0. We assume we exhaust the + // ByteString. + private static > T parsePartialFrom( + T defaultInstance, ByteString data, ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + T message; + try { + CodedInputStream input = data.newCodedInput(); + message = parsePartialFrom(defaultInstance, input, extensionRegistry); + try { + input.checkLastTagWas(0); + } catch (InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(message); + } + return message; + } catch (InvalidProtocolBufferException e) { + throw e; + } + } + + // This is a special case since we want to verify that the last tag is 0. We assume we exhaust the + // ByteString. + private static > T parsePartialFrom( + T defaultInstance, byte[] data, ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + return checkMessageInitialized( + parsePartialFrom(defaultInstance, data, 0, data.length, extensionRegistry)); + } + + // Validates last tag. + protected static > T parseFrom( + T defaultInstance, byte[] data) throws InvalidProtocolBufferException { + return checkMessageInitialized(parsePartialFrom( + defaultInstance, data, 0, data.length, ExtensionRegistryLite.getEmptyRegistry())); + } + + // Validates last tag. + protected static > T parseFrom( + T defaultInstance, byte[] data, ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + return checkMessageInitialized( + parsePartialFrom(defaultInstance, data, 0, data.length, extensionRegistry)); + } + + // Does not validate last tag. + protected static > T parseFrom( + T defaultInstance, InputStream input) throws InvalidProtocolBufferException { + return checkMessageInitialized( + parsePartialFrom( + defaultInstance, + CodedInputStream.newInstance(input), + ExtensionRegistryLite.getEmptyRegistry())); + } + + // Does not validate last tag. + protected static > T parseFrom( + T defaultInstance, InputStream input, ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + return checkMessageInitialized( + parsePartialFrom(defaultInstance, CodedInputStream.newInstance(input), extensionRegistry)); + } + + // Does not validate last tag. + protected static > T parseFrom( + T defaultInstance, CodedInputStream input) throws InvalidProtocolBufferException { + return parseFrom(defaultInstance, input, ExtensionRegistryLite.getEmptyRegistry()); + } + + // Does not validate last tag. + protected static > T parseFrom( + T defaultInstance, CodedInputStream input, ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + return checkMessageInitialized(parsePartialFrom(defaultInstance, input, extensionRegistry)); + } + + // Validates last tag. + protected static > T parseDelimitedFrom( + T defaultInstance, InputStream input) throws InvalidProtocolBufferException { + return checkMessageInitialized( + parsePartialDelimitedFrom( + defaultInstance, input, ExtensionRegistryLite.getEmptyRegistry())); + } + + // Validates last tag. + protected static > T parseDelimitedFrom( + T defaultInstance, InputStream input, ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + return checkMessageInitialized( + parsePartialDelimitedFrom(defaultInstance, input, extensionRegistry)); + } + + private static > T parsePartialDelimitedFrom( + T defaultInstance, InputStream input, ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + int size; + try { + int firstByte = input.read(); + if (firstByte == -1) { + return null; + } + size = CodedInputStream.readRawVarint32(firstByte, input); + } catch (InvalidProtocolBufferException e) { + if (e.getThrownFromInputStream()) { + e = new InvalidProtocolBufferException(e); + } + throw e; + } catch (IOException e) { + throw new InvalidProtocolBufferException(e); + } + InputStream limitedInput = new LimitedInputStream(input, size); + CodedInputStream codedInput = CodedInputStream.newInstance(limitedInput); + T message = parsePartialFrom(defaultInstance, codedInput, extensionRegistry); + try { + codedInput.checkLastTagWas(0); + } catch (InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(message); + } + return message; + } +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/Int32Value.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/Int32Value.java new file mode 100644 index 0000000000000..290ea059e8a35 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/Int32Value.java @@ -0,0 +1,276 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/wrappers.proto + +package com.google.protobuf; + +/** + *

+ * Wrapper message for `int32`.
+ * The JSON representation for `Int32Value` is JSON number.
+ * 
+ * + * Protobuf type {@code google.protobuf.Int32Value} + */ +public final class Int32Value extends + com.google.protobuf.GeneratedMessageLite< + Int32Value, Int32Value.Builder> implements + // @@protoc_insertion_point(message_implements:google.protobuf.Int32Value) + Int32ValueOrBuilder { + private Int32Value() { + } + public static final int VALUE_FIELD_NUMBER = 1; + private int value_; + /** + *
+   * The int32 value.
+   * 
+ * + * int32 value = 1; + * @return The value. + */ + @java.lang.Override + public int getValue() { + return value_; + } + /** + *
+   * The int32 value.
+   * 
+ * + * int32 value = 1; + * @param value The value to set. + */ + private void setValue(int value) { + + value_ = value; + } + /** + *
+   * The int32 value.
+   * 
+ * + * int32 value = 1; + */ + private void clearValue() { + + value_ = 0; + } + + public static com.google.protobuf.Int32Value parseFrom( + java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.Int32Value parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.Int32Value parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.Int32Value parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.Int32Value parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.Int32Value parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.Int32Value parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, 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.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, input, extensionRegistry); + } + public static com.google.protobuf.Int32Value parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return parseDelimitedFrom(DEFAULT_INSTANCE, input); + } + public static com.google.protobuf.Int32Value parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return parseDelimitedFrom(DEFAULT_INSTANCE, input, extensionRegistry); + } + public static com.google.protobuf.Int32Value parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, 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.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, input, extensionRegistry); + } + + public static Builder newBuilder() { + return (Builder) DEFAULT_INSTANCE.createBuilder(); + } + public static Builder newBuilder(com.google.protobuf.Int32Value prototype) { + return (Builder) DEFAULT_INSTANCE.createBuilder(prototype); + } + + /** + *
+   * Wrapper message for `int32`.
+   * The JSON representation for `Int32Value` is JSON number.
+   * 
+ * + * Protobuf type {@code google.protobuf.Int32Value} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessageLite.Builder< + com.google.protobuf.Int32Value, Builder> implements + // @@protoc_insertion_point(builder_implements:google.protobuf.Int32Value) + com.google.protobuf.Int32ValueOrBuilder { + // Construct using com.google.protobuf.Int32Value.newBuilder() + private Builder() { + super(DEFAULT_INSTANCE); + } + + + /** + *
+     * The int32 value.
+     * 
+ * + * int32 value = 1; + * @return The value. + */ + @java.lang.Override + public int getValue() { + return instance.getValue(); + } + /** + *
+     * The int32 value.
+     * 
+ * + * int32 value = 1; + * @param value The value to set. + * @return This builder for chaining. + */ + public Builder setValue(int value) { + copyOnWrite(); + instance.setValue(value); + return this; + } + /** + *
+     * The int32 value.
+     * 
+ * + * int32 value = 1; + * @return This builder for chaining. + */ + public Builder clearValue() { + copyOnWrite(); + instance.clearValue(); + return this; + } + + // @@protoc_insertion_point(builder_scope:google.protobuf.Int32Value) + } + @java.lang.Override + @java.lang.SuppressWarnings({"unchecked", "fallthrough"}) + protected final java.lang.Object dynamicMethod( + com.google.protobuf.GeneratedMessageLite.MethodToInvoke method, + java.lang.Object arg0, java.lang.Object arg1) { + switch (method) { + case NEW_MUTABLE_INSTANCE: { + return new com.google.protobuf.Int32Value(); + } + case NEW_BUILDER: { + return new Builder(); + } + case BUILD_MESSAGE_INFO: { + java.lang.Object[] objects = new java.lang.Object[] { + "value_", + }; + java.lang.String info = + "\u0000\u0001\u0000\u0000\u0001\u0001\u0001\u0000\u0000\u0000\u0001\u0004"; + return newMessageInfo(DEFAULT_INSTANCE, info, objects); + } + // fall through + case GET_DEFAULT_INSTANCE: { + return DEFAULT_INSTANCE; + } + case GET_PARSER: { + com.google.protobuf.Parser parser = PARSER; + if (parser == null) { + synchronized (com.google.protobuf.Int32Value.class) { + parser = PARSER; + if (parser == null) { + parser = + new DefaultInstanceBasedParser( + DEFAULT_INSTANCE); + PARSER = parser; + } + } + } + return parser; + } + case GET_MEMOIZED_IS_INITIALIZED: { + return (byte) 1; + } + case SET_MEMOIZED_IS_INITIALIZED: { + return null; + } + } + throw new UnsupportedOperationException(); + } + + + // @@protoc_insertion_point(class_scope:google.protobuf.Int32Value) + private static final com.google.protobuf.Int32Value DEFAULT_INSTANCE; + static { + Int32Value defaultInstance = new Int32Value(); + // New instances are implicitly immutable so no need to make + // immutable. + DEFAULT_INSTANCE = defaultInstance; + com.google.protobuf.GeneratedMessageLite.registerDefaultInstance( + Int32Value.class, defaultInstance); + } + + public static com.google.protobuf.Int32Value getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + public static com.google.protobuf.Int32Value of(int value) { + return newBuilder().setValue(value).build(); + } + + private static volatile com.google.protobuf.Parser PARSER; + + public static com.google.protobuf.Parser parser() { + return DEFAULT_INSTANCE.getParserForType(); + } +} + diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/Int32ValueOrBuilder.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/Int32ValueOrBuilder.java new file mode 100644 index 0000000000000..d6c78904acb0f --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/Int32ValueOrBuilder.java @@ -0,0 +1,19 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/wrappers.proto + +package com.google.protobuf; + +public interface Int32ValueOrBuilder extends + // @@protoc_insertion_point(interface_extends:google.protobuf.Int32Value) + com.google.protobuf.MessageLiteOrBuilder { + + /** + *
+   * The int32 value.
+   * 
+ * + * int32 value = 1; + * @return The value. + */ + int getValue(); +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/Int64Value.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/Int64Value.java new file mode 100644 index 0000000000000..149609e03e2dd --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/Int64Value.java @@ -0,0 +1,276 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/wrappers.proto + +package com.google.protobuf; + +/** + *
+ * Wrapper message for `int64`.
+ * The JSON representation for `Int64Value` is JSON string.
+ * 
+ * + * Protobuf type {@code google.protobuf.Int64Value} + */ +public final class Int64Value extends + com.google.protobuf.GeneratedMessageLite< + Int64Value, Int64Value.Builder> implements + // @@protoc_insertion_point(message_implements:google.protobuf.Int64Value) + Int64ValueOrBuilder { + private Int64Value() { + } + public static final int VALUE_FIELD_NUMBER = 1; + private long value_; + /** + *
+   * The int64 value.
+   * 
+ * + * int64 value = 1; + * @return The value. + */ + @java.lang.Override + public long getValue() { + return value_; + } + /** + *
+   * The int64 value.
+   * 
+ * + * int64 value = 1; + * @param value The value to set. + */ + private void setValue(long value) { + + value_ = value; + } + /** + *
+   * The int64 value.
+   * 
+ * + * int64 value = 1; + */ + private void clearValue() { + + value_ = 0L; + } + + public static com.google.protobuf.Int64Value parseFrom( + java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.Int64Value parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.Int64Value parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.Int64Value parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.Int64Value parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.Int64Value parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.Int64Value parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, 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.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, input, extensionRegistry); + } + public static com.google.protobuf.Int64Value parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return parseDelimitedFrom(DEFAULT_INSTANCE, input); + } + public static com.google.protobuf.Int64Value parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return parseDelimitedFrom(DEFAULT_INSTANCE, input, extensionRegistry); + } + public static com.google.protobuf.Int64Value parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, 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.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, input, extensionRegistry); + } + + public static Builder newBuilder() { + return (Builder) DEFAULT_INSTANCE.createBuilder(); + } + public static Builder newBuilder(com.google.protobuf.Int64Value prototype) { + return (Builder) DEFAULT_INSTANCE.createBuilder(prototype); + } + + /** + *
+   * Wrapper message for `int64`.
+   * The JSON representation for `Int64Value` is JSON string.
+   * 
+ * + * Protobuf type {@code google.protobuf.Int64Value} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessageLite.Builder< + com.google.protobuf.Int64Value, Builder> implements + // @@protoc_insertion_point(builder_implements:google.protobuf.Int64Value) + com.google.protobuf.Int64ValueOrBuilder { + // Construct using com.google.protobuf.Int64Value.newBuilder() + private Builder() { + super(DEFAULT_INSTANCE); + } + + + /** + *
+     * The int64 value.
+     * 
+ * + * int64 value = 1; + * @return The value. + */ + @java.lang.Override + public long getValue() { + return instance.getValue(); + } + /** + *
+     * The int64 value.
+     * 
+ * + * int64 value = 1; + * @param value The value to set. + * @return This builder for chaining. + */ + public Builder setValue(long value) { + copyOnWrite(); + instance.setValue(value); + return this; + } + /** + *
+     * The int64 value.
+     * 
+ * + * int64 value = 1; + * @return This builder for chaining. + */ + public Builder clearValue() { + copyOnWrite(); + instance.clearValue(); + return this; + } + + // @@protoc_insertion_point(builder_scope:google.protobuf.Int64Value) + } + @java.lang.Override + @java.lang.SuppressWarnings({"unchecked", "fallthrough"}) + protected final java.lang.Object dynamicMethod( + com.google.protobuf.GeneratedMessageLite.MethodToInvoke method, + java.lang.Object arg0, java.lang.Object arg1) { + switch (method) { + case NEW_MUTABLE_INSTANCE: { + return new com.google.protobuf.Int64Value(); + } + case NEW_BUILDER: { + return new Builder(); + } + case BUILD_MESSAGE_INFO: { + java.lang.Object[] objects = new java.lang.Object[] { + "value_", + }; + java.lang.String info = + "\u0000\u0001\u0000\u0000\u0001\u0001\u0001\u0000\u0000\u0000\u0001\u0002"; + return newMessageInfo(DEFAULT_INSTANCE, info, objects); + } + // fall through + case GET_DEFAULT_INSTANCE: { + return DEFAULT_INSTANCE; + } + case GET_PARSER: { + com.google.protobuf.Parser parser = PARSER; + if (parser == null) { + synchronized (com.google.protobuf.Int64Value.class) { + parser = PARSER; + if (parser == null) { + parser = + new DefaultInstanceBasedParser( + DEFAULT_INSTANCE); + PARSER = parser; + } + } + } + return parser; + } + case GET_MEMOIZED_IS_INITIALIZED: { + return (byte) 1; + } + case SET_MEMOIZED_IS_INITIALIZED: { + return null; + } + } + throw new UnsupportedOperationException(); + } + + + // @@protoc_insertion_point(class_scope:google.protobuf.Int64Value) + private static final com.google.protobuf.Int64Value DEFAULT_INSTANCE; + static { + Int64Value defaultInstance = new Int64Value(); + // New instances are implicitly immutable so no need to make + // immutable. + DEFAULT_INSTANCE = defaultInstance; + com.google.protobuf.GeneratedMessageLite.registerDefaultInstance( + Int64Value.class, defaultInstance); + } + + public static com.google.protobuf.Int64Value getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + public static com.google.protobuf.Int64Value of(long value) { + return newBuilder().setValue(value).build(); + } + + private static volatile com.google.protobuf.Parser PARSER; + + public static com.google.protobuf.Parser parser() { + return DEFAULT_INSTANCE.getParserForType(); + } +} + diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/Int64ValueOrBuilder.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/Int64ValueOrBuilder.java new file mode 100644 index 0000000000000..30df2ee039711 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/Int64ValueOrBuilder.java @@ -0,0 +1,19 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/wrappers.proto + +package com.google.protobuf; + +public interface Int64ValueOrBuilder extends + // @@protoc_insertion_point(interface_extends:google.protobuf.Int64Value) + com.google.protobuf.MessageLiteOrBuilder { + + /** + *
+   * The int64 value.
+   * 
+ * + * int64 value = 1; + * @return The value. + */ + long getValue(); +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/IntArrayList.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/IntArrayList.java new file mode 100644 index 0000000000000..9daeebed99236 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/IntArrayList.java @@ -0,0 +1,297 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +import static com.google.protobuf.Internal.checkNotNull; + +import com.google.protobuf.Internal.IntList; +import java.util.Arrays; +import java.util.Collection; +import java.util.RandomAccess; + +/** + * An implementation of {@link IntList} on top of a primitive array. + * + * @author dweis@google.com (Daniel Weis) + */ +final class IntArrayList extends AbstractProtobufList + implements IntList, RandomAccess, PrimitiveNonBoxingCollection { + + private static final IntArrayList EMPTY_LIST = new IntArrayList(new int[0], 0); + static { + EMPTY_LIST.makeImmutable(); + } + + public static IntArrayList emptyList() { + return EMPTY_LIST; + } + + /** The backing store for the list. */ + private int[] array; + + /** + * The size of the list distinct from the length of the array. That is, it is the number of + * elements set in the list. + */ + private int size; + + /** Constructs a new mutable {@code IntArrayList} with default capacity. */ + IntArrayList() { + this(new int[DEFAULT_CAPACITY], 0); + } + + /** + * Constructs a new mutable {@code IntArrayList} containing the same elements as {@code other}. + */ + private IntArrayList(int[] other, int size) { + array = other; + this.size = size; + } + + @Override + protected void removeRange(int fromIndex, int toIndex) { + ensureIsMutable(); + if (toIndex < fromIndex) { + throw new IndexOutOfBoundsException("toIndex < fromIndex"); + } + + System.arraycopy(array, toIndex, array, fromIndex, size - toIndex); + size -= (toIndex - fromIndex); + modCount++; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof IntArrayList)) { + return super.equals(o); + } + IntArrayList other = (IntArrayList) o; + if (size != other.size) { + return false; + } + + final int[] arr = other.array; + for (int i = 0; i < size; i++) { + if (array[i] != arr[i]) { + return false; + } + } + + return true; + } + + @Override + public int hashCode() { + int result = 1; + for (int i = 0; i < size; i++) { + result = (31 * result) + array[i]; + } + return result; + } + + @Override + public IntList mutableCopyWithCapacity(int capacity) { + if (capacity < size) { + throw new IllegalArgumentException(); + } + return new IntArrayList(Arrays.copyOf(array, capacity), size); + } + + @Override + public Integer get(int index) { + return getInt(index); + } + + @Override + public int getInt(int index) { + ensureIndexInRange(index); + return array[index]; + } + + @Override + public int indexOf(Object element) { + if (!(element instanceof Integer)) { + return -1; + } + int unboxedElement = (Integer) element; + int numElems = size(); + for (int i = 0; i < numElems; i++) { + if (array[i] == unboxedElement) { + return i; + } + } + return -1; + } + + @Override + public boolean contains(Object element) { + return indexOf(element) != -1; + } + + @Override + public int size() { + return size; + } + + @Override + public Integer set(int index, Integer element) { + return setInt(index, element); + } + + @Override + public int setInt(int index, int element) { + ensureIsMutable(); + ensureIndexInRange(index); + int previousValue = array[index]; + array[index] = element; + return previousValue; + } + + @Override + public boolean add(Integer element) { + addInt(element); + return true; + } + + @Override + public void add(int index, Integer element) { + addInt(index, element); + } + + /** Like {@link #add(Integer)} but more efficient in that it doesn't box the element. */ + @Override + public void addInt(int element) { + ensureIsMutable(); + if (size == array.length) { + // Resize to 1.5x the size + int length = ((size * 3) / 2) + 1; + int[] newArray = new int[length]; + + System.arraycopy(array, 0, newArray, 0, size); + array = newArray; + } + + array[size++] = element; + } + + /** Like {@link #add(int, Integer)} but more efficient in that it doesn't box the element. */ + private void addInt(int index, int element) { + ensureIsMutable(); + if (index < 0 || index > size) { + throw new IndexOutOfBoundsException(makeOutOfBoundsExceptionMessage(index)); + } + + if (size < array.length) { + // Shift everything over to make room + System.arraycopy(array, index, array, index + 1, size - index); + } else { + // Resize to 1.5x the size + int length = ((size * 3) / 2) + 1; + int[] newArray = new int[length]; + + // Copy the first part directly + System.arraycopy(array, 0, newArray, 0, index); + + // Copy the rest shifted over by one to make room + System.arraycopy(array, index, newArray, index + 1, size - index); + array = newArray; + } + + array[index] = element; + size++; + modCount++; + } + + @Override + public boolean addAll(Collection collection) { + ensureIsMutable(); + + checkNotNull(collection); + + // We specialize when adding another IntArrayList to avoid boxing elements. + if (!(collection instanceof IntArrayList)) { + return super.addAll(collection); + } + + IntArrayList list = (IntArrayList) collection; + if (list.size == 0) { + return false; + } + + int overflow = Integer.MAX_VALUE - size; + if (overflow < list.size) { + // We can't actually represent a list this large. + throw new OutOfMemoryError(); + } + + int newSize = size + list.size; + if (newSize > array.length) { + array = Arrays.copyOf(array, newSize); + } + + System.arraycopy(list.array, 0, array, size, list.size); + size = newSize; + modCount++; + return true; + } + + @Override + public Integer remove(int index) { + ensureIsMutable(); + ensureIndexInRange(index); + int value = array[index]; + if (index < size - 1) { + System.arraycopy(array, index + 1, array, index, size - index - 1); + } + size--; + modCount++; + return value; + } + + /** + * Ensures that the provided {@code index} is within the range of {@code [0, size]}. Throws an + * {@link IndexOutOfBoundsException} if it is not. + * + * @param index the index to verify is in range + */ + private void ensureIndexInRange(int index) { + if (index < 0 || index >= size) { + throw new IndexOutOfBoundsException(makeOutOfBoundsExceptionMessage(index)); + } + } + + private String makeOutOfBoundsExceptionMessage(int index) { + return "Index:" + index + ", Size:" + size; + } +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/Internal.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/Internal.java new file mode 100644 index 0000000000000..90643b8abb999 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/Internal.java @@ -0,0 +1,686 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +import java.lang.reflect.Method; +import java.nio.ByteBuffer; +import java.nio.charset.Charset; +import java.util.AbstractList; +import java.util.AbstractMap; +import java.util.AbstractSet; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.RandomAccess; +import java.util.Set; + +/** + * The classes contained within are used internally by the Protocol Buffer library and generated + * message implementations. They are public only because those generated messages do not reside in + * the {@code protobuf} package. Others should not use this class directly. + * + * @author kenton@google.com (Kenton Varda) + */ +public final class Internal { + + private Internal() {} + + static final Charset UTF_8 = Charset.forName("UTF-8"); + static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1"); + + /** Throws an appropriate {@link NullPointerException} if the given objects is {@code null}. */ + static T checkNotNull(T obj) { + if (obj == null) { + throw new NullPointerException(); + } + return obj; + } + + /** Throws an appropriate {@link NullPointerException} if the given objects is {@code null}. */ + static T checkNotNull(T obj, String message) { + if (obj == null) { + throw new NullPointerException(message); + } + return obj; + } + + /** + * Helper called by generated code to construct default values for string fields. + * + *

The protocol compiler does not actually contain a UTF-8 decoder -- it just pushes + * UTF-8-encoded text around without touching it. The one place where this presents a problem is + * when generating Java string literals. Unicode characters in the string literal would normally + * need to be encoded using a Unicode escape sequence, which would require decoding them. To get + * around this, protoc instead embeds the UTF-8 bytes into the generated code and leaves it to the + * runtime library to decode them. + * + *

It gets worse, though. If protoc just generated a byte array, like: new byte[] {0x12, 0x34, + * 0x56, 0x78} Java actually generates *code* which allocates an array and then fills in each + * value. This is much less efficient than just embedding the bytes directly into the bytecode. To + * get around this, we need another work-around. String literals are embedded directly, so protoc + * actually generates a string literal corresponding to the bytes. The easiest way to do this is + * to use the ISO-8859-1 character set, which corresponds to the first 256 characters of the + * Unicode range. Protoc can then use good old CEscape to generate the string. + * + *

So we have a string literal which represents a set of bytes which represents another string. + * This function -- stringDefaultValue -- converts from the generated string to the string we + * actually want. The generated code calls this automatically. + */ + public static String stringDefaultValue(String bytes) { + return new String(bytes.getBytes(ISO_8859_1), UTF_8); + } + + /** + * Helper called by generated code to construct default values for bytes fields. + * + *

This is a lot like {@link #stringDefaultValue}, but for bytes fields. In this case we only + * need the second of the two hacks -- allowing us to embed raw bytes as a string literal with + * ISO-8859-1 encoding. + */ + public static ByteString bytesDefaultValue(String bytes) { + return ByteString.copyFrom(bytes.getBytes(ISO_8859_1)); + } + /** + * Helper called by generated code to construct default values for bytes fields. + * + *

This is like {@link #bytesDefaultValue}, but returns a byte array. + */ + public static byte[] byteArrayDefaultValue(String bytes) { + return bytes.getBytes(ISO_8859_1); + } + + /** + * Helper called by generated code to construct default values for bytes fields. + * + *

This is like {@link #bytesDefaultValue}, but returns a ByteBuffer. + */ + public static ByteBuffer byteBufferDefaultValue(String bytes) { + return ByteBuffer.wrap(byteArrayDefaultValue(bytes)); + } + + /** + * Create a new ByteBuffer and copy all the content of {@code source} ByteBuffer to the new + * ByteBuffer. The new ByteBuffer's limit and capacity will be source.capacity(), and its position + * will be 0. Note that the state of {@code source} ByteBuffer won't be changed. + */ + public static ByteBuffer copyByteBuffer(ByteBuffer source) { + // Make a duplicate of the source ByteBuffer and read data from the + // duplicate. This is to avoid affecting the source ByteBuffer's state. + ByteBuffer temp = source.duplicate(); + // We want to copy all the data in the source ByteBuffer, not just the + // remaining bytes. + temp.clear(); + ByteBuffer result = ByteBuffer.allocate(temp.capacity()); + result.put(temp); + result.clear(); + return result; + } + + /** + * 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 + * round tripping the bytes without loss. More precisely, returns {@code true} whenever: + * + *

{@code
+   * Arrays.equals(byteString.toByteArray(),
+   *     new String(byteString.toByteArray(), "UTF-8").getBytes("UTF-8"))
+   * }
+ * + *

This method rejects "overlong" byte sequences, as well as 3-byte sequences that would map to + * a surrogate character, in accordance with the restricted definition of UTF-8 introduced in + * Unicode 3.1. Note that the UTF-8 decoder included in Oracle's JDK has been modified to also + * reject "overlong" byte sequences, but currently (2011) still accepts 3-byte surrogate character + * byte sequences. + * + *

See the Unicode Standard,
+ * Table 3-6. UTF-8 Bit Distribution,
+ * Table 3-7. Well Formed UTF-8 Byte Sequences. + * + *

As of 2011-02, this method simply returns the result of {@link ByteString#isValidUtf8()}. + * Calling that method directly is preferred. + * + * @param byteString the string to check + * @return whether the byte array is round trippable + */ + public static boolean isValidUtf8(ByteString byteString) { + return byteString.isValidUtf8(); + } + + /** Like {@link #isValidUtf8(ByteString)} but for byte arrays. */ + public static boolean isValidUtf8(byte[] byteArray) { + return Utf8.isValidUtf8(byteArray); + } + + /** Helper method to get the UTF-8 bytes of a string. */ + public static byte[] toByteArray(String value) { + return value.getBytes(UTF_8); + } + + /** Helper method to convert a byte array to a string using UTF-8 encoding. */ + public static String toStringUtf8(byte[] bytes) { + return new String(bytes, UTF_8); + } + + /** + * Interface for an enum value or value descriptor, to be used in FieldSet. The lite library + * stores enum values directly in FieldSets but the full library stores EnumValueDescriptors in + * order to better support reflection. + */ + public interface EnumLite { + int getNumber(); + } + + /** + * Interface for an object which maps integers to {@link EnumLite}s. {@link + * Descriptors.EnumDescriptor} implements this interface by mapping numbers to {@link + * Descriptors.EnumValueDescriptor}s. Additionally, every generated enum type has a static method + * internalGetValueMap() which returns an implementation of this type that maps numbers to enum + * values. + */ + public interface EnumLiteMap { + T findValueByNumber(int number); + } + + /** Interface for an object which verifies integers are in range. */ + public interface EnumVerifier { + boolean isInRange(int number); + } + + /** + * Helper method for implementing {@link Message#hashCode()} for longs. + * + * @see Long#hashCode() + */ + public static int hashLong(long n) { + return (int) (n ^ (n >>> 32)); + } + + /** + * Helper method for implementing {@link Message#hashCode()} for booleans. + * + * @see Boolean#hashCode() + */ + public static int hashBoolean(boolean b) { + return b ? 1231 : 1237; + } + + /** + * Helper method for implementing {@link Message#hashCode()} for enums. + * + *

This is needed because {@link java.lang.Enum#hashCode()} is final, but we need to use the + * field number as the hash code to ensure compatibility between statically and dynamically + * generated enum objects. + */ + public static int hashEnum(EnumLite e) { + return e.getNumber(); + } + + /** Helper method for implementing {@link Message#hashCode()} for enum lists. */ + public static int hashEnumList(List list) { + int hash = 1; + for (EnumLite e : list) { + hash = 31 * hash + hashEnum(e); + } + return hash; + } + + /** Helper method for implementing {@link Message#equals(Object)} for bytes field. */ + public static boolean equals(List a, List b) { + if (a.size() != b.size()) return false; + for (int i = 0; i < a.size(); ++i) { + if (!Arrays.equals(a.get(i), b.get(i))) { + return false; + } + } + return true; + } + + /** Helper method for implementing {@link Message#hashCode()} for bytes field. */ + public static int hashCode(List list) { + int hash = 1; + for (byte[] bytes : list) { + hash = 31 * hash + hashCode(bytes); + } + return hash; + } + + /** Helper method for implementing {@link Message#hashCode()} for bytes field. */ + public static int hashCode(byte[] bytes) { + // The hash code for a byte array should be the same as the hash code for a + // ByteString with the same content. This is to ensure that the generated + // hashCode() method will return the same value as the pure reflection + // based hashCode() method. + return Internal.hashCode(bytes, 0, bytes.length); + } + + /** Helper method for implementing {@link LiteralByteString#hashCode()}. */ + static int hashCode(byte[] bytes, int offset, int length) { + // The hash code for a byte array should be the same as the hash code for a + // ByteString with the same content. This is to ensure that the generated + // hashCode() method will return the same value as the pure reflection + // based hashCode() method. + int h = Internal.partialHash(length, bytes, offset, length); + return h == 0 ? 1 : h; + } + + /** Helper method for continuously hashing bytes. */ + static int partialHash(int h, byte[] bytes, int offset, int length) { + for (int i = offset; i < offset + length; i++) { + h = h * 31 + bytes[i]; + } + return h; + } + + /** Helper method for implementing {@link Message#equals(Object)} for bytes field. */ + public static boolean equalsByteBuffer(ByteBuffer a, ByteBuffer b) { + if (a.capacity() != b.capacity()) { + return false; + } + // ByteBuffer.equals() will only compare the remaining bytes, but we want to + // compare all the content. + return a.duplicate().clear().equals(b.duplicate().clear()); + } + + /** Helper method for implementing {@link Message#equals(Object)} for bytes field. */ + public static boolean equalsByteBuffer(List a, List b) { + if (a.size() != b.size()) { + return false; + } + for (int i = 0; i < a.size(); ++i) { + if (!equalsByteBuffer(a.get(i), b.get(i))) { + return false; + } + } + return true; + } + + /** Helper method for implementing {@link Message#hashCode()} for bytes field. */ + public static int hashCodeByteBuffer(List list) { + int hash = 1; + for (ByteBuffer bytes : list) { + hash = 31 * hash + hashCodeByteBuffer(bytes); + } + return hash; + } + + private static final int DEFAULT_BUFFER_SIZE = 4096; + + /** Helper method for implementing {@link Message#hashCode()} for bytes field. */ + public static int hashCodeByteBuffer(ByteBuffer bytes) { + if (bytes.hasArray()) { + // Fast path. + int h = partialHash(bytes.capacity(), bytes.array(), bytes.arrayOffset(), bytes.capacity()); + return h == 0 ? 1 : h; + } else { + // Read the data into a temporary byte array before calculating the + // hash value. + final int bufferSize = + bytes.capacity() > DEFAULT_BUFFER_SIZE ? DEFAULT_BUFFER_SIZE : bytes.capacity(); + final byte[] buffer = new byte[bufferSize]; + final ByteBuffer duplicated = bytes.duplicate(); + duplicated.clear(); + int h = bytes.capacity(); + while (duplicated.remaining() > 0) { + final int length = + duplicated.remaining() <= bufferSize ? duplicated.remaining() : bufferSize; + duplicated.get(buffer, 0, length); + h = partialHash(h, buffer, 0, length); + } + return h == 0 ? 1 : h; + } + } + + @SuppressWarnings("unchecked") + public static T getDefaultInstance(Class clazz) { + try { + Method method = clazz.getMethod("getDefaultInstance"); + return (T) method.invoke(method); + } catch (Exception e) { + throw new RuntimeException("Failed to get default instance for " + clazz, e); + } + } + + + /** An empty byte array constant used in generated code. */ + public static final byte[] EMPTY_BYTE_ARRAY = new byte[0]; + + /** An empty byte array constant used in generated code. */ + public static final ByteBuffer EMPTY_BYTE_BUFFER = ByteBuffer.wrap(EMPTY_BYTE_ARRAY); + + /** An empty coded input stream constant used in generated code. */ + public static final CodedInputStream EMPTY_CODED_INPUT_STREAM = + CodedInputStream.newInstance(EMPTY_BYTE_ARRAY); + + + /** Helper method to merge two MessageLite instances. */ + static Object mergeMessage(Object destination, Object source) { + return ((MessageLite) destination).toBuilder().mergeFrom((MessageLite) source).buildPartial(); + } + + /** + * Provides an immutable view of {@code List} around a {@code List}. + * + *

Protobuf internal. Used in protobuf generated code only. + */ + public static class ListAdapter extends AbstractList { + /** Convert individual elements of the List from F to T. */ + public interface Converter { + T convert(F from); + } + + private final List fromList; + private final Converter converter; + + public ListAdapter(List fromList, Converter converter) { + this.fromList = fromList; + this.converter = converter; + } + + @Override + public T get(int index) { + return converter.convert(fromList.get(index)); + } + + @Override + public int size() { + return fromList.size(); + } + } + + /** Wrap around a {@code Map} and provide a {@code Map} interface. */ + public static class MapAdapter extends AbstractMap { + /** An interface used to convert between two types. */ + public interface Converter { + B doForward(A object); + + A doBackward(B object); + } + + public static Converter newEnumConverter( + final EnumLiteMap enumMap, final T unrecognizedValue) { + return new Converter() { + @Override + public T doForward(Integer value) { + T result = enumMap.findValueByNumber(value); + return result == null ? unrecognizedValue : result; + } + + @Override + public Integer doBackward(T value) { + return value.getNumber(); + } + }; + } + + private final Map realMap; + private final Converter valueConverter; + + public MapAdapter(Map realMap, Converter valueConverter) { + this.realMap = realMap; + this.valueConverter = valueConverter; + } + + @SuppressWarnings("unchecked") + @Override + public V get(Object key) { + RealValue result = realMap.get(key); + if (result == null) { + return null; + } + return valueConverter.doForward(result); + } + + @Override + public V put(K key, V value) { + RealValue oldValue = realMap.put(key, valueConverter.doBackward(value)); + if (oldValue == null) { + return null; + } + return valueConverter.doForward(oldValue); + } + + @Override + public Set> entrySet() { + return new SetAdapter(realMap.entrySet()); + } + + private class SetAdapter extends AbstractSet> { + private final Set> realSet; + + public SetAdapter(Set> realSet) { + this.realSet = realSet; + } + + @Override + public Iterator> iterator() { + return new IteratorAdapter(realSet.iterator()); + } + + @Override + public int size() { + return realSet.size(); + } + } + + private class IteratorAdapter implements Iterator> { + private final Iterator> realIterator; + + public IteratorAdapter(Iterator> realIterator) { + this.realIterator = realIterator; + } + + @Override + public boolean hasNext() { + return realIterator.hasNext(); + } + + @Override + public java.util.Map.Entry next() { + return new EntryAdapter(realIterator.next()); + } + + @Override + public void remove() { + realIterator.remove(); + } + } + + private class EntryAdapter implements Map.Entry { + private final Map.Entry realEntry; + + public EntryAdapter(Map.Entry realEntry) { + this.realEntry = realEntry; + } + + @Override + public K getKey() { + return realEntry.getKey(); + } + + @Override + public V getValue() { + return valueConverter.doForward(realEntry.getValue()); + } + + @Override + public V setValue(V value) { + RealValue oldValue = realEntry.setValue(valueConverter.doBackward(value)); + if (oldValue == null) { + return null; + } + return valueConverter.doForward(oldValue); + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (!(o instanceof Map.Entry)) { + return false; + } + @SuppressWarnings("unchecked") + Map.Entry other = (Map.Entry) o; + return getKey().equals(other.getKey()) && getValue().equals(getValue()); + } + + @Override + public int hashCode() { + return realEntry.hashCode(); + } + } + } + + /** + * Extends {@link List} to add the capability to make the list immutable and inspect if it is + * modifiable. + * + *

All implementations must support efficient random access. + */ + public static interface ProtobufList extends List, RandomAccess { + + /** + * Makes this list immutable. All subsequent modifications will throw an {@link + * UnsupportedOperationException}. + */ + void makeImmutable(); + + /** + * Returns whether this list can be modified via the publicly accessible {@link List} methods. + */ + boolean isModifiable(); + + /** Returns a mutable clone of this list with the specified capacity. */ + ProtobufList mutableCopyWithCapacity(int capacity); + } + + /** + * A {@link java.util.List} implementation that avoids boxing the elements into Integers if + * possible. Does not support null elements. + */ + public static interface IntList extends ProtobufList { + + /** Like {@link #get(int)} but more efficient in that it doesn't box the returned value. */ + int getInt(int index); + + /** Like {@link #add(Object)} but more efficient in that it doesn't box the element. */ + void addInt(int element); + + /** Like {@link #set(int, Object)} but more efficient in that it doesn't box the element. */ + int setInt(int index, int element); + + /** Returns a mutable clone of this list with the specified capacity. */ + @Override + IntList mutableCopyWithCapacity(int capacity); + } + + /** + * A {@link java.util.List} implementation that avoids boxing the elements into Booleans if + * possible. Does not support null elements. + */ + public static interface BooleanList extends ProtobufList { + + /** Like {@link #get(int)} but more efficient in that it doesn't box the returned value. */ + boolean getBoolean(int index); + + /** Like {@link #add(Object)} but more efficient in that it doesn't box the element. */ + void addBoolean(boolean element); + + /** Like {@link #set(int, Object)} but more efficient in that it doesn't box the element. */ + boolean setBoolean(int index, boolean element); + + /** Returns a mutable clone of this list with the specified capacity. */ + @Override + BooleanList mutableCopyWithCapacity(int capacity); + } + + /** + * A {@link java.util.List} implementation that avoids boxing the elements into Longs if possible. + * Does not support null elements. + */ + public static interface LongList extends ProtobufList { + + /** Like {@link #get(int)} but more efficient in that it doesn't box the returned value. */ + long getLong(int index); + + /** Like {@link #add(Object)} but more efficient in that it doesn't box the element. */ + void addLong(long element); + + /** Like {@link #set(int, Object)} but more efficient in that it doesn't box the element. */ + long setLong(int index, long element); + + /** Returns a mutable clone of this list with the specified capacity. */ + @Override + LongList mutableCopyWithCapacity(int capacity); + } + + /** + * A {@link java.util.List} implementation that avoids boxing the elements into Doubles if + * possible. Does not support null elements. + */ + public static interface DoubleList extends ProtobufList { + + /** Like {@link #get(int)} but more efficient in that it doesn't box the returned value. */ + double getDouble(int index); + + /** Like {@link #add(Object)} but more efficient in that it doesn't box the element. */ + void addDouble(double element); + + /** Like {@link #set(int, Object)} but more efficient in that it doesn't box the element. */ + double setDouble(int index, double element); + + /** Returns a mutable clone of this list with the specified capacity. */ + @Override + DoubleList mutableCopyWithCapacity(int capacity); + } + + /** + * A {@link java.util.List} implementation that avoids boxing the elements into Floats if + * possible. Does not support null elements. + */ + public static interface FloatList extends ProtobufList { + + /** Like {@link #get(int)} but more efficient in that it doesn't box the returned value. */ + float getFloat(int index); + + /** Like {@link #add(Object)} but more efficient in that it doesn't box the element. */ + void addFloat(float element); + + /** Like {@link #set(int, Object)} but more efficient in that it doesn't box the element. */ + float setFloat(int index, float element); + + /** Returns a mutable clone of this list with the specified capacity. */ + @Override + FloatList mutableCopyWithCapacity(int capacity); + } + +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/InvalidProtocolBufferException.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/InvalidProtocolBufferException.java new file mode 100644 index 0000000000000..4b4303374c83d --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/InvalidProtocolBufferException.java @@ -0,0 +1,166 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +import java.io.IOException; + +/** + * Thrown when a protocol message being parsed is invalid in some way, e.g. it contains a malformed + * varint or a negative byte length. + * + * @author kenton@google.com Kenton Varda + */ +public class InvalidProtocolBufferException extends IOException { + private static final long serialVersionUID = -1616151763072450476L; + private MessageLite unfinishedMessage = null; + private boolean wasThrownFromInputStream; + + public InvalidProtocolBufferException(final String description) { + super(description); + } + + public InvalidProtocolBufferException(IOException e) { + super(e.getMessage(), e); + } + + public InvalidProtocolBufferException(final String description, IOException e) { + super(description, e); + } + + /** + * Attaches an unfinished message to the exception to support best-effort parsing in {@code + * Parser} interface. + * + * @return this + */ + public InvalidProtocolBufferException setUnfinishedMessage(MessageLite unfinishedMessage) { + this.unfinishedMessage = unfinishedMessage; + return this; + } + + /** + * Returns the unfinished message attached to the exception, or null if no message is attached. + */ + public MessageLite getUnfinishedMessage() { + return unfinishedMessage; + } + + /** Set by CodedInputStream */ + void setThrownFromInputStream() { + /* This write can be racy if the same exception is stored and then thrown by multiple custom + * InputStreams on different threads. But since it only ever moves from false->true, there's no + * problem. A thread checking this condition after catching this exception from a delegate + * stream of CodedInputStream is guaranteed to always observe true, because a write on the same + * thread set the value when the exception left the delegate. A thread checking the same + * condition with an exception created by CodedInputStream is guaranteed to always see false, + * because the exception has not been exposed to any code that could publish it to other threads + * and cause a write. + */ + wasThrownFromInputStream = true; + } + + /** + * Allows code catching IOException from CodedInputStream to tell whether this instance was thrown + * by a delegate InputStream, rather than directly by a parse failure. + */ + boolean getThrownFromInputStream() { + return wasThrownFromInputStream; + } + + /** + * Unwraps the underlying {@link IOException} if this exception was caused by an I/O problem. + * Otherwise, returns {@code this}. + */ + public IOException unwrapIOException() { + return getCause() instanceof IOException ? (IOException) getCause() : this; + } + + static InvalidProtocolBufferException truncatedMessage() { + return new InvalidProtocolBufferException( + "While parsing a protocol message, the input ended unexpectedly " + + "in the middle of a field. This could mean either that the " + + "input has been truncated or that an embedded message " + + "misreported its own length."); + } + + static InvalidProtocolBufferException negativeSize() { + return new InvalidProtocolBufferException( + "CodedInputStream encountered an embedded string or message " + + "which claimed to have negative size."); + } + + static InvalidProtocolBufferException malformedVarint() { + return new InvalidProtocolBufferException("CodedInputStream encountered a malformed varint."); + } + + static InvalidProtocolBufferException invalidTag() { + return new InvalidProtocolBufferException("Protocol message contained an invalid tag (zero)."); + } + + static InvalidProtocolBufferException invalidEndTag() { + return new InvalidProtocolBufferException( + "Protocol message end-group tag did not match expected tag."); + } + + static InvalidWireTypeException invalidWireType() { + return new InvalidWireTypeException("Protocol message tag had invalid wire type."); + } + + /** Exception indicating that and unexpected wire type was encountered for a field. */ + @ExperimentalApi + public static class InvalidWireTypeException extends InvalidProtocolBufferException { + private static final long serialVersionUID = 3283890091615336259L; + + public InvalidWireTypeException(String description) { + super(description); + } + } + + static InvalidProtocolBufferException recursionLimitExceeded() { + return new InvalidProtocolBufferException( + "Protocol message had too many levels of nesting. May be malicious. " + + "Use CodedInputStream.setRecursionLimit() to increase the depth limit."); + } + + static InvalidProtocolBufferException sizeLimitExceeded() { + return new InvalidProtocolBufferException( + "Protocol message was too large. May be malicious. " + + "Use CodedInputStream.setSizeLimit() to increase the size limit."); + } + + static InvalidProtocolBufferException parseFailure() { + return new InvalidProtocolBufferException("Failed to parse the message."); + } + + static InvalidProtocolBufferException invalidUtf8() { + return new InvalidProtocolBufferException("Protocol message had invalid UTF-8."); + } +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/IterableByteBufferInputStream.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/IterableByteBufferInputStream.java new file mode 100644 index 0000000000000..713e80646931f --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/IterableByteBufferInputStream.java @@ -0,0 +1,150 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +import static com.google.protobuf.Internal.EMPTY_BYTE_BUFFER; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.ByteBuffer; +import java.util.Iterator; + +class IterableByteBufferInputStream extends InputStream { + /** The {@link Iterator} with type {@link ByteBuffer} of {@code input} */ + private Iterator iterator; + /** The current ByteBuffer; */ + private ByteBuffer currentByteBuffer; + /** The number of ByteBuffers in the input data. */ + private int dataSize; + /** + * Current {@code ByteBuffer}'s index + * + *

If index equals dataSize, then all the data in the InputStream has been consumed + */ + private int currentIndex; + /** The current position for current ByteBuffer */ + private int currentByteBufferPos; + /** Whether current ByteBuffer has an array */ + private boolean hasArray; + /** + * If the current ByteBuffer is unsafe-direct based, currentArray is null; otherwise should be the + * array inside ByteBuffer. + */ + private byte[] currentArray; + /** Current ByteBuffer's array offset */ + private int currentArrayOffset; + /** + * If the current ByteBuffer is unsafe-direct based, currentAddress is the start address of this + * ByteBuffer; otherwise should be zero. + */ + private long currentAddress; + + IterableByteBufferInputStream(Iterable data) { + iterator = data.iterator(); + dataSize = 0; + for (ByteBuffer unused : data) { + dataSize++; + } + currentIndex = -1; + + if (!getNextByteBuffer()) { + currentByteBuffer = EMPTY_BYTE_BUFFER; + currentIndex = 0; + currentByteBufferPos = 0; + currentAddress = 0; + } + } + + private boolean getNextByteBuffer() { + currentIndex++; + if (!iterator.hasNext()) { + return false; + } + currentByteBuffer = iterator.next(); + currentByteBufferPos = currentByteBuffer.position(); + if (currentByteBuffer.hasArray()) { + hasArray = true; + currentArray = currentByteBuffer.array(); + currentArrayOffset = currentByteBuffer.arrayOffset(); + } else { + hasArray = false; + currentAddress = UnsafeUtil.addressOffset(currentByteBuffer); + currentArray = null; + } + return true; + } + + private void updateCurrentByteBufferPos(int numberOfBytesRead) { + currentByteBufferPos += numberOfBytesRead; + if (currentByteBufferPos == currentByteBuffer.limit()) { + getNextByteBuffer(); + } + } + + @Override + public int read() throws IOException { + if (currentIndex == dataSize) { + return -1; + } + if (hasArray) { + int result = currentArray[currentByteBufferPos + currentArrayOffset] & 0xFF; + updateCurrentByteBufferPos(1); + return result; + } else { + int result = UnsafeUtil.getByte(currentByteBufferPos + currentAddress) & 0xFF; + updateCurrentByteBufferPos(1); + return result; + } + } + + @Override + public int read(byte[] output, int offset, int length) throws IOException { + if (currentIndex == dataSize) { + return -1; + } + int remaining = currentByteBuffer.limit() - currentByteBufferPos; + if (length > remaining) { + length = remaining; + } + if (hasArray) { + System.arraycopy( + currentArray, currentByteBufferPos + currentArrayOffset, output, offset, length); + updateCurrentByteBufferPos(length); + } else { + int prevPos = currentByteBuffer.position(); + currentByteBuffer.position(currentByteBufferPos); + currentByteBuffer.get(output, offset, length); + currentByteBuffer.position(prevPos); + updateCurrentByteBufferPos(length); + } + return length; + } +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/JavaType.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/JavaType.java new file mode 100644 index 0000000000000..770aa9ef1ff5c --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/JavaType.java @@ -0,0 +1,76 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +/** Enum that identifies the Java types required to store protobuf fields. */ +@ExperimentalApi +public enum JavaType { + VOID(Void.class, Void.class, null), + INT(int.class, Integer.class, 0), + LONG(long.class, Long.class, 0L), + FLOAT(float.class, Float.class, 0F), + DOUBLE(double.class, Double.class, 0D), + BOOLEAN(boolean.class, Boolean.class, false), + STRING(String.class, String.class, ""), + BYTE_STRING(ByteString.class, ByteString.class, ByteString.EMPTY), + ENUM(int.class, Integer.class, null), + MESSAGE(Object.class, Object.class, null); + + private final Class type; + private final Class boxedType; + private final Object defaultDefault; + + JavaType(Class type, Class boxedType, Object defaultDefault) { + this.type = type; + this.boxedType = boxedType; + this.defaultDefault = defaultDefault; + } + + /** The default default value for fields of this type, if it's a primitive type. */ + public Object getDefaultDefault() { + return defaultDefault; + } + + /** Gets the required type for a field that would hold a value of this type. */ + public Class getType() { + return type; + } + + /** @return the boxedType */ + public Class getBoxedType() { + return boxedType; + } + + /** Indicates whether or not this {@link JavaType} can be applied to a field of the given type. */ + public boolean isValidType(Class t) { + return type.isAssignableFrom(t); + } +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/LazyField.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/LazyField.java new file mode 100644 index 0000000000000..891171d7c867a --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/LazyField.java @@ -0,0 +1,154 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +import java.util.Iterator; +import java.util.Map.Entry; + +/** + * LazyField encapsulates the logic of lazily parsing message fields. It stores the message in a + * ByteString initially and then parse it on-demand. + * + *

Most of key methods are implemented in {@link LazyFieldLite} but this class can contain + * default instance of the message to provide {@code hashCode()}, {@code euqals()} and {@code + * toString()}. + * + * @author xiangl@google.com (Xiang Li) + */ +public class LazyField extends LazyFieldLite { + + /** + * Carry a message's default instance which is used by {@code hashCode()}, {@code euqals()} and + * {@code toString()}. + */ + private final MessageLite defaultInstance; + + public LazyField( + MessageLite defaultInstance, ExtensionRegistryLite extensionRegistry, ByteString bytes) { + super(extensionRegistry, bytes); + + this.defaultInstance = defaultInstance; + } + + @Override + public boolean containsDefaultInstance() { + return super.containsDefaultInstance() || value == defaultInstance; + } + + public MessageLite getValue() { + return getValue(defaultInstance); + } + + @Override + public int hashCode() { + return getValue().hashCode(); + } + + @Override + public boolean equals(Object obj) { + return getValue().equals(obj); + } + + @Override + public String toString() { + return getValue().toString(); + } + + // ==================================================== + + /** + * LazyEntry and LazyIterator are used to encapsulate the LazyField, when users iterate all fields + * from FieldSet. + */ + static class LazyEntry implements Entry { + private Entry entry; + + private LazyEntry(Entry entry) { + this.entry = entry; + } + + @Override + public K getKey() { + return entry.getKey(); + } + + @Override + public Object getValue() { + LazyField field = entry.getValue(); + if (field == null) { + return null; + } + return field.getValue(); + } + + public LazyField getField() { + return entry.getValue(); + } + + @Override + public Object setValue(Object value) { + if (!(value instanceof MessageLite)) { + throw new IllegalArgumentException( + "LazyField now only used for MessageSet, " + + "and the value of MessageSet must be an instance of MessageLite"); + } + return entry.getValue().setValue((MessageLite) value); + } + } + + static class LazyIterator implements Iterator> { + private Iterator> iterator; + + public LazyIterator(Iterator> iterator) { + this.iterator = iterator; + } + + @Override + public boolean hasNext() { + return iterator.hasNext(); + } + + @Override + @SuppressWarnings("unchecked") + public Entry next() { + Entry entry = iterator.next(); + if (entry.getValue() instanceof LazyField) { + return new LazyEntry((Entry) entry); + } + return (Entry) entry; + } + + @Override + public void remove() { + iterator.remove(); + } + } +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/LazyFieldLite.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/LazyFieldLite.java new file mode 100644 index 0000000000000..6fab26fc53711 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/LazyFieldLite.java @@ -0,0 +1,441 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +import java.io.IOException; + +/** + * LazyFieldLite encapsulates the logic of lazily parsing message fields. It stores the message in a + * ByteString initially and then parses it on-demand. + * + *

LazyFieldLite is thread-compatible: concurrent reads are safe once the proto that this + * LazyFieldLite is a part of is no longer being mutated by its Builder. However, explicit + * synchronization is needed under read/write situations. + * + *

When a LazyFieldLite is used in the context of a MessageLite object, its behavior is + * considered to be immutable and none of the setter methods in its API are expected to be invoked. + * All of the getters are expected to be thread-safe. When used in the context of a + * MessageLite.Builder, setters can be invoked, but there is no guarantee of thread safety. + * + *

TODO(yatin,dweis): Consider splitting this class's functionality and put the mutable methods + * into a separate builder class to allow us to give stronger compile-time guarantees. + * + *

This class is internal implementation detail of the protobuf library, so you don't need to use + * it directly. + * + * @author xiangl@google.com (Xiang Li) + */ +public class LazyFieldLite { + private static final ExtensionRegistryLite EMPTY_REGISTRY = + ExtensionRegistryLite.getEmptyRegistry(); + + /* + * The value associated with the LazyFieldLite object is stored in one or more of the following + * three fields (delayedBytes, value, memoizedBytes). They should together be interpreted as + * follows. + * + * 1) delayedBytes can be non-null, while value and memoizedBytes is null. The object will be in + * this state while the value for the object has not yet been parsed. + * + * 2) Both delayedBytes and value are non-null. The object transitions to this state as soon as + * some caller needs to access the value (by invoking getValue()). + * + * 3) memoizedBytes is merely an optimization for calls to LazyFieldLite.toByteString() to avoid + * recomputing the ByteString representation on each call. Instead, when the value is parsed from + * delayedBytes, we will also assign the contents of delayedBytes to memoizedBytes (since that is + * the ByteString representation of value). + * + * 4) Finally, if the LazyFieldLite was created directly with a parsed MessageLite value, then + * delayedBytes will be null, and memoizedBytes will be initialized only upon the first call to + * LazyFieldLite.toByteString(). + * + *

Given the above conditions, any caller that needs a serialized representation of this object + * must first check if the memoizedBytes or delayedBytes ByteString is non-null and use it + * directly; if both of those are null, it can look at the parsed value field. Similarly, any + * caller that needs a parsed value must first check if the value field is already non-null, if + * not it must parse the value from delayedBytes. + */ + + /** + * A delayed-parsed version of the contents of this field. When this field is non-null, then the + * "value" field is allowed to be null until the time that the value needs to be read. + * + *

When delayedBytes is non-null then {@code extensionRegistry} is required to also be + * non-null. {@code value} and {@code memoizedBytes} will be initialized lazily. + */ + private ByteString delayedBytes; + + /** + * An {@code ExtensionRegistryLite} for parsing bytes. It is non-null on a best-effort basis. It + * is only guaranteed to be non-null if this message was initialized using bytes and an {@code + * ExtensionRegistry}. If it directly had a value set then it will be null, unless it has been + * merged with another {@code LazyFieldLite} that had an {@code ExtensionRegistry}. + */ + private ExtensionRegistryLite extensionRegistry; + + /** + * The parsed value. When this is null and a caller needs access to the MessageLite value, then + * {@code delayedBytes} will be parsed lazily at that time. + */ + protected volatile MessageLite value; + + /** + * The memoized bytes for {@code value}. This is an optimization for the toByteString() method to + * not have to recompute its return-value on each invocation. TODO(yatin): Figure out whether this + * optimization is actually necessary. + */ + private volatile ByteString memoizedBytes; + + /** Constructs a LazyFieldLite with bytes that will be parsed lazily. */ + public LazyFieldLite(ExtensionRegistryLite extensionRegistry, ByteString bytes) { + checkArguments(extensionRegistry, bytes); + this.extensionRegistry = extensionRegistry; + this.delayedBytes = bytes; + } + + /** Constructs a LazyFieldLite with no contents, and no ability to parse extensions. */ + public LazyFieldLite() {} + + /** + * Constructs a LazyFieldLite instance with a value. The LazyFieldLite may not be able to parse + * the extensions in the value as it has no ExtensionRegistry. + */ + public static LazyFieldLite fromValue(MessageLite value) { + LazyFieldLite lf = new LazyFieldLite(); + lf.setValue(value); + return lf; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + + if (!(o instanceof LazyFieldLite)) { + return false; + } + + LazyFieldLite other = (LazyFieldLite) o; + + // Lazy fields do not work well with equals... If both are delayedBytes, we do not have a + // mechanism to deserialize them so we rely on bytes equality. Otherwise we coerce into an + // actual message (if necessary) and call equals on the message itself. This implies that two + // messages can by unequal but then be turned equal simply be invoking a getter on a lazy field. + MessageLite value1 = value; + MessageLite value2 = other.value; + if (value1 == null && value2 == null) { + return toByteString().equals(other.toByteString()); + } else if (value1 != null && value2 != null) { + return value1.equals(value2); + } else if (value1 != null) { + return value1.equals(other.getValue(value1.getDefaultInstanceForType())); + } else { + return getValue(value2.getDefaultInstanceForType()).equals(value2); + } + } + + @Override + public int hashCode() { + // We can't provide a memoizable hash code for lazy fields. The byte strings may have different + // hash codes but evaluate to equivalent messages. And we have no facility for constructing + // a message here if we were not already holding a value. + return 1; + } + + /** + * Determines whether this LazyFieldLite instance represents the default instance of this type. + */ + public boolean containsDefaultInstance() { + return memoizedBytes == ByteString.EMPTY + || value == null && (delayedBytes == null || delayedBytes == ByteString.EMPTY); + } + + /** + * Clears the value state of this instance. + * + *

LazyField is not thread-safe for write access. Synchronizations are needed under read/write + * situations. + */ + public void clear() { + // Don't clear the ExtensionRegistry. It might prove useful later on when merging in another + // value, but there is no guarantee that it will contain all extensions that were directly set + // on the values that need to be merged. + delayedBytes = null; + value = null; + memoizedBytes = null; + } + + /** + * Overrides the contents of this LazyField. + * + *

LazyField is not thread-safe for write access. Synchronizations are needed under read/write + * situations. + */ + public void set(LazyFieldLite other) { + this.delayedBytes = other.delayedBytes; + this.value = other.value; + this.memoizedBytes = other.memoizedBytes; + // If the other LazyFieldLite was created by directly setting the value rather than first by + // parsing, then it will not have an extensionRegistry. In this case we hold on to the existing + // extensionRegistry, which has no guarantees that it has all the extensions that will be + // directly set on the value. + if (other.extensionRegistry != null) { + this.extensionRegistry = other.extensionRegistry; + } + } + + /** + * Returns message instance. It may do some thread-safe delayed parsing of bytes. + * + * @param defaultInstance its message's default instance. It's also used to get parser for the + * message type. + */ + public MessageLite getValue(MessageLite defaultInstance) { + ensureInitialized(defaultInstance); + return value; + } + + /** + * Sets the value of the instance and returns the old value without delay parsing anything. + * + *

LazyField is not thread-safe for write access. Synchronizations are needed under read/write + * situations. + */ + public MessageLite setValue(MessageLite value) { + MessageLite originalValue = this.value; + this.delayedBytes = null; + this.memoizedBytes = null; + this.value = value; + return originalValue; + } + + /** + * Merges another instance's contents. In some cases may drop some extensions if both fields + * contain data. If the other field has an {@code ExtensionRegistry} but this does not, then this + * field will copy over that {@code ExtensionRegistry}. + * + *

LazyField is not thread-safe for write access. Synchronizations are needed under read/write + * situations. + */ + public void merge(LazyFieldLite other) { + if (other.containsDefaultInstance()) { + return; + } + + if (this.containsDefaultInstance()) { + set(other); + return; + } + + // If the other field has an extension registry but this does not, copy over the other extension + // registry. + if (this.extensionRegistry == null) { + this.extensionRegistry = other.extensionRegistry; + } + + // In the case that both of them are not parsed we simply concatenate the bytes to save time. In + // the (probably rare) case that they have different extension registries there is a chance that + // some of the extensions may be dropped, but the tradeoff of making this operation fast seems + // to outway the benefits of combining the extension registries, which is not normally done for + // lite protos anyways. + if (this.delayedBytes != null && other.delayedBytes != null) { + this.delayedBytes = this.delayedBytes.concat(other.delayedBytes); + return; + } + + // At least one is parsed and both contain data. We won't drop any extensions here directly, but + // in the case that the extension registries are not the same then we might in the future if we + // need to serialize and parse a message again. + if (this.value == null && other.value != null) { + setValue(mergeValueAndBytes(other.value, this.delayedBytes, this.extensionRegistry)); + return; + } else if (this.value != null && other.value == null) { + setValue(mergeValueAndBytes(this.value, other.delayedBytes, other.extensionRegistry)); + return; + } + + // At this point we have two fully parsed messages. + setValue(this.value.toBuilder().mergeFrom(other.value).build()); + } + + /** + * Merges another instance's contents from a stream. + * + *

LazyField is not thread-safe for write access. Synchronizations are needed under read/write + * situations. + */ + public void mergeFrom(CodedInputStream input, ExtensionRegistryLite extensionRegistry) + throws IOException { + if (this.containsDefaultInstance()) { + setByteString(input.readBytes(), extensionRegistry); + return; + } + + // If the other field has an extension registry but this does not, copy over the other extension + // registry. + if (this.extensionRegistry == null) { + this.extensionRegistry = extensionRegistry; + } + + // In the case that both of them are not parsed we simply concatenate the bytes to save time. In + // the (probably rare) case that they have different extension registries there is a chance that + // some of the extensions may be dropped, but the tradeoff of making this operation fast seems + // to outway the benefits of combining the extension registries, which is not normally done for + // lite protos anyways. + if (this.delayedBytes != null) { + setByteString(this.delayedBytes.concat(input.readBytes()), this.extensionRegistry); + return; + } + + // We are parsed and both contain data. We won't drop any extensions here directly, but in the + // case that the extension registries are not the same then we might in the future if we + // need to serialize and parse a message again. + try { + setValue(value.toBuilder().mergeFrom(input, extensionRegistry).build()); + } catch (InvalidProtocolBufferException e) { + // Nothing is logged and no exceptions are thrown. Clients will be unaware that a proto + // was invalid. + } + } + + private static MessageLite mergeValueAndBytes( + MessageLite value, ByteString otherBytes, ExtensionRegistryLite extensionRegistry) { + try { + return value.toBuilder().mergeFrom(otherBytes, extensionRegistry).build(); + } catch (InvalidProtocolBufferException e) { + // Nothing is logged and no exceptions are thrown. Clients will be unaware that a proto + // was invalid. + return value; + } + } + + /** Sets this field with bytes to delay-parse. */ + public void setByteString(ByteString bytes, ExtensionRegistryLite extensionRegistry) { + checkArguments(extensionRegistry, bytes); + this.delayedBytes = bytes; + this.extensionRegistry = extensionRegistry; + this.value = null; + this.memoizedBytes = null; + } + + /** + * Due to the optional field can be duplicated at the end of serialized bytes, which will make the + * serialized size changed after LazyField parsed. Be careful when using this method. + */ + public int getSerializedSize() { + // We *must* return delayed bytes size if it was ever set because the dependent messages may + // have memoized serialized size based off of it. + if (memoizedBytes != null) { + return memoizedBytes.size(); + } else if (delayedBytes != null) { + return delayedBytes.size(); + } else if (value != null) { + return value.getSerializedSize(); + } else { + return 0; + } + } + + /** Returns a BytesString for this field in a thread-safe way. */ + public ByteString toByteString() { + if (memoizedBytes != null) { + return memoizedBytes; + } + // We *must* return delayed bytes if it was set because the dependent messages may have + // memoized serialized size based off of it. + if (delayedBytes != null) { + return delayedBytes; + } + synchronized (this) { + if (memoizedBytes != null) { + return memoizedBytes; + } + if (value == null) { + memoizedBytes = ByteString.EMPTY; + } else { + memoizedBytes = value.toByteString(); + } + return memoizedBytes; + } + } + + /** Writes this lazy field into a {@link Writer}. */ + void writeTo(Writer writer, int fieldNumber) throws IOException { + if (memoizedBytes != null) { + writer.writeBytes(fieldNumber, memoizedBytes); + } else if (delayedBytes != null) { + writer.writeBytes(fieldNumber, delayedBytes); + } else if (value != null) { + writer.writeMessage(fieldNumber, value); + } else { + writer.writeBytes(fieldNumber, ByteString.EMPTY); + } + } + + /** Might lazily parse the bytes that were previously passed in. Is thread-safe. */ + protected void ensureInitialized(MessageLite defaultInstance) { + if (value != null) { + return; + } + synchronized (this) { + if (value != null) { + return; + } + try { + if (delayedBytes != null) { + // The extensionRegistry shouldn't be null here since we have delayedBytes. + MessageLite parsedValue = + defaultInstance.getParserForType().parseFrom(delayedBytes, extensionRegistry); + this.value = parsedValue; + this.memoizedBytes = delayedBytes; + } else { + this.value = defaultInstance; + this.memoizedBytes = ByteString.EMPTY; + } + } catch (InvalidProtocolBufferException e) { + // Nothing is logged and no exceptions are thrown. Clients will be unaware that this proto + // was invalid. + this.value = defaultInstance; + this.memoizedBytes = ByteString.EMPTY; + } + } + } + + private static void checkArguments(ExtensionRegistryLite extensionRegistry, ByteString bytes) { + if (extensionRegistry == null) { + throw new NullPointerException("found null ExtensionRegistry"); + } + if (bytes == null) { + throw new NullPointerException("found null ByteString"); + } + } +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/LazyStringArrayList.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/LazyStringArrayList.java new file mode 100644 index 0000000000000..a2de6f9cfeb0e --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/LazyStringArrayList.java @@ -0,0 +1,417 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +import java.util.AbstractList; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.RandomAccess; + +/** + * An implementation of {@link LazyStringList} that wraps an ArrayList. Each element is one of + * String, ByteString, or byte[]. It caches the last one requested which is most likely the one + * needed next. This minimizes memory usage while satisfying the most common use cases. + * + *

Note that this implementation is not synchronized. If multiple threads access + * an ArrayList instance concurrently, and at least one of the threads modifies the list + * structurally, it must be synchronized externally. (A structural modification is any + * operation that adds or deletes one or more elements, or explicitly resizes the backing array; + * merely setting the value of an element is not a structural modification.) This is typically + * accomplished by synchronizing on some object that naturally encapsulates the list. + * + *

If the implementation is accessed via concurrent reads, this is thread safe. Conversions are + * done in a thread safe manner. It's possible that the conversion may happen more than once if two + * threads attempt to access the same element and the modifications were not visible to each other, + * but this will not result in any corruption of the list or change in behavior other than + * performance. + * + * @author jonp@google.com (Jon Perlow) + */ +public class LazyStringArrayList extends AbstractProtobufList + implements LazyStringList, RandomAccess { + + private static final LazyStringArrayList EMPTY_LIST = new LazyStringArrayList(); + + static { + EMPTY_LIST.makeImmutable(); + } + + static LazyStringArrayList emptyList() { + return EMPTY_LIST; + } + + // For compatibility with older runtimes. + public static final LazyStringList EMPTY = EMPTY_LIST; + + private final List list; + + public LazyStringArrayList() { + this(DEFAULT_CAPACITY); + } + + public LazyStringArrayList(int initialCapacity) { + this(new ArrayList(initialCapacity)); + } + + public LazyStringArrayList(LazyStringList from) { + list = new ArrayList(from.size()); + addAll(from); + } + + public LazyStringArrayList(List from) { + this(new ArrayList(from)); + } + + private LazyStringArrayList(ArrayList list) { + this.list = list; + } + + @Override + public LazyStringArrayList mutableCopyWithCapacity(int capacity) { + if (capacity < size()) { + throw new IllegalArgumentException(); + } + ArrayList newList = new ArrayList(capacity); + newList.addAll(list); + return new LazyStringArrayList(newList); + } + + @Override + public String get(int index) { + Object o = list.get(index); + if (o instanceof String) { + return (String) o; + } else if (o instanceof ByteString) { + ByteString bs = (ByteString) o; + String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + list.set(index, s); + } + return s; + } else { + byte[] ba = (byte[]) o; + String s = Internal.toStringUtf8(ba); + if (Internal.isValidUtf8(ba)) { + list.set(index, s); + } + return s; + } + } + + @Override + public int size() { + return list.size(); + } + + @Override + public String set(int index, String s) { + ensureIsMutable(); + Object o = list.set(index, s); + return asString(o); + } + + @Override + public void add(int index, String element) { + ensureIsMutable(); + list.add(index, element); + modCount++; + } + + private void add(int index, ByteString element) { + ensureIsMutable(); + list.add(index, element); + modCount++; + } + + private void add(int index, byte[] element) { + ensureIsMutable(); + list.add(index, element); + modCount++; + } + + @Override + public boolean addAll(Collection c) { + // The default implementation of AbstractCollection.addAll(Collection) + // delegates to add(Object). This implementation instead delegates to + // addAll(int, Collection), which makes a special case for Collections + // which are instances of LazyStringList. + return addAll(size(), c); + } + + @Override + public boolean addAll(int index, Collection c) { + ensureIsMutable(); + // When copying from another LazyStringList, directly copy the underlying + // elements rather than forcing each element to be decoded to a String. + Collection collection = + c instanceof LazyStringList ? ((LazyStringList) c).getUnderlyingElements() : c; + boolean ret = list.addAll(index, collection); + modCount++; + return ret; + } + + @Override + public boolean addAllByteString(Collection values) { + ensureIsMutable(); + boolean ret = list.addAll(values); + modCount++; + return ret; + } + + @Override + public boolean addAllByteArray(Collection c) { + ensureIsMutable(); + boolean ret = list.addAll(c); + modCount++; + return ret; + } + + @Override + public String remove(int index) { + ensureIsMutable(); + Object o = list.remove(index); + modCount++; + return asString(o); + } + + @Override + public void clear() { + ensureIsMutable(); + list.clear(); + modCount++; + } + + @Override + public void add(ByteString element) { + ensureIsMutable(); + list.add(element); + modCount++; + } + + @Override + public void add(byte[] element) { + ensureIsMutable(); + list.add(element); + modCount++; + } + + @Override + public Object getRaw(int index) { + return list.get(index); + } + + @Override + public ByteString getByteString(int index) { + Object o = list.get(index); + ByteString b = asByteString(o); + if (b != o) { + list.set(index, b); + } + return b; + } + + @Override + public byte[] getByteArray(int index) { + Object o = list.get(index); + byte[] b = asByteArray(o); + if (b != o) { + list.set(index, b); + } + return b; + } + + @Override + public void set(int index, ByteString s) { + setAndReturn(index, s); + } + + private Object setAndReturn(int index, ByteString s) { + ensureIsMutable(); + return list.set(index, s); + } + + @Override + public void set(int index, byte[] s) { + setAndReturn(index, s); + } + + private Object setAndReturn(int index, byte[] s) { + ensureIsMutable(); + return list.set(index, s); + } + + private static String asString(Object o) { + if (o instanceof String) { + return (String) o; + } else if (o instanceof ByteString) { + return ((ByteString) o).toStringUtf8(); + } else { + return Internal.toStringUtf8((byte[]) o); + } + } + + private static ByteString asByteString(Object o) { + if (o instanceof ByteString) { + return (ByteString) o; + } else if (o instanceof String) { + return ByteString.copyFromUtf8((String) o); + } else { + return ByteString.copyFrom((byte[]) o); + } + } + + private static byte[] asByteArray(Object o) { + if (o instanceof byte[]) { + return (byte[]) o; + } else if (o instanceof String) { + return Internal.toByteArray((String) o); + } else { + return ((ByteString) o).toByteArray(); + } + } + + @Override + public List getUnderlyingElements() { + return Collections.unmodifiableList(list); + } + + @Override + public void mergeFrom(LazyStringList other) { + ensureIsMutable(); + for (Object o : other.getUnderlyingElements()) { + if (o instanceof byte[]) { + byte[] b = (byte[]) o; + // Byte array's content is mutable so they should be copied rather than + // shared when merging from one message to another. + list.add(Arrays.copyOf(b, b.length)); + } else { + list.add(o); + } + } + } + + private static class ByteArrayListView extends AbstractList implements RandomAccess { + private final LazyStringArrayList list; + + ByteArrayListView(LazyStringArrayList list) { + this.list = list; + } + + @Override + public byte[] get(int index) { + return list.getByteArray(index); + } + + @Override + public int size() { + return list.size(); + } + + @Override + public byte[] set(int index, byte[] s) { + Object o = list.setAndReturn(index, s); + modCount++; + return asByteArray(o); + } + + @Override + public void add(int index, byte[] s) { + list.add(index, s); + modCount++; + } + + @Override + public byte[] remove(int index) { + Object o = list.remove(index); + modCount++; + return asByteArray(o); + } + } + + @Override + public List asByteArrayList() { + return new ByteArrayListView(this); + } + + private static class ByteStringListView extends AbstractList implements RandomAccess { + private final LazyStringArrayList list; + + ByteStringListView(LazyStringArrayList list) { + this.list = list; + } + + @Override + public ByteString get(int index) { + return list.getByteString(index); + } + + @Override + public int size() { + return list.size(); + } + + @Override + public ByteString set(int index, ByteString s) { + Object o = list.setAndReturn(index, s); + modCount++; + return asByteString(o); + } + + @Override + public void add(int index, ByteString s) { + list.add(index, s); + modCount++; + } + + @Override + public ByteString remove(int index) { + Object o = list.remove(index); + modCount++; + return asByteString(o); + } + } + + @Override + public List asByteStringList() { + return new ByteStringListView(this); + } + + @Override + public LazyStringList getUnmodifiableView() { + if (isModifiable()) { + return new UnmodifiableLazyStringList(this); + } + return this; + } +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/LazyStringList.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/LazyStringList.java new file mode 100644 index 0000000000000..6b55022caa4ab --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/LazyStringList.java @@ -0,0 +1,164 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +import java.util.Collection; +import java.util.List; + +/** + * An interface extending {@code List} that also provides access to the items of the list as + * UTF8-encoded ByteString or byte[] objects. This is used by the protocol buffer implementation to + * support lazily converting bytes parsed over the wire to String objects until needed and also + * increases the efficiency of serialization if the String was never requested as the ByteString or + * byte[] is already cached. The ByteString methods are used in immutable API only and byte[] + * methods used in mutable API only for they use different representations for string/bytes fields. + * + * @author jonp@google.com (Jon Perlow) + */ +public interface LazyStringList extends ProtocolStringList { + + /** + * Returns the element at the specified position in this list as a ByteString. + * + * @param index index of the element to return + * @return the element at the specified position in this list + * @throws IndexOutOfBoundsException if the index is out of range ({@code index < 0 || index >= + * size()}) + */ + ByteString getByteString(int index); + + /** + * Returns the element at the specified position in this list as an Object that will either be a + * String or a ByteString. + * + * @param index index of the element to return + * @return the element at the specified position in this list + * @throws IndexOutOfBoundsException if the index is out of range ({@code index < 0 || index >= + * size()}) + */ + Object getRaw(int index); + + /** + * Returns the element at the specified position in this list as byte[]. + * + * @param index index of the element to return + * @return the element at the specified position in this list + * @throws IndexOutOfBoundsException if the index is out of range ({@code index < 0 || index >= + * size()}) + */ + byte[] getByteArray(int index); + + /** + * Appends the specified element to the end of this list (optional operation). + * + * @param element element to be appended to this list + * @throws UnsupportedOperationException if the add operation is not supported by this + * list + */ + void add(ByteString element); + + /** + * Appends the specified element to the end of this list (optional operation). + * + * @param element element to be appended to this list + * @throws UnsupportedOperationException if the add operation is not supported by this + * list + */ + void add(byte[] element); + + /** + * Replaces the element at the specified position in this list with the specified element + * (optional operation). + * + * @param index index of the element to replace + * @param element the element to be stored at the specified position + * @throws UnsupportedOperationException if the set operation is not supported by this + * list IndexOutOfBoundsException if the index is out of range ({@code index < 0 || index >= + * size()}) + */ + void set(int index, ByteString element); + + /** + * Replaces the element at the specified position in this list with the specified element + * (optional operation). + * + * @param index index of the element to replace + * @param element the element to be stored at the specified position + * @throws UnsupportedOperationException if the set operation is not supported by this + * list IndexOutOfBoundsException if the index is out of range ({@code index < 0 || index >= + * size()}) + */ + void set(int index, byte[] element); + + /** + * Appends all elements in the specified ByteString collection to the end of this list. + * + * @param c collection whose elements are to be added to this list + * @return true if this list changed as a result of the call + * @throws UnsupportedOperationException if the addAllByteString operation is not + * supported by this list + */ + boolean addAllByteString(Collection c); + + /** + * Appends all elements in the specified byte[] collection to the end of this list. + * + * @param c collection whose elements are to be added to this list + * @return true if this list changed as a result of the call + * @throws UnsupportedOperationException if the addAllByteArray operation is not + * supported by this list + */ + boolean addAllByteArray(Collection c); + + /** + * Returns an unmodifiable List of the underlying elements, each of which is either a {@code + * String} or its equivalent UTF-8 encoded {@code ByteString} or byte[]. It is an error for the + * caller to modify the returned List, and attempting to do so will result in an {@link + * UnsupportedOperationException}. + */ + List getUnderlyingElements(); + + /** + * Merges all elements from another LazyStringList into this one. This method differs from {@link + * #addAll(Collection)} on that underlying byte arrays are copied instead of reference shared. + * Immutable API doesn't need to use this method as byte[] is not used there at all. + */ + void mergeFrom(LazyStringList other); + + /** + * Returns a mutable view of this list. Changes to the view will be made into the original list. + * This method is used in mutable API only. + */ + List asByteArrayList(); + + /** Returns an unmodifiable view of the list. */ + LazyStringList getUnmodifiableView(); +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/ListFieldSchema.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/ListFieldSchema.java new file mode 100644 index 0000000000000..ebc8561a7261d --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/ListFieldSchema.java @@ -0,0 +1,190 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +import com.google.protobuf.Internal.ProtobufList; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * Utility class that aids in properly manipulating list fields for either the lite or full runtime. + */ +abstract class ListFieldSchema { + // Disallow construction. + private ListFieldSchema() {} + + private static final ListFieldSchema FULL_INSTANCE = new ListFieldSchemaFull(); + private static final ListFieldSchema LITE_INSTANCE = new ListFieldSchemaLite(); + + abstract List mutableListAt(Object msg, long offset); + + abstract void makeImmutableListAt(Object msg, long offset); + + abstract void mergeListsAt(Object msg, Object otherMsg, long offset); + + static ListFieldSchema full() { + return FULL_INSTANCE; + } + + static ListFieldSchema lite() { + return LITE_INSTANCE; + } + + /** Implementation for the full runtime. */ + private static final class ListFieldSchemaFull extends ListFieldSchema { + + private static final Class UNMODIFIABLE_LIST_CLASS = + Collections.unmodifiableList(Collections.emptyList()).getClass(); + + @Override + List mutableListAt(Object message, long offset) { + return mutableListAt(message, offset, AbstractProtobufList.DEFAULT_CAPACITY); + } + + @Override + void makeImmutableListAt(Object message, long offset) { + List list = (List) UnsafeUtil.getObject(message, offset); + Object immutable = null; + if (list instanceof LazyStringList) { + immutable = ((LazyStringList) list).getUnmodifiableView(); + } else if (UNMODIFIABLE_LIST_CLASS.isAssignableFrom(list.getClass())) { + // already immutable + return; + } else if (list instanceof PrimitiveNonBoxingCollection && list instanceof ProtobufList) { + if (((ProtobufList) list).isModifiable()) { + ((ProtobufList) list).makeImmutable(); + } + return; + } else { + immutable = Collections.unmodifiableList((List) list); + } + UnsafeUtil.putObject(message, offset, immutable); + } + + @SuppressWarnings("unchecked") + private static List mutableListAt(Object message, long offset, int additionalCapacity) { + List list = getList(message, offset); + if (list.isEmpty()) { + if (list instanceof LazyStringList) { + list = (List) new LazyStringArrayList(additionalCapacity); + } else if (list instanceof PrimitiveNonBoxingCollection && list instanceof ProtobufList) { + list = ((ProtobufList) list).mutableCopyWithCapacity(additionalCapacity); + } else { + list = new ArrayList(additionalCapacity); + } + UnsafeUtil.putObject(message, offset, list); + } else if (UNMODIFIABLE_LIST_CLASS.isAssignableFrom(list.getClass())) { + ArrayList newList = new ArrayList(list.size() + additionalCapacity); + newList.addAll(list); + list = newList; + UnsafeUtil.putObject(message, offset, list); + } else if (list instanceof UnmodifiableLazyStringList) { + LazyStringArrayList newList = new LazyStringArrayList(list.size() + additionalCapacity); + newList.addAll((UnmodifiableLazyStringList) list); + list = (List) newList; + UnsafeUtil.putObject(message, offset, list); + } else if (list instanceof PrimitiveNonBoxingCollection + && list instanceof ProtobufList + && !((ProtobufList) list).isModifiable()) { + list = ((ProtobufList) list).mutableCopyWithCapacity(list.size() + additionalCapacity); + UnsafeUtil.putObject(message, offset, list); + } + return list; + } + + @Override + void mergeListsAt(Object msg, Object otherMsg, long offset) { + List other = getList(otherMsg, offset); + List mine = mutableListAt(msg, offset, other.size()); + + int size = mine.size(); + int otherSize = other.size(); + if (size > 0 && otherSize > 0) { + mine.addAll(other); + } + + List merged = size > 0 ? mine : other; + UnsafeUtil.putObject(msg, offset, merged); + } + + @SuppressWarnings("unchecked") + static List getList(Object message, long offset) { + return (List) UnsafeUtil.getObject(message, offset); + } + } + + /** Implementation for the lite runtime. */ + private static final class ListFieldSchemaLite extends ListFieldSchema { + + @Override + List mutableListAt(Object message, long offset) { + ProtobufList list = getProtobufList(message, offset); + if (!list.isModifiable()) { + int size = list.size(); + list = + list.mutableCopyWithCapacity( + size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY : size * 2); + UnsafeUtil.putObject(message, offset, list); + } + return list; + } + + @Override + void makeImmutableListAt(Object message, long offset) { + ProtobufList list = getProtobufList(message, offset); + list.makeImmutable(); + } + + @Override + void mergeListsAt(Object msg, Object otherMsg, long offset) { + ProtobufList mine = getProtobufList(msg, offset); + ProtobufList other = getProtobufList(otherMsg, offset); + + int size = mine.size(); + int otherSize = other.size(); + if (size > 0 && otherSize > 0) { + if (!mine.isModifiable()) { + mine = mine.mutableCopyWithCapacity(size + otherSize); + } + mine.addAll(other); + } + + ProtobufList merged = size > 0 ? mine : other; + UnsafeUtil.putObject(msg, offset, merged); + } + + @SuppressWarnings("unchecked") + static ProtobufList getProtobufList(Object message, long offset) { + return (ProtobufList) UnsafeUtil.getObject(message, offset); + } + } +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/ListValue.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/ListValue.java new file mode 100644 index 0000000000000..96cc770a534ac --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/ListValue.java @@ -0,0 +1,484 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/struct.proto + +package com.google.protobuf; + +/** + *
+ * `ListValue` is a wrapper around a repeated field of values.
+ * The JSON representation for `ListValue` is JSON array.
+ * 
+ * + * Protobuf type {@code google.protobuf.ListValue} + */ +public final class ListValue extends + com.google.protobuf.GeneratedMessageLite< + ListValue, ListValue.Builder> implements + // @@protoc_insertion_point(message_implements:google.protobuf.ListValue) + ListValueOrBuilder { + private ListValue() { + values_ = emptyProtobufList(); + } + public static final int VALUES_FIELD_NUMBER = 1; + private com.google.protobuf.Internal.ProtobufList values_; + /** + *
+   * Repeated field of dynamically typed values.
+   * 
+ * + * repeated .google.protobuf.Value values = 1; + */ + @java.lang.Override + public java.util.List getValuesList() { + return values_; + } + /** + *
+   * Repeated field of dynamically typed values.
+   * 
+ * + * repeated .google.protobuf.Value values = 1; + */ + public java.util.List + getValuesOrBuilderList() { + return values_; + } + /** + *
+   * Repeated field of dynamically typed values.
+   * 
+ * + * repeated .google.protobuf.Value values = 1; + */ + @java.lang.Override + public int getValuesCount() { + return values_.size(); + } + /** + *
+   * Repeated field of dynamically typed values.
+   * 
+ * + * repeated .google.protobuf.Value values = 1; + */ + @java.lang.Override + public com.google.protobuf.Value getValues(int index) { + return values_.get(index); + } + /** + *
+   * Repeated field of dynamically typed values.
+   * 
+ * + * repeated .google.protobuf.Value values = 1; + */ + public com.google.protobuf.ValueOrBuilder getValuesOrBuilder( + int index) { + return values_.get(index); + } + private void ensureValuesIsMutable() { + com.google.protobuf.Internal.ProtobufList tmp = values_; + if (!tmp.isModifiable()) { + values_ = + com.google.protobuf.GeneratedMessageLite.mutableCopy(tmp); + } + } + + /** + *
+   * Repeated field of dynamically typed values.
+   * 
+ * + * repeated .google.protobuf.Value values = 1; + */ + private void setValues( + int index, com.google.protobuf.Value value) { + value.getClass(); + ensureValuesIsMutable(); + values_.set(index, value); + } + /** + *
+   * Repeated field of dynamically typed values.
+   * 
+ * + * repeated .google.protobuf.Value values = 1; + */ + private void addValues(com.google.protobuf.Value value) { + value.getClass(); + ensureValuesIsMutable(); + values_.add(value); + } + /** + *
+   * Repeated field of dynamically typed values.
+   * 
+ * + * repeated .google.protobuf.Value values = 1; + */ + private void addValues( + int index, com.google.protobuf.Value value) { + value.getClass(); + ensureValuesIsMutable(); + values_.add(index, value); + } + /** + *
+   * Repeated field of dynamically typed values.
+   * 
+ * + * repeated .google.protobuf.Value values = 1; + */ + private void addAllValues( + java.lang.Iterable values) { + ensureValuesIsMutable(); + com.google.protobuf.AbstractMessageLite.addAll( + values, values_); + } + /** + *
+   * Repeated field of dynamically typed values.
+   * 
+ * + * repeated .google.protobuf.Value values = 1; + */ + private void clearValues() { + values_ = emptyProtobufList(); + } + /** + *
+   * Repeated field of dynamically typed values.
+   * 
+ * + * repeated .google.protobuf.Value values = 1; + */ + private void removeValues(int index) { + ensureValuesIsMutable(); + values_.remove(index); + } + + public static com.google.protobuf.ListValue parseFrom( + java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.ListValue parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.ListValue parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.ListValue parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.ListValue parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.ListValue parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.ListValue parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, 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.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, input, extensionRegistry); + } + public static com.google.protobuf.ListValue parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return parseDelimitedFrom(DEFAULT_INSTANCE, input); + } + public static com.google.protobuf.ListValue parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return parseDelimitedFrom(DEFAULT_INSTANCE, input, extensionRegistry); + } + public static com.google.protobuf.ListValue parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, 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.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, input, extensionRegistry); + } + + public static Builder newBuilder() { + return (Builder) DEFAULT_INSTANCE.createBuilder(); + } + public static Builder newBuilder(com.google.protobuf.ListValue prototype) { + return (Builder) DEFAULT_INSTANCE.createBuilder(prototype); + } + + /** + *
+   * `ListValue` is a wrapper around a repeated field of values.
+   * The JSON representation for `ListValue` is JSON array.
+   * 
+ * + * Protobuf type {@code google.protobuf.ListValue} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessageLite.Builder< + com.google.protobuf.ListValue, Builder> implements + // @@protoc_insertion_point(builder_implements:google.protobuf.ListValue) + com.google.protobuf.ListValueOrBuilder { + // Construct using com.google.protobuf.ListValue.newBuilder() + private Builder() { + super(DEFAULT_INSTANCE); + } + + + /** + *
+     * Repeated field of dynamically typed values.
+     * 
+ * + * repeated .google.protobuf.Value values = 1; + */ + @java.lang.Override + public java.util.List getValuesList() { + return java.util.Collections.unmodifiableList( + instance.getValuesList()); + } + /** + *
+     * Repeated field of dynamically typed values.
+     * 
+ * + * repeated .google.protobuf.Value values = 1; + */ + @java.lang.Override + public int getValuesCount() { + return instance.getValuesCount(); + }/** + *
+     * Repeated field of dynamically typed values.
+     * 
+ * + * repeated .google.protobuf.Value values = 1; + */ + @java.lang.Override + public com.google.protobuf.Value getValues(int index) { + return instance.getValues(index); + } + /** + *
+     * Repeated field of dynamically typed values.
+     * 
+ * + * repeated .google.protobuf.Value values = 1; + */ + public Builder setValues( + int index, com.google.protobuf.Value value) { + copyOnWrite(); + instance.setValues(index, value); + return this; + } + /** + *
+     * Repeated field of dynamically typed values.
+     * 
+ * + * repeated .google.protobuf.Value values = 1; + */ + public Builder setValues( + int index, com.google.protobuf.Value.Builder builderForValue) { + copyOnWrite(); + instance.setValues(index, + builderForValue.build()); + return this; + } + /** + *
+     * Repeated field of dynamically typed values.
+     * 
+ * + * repeated .google.protobuf.Value values = 1; + */ + public Builder addValues(com.google.protobuf.Value value) { + copyOnWrite(); + instance.addValues(value); + return this; + } + /** + *
+     * Repeated field of dynamically typed values.
+     * 
+ * + * repeated .google.protobuf.Value values = 1; + */ + public Builder addValues( + int index, com.google.protobuf.Value value) { + copyOnWrite(); + instance.addValues(index, value); + return this; + } + /** + *
+     * Repeated field of dynamically typed values.
+     * 
+ * + * repeated .google.protobuf.Value values = 1; + */ + public Builder addValues( + com.google.protobuf.Value.Builder builderForValue) { + copyOnWrite(); + instance.addValues(builderForValue.build()); + return this; + } + /** + *
+     * Repeated field of dynamically typed values.
+     * 
+ * + * repeated .google.protobuf.Value values = 1; + */ + public Builder addValues( + int index, com.google.protobuf.Value.Builder builderForValue) { + copyOnWrite(); + instance.addValues(index, + builderForValue.build()); + return this; + } + /** + *
+     * Repeated field of dynamically typed values.
+     * 
+ * + * repeated .google.protobuf.Value values = 1; + */ + public Builder addAllValues( + java.lang.Iterable values) { + copyOnWrite(); + instance.addAllValues(values); + return this; + } + /** + *
+     * Repeated field of dynamically typed values.
+     * 
+ * + * repeated .google.protobuf.Value values = 1; + */ + public Builder clearValues() { + copyOnWrite(); + instance.clearValues(); + return this; + } + /** + *
+     * Repeated field of dynamically typed values.
+     * 
+ * + * repeated .google.protobuf.Value values = 1; + */ + public Builder removeValues(int index) { + copyOnWrite(); + instance.removeValues(index); + return this; + } + + // @@protoc_insertion_point(builder_scope:google.protobuf.ListValue) + } + @java.lang.Override + @java.lang.SuppressWarnings({"unchecked", "fallthrough"}) + protected final java.lang.Object dynamicMethod( + com.google.protobuf.GeneratedMessageLite.MethodToInvoke method, + java.lang.Object arg0, java.lang.Object arg1) { + switch (method) { + case NEW_MUTABLE_INSTANCE: { + return new com.google.protobuf.ListValue(); + } + case NEW_BUILDER: { + return new Builder(); + } + case BUILD_MESSAGE_INFO: { + java.lang.Object[] objects = new java.lang.Object[] { + "values_", + com.google.protobuf.Value.class, + }; + java.lang.String info = + "\u0000\u0001\u0000\u0000\u0001\u0001\u0001\u0000\u0001\u0000\u0001\u001b"; + return newMessageInfo(DEFAULT_INSTANCE, info, objects); + } + // fall through + case GET_DEFAULT_INSTANCE: { + return DEFAULT_INSTANCE; + } + case GET_PARSER: { + com.google.protobuf.Parser parser = PARSER; + if (parser == null) { + synchronized (com.google.protobuf.ListValue.class) { + parser = PARSER; + if (parser == null) { + parser = + new DefaultInstanceBasedParser( + DEFAULT_INSTANCE); + PARSER = parser; + } + } + } + return parser; + } + case GET_MEMOIZED_IS_INITIALIZED: { + return (byte) 1; + } + case SET_MEMOIZED_IS_INITIALIZED: { + return null; + } + } + throw new UnsupportedOperationException(); + } + + + // @@protoc_insertion_point(class_scope:google.protobuf.ListValue) + private static final com.google.protobuf.ListValue DEFAULT_INSTANCE; + static { + ListValue defaultInstance = new ListValue(); + // New instances are implicitly immutable so no need to make + // immutable. + DEFAULT_INSTANCE = defaultInstance; + com.google.protobuf.GeneratedMessageLite.registerDefaultInstance( + ListValue.class, defaultInstance); + } + + public static com.google.protobuf.ListValue getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static volatile com.google.protobuf.Parser PARSER; + + public static com.google.protobuf.Parser parser() { + return DEFAULT_INSTANCE.getParserForType(); + } +} + diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/ListValueOrBuilder.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/ListValueOrBuilder.java new file mode 100644 index 0000000000000..273ad2a35efba --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/ListValueOrBuilder.java @@ -0,0 +1,35 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/struct.proto + +package com.google.protobuf; + +public interface ListValueOrBuilder extends + // @@protoc_insertion_point(interface_extends:google.protobuf.ListValue) + com.google.protobuf.MessageLiteOrBuilder { + + /** + *
+   * Repeated field of dynamically typed values.
+   * 
+ * + * repeated .google.protobuf.Value values = 1; + */ + java.util.List + getValuesList(); + /** + *
+   * Repeated field of dynamically typed values.
+   * 
+ * + * repeated .google.protobuf.Value values = 1; + */ + com.google.protobuf.Value getValues(int index); + /** + *
+   * Repeated field of dynamically typed values.
+   * 
+ * + * repeated .google.protobuf.Value values = 1; + */ + int getValuesCount(); +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/LongArrayList.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/LongArrayList.java new file mode 100644 index 0000000000000..bda43a41bb4a1 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/LongArrayList.java @@ -0,0 +1,297 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +import static com.google.protobuf.Internal.checkNotNull; + +import com.google.protobuf.Internal.LongList; +import java.util.Arrays; +import java.util.Collection; +import java.util.RandomAccess; + +/** + * An implementation of {@link LongList} on top of a primitive array. + * + * @author dweis@google.com (Daniel Weis) + */ +final class LongArrayList extends AbstractProtobufList + implements LongList, RandomAccess, PrimitiveNonBoxingCollection { + + private static final LongArrayList EMPTY_LIST = new LongArrayList(new long[0], 0); + static { + EMPTY_LIST.makeImmutable(); + } + + public static LongArrayList emptyList() { + return EMPTY_LIST; + } + + /** The backing store for the list. */ + private long[] array; + + /** + * The size of the list distinct from the length of the array. That is, it is the number of + * elements set in the list. + */ + private int size; + + /** Constructs a new mutable {@code LongArrayList} with default capacity. */ + LongArrayList() { + this(new long[DEFAULT_CAPACITY], 0); + } + + /** + * Constructs a new mutable {@code LongArrayList} containing the same elements as {@code other}. + */ + private LongArrayList(long[] other, int size) { + array = other; + this.size = size; + } + + @Override + protected void removeRange(int fromIndex, int toIndex) { + ensureIsMutable(); + if (toIndex < fromIndex) { + throw new IndexOutOfBoundsException("toIndex < fromIndex"); + } + + System.arraycopy(array, toIndex, array, fromIndex, size - toIndex); + size -= (toIndex - fromIndex); + modCount++; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof LongArrayList)) { + return super.equals(o); + } + LongArrayList other = (LongArrayList) o; + if (size != other.size) { + return false; + } + + final long[] arr = other.array; + for (int i = 0; i < size; i++) { + if (array[i] != arr[i]) { + return false; + } + } + + return true; + } + + @Override + public int hashCode() { + int result = 1; + for (int i = 0; i < size; i++) { + result = (31 * result) + Internal.hashLong(array[i]); + } + return result; + } + + @Override + public LongList mutableCopyWithCapacity(int capacity) { + if (capacity < size) { + throw new IllegalArgumentException(); + } + return new LongArrayList(Arrays.copyOf(array, capacity), size); + } + + @Override + public Long get(int index) { + return getLong(index); + } + + @Override + public long getLong(int index) { + ensureIndexInRange(index); + return array[index]; + } + + @Override + public int indexOf(Object element) { + if (!(element instanceof Long)) { + return -1; + } + long unboxedElement = (Long) element; + int numElems = size(); + for (int i = 0; i < numElems; i++) { + if (array[i] == unboxedElement) { + return i; + } + } + return -1; + } + + @Override + public boolean contains(Object element) { + return indexOf(element) != -1; + } + + @Override + public int size() { + return size; + } + + @Override + public Long set(int index, Long element) { + return setLong(index, element); + } + + @Override + public long setLong(int index, long element) { + ensureIsMutable(); + ensureIndexInRange(index); + long previousValue = array[index]; + array[index] = element; + return previousValue; + } + + @Override + public boolean add(Long element) { + addLong(element); + return true; + } + + @Override + public void add(int index, Long element) { + addLong(index, element); + } + + /** Like {@link #add(Long)} but more efficient in that it doesn't box the element. */ + @Override + public void addLong(long element) { + ensureIsMutable(); + if (size == array.length) { + // Resize to 1.5x the size + int length = ((size * 3) / 2) + 1; + long[] newArray = new long[length]; + + System.arraycopy(array, 0, newArray, 0, size); + array = newArray; + } + + array[size++] = element; + } + + /** Like {@link #add(int, Long)} but more efficient in that it doesn't box the element. */ + private void addLong(int index, long element) { + ensureIsMutable(); + if (index < 0 || index > size) { + throw new IndexOutOfBoundsException(makeOutOfBoundsExceptionMessage(index)); + } + + if (size < array.length) { + // Shift everything over to make room + System.arraycopy(array, index, array, index + 1, size - index); + } else { + // Resize to 1.5x the size + int length = ((size * 3) / 2) + 1; + long[] newArray = new long[length]; + + // Copy the first part directly + System.arraycopy(array, 0, newArray, 0, index); + + // Copy the rest shifted over by one to make room + System.arraycopy(array, index, newArray, index + 1, size - index); + array = newArray; + } + + array[index] = element; + size++; + modCount++; + } + + @Override + public boolean addAll(Collection collection) { + ensureIsMutable(); + + checkNotNull(collection); + + // We specialize when adding another LongArrayList to avoid boxing elements. + if (!(collection instanceof LongArrayList)) { + return super.addAll(collection); + } + + LongArrayList list = (LongArrayList) collection; + if (list.size == 0) { + return false; + } + + int overflow = Integer.MAX_VALUE - size; + if (overflow < list.size) { + // We can't actually represent a list this large. + throw new OutOfMemoryError(); + } + + int newSize = size + list.size; + if (newSize > array.length) { + array = Arrays.copyOf(array, newSize); + } + + System.arraycopy(list.array, 0, array, size, list.size); + size = newSize; + modCount++; + return true; + } + + @Override + public Long remove(int index) { + ensureIsMutable(); + ensureIndexInRange(index); + long value = array[index]; + if (index < size - 1) { + System.arraycopy(array, index + 1, array, index, size - index - 1); + } + size--; + modCount++; + return value; + } + + /** + * Ensures that the provided {@code index} is within the range of {@code [0, size]}. Throws an + * {@link IndexOutOfBoundsException} if it is not. + * + * @param index the index to verify is in range + */ + private void ensureIndexInRange(int index) { + if (index < 0 || index >= size) { + throw new IndexOutOfBoundsException(makeOutOfBoundsExceptionMessage(index)); + } + } + + private String makeOutOfBoundsExceptionMessage(int index) { + return "Index:" + index + ", Size:" + size; + } +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/ManifestSchemaFactory.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/ManifestSchemaFactory.java new file mode 100644 index 0000000000000..84ca9ae0f7576 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/ManifestSchemaFactory.java @@ -0,0 +1,172 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +import static com.google.protobuf.Internal.checkNotNull; + +/** + * Dynamically generates a manifest-based (i.e. table-based) schema for a given protobuf message. + */ +@ExperimentalApi +final class ManifestSchemaFactory implements SchemaFactory { + + private final MessageInfoFactory messageInfoFactory; + + public ManifestSchemaFactory() { + this(getDefaultMessageInfoFactory()); + } + + private ManifestSchemaFactory(MessageInfoFactory messageInfoFactory) { + this.messageInfoFactory = checkNotNull(messageInfoFactory, "messageInfoFactory"); + } + + @Override + public Schema createSchema(Class messageType) { + SchemaUtil.requireGeneratedMessage(messageType); + + MessageInfo messageInfo = messageInfoFactory.messageInfoFor(messageType); + + // MessageSet has a special schema. + if (messageInfo.isMessageSetWireFormat()) { + if (GeneratedMessageLite.class.isAssignableFrom(messageType)) { + return MessageSetSchema.newSchema( + SchemaUtil.unknownFieldSetLiteSchema(), + ExtensionSchemas.lite(), + messageInfo.getDefaultInstance()); + } + return MessageSetSchema.newSchema( + SchemaUtil.proto2UnknownFieldSetSchema(), + ExtensionSchemas.full(), + messageInfo.getDefaultInstance()); + } + + return newSchema(messageType, messageInfo); + } + + private static Schema newSchema(Class messageType, MessageInfo messageInfo) { + if (GeneratedMessageLite.class.isAssignableFrom(messageType)) { + return isProto2(messageInfo) + ? MessageSchema.newSchema( + messageType, + messageInfo, + NewInstanceSchemas.lite(), + ListFieldSchema.lite(), + SchemaUtil.unknownFieldSetLiteSchema(), + ExtensionSchemas.lite(), + MapFieldSchemas.lite()) + : MessageSchema.newSchema( + messageType, + messageInfo, + NewInstanceSchemas.lite(), + ListFieldSchema.lite(), + SchemaUtil.unknownFieldSetLiteSchema(), + /* extensionSchema= */ null, + MapFieldSchemas.lite()); + } + return isProto2(messageInfo) + ? MessageSchema.newSchema( + messageType, + messageInfo, + NewInstanceSchemas.full(), + ListFieldSchema.full(), + SchemaUtil.proto2UnknownFieldSetSchema(), + ExtensionSchemas.full(), + MapFieldSchemas.full()) + : MessageSchema.newSchema( + messageType, + messageInfo, + NewInstanceSchemas.full(), + ListFieldSchema.full(), + SchemaUtil.proto3UnknownFieldSetSchema(), + /* extensionSchema= */ null, + MapFieldSchemas.full()); + } + + private static boolean isProto2(MessageInfo messageInfo) { + return messageInfo.getSyntax() == ProtoSyntax.PROTO2; + } + + private static MessageInfoFactory getDefaultMessageInfoFactory() { + return new CompositeMessageInfoFactory( + GeneratedMessageInfoFactory.getInstance(), getDescriptorMessageInfoFactory()); + } + + private static class CompositeMessageInfoFactory implements MessageInfoFactory { + private MessageInfoFactory[] factories; + + CompositeMessageInfoFactory(MessageInfoFactory... factories) { + this.factories = factories; + } + + @Override + public boolean isSupported(Class clazz) { + for (MessageInfoFactory factory : factories) { + if (factory.isSupported(clazz)) { + return true; + } + } + return false; + } + + @Override + public MessageInfo messageInfoFor(Class clazz) { + for (MessageInfoFactory factory : factories) { + if (factory.isSupported(clazz)) { + return factory.messageInfoFor(clazz); + } + } + throw new UnsupportedOperationException( + "No factory is available for message type: " + clazz.getName()); + } + } + + private static final MessageInfoFactory EMPTY_FACTORY = + new MessageInfoFactory() { + @Override + public boolean isSupported(Class clazz) { + return false; + } + + @Override + public MessageInfo messageInfoFor(Class clazz) { + throw new IllegalStateException("This should never be called."); + } + }; + + private static MessageInfoFactory getDescriptorMessageInfoFactory() { + try { + Class clazz = Class.forName("com.google.protobuf.DescriptorMessageInfoFactory"); + return (MessageInfoFactory) clazz.getDeclaredMethod("getInstance").invoke(null); + } catch (Exception e) { + return EMPTY_FACTORY; + } + } +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/MapEntryLite.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/MapEntryLite.java new file mode 100644 index 0000000000000..81bf4c2b18406 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/MapEntryLite.java @@ -0,0 +1,231 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +import java.io.IOException; +import java.util.AbstractMap; +import java.util.Map; + +/** + * Implements the lite version of map entry messages. + * + *

This class serves as an utility class to help do serialization/parsing of map entries. It's + * used in generated code and also in the full version MapEntry message. + * + *

Protobuf internal. Users shouldn't use. + */ +public class MapEntryLite { + + static class Metadata { + public final WireFormat.FieldType keyType; + public final K defaultKey; + public final WireFormat.FieldType valueType; + public final V defaultValue; + + public Metadata( + WireFormat.FieldType keyType, + K defaultKey, + WireFormat.FieldType valueType, + V defaultValue) { + this.keyType = keyType; + this.defaultKey = defaultKey; + this.valueType = valueType; + this.defaultValue = defaultValue; + } + } + + private static final int KEY_FIELD_NUMBER = 1; + private static final int VALUE_FIELD_NUMBER = 2; + + private final Metadata metadata; + private final K key; + private final V value; + + /** Creates a default MapEntryLite message instance. */ + private MapEntryLite( + WireFormat.FieldType keyType, K defaultKey, WireFormat.FieldType valueType, V defaultValue) { + this.metadata = new Metadata(keyType, defaultKey, valueType, defaultValue); + this.key = defaultKey; + this.value = defaultValue; + } + + /** Creates a new MapEntryLite message. */ + private MapEntryLite(Metadata metadata, K key, V value) { + this.metadata = metadata; + this.key = key; + this.value = value; + } + + public K getKey() { + return key; + } + + public V getValue() { + return value; + } + + /** + * Creates a default MapEntryLite message instance. + * + *

This method is used by generated code to create the default instance for a map entry + * message. The created default instance should be used to create new map entry messages of the + * same type. For each map entry message, only one default instance should be created. + */ + public static MapEntryLite newDefaultInstance( + WireFormat.FieldType keyType, K defaultKey, WireFormat.FieldType valueType, V defaultValue) { + return new MapEntryLite(keyType, defaultKey, valueType, defaultValue); + } + + static void writeTo(CodedOutputStream output, Metadata metadata, K key, V value) + throws IOException { + FieldSet.writeElement(output, metadata.keyType, KEY_FIELD_NUMBER, key); + FieldSet.writeElement(output, metadata.valueType, VALUE_FIELD_NUMBER, value); + } + + static int computeSerializedSize(Metadata metadata, K key, V value) { + return FieldSet.computeElementSize(metadata.keyType, KEY_FIELD_NUMBER, key) + + FieldSet.computeElementSize(metadata.valueType, VALUE_FIELD_NUMBER, value); + } + + @SuppressWarnings("unchecked") + static T parseField( + CodedInputStream input, + ExtensionRegistryLite extensionRegistry, + WireFormat.FieldType type, + T value) + throws IOException { + switch (type) { + case MESSAGE: + MessageLite.Builder subBuilder = ((MessageLite) value).toBuilder(); + input.readMessage(subBuilder, extensionRegistry); + return (T) subBuilder.buildPartial(); + case ENUM: + return (T) (java.lang.Integer) input.readEnum(); + case GROUP: + throw new RuntimeException("Groups are not allowed in maps."); + default: + return (T) FieldSet.readPrimitiveField(input, type, true); + } + } + + /** + * Serializes the provided key and value as though they were wrapped by a {@link MapEntryLite} to + * the output stream. This helper method avoids allocation of a {@link MapEntryLite} built with a + * key and value and is called from generated code directly. + */ + public void serializeTo(CodedOutputStream output, int fieldNumber, K key, V value) + throws IOException { + output.writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + output.writeUInt32NoTag(computeSerializedSize(metadata, key, value)); + writeTo(output, metadata, key, value); + } + + /** + * Computes the message size for the provided key and value as though they were wrapped by a + * {@link MapEntryLite}. This helper method avoids allocation of a {@link MapEntryLite} built with + * a key and value and is called from generated code directly. + */ + public int computeMessageSize(int fieldNumber, K key, V value) { + return CodedOutputStream.computeTagSize(fieldNumber) + + CodedOutputStream.computeLengthDelimitedFieldSize( + computeSerializedSize(metadata, key, value)); + } + + /** + * Parses an entry off of the input as a {@link Map.Entry}. This helper requires an allocation so + * using {@link #parseInto} is preferred if possible. + */ + public Map.Entry parseEntry(ByteString bytes, ExtensionRegistryLite extensionRegistry) + throws IOException { + return parseEntry(bytes.newCodedInput(), metadata, extensionRegistry); + } + + static Map.Entry parseEntry( + CodedInputStream input, Metadata metadata, ExtensionRegistryLite extensionRegistry) + throws IOException { + K key = metadata.defaultKey; + V value = metadata.defaultValue; + while (true) { + int tag = input.readTag(); + if (tag == 0) { + break; + } + if (tag == WireFormat.makeTag(KEY_FIELD_NUMBER, metadata.keyType.getWireType())) { + key = parseField(input, extensionRegistry, metadata.keyType, key); + } else if (tag == WireFormat.makeTag(VALUE_FIELD_NUMBER, metadata.valueType.getWireType())) { + value = parseField(input, extensionRegistry, metadata.valueType, value); + } else { + if (!input.skipField(tag)) { + break; + } + } + } + return new AbstractMap.SimpleImmutableEntry(key, value); + } + + /** + * Parses an entry off of the input into the map. This helper avoids allocation of a {@link + * MapEntryLite} by parsing directly into the provided {@link MapFieldLite}. + */ + public void parseInto( + MapFieldLite map, CodedInputStream input, ExtensionRegistryLite extensionRegistry) + throws IOException { + int length = input.readRawVarint32(); + final int oldLimit = input.pushLimit(length); + K key = metadata.defaultKey; + V value = metadata.defaultValue; + + while (true) { + int tag = input.readTag(); + if (tag == 0) { + break; + } + if (tag == WireFormat.makeTag(KEY_FIELD_NUMBER, metadata.keyType.getWireType())) { + key = parseField(input, extensionRegistry, metadata.keyType, key); + } else if (tag == WireFormat.makeTag(VALUE_FIELD_NUMBER, metadata.valueType.getWireType())) { + value = parseField(input, extensionRegistry, metadata.valueType, value); + } else { + if (!input.skipField(tag)) { + break; + } + } + } + + input.checkLastTagWas(0); + input.popLimit(oldLimit); + map.put(key, value); + } + + /** For experimental runtime internal use only. */ + Metadata getMetadata() { + return metadata; + } +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/MapFieldLite.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/MapFieldLite.java new file mode 100644 index 0000000000000..a9fec4d7d72aa --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/MapFieldLite.java @@ -0,0 +1,235 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +import static com.google.protobuf.Internal.checkNotNull; + +import com.google.protobuf.Internal.EnumLite; +import java.util.Arrays; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Set; + +/** + * Internal representation of map fields in generated lite-runtime messages. + * + *

This class is a protobuf implementation detail. Users shouldn't use this class directly. + */ +public final class MapFieldLite extends LinkedHashMap { + + private boolean isMutable; + + private MapFieldLite() { + this.isMutable = true; + } + + private MapFieldLite(Map mapData) { + super(mapData); + this.isMutable = true; + } + + @SuppressWarnings({"rawtypes", "unchecked"}) + private static final MapFieldLite EMPTY_MAP_FIELD = new MapFieldLite<>(); + + static { + EMPTY_MAP_FIELD.makeImmutable(); + } + + /** Returns an singleton immutable empty MapFieldLite instance. */ + @SuppressWarnings({"unchecked", "cast"}) + public static MapFieldLite emptyMapField() { + return (MapFieldLite) EMPTY_MAP_FIELD; + } + + public void mergeFrom(MapFieldLite other) { + ensureMutable(); + if (!other.isEmpty()) { + putAll(other); + } + } + + @SuppressWarnings({"unchecked", "cast"}) + @Override + public Set> entrySet() { + return isEmpty() ? Collections.>emptySet() : super.entrySet(); + } + + @Override + public void clear() { + ensureMutable(); + super.clear(); + } + + @Override + public V put(K key, V value) { + ensureMutable(); + checkNotNull(key); + + checkNotNull(value); + return super.put(key, value); + } + + public V put(Map.Entry entry) { + return put(entry.getKey(), entry.getValue()); + } + + @Override + public void putAll(Map m) { + ensureMutable(); + checkForNullKeysAndValues(m); + super.putAll(m); + } + + @Override + public V remove(Object key) { + ensureMutable(); + return super.remove(key); + } + + private static void checkForNullKeysAndValues(Map m) { + for (Object key : m.keySet()) { + checkNotNull(key); + checkNotNull(m.get(key)); + } + } + + private static boolean equals(Object a, Object b) { + if (a instanceof byte[] && b instanceof byte[]) { + return Arrays.equals((byte[]) a, (byte[]) b); + } + return a.equals(b); + } + + /** + * Checks whether two {@link Map}s are equal. We don't use the default equals method of {@link + * Map} because it compares by identity not by content for byte arrays. + */ + static boolean equals(Map a, Map b) { + if (a == b) { + return true; + } + if (a.size() != b.size()) { + return false; + } + for (Map.Entry entry : a.entrySet()) { + if (!b.containsKey(entry.getKey())) { + return false; + } + if (!equals(entry.getValue(), b.get(entry.getKey()))) { + return false; + } + } + return true; + } + + /** Checks whether two map fields are equal. */ + @SuppressWarnings("unchecked") + @Override + public boolean equals(Object object) { + return (object instanceof Map) && equals(this, (Map) object); + } + + private static int calculateHashCodeForObject(Object a) { + if (a instanceof byte[]) { + return Internal.hashCode((byte[]) a); + } + // Enums should be stored as integers internally. + if (a instanceof EnumLite) { + throw new UnsupportedOperationException(); + } + return a.hashCode(); + } + + /** + * Calculates the hash code for a {@link Map}. We don't use the default hash code method of {@link + * Map} because for byte arrays and protobuf enums it use {@link Object#hashCode()}. + */ + static int calculateHashCodeForMap(Map a) { + int result = 0; + for (Map.Entry entry : a.entrySet()) { + result += + calculateHashCodeForObject(entry.getKey()) ^ calculateHashCodeForObject(entry.getValue()); + } + return result; + } + + @Override + public int hashCode() { + return calculateHashCodeForMap(this); + } + + private static Object copy(Object object) { + if (object instanceof byte[]) { + byte[] data = (byte[]) object; + return Arrays.copyOf(data, data.length); + } + return object; + } + + /** + * Makes a deep copy of a {@link Map}. Immutable objects in the map will be shared (e.g., + * integers, strings, immutable messages) and mutable ones will have a copy (e.g., byte arrays, + * mutable messages). + */ + @SuppressWarnings("unchecked") + static Map copy(Map map) { + Map result = new LinkedHashMap(); + for (Map.Entry entry : map.entrySet()) { + result.put(entry.getKey(), (V) copy(entry.getValue())); + } + return result; + } + + /** Returns a deep copy of this map field. */ + public MapFieldLite mutableCopy() { + return isEmpty() ? new MapFieldLite() : new MapFieldLite(this); + } + + /** + * Makes this field immutable. All subsequent modifications will throw an {@link + * UnsupportedOperationException}. + */ + public void makeImmutable() { + isMutable = false; + } + + /** Returns whether this field can be modified. */ + public boolean isMutable() { + return isMutable; + } + + private void ensureMutable() { + if (!isMutable()) { + throw new UnsupportedOperationException(); + } + } +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/MapFieldSchema.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/MapFieldSchema.java new file mode 100644 index 0000000000000..195126e51435f --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/MapFieldSchema.java @@ -0,0 +1,63 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +import java.util.Map; + +interface MapFieldSchema { + /** Returns the map data for mutation. */ + Map forMutableMapData(Object mapField); + + /** Returns the map data for read. */ + Map forMapData(Object mapField); + + /** Whether toImmutable() has been called on this map field. */ + boolean isImmutable(Object mapField); + + /** + * Returns an immutable instance of the map field. It may make the parameter immutable and return + * the parameter, or create an immutable copy. The status of the parameter after the call is + * undefined. + */ + Object toImmutable(Object mapField); + + /** Returns a new instance of the map field given a map default entry. */ + Object newMapField(Object mapDefaultEntry); + + /** Returns the metadata from a default entry. */ + MapEntryLite.Metadata forMapMetadata(Object mapDefaultEntry); + + /** Merges {@code srcMapField} into {@code destMapField}, and returns the merged instance. */ + Object mergeFrom(Object destMapField, Object srcMapField); + + /** Compute the serialized size for the map with a given field number. */ + int getSerializedSize(int fieldNumber, Object mapField, Object mapDefaultEntry); +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/MapFieldSchemaLite.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/MapFieldSchemaLite.java new file mode 100644 index 0000000000000..8a8c78de8aaa6 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/MapFieldSchemaLite.java @@ -0,0 +1,107 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +import com.google.protobuf.MapEntryLite.Metadata; +import java.util.Map; + +class MapFieldSchemaLite implements MapFieldSchema { + + @Override + public Map forMutableMapData(Object mapField) { + return (MapFieldLite) mapField; + } + + @Override + public Metadata forMapMetadata(Object mapDefaultEntry) { + return ((MapEntryLite) mapDefaultEntry).getMetadata(); + } + + @Override + public Map forMapData(Object mapField) { + return (MapFieldLite) mapField; + } + + @Override + public boolean isImmutable(Object mapField) { + return !((MapFieldLite) mapField).isMutable(); + } + + @Override + public Object toImmutable(Object mapField) { + ((MapFieldLite) mapField).makeImmutable(); + return mapField; + } + + @Override + public Object newMapField(Object unused) { + return MapFieldLite.emptyMapField().mutableCopy(); + } + + @Override + public Object mergeFrom(Object destMapField, Object srcMapField) { + return mergeFromLite(destMapField, srcMapField); + } + + @SuppressWarnings("unchecked") + private static MapFieldLite mergeFromLite(Object destMapField, Object srcMapField) { + MapFieldLite mine = (MapFieldLite) destMapField; + MapFieldLite other = (MapFieldLite) srcMapField; + if (!other.isEmpty()) { + if (!mine.isMutable()) { + mine = mine.mutableCopy(); + } + mine.mergeFrom(other); + } + return mine; + } + + @Override + public int getSerializedSize(int fieldNumber, Object mapField, Object mapDefaultEntry) { + return getSerializedSizeLite(fieldNumber, mapField, mapDefaultEntry); + } + + @SuppressWarnings("unchecked") + private static int getSerializedSizeLite( + int fieldNumber, Object mapField, Object defaultEntry) { + MapFieldLite mapFieldLite = (MapFieldLite) mapField; + MapEntryLite defaultEntryLite = (MapEntryLite) defaultEntry; + + if (mapFieldLite.isEmpty()) { + return 0; + } + int size = 0; + for (Map.Entry entry : mapFieldLite.entrySet()) { + size += defaultEntryLite.computeMessageSize(fieldNumber, entry.getKey(), entry.getValue()); + } + return size; + } +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/MapFieldSchemas.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/MapFieldSchemas.java new file mode 100644 index 0000000000000..b398c61022149 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/MapFieldSchemas.java @@ -0,0 +1,53 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +final class MapFieldSchemas { + private static final MapFieldSchema FULL_SCHEMA = loadSchemaForFullRuntime(); + private static final MapFieldSchema LITE_SCHEMA = new MapFieldSchemaLite(); + + static MapFieldSchema full() { + return FULL_SCHEMA; + } + + static MapFieldSchema lite() { + return LITE_SCHEMA; + } + + private static MapFieldSchema loadSchemaForFullRuntime() { + try { + Class clazz = Class.forName("com.google.protobuf.MapFieldSchemaFull"); + return (MapFieldSchema) clazz.getDeclaredConstructor().newInstance(); + } catch (Exception e) { + return null; + } + } +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/MessageInfo.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/MessageInfo.java new file mode 100644 index 0000000000000..69e318696aa33 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/MessageInfo.java @@ -0,0 +1,43 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +/** A MesageInfo object describes a proto message type. */ +interface MessageInfo { + /** Gets syntax for this type. */ + ProtoSyntax getSyntax(); + + /** Whether this type is MessageSet. */ + boolean isMessageSetWireFormat(); + + /** Gets the default instance of this type. */ + MessageLite getDefaultInstance(); +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/MessageInfoFactory.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/MessageInfoFactory.java new file mode 100644 index 0000000000000..005c26d05f7d4 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/MessageInfoFactory.java @@ -0,0 +1,41 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +/** A factory that creates {@link MessageInfo} instances for message types. */ +@ExperimentalApi +interface MessageInfoFactory { + /** Whether the message class is supported by this factory. */ + boolean isSupported(Class clazz); + + /** Returns a information of the message class. */ + MessageInfo messageInfoFor(Class clazz); +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/MessageLite.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/MessageLite.java new file mode 100644 index 0000000000000..7d2ef33a17f0e --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/MessageLite.java @@ -0,0 +1,298 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// TODO(kenton): Use generics? E.g. Builder, then +// mergeFrom*() could return BuilderType for better type-safety. + +package com.google.protobuf; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +/** + * Abstract interface implemented by Protocol Message objects. + * + *

This interface is implemented by all protocol message objects. Non-lite messages additionally + * implement the Message interface, which is a subclass of MessageLite. Use MessageLite instead when + * you only need the subset of features which it supports -- namely, nothing that uses descriptors + * or reflection. You can instruct the protocol compiler to generate classes which implement only + * MessageLite, not the full Message interface, by adding the follow line to the .proto file: + * + *

+ *   option optimize_for = LITE_RUNTIME;
+ * 
+ * + *

This is particularly useful on resource-constrained systems where the full protocol buffers + * runtime library is too big. + * + *

Note that on non-constrained systems (e.g. servers) when you need to link in lots of protocol + * definitions, a better way to reduce total code footprint is to use {@code optimize_for = + * CODE_SIZE}. This will make the generated code smaller while still supporting all the same + * features (at the expense of speed). {@code optimize_for = LITE_RUNTIME} is best when you only + * have a small number of message types linked into your binary, in which case the size of the + * protocol buffers runtime itself is the biggest problem. + * + * @author kenton@google.com Kenton Varda + */ +public interface MessageLite extends MessageLiteOrBuilder { + + /** + * Serializes the message and writes it to {@code output}. This does not flush or close the + * stream. + */ + void writeTo(CodedOutputStream output) throws IOException; + + /** + * Get the number of bytes required to encode this message. The result is only computed on the + * first call and memoized after that. + */ + int getSerializedSize(); + + /** Gets the parser for a message of the same type as this message. */ + Parser getParserForType(); + + // ----------------------------------------------------------------- + // Convenience methods. + + /** + * Serializes the message to a {@code ByteString} and returns it. This is just a trivial wrapper + * around {@link #writeTo(CodedOutputStream)}. + */ + ByteString toByteString(); + + /** + * Serializes the message to a {@code byte} array and returns it. This is just a trivial wrapper + * around {@link #writeTo(CodedOutputStream)}. + */ + byte[] toByteArray(); + + /** + * Serializes the message and writes it to {@code output}. This is just a trivial wrapper around + * {@link #writeTo(CodedOutputStream)}. This does not flush or close the stream. + * + *

NOTE: Protocol Buffers are not self-delimiting. Therefore, if you write any more data to the + * stream after the message, you must somehow ensure that the parser on the receiving end does not + * interpret this as being part of the protocol message. This can be done e.g. by writing the size + * of the message before the data, then making sure to limit the input to that size on the + * receiving end (e.g. by wrapping the InputStream in one which limits the input). Alternatively, + * just use {@link #writeDelimitedTo(OutputStream)}. + */ + void writeTo(OutputStream output) throws IOException; + + /** + * Like {@link #writeTo(OutputStream)}, but writes the size of the message as a varint before + * writing the data. This allows more data to be written to the stream after the message without + * the need to delimit the message data yourself. Use {@link + * Builder#mergeDelimitedFrom(InputStream)} (or the static method {@code + * YourMessageType.parseDelimitedFrom(InputStream)}) to parse messages written by this method. + */ + void writeDelimitedTo(OutputStream output) throws IOException; + + + // ================================================================= + // Builders + + /** Constructs a new builder for a message of the same type as this message. */ + Builder newBuilderForType(); + + /** + * Constructs a builder initialized with the current message. Use this to derive a new message + * from the current one. + */ + Builder toBuilder(); + + /** Abstract interface implemented by Protocol Message builders. */ + interface Builder extends MessageLiteOrBuilder, Cloneable { + /** Resets all fields to their default values. */ + Builder clear(); + + /** + * Constructs the message based on the state of the Builder. Subsequent changes to the Builder + * will not affect the returned message. + * + * @throws UninitializedMessageException The message is missing one or more required fields + * (i.e. {@link #isInitialized()} returns false). Use {@link #buildPartial()} to bypass this + * check. + */ + MessageLite build(); + + /** + * Like {@link #build()}, but does not throw an exception if the message is missing required + * fields. Instead, a partial message is returned. Subsequent changes to the Builder will not + * affect the returned message. + */ + MessageLite buildPartial(); + + /** + * Clones the Builder. + * + * @see Object#clone() + */ + Builder clone(); + + /** + * Parses a message of this type from the input and merges it with this message. + * + *

Warning: This does not verify that all required fields are present in the input message. + * If you call {@link #build()} without setting all required fields, it will throw an {@link + * UninitializedMessageException}, which is a {@code RuntimeException} and thus might not be + * caught. There are a few good ways to deal with this: + * + *

    + *
  • Call {@link #isInitialized()} to verify that all required fields are set before + * building. + *
  • Use {@code buildPartial()} to build, which ignores missing required fields. + *
+ * + *

Note: The caller should call {@link CodedInputStream#checkLastTagWas(int)} after calling + * this to verify that the last tag seen was the appropriate end-group tag, or zero for EOF. + */ + Builder mergeFrom(CodedInputStream input) throws IOException; + + /** + * Like {@link Builder#mergeFrom(CodedInputStream)}, but also parses extensions. The extensions + * that you want to be able to parse must be registered in {@code extensionRegistry}. Extensions + * not in the registry will be treated as unknown fields. + */ + Builder mergeFrom(CodedInputStream input, ExtensionRegistryLite extensionRegistry) + throws IOException; + + // --------------------------------------------------------------- + // Convenience methods. + + /** + * Parse {@code data} as a message of this type and merge it with the message being built. This + * is just a small wrapper around {@link #mergeFrom(CodedInputStream)}. + * + * @return this + */ + Builder mergeFrom(ByteString data) throws InvalidProtocolBufferException; + + /** + * Parse {@code data} as a message of this type and merge it with the message being built. This + * is just a small wrapper around {@link #mergeFrom(CodedInputStream,ExtensionRegistryLite)}. + * + * @return this + */ + Builder mergeFrom(ByteString data, ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException; + + /** + * Parse {@code data} as a message of this type and merge it with the message being built. This + * is just a small wrapper around {@link #mergeFrom(CodedInputStream)}. + * + * @return this + */ + Builder mergeFrom(byte[] data) throws InvalidProtocolBufferException; + + /** + * Parse {@code data} as a message of this type and merge it with the message being built. This + * is just a small wrapper around {@link #mergeFrom(CodedInputStream)}. + * + * @return this + */ + Builder mergeFrom(byte[] data, int off, int len) throws InvalidProtocolBufferException; + + /** + * Parse {@code data} as a message of this type and merge it with the message being built. This + * is just a small wrapper around {@link #mergeFrom(CodedInputStream,ExtensionRegistryLite)}. + * + * @return this + */ + Builder mergeFrom(byte[] data, ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException; + + /** + * Parse {@code data} as a message of this type and merge it with the message being built. This + * is just a small wrapper around {@link #mergeFrom(CodedInputStream,ExtensionRegistryLite)}. + * + * @return this + */ + Builder mergeFrom(byte[] data, int off, int len, ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException; + + /** + * Parse a message of this type from {@code input} and merge it with the message being built. + * This is just a small wrapper around {@link #mergeFrom(CodedInputStream)}. Note that this + * method always reads the entire input (unless it throws an exception). If you want it + * to stop earlier, you will need to wrap your input in some wrapper stream that limits reading. + * Or, use {@link MessageLite#writeDelimitedTo(OutputStream)} to write your message and {@link + * #mergeDelimitedFrom(InputStream)} to read it. + * + *

Despite usually reading the entire input, this does not close the stream. + * + * @return this + */ + Builder mergeFrom(InputStream input) throws IOException; + + /** + * Parse a message of this type from {@code input} and merge it with the message being built. + * This is just a small wrapper around {@link + * #mergeFrom(CodedInputStream,ExtensionRegistryLite)}. + * + * @return this + */ + Builder mergeFrom(InputStream input, ExtensionRegistryLite extensionRegistry) + throws IOException; + + /** + * Merge {@code other} into the message being built. {@code other} must have the exact same type + * as {@code this} (i.e. {@code getClass().equals(getDefaultInstanceForType().getClass())}). + * + *

Merging occurs as follows. For each field:
+ * * For singular primitive fields, if the field is set in {@code other}, then {@code other}'s + * value overwrites the value in this message.
+ * * For singular message fields, if the field is set in {@code other}, it is merged into the + * corresponding sub-message of this message using the same merging rules.
+ * * For repeated fields, the elements in {@code other} are concatenated with the elements in + * this message. * For oneof groups, if the other message has one of the fields set, the group + * of this message is cleared and replaced by the field of the other message, so that the oneof + * constraint is preserved. + * + *

This is equivalent to the {@code Message::MergeFrom} method in C++. + */ + Builder mergeFrom(MessageLite other); + + /** + * Like {@link #mergeFrom(InputStream)}, but does not read until EOF. Instead, the size of the + * message (encoded as a varint) is read first, then the message data. Use {@link + * MessageLite#writeDelimitedTo(OutputStream)} to write messages in this format. + * + * @return True if successful, or false if the stream is at EOF when the method starts. Any + * other error (including reaching EOF during parsing) will cause an exception to be thrown. + */ + boolean mergeDelimitedFrom(InputStream input) throws IOException; + + /** Like {@link #mergeDelimitedFrom(InputStream)} but supporting extensions. */ + boolean mergeDelimitedFrom(InputStream input, ExtensionRegistryLite extensionRegistry) + throws IOException; + } +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/MessageLiteOrBuilder.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/MessageLiteOrBuilder.java new file mode 100644 index 0000000000000..7a5ef3ed518d0 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/MessageLiteOrBuilder.java @@ -0,0 +1,57 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +/** + * Base interface for methods common to {@link MessageLite} and {@link MessageLite.Builder} to + * provide type equivalency. + * + * @author jonp@google.com (Jon Perlow) + */ +public interface MessageLiteOrBuilder { + /** + * Get an instance of the type with no fields set. Because no fields are set, all getters for + * singular fields will return default values and repeated fields will appear empty. This may or + * may not be a singleton. This differs from the {@code getDefaultInstance()} method of generated + * message classes in that this method is an abstract method of the {@code MessageLite} interface + * whereas {@code getDefaultInstance()} is a static method of a specific class. They return the + * same thing. + */ + MessageLite getDefaultInstanceForType(); + + /** + * Returns true if all required fields in the message and all embedded messages are set, false + * otherwise. + * + *

See also: {@link MessageOrBuilder#getInitializationErrorString()} + */ + boolean isInitialized(); +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/MessageLiteToString.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/MessageLiteToString.java new file mode 100644 index 0000000000000..4aea9528ac017 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/MessageLiteToString.java @@ -0,0 +1,281 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; + +/** Helps generate {@link String} representations of {@link MessageLite} protos. */ +final class MessageLiteToString { + + private static final String LIST_SUFFIX = "List"; + private static final String BUILDER_LIST_SUFFIX = "OrBuilderList"; + private static final String MAP_SUFFIX = "Map"; + private static final String BYTES_SUFFIX = "Bytes"; + + /** + * Returns a {@link String} representation of the {@link MessageLite} object. The first line of + * the {@code String} representation representation includes a comment string to uniquely identify + * the object instance. This acts as an indicator that this should not be relied on for + * comparisons. + * + *

For use by generated code only. + */ + static String toString(MessageLite messageLite, String commentString) { + StringBuilder buffer = new StringBuilder(); + buffer.append("# ").append(commentString); + reflectivePrintWithIndent(messageLite, buffer, 0); + return buffer.toString(); + } + + /** + * Reflectively prints the {@link MessageLite} to the buffer at given {@code indent} level. + * + * @param buffer the buffer to write to + * @param indent the number of spaces to indent the proto by + */ + private static void reflectivePrintWithIndent( + MessageLite messageLite, StringBuilder buffer, int indent) { + // Build a map of method name to method. We're looking for methods like getFoo(), hasFoo(), + // getFooList() and getFooMap() which might be useful for building an object's string + // representation. + Map nameToNoArgMethod = new HashMap(); + Map nameToMethod = new HashMap(); + Set getters = new TreeSet(); + for (Method method : messageLite.getClass().getDeclaredMethods()) { + nameToMethod.put(method.getName(), method); + if (method.getParameterTypes().length == 0) { + nameToNoArgMethod.put(method.getName(), method); + + if (method.getName().startsWith("get")) { + getters.add(method.getName()); + } + } + } + + for (String getter : getters) { + String suffix = getter.startsWith("get") ? getter.substring(3) : getter; + if (suffix.endsWith(LIST_SUFFIX) + && !suffix.endsWith(BUILDER_LIST_SUFFIX) + // Sometimes people have fields named 'list' that aren't repeated. + && !suffix.equals(LIST_SUFFIX)) { + String camelCase = + suffix.substring(0, 1).toLowerCase() + + suffix.substring(1, suffix.length() - LIST_SUFFIX.length()); + // Try to reflectively get the value and toString() the field as if it were repeated. This + // only works if the method names have not been proguarded out or renamed. + Method listMethod = nameToNoArgMethod.get(getter); + if (listMethod != null && listMethod.getReturnType().equals(List.class)) { + printField( + buffer, + indent, + camelCaseToSnakeCase(camelCase), + GeneratedMessageLite.invokeOrDie(listMethod, messageLite)); + continue; + } + } + if (suffix.endsWith(MAP_SUFFIX) + // Sometimes people have fields named 'map' that aren't maps. + && !suffix.equals(MAP_SUFFIX)) { + String camelCase = + suffix.substring(0, 1).toLowerCase() + + suffix.substring(1, suffix.length() - MAP_SUFFIX.length()); + // Try to reflectively get the value and toString() the field as if it were a map. This only + // works if the method names have not been proguarded out or renamed. + Method mapMethod = nameToNoArgMethod.get(getter); + if (mapMethod != null + && mapMethod.getReturnType().equals(Map.class) + // Skip the deprecated getter method with no prefix "Map" when the field name ends with + // "map". + && !mapMethod.isAnnotationPresent(Deprecated.class) + // Skip the internal mutable getter method. + && Modifier.isPublic(mapMethod.getModifiers())) { + printField( + buffer, + indent, + camelCaseToSnakeCase(camelCase), + GeneratedMessageLite.invokeOrDie(mapMethod, messageLite)); + continue; + } + } + + Method setter = nameToMethod.get("set" + suffix); + if (setter == null) { + continue; + } + if (suffix.endsWith(BYTES_SUFFIX) + && nameToNoArgMethod.containsKey( + "get" + suffix.substring(0, suffix.length() - "Bytes".length()))) { + // Heuristic to skip bytes based accessors for string fields. + continue; + } + + String camelCase = suffix.substring(0, 1).toLowerCase() + suffix.substring(1); + + // Try to reflectively get the value and toString() the field as if it were optional. This + // only works if the method names have not been proguarded out or renamed. + Method getMethod = nameToNoArgMethod.get("get" + suffix); + Method hasMethod = nameToNoArgMethod.get("has" + suffix); + // TODO(dweis): Fix proto3 semantics. + if (getMethod != null) { + Object value = GeneratedMessageLite.invokeOrDie(getMethod, messageLite); + final boolean hasValue = + hasMethod == null + ? !isDefaultValue(value) + : (Boolean) GeneratedMessageLite.invokeOrDie(hasMethod, messageLite); + // TODO(dweis): This doesn't stop printing oneof case twice: value and enum style. + if (hasValue) { + printField(buffer, indent, camelCaseToSnakeCase(camelCase), value); + } + continue; + } + } + + if (messageLite instanceof GeneratedMessageLite.ExtendableMessage) { + Iterator> iter = + ((GeneratedMessageLite.ExtendableMessage) messageLite).extensions.iterator(); + while (iter.hasNext()) { + Map.Entry entry = iter.next(); + printField(buffer, indent, "[" + entry.getKey().getNumber() + "]", entry.getValue()); + } + } + + if (((GeneratedMessageLite) messageLite).unknownFields != null) { + ((GeneratedMessageLite) messageLite).unknownFields.printWithIndent(buffer, indent); + } + } + + private static boolean isDefaultValue(Object o) { + if (o instanceof Boolean) { + return !((Boolean) o); + } + if (o instanceof Integer) { + return ((Integer) o) == 0; + } + if (o instanceof Float) { + return ((Float) o) == 0f; + } + if (o instanceof Double) { + return ((Double) o) == 0d; + } + if (o instanceof String) { + return o.equals(""); + } + if (o instanceof ByteString) { + return o.equals(ByteString.EMPTY); + } + if (o instanceof MessageLite) { // Can happen in oneofs. + return o == ((MessageLite) o).getDefaultInstanceForType(); + } + if (o instanceof java.lang.Enum) { // Catches oneof enums. + return ((java.lang.Enum) o).ordinal() == 0; + } + + return false; + } + + /** + * Formats a text proto field. + * + *

For use by generated code only. + * + * @param buffer the buffer to write to + * @param indent the number of spaces the proto should be indented by + * @param name the field name (in lower underscore case) + * @param object the object value of the field + */ + static final void printField(StringBuilder buffer, int indent, String name, Object object) { + if (object instanceof List) { + List list = (List) object; + for (Object entry : list) { + printField(buffer, indent, name, entry); + } + return; + } + if (object instanceof Map) { + Map map = (Map) object; + for (Map.Entry entry : map.entrySet()) { + printField(buffer, indent, name, entry); + } + return; + } + + buffer.append('\n'); + for (int i = 0; i < indent; i++) { + buffer.append(' '); + } + buffer.append(name); + + if (object instanceof String) { + buffer.append(": \"").append(TextFormatEscaper.escapeText((String) object)).append('"'); + } else if (object instanceof ByteString) { + buffer.append(": \"").append(TextFormatEscaper.escapeBytes((ByteString) object)).append('"'); + } else if (object instanceof GeneratedMessageLite) { + buffer.append(" {"); + reflectivePrintWithIndent((GeneratedMessageLite) object, buffer, indent + 2); + buffer.append("\n"); + for (int i = 0; i < indent; i++) { + buffer.append(' '); + } + buffer.append("}"); + } else if (object instanceof Map.Entry) { + buffer.append(" {"); + Map.Entry entry = (Map.Entry) object; + printField(buffer, indent + 2, "key", entry.getKey()); + printField(buffer, indent + 2, "value", entry.getValue()); + buffer.append("\n"); + for (int i = 0; i < indent; i++) { + buffer.append(' '); + } + buffer.append("}"); + } else { + buffer.append(": ").append(object.toString()); + } + } + + private static final String camelCaseToSnakeCase(String camelCase) { + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < camelCase.length(); i++) { + char ch = camelCase.charAt(i); + if (Character.isUpperCase(ch)) { + builder.append("_"); + } + builder.append(Character.toLowerCase(ch)); + } + return builder.toString(); + } +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/MessageSchema.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/MessageSchema.java new file mode 100644 index 0000000000000..33c8e914b24e1 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/MessageSchema.java @@ -0,0 +1,5930 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +import static com.google.protobuf.ArrayDecoders.decodeBoolList; +import static com.google.protobuf.ArrayDecoders.decodeBytes; +import static com.google.protobuf.ArrayDecoders.decodeBytesList; +import static com.google.protobuf.ArrayDecoders.decodeDouble; +import static com.google.protobuf.ArrayDecoders.decodeDoubleList; +import static com.google.protobuf.ArrayDecoders.decodeExtensionOrUnknownField; +import static com.google.protobuf.ArrayDecoders.decodeFixed32; +import static com.google.protobuf.ArrayDecoders.decodeFixed32List; +import static com.google.protobuf.ArrayDecoders.decodeFixed64; +import static com.google.protobuf.ArrayDecoders.decodeFixed64List; +import static com.google.protobuf.ArrayDecoders.decodeFloat; +import static com.google.protobuf.ArrayDecoders.decodeFloatList; +import static com.google.protobuf.ArrayDecoders.decodeGroupField; +import static com.google.protobuf.ArrayDecoders.decodeGroupList; +import static com.google.protobuf.ArrayDecoders.decodeMessageField; +import static com.google.protobuf.ArrayDecoders.decodeMessageList; +import static com.google.protobuf.ArrayDecoders.decodePackedBoolList; +import static com.google.protobuf.ArrayDecoders.decodePackedDoubleList; +import static com.google.protobuf.ArrayDecoders.decodePackedFixed32List; +import static com.google.protobuf.ArrayDecoders.decodePackedFixed64List; +import static com.google.protobuf.ArrayDecoders.decodePackedFloatList; +import static com.google.protobuf.ArrayDecoders.decodePackedSInt32List; +import static com.google.protobuf.ArrayDecoders.decodePackedSInt64List; +import static com.google.protobuf.ArrayDecoders.decodePackedVarint32List; +import static com.google.protobuf.ArrayDecoders.decodePackedVarint64List; +import static com.google.protobuf.ArrayDecoders.decodeSInt32List; +import static com.google.protobuf.ArrayDecoders.decodeSInt64List; +import static com.google.protobuf.ArrayDecoders.decodeString; +import static com.google.protobuf.ArrayDecoders.decodeStringList; +import static com.google.protobuf.ArrayDecoders.decodeStringListRequireUtf8; +import static com.google.protobuf.ArrayDecoders.decodeStringRequireUtf8; +import static com.google.protobuf.ArrayDecoders.decodeUnknownField; +import static com.google.protobuf.ArrayDecoders.decodeVarint32; +import static com.google.protobuf.ArrayDecoders.decodeVarint32List; +import static com.google.protobuf.ArrayDecoders.decodeVarint64; +import static com.google.protobuf.ArrayDecoders.decodeVarint64List; +import static com.google.protobuf.ArrayDecoders.skipField; + +import com.google.protobuf.ArrayDecoders.Registers; +import com.google.protobuf.ByteString.CodedBuilder; +import com.google.protobuf.FieldSet.FieldDescriptorLite; +import com.google.protobuf.Internal.EnumVerifier; +import com.google.protobuf.Internal.ProtobufList; +import com.google.protobuf.MapEntryLite.Metadata; +import java.io.IOException; +import java.lang.reflect.Field; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +/** Schema used for standard messages. */ +final class MessageSchema implements Schema { + private static final int INTS_PER_FIELD = 3; + private static final int OFFSET_BITS = 20; + private static final int OFFSET_MASK = 0XFFFFF; + private static final int FIELD_TYPE_MASK = 0x0FF00000; + private static final int REQUIRED_MASK = 0x10000000; + private static final int ENFORCE_UTF8_MASK = 0x20000000; + private static final int NO_PRESENCE_SENTINEL = -1 & OFFSET_MASK; + private static final int[] EMPTY_INT_ARRAY = new int[0]; + + /** An offset applied to the field type ID for scalar fields that are a member of a oneof. */ + static final int ONEOF_TYPE_OFFSET = 51 /* FieldType.MAP + 1 */; + + /** + * Keep a direct reference to the unsafe object so we don't need to go through the UnsafeUtil + * wrapper for every call. + */ + private static final sun.misc.Unsafe UNSAFE = UnsafeUtil.getUnsafe(); + + /** + * Holds all information for accessing the message fields. The layout is as follows (field + * positions are relative to the offset of the start of the field in the buffer): + * + *

+ * + *

+   * [ 0 -    3] unused
+   * [ 4 -   31] field number
+   * [32 -   33] unused
+   * [34 -   34] whether UTF-8 enforcement should be applied to a string field.
+   * [35 -   35] whether the field is required
+   * [36 -   43] field type / for oneof: field type + {@link #ONEOF_TYPE_OFFSET}
+   * [44 -   63] field offset / oneof value field offset
+   * [64 -   69] unused
+   * [70 -   75] field presence mask shift (unused for oneof/repeated fields)
+   * [76 -   95] presence field offset / oneof case field offset / cached size field offset
+   * 
+ * + * Note that presence field offset can only use 20 bits - 1. All bits set to 1 is the sentinel + * value for non-presence. This is not validated at runtime, we simply assume message layouts + * will not exceed 1MB (assuming ~10 bytes per field, that implies 100k fields which should hit + * other javac limits first). + */ + private final int[] buffer; + + /** + * Holds object references for fields. For each field entry in {@code buffer}, there are two + * corresponding entries in this array. The content is different from different field types: + * + *
+   *   Map fields:
+   *     objects[pos] = map default entry instance
+   *     objects[pos + 1] = EnumVerifier if map value is enum, or message class reference if map
+   *                        value is message.
+   *   Message fields:
+   *     objects[pos] = null or cached message schema
+   *     objects[pos + 1] = message class reference
+   *   Enum fields:
+   *     objects[pos] = null
+   *     objects[pos + 1] = EnumVerifier
+   * 
+ */ + private final Object[] objects; + + private final int minFieldNumber; + private final int maxFieldNumber; + + private final MessageLite defaultInstance; + private final boolean hasExtensions; + private final boolean lite; + private final boolean proto3; + // TODO(xiaofeng): Make both full-runtime and lite-runtime support cached field size. + private final boolean useCachedSizeField; + + /** Represents [checkInitialized positions, map field positions, repeated field offsets]. */ + private final int[] intArray; + + /** + * Values at indices 0 -> checkInitializedCount in intArray are positions to check for + * initialization. + */ + private final int checkInitializedCount; + + /** + * Values at indices checkInitializedCount -> repeatedFieldOffsetStart are map positions. + * Everything after that are repeated field offsets. + */ + private final int repeatedFieldOffsetStart; + + private final NewInstanceSchema newInstanceSchema; + private final ListFieldSchema listFieldSchema; + private final UnknownFieldSchema unknownFieldSchema; + private final ExtensionSchema extensionSchema; + private final MapFieldSchema mapFieldSchema; + + private MessageSchema( + int[] buffer, + Object[] objects, + int minFieldNumber, + int maxFieldNumber, + MessageLite defaultInstance, + boolean proto3, + boolean useCachedSizeField, + int[] intArray, + int checkInitialized, + int mapFieldPositions, + NewInstanceSchema newInstanceSchema, + ListFieldSchema listFieldSchema, + UnknownFieldSchema unknownFieldSchema, + ExtensionSchema extensionSchema, + MapFieldSchema mapFieldSchema) { + this.buffer = buffer; + this.objects = objects; + this.minFieldNumber = minFieldNumber; + this.maxFieldNumber = maxFieldNumber; + + this.lite = defaultInstance instanceof GeneratedMessageLite; + this.proto3 = proto3; + this.hasExtensions = extensionSchema != null && extensionSchema.hasExtensions(defaultInstance); + this.useCachedSizeField = useCachedSizeField; + + this.intArray = intArray; + this.checkInitializedCount = checkInitialized; + this.repeatedFieldOffsetStart = mapFieldPositions; + + this.newInstanceSchema = newInstanceSchema; + this.listFieldSchema = listFieldSchema; + this.unknownFieldSchema = unknownFieldSchema; + this.extensionSchema = extensionSchema; + this.defaultInstance = defaultInstance; + this.mapFieldSchema = mapFieldSchema; + } + + static MessageSchema newSchema( + Class messageClass, + MessageInfo messageInfo, + NewInstanceSchema newInstanceSchema, + ListFieldSchema listFieldSchema, + UnknownFieldSchema unknownFieldSchema, + ExtensionSchema extensionSchema, + MapFieldSchema mapFieldSchema) { + if (messageInfo instanceof RawMessageInfo) { + return newSchemaForRawMessageInfo( + (RawMessageInfo) messageInfo, + newInstanceSchema, + listFieldSchema, + unknownFieldSchema, + extensionSchema, + mapFieldSchema); + + } else { + return newSchemaForMessageInfo( + (StructuralMessageInfo) messageInfo, + newInstanceSchema, + listFieldSchema, + unknownFieldSchema, + extensionSchema, + mapFieldSchema); + } + } + + static MessageSchema newSchemaForRawMessageInfo( + RawMessageInfo messageInfo, + NewInstanceSchema newInstanceSchema, + ListFieldSchema listFieldSchema, + UnknownFieldSchema unknownFieldSchema, + ExtensionSchema extensionSchema, + MapFieldSchema mapFieldSchema) { + final boolean isProto3 = messageInfo.getSyntax() == ProtoSyntax.PROTO3; + + String info = messageInfo.getStringInfo(); + final int length = info.length(); + int i = 0; + + int next = info.charAt(i++); + if (next >= 0xD800) { + int result = next & 0x1FFF; + int shift = 13; + while ((next = info.charAt(i++)) >= 0xD800) { + result |= (next & 0x1FFF) << shift; + shift += 13; + } + next = result | (next << shift); + } + final int unusedFlags = next; + + next = info.charAt(i++); + if (next >= 0xD800) { + int result = next & 0x1FFF; + int shift = 13; + while ((next = info.charAt(i++)) >= 0xD800) { + result |= (next & 0x1FFF) << shift; + shift += 13; + } + next = result | (next << shift); + } + final int fieldCount = next; + + final int oneofCount; + final int hasBitsCount; + final int minFieldNumber; + final int maxFieldNumber; + final int numEntries; + final int mapFieldCount; + final int repeatedFieldCount; + final int checkInitialized; + final int[] intArray; + int objectsPosition; + if (fieldCount == 0) { + oneofCount = 0; + hasBitsCount = 0; + minFieldNumber = 0; + maxFieldNumber = 0; + numEntries = 0; + mapFieldCount = 0; + repeatedFieldCount = 0; + checkInitialized = 0; + intArray = EMPTY_INT_ARRAY; + objectsPosition = 0; + } else { + next = info.charAt(i++); + if (next >= 0xD800) { + int result = next & 0x1FFF; + int shift = 13; + while ((next = info.charAt(i++)) >= 0xD800) { + result |= (next & 0x1FFF) << shift; + shift += 13; + } + next = result | (next << shift); + } + oneofCount = next; + + next = info.charAt(i++); + if (next >= 0xD800) { + int result = next & 0x1FFF; + int shift = 13; + while ((next = info.charAt(i++)) >= 0xD800) { + result |= (next & 0x1FFF) << shift; + shift += 13; + } + next = result | (next << shift); + } + hasBitsCount = next; + + next = info.charAt(i++); + if (next >= 0xD800) { + int result = next & 0x1FFF; + int shift = 13; + while ((next = info.charAt(i++)) >= 0xD800) { + result |= (next & 0x1FFF) << shift; + shift += 13; + } + next = result | (next << shift); + } + minFieldNumber = next; + + next = info.charAt(i++); + if (next >= 0xD800) { + int result = next & 0x1FFF; + int shift = 13; + while ((next = info.charAt(i++)) >= 0xD800) { + result |= (next & 0x1FFF) << shift; + shift += 13; + } + next = result | (next << shift); + } + maxFieldNumber = next; + + next = info.charAt(i++); + if (next >= 0xD800) { + int result = next & 0x1FFF; + int shift = 13; + while ((next = info.charAt(i++)) >= 0xD800) { + result |= (next & 0x1FFF) << shift; + shift += 13; + } + next = result | (next << shift); + } + numEntries = next; + + next = info.charAt(i++); + if (next >= 0xD800) { + int result = next & 0x1FFF; + int shift = 13; + while ((next = info.charAt(i++)) >= 0xD800) { + result |= (next & 0x1FFF) << shift; + shift += 13; + } + next = result | (next << shift); + } + mapFieldCount = next; + + next = info.charAt(i++); + if (next >= 0xD800) { + int result = next & 0x1FFF; + int shift = 13; + while ((next = info.charAt(i++)) >= 0xD800) { + result |= (next & 0x1FFF) << shift; + shift += 13; + } + next = result | (next << shift); + } + repeatedFieldCount = next; + + next = info.charAt(i++); + if (next >= 0xD800) { + int result = next & 0x1FFF; + int shift = 13; + while ((next = info.charAt(i++)) >= 0xD800) { + result |= (next & 0x1FFF) << shift; + shift += 13; + } + next = result | (next << shift); + } + checkInitialized = next; + intArray = new int[checkInitialized + mapFieldCount + repeatedFieldCount]; + // Field objects are after a list of (oneof, oneofCase) pairs + a list of hasbits fields. + objectsPosition = oneofCount * 2 + hasBitsCount; + } + + final sun.misc.Unsafe unsafe = UNSAFE; + final Object[] messageInfoObjects = messageInfo.getObjects(); + int checkInitializedPosition = 0; + final Class messageClass = messageInfo.getDefaultInstance().getClass(); + int[] buffer = new int[numEntries * INTS_PER_FIELD]; + Object[] objects = new Object[numEntries * 2]; + + int mapFieldIndex = checkInitialized; + int repeatedFieldIndex = checkInitialized + mapFieldCount; + + int bufferIndex = 0; + while (i < length) { + final int fieldNumber; + final int fieldTypeWithExtraBits; + final int fieldType; + + next = info.charAt(i++); + if (next >= 0xD800) { + int result = next & 0x1FFF; + int shift = 13; + while ((next = info.charAt(i++)) >= 0xD800) { + result |= (next & 0x1FFF) << shift; + shift += 13; + } + next = result | (next << shift); + } + fieldNumber = next; + + next = info.charAt(i++); + if (next >= 0xD800) { + int result = next & 0x1FFF; + int shift = 13; + while ((next = info.charAt(i++)) >= 0xD800) { + result |= (next & 0x1FFF) << shift; + shift += 13; + } + next = result | (next << shift); + } + fieldTypeWithExtraBits = next; + fieldType = fieldTypeWithExtraBits & 0xFF; + + if ((fieldTypeWithExtraBits & 0x400) != 0) { + intArray[checkInitializedPosition++] = bufferIndex; + } + + final int fieldOffset; + final int presenceMaskShift; + final int presenceFieldOffset; + + // Oneof + if (fieldType >= ONEOF_TYPE_OFFSET) { + next = info.charAt(i++); + if (next >= 0xD800) { + int result = next & 0x1FFF; + int shift = 13; + while ((next = info.charAt(i++)) >= 0xD800) { + result |= (next & 0x1FFF) << shift; + shift += 13; + } + next = result | (next << shift); + } + int oneofIndex = next; + + final int oneofFieldType = fieldType - ONEOF_TYPE_OFFSET; + if (oneofFieldType == 9 /* FieldType.MESSAGE */ + || oneofFieldType == 17 /* FieldType.GROUP */) { + objects[bufferIndex / INTS_PER_FIELD * 2 + 1] = messageInfoObjects[objectsPosition++]; + } else if (oneofFieldType == 12 /* FieldType.ENUM */) { + if (!isProto3) { + objects[bufferIndex / INTS_PER_FIELD * 2 + 1] = messageInfoObjects[objectsPosition++]; + } + } + + final java.lang.reflect.Field oneofField; + int index = oneofIndex * 2; + Object o = messageInfoObjects[index]; + if (o instanceof java.lang.reflect.Field) { + oneofField = (java.lang.reflect.Field) o; + } else { + oneofField = reflectField(messageClass, (String) o); + // Memoize java.lang.reflect.Field instances for oneof/hasbits fields, since they're + // potentially used for many Protobuf fields. Since there's a 1-1 mapping from the + // Protobuf field to the Java Field for non-oneofs, there's no benefit for memoizing + // those. + messageInfoObjects[index] = oneofField; + } + + fieldOffset = (int) unsafe.objectFieldOffset(oneofField); + + final java.lang.reflect.Field oneofCaseField; + index++; + o = messageInfoObjects[index]; + if (o instanceof java.lang.reflect.Field) { + oneofCaseField = (java.lang.reflect.Field) o; + } else { + oneofCaseField = reflectField(messageClass, (String) o); + messageInfoObjects[index] = oneofCaseField; + } + + presenceFieldOffset = (int) unsafe.objectFieldOffset(oneofCaseField); + presenceMaskShift = 0; + } else { + Field field = reflectField(messageClass, (String) messageInfoObjects[objectsPosition++]); + if (fieldType == 9 /* FieldType.MESSAGE */ || fieldType == 17 /* FieldType.GROUP */) { + objects[bufferIndex / INTS_PER_FIELD * 2 + 1] = field.getType(); + } else if (fieldType == 27 /* FieldType.MESSAGE_LIST */ + || fieldType == 49 /* FieldType.GROUP_LIST */) { + objects[bufferIndex / INTS_PER_FIELD * 2 + 1] = messageInfoObjects[objectsPosition++]; + } else if (fieldType == 12 /* FieldType.ENUM */ + || fieldType == 30 /* FieldType.ENUM_LIST */ + || fieldType == 44 /* FieldType.ENUM_LIST_PACKED */) { + if (!isProto3) { + objects[bufferIndex / INTS_PER_FIELD * 2 + 1] = messageInfoObjects[objectsPosition++]; + } + } else if (fieldType == 50 /* FieldType.MAP */) { + intArray[mapFieldIndex++] = bufferIndex; + objects[bufferIndex / INTS_PER_FIELD * 2] = messageInfoObjects[objectsPosition++]; + if ((fieldTypeWithExtraBits & 0x800) != 0) { + objects[bufferIndex / INTS_PER_FIELD * 2 + 1] = messageInfoObjects[objectsPosition++]; + } + } + + fieldOffset = (int) unsafe.objectFieldOffset(field); + boolean hasHasBit = (fieldTypeWithExtraBits & 0x1000) == 0x1000; + if (hasHasBit && fieldType <= 17 /* FieldType.GROUP */) { + next = info.charAt(i++); + if (next >= 0xD800) { + int result = next & 0x1FFF; + int shift = 13; + while ((next = info.charAt(i++)) >= 0xD800) { + result |= (next & 0x1FFF) << shift; + shift += 13; + } + next = result | (next << shift); + } + int hasBitsIndex = next; + + final java.lang.reflect.Field hasBitsField; + int index = oneofCount * 2 + hasBitsIndex / 32; + Object o = messageInfoObjects[index]; + if (o instanceof java.lang.reflect.Field) { + hasBitsField = (java.lang.reflect.Field) o; + } else { + hasBitsField = reflectField(messageClass, (String) o); + messageInfoObjects[index] = hasBitsField; + } + + presenceFieldOffset = (int) unsafe.objectFieldOffset(hasBitsField); + presenceMaskShift = hasBitsIndex % 32; + } else { + presenceFieldOffset = NO_PRESENCE_SENTINEL; + presenceMaskShift = 0; + } + + if (fieldType >= 18 && fieldType <= 49) { + // Field types of repeated fields are in a consecutive range from 18 (DOUBLE_LIST) to + // 49 (GROUP_LIST). + intArray[repeatedFieldIndex++] = fieldOffset; + } + } + + buffer[bufferIndex++] = fieldNumber; + buffer[bufferIndex++] = + ((fieldTypeWithExtraBits & 0x200) != 0 ? ENFORCE_UTF8_MASK : 0) + | ((fieldTypeWithExtraBits & 0x100) != 0 ? REQUIRED_MASK : 0) + | (fieldType << OFFSET_BITS) + | fieldOffset; + buffer[bufferIndex++] = (presenceMaskShift << OFFSET_BITS) | presenceFieldOffset; + } + + return new MessageSchema( + buffer, + objects, + minFieldNumber, + maxFieldNumber, + messageInfo.getDefaultInstance(), + isProto3, + /* useCachedSizeField= */ false, + intArray, + checkInitialized, + checkInitialized + mapFieldCount, + newInstanceSchema, + listFieldSchema, + unknownFieldSchema, + extensionSchema, + mapFieldSchema); + } + + private static java.lang.reflect.Field reflectField(Class messageClass, String fieldName) { + try { + return messageClass.getDeclaredField(fieldName); + } catch (NoSuchFieldException e) { + // Some Samsung devices lie about what fields are present via the getDeclaredField API so + // we do the for loop properly that they seem to have messed up... + java.lang.reflect.Field[] fields = messageClass.getDeclaredFields(); + for (java.lang.reflect.Field field : fields) { + if (fieldName.equals(field.getName())) { + return field; + } + } + + // If we make it here, the runtime still lies about what we know to be true at compile + // time. We throw to alert server monitoring for further remediation. + throw new RuntimeException( + "Field " + + fieldName + + " for " + + messageClass.getName() + + " not found. Known fields are " + + Arrays.toString(fields)); + } + } + + static MessageSchema newSchemaForMessageInfo( + StructuralMessageInfo messageInfo, + NewInstanceSchema newInstanceSchema, + ListFieldSchema listFieldSchema, + UnknownFieldSchema unknownFieldSchema, + ExtensionSchema extensionSchema, + MapFieldSchema mapFieldSchema) { + final boolean isProto3 = messageInfo.getSyntax() == ProtoSyntax.PROTO3; + FieldInfo[] fis = messageInfo.getFields(); + final int minFieldNumber; + final int maxFieldNumber; + if (fis.length == 0) { + minFieldNumber = 0; + maxFieldNumber = 0; + } else { + minFieldNumber = fis[0].getFieldNumber(); + maxFieldNumber = fis[fis.length - 1].getFieldNumber(); + } + + final int numEntries = fis.length; + + int[] buffer = new int[numEntries * INTS_PER_FIELD]; + Object[] objects = new Object[numEntries * 2]; + + int mapFieldCount = 0; + int repeatedFieldCount = 0; + for (FieldInfo fi : fis) { + if (fi.getType() == FieldType.MAP) { + mapFieldCount++; + } else if (fi.getType().id() >= 18 && fi.getType().id() <= 49) { + // Field types of repeated fields are in a consecutive range from 18 (DOUBLE_LIST) to + // 49 (GROUP_LIST). + repeatedFieldCount++; + } + } + int[] mapFieldPositions = mapFieldCount > 0 ? new int[mapFieldCount] : null; + int[] repeatedFieldOffsets = repeatedFieldCount > 0 ? new int[repeatedFieldCount] : null; + mapFieldCount = 0; + repeatedFieldCount = 0; + + int[] checkInitialized = messageInfo.getCheckInitialized(); + if (checkInitialized == null) { + checkInitialized = EMPTY_INT_ARRAY; + } + int checkInitializedIndex = 0; + // Fill in the manifest data from the descriptors. + int fieldIndex = 0; + for (int bufferIndex = 0; fieldIndex < fis.length; bufferIndex += INTS_PER_FIELD) { + final FieldInfo fi = fis[fieldIndex]; + final int fieldNumber = fi.getFieldNumber(); + + // We found the entry for the next field. Store the entry in the manifest for + // this field and increment the field index. + storeFieldData(fi, buffer, bufferIndex, objects); + + // Convert field number to index + if (checkInitializedIndex < checkInitialized.length + && checkInitialized[checkInitializedIndex] == fieldNumber) { + checkInitialized[checkInitializedIndex++] = bufferIndex; + } + + if (fi.getType() == FieldType.MAP) { + mapFieldPositions[mapFieldCount++] = bufferIndex; + } else if (fi.getType().id() >= 18 && fi.getType().id() <= 49) { + // Field types of repeated fields are in a consecutive range from 18 (DOUBLE_LIST) to + // 49 (GROUP_LIST). + repeatedFieldOffsets[repeatedFieldCount++] = + (int) UnsafeUtil.objectFieldOffset(fi.getField()); + } + + fieldIndex++; + } + + if (mapFieldPositions == null) { + mapFieldPositions = EMPTY_INT_ARRAY; + } + if (repeatedFieldOffsets == null) { + repeatedFieldOffsets = EMPTY_INT_ARRAY; + } + int[] combined = + new int[checkInitialized.length + mapFieldPositions.length + repeatedFieldOffsets.length]; + System.arraycopy(checkInitialized, 0, combined, 0, checkInitialized.length); + System.arraycopy( + mapFieldPositions, 0, combined, checkInitialized.length, mapFieldPositions.length); + System.arraycopy( + repeatedFieldOffsets, + 0, + combined, + checkInitialized.length + mapFieldPositions.length, + repeatedFieldOffsets.length); + + return new MessageSchema( + buffer, + objects, + minFieldNumber, + maxFieldNumber, + messageInfo.getDefaultInstance(), + isProto3, + /* useCachedSizeField= */ true, + combined, + checkInitialized.length, + checkInitialized.length + mapFieldPositions.length, + newInstanceSchema, + listFieldSchema, + unknownFieldSchema, + extensionSchema, + mapFieldSchema); + } + + private static void storeFieldData( + FieldInfo fi, int[] buffer, int bufferIndex, Object[] objects) { + final int fieldOffset; + final int typeId; + final int presenceMaskShift; + final int presenceFieldOffset; + + OneofInfo oneof = fi.getOneof(); + if (oneof != null) { + typeId = fi.getType().id() + ONEOF_TYPE_OFFSET; + fieldOffset = (int) UnsafeUtil.objectFieldOffset(oneof.getValueField()); + presenceFieldOffset = (int) UnsafeUtil.objectFieldOffset(oneof.getCaseField()); + presenceMaskShift = 0; + } else { + FieldType type = fi.getType(); + fieldOffset = (int) UnsafeUtil.objectFieldOffset(fi.getField()); + typeId = type.id(); + if (!type.isList() && !type.isMap()) { + Field presenceField = fi.getPresenceField(); + if (presenceField == null) { + presenceFieldOffset = NO_PRESENCE_SENTINEL; + } else { + presenceFieldOffset = (int) UnsafeUtil.objectFieldOffset(presenceField); + } + presenceMaskShift = Integer.numberOfTrailingZeros(fi.getPresenceMask()); + } else { + if (fi.getCachedSizeField() == null) { + presenceFieldOffset = 0; + presenceMaskShift = 0; + } else { + presenceFieldOffset = (int) UnsafeUtil.objectFieldOffset(fi.getCachedSizeField()); + presenceMaskShift = 0; + } + } + } + + buffer[bufferIndex] = fi.getFieldNumber(); + buffer[bufferIndex + 1] = + (fi.isEnforceUtf8() ? ENFORCE_UTF8_MASK : 0) + | (fi.isRequired() ? REQUIRED_MASK : 0) + | (typeId << OFFSET_BITS) + | fieldOffset; + buffer[bufferIndex + 2] = (presenceMaskShift << OFFSET_BITS) | presenceFieldOffset; + + Object messageFieldClass = fi.getMessageFieldClass(); + if (fi.getMapDefaultEntry() != null) { + objects[bufferIndex / INTS_PER_FIELD * 2] = fi.getMapDefaultEntry(); + if (messageFieldClass != null) { + objects[bufferIndex / INTS_PER_FIELD * 2 + 1] = messageFieldClass; + } else if (fi.getEnumVerifier() != null) { + objects[bufferIndex / INTS_PER_FIELD * 2 + 1] = fi.getEnumVerifier(); + } + } else { + if (messageFieldClass != null) { + objects[bufferIndex / INTS_PER_FIELD * 2 + 1] = messageFieldClass; + } else if (fi.getEnumVerifier() != null) { + objects[bufferIndex / INTS_PER_FIELD * 2 + 1] = fi.getEnumVerifier(); + } + } + } + + @SuppressWarnings("unchecked") + @Override + public T newInstance() { + return (T) newInstanceSchema.newInstance(defaultInstance); + } + + @Override + public boolean equals(T message, T other) { + final int bufferLength = buffer.length; + for (int pos = 0; pos < bufferLength; pos += INTS_PER_FIELD) { + if (!equals(message, other, pos)) { + return false; + } + } + + Object messageUnknown = unknownFieldSchema.getFromMessage(message); + Object otherUnknown = unknownFieldSchema.getFromMessage(other); + if (!messageUnknown.equals(otherUnknown)) { + return false; + } + + if (hasExtensions) { + FieldSet messageExtensions = extensionSchema.getExtensions(message); + FieldSet otherExtensions = extensionSchema.getExtensions(other); + return messageExtensions.equals(otherExtensions); + } + return true; + } + + private boolean equals(T message, T other, int pos) { + final int typeAndOffset = typeAndOffsetAt(pos); + final long offset = offset(typeAndOffset); + + switch (type(typeAndOffset)) { + case 0: // DOUBLE: + return arePresentForEquals(message, other, pos) + && Double.doubleToLongBits(UnsafeUtil.getDouble(message, offset)) + == Double.doubleToLongBits(UnsafeUtil.getDouble(other, offset)); + case 1: // FLOAT: + return arePresentForEquals(message, other, pos) + && Float.floatToIntBits(UnsafeUtil.getFloat(message, offset)) + == Float.floatToIntBits(UnsafeUtil.getFloat(other, offset)); + case 2: // INT64: + return arePresentForEquals(message, other, pos) + && UnsafeUtil.getLong(message, offset) == UnsafeUtil.getLong(other, offset); + case 3: // UINT64: + return arePresentForEquals(message, other, pos) + && UnsafeUtil.getLong(message, offset) == UnsafeUtil.getLong(other, offset); + case 4: // INT32: + return arePresentForEquals(message, other, pos) + && UnsafeUtil.getInt(message, offset) == UnsafeUtil.getInt(other, offset); + case 5: // FIXED64: + return arePresentForEquals(message, other, pos) + && UnsafeUtil.getLong(message, offset) == UnsafeUtil.getLong(other, offset); + case 6: // FIXED32: + return arePresentForEquals(message, other, pos) + && UnsafeUtil.getInt(message, offset) == UnsafeUtil.getInt(other, offset); + case 7: // BOOL: + return arePresentForEquals(message, other, pos) + && UnsafeUtil.getBoolean(message, offset) == UnsafeUtil.getBoolean(other, offset); + case 8: // STRING: + return arePresentForEquals(message, other, pos) + && SchemaUtil.safeEquals( + UnsafeUtil.getObject(message, offset), UnsafeUtil.getObject(other, offset)); + case 9: // MESSAGE: + return arePresentForEquals(message, other, pos) + && SchemaUtil.safeEquals( + UnsafeUtil.getObject(message, offset), UnsafeUtil.getObject(other, offset)); + case 10: // BYTES: + return arePresentForEquals(message, other, pos) + && SchemaUtil.safeEquals( + UnsafeUtil.getObject(message, offset), UnsafeUtil.getObject(other, offset)); + case 11: // UINT32: + return arePresentForEquals(message, other, pos) + && UnsafeUtil.getInt(message, offset) == UnsafeUtil.getInt(other, offset); + case 12: // ENUM: + return arePresentForEquals(message, other, pos) + && UnsafeUtil.getInt(message, offset) == UnsafeUtil.getInt(other, offset); + case 13: // SFIXED32: + return arePresentForEquals(message, other, pos) + && UnsafeUtil.getInt(message, offset) == UnsafeUtil.getInt(other, offset); + case 14: // SFIXED64: + return arePresentForEquals(message, other, pos) + && UnsafeUtil.getLong(message, offset) == UnsafeUtil.getLong(other, offset); + case 15: // SINT32: + return arePresentForEquals(message, other, pos) + && UnsafeUtil.getInt(message, offset) == UnsafeUtil.getInt(other, offset); + case 16: // SINT64: + return arePresentForEquals(message, other, pos) + && UnsafeUtil.getLong(message, offset) == UnsafeUtil.getLong(other, offset); + case 17: // GROUP: + return arePresentForEquals(message, other, pos) + && SchemaUtil.safeEquals( + UnsafeUtil.getObject(message, offset), UnsafeUtil.getObject(other, offset)); + + case 18: // DOUBLE_LIST: + case 19: // FLOAT_LIST: + case 20: // INT64_LIST: + case 21: // UINT64_LIST: + case 22: // INT32_LIST: + case 23: // FIXED64_LIST: + case 24: // FIXED32_LIST: + case 25: // BOOL_LIST: + case 26: // STRING_LIST: + case 27: // MESSAGE_LIST: + case 28: // BYTES_LIST: + case 29: // UINT32_LIST: + case 30: // ENUM_LIST: + case 31: // SFIXED32_LIST: + case 32: // SFIXED64_LIST: + case 33: // SINT32_LIST: + case 34: // SINT64_LIST: + case 35: // DOUBLE_LIST_PACKED: + case 36: // FLOAT_LIST_PACKED: + case 37: // INT64_LIST_PACKED: + case 38: // UINT64_LIST_PACKED: + case 39: // INT32_LIST_PACKED: + case 40: // FIXED64_LIST_PACKED: + case 41: // FIXED32_LIST_PACKED: + case 42: // BOOL_LIST_PACKED: + case 43: // UINT32_LIST_PACKED: + case 44: // ENUM_LIST_PACKED: + case 45: // SFIXED32_LIST_PACKED: + case 46: // SFIXED64_LIST_PACKED: + case 47: // SINT32_LIST_PACKED: + case 48: // SINT64_LIST_PACKED: + case 49: // GROUP_LIST: + return SchemaUtil.safeEquals( + UnsafeUtil.getObject(message, offset), UnsafeUtil.getObject(other, offset)); + case 50: // MAP: + return SchemaUtil.safeEquals( + UnsafeUtil.getObject(message, offset), UnsafeUtil.getObject(other, offset)); + case 51: // ONEOF_DOUBLE: + case 52: // ONEOF_FLOAT: + case 53: // ONEOF_INT64: + case 54: // ONEOF_UINT64: + case 55: // ONEOF_INT32: + case 56: // ONEOF_FIXED64: + case 57: // ONEOF_FIXED32: + case 58: // ONEOF_BOOL: + case 59: // ONEOF_STRING: + case 60: // ONEOF_MESSAGE: + case 61: // ONEOF_BYTES: + case 62: // ONEOF_UINT32: + case 63: // ONEOF_ENUM: + case 64: // ONEOF_SFIXED32: + case 65: // ONEOF_SFIXED64: + case 66: // ONEOF_SINT32: + case 67: // ONEOF_SINT64: + case 68: // ONEOF_GROUP: + return isOneofCaseEqual(message, other, pos) + && SchemaUtil.safeEquals( + UnsafeUtil.getObject(message, offset), UnsafeUtil.getObject(other, offset)); + default: + // Assume it's an empty entry - just go to the next entry. + return true; + } + } + + @Override + public int hashCode(T message) { + int hashCode = 0; + final int bufferLength = buffer.length; + for (int pos = 0; pos < bufferLength; pos += INTS_PER_FIELD) { + final int typeAndOffset = typeAndOffsetAt(pos); + final int entryNumber = numberAt(pos); + + final long offset = offset(typeAndOffset); + + switch (type(typeAndOffset)) { + case 0: // DOUBLE: + hashCode = + (hashCode * 53) + + Internal.hashLong( + Double.doubleToLongBits(UnsafeUtil.getDouble(message, offset))); + break; + case 1: // FLOAT: + hashCode = (hashCode * 53) + Float.floatToIntBits(UnsafeUtil.getFloat(message, offset)); + break; + case 2: // INT64: + hashCode = (hashCode * 53) + Internal.hashLong(UnsafeUtil.getLong(message, offset)); + break; + case 3: // UINT64: + hashCode = (hashCode * 53) + Internal.hashLong(UnsafeUtil.getLong(message, offset)); + break; + case 4: // INT32: + hashCode = (hashCode * 53) + (UnsafeUtil.getInt(message, offset)); + break; + case 5: // FIXED64: + hashCode = (hashCode * 53) + Internal.hashLong(UnsafeUtil.getLong(message, offset)); + break; + case 6: // FIXED32: + hashCode = (hashCode * 53) + (UnsafeUtil.getInt(message, offset)); + break; + case 7: // BOOL: + hashCode = (hashCode * 53) + Internal.hashBoolean(UnsafeUtil.getBoolean(message, offset)); + break; + case 8: // STRING: + hashCode = (hashCode * 53) + ((String) UnsafeUtil.getObject(message, offset)).hashCode(); + break; + case 9: // MESSAGE: + { + int protoHash = 37; + Object submessage = UnsafeUtil.getObject(message, offset); + if (submessage != null) { + protoHash = submessage.hashCode(); + } + hashCode = (53 * hashCode) + protoHash; + break; + } + case 10: // BYTES: + hashCode = (hashCode * 53) + UnsafeUtil.getObject(message, offset).hashCode(); + break; + case 11: // UINT32: + hashCode = (hashCode * 53) + (UnsafeUtil.getInt(message, offset)); + break; + case 12: // ENUM: + hashCode = (hashCode * 53) + (UnsafeUtil.getInt(message, offset)); + break; + case 13: // SFIXED32: + hashCode = (hashCode * 53) + (UnsafeUtil.getInt(message, offset)); + break; + case 14: // SFIXED64: + hashCode = (hashCode * 53) + Internal.hashLong(UnsafeUtil.getLong(message, offset)); + break; + case 15: // SINT32: + hashCode = (hashCode * 53) + (UnsafeUtil.getInt(message, offset)); + break; + case 16: // SINT64: + hashCode = (hashCode * 53) + Internal.hashLong(UnsafeUtil.getLong(message, offset)); + break; + + case 17: // GROUP: + { + int protoHash = 37; + Object submessage = UnsafeUtil.getObject(message, offset); + if (submessage != null) { + protoHash = submessage.hashCode(); + } + hashCode = (53 * hashCode) + protoHash; + break; + } + case 18: // DOUBLE_LIST: + case 19: // FLOAT_LIST: + case 20: // INT64_LIST: + case 21: // UINT64_LIST: + case 22: // INT32_LIST: + case 23: // FIXED64_LIST: + case 24: // FIXED32_LIST: + case 25: // BOOL_LIST: + case 26: // STRING_LIST: + case 27: // MESSAGE_LIST: + case 28: // BYTES_LIST: + case 29: // UINT32_LIST: + case 30: // ENUM_LIST: + case 31: // SFIXED32_LIST: + case 32: // SFIXED64_LIST: + case 33: // SINT32_LIST: + case 34: // SINT64_LIST: + case 35: // DOUBLE_LIST_PACKED: + case 36: // FLOAT_LIST_PACKED: + case 37: // INT64_LIST_PACKED: + case 38: // UINT64_LIST_PACKED: + case 39: // INT32_LIST_PACKED: + case 40: // FIXED64_LIST_PACKED: + case 41: // FIXED32_LIST_PACKED: + case 42: // BOOL_LIST_PACKED: + case 43: // UINT32_LIST_PACKED: + case 44: // ENUM_LIST_PACKED: + case 45: // SFIXED32_LIST_PACKED: + case 46: // SFIXED64_LIST_PACKED: + case 47: // SINT32_LIST_PACKED: + case 48: // SINT64_LIST_PACKED: + case 49: // GROUP_LIST: + hashCode = (hashCode * 53) + UnsafeUtil.getObject(message, offset).hashCode(); + break; + case 50: // MAP: + hashCode = (hashCode * 53) + UnsafeUtil.getObject(message, offset).hashCode(); + break; + case 51: // ONEOF_DOUBLE: + if (isOneofPresent(message, entryNumber, pos)) { + hashCode = + (hashCode * 53) + + Internal.hashLong(Double.doubleToLongBits(oneofDoubleAt(message, offset))); + } + break; + case 52: // ONEOF_FLOAT: + if (isOneofPresent(message, entryNumber, pos)) { + hashCode = (hashCode * 53) + Float.floatToIntBits(oneofFloatAt(message, offset)); + } + break; + case 53: // ONEOF_INT64: + if (isOneofPresent(message, entryNumber, pos)) { + hashCode = (hashCode * 53) + Internal.hashLong(oneofLongAt(message, offset)); + } + break; + case 54: // ONEOF_UINT64: + if (isOneofPresent(message, entryNumber, pos)) { + hashCode = (hashCode * 53) + Internal.hashLong(oneofLongAt(message, offset)); + } + break; + case 55: // ONEOF_INT32: + if (isOneofPresent(message, entryNumber, pos)) { + hashCode = (hashCode * 53) + (oneofIntAt(message, offset)); + } + break; + case 56: // ONEOF_FIXED64: + if (isOneofPresent(message, entryNumber, pos)) { + hashCode = (hashCode * 53) + Internal.hashLong(oneofLongAt(message, offset)); + } + break; + case 57: // ONEOF_FIXED32: + if (isOneofPresent(message, entryNumber, pos)) { + hashCode = (hashCode * 53) + (oneofIntAt(message, offset)); + } + break; + case 58: // ONEOF_BOOL: + if (isOneofPresent(message, entryNumber, pos)) { + hashCode = (hashCode * 53) + Internal.hashBoolean(oneofBooleanAt(message, offset)); + } + break; + case 59: // ONEOF_STRING: + if (isOneofPresent(message, entryNumber, pos)) { + hashCode = + (hashCode * 53) + ((String) UnsafeUtil.getObject(message, offset)).hashCode(); + } + break; + case 60: // ONEOF_MESSAGE: + if (isOneofPresent(message, entryNumber, pos)) { + Object submessage = UnsafeUtil.getObject(message, offset); + hashCode = (53 * hashCode) + submessage.hashCode(); + } + break; + case 61: // ONEOF_BYTES: + if (isOneofPresent(message, entryNumber, pos)) { + hashCode = (hashCode * 53) + UnsafeUtil.getObject(message, offset).hashCode(); + } + break; + case 62: // ONEOF_UINT32: + if (isOneofPresent(message, entryNumber, pos)) { + hashCode = (hashCode * 53) + (oneofIntAt(message, offset)); + } + break; + case 63: // ONEOF_ENUM: + if (isOneofPresent(message, entryNumber, pos)) { + hashCode = (hashCode * 53) + (oneofIntAt(message, offset)); + } + break; + case 64: // ONEOF_SFIXED32: + if (isOneofPresent(message, entryNumber, pos)) { + hashCode = (hashCode * 53) + (oneofIntAt(message, offset)); + } + break; + case 65: // ONEOF_SFIXED64: + if (isOneofPresent(message, entryNumber, pos)) { + hashCode = (hashCode * 53) + Internal.hashLong(oneofLongAt(message, offset)); + } + break; + case 66: // ONEOF_SINT32: + if (isOneofPresent(message, entryNumber, pos)) { + hashCode = (hashCode * 53) + (oneofIntAt(message, offset)); + } + break; + case 67: // ONEOF_SINT64: + if (isOneofPresent(message, entryNumber, pos)) { + hashCode = (hashCode * 53) + Internal.hashLong(oneofLongAt(message, offset)); + } + break; + case 68: // ONEOF_GROUP: + if (isOneofPresent(message, entryNumber, pos)) { + Object submessage = UnsafeUtil.getObject(message, offset); + hashCode = (53 * hashCode) + submessage.hashCode(); + } + break; + default: + // Assume it's an empty entry - just go to the next entry. + break; + } + } + + hashCode = (hashCode * 53) + unknownFieldSchema.getFromMessage(message).hashCode(); + + if (hasExtensions) { + hashCode = (hashCode * 53) + extensionSchema.getExtensions(message).hashCode(); + } + + return hashCode; + } + + @Override + public void mergeFrom(T message, T other) { + if (other == null) { + throw new NullPointerException(); + } + for (int i = 0; i < buffer.length; i += INTS_PER_FIELD) { + // A separate method allows for better JIT optimizations + mergeSingleField(message, other, i); + } + + SchemaUtil.mergeUnknownFields(unknownFieldSchema, message, other); + + if (hasExtensions) { + SchemaUtil.mergeExtensions(extensionSchema, message, other); + } + } + + private void mergeSingleField(T message, T other, int pos) { + final int typeAndOffset = typeAndOffsetAt(pos); + final long offset = offset(typeAndOffset); + final int number = numberAt(pos); + + switch (type(typeAndOffset)) { + case 0: // DOUBLE: + if (isFieldPresent(other, pos)) { + UnsafeUtil.putDouble(message, offset, UnsafeUtil.getDouble(other, offset)); + setFieldPresent(message, pos); + } + break; + case 1: // FLOAT: + if (isFieldPresent(other, pos)) { + UnsafeUtil.putFloat(message, offset, UnsafeUtil.getFloat(other, offset)); + setFieldPresent(message, pos); + } + break; + case 2: // INT64: + if (isFieldPresent(other, pos)) { + UnsafeUtil.putLong(message, offset, UnsafeUtil.getLong(other, offset)); + setFieldPresent(message, pos); + } + break; + case 3: // UINT64: + if (isFieldPresent(other, pos)) { + UnsafeUtil.putLong(message, offset, UnsafeUtil.getLong(other, offset)); + setFieldPresent(message, pos); + } + break; + case 4: // INT32: + if (isFieldPresent(other, pos)) { + UnsafeUtil.putInt(message, offset, UnsafeUtil.getInt(other, offset)); + setFieldPresent(message, pos); + } + break; + case 5: // FIXED64: + if (isFieldPresent(other, pos)) { + UnsafeUtil.putLong(message, offset, UnsafeUtil.getLong(other, offset)); + setFieldPresent(message, pos); + } + break; + case 6: // FIXED32: + if (isFieldPresent(other, pos)) { + UnsafeUtil.putInt(message, offset, UnsafeUtil.getInt(other, offset)); + setFieldPresent(message, pos); + } + break; + case 7: // BOOL: + if (isFieldPresent(other, pos)) { + UnsafeUtil.putBoolean(message, offset, UnsafeUtil.getBoolean(other, offset)); + setFieldPresent(message, pos); + } + break; + case 8: // STRING: + if (isFieldPresent(other, pos)) { + UnsafeUtil.putObject(message, offset, UnsafeUtil.getObject(other, offset)); + setFieldPresent(message, pos); + } + break; + case 9: // MESSAGE: + mergeMessage(message, other, pos); + break; + case 10: // BYTES: + if (isFieldPresent(other, pos)) { + UnsafeUtil.putObject(message, offset, UnsafeUtil.getObject(other, offset)); + setFieldPresent(message, pos); + } + break; + case 11: // UINT32: + if (isFieldPresent(other, pos)) { + UnsafeUtil.putInt(message, offset, UnsafeUtil.getInt(other, offset)); + setFieldPresent(message, pos); + } + break; + case 12: // ENUM: + if (isFieldPresent(other, pos)) { + UnsafeUtil.putInt(message, offset, UnsafeUtil.getInt(other, offset)); + setFieldPresent(message, pos); + } + break; + case 13: // SFIXED32: + if (isFieldPresent(other, pos)) { + UnsafeUtil.putInt(message, offset, UnsafeUtil.getInt(other, offset)); + setFieldPresent(message, pos); + } + break; + case 14: // SFIXED64: + if (isFieldPresent(other, pos)) { + UnsafeUtil.putLong(message, offset, UnsafeUtil.getLong(other, offset)); + setFieldPresent(message, pos); + } + break; + case 15: // SINT32: + if (isFieldPresent(other, pos)) { + UnsafeUtil.putInt(message, offset, UnsafeUtil.getInt(other, offset)); + setFieldPresent(message, pos); + } + break; + case 16: // SINT64: + if (isFieldPresent(other, pos)) { + UnsafeUtil.putLong(message, offset, UnsafeUtil.getLong(other, offset)); + setFieldPresent(message, pos); + } + break; + case 17: // GROUP: + mergeMessage(message, other, pos); + break; + case 18: // DOUBLE_LIST: + case 19: // FLOAT_LIST: + case 20: // INT64_LIST: + case 21: // UINT64_LIST: + case 22: // INT32_LIST: + case 23: // FIXED64_LIST: + case 24: // FIXED32_LIST: + case 25: // BOOL_LIST: + case 26: // STRING_LIST: + case 27: // MESSAGE_LIST: + case 28: // BYTES_LIST: + case 29: // UINT32_LIST: + case 30: // ENUM_LIST: + case 31: // SFIXED32_LIST: + case 32: // SFIXED64_LIST: + case 33: // SINT32_LIST: + case 34: // SINT64_LIST: + case 35: // DOUBLE_LIST_PACKED: + case 36: // FLOAT_LIST_PACKED: + case 37: // INT64_LIST_PACKED: + case 38: // UINT64_LIST_PACKED: + case 39: // INT32_LIST_PACKED: + case 40: // FIXED64_LIST_PACKED: + case 41: // FIXED32_LIST_PACKED: + case 42: // BOOL_LIST_PACKED: + case 43: // UINT32_LIST_PACKED: + case 44: // ENUM_LIST_PACKED: + case 45: // SFIXED32_LIST_PACKED: + case 46: // SFIXED64_LIST_PACKED: + case 47: // SINT32_LIST_PACKED: + case 48: // SINT64_LIST_PACKED: + case 49: // GROUP_LIST: + listFieldSchema.mergeListsAt(message, other, offset); + break; + case 50: // MAP: + SchemaUtil.mergeMap(mapFieldSchema, message, other, offset); + break; + case 51: // ONEOF_DOUBLE: + case 52: // ONEOF_FLOAT: + case 53: // ONEOF_INT64: + case 54: // ONEOF_UINT64: + case 55: // ONEOF_INT32: + case 56: // ONEOF_FIXED64: + case 57: // ONEOF_FIXED32: + case 58: // ONEOF_BOOL: + case 59: // ONEOF_STRING: + if (isOneofPresent(other, number, pos)) { + UnsafeUtil.putObject(message, offset, UnsafeUtil.getObject(other, offset)); + setOneofPresent(message, number, pos); + } + break; + + case 60: // ONEOF_MESSAGE: + mergeOneofMessage(message, other, pos); + break; + case 61: // ONEOF_BYTES: + case 62: // ONEOF_UINT32: + case 63: // ONEOF_ENUM: + case 64: // ONEOF_SFIXED32: + case 65: // ONEOF_SFIXED64: + case 66: // ONEOF_SINT32: + case 67: // ONEOF_SINT64: + if (isOneofPresent(other, number, pos)) { + UnsafeUtil.putObject(message, offset, UnsafeUtil.getObject(other, offset)); + setOneofPresent(message, number, pos); + } + break; + case 68: // ONEOF_GROUP: + mergeOneofMessage(message, other, pos); + break; + default: + break; + } + } + + private void mergeMessage(T message, T other, int pos) { + final int typeAndOffset = typeAndOffsetAt(pos); + final long offset = offset(typeAndOffset); + + if (!isFieldPresent(other, pos)) { + return; + } + + Object mine = UnsafeUtil.getObject(message, offset); + Object theirs = UnsafeUtil.getObject(other, offset); + if (mine != null && theirs != null) { + Object merged = Internal.mergeMessage(mine, theirs); + UnsafeUtil.putObject(message, offset, merged); + setFieldPresent(message, pos); + } else if (theirs != null) { + UnsafeUtil.putObject(message, offset, theirs); + setFieldPresent(message, pos); + } + } + + private void mergeOneofMessage(T message, T other, int pos) { + int typeAndOffset = typeAndOffsetAt(pos); + int number = numberAt(pos); + long offset = offset(typeAndOffset); + + if (!isOneofPresent(other, number, pos)) { + return; + } + Object mine = null; + if (isOneofPresent(message, number, pos)) { + mine = UnsafeUtil.getObject(message, offset); + } + Object theirs = UnsafeUtil.getObject(other, offset); + if (mine != null && theirs != null) { + Object merged = Internal.mergeMessage(mine, theirs); + UnsafeUtil.putObject(message, offset, merged); + setOneofPresent(message, number, pos); + } else if (theirs != null) { + UnsafeUtil.putObject(message, offset, theirs); + setOneofPresent(message, number, pos); + } + } + + @Override + public int getSerializedSize(T message) { + return proto3 ? getSerializedSizeProto3(message) : getSerializedSizeProto2(message); + } + + @SuppressWarnings("unchecked") + private int getSerializedSizeProto2(T message) { + int size = 0; + + final sun.misc.Unsafe unsafe = UNSAFE; + int currentPresenceFieldOffset = NO_PRESENCE_SENTINEL; + int currentPresenceField = 0; + for (int i = 0; i < buffer.length; i += INTS_PER_FIELD) { + final int typeAndOffset = typeAndOffsetAt(i); + final int number = numberAt(i); + + int fieldType = type(typeAndOffset); + int presenceMaskAndOffset = 0; + int presenceMask = 0; + if (fieldType <= 17) { + presenceMaskAndOffset = buffer[i + 2]; + final int presenceFieldOffset = presenceMaskAndOffset & OFFSET_MASK; + presenceMask = 1 << (presenceMaskAndOffset >>> OFFSET_BITS); + if (presenceFieldOffset != currentPresenceFieldOffset) { + currentPresenceFieldOffset = presenceFieldOffset; + currentPresenceField = unsafe.getInt(message, (long) presenceFieldOffset); + } + } else if (useCachedSizeField + && fieldType >= FieldType.DOUBLE_LIST_PACKED.id() + && fieldType <= FieldType.SINT64_LIST_PACKED.id()) { + presenceMaskAndOffset = buffer[i + 2] & OFFSET_MASK; + } + + final long offset = offset(typeAndOffset); + + switch (fieldType) { + case 0: // DOUBLE: + if ((currentPresenceField & presenceMask) != 0) { + size += CodedOutputStream.computeDoubleSize(number, 0); + } + break; + case 1: // FLOAT: + if ((currentPresenceField & presenceMask) != 0) { + size += CodedOutputStream.computeFloatSize(number, 0); + } + break; + case 2: // INT64: + if ((currentPresenceField & presenceMask) != 0) { + size += CodedOutputStream.computeInt64Size(number, unsafe.getLong(message, offset)); + } + break; + case 3: // UINT64: + if ((currentPresenceField & presenceMask) != 0) { + size += CodedOutputStream.computeUInt64Size(number, unsafe.getLong(message, offset)); + } + break; + case 4: // INT32: + if ((currentPresenceField & presenceMask) != 0) { + size += CodedOutputStream.computeInt32Size(number, unsafe.getInt(message, offset)); + } + break; + case 5: // FIXED64: + if ((currentPresenceField & presenceMask) != 0) { + size += CodedOutputStream.computeFixed64Size(number, 0); + } + break; + case 6: // FIXED32: + if ((currentPresenceField & presenceMask) != 0) { + size += CodedOutputStream.computeFixed32Size(number, 0); + } + break; + case 7: // BOOL: + if ((currentPresenceField & presenceMask) != 0) { + size += CodedOutputStream.computeBoolSize(number, true); + } + break; + case 8: // STRING: + if ((currentPresenceField & presenceMask) != 0) { + Object value = unsafe.getObject(message, offset); + if (value instanceof ByteString) { + size += CodedOutputStream.computeBytesSize(number, (ByteString) value); + } else { + size += CodedOutputStream.computeStringSize(number, (String) value); + } + } + break; + case 9: // MESSAGE: + if ((currentPresenceField & presenceMask) != 0) { + Object value = unsafe.getObject(message, offset); + size += SchemaUtil.computeSizeMessage(number, value, getMessageFieldSchema(i)); + } + break; + case 10: // BYTES: + if ((currentPresenceField & presenceMask) != 0) { + ByteString value = (ByteString) unsafe.getObject(message, offset); + size += CodedOutputStream.computeBytesSize(number, value); + } + break; + case 11: // UINT32: + if ((currentPresenceField & presenceMask) != 0) { + size += CodedOutputStream.computeUInt32Size(number, unsafe.getInt(message, offset)); + } + break; + case 12: // ENUM: + if ((currentPresenceField & presenceMask) != 0) { + size += CodedOutputStream.computeEnumSize(number, unsafe.getInt(message, offset)); + } + break; + case 13: // SFIXED32: + if ((currentPresenceField & presenceMask) != 0) { + size += CodedOutputStream.computeSFixed32Size(number, 0); + } + break; + case 14: // SFIXED64: + if ((currentPresenceField & presenceMask) != 0) { + size += CodedOutputStream.computeSFixed64Size(number, 0); + } + break; + case 15: // SINT32: + if ((currentPresenceField & presenceMask) != 0) { + size += CodedOutputStream.computeSInt32Size(number, unsafe.getInt(message, offset)); + } + break; + case 16: // SINT64: + if ((currentPresenceField & presenceMask) != 0) { + size += CodedOutputStream.computeSInt64Size(number, unsafe.getLong(message, offset)); + } + break; + case 17: // GROUP: + if ((currentPresenceField & presenceMask) != 0) { + size += + CodedOutputStream.computeGroupSize( + number, + (MessageLite) unsafe.getObject(message, offset), + getMessageFieldSchema(i)); + } + break; + case 18: // DOUBLE_LIST: + size += + SchemaUtil.computeSizeFixed64List( + number, (List) unsafe.getObject(message, offset), false); + break; + case 19: // FLOAT_LIST: + size += + SchemaUtil.computeSizeFixed32List( + number, (List) unsafe.getObject(message, offset), false); + break; + case 20: // INT64_LIST: + size += + SchemaUtil.computeSizeInt64List( + number, (List) unsafe.getObject(message, offset), false); + break; + case 21: // UINT64_LIST: + size += + SchemaUtil.computeSizeUInt64List( + number, (List) unsafe.getObject(message, offset), false); + break; + case 22: // INT32_LIST: + size += + SchemaUtil.computeSizeInt32List( + number, (List) unsafe.getObject(message, offset), false); + break; + case 23: // FIXED64_LIST: + size += + SchemaUtil.computeSizeFixed64List( + number, (List) unsafe.getObject(message, offset), false); + break; + case 24: // FIXED32_LIST: + size += + SchemaUtil.computeSizeFixed32List( + number, (List) unsafe.getObject(message, offset), false); + break; + case 25: // BOOL_LIST: + size += + SchemaUtil.computeSizeBoolList( + number, (List) unsafe.getObject(message, offset), false); + break; + case 26: // STRING_LIST: + size += + SchemaUtil.computeSizeStringList(number, (List) unsafe.getObject(message, offset)); + break; + case 27: // MESSAGE_LIST: + size += + SchemaUtil.computeSizeMessageList( + number, (List) unsafe.getObject(message, offset), getMessageFieldSchema(i)); + break; + case 28: // BYTES_LIST: + size += + SchemaUtil.computeSizeByteStringList( + number, (List) unsafe.getObject(message, offset)); + break; + case 29: // UINT32_LIST: + size += + SchemaUtil.computeSizeUInt32List( + number, (List) unsafe.getObject(message, offset), false); + break; + case 30: // ENUM_LIST: + size += + SchemaUtil.computeSizeEnumList( + number, (List) unsafe.getObject(message, offset), false); + break; + case 31: // SFIXED32_LIST: + size += + SchemaUtil.computeSizeFixed32List( + number, (List) unsafe.getObject(message, offset), false); + break; + case 32: // SFIXED64_LIST: + size += + SchemaUtil.computeSizeFixed64List( + number, (List) unsafe.getObject(message, offset), false); + break; + case 33: // SINT32_LIST: + size += + SchemaUtil.computeSizeSInt32List( + number, (List) unsafe.getObject(message, offset), false); + break; + case 34: // SINT64_LIST: + size += + SchemaUtil.computeSizeSInt64List( + number, (List) unsafe.getObject(message, offset), false); + break; + case 35: + { // DOUBLE_LIST_PACKED: + int fieldSize = + SchemaUtil.computeSizeFixed64ListNoTag( + (List) unsafe.getObject(message, offset)); + if (fieldSize > 0) { + if (useCachedSizeField) { + unsafe.putInt(message, (long) presenceMaskAndOffset, fieldSize); + } + size += + CodedOutputStream.computeTagSize(number) + + CodedOutputStream.computeUInt32SizeNoTag(fieldSize) + + fieldSize; + } + break; + } + case 36: + { // FLOAT_LIST_PACKED: + int fieldSize = + SchemaUtil.computeSizeFixed32ListNoTag( + (List) unsafe.getObject(message, offset)); + if (fieldSize > 0) { + if (useCachedSizeField) { + unsafe.putInt(message, (long) presenceMaskAndOffset, fieldSize); + } + size += + CodedOutputStream.computeTagSize(number) + + CodedOutputStream.computeUInt32SizeNoTag(fieldSize) + + fieldSize; + } + break; + } + case 37: + { // INT64_LIST_PACKED: + int fieldSize = + SchemaUtil.computeSizeInt64ListNoTag( + (List) unsafe.getObject(message, offset)); + if (fieldSize > 0) { + if (useCachedSizeField) { + unsafe.putInt(message, (long) presenceMaskAndOffset, fieldSize); + } + size += + CodedOutputStream.computeTagSize(number) + + CodedOutputStream.computeUInt32SizeNoTag(fieldSize) + + fieldSize; + } + break; + } + case 38: + { // UINT64_LIST_PACKED: + int fieldSize = + SchemaUtil.computeSizeUInt64ListNoTag( + (List) unsafe.getObject(message, offset)); + if (fieldSize > 0) { + if (useCachedSizeField) { + unsafe.putInt(message, (long) presenceMaskAndOffset, fieldSize); + } + size += + CodedOutputStream.computeTagSize(number) + + CodedOutputStream.computeUInt32SizeNoTag(fieldSize) + + fieldSize; + } + break; + } + case 39: + { // INT32_LIST_PACKED: + int fieldSize = + SchemaUtil.computeSizeInt32ListNoTag( + (List) unsafe.getObject(message, offset)); + if (fieldSize > 0) { + if (useCachedSizeField) { + unsafe.putInt(message, (long) presenceMaskAndOffset, fieldSize); + } + size += + CodedOutputStream.computeTagSize(number) + + CodedOutputStream.computeUInt32SizeNoTag(fieldSize) + + fieldSize; + } + break; + } + case 40: + { // FIXED64_LIST_PACKED: + int fieldSize = + SchemaUtil.computeSizeFixed64ListNoTag( + (List) unsafe.getObject(message, offset)); + if (fieldSize > 0) { + if (useCachedSizeField) { + unsafe.putInt(message, (long) presenceMaskAndOffset, fieldSize); + } + size += + CodedOutputStream.computeTagSize(number) + + CodedOutputStream.computeUInt32SizeNoTag(fieldSize) + + fieldSize; + } + break; + } + case 41: + { // FIXED32_LIST_PACKED: + int fieldSize = + SchemaUtil.computeSizeFixed32ListNoTag( + (List) unsafe.getObject(message, offset)); + if (fieldSize > 0) { + if (useCachedSizeField) { + unsafe.putInt(message, (long) presenceMaskAndOffset, fieldSize); + } + size += + CodedOutputStream.computeTagSize(number) + + CodedOutputStream.computeUInt32SizeNoTag(fieldSize) + + fieldSize; + } + break; + } + case 42: + { // BOOL_LIST_PACKED: + int fieldSize = + SchemaUtil.computeSizeBoolListNoTag( + (List) unsafe.getObject(message, offset)); + if (fieldSize > 0) { + if (useCachedSizeField) { + unsafe.putInt(message, (long) presenceMaskAndOffset, fieldSize); + } + size += + CodedOutputStream.computeTagSize(number) + + CodedOutputStream.computeUInt32SizeNoTag(fieldSize) + + fieldSize; + } + break; + } + case 43: + { // UINT32_LIST_PACKED: + int fieldSize = + SchemaUtil.computeSizeUInt32ListNoTag( + (List) unsafe.getObject(message, offset)); + if (fieldSize > 0) { + if (useCachedSizeField) { + unsafe.putInt(message, (long) presenceMaskAndOffset, fieldSize); + } + size += + CodedOutputStream.computeTagSize(number) + + CodedOutputStream.computeUInt32SizeNoTag(fieldSize) + + fieldSize; + } + break; + } + case 44: + { // ENUM_LIST_PACKED: + int fieldSize = + SchemaUtil.computeSizeEnumListNoTag( + (List) unsafe.getObject(message, offset)); + if (fieldSize > 0) { + if (useCachedSizeField) { + unsafe.putInt(message, (long) presenceMaskAndOffset, fieldSize); + } + size += + CodedOutputStream.computeTagSize(number) + + CodedOutputStream.computeUInt32SizeNoTag(fieldSize) + + fieldSize; + } + break; + } + case 45: + { // SFIXED32_LIST_PACKED: + int fieldSize = + SchemaUtil.computeSizeFixed32ListNoTag( + (List) unsafe.getObject(message, offset)); + if (fieldSize > 0) { + if (useCachedSizeField) { + unsafe.putInt(message, (long) presenceMaskAndOffset, fieldSize); + } + size += + CodedOutputStream.computeTagSize(number) + + CodedOutputStream.computeUInt32SizeNoTag(fieldSize) + + fieldSize; + } + break; + } + case 46: + { // SFIXED64_LIST_PACKED: + int fieldSize = + SchemaUtil.computeSizeFixed64ListNoTag( + (List) unsafe.getObject(message, offset)); + if (fieldSize > 0) { + if (useCachedSizeField) { + unsafe.putInt(message, (long) presenceMaskAndOffset, fieldSize); + } + size += + CodedOutputStream.computeTagSize(number) + + CodedOutputStream.computeUInt32SizeNoTag(fieldSize) + + fieldSize; + } + break; + } + case 47: + { // SINT32_LIST_PACKED: + int fieldSize = + SchemaUtil.computeSizeSInt32ListNoTag( + (List) unsafe.getObject(message, offset)); + if (fieldSize > 0) { + if (useCachedSizeField) { + unsafe.putInt(message, (long) presenceMaskAndOffset, fieldSize); + } + size += + CodedOutputStream.computeTagSize(number) + + CodedOutputStream.computeUInt32SizeNoTag(fieldSize) + + fieldSize; + } + break; + } + case 48: + { // SINT64_LIST_PACKED: + int fieldSize = + SchemaUtil.computeSizeSInt64ListNoTag( + (List) unsafe.getObject(message, offset)); + if (fieldSize > 0) { + if (useCachedSizeField) { + unsafe.putInt(message, (long) presenceMaskAndOffset, fieldSize); + } + size += + CodedOutputStream.computeTagSize(number) + + CodedOutputStream.computeUInt32SizeNoTag(fieldSize) + + fieldSize; + } + break; + } + case 49: // GROUP_LIST: + size += + SchemaUtil.computeSizeGroupList( + number, + (List) unsafe.getObject(message, offset), + getMessageFieldSchema(i)); + break; + case 50: // MAP: + // TODO(dweis): Use schema cache. + size += + mapFieldSchema.getSerializedSize( + number, unsafe.getObject(message, offset), getMapFieldDefaultEntry(i)); + break; + case 51: // ONEOF_DOUBLE: + if (isOneofPresent(message, number, i)) { + size += CodedOutputStream.computeDoubleSize(number, 0); + } + break; + case 52: // ONEOF_FLOAT: + if (isOneofPresent(message, number, i)) { + size += CodedOutputStream.computeFloatSize(number, 0); + } + break; + case 53: // ONEOF_INT64: + if (isOneofPresent(message, number, i)) { + size += CodedOutputStream.computeInt64Size(number, oneofLongAt(message, offset)); + } + break; + case 54: // ONEOF_UINT64: + if (isOneofPresent(message, number, i)) { + size += CodedOutputStream.computeUInt64Size(number, oneofLongAt(message, offset)); + } + break; + case 55: // ONEOF_INT32: + if (isOneofPresent(message, number, i)) { + size += CodedOutputStream.computeInt32Size(number, oneofIntAt(message, offset)); + } + break; + case 56: // ONEOF_FIXED64: + if (isOneofPresent(message, number, i)) { + size += CodedOutputStream.computeFixed64Size(number, 0); + } + break; + case 57: // ONEOF_FIXED32: + if (isOneofPresent(message, number, i)) { + size += CodedOutputStream.computeFixed32Size(number, 0); + } + break; + case 58: // ONEOF_BOOL: + if (isOneofPresent(message, number, i)) { + size += CodedOutputStream.computeBoolSize(number, true); + } + break; + case 59: // ONEOF_STRING: + if (isOneofPresent(message, number, i)) { + Object value = unsafe.getObject(message, offset); + if (value instanceof ByteString) { + size += CodedOutputStream.computeBytesSize(number, (ByteString) value); + } else { + size += CodedOutputStream.computeStringSize(number, (String) value); + } + } + break; + case 60: // ONEOF_MESSAGE: + if (isOneofPresent(message, number, i)) { + Object value = unsafe.getObject(message, offset); + size += SchemaUtil.computeSizeMessage(number, value, getMessageFieldSchema(i)); + } + break; + case 61: // ONEOF_BYTES: + if (isOneofPresent(message, number, i)) { + size += + CodedOutputStream.computeBytesSize( + number, (ByteString) unsafe.getObject(message, offset)); + } + break; + case 62: // ONEOF_UINT32: + if (isOneofPresent(message, number, i)) { + size += CodedOutputStream.computeUInt32Size(number, oneofIntAt(message, offset)); + } + break; + case 63: // ONEOF_ENUM: + if (isOneofPresent(message, number, i)) { + size += CodedOutputStream.computeEnumSize(number, oneofIntAt(message, offset)); + } + break; + case 64: // ONEOF_SFIXED32: + if (isOneofPresent(message, number, i)) { + size += CodedOutputStream.computeSFixed32Size(number, 0); + } + break; + case 65: // ONEOF_SFIXED64: + if (isOneofPresent(message, number, i)) { + size += CodedOutputStream.computeSFixed64Size(number, 0); + } + break; + case 66: // ONEOF_SINT32: + if (isOneofPresent(message, number, i)) { + size += CodedOutputStream.computeSInt32Size(number, oneofIntAt(message, offset)); + } + break; + case 67: // ONEOF_SINT64: + if (isOneofPresent(message, number, i)) { + size += CodedOutputStream.computeSInt64Size(number, oneofLongAt(message, offset)); + } + break; + case 68: // ONEOF_GROUP: + if (isOneofPresent(message, number, i)) { + size += + CodedOutputStream.computeGroupSize( + number, + (MessageLite) unsafe.getObject(message, offset), + getMessageFieldSchema(i)); + } + break; + default: + // Assume it's an empty entry. + } + } + + size += getUnknownFieldsSerializedSize(unknownFieldSchema, message); + + if (hasExtensions) { + size += extensionSchema.getExtensions(message).getSerializedSize(); + } + + return size; + } + + private int getSerializedSizeProto3(T message) { + final sun.misc.Unsafe unsafe = UNSAFE; + int size = 0; + for (int i = 0; i < buffer.length; i += INTS_PER_FIELD) { + final int typeAndOffset = typeAndOffsetAt(i); + final int fieldType = type(typeAndOffset); + final int number = numberAt(i); + + final long offset = offset(typeAndOffset); + final int cachedSizeOffset = + fieldType >= FieldType.DOUBLE_LIST_PACKED.id() + && fieldType <= FieldType.SINT64_LIST_PACKED.id() + ? buffer[i + 2] & OFFSET_MASK + : 0; + + switch (fieldType) { + case 0: // DOUBLE: + if (isFieldPresent(message, i)) { + size += CodedOutputStream.computeDoubleSize(number, 0); + } + break; + case 1: // FLOAT: + if (isFieldPresent(message, i)) { + size += CodedOutputStream.computeFloatSize(number, 0); + } + break; + case 2: // INT64: + if (isFieldPresent(message, i)) { + size += CodedOutputStream.computeInt64Size(number, UnsafeUtil.getLong(message, offset)); + } + break; + case 3: // UINT64: + if (isFieldPresent(message, i)) { + size += + CodedOutputStream.computeUInt64Size(number, UnsafeUtil.getLong(message, offset)); + } + break; + case 4: // INT32: + if (isFieldPresent(message, i)) { + size += CodedOutputStream.computeInt32Size(number, UnsafeUtil.getInt(message, offset)); + } + break; + case 5: // FIXED64: + if (isFieldPresent(message, i)) { + size += CodedOutputStream.computeFixed64Size(number, 0); + } + break; + case 6: // FIXED32: + if (isFieldPresent(message, i)) { + size += CodedOutputStream.computeFixed32Size(number, 0); + } + break; + case 7: // BOOL: + if (isFieldPresent(message, i)) { + size += CodedOutputStream.computeBoolSize(number, true); + } + break; + case 8: // STRING: + if (isFieldPresent(message, i)) { + Object value = UnsafeUtil.getObject(message, offset); + if (value instanceof ByteString) { + size += CodedOutputStream.computeBytesSize(number, (ByteString) value); + } else { + size += CodedOutputStream.computeStringSize(number, (String) value); + } + } + break; + case 9: // MESSAGE: + if (isFieldPresent(message, i)) { + Object value = UnsafeUtil.getObject(message, offset); + size += SchemaUtil.computeSizeMessage(number, value, getMessageFieldSchema(i)); + } + break; + case 10: // BYTES: + if (isFieldPresent(message, i)) { + ByteString value = (ByteString) UnsafeUtil.getObject(message, offset); + size += CodedOutputStream.computeBytesSize(number, value); + } + break; + case 11: // UINT32: + if (isFieldPresent(message, i)) { + size += CodedOutputStream.computeUInt32Size(number, UnsafeUtil.getInt(message, offset)); + } + break; + case 12: // ENUM: + if (isFieldPresent(message, i)) { + size += CodedOutputStream.computeEnumSize(number, UnsafeUtil.getInt(message, offset)); + } + break; + case 13: // SFIXED32: + if (isFieldPresent(message, i)) { + size += CodedOutputStream.computeSFixed32Size(number, 0); + } + break; + case 14: // SFIXED64: + if (isFieldPresent(message, i)) { + size += CodedOutputStream.computeSFixed64Size(number, 0); + } + break; + case 15: // SINT32: + if (isFieldPresent(message, i)) { + size += CodedOutputStream.computeSInt32Size(number, UnsafeUtil.getInt(message, offset)); + } + break; + case 16: // SINT64: + if (isFieldPresent(message, i)) { + size += + CodedOutputStream.computeSInt64Size(number, UnsafeUtil.getLong(message, offset)); + } + break; + case 17: // GROUP: + if (isFieldPresent(message, i)) { + size += + CodedOutputStream.computeGroupSize( + number, + (MessageLite) UnsafeUtil.getObject(message, offset), + getMessageFieldSchema(i)); + } + break; + case 18: // DOUBLE_LIST: + size += SchemaUtil.computeSizeFixed64List(number, listAt(message, offset), false); + break; + case 19: // FLOAT_LIST: + size += SchemaUtil.computeSizeFixed32List(number, listAt(message, offset), false); + break; + case 20: // INT64_LIST: + size += + SchemaUtil.computeSizeInt64List(number, (List) listAt(message, offset), false); + break; + case 21: // UINT64_LIST: + size += + SchemaUtil.computeSizeUInt64List(number, (List) listAt(message, offset), false); + break; + case 22: // INT32_LIST: + size += + SchemaUtil.computeSizeInt32List( + number, (List) listAt(message, offset), false); + break; + case 23: // FIXED64_LIST: + size += SchemaUtil.computeSizeFixed64List(number, listAt(message, offset), false); + break; + case 24: // FIXED32_LIST: + size += SchemaUtil.computeSizeFixed32List(number, listAt(message, offset), false); + break; + case 25: // BOOL_LIST: + size += SchemaUtil.computeSizeBoolList(number, listAt(message, offset), false); + break; + case 26: // STRING_LIST: + size += SchemaUtil.computeSizeStringList(number, listAt(message, offset)); + break; + case 27: // MESSAGE_LIST: + size += + SchemaUtil.computeSizeMessageList( + number, listAt(message, offset), getMessageFieldSchema(i)); + break; + case 28: // BYTES_LIST: + size += + SchemaUtil.computeSizeByteStringList( + number, (List) listAt(message, offset)); + break; + case 29: // UINT32_LIST: + size += + SchemaUtil.computeSizeUInt32List( + number, (List) listAt(message, offset), false); + break; + case 30: // ENUM_LIST: + size += + SchemaUtil.computeSizeEnumList( + number, (List) listAt(message, offset), false); + break; + case 31: // SFIXED32_LIST: + size += SchemaUtil.computeSizeFixed32List(number, listAt(message, offset), false); + break; + case 32: // SFIXED64_LIST: + size += SchemaUtil.computeSizeFixed64List(number, listAt(message, offset), false); + break; + case 33: // SINT32_LIST: + size += + SchemaUtil.computeSizeSInt32List( + number, (List) listAt(message, offset), false); + break; + case 34: // SINT64_LIST: + size += + SchemaUtil.computeSizeSInt64List(number, (List) listAt(message, offset), false); + break; + case 35: + { // DOUBLE_LIST_PACKED: + int fieldSize = + SchemaUtil.computeSizeFixed64ListNoTag( + (List) unsafe.getObject(message, offset)); + if (fieldSize > 0) { + if (useCachedSizeField) { + unsafe.putInt(message, (long) cachedSizeOffset, fieldSize); + } + size += + CodedOutputStream.computeTagSize(number) + + CodedOutputStream.computeUInt32SizeNoTag(fieldSize) + + fieldSize; + } + break; + } + case 36: + { // FLOAT_LIST_PACKED: + int fieldSize = + SchemaUtil.computeSizeFixed32ListNoTag( + (List) unsafe.getObject(message, offset)); + if (fieldSize > 0) { + if (useCachedSizeField) { + unsafe.putInt(message, (long) cachedSizeOffset, fieldSize); + } + size += + CodedOutputStream.computeTagSize(number) + + CodedOutputStream.computeUInt32SizeNoTag(fieldSize) + + fieldSize; + } + break; + } + case 37: + { // INT64_LIST_PACKED: + int fieldSize = + SchemaUtil.computeSizeInt64ListNoTag( + (List) unsafe.getObject(message, offset)); + if (fieldSize > 0) { + if (useCachedSizeField) { + unsafe.putInt(message, (long) cachedSizeOffset, fieldSize); + } + size += + CodedOutputStream.computeTagSize(number) + + CodedOutputStream.computeUInt32SizeNoTag(fieldSize) + + fieldSize; + } + break; + } + case 38: + { // UINT64_LIST_PACKED: + int fieldSize = + SchemaUtil.computeSizeUInt64ListNoTag( + (List) unsafe.getObject(message, offset)); + if (fieldSize > 0) { + if (useCachedSizeField) { + unsafe.putInt(message, (long) cachedSizeOffset, fieldSize); + } + size += + CodedOutputStream.computeTagSize(number) + + CodedOutputStream.computeUInt32SizeNoTag(fieldSize) + + fieldSize; + } + break; + } + case 39: + { // INT32_LIST_PACKED: + int fieldSize = + SchemaUtil.computeSizeInt32ListNoTag( + (List) unsafe.getObject(message, offset)); + if (fieldSize > 0) { + if (useCachedSizeField) { + unsafe.putInt(message, (long) cachedSizeOffset, fieldSize); + } + size += + CodedOutputStream.computeTagSize(number) + + CodedOutputStream.computeUInt32SizeNoTag(fieldSize) + + fieldSize; + } + break; + } + case 40: + { // FIXED64_LIST_PACKED: + int fieldSize = + SchemaUtil.computeSizeFixed64ListNoTag( + (List) unsafe.getObject(message, offset)); + if (fieldSize > 0) { + if (useCachedSizeField) { + unsafe.putInt(message, (long) cachedSizeOffset, fieldSize); + } + size += + CodedOutputStream.computeTagSize(number) + + CodedOutputStream.computeUInt32SizeNoTag(fieldSize) + + fieldSize; + } + break; + } + case 41: + { // FIXED32_LIST_PACKED: + int fieldSize = + SchemaUtil.computeSizeFixed32ListNoTag( + (List) unsafe.getObject(message, offset)); + if (fieldSize > 0) { + if (useCachedSizeField) { + unsafe.putInt(message, (long) cachedSizeOffset, fieldSize); + } + size += + CodedOutputStream.computeTagSize(number) + + CodedOutputStream.computeUInt32SizeNoTag(fieldSize) + + fieldSize; + } + break; + } + case 42: + { // BOOL_LIST_PACKED: + int fieldSize = + SchemaUtil.computeSizeBoolListNoTag( + (List) unsafe.getObject(message, offset)); + if (fieldSize > 0) { + if (useCachedSizeField) { + unsafe.putInt(message, (long) cachedSizeOffset, fieldSize); + } + size += + CodedOutputStream.computeTagSize(number) + + CodedOutputStream.computeUInt32SizeNoTag(fieldSize) + + fieldSize; + } + break; + } + case 43: + { // UINT32_LIST_PACKED: + int fieldSize = + SchemaUtil.computeSizeUInt32ListNoTag( + (List) unsafe.getObject(message, offset)); + if (fieldSize > 0) { + if (useCachedSizeField) { + unsafe.putInt(message, (long) cachedSizeOffset, fieldSize); + } + size += + CodedOutputStream.computeTagSize(number) + + CodedOutputStream.computeUInt32SizeNoTag(fieldSize) + + fieldSize; + } + break; + } + case 44: + { // ENUM_LIST_PACKED: + int fieldSize = + SchemaUtil.computeSizeEnumListNoTag( + (List) unsafe.getObject(message, offset)); + if (fieldSize > 0) { + if (useCachedSizeField) { + unsafe.putInt(message, (long) cachedSizeOffset, fieldSize); + } + size += + CodedOutputStream.computeTagSize(number) + + CodedOutputStream.computeUInt32SizeNoTag(fieldSize) + + fieldSize; + } + break; + } + case 45: + { // SFIXED32_LIST_PACKED: + int fieldSize = + SchemaUtil.computeSizeFixed32ListNoTag( + (List) unsafe.getObject(message, offset)); + if (fieldSize > 0) { + if (useCachedSizeField) { + unsafe.putInt(message, (long) cachedSizeOffset, fieldSize); + } + size += + CodedOutputStream.computeTagSize(number) + + CodedOutputStream.computeUInt32SizeNoTag(fieldSize) + + fieldSize; + } + break; + } + case 46: + { // SFIXED64_LIST_PACKED: + int fieldSize = + SchemaUtil.computeSizeFixed64ListNoTag( + (List) unsafe.getObject(message, offset)); + if (fieldSize > 0) { + if (useCachedSizeField) { + unsafe.putInt(message, (long) cachedSizeOffset, fieldSize); + } + size += + CodedOutputStream.computeTagSize(number) + + CodedOutputStream.computeUInt32SizeNoTag(fieldSize) + + fieldSize; + } + break; + } + case 47: + { // SINT32_LIST_PACKED: + int fieldSize = + SchemaUtil.computeSizeSInt32ListNoTag( + (List) unsafe.getObject(message, offset)); + if (fieldSize > 0) { + if (useCachedSizeField) { + unsafe.putInt(message, (long) cachedSizeOffset, fieldSize); + } + size += + CodedOutputStream.computeTagSize(number) + + CodedOutputStream.computeUInt32SizeNoTag(fieldSize) + + fieldSize; + } + break; + } + case 48: + { // SINT64_LIST_PACKED: + int fieldSize = + SchemaUtil.computeSizeSInt64ListNoTag( + (List) unsafe.getObject(message, offset)); + if (fieldSize > 0) { + if (useCachedSizeField) { + unsafe.putInt(message, (long) cachedSizeOffset, fieldSize); + } + size += + CodedOutputStream.computeTagSize(number) + + CodedOutputStream.computeUInt32SizeNoTag(fieldSize) + + fieldSize; + } + break; + } + case 49: // GROUP_LIST: + size += + SchemaUtil.computeSizeGroupList( + number, (List) listAt(message, offset), getMessageFieldSchema(i)); + break; + case 50: // MAP: + // TODO(dweis): Use schema cache. + size += + mapFieldSchema.getSerializedSize( + number, UnsafeUtil.getObject(message, offset), getMapFieldDefaultEntry(i)); + break; + case 51: // ONEOF_DOUBLE: + if (isOneofPresent(message, number, i)) { + size += CodedOutputStream.computeDoubleSize(number, 0); + } + break; + case 52: // ONEOF_FLOAT: + if (isOneofPresent(message, number, i)) { + size += CodedOutputStream.computeFloatSize(number, 0); + } + break; + case 53: // ONEOF_INT64: + if (isOneofPresent(message, number, i)) { + size += CodedOutputStream.computeInt64Size(number, oneofLongAt(message, offset)); + } + break; + case 54: // ONEOF_UINT64: + if (isOneofPresent(message, number, i)) { + size += CodedOutputStream.computeUInt64Size(number, oneofLongAt(message, offset)); + } + break; + case 55: // ONEOF_INT32: + if (isOneofPresent(message, number, i)) { + size += CodedOutputStream.computeInt32Size(number, oneofIntAt(message, offset)); + } + break; + case 56: // ONEOF_FIXED64: + if (isOneofPresent(message, number, i)) { + size += CodedOutputStream.computeFixed64Size(number, 0); + } + break; + case 57: // ONEOF_FIXED32: + if (isOneofPresent(message, number, i)) { + size += CodedOutputStream.computeFixed32Size(number, 0); + } + break; + case 58: // ONEOF_BOOL: + if (isOneofPresent(message, number, i)) { + size += CodedOutputStream.computeBoolSize(number, true); + } + break; + case 59: // ONEOF_STRING: + if (isOneofPresent(message, number, i)) { + Object value = UnsafeUtil.getObject(message, offset); + if (value instanceof ByteString) { + size += CodedOutputStream.computeBytesSize(number, (ByteString) value); + } else { + size += CodedOutputStream.computeStringSize(number, (String) value); + } + } + break; + case 60: // ONEOF_MESSAGE: + if (isOneofPresent(message, number, i)) { + Object value = UnsafeUtil.getObject(message, offset); + size += SchemaUtil.computeSizeMessage(number, value, getMessageFieldSchema(i)); + } + break; + case 61: // ONEOF_BYTES: + if (isOneofPresent(message, number, i)) { + size += + CodedOutputStream.computeBytesSize( + number, (ByteString) UnsafeUtil.getObject(message, offset)); + } + break; + case 62: // ONEOF_UINT32: + if (isOneofPresent(message, number, i)) { + size += CodedOutputStream.computeUInt32Size(number, oneofIntAt(message, offset)); + } + break; + case 63: // ONEOF_ENUM: + if (isOneofPresent(message, number, i)) { + size += CodedOutputStream.computeEnumSize(number, oneofIntAt(message, offset)); + } + break; + case 64: // ONEOF_SFIXED32: + if (isOneofPresent(message, number, i)) { + size += CodedOutputStream.computeSFixed32Size(number, 0); + } + break; + case 65: // ONEOF_SFIXED64: + if (isOneofPresent(message, number, i)) { + size += CodedOutputStream.computeSFixed64Size(number, 0); + } + break; + case 66: // ONEOF_SINT32: + if (isOneofPresent(message, number, i)) { + size += CodedOutputStream.computeSInt32Size(number, oneofIntAt(message, offset)); + } + break; + case 67: // ONEOF_SINT64: + if (isOneofPresent(message, number, i)) { + size += CodedOutputStream.computeSInt64Size(number, oneofLongAt(message, offset)); + } + break; + case 68: // ONEOF_GROUP: + if (isOneofPresent(message, number, i)) { + size += + CodedOutputStream.computeGroupSize( + number, + (MessageLite) UnsafeUtil.getObject(message, offset), + getMessageFieldSchema(i)); + } + break; + default: + // Assume it's an empty entry. + } + } + + size += getUnknownFieldsSerializedSize(unknownFieldSchema, message); + + return size; + } + + private int getUnknownFieldsSerializedSize( + UnknownFieldSchema schema, T message) { + UT unknowns = schema.getFromMessage(message); + return schema.getSerializedSize(unknowns); + } + + private static List listAt(Object message, long offset) { + return (List) UnsafeUtil.getObject(message, offset); + } + + @SuppressWarnings("unchecked") + @Override + // TODO(nathanmittler): Consider serializing oneof fields last so that only one entry per + // oneof is actually serialized. This would mean that we would violate the serialization order + // contract. It should also be noted that Go currently does this. + public void writeTo(T message, Writer writer) throws IOException { + if (writer.fieldOrder() == Writer.FieldOrder.DESCENDING) { + writeFieldsInDescendingOrder(message, writer); + } else { + if (proto3) { + writeFieldsInAscendingOrderProto3(message, writer); + } else { + writeFieldsInAscendingOrderProto2(message, writer); + } + } + } + + @SuppressWarnings("unchecked") + private void writeFieldsInAscendingOrderProto2(T message, Writer writer) throws IOException { + Iterator> extensionIterator = null; + Map.Entry nextExtension = null; + if (hasExtensions) { + FieldSet extensions = extensionSchema.getExtensions(message); + if (!extensions.isEmpty()) { + extensionIterator = extensions.iterator(); + nextExtension = extensionIterator.next(); + } + } + int currentPresenceFieldOffset = NO_PRESENCE_SENTINEL; + int currentPresenceField = 0; + final int bufferLength = buffer.length; + final sun.misc.Unsafe unsafe = UNSAFE; + for (int pos = 0; pos < bufferLength; pos += INTS_PER_FIELD) { + final int typeAndOffset = typeAndOffsetAt(pos); + final int number = numberAt(pos); + final int fieldType = type(typeAndOffset); + + int presenceMaskAndOffset = 0; + int presenceMask = 0; + if (fieldType <= 17) { + presenceMaskAndOffset = buffer[pos + 2]; + final int presenceFieldOffset = presenceMaskAndOffset & OFFSET_MASK; + if (presenceFieldOffset != currentPresenceFieldOffset) { + currentPresenceFieldOffset = presenceFieldOffset; + currentPresenceField = unsafe.getInt(message, (long) presenceFieldOffset); + } + presenceMask = 1 << (presenceMaskAndOffset >>> OFFSET_BITS); + } + + // Write any extensions that need to be written before the current field. + while (nextExtension != null && extensionSchema.extensionNumber(nextExtension) <= number) { + extensionSchema.serializeExtension(writer, nextExtension); + nextExtension = extensionIterator.hasNext() ? extensionIterator.next() : null; + } + final long offset = offset(typeAndOffset); + + switch (fieldType) { + case 0: // DOUBLE: + if ((currentPresenceField & presenceMask) != 0) { + writer.writeDouble(number, doubleAt(message, offset)); + } + break; + case 1: // FLOAT: + if ((currentPresenceField & presenceMask) != 0) { + writer.writeFloat(number, floatAt(message, offset)); + } + break; + case 2: // INT64: + if ((currentPresenceField & presenceMask) != 0) { + writer.writeInt64(number, unsafe.getLong(message, offset)); + } + break; + case 3: // UINT64: + if ((currentPresenceField & presenceMask) != 0) { + writer.writeUInt64(number, unsafe.getLong(message, offset)); + } + break; + case 4: // INT32: + if ((currentPresenceField & presenceMask) != 0) { + writer.writeInt32(number, unsafe.getInt(message, offset)); + } + break; + case 5: // FIXED64: + if ((currentPresenceField & presenceMask) != 0) { + writer.writeFixed64(number, unsafe.getLong(message, offset)); + } + break; + case 6: // FIXED32: + if ((currentPresenceField & presenceMask) != 0) { + writer.writeFixed32(number, unsafe.getInt(message, offset)); + } + break; + case 7: // BOOL: + if ((currentPresenceField & presenceMask) != 0) { + writer.writeBool(number, booleanAt(message, offset)); + } + break; + case 8: // STRING: + if ((currentPresenceField & presenceMask) != 0) { + writeString(number, unsafe.getObject(message, offset), writer); + } + break; + case 9: // MESSAGE: + if ((currentPresenceField & presenceMask) != 0) { + Object value = unsafe.getObject(message, offset); + writer.writeMessage(number, value, getMessageFieldSchema(pos)); + } + break; + case 10: // BYTES: + if ((currentPresenceField & presenceMask) != 0) { + writer.writeBytes(number, (ByteString) unsafe.getObject(message, offset)); + } + break; + case 11: // UINT32: + if ((currentPresenceField & presenceMask) != 0) { + writer.writeUInt32(number, unsafe.getInt(message, offset)); + } + break; + case 12: // ENUM: + if ((currentPresenceField & presenceMask) != 0) { + writer.writeEnum(number, unsafe.getInt(message, offset)); + } + break; + case 13: // SFIXED32: + if ((currentPresenceField & presenceMask) != 0) { + writer.writeSFixed32(number, unsafe.getInt(message, offset)); + } + break; + case 14: // SFIXED64: + if ((currentPresenceField & presenceMask) != 0) { + writer.writeSFixed64(number, unsafe.getLong(message, offset)); + } + break; + case 15: // SINT32: + if ((currentPresenceField & presenceMask) != 0) { + writer.writeSInt32(number, unsafe.getInt(message, offset)); + } + break; + case 16: // SINT64: + if ((currentPresenceField & presenceMask) != 0) { + writer.writeSInt64(number, unsafe.getLong(message, offset)); + } + break; + case 17: // GROUP: + if ((currentPresenceField & presenceMask) != 0) { + writer.writeGroup( + number, unsafe.getObject(message, offset), getMessageFieldSchema(pos)); + } + break; + case 18: // DOUBLE_LIST: + SchemaUtil.writeDoubleList( + numberAt(pos), (List) unsafe.getObject(message, offset), writer, false); + break; + case 19: // FLOAT_LIST: + SchemaUtil.writeFloatList( + numberAt(pos), (List) unsafe.getObject(message, offset), writer, false); + break; + case 20: // INT64_LIST: + SchemaUtil.writeInt64List( + numberAt(pos), (List) unsafe.getObject(message, offset), writer, false); + break; + case 21: // UINT64_LIST: + SchemaUtil.writeUInt64List( + numberAt(pos), (List) unsafe.getObject(message, offset), writer, false); + break; + case 22: // INT32_LIST: + SchemaUtil.writeInt32List( + numberAt(pos), (List) unsafe.getObject(message, offset), writer, false); + break; + case 23: // FIXED64_LIST: + SchemaUtil.writeFixed64List( + numberAt(pos), (List) unsafe.getObject(message, offset), writer, false); + break; + case 24: // FIXED32_LIST: + SchemaUtil.writeFixed32List( + numberAt(pos), (List) unsafe.getObject(message, offset), writer, false); + break; + case 25: // BOOL_LIST: + SchemaUtil.writeBoolList( + numberAt(pos), (List) unsafe.getObject(message, offset), writer, false); + break; + case 26: // STRING_LIST: + SchemaUtil.writeStringList( + numberAt(pos), (List) unsafe.getObject(message, offset), writer); + break; + case 27: // MESSAGE_LIST: + SchemaUtil.writeMessageList( + numberAt(pos), + (List) unsafe.getObject(message, offset), + writer, + getMessageFieldSchema(pos)); + break; + case 28: // BYTES_LIST: + SchemaUtil.writeBytesList( + numberAt(pos), (List) unsafe.getObject(message, offset), writer); + break; + case 29: // UINT32_LIST: + SchemaUtil.writeUInt32List( + numberAt(pos), (List) unsafe.getObject(message, offset), writer, false); + break; + case 30: // ENUM_LIST: + SchemaUtil.writeEnumList( + numberAt(pos), (List) unsafe.getObject(message, offset), writer, false); + break; + case 31: // SFIXED32_LIST: + SchemaUtil.writeSFixed32List( + numberAt(pos), (List) unsafe.getObject(message, offset), writer, false); + break; + case 32: // SFIXED64_LIST: + SchemaUtil.writeSFixed64List( + numberAt(pos), (List) unsafe.getObject(message, offset), writer, false); + break; + case 33: // SINT32_LIST: + SchemaUtil.writeSInt32List( + numberAt(pos), (List) unsafe.getObject(message, offset), writer, false); + break; + case 34: // SINT64_LIST: + SchemaUtil.writeSInt64List( + numberAt(pos), (List) unsafe.getObject(message, offset), writer, false); + break; + case 35: // DOUBLE_LIST_PACKED: + // TODO(xiaofeng): Make use of cached field size to speed up serialization. + SchemaUtil.writeDoubleList( + numberAt(pos), (List) unsafe.getObject(message, offset), writer, true); + break; + case 36: // FLOAT_LIST_PACKED: + SchemaUtil.writeFloatList( + numberAt(pos), (List) unsafe.getObject(message, offset), writer, true); + break; + case 37: // INT64_LIST_PACKED: + SchemaUtil.writeInt64List( + numberAt(pos), (List) unsafe.getObject(message, offset), writer, true); + break; + case 38: // UINT64_LIST_PACKED: + SchemaUtil.writeUInt64List( + numberAt(pos), (List) unsafe.getObject(message, offset), writer, true); + break; + case 39: // INT32_LIST_PACKED: + SchemaUtil.writeInt32List( + numberAt(pos), (List) unsafe.getObject(message, offset), writer, true); + break; + case 40: // FIXED64_LIST_PACKED: + SchemaUtil.writeFixed64List( + numberAt(pos), (List) unsafe.getObject(message, offset), writer, true); + break; + case 41: // FIXED32_LIST_PACKED: + SchemaUtil.writeFixed32List( + numberAt(pos), (List) unsafe.getObject(message, offset), writer, true); + + break; + case 42: // BOOL_LIST_PACKED: + SchemaUtil.writeBoolList( + numberAt(pos), (List) unsafe.getObject(message, offset), writer, true); + break; + case 43: // UINT32_LIST_PACKED: + SchemaUtil.writeUInt32List( + numberAt(pos), (List) unsafe.getObject(message, offset), writer, true); + break; + case 44: // ENUM_LIST_PACKED: + SchemaUtil.writeEnumList( + numberAt(pos), (List) unsafe.getObject(message, offset), writer, true); + break; + case 45: // SFIXED32_LIST_PACKED: + SchemaUtil.writeSFixed32List( + numberAt(pos), (List) unsafe.getObject(message, offset), writer, true); + break; + case 46: // SFIXED64_LIST_PACKED: + SchemaUtil.writeSFixed64List( + numberAt(pos), (List) unsafe.getObject(message, offset), writer, true); + break; + case 47: // SINT32_LIST_PACKED: + SchemaUtil.writeSInt32List( + numberAt(pos), (List) unsafe.getObject(message, offset), writer, true); + break; + case 48: // SINT64_LIST_PACKED: + SchemaUtil.writeSInt64List( + numberAt(pos), (List) unsafe.getObject(message, offset), writer, true); + break; + case 49: // GROUP_LIST: + SchemaUtil.writeGroupList( + numberAt(pos), + (List) unsafe.getObject(message, offset), + writer, + getMessageFieldSchema(pos)); + break; + case 50: // MAP: + // TODO(dweis): Use schema cache. + writeMapHelper(writer, number, unsafe.getObject(message, offset), pos); + break; + case 51: // ONEOF_DOUBLE: + if (isOneofPresent(message, number, pos)) { + writer.writeDouble(number, oneofDoubleAt(message, offset)); + } + break; + case 52: // ONEOF_FLOAT: + if (isOneofPresent(message, number, pos)) { + writer.writeFloat(number, oneofFloatAt(message, offset)); + } + break; + case 53: // ONEOF_INT64: + if (isOneofPresent(message, number, pos)) { + writer.writeInt64(number, oneofLongAt(message, offset)); + } + break; + case 54: // ONEOF_UINT64: + if (isOneofPresent(message, number, pos)) { + writer.writeUInt64(number, oneofLongAt(message, offset)); + } + break; + case 55: // ONEOF_INT32: + if (isOneofPresent(message, number, pos)) { + writer.writeInt32(number, oneofIntAt(message, offset)); + } + break; + case 56: // ONEOF_FIXED64: + if (isOneofPresent(message, number, pos)) { + writer.writeFixed64(number, oneofLongAt(message, offset)); + } + break; + case 57: // ONEOF_FIXED32: + if (isOneofPresent(message, number, pos)) { + writer.writeFixed32(number, oneofIntAt(message, offset)); + } + break; + case 58: // ONEOF_BOOL: + if (isOneofPresent(message, number, pos)) { + writer.writeBool(number, oneofBooleanAt(message, offset)); + } + break; + case 59: // ONEOF_STRING: + if (isOneofPresent(message, number, pos)) { + writeString(number, unsafe.getObject(message, offset), writer); + } + break; + case 60: // ONEOF_MESSAGE: + if (isOneofPresent(message, number, pos)) { + Object value = unsafe.getObject(message, offset); + writer.writeMessage(number, value, getMessageFieldSchema(pos)); + } + break; + case 61: // ONEOF_BYTES: + if (isOneofPresent(message, number, pos)) { + writer.writeBytes(number, (ByteString) unsafe.getObject(message, offset)); + } + break; + case 62: // ONEOF_UINT32: + if (isOneofPresent(message, number, pos)) { + writer.writeUInt32(number, oneofIntAt(message, offset)); + } + break; + case 63: // ONEOF_ENUM: + if (isOneofPresent(message, number, pos)) { + writer.writeEnum(number, oneofIntAt(message, offset)); + } + break; + case 64: // ONEOF_SFIXED32: + if (isOneofPresent(message, number, pos)) { + writer.writeSFixed32(number, oneofIntAt(message, offset)); + } + break; + case 65: // ONEOF_SFIXED64: + if (isOneofPresent(message, number, pos)) { + writer.writeSFixed64(number, oneofLongAt(message, offset)); + } + break; + case 66: // ONEOF_SINT32: + if (isOneofPresent(message, number, pos)) { + writer.writeSInt32(number, oneofIntAt(message, offset)); + } + break; + case 67: // ONEOF_SINT64: + if (isOneofPresent(message, number, pos)) { + writer.writeSInt64(number, oneofLongAt(message, offset)); + } + break; + case 68: // ONEOF_GROUP: + if (isOneofPresent(message, number, pos)) { + writer.writeGroup( + number, unsafe.getObject(message, offset), getMessageFieldSchema(pos)); + } + break; + default: + // Assume it's an empty entry - just go to the next entry. + break; + } + } + while (nextExtension != null) { + extensionSchema.serializeExtension(writer, nextExtension); + nextExtension = extensionIterator.hasNext() ? extensionIterator.next() : null; + } + writeUnknownInMessageTo(unknownFieldSchema, message, writer); + } + + @SuppressWarnings("unchecked") + private void writeFieldsInAscendingOrderProto3(T message, Writer writer) throws IOException { + Iterator> extensionIterator = null; + Map.Entry nextExtension = null; + if (hasExtensions) { + FieldSet extensions = extensionSchema.getExtensions(message); + if (!extensions.isEmpty()) { + extensionIterator = extensions.iterator(); + nextExtension = extensionIterator.next(); + } + } + final int bufferLength = buffer.length; + for (int pos = 0; pos < bufferLength; pos += INTS_PER_FIELD) { + final int typeAndOffset = typeAndOffsetAt(pos); + final int number = numberAt(pos); + + // Write any extensions that need to be written before the current field. + while (nextExtension != null && extensionSchema.extensionNumber(nextExtension) <= number) { + extensionSchema.serializeExtension(writer, nextExtension); + nextExtension = extensionIterator.hasNext() ? extensionIterator.next() : null; + } + + switch (type(typeAndOffset)) { + case 0: // DOUBLE: + if (isFieldPresent(message, pos)) { + writer.writeDouble(number, doubleAt(message, offset(typeAndOffset))); + } + break; + case 1: // FLOAT: + if (isFieldPresent(message, pos)) { + writer.writeFloat(number, floatAt(message, offset(typeAndOffset))); + } + break; + case 2: // INT64: + if (isFieldPresent(message, pos)) { + writer.writeInt64(number, longAt(message, offset(typeAndOffset))); + } + break; + case 3: // UINT64: + if (isFieldPresent(message, pos)) { + writer.writeUInt64(number, longAt(message, offset(typeAndOffset))); + } + break; + case 4: // INT32: + if (isFieldPresent(message, pos)) { + writer.writeInt32(number, intAt(message, offset(typeAndOffset))); + } + break; + case 5: // FIXED64: + if (isFieldPresent(message, pos)) { + writer.writeFixed64(number, longAt(message, offset(typeAndOffset))); + } + break; + case 6: // FIXED32: + if (isFieldPresent(message, pos)) { + writer.writeFixed32(number, intAt(message, offset(typeAndOffset))); + } + break; + case 7: // BOOL: + if (isFieldPresent(message, pos)) { + writer.writeBool(number, booleanAt(message, offset(typeAndOffset))); + } + break; + case 8: // STRING: + if (isFieldPresent(message, pos)) { + writeString(number, UnsafeUtil.getObject(message, offset(typeAndOffset)), writer); + } + break; + case 9: // MESSAGE: + if (isFieldPresent(message, pos)) { + Object value = UnsafeUtil.getObject(message, offset(typeAndOffset)); + writer.writeMessage(number, value, getMessageFieldSchema(pos)); + } + break; + case 10: // BYTES: + if (isFieldPresent(message, pos)) { + writer.writeBytes( + number, (ByteString) UnsafeUtil.getObject(message, offset(typeAndOffset))); + } + break; + case 11: // UINT32: + if (isFieldPresent(message, pos)) { + writer.writeUInt32(number, intAt(message, offset(typeAndOffset))); + } + break; + case 12: // ENUM: + if (isFieldPresent(message, pos)) { + writer.writeEnum(number, intAt(message, offset(typeAndOffset))); + } + break; + case 13: // SFIXED32: + if (isFieldPresent(message, pos)) { + writer.writeSFixed32(number, intAt(message, offset(typeAndOffset))); + } + break; + case 14: // SFIXED64: + if (isFieldPresent(message, pos)) { + writer.writeSFixed64(number, longAt(message, offset(typeAndOffset))); + } + break; + case 15: // SINT32: + if (isFieldPresent(message, pos)) { + writer.writeSInt32(number, intAt(message, offset(typeAndOffset))); + } + break; + case 16: // SINT64: + if (isFieldPresent(message, pos)) { + writer.writeSInt64(number, longAt(message, offset(typeAndOffset))); + } + break; + case 17: // GROUP: + if (isFieldPresent(message, pos)) { + writer.writeGroup( + number, + UnsafeUtil.getObject(message, offset(typeAndOffset)), + getMessageFieldSchema(pos)); + } + break; + case 18: // DOUBLE_LIST: + SchemaUtil.writeDoubleList( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + false); + break; + case 19: // FLOAT_LIST: + SchemaUtil.writeFloatList( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + false); + break; + case 20: // INT64_LIST: + SchemaUtil.writeInt64List( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + false); + break; + case 21: // UINT64_LIST: + SchemaUtil.writeUInt64List( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + false); + break; + case 22: // INT32_LIST: + SchemaUtil.writeInt32List( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + false); + break; + case 23: // FIXED64_LIST: + SchemaUtil.writeFixed64List( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + false); + break; + case 24: // FIXED32_LIST: + SchemaUtil.writeFixed32List( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + false); + break; + case 25: // BOOL_LIST: + SchemaUtil.writeBoolList( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + false); + break; + case 26: // STRING_LIST: + SchemaUtil.writeStringList( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer); + break; + case 27: // MESSAGE_LIST: + SchemaUtil.writeMessageList( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + getMessageFieldSchema(pos)); + break; + case 28: // BYTES_LIST: + SchemaUtil.writeBytesList( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer); + break; + case 29: // UINT32_LIST: + SchemaUtil.writeUInt32List( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + false); + break; + case 30: // ENUM_LIST: + SchemaUtil.writeEnumList( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + false); + break; + case 31: // SFIXED32_LIST: + SchemaUtil.writeSFixed32List( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + false); + break; + case 32: // SFIXED64_LIST: + SchemaUtil.writeSFixed64List( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + false); + break; + case 33: // SINT32_LIST: + SchemaUtil.writeSInt32List( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + false); + break; + case 34: // SINT64_LIST: + SchemaUtil.writeSInt64List( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + false); + break; + case 35: // DOUBLE_LIST_PACKED: + // TODO(xiaofeng): Make use of cached field size to speed up serialization. + SchemaUtil.writeDoubleList( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + true); + break; + case 36: // FLOAT_LIST_PACKED: + SchemaUtil.writeFloatList( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + true); + break; + case 37: // INT64_LIST_PACKED: + SchemaUtil.writeInt64List( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + true); + break; + case 38: // UINT64_LIST_PACKED: + SchemaUtil.writeUInt64List( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + true); + break; + case 39: // INT32_LIST_PACKED: + SchemaUtil.writeInt32List( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + true); + break; + case 40: // FIXED64_LIST_PACKED: + SchemaUtil.writeFixed64List( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + true); + break; + case 41: // FIXED32_LIST_PACKED: + SchemaUtil.writeFixed32List( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + true); + + break; + case 42: // BOOL_LIST_PACKED: + SchemaUtil.writeBoolList( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + true); + break; + case 43: // UINT32_LIST_PACKED: + SchemaUtil.writeUInt32List( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + true); + break; + case 44: // ENUM_LIST_PACKED: + SchemaUtil.writeEnumList( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + true); + break; + case 45: // SFIXED32_LIST_PACKED: + SchemaUtil.writeSFixed32List( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + true); + break; + case 46: // SFIXED64_LIST_PACKED: + SchemaUtil.writeSFixed64List( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + true); + break; + case 47: // SINT32_LIST_PACKED: + SchemaUtil.writeSInt32List( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + true); + break; + case 48: // SINT64_LIST_PACKED: + SchemaUtil.writeSInt64List( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + true); + break; + case 49: // GROUP_LIST: + SchemaUtil.writeGroupList( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + getMessageFieldSchema(pos)); + break; + case 50: // MAP: + // TODO(dweis): Use schema cache. + writeMapHelper(writer, number, UnsafeUtil.getObject(message, offset(typeAndOffset)), pos); + break; + case 51: // ONEOF_DOUBLE: + if (isOneofPresent(message, number, pos)) { + writer.writeDouble(number, oneofDoubleAt(message, offset(typeAndOffset))); + } + break; + case 52: // ONEOF_FLOAT: + if (isOneofPresent(message, number, pos)) { + writer.writeFloat(number, oneofFloatAt(message, offset(typeAndOffset))); + } + break; + case 53: // ONEOF_INT64: + if (isOneofPresent(message, number, pos)) { + writer.writeInt64(number, oneofLongAt(message, offset(typeAndOffset))); + } + break; + case 54: // ONEOF_UINT64: + if (isOneofPresent(message, number, pos)) { + writer.writeUInt64(number, oneofLongAt(message, offset(typeAndOffset))); + } + break; + case 55: // ONEOF_INT32: + if (isOneofPresent(message, number, pos)) { + writer.writeInt32(number, oneofIntAt(message, offset(typeAndOffset))); + } + break; + case 56: // ONEOF_FIXED64: + if (isOneofPresent(message, number, pos)) { + writer.writeFixed64(number, oneofLongAt(message, offset(typeAndOffset))); + } + break; + case 57: // ONEOF_FIXED32: + if (isOneofPresent(message, number, pos)) { + writer.writeFixed32(number, oneofIntAt(message, offset(typeAndOffset))); + } + break; + case 58: // ONEOF_BOOL: + if (isOneofPresent(message, number, pos)) { + writer.writeBool(number, oneofBooleanAt(message, offset(typeAndOffset))); + } + break; + case 59: // ONEOF_STRING: + if (isOneofPresent(message, number, pos)) { + writeString(number, UnsafeUtil.getObject(message, offset(typeAndOffset)), writer); + } + break; + case 60: // ONEOF_MESSAGE: + if (isOneofPresent(message, number, pos)) { + Object value = UnsafeUtil.getObject(message, offset(typeAndOffset)); + writer.writeMessage(number, value, getMessageFieldSchema(pos)); + } + break; + case 61: // ONEOF_BYTES: + if (isOneofPresent(message, number, pos)) { + writer.writeBytes( + number, (ByteString) UnsafeUtil.getObject(message, offset(typeAndOffset))); + } + break; + case 62: // ONEOF_UINT32: + if (isOneofPresent(message, number, pos)) { + writer.writeUInt32(number, oneofIntAt(message, offset(typeAndOffset))); + } + break; + case 63: // ONEOF_ENUM: + if (isOneofPresent(message, number, pos)) { + writer.writeEnum(number, oneofIntAt(message, offset(typeAndOffset))); + } + break; + case 64: // ONEOF_SFIXED32: + if (isOneofPresent(message, number, pos)) { + writer.writeSFixed32(number, oneofIntAt(message, offset(typeAndOffset))); + } + break; + case 65: // ONEOF_SFIXED64: + if (isOneofPresent(message, number, pos)) { + writer.writeSFixed64(number, oneofLongAt(message, offset(typeAndOffset))); + } + break; + case 66: // ONEOF_SINT32: + if (isOneofPresent(message, number, pos)) { + writer.writeSInt32(number, oneofIntAt(message, offset(typeAndOffset))); + } + break; + case 67: // ONEOF_SINT64: + if (isOneofPresent(message, number, pos)) { + writer.writeSInt64(number, oneofLongAt(message, offset(typeAndOffset))); + } + break; + case 68: // ONEOF_GROUP: + if (isOneofPresent(message, number, pos)) { + writer.writeGroup( + number, + UnsafeUtil.getObject(message, offset(typeAndOffset)), + getMessageFieldSchema(pos)); + } + break; + default: + // Assume it's an empty entry - just go to the next entry. + break; + } + } + while (nextExtension != null) { + extensionSchema.serializeExtension(writer, nextExtension); + nextExtension = extensionIterator.hasNext() ? extensionIterator.next() : null; + } + writeUnknownInMessageTo(unknownFieldSchema, message, writer); + } + + @SuppressWarnings("unchecked") + private void writeFieldsInDescendingOrder(T message, Writer writer) throws IOException { + writeUnknownInMessageTo(unknownFieldSchema, message, writer); + + Iterator> extensionIterator = null; + Map.Entry nextExtension = null; + if (hasExtensions) { + FieldSet extensions = extensionSchema.getExtensions(message); + if (!extensions.isEmpty()) { + extensionIterator = extensions.descendingIterator(); + nextExtension = extensionIterator.next(); + } + } + + for (int pos = buffer.length - INTS_PER_FIELD; pos >= 0; pos -= INTS_PER_FIELD) { + final int typeAndOffset = typeAndOffsetAt(pos); + final int number = numberAt(pos); + + // Write any extensions that need to be written before the current field. + while (nextExtension != null && extensionSchema.extensionNumber(nextExtension) > number) { + extensionSchema.serializeExtension(writer, nextExtension); + nextExtension = extensionIterator.hasNext() ? extensionIterator.next() : null; + } + + switch (type(typeAndOffset)) { + case 0: // DOUBLE: + if (isFieldPresent(message, pos)) { + writer.writeDouble(number, doubleAt(message, offset(typeAndOffset))); + } + break; + case 1: // FLOAT: + if (isFieldPresent(message, pos)) { + writer.writeFloat(number, floatAt(message, offset(typeAndOffset))); + } + break; + case 2: // INT64: + if (isFieldPresent(message, pos)) { + writer.writeInt64(number, longAt(message, offset(typeAndOffset))); + } + break; + case 3: // UINT64: + if (isFieldPresent(message, pos)) { + writer.writeUInt64(number, longAt(message, offset(typeAndOffset))); + } + break; + case 4: // INT32: + if (isFieldPresent(message, pos)) { + writer.writeInt32(number, intAt(message, offset(typeAndOffset))); + } + break; + case 5: // FIXED64: + if (isFieldPresent(message, pos)) { + writer.writeFixed64(number, longAt(message, offset(typeAndOffset))); + } + break; + case 6: // FIXED32: + if (isFieldPresent(message, pos)) { + writer.writeFixed32(number, intAt(message, offset(typeAndOffset))); + } + break; + case 7: // BOOL: + if (isFieldPresent(message, pos)) { + writer.writeBool(number, booleanAt(message, offset(typeAndOffset))); + } + break; + case 8: // STRING: + if (isFieldPresent(message, pos)) { + writeString(number, UnsafeUtil.getObject(message, offset(typeAndOffset)), writer); + } + break; + case 9: // MESSAGE: + if (isFieldPresent(message, pos)) { + Object value = UnsafeUtil.getObject(message, offset(typeAndOffset)); + writer.writeMessage(number, value, getMessageFieldSchema(pos)); + } + break; + case 10: // BYTES: + if (isFieldPresent(message, pos)) { + writer.writeBytes( + number, (ByteString) UnsafeUtil.getObject(message, offset(typeAndOffset))); + } + break; + case 11: // UINT32: + if (isFieldPresent(message, pos)) { + writer.writeUInt32(number, intAt(message, offset(typeAndOffset))); + } + break; + case 12: // ENUM: + if (isFieldPresent(message, pos)) { + writer.writeEnum(number, intAt(message, offset(typeAndOffset))); + } + break; + case 13: // SFIXED32: + if (isFieldPresent(message, pos)) { + writer.writeSFixed32(number, intAt(message, offset(typeAndOffset))); + } + break; + case 14: // SFIXED64: + if (isFieldPresent(message, pos)) { + writer.writeSFixed64(number, longAt(message, offset(typeAndOffset))); + } + break; + case 15: // SINT32: + if (isFieldPresent(message, pos)) { + writer.writeSInt32(number, intAt(message, offset(typeAndOffset))); + } + break; + case 16: // SINT64: + if (isFieldPresent(message, pos)) { + writer.writeSInt64(number, longAt(message, offset(typeAndOffset))); + } + break; + case 17: // GROUP: + if (isFieldPresent(message, pos)) { + writer.writeGroup( + number, + UnsafeUtil.getObject(message, offset(typeAndOffset)), + getMessageFieldSchema(pos)); + } + break; + case 18: // DOUBLE_LIST: + SchemaUtil.writeDoubleList( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + false); + break; + case 19: // FLOAT_LIST: + SchemaUtil.writeFloatList( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + false); + break; + case 20: // INT64_LIST: + SchemaUtil.writeInt64List( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + false); + break; + case 21: // UINT64_LIST: + SchemaUtil.writeUInt64List( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + false); + break; + case 22: // INT32_LIST: + SchemaUtil.writeInt32List( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + false); + break; + case 23: // FIXED64_LIST: + SchemaUtil.writeFixed64List( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + false); + break; + case 24: // FIXED32_LIST: + SchemaUtil.writeFixed32List( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + false); + break; + case 25: // BOOL_LIST: + SchemaUtil.writeBoolList( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + false); + break; + case 26: // STRING_LIST: + SchemaUtil.writeStringList( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer); + break; + case 27: // MESSAGE_LIST: + SchemaUtil.writeMessageList( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + getMessageFieldSchema(pos)); + break; + case 28: // BYTES_LIST: + SchemaUtil.writeBytesList( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer); + break; + case 29: // UINT32_LIST: + SchemaUtil.writeUInt32List( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + false); + break; + case 30: // ENUM_LIST: + SchemaUtil.writeEnumList( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + false); + break; + case 31: // SFIXED32_LIST: + SchemaUtil.writeSFixed32List( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + false); + break; + case 32: // SFIXED64_LIST: + SchemaUtil.writeSFixed64List( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + false); + break; + case 33: // SINT32_LIST: + SchemaUtil.writeSInt32List( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + false); + break; + case 34: // SINT64_LIST: + SchemaUtil.writeSInt64List( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + false); + break; + case 35: // DOUBLE_LIST_PACKED: + SchemaUtil.writeDoubleList( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + true); + break; + case 36: // FLOAT_LIST_PACKED: + SchemaUtil.writeFloatList( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + true); + break; + case 37: // INT64_LIST_PACKED: + SchemaUtil.writeInt64List( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + true); + break; + case 38: // UINT64_LIST_PACKED: + SchemaUtil.writeUInt64List( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + true); + break; + case 39: // INT32_LIST_PACKED: + SchemaUtil.writeInt32List( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + true); + break; + case 40: // FIXED64_LIST_PACKED: + SchemaUtil.writeFixed64List( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + true); + break; + case 41: // FIXED32_LIST_PACKED: + SchemaUtil.writeFixed32List( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + true); + + break; + case 42: // BOOL_LIST_PACKED: + SchemaUtil.writeBoolList( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + true); + break; + case 43: // UINT32_LIST_PACKED: + SchemaUtil.writeUInt32List( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + true); + break; + case 44: // ENUM_LIST_PACKED: + SchemaUtil.writeEnumList( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + true); + break; + case 45: // SFIXED32_LIST_PACKED: + SchemaUtil.writeSFixed32List( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + true); + break; + case 46: // SFIXED64_LIST_PACKED: + SchemaUtil.writeSFixed64List( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + true); + break; + case 47: // SINT32_LIST_PACKED: + SchemaUtil.writeSInt32List( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + true); + break; + case 48: // SINT64_LIST_PACKED: + SchemaUtil.writeSInt64List( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + true); + break; + case 49: // GROUP_LIST: + SchemaUtil.writeGroupList( + numberAt(pos), + (List) UnsafeUtil.getObject(message, offset(typeAndOffset)), + writer, + getMessageFieldSchema(pos)); + break; + case 50: // MAP: + // TODO(dweis): Use schema cache. + writeMapHelper(writer, number, UnsafeUtil.getObject(message, offset(typeAndOffset)), pos); + break; + case 51: // ONEOF_DOUBLE: + if (isOneofPresent(message, number, pos)) { + writer.writeDouble(number, oneofDoubleAt(message, offset(typeAndOffset))); + } + break; + case 52: // ONEOF_FLOAT: + if (isOneofPresent(message, number, pos)) { + writer.writeFloat(number, oneofFloatAt(message, offset(typeAndOffset))); + } + break; + case 53: // ONEOF_INT64: + if (isOneofPresent(message, number, pos)) { + writer.writeInt64(number, oneofLongAt(message, offset(typeAndOffset))); + } + break; + case 54: // ONEOF_UINT64: + if (isOneofPresent(message, number, pos)) { + writer.writeUInt64(number, oneofLongAt(message, offset(typeAndOffset))); + } + break; + case 55: // ONEOF_INT32: + if (isOneofPresent(message, number, pos)) { + writer.writeInt32(number, oneofIntAt(message, offset(typeAndOffset))); + } + break; + case 56: // ONEOF_FIXED64: + if (isOneofPresent(message, number, pos)) { + writer.writeFixed64(number, oneofLongAt(message, offset(typeAndOffset))); + } + break; + case 57: // ONEOF_FIXED32: + if (isOneofPresent(message, number, pos)) { + writer.writeFixed32(number, oneofIntAt(message, offset(typeAndOffset))); + } + break; + case 58: // ONEOF_BOOL: + if (isOneofPresent(message, number, pos)) { + writer.writeBool(number, oneofBooleanAt(message, offset(typeAndOffset))); + } + break; + case 59: // ONEOF_STRING: + if (isOneofPresent(message, number, pos)) { + writeString(number, UnsafeUtil.getObject(message, offset(typeAndOffset)), writer); + } + break; + case 60: // ONEOF_MESSAGE: + if (isOneofPresent(message, number, pos)) { + Object value = UnsafeUtil.getObject(message, offset(typeAndOffset)); + writer.writeMessage(number, value, getMessageFieldSchema(pos)); + } + break; + case 61: // ONEOF_BYTES: + if (isOneofPresent(message, number, pos)) { + writer.writeBytes( + number, (ByteString) UnsafeUtil.getObject(message, offset(typeAndOffset))); + } + break; + case 62: // ONEOF_UINT32: + if (isOneofPresent(message, number, pos)) { + writer.writeUInt32(number, oneofIntAt(message, offset(typeAndOffset))); + } + break; + case 63: // ONEOF_ENUM: + if (isOneofPresent(message, number, pos)) { + writer.writeEnum(number, oneofIntAt(message, offset(typeAndOffset))); + } + break; + case 64: // ONEOF_SFIXED32: + if (isOneofPresent(message, number, pos)) { + writer.writeSFixed32(number, oneofIntAt(message, offset(typeAndOffset))); + } + break; + case 65: // ONEOF_SFIXED64: + if (isOneofPresent(message, number, pos)) { + writer.writeSFixed64(number, oneofLongAt(message, offset(typeAndOffset))); + } + break; + case 66: // ONEOF_SINT32: + if (isOneofPresent(message, number, pos)) { + writer.writeSInt32(number, oneofIntAt(message, offset(typeAndOffset))); + } + break; + case 67: // ONEOF_SINT64: + if (isOneofPresent(message, number, pos)) { + writer.writeSInt64(number, oneofLongAt(message, offset(typeAndOffset))); + } + break; + case 68: // ONEOF_GROUP: + if (isOneofPresent(message, number, pos)) { + writer.writeGroup( + number, + UnsafeUtil.getObject(message, offset(typeAndOffset)), + getMessageFieldSchema(pos)); + } + break; + default: + break; + } + } + while (nextExtension != null) { + extensionSchema.serializeExtension(writer, nextExtension); + nextExtension = extensionIterator.hasNext() ? extensionIterator.next() : null; + } + } + + @SuppressWarnings("unchecked") + private void writeMapHelper(Writer writer, int number, Object mapField, int pos) + throws IOException { + if (mapField != null) { + writer.writeMap( + number, + (MapEntryLite.Metadata) mapFieldSchema.forMapMetadata(getMapFieldDefaultEntry(pos)), + (Map) mapFieldSchema.forMapData(mapField)); + } + } + + private void writeUnknownInMessageTo( + UnknownFieldSchema schema, T message, Writer writer) throws IOException { + schema.writeTo(schema.getFromMessage(message), writer); + } + + @Override + public void mergeFrom(T message, Reader reader, ExtensionRegistryLite extensionRegistry) + throws IOException { + if (extensionRegistry == null) { + throw new NullPointerException(); + } + mergeFromHelper(unknownFieldSchema, extensionSchema, message, reader, extensionRegistry); + } + + /** + * A helper method for wildcard capture of {@code unknownFieldSchema}. See: + * https://docs.oracle.com/javase/tutorial/java/generics/capture.html + */ + private > void mergeFromHelper( + UnknownFieldSchema unknownFieldSchema, + ExtensionSchema extensionSchema, + T message, + Reader reader, + ExtensionRegistryLite extensionRegistry) + throws IOException { + UB unknownFields = null; + FieldSet extensions = null; + try { + while (true) { + final int number = reader.getFieldNumber(); + final int pos = positionForFieldNumber(number); + if (pos < 0) { + if (number == Reader.READ_DONE) { + return; + } + // Check if it's an extension. + Object extension = + !hasExtensions + ? null + : extensionSchema.findExtensionByNumber( + extensionRegistry, defaultInstance, number); + if (extension != null) { + if (extensions == null) { + extensions = extensionSchema.getMutableExtensions(message); + } + unknownFields = + extensionSchema.parseExtension( + reader, + extension, + extensionRegistry, + extensions, + unknownFields, + unknownFieldSchema); + continue; + } + if (unknownFieldSchema.shouldDiscardUnknownFields(reader)) { + if (reader.skipField()) { + continue; + } + } else { + if (unknownFields == null) { + unknownFields = unknownFieldSchema.getBuilderFromMessage(message); + } + // Unknown field. + if (unknownFieldSchema.mergeOneFieldFrom(unknownFields, reader)) { + continue; + } + } + // Done reading. + return; + } + final int typeAndOffset = typeAndOffsetAt(pos); + + try { + switch (type(typeAndOffset)) { + case 0: // DOUBLE: + UnsafeUtil.putDouble(message, offset(typeAndOffset), reader.readDouble()); + setFieldPresent(message, pos); + break; + case 1: // FLOAT: + UnsafeUtil.putFloat(message, offset(typeAndOffset), reader.readFloat()); + setFieldPresent(message, pos); + break; + case 2: // INT64: + UnsafeUtil.putLong(message, offset(typeAndOffset), reader.readInt64()); + setFieldPresent(message, pos); + break; + case 3: // UINT64: + UnsafeUtil.putLong(message, offset(typeAndOffset), reader.readUInt64()); + setFieldPresent(message, pos); + break; + case 4: // INT32: + UnsafeUtil.putInt(message, offset(typeAndOffset), reader.readInt32()); + setFieldPresent(message, pos); + break; + case 5: // FIXED64: + UnsafeUtil.putLong(message, offset(typeAndOffset), reader.readFixed64()); + setFieldPresent(message, pos); + break; + case 6: // FIXED32: + UnsafeUtil.putInt(message, offset(typeAndOffset), reader.readFixed32()); + setFieldPresent(message, pos); + break; + case 7: // BOOL: + UnsafeUtil.putBoolean(message, offset(typeAndOffset), reader.readBool()); + setFieldPresent(message, pos); + break; + case 8: // STRING: + readString(message, typeAndOffset, reader); + setFieldPresent(message, pos); + break; + case 9: + { // MESSAGE: + if (isFieldPresent(message, pos)) { + Object mergedResult = + Internal.mergeMessage( + UnsafeUtil.getObject(message, offset(typeAndOffset)), + reader.readMessageBySchemaWithCheck( + (Schema) getMessageFieldSchema(pos), extensionRegistry)); + UnsafeUtil.putObject(message, offset(typeAndOffset), mergedResult); + } else { + UnsafeUtil.putObject( + message, + offset(typeAndOffset), + reader.readMessageBySchemaWithCheck( + (Schema) getMessageFieldSchema(pos), extensionRegistry)); + setFieldPresent(message, pos); + } + break; + } + case 10: // BYTES: + UnsafeUtil.putObject(message, offset(typeAndOffset), reader.readBytes()); + setFieldPresent(message, pos); + break; + case 11: // UINT32: + UnsafeUtil.putInt(message, offset(typeAndOffset), reader.readUInt32()); + setFieldPresent(message, pos); + break; + case 12: // ENUM: + { + int enumValue = reader.readEnum(); + EnumVerifier enumVerifier = getEnumFieldVerifier(pos); + if (enumVerifier == null || enumVerifier.isInRange(enumValue)) { + UnsafeUtil.putInt(message, offset(typeAndOffset), enumValue); + setFieldPresent(message, pos); + } else { + unknownFields = + SchemaUtil.storeUnknownEnum( + number, enumValue, unknownFields, unknownFieldSchema); + } + break; + } + case 13: // SFIXED32: + UnsafeUtil.putInt(message, offset(typeAndOffset), reader.readSFixed32()); + setFieldPresent(message, pos); + break; + case 14: // SFIXED64: + UnsafeUtil.putLong(message, offset(typeAndOffset), reader.readSFixed64()); + setFieldPresent(message, pos); + break; + case 15: // SINT32: + UnsafeUtil.putInt(message, offset(typeAndOffset), reader.readSInt32()); + setFieldPresent(message, pos); + break; + case 16: // SINT64: + UnsafeUtil.putLong(message, offset(typeAndOffset), reader.readSInt64()); + setFieldPresent(message, pos); + break; + case 17: + { // GROUP: + if (isFieldPresent(message, pos)) { + Object mergedResult = + Internal.mergeMessage( + UnsafeUtil.getObject(message, offset(typeAndOffset)), + reader.readGroupBySchemaWithCheck( + (Schema) getMessageFieldSchema(pos), extensionRegistry)); + UnsafeUtil.putObject(message, offset(typeAndOffset), mergedResult); + } else { + UnsafeUtil.putObject( + message, + offset(typeAndOffset), + reader.readGroupBySchemaWithCheck( + (Schema) getMessageFieldSchema(pos), extensionRegistry)); + setFieldPresent(message, pos); + } + break; + } + case 18: // DOUBLE_LIST: + reader.readDoubleList( + listFieldSchema.mutableListAt(message, offset(typeAndOffset))); + break; + case 19: // FLOAT_LIST: + reader.readFloatList( + listFieldSchema.mutableListAt(message, offset(typeAndOffset))); + break; + case 20: // INT64_LIST: + reader.readInt64List( + listFieldSchema.mutableListAt(message, offset(typeAndOffset))); + break; + case 21: // UINT64_LIST: + reader.readUInt64List( + listFieldSchema.mutableListAt(message, offset(typeAndOffset))); + break; + case 22: // INT32_LIST: + reader.readInt32List( + listFieldSchema.mutableListAt(message, offset(typeAndOffset))); + break; + case 23: // FIXED64_LIST: + reader.readFixed64List( + listFieldSchema.mutableListAt(message, offset(typeAndOffset))); + break; + case 24: // FIXED32_LIST: + reader.readFixed32List( + listFieldSchema.mutableListAt(message, offset(typeAndOffset))); + break; + case 25: // BOOL_LIST: + reader.readBoolList( + listFieldSchema.mutableListAt(message, offset(typeAndOffset))); + break; + case 26: // STRING_LIST: + readStringList(message, typeAndOffset, reader); + break; + case 27: + { // MESSAGE_LIST: + readMessageList( + message, + typeAndOffset, + reader, + (Schema) getMessageFieldSchema(pos), + extensionRegistry); + break; + } + case 28: // BYTES_LIST: + reader.readBytesList( + listFieldSchema.mutableListAt(message, offset(typeAndOffset))); + break; + case 29: // UINT32_LIST: + reader.readUInt32List( + listFieldSchema.mutableListAt(message, offset(typeAndOffset))); + break; + case 30: // ENUM_LIST: + { + List enumList = + listFieldSchema.mutableListAt(message, offset(typeAndOffset)); + reader.readEnumList(enumList); + unknownFields = + SchemaUtil.filterUnknownEnumList( + number, + enumList, + getEnumFieldVerifier(pos), + unknownFields, + unknownFieldSchema); + break; + } + case 31: // SFIXED32_LIST: + reader.readSFixed32List( + listFieldSchema.mutableListAt(message, offset(typeAndOffset))); + break; + case 32: // SFIXED64_LIST: + reader.readSFixed64List( + listFieldSchema.mutableListAt(message, offset(typeAndOffset))); + break; + case 33: // SINT32_LIST: + reader.readSInt32List( + listFieldSchema.mutableListAt(message, offset(typeAndOffset))); + break; + case 34: // SINT64_LIST: + reader.readSInt64List( + listFieldSchema.mutableListAt(message, offset(typeAndOffset))); + break; + case 35: // DOUBLE_LIST_PACKED: + reader.readDoubleList( + listFieldSchema.mutableListAt(message, offset(typeAndOffset))); + break; + case 36: // FLOAT_LIST_PACKED: + reader.readFloatList( + listFieldSchema.mutableListAt(message, offset(typeAndOffset))); + break; + case 37: // INT64_LIST_PACKED: + reader.readInt64List( + listFieldSchema.mutableListAt(message, offset(typeAndOffset))); + break; + case 38: // UINT64_LIST_PACKED: + reader.readUInt64List( + listFieldSchema.mutableListAt(message, offset(typeAndOffset))); + break; + case 39: // INT32_LIST_PACKED: + reader.readInt32List( + listFieldSchema.mutableListAt(message, offset(typeAndOffset))); + break; + case 40: // FIXED64_LIST_PACKED: + reader.readFixed64List( + listFieldSchema.mutableListAt(message, offset(typeAndOffset))); + break; + case 41: // FIXED32_LIST_PACKED: + reader.readFixed32List( + listFieldSchema.mutableListAt(message, offset(typeAndOffset))); + break; + case 42: // BOOL_LIST_PACKED: + reader.readBoolList( + listFieldSchema.mutableListAt(message, offset(typeAndOffset))); + break; + case 43: // UINT32_LIST_PACKED: + reader.readUInt32List( + listFieldSchema.mutableListAt(message, offset(typeAndOffset))); + break; + case 44: // ENUM_LIST_PACKED: + { + List enumList = + listFieldSchema.mutableListAt(message, offset(typeAndOffset)); + reader.readEnumList(enumList); + unknownFields = + SchemaUtil.filterUnknownEnumList( + number, + enumList, + getEnumFieldVerifier(pos), + unknownFields, + unknownFieldSchema); + break; + } + case 45: // SFIXED32_LIST_PACKED: + reader.readSFixed32List( + listFieldSchema.mutableListAt(message, offset(typeAndOffset))); + break; + case 46: // SFIXED64_LIST_PACKED: + reader.readSFixed64List( + listFieldSchema.mutableListAt(message, offset(typeAndOffset))); + break; + case 47: // SINT32_LIST_PACKED: + reader.readSInt32List( + listFieldSchema.mutableListAt(message, offset(typeAndOffset))); + break; + case 48: // SINT64_LIST_PACKED: + reader.readSInt64List( + listFieldSchema.mutableListAt(message, offset(typeAndOffset))); + break; + case 49: + { // GROUP_LIST: + readGroupList( + message, + offset(typeAndOffset), + reader, + (Schema) getMessageFieldSchema(pos), + extensionRegistry); + break; + } + case 50: // MAP: + mergeMap(message, pos, getMapFieldDefaultEntry(pos), extensionRegistry, reader); + break; + case 51: // ONEOF_DOUBLE: + UnsafeUtil.putObject( + message, offset(typeAndOffset), Double.valueOf(reader.readDouble())); + setOneofPresent(message, number, pos); + break; + case 52: // ONEOF_FLOAT: + UnsafeUtil.putObject( + message, offset(typeAndOffset), Float.valueOf(reader.readFloat())); + setOneofPresent(message, number, pos); + break; + case 53: // ONEOF_INT64: + UnsafeUtil.putObject( + message, offset(typeAndOffset), Long.valueOf(reader.readInt64())); + setOneofPresent(message, number, pos); + break; + case 54: // ONEOF_UINT64: + UnsafeUtil.putObject( + message, offset(typeAndOffset), Long.valueOf(reader.readUInt64())); + setOneofPresent(message, number, pos); + break; + case 55: // ONEOF_INT32: + UnsafeUtil.putObject( + message, offset(typeAndOffset), Integer.valueOf(reader.readInt32())); + setOneofPresent(message, number, pos); + break; + case 56: // ONEOF_FIXED64: + UnsafeUtil.putObject( + message, offset(typeAndOffset), Long.valueOf(reader.readFixed64())); + setOneofPresent(message, number, pos); + break; + case 57: // ONEOF_FIXED32: + UnsafeUtil.putObject( + message, offset(typeAndOffset), Integer.valueOf(reader.readFixed32())); + setOneofPresent(message, number, pos); + break; + case 58: // ONEOF_BOOL: + UnsafeUtil.putObject( + message, offset(typeAndOffset), Boolean.valueOf(reader.readBool())); + setOneofPresent(message, number, pos); + break; + case 59: // ONEOF_STRING: + readString(message, typeAndOffset, reader); + setOneofPresent(message, number, pos); + break; + case 60: // ONEOF_MESSAGE: + if (isOneofPresent(message, number, pos)) { + Object mergedResult = + Internal.mergeMessage( + UnsafeUtil.getObject(message, offset(typeAndOffset)), + reader.readMessageBySchemaWithCheck( + getMessageFieldSchema(pos), extensionRegistry)); + UnsafeUtil.putObject(message, offset(typeAndOffset), mergedResult); + } else { + UnsafeUtil.putObject( + message, + offset(typeAndOffset), + reader.readMessageBySchemaWithCheck( + getMessageFieldSchema(pos), extensionRegistry)); + setFieldPresent(message, pos); + } + setOneofPresent(message, number, pos); + break; + case 61: // ONEOF_BYTES: + UnsafeUtil.putObject(message, offset(typeAndOffset), reader.readBytes()); + setOneofPresent(message, number, pos); + break; + case 62: // ONEOF_UINT32: + UnsafeUtil.putObject( + message, offset(typeAndOffset), Integer.valueOf(reader.readUInt32())); + setOneofPresent(message, number, pos); + break; + case 63: // ONEOF_ENUM: + { + int enumValue = reader.readEnum(); + EnumVerifier enumVerifier = getEnumFieldVerifier(pos); + if (enumVerifier == null || enumVerifier.isInRange(enumValue)) { + UnsafeUtil.putObject(message, offset(typeAndOffset), enumValue); + setOneofPresent(message, number, pos); + } else { + unknownFields = + SchemaUtil.storeUnknownEnum( + number, enumValue, unknownFields, unknownFieldSchema); + } + break; + } + case 64: // ONEOF_SFIXED32: + UnsafeUtil.putObject( + message, offset(typeAndOffset), Integer.valueOf(reader.readSFixed32())); + setOneofPresent(message, number, pos); + break; + case 65: // ONEOF_SFIXED64: + UnsafeUtil.putObject( + message, offset(typeAndOffset), Long.valueOf(reader.readSFixed64())); + setOneofPresent(message, number, pos); + break; + case 66: // ONEOF_SINT32: + UnsafeUtil.putObject( + message, offset(typeAndOffset), Integer.valueOf(reader.readSInt32())); + setOneofPresent(message, number, pos); + break; + case 67: // ONEOF_SINT64: + UnsafeUtil.putObject( + message, offset(typeAndOffset), Long.valueOf(reader.readSInt64())); + setOneofPresent(message, number, pos); + break; + case 68: // ONEOF_GROUP: + UnsafeUtil.putObject( + message, + offset(typeAndOffset), + reader.readGroupBySchemaWithCheck(getMessageFieldSchema(pos), extensionRegistry)); + setOneofPresent(message, number, pos); + break; + default: + // Assume we've landed on an empty entry. Treat it as an unknown field. + if (unknownFields == null) { + unknownFields = unknownFieldSchema.newBuilder(); + } + if (!unknownFieldSchema.mergeOneFieldFrom(unknownFields, reader)) { + return; + } + break; + } + } catch (InvalidProtocolBufferException.InvalidWireTypeException e) { + // Treat fields with an invalid wire type as unknown fields + // (i.e. same as the default case). + if (unknownFieldSchema.shouldDiscardUnknownFields(reader)) { + if (!reader.skipField()) { + return; + } + } else { + if (unknownFields == null) { + unknownFields = unknownFieldSchema.getBuilderFromMessage(message); + } + if (!unknownFieldSchema.mergeOneFieldFrom(unknownFields, reader)) { + return; + } + } + } + } + } finally { + for (int i = checkInitializedCount; i < repeatedFieldOffsetStart; i++) { + unknownFields = + filterMapUnknownEnumValues(message, intArray[i], unknownFields, unknownFieldSchema); + } + if (unknownFields != null) { + unknownFieldSchema.setBuilderToMessage(message, unknownFields); + } + } + } + + @SuppressWarnings("ReferenceEquality") + static UnknownFieldSetLite getMutableUnknownFields(Object message) { + UnknownFieldSetLite unknownFields = ((GeneratedMessageLite) message).unknownFields; + if (unknownFields == UnknownFieldSetLite.getDefaultInstance()) { + unknownFields = UnknownFieldSetLite.newInstance(); + ((GeneratedMessageLite) message).unknownFields = unknownFields; + } + return unknownFields; + } + + /** Decodes a map entry key or value. Stores result in registers.object1. */ + private int decodeMapEntryValue( + byte[] data, + int position, + int limit, + WireFormat.FieldType fieldType, + Class messageType, + Registers registers) + throws IOException { + switch (fieldType) { + case BOOL: + position = decodeVarint64(data, position, registers); + registers.object1 = registers.long1 != 0; + break; + case BYTES: + position = decodeBytes(data, position, registers); + break; + case DOUBLE: + registers.object1 = decodeDouble(data, position); + position += 8; + break; + case FIXED32: + case SFIXED32: + registers.object1 = decodeFixed32(data, position); + position += 4; + break; + case FIXED64: + case SFIXED64: + registers.object1 = decodeFixed64(data, position); + position += 8; + break; + case FLOAT: + registers.object1 = decodeFloat(data, position); + position += 4; + break; + case ENUM: + case INT32: + case UINT32: + position = decodeVarint32(data, position, registers); + registers.object1 = registers.int1; + break; + case INT64: + case UINT64: + position = decodeVarint64(data, position, registers); + registers.object1 = registers.long1; + break; + case MESSAGE: + position = + decodeMessageField( + Protobuf.getInstance().schemaFor(messageType), data, position, limit, registers); + break; + case SINT32: + position = decodeVarint32(data, position, registers); + registers.object1 = CodedInputStream.decodeZigZag32(registers.int1); + break; + case SINT64: + position = decodeVarint64(data, position, registers); + registers.object1 = CodedInputStream.decodeZigZag64(registers.long1); + break; + case STRING: + position = decodeStringRequireUtf8(data, position, registers); + break; + default: + throw new RuntimeException("unsupported field type."); + } + return position; + } + + /** Decodes a map entry. */ + private int decodeMapEntry( + byte[] data, + int position, + int limit, + MapEntryLite.Metadata metadata, + Map target, + Registers registers) + throws IOException { + position = decodeVarint32(data, position, registers); + final int length = registers.int1; + if (length < 0 || length > limit - position) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + final int end = position + length; + K key = metadata.defaultKey; + V value = metadata.defaultValue; + while (position < end) { + int tag = data[position++]; + if (tag < 0) { + position = decodeVarint32(tag, data, position, registers); + tag = registers.int1; + } + final int fieldNumber = tag >>> 3; + final int wireType = tag & 0x7; + switch (fieldNumber) { + case 1: + if (wireType == metadata.keyType.getWireType()) { + position = + decodeMapEntryValue(data, position, limit, metadata.keyType, null, registers); + key = (K) registers.object1; + continue; + } + break; + case 2: + if (wireType == metadata.valueType.getWireType()) { + position = + decodeMapEntryValue( + data, + position, + limit, + metadata.valueType, + metadata.defaultValue.getClass(), + registers); + value = (V) registers.object1; + continue; + } + break; + default: + break; + } + position = skipField(tag, data, position, limit, registers); + } + if (position != end) { + throw InvalidProtocolBufferException.parseFailure(); + } + target.put(key, value); + return end; + } + + @SuppressWarnings("ReferenceEquality") + private int parseRepeatedField( + T message, + byte[] data, + int position, + int limit, + int tag, + int number, + int wireType, + int bufferPosition, + long typeAndOffset, + int fieldType, + long fieldOffset, + Registers registers) + throws IOException { + ProtobufList list = (ProtobufList) UNSAFE.getObject(message, fieldOffset); + if (!list.isModifiable()) { + final int size = list.size(); + list = + list.mutableCopyWithCapacity( + size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY : size * 2); + UNSAFE.putObject(message, fieldOffset, list); + } + switch (fieldType) { + case 18: // DOUBLE_LIST: + case 35: // DOUBLE_LIST_PACKED: + if (wireType == WireFormat.WIRETYPE_LENGTH_DELIMITED) { + position = decodePackedDoubleList(data, position, list, registers); + } else if (wireType == WireFormat.WIRETYPE_FIXED64) { + position = decodeDoubleList(tag, data, position, limit, list, registers); + } + break; + case 19: // FLOAT_LIST: + case 36: // FLOAT_LIST_PACKED: + if (wireType == WireFormat.WIRETYPE_LENGTH_DELIMITED) { + position = decodePackedFloatList(data, position, list, registers); + } else if (wireType == WireFormat.WIRETYPE_FIXED32) { + position = decodeFloatList(tag, data, position, limit, list, registers); + } + break; + case 20: // INT64_LIST: + case 21: // UINT64_LIST: + case 37: // INT64_LIST_PACKED: + case 38: // UINT64_LIST_PACKED: + if (wireType == WireFormat.WIRETYPE_LENGTH_DELIMITED) { + position = decodePackedVarint64List(data, position, list, registers); + } else if (wireType == WireFormat.WIRETYPE_VARINT) { + position = decodeVarint64List(tag, data, position, limit, list, registers); + } + break; + case 22: // INT32_LIST: + case 29: // UINT32_LIST: + case 39: // INT32_LIST_PACKED: + case 43: // UINT32_LIST_PACKED: + if (wireType == WireFormat.WIRETYPE_LENGTH_DELIMITED) { + position = decodePackedVarint32List(data, position, list, registers); + } else if (wireType == WireFormat.WIRETYPE_VARINT) { + position = decodeVarint32List(tag, data, position, limit, list, registers); + } + break; + case 23: // FIXED64_LIST: + case 32: // SFIXED64_LIST: + case 40: // FIXED64_LIST_PACKED: + case 46: // SFIXED64_LIST_PACKED: + if (wireType == WireFormat.WIRETYPE_LENGTH_DELIMITED) { + position = decodePackedFixed64List(data, position, list, registers); + } else if (wireType == WireFormat.WIRETYPE_FIXED64) { + position = decodeFixed64List(tag, data, position, limit, list, registers); + } + break; + case 24: // FIXED32_LIST: + case 31: // SFIXED32_LIST: + case 41: // FIXED32_LIST_PACKED: + case 45: // SFIXED32_LIST_PACKED: + if (wireType == WireFormat.WIRETYPE_LENGTH_DELIMITED) { + position = decodePackedFixed32List(data, position, list, registers); + } else if (wireType == WireFormat.WIRETYPE_FIXED32) { + position = decodeFixed32List(tag, data, position, limit, list, registers); + } + break; + case 25: // BOOL_LIST: + case 42: // BOOL_LIST_PACKED: + if (wireType == WireFormat.WIRETYPE_LENGTH_DELIMITED) { + position = decodePackedBoolList(data, position, list, registers); + } else if (wireType == WireFormat.WIRETYPE_VARINT) { + position = decodeBoolList(tag, data, position, limit, list, registers); + } + break; + case 26: // STRING_LIST: + if (wireType == WireFormat.WIRETYPE_LENGTH_DELIMITED) { + if ((typeAndOffset & ENFORCE_UTF8_MASK) == 0) { + position = decodeStringList(tag, data, position, limit, list, registers); + } else { + position = decodeStringListRequireUtf8(tag, data, position, limit, list, registers); + } + } + break; + case 27: // MESSAGE_LIST: + if (wireType == WireFormat.WIRETYPE_LENGTH_DELIMITED) { + position = + decodeMessageList( + getMessageFieldSchema(bufferPosition), + tag, + data, + position, + limit, + list, + registers); + } + break; + case 28: // BYTES_LIST: + if (wireType == WireFormat.WIRETYPE_LENGTH_DELIMITED) { + position = decodeBytesList(tag, data, position, limit, list, registers); + } + break; + case 30: // ENUM_LIST: + case 44: // ENUM_LIST_PACKED: + if (wireType == WireFormat.WIRETYPE_LENGTH_DELIMITED) { + position = decodePackedVarint32List(data, position, list, registers); + } else if (wireType == WireFormat.WIRETYPE_VARINT) { + position = decodeVarint32List(tag, data, position, limit, list, registers); + } else { + break; + } + UnknownFieldSetLite unknownFields = ((GeneratedMessageLite) message).unknownFields; + if (unknownFields == UnknownFieldSetLite.getDefaultInstance()) { + // filterUnknownEnumList() expects the unknownFields parameter to be mutable or null. + // Since we don't know yet whether there exist unknown enum values, we'd better pass + // null to it instead of allocating a mutable instance. This is also needed to be + // consistent with the behavior of generated parser/builder. + unknownFields = null; + } + unknownFields = + SchemaUtil.filterUnknownEnumList( + number, + (ProtobufList) list, + getEnumFieldVerifier(bufferPosition), + unknownFields, + (UnknownFieldSchema) unknownFieldSchema); + if (unknownFields != null) { + ((GeneratedMessageLite) message).unknownFields = unknownFields; + } + break; + case 33: // SINT32_LIST: + case 47: // SINT32_LIST_PACKED: + if (wireType == WireFormat.WIRETYPE_LENGTH_DELIMITED) { + position = decodePackedSInt32List(data, position, list, registers); + } else if (wireType == WireFormat.WIRETYPE_VARINT) { + position = decodeSInt32List(tag, data, position, limit, list, registers); + } + break; + case 34: // SINT64_LIST: + case 48: // SINT64_LIST_PACKED: + if (wireType == WireFormat.WIRETYPE_LENGTH_DELIMITED) { + position = decodePackedSInt64List(data, position, list, registers); + } else if (wireType == WireFormat.WIRETYPE_VARINT) { + position = decodeSInt64List(tag, data, position, limit, list, registers); + } + break; + case 49: // GROUP_LIST: + if (wireType == WireFormat.WIRETYPE_START_GROUP) { + position = + decodeGroupList( + getMessageFieldSchema(bufferPosition), + tag, + data, + position, + limit, + list, + registers); + } + break; + default: + break; + } + return position; + } + + private int parseMapField( + T message, + byte[] data, + int position, + int limit, + int bufferPosition, + long fieldOffset, + Registers registers) + throws IOException { + final sun.misc.Unsafe unsafe = UNSAFE; + Object mapDefaultEntry = getMapFieldDefaultEntry(bufferPosition); + Object mapField = unsafe.getObject(message, fieldOffset); + if (mapFieldSchema.isImmutable(mapField)) { + Object oldMapField = mapField; + mapField = mapFieldSchema.newMapField(mapDefaultEntry); + mapFieldSchema.mergeFrom(mapField, oldMapField); + unsafe.putObject(message, fieldOffset, mapField); + } + return decodeMapEntry( + data, + position, + limit, + (Metadata) mapFieldSchema.forMapMetadata(mapDefaultEntry), + (Map) mapFieldSchema.forMutableMapData(mapField), + registers); + } + + private int parseOneofField( + T message, + byte[] data, + int position, + int limit, + int tag, + int number, + int wireType, + int typeAndOffset, + int fieldType, + long fieldOffset, + int bufferPosition, + Registers registers) + throws IOException { + final sun.misc.Unsafe unsafe = UNSAFE; + final long oneofCaseOffset = buffer[bufferPosition + 2] & OFFSET_MASK; + switch (fieldType) { + case 51: // ONEOF_DOUBLE: + if (wireType == WireFormat.WIRETYPE_FIXED64) { + unsafe.putObject(message, fieldOffset, decodeDouble(data, position)); + position += 8; + unsafe.putInt(message, oneofCaseOffset, number); + } + break; + case 52: // ONEOF_FLOAT: + if (wireType == WireFormat.WIRETYPE_FIXED32) { + unsafe.putObject(message, fieldOffset, decodeFloat(data, position)); + position += 4; + unsafe.putInt(message, oneofCaseOffset, number); + } + break; + case 53: // ONEOF_INT64: + case 54: // ONEOF_UINT64: + if (wireType == WireFormat.WIRETYPE_VARINT) { + position = decodeVarint64(data, position, registers); + unsafe.putObject(message, fieldOffset, registers.long1); + unsafe.putInt(message, oneofCaseOffset, number); + } + break; + case 55: // ONEOF_INT32: + case 62: // ONEOF_UINT32: + if (wireType == WireFormat.WIRETYPE_VARINT) { + position = decodeVarint32(data, position, registers); + unsafe.putObject(message, fieldOffset, registers.int1); + unsafe.putInt(message, oneofCaseOffset, number); + } + break; + case 56: // ONEOF_FIXED64: + case 65: // ONEOF_SFIXED64: + if (wireType == WireFormat.WIRETYPE_FIXED64) { + unsafe.putObject(message, fieldOffset, decodeFixed64(data, position)); + position += 8; + unsafe.putInt(message, oneofCaseOffset, number); + } + break; + case 57: // ONEOF_FIXED32: + case 64: // ONEOF_SFIXED32: + if (wireType == WireFormat.WIRETYPE_FIXED32) { + unsafe.putObject(message, fieldOffset, decodeFixed32(data, position)); + position += 4; + unsafe.putInt(message, oneofCaseOffset, number); + } + break; + case 58: // ONEOF_BOOL: + if (wireType == WireFormat.WIRETYPE_VARINT) { + position = decodeVarint64(data, position, registers); + unsafe.putObject(message, fieldOffset, registers.long1 != 0); + unsafe.putInt(message, oneofCaseOffset, number); + } + break; + case 59: // ONEOF_STRING: + if (wireType == WireFormat.WIRETYPE_LENGTH_DELIMITED) { + position = decodeVarint32(data, position, registers); + final int length = registers.int1; + if (length == 0) { + unsafe.putObject(message, fieldOffset, ""); + } else { + if ((typeAndOffset & ENFORCE_UTF8_MASK) != 0 + && !Utf8.isValidUtf8(data, position, position + length)) { + throw InvalidProtocolBufferException.invalidUtf8(); + } + final String value = new String(data, position, length, Internal.UTF_8); + unsafe.putObject(message, fieldOffset, value); + position += length; + } + unsafe.putInt(message, oneofCaseOffset, number); + } + break; + case 60: // ONEOF_MESSAGE: + if (wireType == WireFormat.WIRETYPE_LENGTH_DELIMITED) { + position = + decodeMessageField( + getMessageFieldSchema(bufferPosition), data, position, limit, registers); + final Object oldValue = + unsafe.getInt(message, oneofCaseOffset) == number + ? unsafe.getObject(message, fieldOffset) + : null; + if (oldValue == null) { + unsafe.putObject(message, fieldOffset, registers.object1); + } else { + unsafe.putObject( + message, fieldOffset, Internal.mergeMessage(oldValue, registers.object1)); + } + unsafe.putInt(message, oneofCaseOffset, number); + } + break; + case 61: // ONEOF_BYTES: + if (wireType == WireFormat.WIRETYPE_LENGTH_DELIMITED) { + position = decodeBytes(data, position, registers); + unsafe.putObject(message, fieldOffset, registers.object1); + unsafe.putInt(message, oneofCaseOffset, number); + } + break; + case 63: // ONEOF_ENUM: + if (wireType == WireFormat.WIRETYPE_VARINT) { + position = decodeVarint32(data, position, registers); + final int enumValue = registers.int1; + EnumVerifier enumVerifier = getEnumFieldVerifier(bufferPosition); + if (enumVerifier == null || enumVerifier.isInRange(enumValue)) { + unsafe.putObject(message, fieldOffset, enumValue); + unsafe.putInt(message, oneofCaseOffset, number); + } else { + // UnknownFieldSetLite requires varint to be represented as Long. + getMutableUnknownFields(message).storeField(tag, (long) enumValue); + } + } + break; + case 66: // ONEOF_SINT32: + if (wireType == WireFormat.WIRETYPE_VARINT) { + position = decodeVarint32(data, position, registers); + unsafe.putObject(message, fieldOffset, CodedInputStream.decodeZigZag32(registers.int1)); + unsafe.putInt(message, oneofCaseOffset, number); + } + break; + case 67: // ONEOF_SINT64: + if (wireType == WireFormat.WIRETYPE_VARINT) { + position = decodeVarint64(data, position, registers); + unsafe.putObject(message, fieldOffset, CodedInputStream.decodeZigZag64(registers.long1)); + unsafe.putInt(message, oneofCaseOffset, number); + } + break; + case 68: // ONEOF_GROUP: + if (wireType == WireFormat.WIRETYPE_START_GROUP) { + final int endTag = (tag & ~0x7) | WireFormat.WIRETYPE_END_GROUP; + position = + decodeGroupField( + getMessageFieldSchema(bufferPosition), data, position, limit, endTag, registers); + final Object oldValue = + unsafe.getInt(message, oneofCaseOffset) == number + ? unsafe.getObject(message, fieldOffset) + : null; + if (oldValue == null) { + unsafe.putObject(message, fieldOffset, registers.object1); + } else { + unsafe.putObject( + message, fieldOffset, Internal.mergeMessage(oldValue, registers.object1)); + } + unsafe.putInt(message, oneofCaseOffset, number); + } + break; + default: + break; + } + return position; + } + + private Schema getMessageFieldSchema(int pos) { + final int index = pos / INTS_PER_FIELD * 2; + Schema schema = (Schema) objects[index]; + if (schema != null) { + return schema; + } + schema = Protobuf.getInstance().schemaFor((Class) objects[index + 1]); + objects[index] = schema; + return schema; + } + + private Object getMapFieldDefaultEntry(int pos) { + return objects[pos / INTS_PER_FIELD * 2]; + } + + private EnumVerifier getEnumFieldVerifier(int pos) { + return (EnumVerifier) objects[pos / INTS_PER_FIELD * 2 + 1]; + } + + /** + * Parses a proto2 message or group and returns the position after the message/group. If it's + * parsing a message (endGroup == 0), returns limit if parsing is successful; It it's parsing a + * group (endGroup != 0), parsing ends when a tag == endGroup is encountered and the position + * after that tag is returned. + */ + int parseProto2Message( + T message, byte[] data, int position, int limit, int endGroup, Registers registers) + throws IOException { + final sun.misc.Unsafe unsafe = UNSAFE; + int currentPresenceFieldOffset = NO_PRESENCE_SENTINEL; + int currentPresenceField = 0; + int tag = 0; + int oldNumber = -1; + int pos = 0; + while (position < limit) { + tag = data[position++]; + if (tag < 0) { + position = decodeVarint32(tag, data, position, registers); + tag = registers.int1; + } + final int number = tag >>> 3; + final int wireType = tag & 0x7; + if (number > oldNumber) { + pos = positionForFieldNumber(number, pos / INTS_PER_FIELD); + } else { + pos = positionForFieldNumber(number); + } + oldNumber = number; + if (pos == -1) { + // need to reset + pos = 0; + } else { + final int typeAndOffset = buffer[pos + 1]; + final int fieldType = type(typeAndOffset); + final long fieldOffset = offset(typeAndOffset); + if (fieldType <= 17) { + // Proto2 optional fields have has-bits. + final int presenceMaskAndOffset = buffer[pos + 2]; + final int presenceMask = 1 << (presenceMaskAndOffset >>> OFFSET_BITS); + final int presenceFieldOffset = presenceMaskAndOffset & OFFSET_MASK; + // We cache the 32-bit has-bits integer value and only write it back when parsing a field + // using a different has-bits integer. + if (presenceFieldOffset != currentPresenceFieldOffset) { + if (currentPresenceFieldOffset != NO_PRESENCE_SENTINEL) { + unsafe.putInt(message, (long) currentPresenceFieldOffset, currentPresenceField); + } + currentPresenceFieldOffset = presenceFieldOffset; + currentPresenceField = unsafe.getInt(message, (long) presenceFieldOffset); + } + switch (fieldType) { + case 0: // DOUBLE + if (wireType == WireFormat.WIRETYPE_FIXED64) { + UnsafeUtil.putDouble(message, fieldOffset, decodeDouble(data, position)); + position += 8; + currentPresenceField |= presenceMask; + continue; + } + break; + case 1: // FLOAT + if (wireType == WireFormat.WIRETYPE_FIXED32) { + UnsafeUtil.putFloat(message, fieldOffset, decodeFloat(data, position)); + position += 4; + currentPresenceField |= presenceMask; + continue; + } + break; + case 2: // INT64 + case 3: // UINT64 + if (wireType == WireFormat.WIRETYPE_VARINT) { + position = decodeVarint64(data, position, registers); + unsafe.putLong(message, fieldOffset, registers.long1); + currentPresenceField |= presenceMask; + continue; + } + break; + case 4: // INT32 + case 11: // UINT32 + if (wireType == WireFormat.WIRETYPE_VARINT) { + position = decodeVarint32(data, position, registers); + unsafe.putInt(message, fieldOffset, registers.int1); + currentPresenceField |= presenceMask; + continue; + } + break; + case 5: // FIXED64 + case 14: // SFIXED64 + if (wireType == WireFormat.WIRETYPE_FIXED64) { + unsafe.putLong(message, fieldOffset, decodeFixed64(data, position)); + position += 8; + currentPresenceField |= presenceMask; + continue; + } + break; + case 6: // FIXED32 + case 13: // SFIXED32 + if (wireType == WireFormat.WIRETYPE_FIXED32) { + unsafe.putInt(message, fieldOffset, decodeFixed32(data, position)); + position += 4; + currentPresenceField |= presenceMask; + continue; + } + break; + case 7: // BOOL + if (wireType == WireFormat.WIRETYPE_VARINT) { + position = decodeVarint64(data, position, registers); + UnsafeUtil.putBoolean(message, fieldOffset, registers.long1 != 0); + currentPresenceField |= presenceMask; + continue; + } + break; + case 8: // STRING + if (wireType == WireFormat.WIRETYPE_LENGTH_DELIMITED) { + if ((typeAndOffset & ENFORCE_UTF8_MASK) == 0) { + position = decodeString(data, position, registers); + } else { + position = decodeStringRequireUtf8(data, position, registers); + } + unsafe.putObject(message, fieldOffset, registers.object1); + currentPresenceField |= presenceMask; + continue; + } + break; + case 9: // MESSAGE + if (wireType == WireFormat.WIRETYPE_LENGTH_DELIMITED) { + position = + decodeMessageField( + getMessageFieldSchema(pos), data, position, limit, registers); + if ((currentPresenceField & presenceMask) == 0) { + unsafe.putObject(message, fieldOffset, registers.object1); + } else { + unsafe.putObject( + message, + fieldOffset, + Internal.mergeMessage( + unsafe.getObject(message, fieldOffset), registers.object1)); + } + currentPresenceField |= presenceMask; + continue; + } + break; + case 10: // BYTES + if (wireType == WireFormat.WIRETYPE_LENGTH_DELIMITED) { + position = decodeBytes(data, position, registers); + unsafe.putObject(message, fieldOffset, registers.object1); + currentPresenceField |= presenceMask; + continue; + } + break; + case 12: // ENUM + if (wireType == WireFormat.WIRETYPE_VARINT) { + position = decodeVarint32(data, position, registers); + final int enumValue = registers.int1; + EnumVerifier enumVerifier = getEnumFieldVerifier(pos); + if (enumVerifier == null || enumVerifier.isInRange(enumValue)) { + unsafe.putInt(message, fieldOffset, enumValue); + currentPresenceField |= presenceMask; + } else { + // UnknownFieldSetLite requires varint to be represented as Long. + getMutableUnknownFields(message).storeField(tag, (long) enumValue); + } + continue; + } + break; + case 15: // SINT32 + if (wireType == WireFormat.WIRETYPE_VARINT) { + position = decodeVarint32(data, position, registers); + unsafe.putInt( + message, fieldOffset, CodedInputStream.decodeZigZag32(registers.int1)); + currentPresenceField |= presenceMask; + continue; + } + break; + case 16: // SINT64 + if (wireType == WireFormat.WIRETYPE_VARINT) { + position = decodeVarint64(data, position, registers); + unsafe.putLong( + message, fieldOffset, CodedInputStream.decodeZigZag64(registers.long1)); + + currentPresenceField |= presenceMask; + continue; + } + break; + case 17: // GROUP + if (wireType == WireFormat.WIRETYPE_START_GROUP) { + final int endTag = (number << 3) | WireFormat.WIRETYPE_END_GROUP; + position = + decodeGroupField( + getMessageFieldSchema(pos), data, position, limit, endTag, registers); + if ((currentPresenceField & presenceMask) == 0) { + unsafe.putObject(message, fieldOffset, registers.object1); + } else { + unsafe.putObject( + message, + fieldOffset, + Internal.mergeMessage( + unsafe.getObject(message, fieldOffset), registers.object1)); + } + + currentPresenceField |= presenceMask; + continue; + } + break; + default: + break; + } + } else if (fieldType == 27) { + // Handle repeated message fields. + if (wireType == WireFormat.WIRETYPE_LENGTH_DELIMITED) { + ProtobufList list = (ProtobufList) unsafe.getObject(message, fieldOffset); + if (!list.isModifiable()) { + final int size = list.size(); + list = + list.mutableCopyWithCapacity( + size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY : size * 2); + unsafe.putObject(message, fieldOffset, list); + } + position = + decodeMessageList( + getMessageFieldSchema(pos), tag, data, position, limit, list, registers); + continue; + } + } else if (fieldType <= 49) { + // Handle all other repeated fields. + final int oldPosition = position; + position = + parseRepeatedField( + message, + data, + position, + limit, + tag, + number, + wireType, + pos, + typeAndOffset, + fieldType, + fieldOffset, + registers); + if (position != oldPosition) { + continue; + } + } else if (fieldType == 50) { + if (wireType == WireFormat.WIRETYPE_LENGTH_DELIMITED) { + final int oldPosition = position; + position = parseMapField(message, data, position, limit, pos, fieldOffset, registers); + if (position != oldPosition) { + continue; + } + } + } else { + final int oldPosition = position; + position = + parseOneofField( + message, + data, + position, + limit, + tag, + number, + wireType, + typeAndOffset, + fieldType, + fieldOffset, + pos, + registers); + if (position != oldPosition) { + continue; + } + } + } + if (tag == endGroup && endGroup != 0) { + break; + } + + if (hasExtensions + && registers.extensionRegistry != ExtensionRegistryLite.getEmptyRegistry()) { + position = decodeExtensionOrUnknownField( + tag, data, position, limit, message, defaultInstance, + (UnknownFieldSchema) unknownFieldSchema, + registers); + } else { + position = decodeUnknownField( + tag, data, position, limit, getMutableUnknownFields(message), registers); + } + } + if (currentPresenceFieldOffset != NO_PRESENCE_SENTINEL) { + unsafe.putInt(message, (long) currentPresenceFieldOffset, currentPresenceField); + } + UnknownFieldSetLite unknownFields = null; + for (int i = checkInitializedCount; i < repeatedFieldOffsetStart; i++) { + unknownFields = + filterMapUnknownEnumValues( + message, + intArray[i], + unknownFields, + (UnknownFieldSchema) unknownFieldSchema); + } + if (unknownFields != null) { + ((UnknownFieldSchema) unknownFieldSchema) + .setBuilderToMessage(message, unknownFields); + } + if (endGroup == 0) { + if (position != limit) { + throw InvalidProtocolBufferException.parseFailure(); + } + } else { + if (position > limit || tag != endGroup) { + throw InvalidProtocolBufferException.parseFailure(); + } + } + return position; + } + + /** Parses a proto3 message and returns the limit if parsing is successful. */ + private int parseProto3Message( + T message, byte[] data, int position, int limit, Registers registers) throws IOException { + final sun.misc.Unsafe unsafe = UNSAFE; + int currentPresenceFieldOffset = NO_PRESENCE_SENTINEL; + int currentPresenceField = 0; + int tag = 0; + int oldNumber = -1; + int pos = 0; + while (position < limit) { + tag = data[position++]; + if (tag < 0) { + position = decodeVarint32(tag, data, position, registers); + tag = registers.int1; + } + final int number = tag >>> 3; + final int wireType = tag & 0x7; + if (number > oldNumber) { + pos = positionForFieldNumber(number, pos / INTS_PER_FIELD); + } else { + pos = positionForFieldNumber(number); + } + oldNumber = number; + if (pos == -1) { + // need to reset + pos = 0; + } else { + final int typeAndOffset = buffer[pos + 1]; + final int fieldType = type(typeAndOffset); + final long fieldOffset = offset(typeAndOffset); + if (fieldType <= 17) { + // Proto3 optional fields have has-bits. + final int presenceMaskAndOffset = buffer[pos + 2]; + final int presenceMask = 1 << (presenceMaskAndOffset >>> OFFSET_BITS); + final int presenceFieldOffset = presenceMaskAndOffset & OFFSET_MASK; + // We cache the 32-bit has-bits integer value and only write it back when parsing a field + // using a different has-bits integer. + // + // Note that for fields that do not have hasbits, we unconditionally write and discard + // the data. + if (presenceFieldOffset != currentPresenceFieldOffset) { + if (currentPresenceFieldOffset != NO_PRESENCE_SENTINEL) { + unsafe.putInt(message, (long) currentPresenceFieldOffset, currentPresenceField); + } + if (presenceFieldOffset != NO_PRESENCE_SENTINEL) { + currentPresenceField = unsafe.getInt(message, (long) presenceFieldOffset); + } + currentPresenceFieldOffset = presenceFieldOffset; + } + switch (fieldType) { + case 0: // DOUBLE: + if (wireType == WireFormat.WIRETYPE_FIXED64) { + UnsafeUtil.putDouble(message, fieldOffset, decodeDouble(data, position)); + position += 8; + currentPresenceField |= presenceMask; + continue; + } + break; + case 1: // FLOAT: + if (wireType == WireFormat.WIRETYPE_FIXED32) { + UnsafeUtil.putFloat(message, fieldOffset, decodeFloat(data, position)); + position += 4; + currentPresenceField |= presenceMask; + continue; + } + break; + case 2: // INT64: + case 3: // UINT64: + if (wireType == WireFormat.WIRETYPE_VARINT) { + position = decodeVarint64(data, position, registers); + unsafe.putLong(message, fieldOffset, registers.long1); + currentPresenceField |= presenceMask; + continue; + } + break; + case 4: // INT32: + case 11: // UINT32: + if (wireType == WireFormat.WIRETYPE_VARINT) { + position = decodeVarint32(data, position, registers); + unsafe.putInt(message, fieldOffset, registers.int1); + currentPresenceField |= presenceMask; + continue; + } + break; + case 5: // FIXED64: + case 14: // SFIXED64: + if (wireType == WireFormat.WIRETYPE_FIXED64) { + unsafe.putLong(message, fieldOffset, decodeFixed64(data, position)); + position += 8; + currentPresenceField |= presenceMask; + continue; + } + break; + case 6: // FIXED32: + case 13: // SFIXED32: + if (wireType == WireFormat.WIRETYPE_FIXED32) { + unsafe.putInt(message, fieldOffset, decodeFixed32(data, position)); + position += 4; + currentPresenceField |= presenceMask; + continue; + } + break; + case 7: // BOOL: + if (wireType == WireFormat.WIRETYPE_VARINT) { + position = decodeVarint64(data, position, registers); + UnsafeUtil.putBoolean(message, fieldOffset, registers.long1 != 0); + currentPresenceField |= presenceMask; + continue; + } + break; + case 8: // STRING: + if (wireType == WireFormat.WIRETYPE_LENGTH_DELIMITED) { + if ((typeAndOffset & ENFORCE_UTF8_MASK) == 0) { + position = decodeString(data, position, registers); + } else { + position = decodeStringRequireUtf8(data, position, registers); + } + unsafe.putObject(message, fieldOffset, registers.object1); + currentPresenceField |= presenceMask; + continue; + } + break; + case 9: // MESSAGE: + if (wireType == WireFormat.WIRETYPE_LENGTH_DELIMITED) { + position = + decodeMessageField( + getMessageFieldSchema(pos), data, position, limit, registers); + final Object oldValue = unsafe.getObject(message, fieldOffset); + if (oldValue == null) { + unsafe.putObject(message, fieldOffset, registers.object1); + } else { + unsafe.putObject( + message, fieldOffset, Internal.mergeMessage(oldValue, registers.object1)); + } + currentPresenceField |= presenceMask; + continue; + } + break; + case 10: // BYTES: + if (wireType == WireFormat.WIRETYPE_LENGTH_DELIMITED) { + position = decodeBytes(data, position, registers); + unsafe.putObject(message, fieldOffset, registers.object1); + currentPresenceField |= presenceMask; + continue; + } + break; + case 12: // ENUM: + if (wireType == WireFormat.WIRETYPE_VARINT) { + position = decodeVarint32(data, position, registers); + unsafe.putInt(message, fieldOffset, registers.int1); + currentPresenceField |= presenceMask; + continue; + } + break; + case 15: // SINT32: + if (wireType == WireFormat.WIRETYPE_VARINT) { + position = decodeVarint32(data, position, registers); + unsafe.putInt( + message, fieldOffset, CodedInputStream.decodeZigZag32(registers.int1)); + currentPresenceField |= presenceMask; + continue; + } + break; + case 16: // SINT64: + if (wireType == WireFormat.WIRETYPE_VARINT) { + position = decodeVarint64(data, position, registers); + unsafe.putLong( + message, fieldOffset, CodedInputStream.decodeZigZag64(registers.long1)); + currentPresenceField |= presenceMask; + continue; + } + break; + default: + break; + } + } else if (fieldType == 27) { + // Handle repeated message field. + if (wireType == WireFormat.WIRETYPE_LENGTH_DELIMITED) { + ProtobufList list = (ProtobufList) unsafe.getObject(message, fieldOffset); + if (!list.isModifiable()) { + final int size = list.size(); + list = + list.mutableCopyWithCapacity( + size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY : size * 2); + unsafe.putObject(message, fieldOffset, list); + } + position = + decodeMessageList( + getMessageFieldSchema(pos), tag, data, position, limit, list, registers); + continue; + } + } else if (fieldType <= 49) { + // Handle all other repeated fields. + final int oldPosition = position; + position = + parseRepeatedField( + message, + data, + position, + limit, + tag, + number, + wireType, + pos, + typeAndOffset, + fieldType, + fieldOffset, + registers); + if (position != oldPosition) { + continue; + } + } else if (fieldType == 50) { + if (wireType == WireFormat.WIRETYPE_LENGTH_DELIMITED) { + final int oldPosition = position; + position = parseMapField(message, data, position, limit, pos, fieldOffset, registers); + if (position != oldPosition) { + continue; + } + } + } else { + final int oldPosition = position; + position = + parseOneofField( + message, + data, + position, + limit, + tag, + number, + wireType, + typeAndOffset, + fieldType, + fieldOffset, + pos, + registers); + if (position != oldPosition) { + continue; + } + } + } + position = decodeUnknownField( + tag, data, position, limit, getMutableUnknownFields(message), registers); + } + if (currentPresenceFieldOffset != NO_PRESENCE_SENTINEL) { + unsafe.putInt(message, (long) currentPresenceFieldOffset, currentPresenceField); + } + if (position != limit) { + throw InvalidProtocolBufferException.parseFailure(); + } + return position; + } + + @Override + public void mergeFrom(T message, byte[] data, int position, int limit, Registers registers) + throws IOException { + if (proto3) { + parseProto3Message(message, data, position, limit, registers); + } else { + parseProto2Message(message, data, position, limit, 0, registers); + } + } + + @Override + public void makeImmutable(T message) { + // Make all repeated/map fields immutable. + for (int i = checkInitializedCount; i < repeatedFieldOffsetStart; i++) { + long offset = offset(typeAndOffsetAt(intArray[i])); + Object mapField = UnsafeUtil.getObject(message, offset); + if (mapField == null) { + continue; + } + UnsafeUtil.putObject(message, offset, mapFieldSchema.toImmutable(mapField)); + } + final int length = intArray.length; + for (int i = repeatedFieldOffsetStart; i < length; i++) { + listFieldSchema.makeImmutableListAt(message, intArray[i]); + } + unknownFieldSchema.makeImmutable(message); + if (hasExtensions) { + extensionSchema.makeImmutable(message); + } + } + + @SuppressWarnings("unchecked") + private final void mergeMap( + Object message, + int pos, + Object mapDefaultEntry, + ExtensionRegistryLite extensionRegistry, + Reader reader) + throws IOException { + long offset = offset(typeAndOffsetAt(pos)); + Object mapField = UnsafeUtil.getObject(message, offset); + // TODO(xiaofeng): Consider creating separate implementations for full and lite. In lite + // runtime map field will never be null but here we still need to check null because the + // code is shared by both full and lite. It might be better if full/lite uses different + // schema implementations. + if (mapField == null) { + mapField = mapFieldSchema.newMapField(mapDefaultEntry); + UnsafeUtil.putObject(message, offset, mapField); + } else if (mapFieldSchema.isImmutable(mapField)) { + Object oldMapField = mapField; + mapField = mapFieldSchema.newMapField(mapDefaultEntry); + mapFieldSchema.mergeFrom(mapField, oldMapField); + UnsafeUtil.putObject(message, offset, mapField); + } + reader.readMap( + (Map) mapFieldSchema.forMutableMapData(mapField), + (Metadata) mapFieldSchema.forMapMetadata(mapDefaultEntry), + extensionRegistry); + } + + private final UB filterMapUnknownEnumValues( + Object message, int pos, UB unknownFields, UnknownFieldSchema unknownFieldSchema) { + int fieldNumber = numberAt(pos); + long offset = offset(typeAndOffsetAt(pos)); + Object mapField = UnsafeUtil.getObject(message, offset); + if (mapField == null) { + return unknownFields; + } + EnumVerifier enumVerifier = getEnumFieldVerifier(pos); + if (enumVerifier == null) { + return unknownFields; + } + Map mapData = mapFieldSchema.forMutableMapData(mapField); + // Filter unknown enum values. + unknownFields = + filterUnknownEnumMap( + pos, fieldNumber, mapData, enumVerifier, unknownFields, unknownFieldSchema); + return unknownFields; + } + + @SuppressWarnings("unchecked") + private final UB filterUnknownEnumMap( + int pos, + int number, + Map mapData, + EnumVerifier enumVerifier, + UB unknownFields, + UnknownFieldSchema unknownFieldSchema) { + Metadata metadata = + (Metadata) mapFieldSchema.forMapMetadata(getMapFieldDefaultEntry(pos)); + for (Iterator> it = mapData.entrySet().iterator(); it.hasNext(); ) { + Map.Entry entry = it.next(); + if (!enumVerifier.isInRange((Integer) entry.getValue())) { + if (unknownFields == null) { + unknownFields = unknownFieldSchema.newBuilder(); + } + int entrySize = + MapEntryLite.computeSerializedSize(metadata, entry.getKey(), entry.getValue()); + CodedBuilder codedBuilder = ByteString.newCodedBuilder(entrySize); + CodedOutputStream codedOutput = codedBuilder.getCodedOutput(); + try { + MapEntryLite.writeTo(codedOutput, metadata, entry.getKey(), entry.getValue()); + } catch (IOException e) { + // Writing to ByteString CodedOutputStream should not throw IOException. + throw new RuntimeException(e); + } + unknownFieldSchema.addLengthDelimited(unknownFields, number, codedBuilder.build()); + it.remove(); + } + } + return unknownFields; + } + + @Override + public final boolean isInitialized(T message) { + int currentPresenceFieldOffset = NO_PRESENCE_SENTINEL; + int currentPresenceField = 0; + for (int i = 0; i < checkInitializedCount; i++) { + final int pos = intArray[i]; + final int number = numberAt(pos); + final int typeAndOffset = typeAndOffsetAt(pos); + + int presenceMaskAndOffset = buffer[pos + 2]; + final int presenceFieldOffset = presenceMaskAndOffset & OFFSET_MASK; + int presenceMask = 1 << (presenceMaskAndOffset >>> OFFSET_BITS); + if (presenceFieldOffset != currentPresenceFieldOffset) { + currentPresenceFieldOffset = presenceFieldOffset; + if (currentPresenceFieldOffset != NO_PRESENCE_SENTINEL) { + currentPresenceField = UNSAFE.getInt(message, (long) presenceFieldOffset); + } + } + + if (isRequired(typeAndOffset)) { + if (!isFieldPresent( + message, pos, currentPresenceFieldOffset, currentPresenceField, presenceMask)) { + return false; + } + // If a required message field is set but has no required fields of it's own, we still + // proceed and check the message is initialized. It should be fairly cheap to check these + // messages but is worth documenting. + } + // Check nested message and groups. + switch (type(typeAndOffset)) { + case 9: // MESSAGE + case 17: // GROUP + if (isFieldPresent( + message, pos, currentPresenceFieldOffset, currentPresenceField, presenceMask) + && !isInitialized(message, typeAndOffset, getMessageFieldSchema(pos))) { + return false; + } + break; + case 27: // MESSAGE_LIST + case 49: // GROUP_LIST + if (!isListInitialized(message, typeAndOffset, pos)) { + return false; + } + break; + case 60: // ONEOF_MESSAGE + case 68: // ONEOF_GROUP + if (isOneofPresent(message, number, pos) + && !isInitialized(message, typeAndOffset, getMessageFieldSchema(pos))) { + return false; + } + break; + case 50: // MAP + if (!isMapInitialized(message, typeAndOffset, pos)) { + return false; + } + break; + default: + break; + } + } + + if (hasExtensions) { + if (!extensionSchema.getExtensions(message).isInitialized()) { + return false; + } + } + + return true; + } + + private static boolean isInitialized(Object message, int typeAndOffset, Schema schema) { + Object nested = UnsafeUtil.getObject(message, offset(typeAndOffset)); + return schema.isInitialized(nested); + } + + private boolean isListInitialized(Object message, int typeAndOffset, int pos) { + @SuppressWarnings("unchecked") + List list = (List) UnsafeUtil.getObject(message, offset(typeAndOffset)); + if (list.isEmpty()) { + return true; + } + + Schema schema = getMessageFieldSchema(pos); + for (int i = 0; i < list.size(); i++) { + N nested = list.get(i); + if (!schema.isInitialized(nested)) { + return false; + } + } + return true; + } + + private boolean isMapInitialized(T message, int typeAndOffset, int pos) { + Map map = mapFieldSchema.forMapData(UnsafeUtil.getObject(message, offset(typeAndOffset))); + if (map.isEmpty()) { + return true; + } + Object mapDefaultEntry = getMapFieldDefaultEntry(pos); + MapEntryLite.Metadata metadata = mapFieldSchema.forMapMetadata(mapDefaultEntry); + if (metadata.valueType.getJavaType() != WireFormat.JavaType.MESSAGE) { + return true; + } + // TODO(dweis): Use schema cache. + Schema schema = null; + for (Object nested : map.values()) { + if (schema == null) { + schema = Protobuf.getInstance().schemaFor(nested.getClass()); + } + if (!schema.isInitialized(nested)) { + return false; + } + } + return true; + } + + private void writeString(int fieldNumber, Object value, Writer writer) throws IOException { + if (value instanceof String) { + writer.writeString(fieldNumber, (String) value); + } else { + writer.writeBytes(fieldNumber, (ByteString) value); + } + } + + private void readString(Object message, int typeAndOffset, Reader reader) throws IOException { + if (isEnforceUtf8(typeAndOffset)) { + // Enforce valid UTF-8 on the read. + UnsafeUtil.putObject(message, offset(typeAndOffset), reader.readStringRequireUtf8()); + } else if (lite) { + // Lite messages use String fields to store strings. Read a string but do not + // enforce UTF-8 + UnsafeUtil.putObject(message, offset(typeAndOffset), reader.readString()); + } else { + // Full runtime messages use Objects to store either a String or ByteString. Read + // the string as a ByteString and do not enforce UTF-8. + UnsafeUtil.putObject(message, offset(typeAndOffset), reader.readBytes()); + } + } + + private void readStringList(Object message, int typeAndOffset, Reader reader) throws IOException { + if (isEnforceUtf8(typeAndOffset)) { + reader.readStringListRequireUtf8( + listFieldSchema.mutableListAt(message, offset(typeAndOffset))); + } else { + reader.readStringList(listFieldSchema.mutableListAt(message, offset(typeAndOffset))); + } + } + + private void readMessageList( + Object message, + int typeAndOffset, + Reader reader, + Schema schema, + ExtensionRegistryLite extensionRegistry) + throws IOException { + long offset = offset(typeAndOffset); + reader.readMessageList( + listFieldSchema.mutableListAt(message, offset), schema, extensionRegistry); + } + + private void readGroupList( + Object message, + long offset, + Reader reader, + Schema schema, + ExtensionRegistryLite extensionRegistry) + throws IOException { + reader.readGroupList( + listFieldSchema.mutableListAt(message, offset), schema, extensionRegistry); + } + + private int numberAt(int pos) { + return buffer[pos]; + } + + private int typeAndOffsetAt(int pos) { + return buffer[pos + 1]; + } + + private int presenceMaskAndOffsetAt(int pos) { + return buffer[pos + 2]; + } + + private static int type(int value) { + return (value & FIELD_TYPE_MASK) >>> OFFSET_BITS; + } + + private static boolean isRequired(int value) { + return (value & REQUIRED_MASK) != 0; + } + + private static boolean isEnforceUtf8(int value) { + return (value & ENFORCE_UTF8_MASK) != 0; + } + + private static long offset(int value) { + return value & OFFSET_MASK; + } + + private static double doubleAt(T message, long offset) { + return UnsafeUtil.getDouble(message, offset); + } + + private static float floatAt(T message, long offset) { + return UnsafeUtil.getFloat(message, offset); + } + + private static int intAt(T message, long offset) { + return UnsafeUtil.getInt(message, offset); + } + + private static long longAt(T message, long offset) { + return UnsafeUtil.getLong(message, offset); + } + + private static boolean booleanAt(T message, long offset) { + return UnsafeUtil.getBoolean(message, offset); + } + + private static double oneofDoubleAt(T message, long offset) { + return ((Double) UnsafeUtil.getObject(message, offset)).doubleValue(); + } + + private static float oneofFloatAt(T message, long offset) { + return ((Float) UnsafeUtil.getObject(message, offset)).floatValue(); + } + + private static int oneofIntAt(T message, long offset) { + return ((Integer) UnsafeUtil.getObject(message, offset)).intValue(); + } + + private static long oneofLongAt(T message, long offset) { + return ((Long) UnsafeUtil.getObject(message, offset)).longValue(); + } + + private static boolean oneofBooleanAt(T message, long offset) { + return ((Boolean) UnsafeUtil.getObject(message, offset)).booleanValue(); + } + + /** Returns true the field is present in both messages, or neither. */ + private boolean arePresentForEquals(T message, T other, int pos) { + return isFieldPresent(message, pos) == isFieldPresent(other, pos); + } + + private boolean isFieldPresent( + T message, int pos, int presenceFieldOffset, int presenceField, int presenceMask) { + if (presenceFieldOffset == NO_PRESENCE_SENTINEL) { + return isFieldPresent(message, pos); + } else { + return (presenceField & presenceMask) != 0; + } + } + + private boolean isFieldPresent(T message, int pos) { + final int presenceMaskAndOffset = presenceMaskAndOffsetAt(pos); + final long presenceFieldOffset = presenceMaskAndOffset & OFFSET_MASK; + if (presenceFieldOffset == NO_PRESENCE_SENTINEL) { + final int typeAndOffset = typeAndOffsetAt(pos); + final long offset = offset(typeAndOffset); + switch (type(typeAndOffset)) { + case 0: // DOUBLE: + return UnsafeUtil.getDouble(message, offset) != 0D; + case 1: // FLOAT: + return UnsafeUtil.getFloat(message, offset) != 0F; + case 2: // INT64: + return UnsafeUtil.getLong(message, offset) != 0L; + case 3: // UINT64: + return UnsafeUtil.getLong(message, offset) != 0L; + case 4: // INT32: + return UnsafeUtil.getInt(message, offset) != 0; + case 5: // FIXED64: + return UnsafeUtil.getLong(message, offset) != 0L; + case 6: // FIXED32: + return UnsafeUtil.getInt(message, offset) != 0; + case 7: // BOOL: + return UnsafeUtil.getBoolean(message, offset); + case 8: // STRING: + Object value = UnsafeUtil.getObject(message, offset); + if (value instanceof String) { + return !((String) value).isEmpty(); + } else if (value instanceof ByteString) { + return !ByteString.EMPTY.equals(value); + } else { + throw new IllegalArgumentException(); + } + case 9: // MESSAGE: + return UnsafeUtil.getObject(message, offset) != null; + case 10: // BYTES: + return !ByteString.EMPTY.equals(UnsafeUtil.getObject(message, offset)); + case 11: // UINT32: + return UnsafeUtil.getInt(message, offset) != 0; + case 12: // ENUM: + return UnsafeUtil.getInt(message, offset) != 0; + case 13: // SFIXED32: + return UnsafeUtil.getInt(message, offset) != 0; + case 14: // SFIXED64: + return UnsafeUtil.getLong(message, offset) != 0L; + case 15: // SINT32: + return UnsafeUtil.getInt(message, offset) != 0; + case 16: // SINT64: + return UnsafeUtil.getLong(message, offset) != 0L; + case 17: // GROUP: + return UnsafeUtil.getObject(message, offset) != null; + default: + throw new IllegalArgumentException(); + } + } else { + final int presenceMask = 1 << (presenceMaskAndOffset >>> OFFSET_BITS); + return (UnsafeUtil.getInt(message, presenceMaskAndOffset & OFFSET_MASK) & presenceMask) != 0; + } + } + + private void setFieldPresent(T message, int pos) { + int presenceMaskAndOffset = presenceMaskAndOffsetAt(pos); + final long presenceFieldOffset = presenceMaskAndOffset & OFFSET_MASK; + if (presenceFieldOffset == NO_PRESENCE_SENTINEL) { + return; + } + final int presenceMask = 1 << (presenceMaskAndOffset >>> OFFSET_BITS); + UnsafeUtil.putInt( + message, + presenceFieldOffset, + UnsafeUtil.getInt(message, presenceFieldOffset) | presenceMask); + } + + private boolean isOneofPresent(T message, int fieldNumber, int pos) { + int presenceMaskAndOffset = presenceMaskAndOffsetAt(pos); + return UnsafeUtil.getInt(message, presenceMaskAndOffset & OFFSET_MASK) == fieldNumber; + } + + private boolean isOneofCaseEqual(T message, T other, int pos) { + int presenceMaskAndOffset = presenceMaskAndOffsetAt(pos); + return UnsafeUtil.getInt(message, presenceMaskAndOffset & OFFSET_MASK) + == UnsafeUtil.getInt(other, presenceMaskAndOffset & OFFSET_MASK); + } + + private void setOneofPresent(T message, int fieldNumber, int pos) { + int presenceMaskAndOffset = presenceMaskAndOffsetAt(pos); + UnsafeUtil.putInt(message, presenceMaskAndOffset & OFFSET_MASK, fieldNumber); + } + + private int positionForFieldNumber(final int number) { + if (number >= minFieldNumber && number <= maxFieldNumber) { + return slowPositionForFieldNumber(number, 0); + } + return -1; + } + + private int positionForFieldNumber(final int number, final int min) { + if (number >= minFieldNumber && number <= maxFieldNumber) { + return slowPositionForFieldNumber(number, min); + } + return -1; + } + + private int slowPositionForFieldNumber(final int number, int min) { + int max = buffer.length / INTS_PER_FIELD - 1; + while (min <= max) { + // Find the midpoint address. + final int mid = (max + min) >>> 1; + final int pos = mid * INTS_PER_FIELD; + final int midFieldNumber = numberAt(pos); + if (number == midFieldNumber) { + // Found the field. + return pos; + } + if (number < midFieldNumber) { + // Search the lower half. + max = mid - 1; + } else { + // Search the upper half. + min = mid + 1; + } + } + return -1; + } + + int getSchemaSize() { + return buffer.length * 3; + } +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/MessageSetSchema.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/MessageSetSchema.java new file mode 100644 index 0000000000000..187dc8b8a5e13 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/MessageSetSchema.java @@ -0,0 +1,392 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +import java.io.IOException; +import java.util.Iterator; +import java.util.Map.Entry; + +/** Schema used for proto2 messages using message_set_wireformat. */ +final class MessageSetSchema implements Schema { + private final MessageLite defaultInstance; + private final UnknownFieldSchema unknownFieldSchema; + private final boolean hasExtensions; + private final ExtensionSchema extensionSchema; + + private MessageSetSchema( + UnknownFieldSchema unknownFieldSchema, + ExtensionSchema extensionSchema, + MessageLite defaultInstance) { + this.unknownFieldSchema = unknownFieldSchema; + this.hasExtensions = extensionSchema.hasExtensions(defaultInstance); + this.extensionSchema = extensionSchema; + this.defaultInstance = defaultInstance; + } + + static MessageSetSchema newSchema( + UnknownFieldSchema unknownFieldSchema, + ExtensionSchema extensionSchema, + MessageLite defaultInstance) { + return new MessageSetSchema(unknownFieldSchema, extensionSchema, defaultInstance); + } + + @SuppressWarnings("unchecked") + @Override + public T newInstance() { + return (T) defaultInstance.newBuilderForType().buildPartial(); + } + + @Override + public boolean equals(T message, T other) { + Object messageUnknown = unknownFieldSchema.getFromMessage(message); + Object otherUnknown = unknownFieldSchema.getFromMessage(other); + if (!messageUnknown.equals(otherUnknown)) { + return false; + } + if (hasExtensions) { + FieldSet messageExtensions = extensionSchema.getExtensions(message); + FieldSet otherExtensions = extensionSchema.getExtensions(other); + return messageExtensions.equals(otherExtensions); + } + return true; + } + + @Override + public int hashCode(T message) { + int hashCode = unknownFieldSchema.getFromMessage(message).hashCode(); + if (hasExtensions) { + FieldSet extensions = extensionSchema.getExtensions(message); + hashCode = (hashCode * 53) + extensions.hashCode(); + } + return hashCode; + } + + @Override + public void mergeFrom(T message, T other) { + SchemaUtil.mergeUnknownFields(unknownFieldSchema, message, other); + if (hasExtensions) { + SchemaUtil.mergeExtensions(extensionSchema, message, other); + } + } + + @SuppressWarnings("unchecked") + @Override + public void writeTo(T message, Writer writer) throws IOException { + FieldSet extensions = extensionSchema.getExtensions(message); + Iterator iterator = extensions.iterator(); + while (iterator.hasNext()) { + Entry extension = (Entry) iterator.next(); + FieldSet.FieldDescriptorLite fd = (FieldSet.FieldDescriptorLite) extension.getKey(); + if (fd.getLiteJavaType() != WireFormat.JavaType.MESSAGE || fd.isRepeated() || fd.isPacked()) { + throw new IllegalStateException("Found invalid MessageSet item."); + } + if (extension instanceof LazyField.LazyEntry) { + writer.writeMessageSetItem( + fd.getNumber(), ((LazyField.LazyEntry) extension).getField().toByteString()); + } else { + writer.writeMessageSetItem(fd.getNumber(), extension.getValue()); + } + } + writeUnknownFieldsHelper(unknownFieldSchema, message, writer); + } + + /** + * A helper method for wildcard capture of {@code unknownFieldSchema}. See: + * https://docs.oracle.com/javase/tutorial/java/generics/capture.html + */ + private void writeUnknownFieldsHelper( + UnknownFieldSchema unknownFieldSchema, T message, Writer writer) throws IOException { + unknownFieldSchema.writeAsMessageSetTo(unknownFieldSchema.getFromMessage(message), writer); + } + + @SuppressWarnings("ReferenceEquality") + @Override + public void mergeFrom( + T message, byte[] data, int position, int limit, ArrayDecoders.Registers registers) + throws IOException { + UnknownFieldSetLite unknownFields = ((GeneratedMessageLite) message).unknownFields; + if (unknownFields == UnknownFieldSetLite.getDefaultInstance()) { + unknownFields = UnknownFieldSetLite.newInstance(); + ((GeneratedMessageLite) message).unknownFields = unknownFields; + } + final FieldSet extensions = + ((GeneratedMessageLite.ExtendableMessage) message).ensureExtensionsAreMutable(); + GeneratedMessageLite.GeneratedExtension extension = null; + while (position < limit) { + position = ArrayDecoders.decodeVarint32(data, position, registers); + final int startTag = registers.int1; + if (startTag != WireFormat.MESSAGE_SET_ITEM_TAG) { + if (WireFormat.getTagWireType(startTag) == WireFormat.WIRETYPE_LENGTH_DELIMITED) { + extension = + (GeneratedMessageLite.GeneratedExtension) extensionSchema.findExtensionByNumber( + registers.extensionRegistry, defaultInstance, + WireFormat.getTagFieldNumber(startTag)); + if (extension != null) { + position = + ArrayDecoders.decodeMessageField( + Protobuf.getInstance().schemaFor( + extension.getMessageDefaultInstance().getClass()), + data, position, limit, registers); + extensions.setField(extension.descriptor, registers.object1); + } else { + position = + ArrayDecoders.decodeUnknownField( + startTag, data, position, limit, unknownFields, registers); + } + } else { + position = ArrayDecoders.skipField(startTag, data, position, limit, registers); + } + continue; + } + + int typeId = 0; + ByteString rawBytes = null; + + while (position < limit) { + position = ArrayDecoders.decodeVarint32(data, position, registers); + final int tag = registers.int1; + final int number = WireFormat.getTagFieldNumber(tag); + final int wireType = WireFormat.getTagWireType(tag); + switch (number) { + case WireFormat.MESSAGE_SET_TYPE_ID: + if (wireType == WireFormat.WIRETYPE_VARINT) { + position = ArrayDecoders.decodeVarint32(data, position, registers); + typeId = registers.int1; + extension = + (GeneratedMessageLite.GeneratedExtension) extensionSchema + .findExtensionByNumber(registers.extensionRegistry, defaultInstance, typeId); + continue; + } + break; + case WireFormat.MESSAGE_SET_MESSAGE: + if (extension != null) { + position = ArrayDecoders.decodeMessageField( + Protobuf.getInstance().schemaFor( + extension.getMessageDefaultInstance().getClass()), + data, position, limit, registers); + extensions.setField(extension.descriptor, registers.object1); + continue; + } else { + if (wireType == WireFormat.WIRETYPE_LENGTH_DELIMITED) { + position = ArrayDecoders.decodeBytes(data, position, registers); + rawBytes = (ByteString) registers.object1; + continue; + } + break; + } + default: + break; + } + if (tag == WireFormat.MESSAGE_SET_ITEM_END_TAG) { + break; + } + position = ArrayDecoders.skipField(tag, data, position, limit, registers); + } + + if (rawBytes != null) { + unknownFields.storeField( + WireFormat.makeTag(typeId, WireFormat.WIRETYPE_LENGTH_DELIMITED), rawBytes); + } + } + if (position != limit) { + throw InvalidProtocolBufferException.parseFailure(); + } + } + + @Override + public void mergeFrom(T message, Reader reader, ExtensionRegistryLite extensionRegistry) + throws IOException { + mergeFromHelper(unknownFieldSchema, extensionSchema, message, reader, extensionRegistry); + } + + /** + * A helper method for wildcard capture of {@code unknownFieldSchema}. See: + * https://docs.oracle.com/javase/tutorial/java/generics/capture.html + */ + @SuppressWarnings("unchecked") + private > void mergeFromHelper( + UnknownFieldSchema unknownFieldSchema, + ExtensionSchema extensionSchema, + T message, + Reader reader, + ExtensionRegistryLite extensionRegistry) + throws IOException { + UB unknownFields = unknownFieldSchema.getBuilderFromMessage(message); + FieldSet extensions = extensionSchema.getMutableExtensions(message); + try { + while (true) { + final int number = reader.getFieldNumber(); + if (number == Reader.READ_DONE) { + return; + } + if (parseMessageSetItemOrUnknownField( + reader, + extensionRegistry, + extensionSchema, + extensions, + unknownFieldSchema, + unknownFields)) { + continue; + } + // Done reading. + return; + } + } finally { + unknownFieldSchema.setBuilderToMessage(message, unknownFields); + } + } + + @Override + public void makeImmutable(T message) { + unknownFieldSchema.makeImmutable(message); + extensionSchema.makeImmutable(message); + } + + private > + boolean parseMessageSetItemOrUnknownField( + Reader reader, + ExtensionRegistryLite extensionRegistry, + ExtensionSchema extensionSchema, + FieldSet extensions, + UnknownFieldSchema unknownFieldSchema, + UB unknownFields) + throws IOException { + int startTag = reader.getTag(); + if (startTag != WireFormat.MESSAGE_SET_ITEM_TAG) { + if (WireFormat.getTagWireType(startTag) == WireFormat.WIRETYPE_LENGTH_DELIMITED) { + Object extension = + extensionSchema.findExtensionByNumber( + extensionRegistry, defaultInstance, WireFormat.getTagFieldNumber(startTag)); + if (extension != null) { + extensionSchema.parseLengthPrefixedMessageSetItem( + reader, extension, extensionRegistry, extensions); + return true; + } else { + return unknownFieldSchema.mergeOneFieldFrom(unknownFields, reader); + } + } else { + return reader.skipField(); + } + } + + // The wire format for MessageSet is: + // message MessageSet { + // repeated group Item = 1 { + // required int32 typeId = 2; + // required bytes message = 3; + // } + // } + // "typeId" is the extension's field number. The extension can only be + // a message type, where "message" contains the encoded bytes of that + // message. + // + // In practice, we will probably never see a MessageSet item in which + // the message appears before the type ID, or where either field does not + // appear exactly once. However, in theory such cases are valid, so we + // should be prepared to accept them. + + int typeId = 0; + ByteString rawBytes = null; // If we encounter "message" before "typeId" + Object extension = null; + + // Read bytes from input, if we get it's type first then parse it eagerly, + // otherwise we store the raw bytes in a local variable. + loop: + while (true) { + final int number = reader.getFieldNumber(); + if (number == Reader.READ_DONE) { + break; + } + + final int tag = reader.getTag(); + if (tag == WireFormat.MESSAGE_SET_TYPE_ID_TAG) { + typeId = reader.readUInt32(); + extension = + extensionSchema.findExtensionByNumber(extensionRegistry, defaultInstance, typeId); + continue; + } else if (tag == WireFormat.MESSAGE_SET_MESSAGE_TAG) { + if (extension != null) { + extensionSchema.parseLengthPrefixedMessageSetItem( + reader, extension, extensionRegistry, extensions); + continue; + } + // We haven't seen a type ID yet or we want parse message lazily. + rawBytes = reader.readBytes(); + continue; + } else { + if (!reader.skipField()) { + break loop; // End of group + } + } + } + + if (reader.getTag() != WireFormat.MESSAGE_SET_ITEM_END_TAG) { + throw InvalidProtocolBufferException.invalidEndTag(); + } + + // If there are any rawBytes left, it means the message content appears before the type ID. + if (rawBytes != null) { + if (extension != null) { // We known the type + // TODO(xiaofeng): Instead of reading into a temporary ByteString, maybe there is a way + // to read directly from Reader to the submessage? + extensionSchema.parseMessageSetItem(rawBytes, extension, extensionRegistry, extensions); + } else { + unknownFieldSchema.addLengthDelimited(unknownFields, typeId, rawBytes); + } + } + return true; + } + + @Override + public final boolean isInitialized(T message) { + FieldSet extensions = extensionSchema.getExtensions(message); + return extensions.isInitialized(); + } + + @Override + public int getSerializedSize(T message) { + int size = 0; + + size += getUnknownFieldsSerializedSize(unknownFieldSchema, message); + + if (hasExtensions) { + size += extensionSchema.getExtensions(message).getMessageSetSerializedSize(); + } + + return size; + } + + private int getUnknownFieldsSerializedSize( + UnknownFieldSchema schema, T message) { + UT unknowns = schema.getFromMessage(message); + return schema.getSerializedSizeAsMessageSet(unknowns); + } +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/Method.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/Method.java new file mode 100644 index 0000000000000..8320af65fccc0 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/Method.java @@ -0,0 +1,1184 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/api.proto + +package com.google.protobuf; + +/** + *
+ * Method represents a method of an API interface.
+ * 
+ * + * Protobuf type {@code google.protobuf.Method} + */ +public final class Method extends + com.google.protobuf.GeneratedMessageLite< + Method, Method.Builder> implements + // @@protoc_insertion_point(message_implements:google.protobuf.Method) + MethodOrBuilder { + private Method() { + name_ = ""; + requestTypeUrl_ = ""; + responseTypeUrl_ = ""; + options_ = emptyProtobufList(); + } + public static final int NAME_FIELD_NUMBER = 1; + private java.lang.String name_; + /** + *
+   * The simple name of this method.
+   * 
+ * + * string name = 1; + * @return The name. + */ + @java.lang.Override + public java.lang.String getName() { + return name_; + } + /** + *
+   * The simple name of this method.
+   * 
+ * + * string name = 1; + * @return The bytes for name. + */ + @java.lang.Override + public com.google.protobuf.ByteString + getNameBytes() { + return com.google.protobuf.ByteString.copyFromUtf8(name_); + } + /** + *
+   * The simple name of this method.
+   * 
+ * + * string name = 1; + * @param value The name to set. + */ + private void setName( + java.lang.String value) { + value.getClass(); + + name_ = value; + } + /** + *
+   * The simple name of this method.
+   * 
+ * + * string name = 1; + */ + private void clearName() { + + name_ = getDefaultInstance().getName(); + } + /** + *
+   * The simple name of this method.
+   * 
+ * + * string name = 1; + * @param value The bytes for name to set. + */ + private void setNameBytes( + com.google.protobuf.ByteString value) { + checkByteStringIsUtf8(value); + name_ = value.toStringUtf8(); + + } + + public static final int REQUEST_TYPE_URL_FIELD_NUMBER = 2; + private java.lang.String requestTypeUrl_; + /** + *
+   * A URL of the input message type.
+   * 
+ * + * string request_type_url = 2; + * @return The requestTypeUrl. + */ + @java.lang.Override + public java.lang.String getRequestTypeUrl() { + return requestTypeUrl_; + } + /** + *
+   * A URL of the input message type.
+   * 
+ * + * string request_type_url = 2; + * @return The bytes for requestTypeUrl. + */ + @java.lang.Override + public com.google.protobuf.ByteString + getRequestTypeUrlBytes() { + return com.google.protobuf.ByteString.copyFromUtf8(requestTypeUrl_); + } + /** + *
+   * A URL of the input message type.
+   * 
+ * + * string request_type_url = 2; + * @param value The requestTypeUrl to set. + */ + private void setRequestTypeUrl( + java.lang.String value) { + value.getClass(); + + requestTypeUrl_ = value; + } + /** + *
+   * A URL of the input message type.
+   * 
+ * + * string request_type_url = 2; + */ + private void clearRequestTypeUrl() { + + requestTypeUrl_ = getDefaultInstance().getRequestTypeUrl(); + } + /** + *
+   * A URL of the input message type.
+   * 
+ * + * string request_type_url = 2; + * @param value The bytes for requestTypeUrl to set. + */ + private void setRequestTypeUrlBytes( + com.google.protobuf.ByteString value) { + checkByteStringIsUtf8(value); + requestTypeUrl_ = value.toStringUtf8(); + + } + + public static final int REQUEST_STREAMING_FIELD_NUMBER = 3; + private boolean requestStreaming_; + /** + *
+   * If true, the request is streamed.
+   * 
+ * + * bool request_streaming = 3; + * @return The requestStreaming. + */ + @java.lang.Override + public boolean getRequestStreaming() { + return requestStreaming_; + } + /** + *
+   * If true, the request is streamed.
+   * 
+ * + * bool request_streaming = 3; + * @param value The requestStreaming to set. + */ + private void setRequestStreaming(boolean value) { + + requestStreaming_ = value; + } + /** + *
+   * If true, the request is streamed.
+   * 
+ * + * bool request_streaming = 3; + */ + private void clearRequestStreaming() { + + requestStreaming_ = false; + } + + public static final int RESPONSE_TYPE_URL_FIELD_NUMBER = 4; + private java.lang.String responseTypeUrl_; + /** + *
+   * The URL of the output message type.
+   * 
+ * + * string response_type_url = 4; + * @return The responseTypeUrl. + */ + @java.lang.Override + public java.lang.String getResponseTypeUrl() { + return responseTypeUrl_; + } + /** + *
+   * The URL of the output message type.
+   * 
+ * + * string response_type_url = 4; + * @return The bytes for responseTypeUrl. + */ + @java.lang.Override + public com.google.protobuf.ByteString + getResponseTypeUrlBytes() { + return com.google.protobuf.ByteString.copyFromUtf8(responseTypeUrl_); + } + /** + *
+   * The URL of the output message type.
+   * 
+ * + * string response_type_url = 4; + * @param value The responseTypeUrl to set. + */ + private void setResponseTypeUrl( + java.lang.String value) { + value.getClass(); + + responseTypeUrl_ = value; + } + /** + *
+   * The URL of the output message type.
+   * 
+ * + * string response_type_url = 4; + */ + private void clearResponseTypeUrl() { + + responseTypeUrl_ = getDefaultInstance().getResponseTypeUrl(); + } + /** + *
+   * The URL of the output message type.
+   * 
+ * + * string response_type_url = 4; + * @param value The bytes for responseTypeUrl to set. + */ + private void setResponseTypeUrlBytes( + com.google.protobuf.ByteString value) { + checkByteStringIsUtf8(value); + responseTypeUrl_ = value.toStringUtf8(); + + } + + public static final int RESPONSE_STREAMING_FIELD_NUMBER = 5; + private boolean responseStreaming_; + /** + *
+   * If true, the response is streamed.
+   * 
+ * + * bool response_streaming = 5; + * @return The responseStreaming. + */ + @java.lang.Override + public boolean getResponseStreaming() { + return responseStreaming_; + } + /** + *
+   * If true, the response is streamed.
+   * 
+ * + * bool response_streaming = 5; + * @param value The responseStreaming to set. + */ + private void setResponseStreaming(boolean value) { + + responseStreaming_ = value; + } + /** + *
+   * If true, the response is streamed.
+   * 
+ * + * bool response_streaming = 5; + */ + private void clearResponseStreaming() { + + responseStreaming_ = false; + } + + public static final int OPTIONS_FIELD_NUMBER = 6; + private com.google.protobuf.Internal.ProtobufList options_; + /** + *
+   * Any metadata attached to the method.
+   * 
+ * + * repeated .google.protobuf.Option options = 6; + */ + @java.lang.Override + public java.util.List getOptionsList() { + return options_; + } + /** + *
+   * Any metadata attached to the method.
+   * 
+ * + * repeated .google.protobuf.Option options = 6; + */ + public java.util.List + getOptionsOrBuilderList() { + return options_; + } + /** + *
+   * Any metadata attached to the method.
+   * 
+ * + * repeated .google.protobuf.Option options = 6; + */ + @java.lang.Override + public int getOptionsCount() { + return options_.size(); + } + /** + *
+   * Any metadata attached to the method.
+   * 
+ * + * repeated .google.protobuf.Option options = 6; + */ + @java.lang.Override + public com.google.protobuf.Option getOptions(int index) { + return options_.get(index); + } + /** + *
+   * Any metadata attached to the method.
+   * 
+ * + * repeated .google.protobuf.Option options = 6; + */ + public com.google.protobuf.OptionOrBuilder getOptionsOrBuilder( + int index) { + return options_.get(index); + } + private void ensureOptionsIsMutable() { + com.google.protobuf.Internal.ProtobufList tmp = options_; + if (!tmp.isModifiable()) { + options_ = + com.google.protobuf.GeneratedMessageLite.mutableCopy(tmp); + } + } + + /** + *
+   * Any metadata attached to the method.
+   * 
+ * + * repeated .google.protobuf.Option options = 6; + */ + private void setOptions( + int index, com.google.protobuf.Option value) { + value.getClass(); + ensureOptionsIsMutable(); + options_.set(index, value); + } + /** + *
+   * Any metadata attached to the method.
+   * 
+ * + * repeated .google.protobuf.Option options = 6; + */ + private void addOptions(com.google.protobuf.Option value) { + value.getClass(); + ensureOptionsIsMutable(); + options_.add(value); + } + /** + *
+   * Any metadata attached to the method.
+   * 
+ * + * repeated .google.protobuf.Option options = 6; + */ + private void addOptions( + int index, com.google.protobuf.Option value) { + value.getClass(); + ensureOptionsIsMutable(); + options_.add(index, value); + } + /** + *
+   * Any metadata attached to the method.
+   * 
+ * + * repeated .google.protobuf.Option options = 6; + */ + private void addAllOptions( + java.lang.Iterable values) { + ensureOptionsIsMutable(); + com.google.protobuf.AbstractMessageLite.addAll( + values, options_); + } + /** + *
+   * Any metadata attached to the method.
+   * 
+ * + * repeated .google.protobuf.Option options = 6; + */ + private void clearOptions() { + options_ = emptyProtobufList(); + } + /** + *
+   * Any metadata attached to the method.
+   * 
+ * + * repeated .google.protobuf.Option options = 6; + */ + private void removeOptions(int index) { + ensureOptionsIsMutable(); + options_.remove(index); + } + + public static final int SYNTAX_FIELD_NUMBER = 7; + private int syntax_; + /** + *
+   * The source syntax of this method.
+   * 
+ * + * .google.protobuf.Syntax syntax = 7; + * @return The enum numeric value on the wire for syntax. + */ + @java.lang.Override + public int getSyntaxValue() { + return syntax_; + } + /** + *
+   * The source syntax of this method.
+   * 
+ * + * .google.protobuf.Syntax syntax = 7; + * @return The syntax. + */ + @java.lang.Override + public com.google.protobuf.Syntax getSyntax() { + com.google.protobuf.Syntax result = com.google.protobuf.Syntax.forNumber(syntax_); + return result == null ? com.google.protobuf.Syntax.UNRECOGNIZED : result; + } + /** + *
+   * The source syntax of this method.
+   * 
+ * + * .google.protobuf.Syntax syntax = 7; + * @param value The enum numeric value on the wire for syntax to set. + */ + private void setSyntaxValue(int value) { + syntax_ = value; + } + /** + *
+   * The source syntax of this method.
+   * 
+ * + * .google.protobuf.Syntax syntax = 7; + * @param value The syntax to set. + */ + private void setSyntax(com.google.protobuf.Syntax value) { + syntax_ = value.getNumber(); + + } + /** + *
+   * The source syntax of this method.
+   * 
+ * + * .google.protobuf.Syntax syntax = 7; + */ + private void clearSyntax() { + + syntax_ = 0; + } + + public static com.google.protobuf.Method parseFrom( + java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.Method parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.Method parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.Method parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.Method parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.Method parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.Method parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, 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.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, input, extensionRegistry); + } + public static com.google.protobuf.Method parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return parseDelimitedFrom(DEFAULT_INSTANCE, input); + } + public static com.google.protobuf.Method parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return parseDelimitedFrom(DEFAULT_INSTANCE, input, extensionRegistry); + } + public static com.google.protobuf.Method parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, 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.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, input, extensionRegistry); + } + + public static Builder newBuilder() { + return (Builder) DEFAULT_INSTANCE.createBuilder(); + } + public static Builder newBuilder(com.google.protobuf.Method prototype) { + return (Builder) DEFAULT_INSTANCE.createBuilder(prototype); + } + + /** + *
+   * Method represents a method of an API interface.
+   * 
+ * + * Protobuf type {@code google.protobuf.Method} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessageLite.Builder< + com.google.protobuf.Method, Builder> implements + // @@protoc_insertion_point(builder_implements:google.protobuf.Method) + com.google.protobuf.MethodOrBuilder { + // Construct using com.google.protobuf.Method.newBuilder() + private Builder() { + super(DEFAULT_INSTANCE); + } + + + /** + *
+     * The simple name of this method.
+     * 
+ * + * string name = 1; + * @return The name. + */ + @java.lang.Override + public java.lang.String getName() { + return instance.getName(); + } + /** + *
+     * The simple name of this method.
+     * 
+ * + * string name = 1; + * @return The bytes for name. + */ + @java.lang.Override + public com.google.protobuf.ByteString + getNameBytes() { + return instance.getNameBytes(); + } + /** + *
+     * The simple name of this method.
+     * 
+ * + * string name = 1; + * @param value The name to set. + * @return This builder for chaining. + */ + public Builder setName( + java.lang.String value) { + copyOnWrite(); + instance.setName(value); + return this; + } + /** + *
+     * The simple name of this method.
+     * 
+ * + * string name = 1; + * @return This builder for chaining. + */ + public Builder clearName() { + copyOnWrite(); + instance.clearName(); + return this; + } + /** + *
+     * The simple name of this method.
+     * 
+ * + * string name = 1; + * @param value The bytes for name to set. + * @return This builder for chaining. + */ + public Builder setNameBytes( + com.google.protobuf.ByteString value) { + copyOnWrite(); + instance.setNameBytes(value); + return this; + } + + /** + *
+     * A URL of the input message type.
+     * 
+ * + * string request_type_url = 2; + * @return The requestTypeUrl. + */ + @java.lang.Override + public java.lang.String getRequestTypeUrl() { + return instance.getRequestTypeUrl(); + } + /** + *
+     * A URL of the input message type.
+     * 
+ * + * string request_type_url = 2; + * @return The bytes for requestTypeUrl. + */ + @java.lang.Override + public com.google.protobuf.ByteString + getRequestTypeUrlBytes() { + return instance.getRequestTypeUrlBytes(); + } + /** + *
+     * A URL of the input message type.
+     * 
+ * + * string request_type_url = 2; + * @param value The requestTypeUrl to set. + * @return This builder for chaining. + */ + public Builder setRequestTypeUrl( + java.lang.String value) { + copyOnWrite(); + instance.setRequestTypeUrl(value); + return this; + } + /** + *
+     * A URL of the input message type.
+     * 
+ * + * string request_type_url = 2; + * @return This builder for chaining. + */ + public Builder clearRequestTypeUrl() { + copyOnWrite(); + instance.clearRequestTypeUrl(); + return this; + } + /** + *
+     * A URL of the input message type.
+     * 
+ * + * string request_type_url = 2; + * @param value The bytes for requestTypeUrl to set. + * @return This builder for chaining. + */ + public Builder setRequestTypeUrlBytes( + com.google.protobuf.ByteString value) { + copyOnWrite(); + instance.setRequestTypeUrlBytes(value); + return this; + } + + /** + *
+     * If true, the request is streamed.
+     * 
+ * + * bool request_streaming = 3; + * @return The requestStreaming. + */ + @java.lang.Override + public boolean getRequestStreaming() { + return instance.getRequestStreaming(); + } + /** + *
+     * If true, the request is streamed.
+     * 
+ * + * bool request_streaming = 3; + * @param value The requestStreaming to set. + * @return This builder for chaining. + */ + public Builder setRequestStreaming(boolean value) { + copyOnWrite(); + instance.setRequestStreaming(value); + return this; + } + /** + *
+     * If true, the request is streamed.
+     * 
+ * + * bool request_streaming = 3; + * @return This builder for chaining. + */ + public Builder clearRequestStreaming() { + copyOnWrite(); + instance.clearRequestStreaming(); + return this; + } + + /** + *
+     * The URL of the output message type.
+     * 
+ * + * string response_type_url = 4; + * @return The responseTypeUrl. + */ + @java.lang.Override + public java.lang.String getResponseTypeUrl() { + return instance.getResponseTypeUrl(); + } + /** + *
+     * The URL of the output message type.
+     * 
+ * + * string response_type_url = 4; + * @return The bytes for responseTypeUrl. + */ + @java.lang.Override + public com.google.protobuf.ByteString + getResponseTypeUrlBytes() { + return instance.getResponseTypeUrlBytes(); + } + /** + *
+     * The URL of the output message type.
+     * 
+ * + * string response_type_url = 4; + * @param value The responseTypeUrl to set. + * @return This builder for chaining. + */ + public Builder setResponseTypeUrl( + java.lang.String value) { + copyOnWrite(); + instance.setResponseTypeUrl(value); + return this; + } + /** + *
+     * The URL of the output message type.
+     * 
+ * + * string response_type_url = 4; + * @return This builder for chaining. + */ + public Builder clearResponseTypeUrl() { + copyOnWrite(); + instance.clearResponseTypeUrl(); + return this; + } + /** + *
+     * The URL of the output message type.
+     * 
+ * + * string response_type_url = 4; + * @param value The bytes for responseTypeUrl to set. + * @return This builder for chaining. + */ + public Builder setResponseTypeUrlBytes( + com.google.protobuf.ByteString value) { + copyOnWrite(); + instance.setResponseTypeUrlBytes(value); + return this; + } + + /** + *
+     * If true, the response is streamed.
+     * 
+ * + * bool response_streaming = 5; + * @return The responseStreaming. + */ + @java.lang.Override + public boolean getResponseStreaming() { + return instance.getResponseStreaming(); + } + /** + *
+     * If true, the response is streamed.
+     * 
+ * + * bool response_streaming = 5; + * @param value The responseStreaming to set. + * @return This builder for chaining. + */ + public Builder setResponseStreaming(boolean value) { + copyOnWrite(); + instance.setResponseStreaming(value); + return this; + } + /** + *
+     * If true, the response is streamed.
+     * 
+ * + * bool response_streaming = 5; + * @return This builder for chaining. + */ + public Builder clearResponseStreaming() { + copyOnWrite(); + instance.clearResponseStreaming(); + return this; + } + + /** + *
+     * Any metadata attached to the method.
+     * 
+ * + * repeated .google.protobuf.Option options = 6; + */ + @java.lang.Override + public java.util.List getOptionsList() { + return java.util.Collections.unmodifiableList( + instance.getOptionsList()); + } + /** + *
+     * Any metadata attached to the method.
+     * 
+ * + * repeated .google.protobuf.Option options = 6; + */ + @java.lang.Override + public int getOptionsCount() { + return instance.getOptionsCount(); + }/** + *
+     * Any metadata attached to the method.
+     * 
+ * + * repeated .google.protobuf.Option options = 6; + */ + @java.lang.Override + public com.google.protobuf.Option getOptions(int index) { + return instance.getOptions(index); + } + /** + *
+     * Any metadata attached to the method.
+     * 
+ * + * repeated .google.protobuf.Option options = 6; + */ + public Builder setOptions( + int index, com.google.protobuf.Option value) { + copyOnWrite(); + instance.setOptions(index, value); + return this; + } + /** + *
+     * Any metadata attached to the method.
+     * 
+ * + * repeated .google.protobuf.Option options = 6; + */ + public Builder setOptions( + int index, com.google.protobuf.Option.Builder builderForValue) { + copyOnWrite(); + instance.setOptions(index, + builderForValue.build()); + return this; + } + /** + *
+     * Any metadata attached to the method.
+     * 
+ * + * repeated .google.protobuf.Option options = 6; + */ + public Builder addOptions(com.google.protobuf.Option value) { + copyOnWrite(); + instance.addOptions(value); + return this; + } + /** + *
+     * Any metadata attached to the method.
+     * 
+ * + * repeated .google.protobuf.Option options = 6; + */ + public Builder addOptions( + int index, com.google.protobuf.Option value) { + copyOnWrite(); + instance.addOptions(index, value); + return this; + } + /** + *
+     * Any metadata attached to the method.
+     * 
+ * + * repeated .google.protobuf.Option options = 6; + */ + public Builder addOptions( + com.google.protobuf.Option.Builder builderForValue) { + copyOnWrite(); + instance.addOptions(builderForValue.build()); + return this; + } + /** + *
+     * Any metadata attached to the method.
+     * 
+ * + * repeated .google.protobuf.Option options = 6; + */ + public Builder addOptions( + int index, com.google.protobuf.Option.Builder builderForValue) { + copyOnWrite(); + instance.addOptions(index, + builderForValue.build()); + return this; + } + /** + *
+     * Any metadata attached to the method.
+     * 
+ * + * repeated .google.protobuf.Option options = 6; + */ + public Builder addAllOptions( + java.lang.Iterable values) { + copyOnWrite(); + instance.addAllOptions(values); + return this; + } + /** + *
+     * Any metadata attached to the method.
+     * 
+ * + * repeated .google.protobuf.Option options = 6; + */ + public Builder clearOptions() { + copyOnWrite(); + instance.clearOptions(); + return this; + } + /** + *
+     * Any metadata attached to the method.
+     * 
+ * + * repeated .google.protobuf.Option options = 6; + */ + public Builder removeOptions(int index) { + copyOnWrite(); + instance.removeOptions(index); + return this; + } + + /** + *
+     * The source syntax of this method.
+     * 
+ * + * .google.protobuf.Syntax syntax = 7; + * @return The enum numeric value on the wire for syntax. + */ + @java.lang.Override + public int getSyntaxValue() { + return instance.getSyntaxValue(); + } + /** + *
+     * The source syntax of this method.
+     * 
+ * + * .google.protobuf.Syntax syntax = 7; + * @param value The syntax to set. + * @return This builder for chaining. + */ + public Builder setSyntaxValue(int value) { + copyOnWrite(); + instance.setSyntaxValue(value); + return this; + } + /** + *
+     * The source syntax of this method.
+     * 
+ * + * .google.protobuf.Syntax syntax = 7; + * @return The syntax. + */ + @java.lang.Override + public com.google.protobuf.Syntax getSyntax() { + return instance.getSyntax(); + } + /** + *
+     * The source syntax of this method.
+     * 
+ * + * .google.protobuf.Syntax syntax = 7; + * @param value The enum numeric value on the wire for syntax to set. + * @return This builder for chaining. + */ + public Builder setSyntax(com.google.protobuf.Syntax value) { + copyOnWrite(); + instance.setSyntax(value); + return this; + } + /** + *
+     * The source syntax of this method.
+     * 
+ * + * .google.protobuf.Syntax syntax = 7; + * @return This builder for chaining. + */ + public Builder clearSyntax() { + copyOnWrite(); + instance.clearSyntax(); + return this; + } + + // @@protoc_insertion_point(builder_scope:google.protobuf.Method) + } + @java.lang.Override + @java.lang.SuppressWarnings({"unchecked", "fallthrough"}) + protected final java.lang.Object dynamicMethod( + com.google.protobuf.GeneratedMessageLite.MethodToInvoke method, + java.lang.Object arg0, java.lang.Object arg1) { + switch (method) { + case NEW_MUTABLE_INSTANCE: { + return new com.google.protobuf.Method(); + } + case NEW_BUILDER: { + return new Builder(); + } + case BUILD_MESSAGE_INFO: { + java.lang.Object[] objects = new java.lang.Object[] { + "name_", + "requestTypeUrl_", + "requestStreaming_", + "responseTypeUrl_", + "responseStreaming_", + "options_", + com.google.protobuf.Option.class, + "syntax_", + }; + java.lang.String info = + "\u0000\u0007\u0000\u0000\u0001\u0007\u0007\u0000\u0001\u0000\u0001\u0208\u0002\u0208" + + "\u0003\u0007\u0004\u0208\u0005\u0007\u0006\u001b\u0007\f"; + return newMessageInfo(DEFAULT_INSTANCE, info, objects); + } + // fall through + case GET_DEFAULT_INSTANCE: { + return DEFAULT_INSTANCE; + } + case GET_PARSER: { + com.google.protobuf.Parser parser = PARSER; + if (parser == null) { + synchronized (com.google.protobuf.Method.class) { + parser = PARSER; + if (parser == null) { + parser = + new DefaultInstanceBasedParser( + DEFAULT_INSTANCE); + PARSER = parser; + } + } + } + return parser; + } + case GET_MEMOIZED_IS_INITIALIZED: { + return (byte) 1; + } + case SET_MEMOIZED_IS_INITIALIZED: { + return null; + } + } + throw new UnsupportedOperationException(); + } + + + // @@protoc_insertion_point(class_scope:google.protobuf.Method) + private static final com.google.protobuf.Method DEFAULT_INSTANCE; + static { + Method defaultInstance = new Method(); + // New instances are implicitly immutable so no need to make + // immutable. + DEFAULT_INSTANCE = defaultInstance; + com.google.protobuf.GeneratedMessageLite.registerDefaultInstance( + Method.class, defaultInstance); + } + + public static com.google.protobuf.Method getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static volatile com.google.protobuf.Parser PARSER; + + public static com.google.protobuf.Parser parser() { + return DEFAULT_INSTANCE.getParserForType(); + } +} + diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/MethodOrBuilder.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/MethodOrBuilder.java new file mode 100644 index 0000000000000..402432d474a74 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/MethodOrBuilder.java @@ -0,0 +1,134 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/api.proto + +package com.google.protobuf; + +public interface MethodOrBuilder extends + // @@protoc_insertion_point(interface_extends:google.protobuf.Method) + com.google.protobuf.MessageLiteOrBuilder { + + /** + *
+   * The simple name of this method.
+   * 
+ * + * string name = 1; + * @return The name. + */ + java.lang.String getName(); + /** + *
+   * The simple name of this method.
+   * 
+ * + * string name = 1; + * @return The bytes for name. + */ + com.google.protobuf.ByteString + getNameBytes(); + + /** + *
+   * A URL of the input message type.
+   * 
+ * + * string request_type_url = 2; + * @return The requestTypeUrl. + */ + java.lang.String getRequestTypeUrl(); + /** + *
+   * A URL of the input message type.
+   * 
+ * + * string request_type_url = 2; + * @return The bytes for requestTypeUrl. + */ + com.google.protobuf.ByteString + getRequestTypeUrlBytes(); + + /** + *
+   * If true, the request is streamed.
+   * 
+ * + * bool request_streaming = 3; + * @return The requestStreaming. + */ + boolean getRequestStreaming(); + + /** + *
+   * The URL of the output message type.
+   * 
+ * + * string response_type_url = 4; + * @return The responseTypeUrl. + */ + java.lang.String getResponseTypeUrl(); + /** + *
+   * The URL of the output message type.
+   * 
+ * + * string response_type_url = 4; + * @return The bytes for responseTypeUrl. + */ + com.google.protobuf.ByteString + getResponseTypeUrlBytes(); + + /** + *
+   * If true, the response is streamed.
+   * 
+ * + * bool response_streaming = 5; + * @return The responseStreaming. + */ + boolean getResponseStreaming(); + + /** + *
+   * Any metadata attached to the method.
+   * 
+ * + * repeated .google.protobuf.Option options = 6; + */ + java.util.List + getOptionsList(); + /** + *
+   * Any metadata attached to the method.
+   * 
+ * + * repeated .google.protobuf.Option options = 6; + */ + com.google.protobuf.Option getOptions(int index); + /** + *
+   * Any metadata attached to the method.
+   * 
+ * + * repeated .google.protobuf.Option options = 6; + */ + int getOptionsCount(); + + /** + *
+   * The source syntax of this method.
+   * 
+ * + * .google.protobuf.Syntax syntax = 7; + * @return The enum numeric value on the wire for syntax. + */ + int getSyntaxValue(); + /** + *
+   * The source syntax of this method.
+   * 
+ * + * .google.protobuf.Syntax syntax = 7; + * @return The syntax. + */ + com.google.protobuf.Syntax getSyntax(); +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/Mixin.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/Mixin.java new file mode 100644 index 0000000000000..6a67f263ff153 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/Mixin.java @@ -0,0 +1,600 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/api.proto + +package com.google.protobuf; + +/** + *
+ * Declares an API Interface to be included in this interface. The including
+ * interface must redeclare all the methods from the included interface, but
+ * documentation and options are inherited as follows:
+ * - If after comment and whitespace stripping, the documentation
+ *   string of the redeclared method is empty, it will be inherited
+ *   from the original method.
+ * - Each annotation belonging to the service config (http,
+ *   visibility) which is not set in the redeclared method will be
+ *   inherited.
+ * - If an http annotation is inherited, the path pattern will be
+ *   modified as follows. Any version prefix will be replaced by the
+ *   version of the including interface plus the [root][] path if
+ *   specified.
+ * Example of a simple mixin:
+ *     package google.acl.v1;
+ *     service AccessControl {
+ *       // Get the underlying ACL object.
+ *       rpc GetAcl(GetAclRequest) returns (Acl) {
+ *         option (google.api.http).get = "/v1/{resource=**}:getAcl";
+ *       }
+ *     }
+ *     package google.storage.v2;
+ *     service Storage {
+ *       rpc GetAcl(GetAclRequest) returns (Acl);
+ *       // Get a data record.
+ *       rpc GetData(GetDataRequest) returns (Data) {
+ *         option (google.api.http).get = "/v2/{resource=**}";
+ *       }
+ *     }
+ * Example of a mixin configuration:
+ *     apis:
+ *     - name: google.storage.v2.Storage
+ *       mixins:
+ *       - name: google.acl.v1.AccessControl
+ * The mixin construct implies that all methods in `AccessControl` are
+ * also declared with same name and request/response types in
+ * `Storage`. A documentation generator or annotation processor will
+ * see the effective `Storage.GetAcl` method after inheriting
+ * documentation and annotations as follows:
+ *     service Storage {
+ *       // Get the underlying ACL object.
+ *       rpc GetAcl(GetAclRequest) returns (Acl) {
+ *         option (google.api.http).get = "/v2/{resource=**}:getAcl";
+ *       }
+ *       ...
+ *     }
+ * Note how the version in the path pattern changed from `v1` to `v2`.
+ * If the `root` field in the mixin is specified, it should be a
+ * relative path under which inherited HTTP paths are placed. Example:
+ *     apis:
+ *     - name: google.storage.v2.Storage
+ *       mixins:
+ *       - name: google.acl.v1.AccessControl
+ *         root: acls
+ * This implies the following inherited HTTP annotation:
+ *     service Storage {
+ *       // Get the underlying ACL object.
+ *       rpc GetAcl(GetAclRequest) returns (Acl) {
+ *         option (google.api.http).get = "/v2/acls/{resource=**}:getAcl";
+ *       }
+ *       ...
+ *     }
+ * 
+ * + * Protobuf type {@code google.protobuf.Mixin} + */ +public final class Mixin extends + com.google.protobuf.GeneratedMessageLite< + Mixin, Mixin.Builder> implements + // @@protoc_insertion_point(message_implements:google.protobuf.Mixin) + MixinOrBuilder { + private Mixin() { + name_ = ""; + root_ = ""; + } + public static final int NAME_FIELD_NUMBER = 1; + private java.lang.String name_; + /** + *
+   * The fully qualified name of the interface which is included.
+   * 
+ * + * string name = 1; + * @return The name. + */ + @java.lang.Override + public java.lang.String getName() { + return name_; + } + /** + *
+   * The fully qualified name of the interface which is included.
+   * 
+ * + * string name = 1; + * @return The bytes for name. + */ + @java.lang.Override + public com.google.protobuf.ByteString + getNameBytes() { + return com.google.protobuf.ByteString.copyFromUtf8(name_); + } + /** + *
+   * The fully qualified name of the interface which is included.
+   * 
+ * + * string name = 1; + * @param value The name to set. + */ + private void setName( + java.lang.String value) { + value.getClass(); + + name_ = value; + } + /** + *
+   * The fully qualified name of the interface which is included.
+   * 
+ * + * string name = 1; + */ + private void clearName() { + + name_ = getDefaultInstance().getName(); + } + /** + *
+   * The fully qualified name of the interface which is included.
+   * 
+ * + * string name = 1; + * @param value The bytes for name to set. + */ + private void setNameBytes( + com.google.protobuf.ByteString value) { + checkByteStringIsUtf8(value); + name_ = value.toStringUtf8(); + + } + + public static final int ROOT_FIELD_NUMBER = 2; + private java.lang.String root_; + /** + *
+   * If non-empty specifies a path under which inherited HTTP paths
+   * are rooted.
+   * 
+ * + * string root = 2; + * @return The root. + */ + @java.lang.Override + public java.lang.String getRoot() { + return root_; + } + /** + *
+   * If non-empty specifies a path under which inherited HTTP paths
+   * are rooted.
+   * 
+ * + * string root = 2; + * @return The bytes for root. + */ + @java.lang.Override + public com.google.protobuf.ByteString + getRootBytes() { + return com.google.protobuf.ByteString.copyFromUtf8(root_); + } + /** + *
+   * If non-empty specifies a path under which inherited HTTP paths
+   * are rooted.
+   * 
+ * + * string root = 2; + * @param value The root to set. + */ + private void setRoot( + java.lang.String value) { + value.getClass(); + + root_ = value; + } + /** + *
+   * If non-empty specifies a path under which inherited HTTP paths
+   * are rooted.
+   * 
+ * + * string root = 2; + */ + private void clearRoot() { + + root_ = getDefaultInstance().getRoot(); + } + /** + *
+   * If non-empty specifies a path under which inherited HTTP paths
+   * are rooted.
+   * 
+ * + * string root = 2; + * @param value The bytes for root to set. + */ + private void setRootBytes( + com.google.protobuf.ByteString value) { + checkByteStringIsUtf8(value); + root_ = value.toStringUtf8(); + + } + + public static com.google.protobuf.Mixin parseFrom( + java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.Mixin parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.Mixin parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.Mixin parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.Mixin parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.Mixin parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.Mixin parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, 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.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, input, extensionRegistry); + } + public static com.google.protobuf.Mixin parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return parseDelimitedFrom(DEFAULT_INSTANCE, input); + } + public static com.google.protobuf.Mixin parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return parseDelimitedFrom(DEFAULT_INSTANCE, input, extensionRegistry); + } + public static com.google.protobuf.Mixin parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, 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.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, input, extensionRegistry); + } + + public static Builder newBuilder() { + return (Builder) DEFAULT_INSTANCE.createBuilder(); + } + public static Builder newBuilder(com.google.protobuf.Mixin prototype) { + return (Builder) DEFAULT_INSTANCE.createBuilder(prototype); + } + + /** + *
+   * Declares an API Interface to be included in this interface. The including
+   * interface must redeclare all the methods from the included interface, but
+   * documentation and options are inherited as follows:
+   * - If after comment and whitespace stripping, the documentation
+   *   string of the redeclared method is empty, it will be inherited
+   *   from the original method.
+   * - Each annotation belonging to the service config (http,
+   *   visibility) which is not set in the redeclared method will be
+   *   inherited.
+   * - If an http annotation is inherited, the path pattern will be
+   *   modified as follows. Any version prefix will be replaced by the
+   *   version of the including interface plus the [root][] path if
+   *   specified.
+   * Example of a simple mixin:
+   *     package google.acl.v1;
+   *     service AccessControl {
+   *       // Get the underlying ACL object.
+   *       rpc GetAcl(GetAclRequest) returns (Acl) {
+   *         option (google.api.http).get = "/v1/{resource=**}:getAcl";
+   *       }
+   *     }
+   *     package google.storage.v2;
+   *     service Storage {
+   *       rpc GetAcl(GetAclRequest) returns (Acl);
+   *       // Get a data record.
+   *       rpc GetData(GetDataRequest) returns (Data) {
+   *         option (google.api.http).get = "/v2/{resource=**}";
+   *       }
+   *     }
+   * Example of a mixin configuration:
+   *     apis:
+   *     - name: google.storage.v2.Storage
+   *       mixins:
+   *       - name: google.acl.v1.AccessControl
+   * The mixin construct implies that all methods in `AccessControl` are
+   * also declared with same name and request/response types in
+   * `Storage`. A documentation generator or annotation processor will
+   * see the effective `Storage.GetAcl` method after inheriting
+   * documentation and annotations as follows:
+   *     service Storage {
+   *       // Get the underlying ACL object.
+   *       rpc GetAcl(GetAclRequest) returns (Acl) {
+   *         option (google.api.http).get = "/v2/{resource=**}:getAcl";
+   *       }
+   *       ...
+   *     }
+   * Note how the version in the path pattern changed from `v1` to `v2`.
+   * If the `root` field in the mixin is specified, it should be a
+   * relative path under which inherited HTTP paths are placed. Example:
+   *     apis:
+   *     - name: google.storage.v2.Storage
+   *       mixins:
+   *       - name: google.acl.v1.AccessControl
+   *         root: acls
+   * This implies the following inherited HTTP annotation:
+   *     service Storage {
+   *       // Get the underlying ACL object.
+   *       rpc GetAcl(GetAclRequest) returns (Acl) {
+   *         option (google.api.http).get = "/v2/acls/{resource=**}:getAcl";
+   *       }
+   *       ...
+   *     }
+   * 
+ * + * Protobuf type {@code google.protobuf.Mixin} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessageLite.Builder< + com.google.protobuf.Mixin, Builder> implements + // @@protoc_insertion_point(builder_implements:google.protobuf.Mixin) + com.google.protobuf.MixinOrBuilder { + // Construct using com.google.protobuf.Mixin.newBuilder() + private Builder() { + super(DEFAULT_INSTANCE); + } + + + /** + *
+     * The fully qualified name of the interface which is included.
+     * 
+ * + * string name = 1; + * @return The name. + */ + @java.lang.Override + public java.lang.String getName() { + return instance.getName(); + } + /** + *
+     * The fully qualified name of the interface which is included.
+     * 
+ * + * string name = 1; + * @return The bytes for name. + */ + @java.lang.Override + public com.google.protobuf.ByteString + getNameBytes() { + return instance.getNameBytes(); + } + /** + *
+     * The fully qualified name of the interface which is included.
+     * 
+ * + * string name = 1; + * @param value The name to set. + * @return This builder for chaining. + */ + public Builder setName( + java.lang.String value) { + copyOnWrite(); + instance.setName(value); + return this; + } + /** + *
+     * The fully qualified name of the interface which is included.
+     * 
+ * + * string name = 1; + * @return This builder for chaining. + */ + public Builder clearName() { + copyOnWrite(); + instance.clearName(); + return this; + } + /** + *
+     * The fully qualified name of the interface which is included.
+     * 
+ * + * string name = 1; + * @param value The bytes for name to set. + * @return This builder for chaining. + */ + public Builder setNameBytes( + com.google.protobuf.ByteString value) { + copyOnWrite(); + instance.setNameBytes(value); + return this; + } + + /** + *
+     * If non-empty specifies a path under which inherited HTTP paths
+     * are rooted.
+     * 
+ * + * string root = 2; + * @return The root. + */ + @java.lang.Override + public java.lang.String getRoot() { + return instance.getRoot(); + } + /** + *
+     * If non-empty specifies a path under which inherited HTTP paths
+     * are rooted.
+     * 
+ * + * string root = 2; + * @return The bytes for root. + */ + @java.lang.Override + public com.google.protobuf.ByteString + getRootBytes() { + return instance.getRootBytes(); + } + /** + *
+     * If non-empty specifies a path under which inherited HTTP paths
+     * are rooted.
+     * 
+ * + * string root = 2; + * @param value The root to set. + * @return This builder for chaining. + */ + public Builder setRoot( + java.lang.String value) { + copyOnWrite(); + instance.setRoot(value); + return this; + } + /** + *
+     * If non-empty specifies a path under which inherited HTTP paths
+     * are rooted.
+     * 
+ * + * string root = 2; + * @return This builder for chaining. + */ + public Builder clearRoot() { + copyOnWrite(); + instance.clearRoot(); + return this; + } + /** + *
+     * If non-empty specifies a path under which inherited HTTP paths
+     * are rooted.
+     * 
+ * + * string root = 2; + * @param value The bytes for root to set. + * @return This builder for chaining. + */ + public Builder setRootBytes( + com.google.protobuf.ByteString value) { + copyOnWrite(); + instance.setRootBytes(value); + return this; + } + + // @@protoc_insertion_point(builder_scope:google.protobuf.Mixin) + } + @java.lang.Override + @java.lang.SuppressWarnings({"unchecked", "fallthrough"}) + protected final java.lang.Object dynamicMethod( + com.google.protobuf.GeneratedMessageLite.MethodToInvoke method, + java.lang.Object arg0, java.lang.Object arg1) { + switch (method) { + case NEW_MUTABLE_INSTANCE: { + return new com.google.protobuf.Mixin(); + } + case NEW_BUILDER: { + return new Builder(); + } + case BUILD_MESSAGE_INFO: { + java.lang.Object[] objects = new java.lang.Object[] { + "name_", + "root_", + }; + java.lang.String info = + "\u0000\u0002\u0000\u0000\u0001\u0002\u0002\u0000\u0000\u0000\u0001\u0208\u0002\u0208" + + ""; + return newMessageInfo(DEFAULT_INSTANCE, info, objects); + } + // fall through + case GET_DEFAULT_INSTANCE: { + return DEFAULT_INSTANCE; + } + case GET_PARSER: { + com.google.protobuf.Parser parser = PARSER; + if (parser == null) { + synchronized (com.google.protobuf.Mixin.class) { + parser = PARSER; + if (parser == null) { + parser = + new DefaultInstanceBasedParser( + DEFAULT_INSTANCE); + PARSER = parser; + } + } + } + return parser; + } + case GET_MEMOIZED_IS_INITIALIZED: { + return (byte) 1; + } + case SET_MEMOIZED_IS_INITIALIZED: { + return null; + } + } + throw new UnsupportedOperationException(); + } + + + // @@protoc_insertion_point(class_scope:google.protobuf.Mixin) + private static final com.google.protobuf.Mixin DEFAULT_INSTANCE; + static { + Mixin defaultInstance = new Mixin(); + // New instances are implicitly immutable so no need to make + // immutable. + DEFAULT_INSTANCE = defaultInstance; + com.google.protobuf.GeneratedMessageLite.registerDefaultInstance( + Mixin.class, defaultInstance); + } + + public static com.google.protobuf.Mixin getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static volatile com.google.protobuf.Parser PARSER; + + public static com.google.protobuf.Parser parser() { + return DEFAULT_INSTANCE.getParserForType(); + } +} + diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/MixinOrBuilder.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/MixinOrBuilder.java new file mode 100644 index 0000000000000..7808cdc41d4c5 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/MixinOrBuilder.java @@ -0,0 +1,51 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/api.proto + +package com.google.protobuf; + +public interface MixinOrBuilder extends + // @@protoc_insertion_point(interface_extends:google.protobuf.Mixin) + com.google.protobuf.MessageLiteOrBuilder { + + /** + *
+   * The fully qualified name of the interface which is included.
+   * 
+ * + * string name = 1; + * @return The name. + */ + java.lang.String getName(); + /** + *
+   * The fully qualified name of the interface which is included.
+   * 
+ * + * string name = 1; + * @return The bytes for name. + */ + com.google.protobuf.ByteString + getNameBytes(); + + /** + *
+   * If non-empty specifies a path under which inherited HTTP paths
+   * are rooted.
+   * 
+ * + * string root = 2; + * @return The root. + */ + java.lang.String getRoot(); + /** + *
+   * If non-empty specifies a path under which inherited HTTP paths
+   * are rooted.
+   * 
+ * + * string root = 2; + * @return The bytes for root. + */ + com.google.protobuf.ByteString + getRootBytes(); +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/MutabilityOracle.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/MutabilityOracle.java new file mode 100644 index 0000000000000..7c2f157567543 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/MutabilityOracle.java @@ -0,0 +1,45 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +/** Verifies that an object is mutable, throwing if not. */ +interface MutabilityOracle { + static final MutabilityOracle IMMUTABLE = + new MutabilityOracle() { + @Override + public void ensureMutable() { + throw new UnsupportedOperationException(); + } + }; + + /** Throws an {@link UnsupportedOperationException} if not mutable. */ + void ensureMutable(); +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/NewInstanceSchema.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/NewInstanceSchema.java new file mode 100644 index 0000000000000..f2dbb8ef9cc11 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/NewInstanceSchema.java @@ -0,0 +1,36 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +interface NewInstanceSchema { + /** Create a new message instance given the default instance of the message type. */ + Object newInstance(Object defaultInstance); +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/NewInstanceSchemaLite.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/NewInstanceSchemaLite.java new file mode 100644 index 0000000000000..9b922667638d2 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/NewInstanceSchemaLite.java @@ -0,0 +1,39 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +final class NewInstanceSchemaLite implements NewInstanceSchema { + @Override + public Object newInstance(Object defaultInstance) { + return ((GeneratedMessageLite) defaultInstance) + .dynamicMethod(GeneratedMessageLite.MethodToInvoke.NEW_MUTABLE_INSTANCE); + } +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/NewInstanceSchemas.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/NewInstanceSchemas.java new file mode 100644 index 0000000000000..eff45f67b9c04 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/NewInstanceSchemas.java @@ -0,0 +1,53 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +final class NewInstanceSchemas { + private static final NewInstanceSchema FULL_SCHEMA = loadSchemaForFullRuntime(); + private static final NewInstanceSchema LITE_SCHEMA = new NewInstanceSchemaLite(); + + static NewInstanceSchema full() { + return FULL_SCHEMA; + } + + static NewInstanceSchema lite() { + return LITE_SCHEMA; + } + + private static NewInstanceSchema loadSchemaForFullRuntime() { + try { + Class clazz = Class.forName("com.google.protobuf.NewInstanceSchemaFull"); + return (NewInstanceSchema) clazz.getDeclaredConstructor().newInstance(); + } catch (Exception e) { + return null; + } + } +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/NioByteString.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/NioByteString.java new file mode 100644 index 0000000000000..1e594ff878c57 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/NioByteString.java @@ -0,0 +1,293 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +import static com.google.protobuf.Internal.checkNotNull; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InvalidObjectException; +import java.io.ObjectInputStream; +import java.io.OutputStream; +import java.nio.Buffer; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.InvalidMarkException; +import java.nio.charset.Charset; +import java.util.Collections; +import java.util.List; + +/** A {@link ByteString} that wraps around a {@link ByteBuffer}. */ +final class NioByteString extends ByteString.LeafByteString { + private final ByteBuffer buffer; + + NioByteString(ByteBuffer buffer) { + checkNotNull(buffer, "buffer"); + + // Use native byte order for fast fixed32/64 operations. + this.buffer = buffer.slice().order(ByteOrder.nativeOrder()); + } + + // ================================================================= + // Serializable + + /** Magic method that lets us override serialization behavior. */ + private Object writeReplace() { + return ByteString.copyFrom(buffer.slice()); + } + + /** Magic method that lets us override deserialization behavior. */ + private void readObject(@SuppressWarnings("unused") ObjectInputStream in) throws IOException { + throw new InvalidObjectException("NioByteString instances are not to be serialized directly"); + } + + // ================================================================= + + @Override + public byte byteAt(int index) { + try { + return buffer.get(index); + } catch (ArrayIndexOutOfBoundsException e) { + throw e; + } catch (IndexOutOfBoundsException e) { + throw new ArrayIndexOutOfBoundsException(e.getMessage()); + } + } + + @Override + public byte internalByteAt(int index) { + // it isn't possible to avoid the bounds checking inside of ByteBuffer, so just use the default + // implementation. + return byteAt(index); + } + + @Override + public int size() { + return buffer.remaining(); + } + + @Override + public ByteString substring(int beginIndex, int endIndex) { + try { + ByteBuffer slice = slice(beginIndex, endIndex); + return new NioByteString(slice); + } catch (ArrayIndexOutOfBoundsException e) { + throw e; + } catch (IndexOutOfBoundsException e) { + throw new ArrayIndexOutOfBoundsException(e.getMessage()); + } + } + + @Override + protected void copyToInternal( + byte[] target, int sourceOffset, int targetOffset, int numberToCopy) { + ByteBuffer slice = buffer.slice(); + ((Buffer) slice).position(sourceOffset); + slice.get(target, targetOffset, numberToCopy); + } + + @Override + public void copyTo(ByteBuffer target) { + target.put(buffer.slice()); + } + + @Override + public void writeTo(OutputStream out) throws IOException { + out.write(toByteArray()); + } + + @Override + boolean equalsRange(ByteString other, int offset, int length) { + return substring(0, length).equals(other.substring(offset, offset + length)); + } + + @Override + void writeToInternal(OutputStream out, int sourceOffset, int numberToWrite) throws IOException { + if (buffer.hasArray()) { + // Optimized write for array-backed buffers. + // Note that we're taking the risk that a malicious OutputStream could modify the array. + int bufferOffset = buffer.arrayOffset() + buffer.position() + sourceOffset; + out.write(buffer.array(), bufferOffset, numberToWrite); + return; + } + + ByteBufferWriter.write(slice(sourceOffset, sourceOffset + numberToWrite), out); + } + + @Override + void writeTo(ByteOutput output) throws IOException { + output.writeLazy(buffer.slice()); + } + + @Override + public ByteBuffer asReadOnlyByteBuffer() { + return buffer.asReadOnlyBuffer(); + } + + @Override + public List asReadOnlyByteBufferList() { + return Collections.singletonList(asReadOnlyByteBuffer()); + } + + @Override + protected String toStringInternal(Charset charset) { + final byte[] bytes; + final int offset; + final int length; + if (buffer.hasArray()) { + bytes = buffer.array(); + offset = buffer.arrayOffset() + buffer.position(); + length = buffer.remaining(); + } else { + // TODO(nathanmittler): Can we optimize this? + bytes = toByteArray(); + offset = 0; + length = bytes.length; + } + return new String(bytes, offset, length, charset); + } + + @Override + public boolean isValidUtf8() { + return Utf8.isValidUtf8(buffer); + } + + @Override + protected int partialIsValidUtf8(int state, int offset, int length) { + return Utf8.partialIsValidUtf8(state, buffer, offset, offset + length); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof ByteString)) { + return false; + } + ByteString otherString = ((ByteString) other); + if (size() != otherString.size()) { + return false; + } + if (size() == 0) { + return true; + } + if (other instanceof NioByteString) { + return buffer.equals(((NioByteString) other).buffer); + } + if (other instanceof RopeByteString) { + return other.equals(this); + } + return buffer.equals(otherString.asReadOnlyByteBuffer()); + } + + @Override + protected int partialHash(int h, int offset, int length) { + for (int i = offset; i < offset + length; i++) { + h = h * 31 + buffer.get(i); + } + return h; + } + + @Override + public InputStream newInput() { + return new InputStream() { + private final ByteBuffer buf = buffer.slice(); + + @Override + public void mark(int readlimit) { + buf.mark(); + } + + @Override + public boolean markSupported() { + return true; + } + + @Override + public void reset() throws IOException { + try { + buf.reset(); + } catch (InvalidMarkException e) { + throw new IOException(e); + } + } + + @Override + public int available() throws IOException { + return buf.remaining(); + } + + @Override + public int read() throws IOException { + if (!buf.hasRemaining()) { + return -1; + } + return buf.get() & 0xFF; + } + + @Override + public int read(byte[] bytes, int off, int len) throws IOException { + if (!buf.hasRemaining()) { + return -1; + } + + len = Math.min(len, buf.remaining()); + buf.get(bytes, off, len); + return len; + } + }; + } + + @Override + public CodedInputStream newCodedInput() { + return CodedInputStream.newInstance(buffer, true); + } + + /** + * Creates a slice of a range of this buffer. + * + * @param beginIndex the beginning index of the slice (inclusive). + * @param endIndex the end index of the slice (exclusive). + * @return the requested slice. + */ + private ByteBuffer slice(int beginIndex, int endIndex) { + if (beginIndex < buffer.position() || endIndex > buffer.limit() || beginIndex > endIndex) { + throw new IllegalArgumentException( + String.format("Invalid indices [%d, %d]", beginIndex, endIndex)); + } + + ByteBuffer slice = buffer.slice(); + ((Buffer) slice).position(beginIndex - buffer.position()); + ((Buffer) slice).limit(endIndex - buffer.position()); + return slice; + } +} diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/NullValue.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/NullValue.java new file mode 100644 index 0000000000000..9c430114ebb25 --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/NullValue.java @@ -0,0 +1,99 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/struct.proto + +package com.google.protobuf; + +/** + *
+ * `NullValue` is a singleton enumeration to represent the null value for the
+ * `Value` type union.
+ *  The JSON representation for `NullValue` is JSON `null`.
+ * 
+ * + * Protobuf enum {@code google.protobuf.NullValue} + */ +public enum NullValue + implements com.google.protobuf.Internal.EnumLite { + /** + *
+   * Null value.
+   * 
+ * + * NULL_VALUE = 0; + */ + NULL_VALUE(0), + UNRECOGNIZED(-1), + ; + + /** + *
+   * Null value.
+   * 
+ * + * NULL_VALUE = 0; + */ + public static final int NULL_VALUE_VALUE = 0; + + + @java.lang.Override + public final int getNumber() { + if (this == UNRECOGNIZED) { + throw new java.lang.IllegalArgumentException( + "Can't get the number of an unknown enum value."); + } + return value; + } + + /** + * @param value The number of the enum to look for. + * @return The enum associated with the given number. + * @deprecated Use {@link #forNumber(int)} instead. + */ + @java.lang.Deprecated + public static NullValue valueOf(int value) { + return forNumber(value); + } + + public static NullValue forNumber(int value) { + switch (value) { + case 0: return NULL_VALUE; + default: return null; + } + } + + public static com.google.protobuf.Internal.EnumLiteMap + internalGetValueMap() { + return internalValueMap; + } + private static final com.google.protobuf.Internal.EnumLiteMap< + NullValue> internalValueMap = + new com.google.protobuf.Internal.EnumLiteMap() { + @java.lang.Override + public NullValue findValueByNumber(int number) { + return NullValue.forNumber(number); + } + }; + + public static com.google.protobuf.Internal.EnumVerifier + internalGetVerifier() { + return NullValueVerifier.INSTANCE; + } + + private static final class NullValueVerifier implements + com.google.protobuf.Internal.EnumVerifier { + static final com.google.protobuf.Internal.EnumVerifier INSTANCE = new NullValueVerifier(); + @java.lang.Override + public boolean isInRange(int number) { + return NullValue.forNumber(number) != null; + } + }; + + private final int value; + + private NullValue(int value) { + this.value = value; + } + + // @@protoc_insertion_point(enum_scope:google.protobuf.NullValue) +} + diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/OneofInfo.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/OneofInfo.java new file mode 100644 index 0000000000000..bc518fcadd93f --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/OneofInfo.java @@ -0,0 +1,66 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +import java.lang.reflect.Field; + +/** Information for a oneof within a protobuf message. */ +// TODO(nathanmittler): make this private once all of experimental code is migrated to protobuf. +@ExperimentalApi +final class OneofInfo { + private final int id; + private final Field caseField; + private final Field valueField; + + public OneofInfo(int id, Field caseField, Field valueField) { + this.id = id; + this.caseField = caseField; + this.valueField = valueField; + } + + /** + * Returns the unique identifier of the oneof within the message. This is really just an index + * starting at zero. + */ + public int getId() { + return id; + } + + /** The {@code int} field containing the field number of the currently active member. */ + public Field getCaseField() { + return caseField; + } + + /** The {@link Object} field containing the value of the currently active member. */ + public Field getValueField() { + return valueField; + } +} diff --git a/java/core/src/main/kotlin/com/google/protobuf/OnlyForUseByGeneratedProtoCode.kt b/java/kotlin-lite/target/generated-sources/com/google/protobuf/OnlyForUseByGeneratedProtoCode.kt similarity index 100% rename from java/core/src/main/kotlin/com/google/protobuf/OnlyForUseByGeneratedProtoCode.kt rename to java/kotlin-lite/target/generated-sources/com/google/protobuf/OnlyForUseByGeneratedProtoCode.kt diff --git a/java/kotlin-lite/target/generated-sources/com/google/protobuf/Option.java b/java/kotlin-lite/target/generated-sources/com/google/protobuf/Option.java new file mode 100644 index 0000000000000..988766c8281ae --- /dev/null +++ b/java/kotlin-lite/target/generated-sources/com/google/protobuf/Option.java @@ -0,0 +1,533 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/type.proto + +package com.google.protobuf; + +/** + *
+ * A protocol buffer option, which can be attached to a message, field,
+ * enumeration, etc.
+ * 
+ * + * Protobuf type {@code google.protobuf.Option} + */ +public final class Option extends + com.google.protobuf.GeneratedMessageLite< + Option, Option.Builder> implements + // @@protoc_insertion_point(message_implements:google.protobuf.Option) + OptionOrBuilder { + private Option() { + name_ = ""; + } + public static final int NAME_FIELD_NUMBER = 1; + private java.lang.String name_; + /** + *
+   * The option's name. For protobuf built-in options (options defined in
+   * descriptor.proto), this is the short name. For example, `"map_entry"`.
+   * For custom options, it should be the fully-qualified name. For example,
+   * `"google.api.http"`.
+   * 
+ * + * string name = 1; + * @return The name. + */ + @java.lang.Override + public java.lang.String getName() { + return name_; + } + /** + *
+   * The option's name. For protobuf built-in options (options defined in
+   * descriptor.proto), this is the short name. For example, `"map_entry"`.
+   * For custom options, it should be the fully-qualified name. For example,
+   * `"google.api.http"`.
+   * 
+ * + * string name = 1; + * @return The bytes for name. + */ + @java.lang.Override + public com.google.protobuf.ByteString + getNameBytes() { + return com.google.protobuf.ByteString.copyFromUtf8(name_); + } + /** + *
+   * The option's name. For protobuf built-in options (options defined in
+   * descriptor.proto), this is the short name. For example, `"map_entry"`.
+   * For custom options, it should be the fully-qualified name. For example,
+   * `"google.api.http"`.
+   * 
+ * + * string name = 1; + * @param value The name to set. + */ + private void setName( + java.lang.String value) { + value.getClass(); + + name_ = value; + } + /** + *
+   * The option's name. For protobuf built-in options (options defined in
+   * descriptor.proto), this is the short name. For example, `"map_entry"`.
+   * For custom options, it should be the fully-qualified name. For example,
+   * `"google.api.http"`.
+   * 
+ * + * string name = 1; + */ + private void clearName() { + + name_ = getDefaultInstance().getName(); + } + /** + *
+   * The option's name. For protobuf built-in options (options defined in
+   * descriptor.proto), this is the short name. For example, `"map_entry"`.
+   * For custom options, it should be the fully-qualified name. For example,
+   * `"google.api.http"`.
+   * 
+ * + * string name = 1; + * @param value The bytes for name to set. + */ + private void setNameBytes( + com.google.protobuf.ByteString value) { + checkByteStringIsUtf8(value); + name_ = value.toStringUtf8(); + + } + + public static final int VALUE_FIELD_NUMBER = 2; + private com.google.protobuf.Any value_; + /** + *
+   * The option's value packed in an Any message. If the value is a primitive,
+   * the corresponding wrapper type defined in google/protobuf/wrappers.proto
+   * should be used. If the value is an enum, it should be stored as an int32
+   * value using the google.protobuf.Int32Value type.
+   * 
+ * + * .google.protobuf.Any value = 2; + */ + @java.lang.Override + public boolean hasValue() { + return value_ != null; + } + /** + *
+   * The option's value packed in an Any message. If the value is a primitive,
+   * the corresponding wrapper type defined in google/protobuf/wrappers.proto
+   * should be used. If the value is an enum, it should be stored as an int32
+   * value using the google.protobuf.Int32Value type.
+   * 
+ * + * .google.protobuf.Any value = 2; + */ + @java.lang.Override + public com.google.protobuf.Any getValue() { + return value_ == null ? com.google.protobuf.Any.getDefaultInstance() : value_; + } + /** + *
+   * The option's value packed in an Any message. If the value is a primitive,
+   * the corresponding wrapper type defined in google/protobuf/wrappers.proto
+   * should be used. If the value is an enum, it should be stored as an int32
+   * value using the google.protobuf.Int32Value type.
+   * 
+ * + * .google.protobuf.Any value = 2; + */ + private void setValue(com.google.protobuf.Any value) { + value.getClass(); + value_ = value; + + } + /** + *
+   * The option's value packed in an Any message. If the value is a primitive,
+   * the corresponding wrapper type defined in google/protobuf/wrappers.proto
+   * should be used. If the value is an enum, it should be stored as an int32
+   * value using the google.protobuf.Int32Value type.
+   * 
+ * + * .google.protobuf.Any value = 2; + */ + @java.lang.SuppressWarnings({"ReferenceEquality"}) + private void mergeValue(com.google.protobuf.Any value) { + value.getClass(); + if (value_ != null && + value_ != com.google.protobuf.Any.getDefaultInstance()) { + value_ = + com.google.protobuf.Any.newBuilder(value_).mergeFrom(value).buildPartial(); + } else { + value_ = value; + } + + } + /** + *
+   * The option's value packed in an Any message. If the value is a primitive,
+   * the corresponding wrapper type defined in google/protobuf/wrappers.proto
+   * should be used. If the value is an enum, it should be stored as an int32
+   * value using the google.protobuf.Int32Value type.
+   * 
+ * + * .google.protobuf.Any value = 2; + */ + private void clearValue() { value_ = null; + + } + + public static com.google.protobuf.Option parseFrom( + java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.Option parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.Option parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.Option parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.Option parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data); + } + public static com.google.protobuf.Option parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, data, extensionRegistry); + } + public static com.google.protobuf.Option parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, 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.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, input, extensionRegistry); + } + public static com.google.protobuf.Option parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return parseDelimitedFrom(DEFAULT_INSTANCE, input); + } + public static com.google.protobuf.Option parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return parseDelimitedFrom(DEFAULT_INSTANCE, input, extensionRegistry); + } + public static com.google.protobuf.Option parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, 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.GeneratedMessageLite.parseFrom( + DEFAULT_INSTANCE, input, extensionRegistry); + } + + public static Builder newBuilder() { + return (Builder) DEFAULT_INSTANCE.createBuilder(); + } + public static Builder newBuilder(com.google.protobuf.Option prototype) { + return (Builder) DEFAULT_INSTANCE.createBuilder(prototype); + } + + /** + *
+   * A protocol buffer option, which can be attached to a message, field,
+   * enumeration, etc.
+   * 
+ * + * Protobuf type {@code google.protobuf.Option} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessageLite.Builder< + com.google.protobuf.Option, Builder> implements + // @@protoc_insertion_point(builder_implements:google.protobuf.Option) + com.google.protobuf.OptionOrBuilder { + // Construct using com.google.protobuf.Option.newBuilder() + private Builder() { + super(DEFAULT_INSTANCE); + } + + + /** + *
+     * The option's name. For protobuf built-in options (options defined in
+     * descriptor.proto), this is the short name. For example, `"map_entry"`.
+     * For custom options, it should be the fully-qualified name. For example,
+     * `"google.api.http"`.
+     * 
+ * + * string name = 1; + * @return The name. + */ + @java.lang.Override + public java.lang.String getName() { + return instance.getName(); + } + /** + *
+     * The option's name. For protobuf built-in options (options defined in
+     * descriptor.proto), this is the short name. For example, `"map_entry"`.
+     * For custom options, it should be the fully-qualified name. For example,
+     * `"google.api.http"`.
+     * 
+ * + * string name = 1; + * @return The bytes for name. + */ + @java.lang.Override + public com.google.protobuf.ByteString + getNameBytes() { + return instance.getNameBytes(); + } + /** + *
+     * The option's name. For protobuf built-in options (options defined in
+     * descriptor.proto), this is the short name. For example, `"map_entry"`.
+     * For custom options, it should be the fully-qualified name. For example,
+     * `"google.api.http"`.
+     * 
+ * + * string name = 1; + * @param value The name to set. + * @return This builder for chaining. + */ + public Builder setName( + java.lang.String value) { + copyOnWrite(); + instance.setName(value); + return this; + } + /** + *
+     * The option's name. For protobuf built-in options (options defined in
+     * descriptor.proto), this is the short name. For example, `"map_entry"`.
+     * For custom options, it should be the fully-qualified name. For example,
+     * `"google.api.http"`.
+     * 
+ * + * string name = 1; + * @return This builder for chaining. + */ + public Builder clearName() { + copyOnWrite(); + instance.clearName(); + return this; + } + /** + *
+     * The option's name. For protobuf built-in options (options defined in
+     * descriptor.proto), this is the short name. For example, `"map_entry"`.
+     * For custom options, it should be the fully-qualified name. For example,
+     * `"google.api.http"`.
+     * 
+ * + * string name = 1; + * @param value The bytes for name to set. + * @return This builder for chaining. + */ + public Builder setNameBytes( + com.google.protobuf.ByteString value) { + copyOnWrite(); + instance.setNameBytes(value); + return this; + } + + /** + *
+     * The option's value packed in an Any message. If the value is a primitive,
+     * the corresponding wrapper type defined in google/protobuf/wrappers.proto
+     * should be used. If the value is an enum, it should be stored as an int32
+     * value using the google.protobuf.Int32Value type.
+     * 
+ * + * .google.protobuf.Any value = 2; + */ + @java.lang.Override + public boolean hasValue() { + return instance.hasValue(); + } + /** + *
+     * The option's value packed in an Any message. If the value is a primitive,
+     * the corresponding wrapper type defined in google/protobuf/wrappers.proto
+     * should be used. If the value is an enum, it should be stored as an int32
+     * value using the google.protobuf.Int32Value type.
+     * 
+ * + * .google.protobuf.Any value = 2; + */ + @java.lang.Override + public com.google.protobuf.Any getValue() { + return instance.getValue(); + } + /** + *
+     * The option's value packed in an Any message. If the value is a primitive,
+     * the corresponding wrapper type defined in google/protobuf/wrappers.proto
+     * should be used. If the value is an enum, it should be stored as an int32
+     * value using the google.protobuf.Int32Value type.
+     * 
+ * + * .google.protobuf.Any value = 2; + */ + public Builder setValue(com.google.protobuf.Any value) { + copyOnWrite(); + instance.setValue(value); + return this; + } + /** + *
+     * The option's value packed in an Any message. If the value is a primitive,
+     * the corresponding wrapper type defined in google/protobuf/wrappers.proto
+     * should be used. If the value is an enum, it should be stored as an int32
+     * value using the google.protobuf.Int32Value type.
+     * 
+ * + * .google.protobuf.Any value = 2; + */ + public Builder setValue( + com.google.protobuf.Any.Builder builderForValue) { + copyOnWrite(); + instance.setValue(builderForValue.build()); + return this; + } + /** + *
+     * The option's value packed in an Any message. If the value is a primitive,
+     * the corresponding wrapper type defined in google/protobuf/wrappers.proto
+     * should be used. If the value is an enum, it should be stored as an int32
+     * value using the google.protobuf.Int32Value type.
+     * 
+ * + * .google.protobuf.Any value = 2; + */ + public Builder mergeValue(com.google.protobuf.Any value) { + copyOnWrite(); + instance.mergeValue(value); + return this; + } + /** + *
+     * The option's value packed in an Any message. If the value is a primitive,
+     * the corresponding wrapper type defined in google/protobuf/wrappers.proto
+     * should be used. If the value is an enum, it should be stored as an int32
+     * value using the google.protobuf.Int32Value type.
+     * 
+ * + * .google.protobuf.Any value = 2; + */ + public Builder clearValue() { copyOnWrite(); + instance.clearValue(); + return this; + } + + // @@protoc_insertion_point(builder_scope:google.protobuf.Option) + } + @java.lang.Override + @java.lang.SuppressWarnings({"unchecked", "fallthrough"}) + protected final java.lang.Object dynamicMethod( + com.google.protobuf.GeneratedMessageLite.MethodToInvoke method, + java.lang.Object arg0, java.lang.Object arg1) { + switch (method) { + case NEW_MUTABLE_INSTANCE: { + return new com.google.protobuf.Option(); + } + case NEW_BUILDER: { + return new Builder(); + } + case BUILD_MESSAGE_INFO: { + java.lang.Object[] objects = new java.lang.Object[] { + "name_", + "value_", + }; + java.lang.String info = + "\u0000\u0002\u0000\u0000\u0001\u0002\u0002\u0000\u0000\u0000\u0001\u0208\u0002\t" + + ""; + return newMessageInfo(DEFAULT_INSTANCE, info, objects); + } + // fall through + case GET_DEFAULT_INSTANCE: { + return DEFAULT_INSTANCE; + } + case GET_PARSER: { + com.google.protobuf.Parser parser = PARSER; + if (parser == null) { + synchronized (com.google.protobuf.Option.class) { + parser = PARSER; + if (parser == null) { + parser = + new DefaultInstanceBasedParser( + DEFAULT_INSTANCE); + PARSER = parser; + } + } + } + return parser; + } + case GET_MEMOIZED_IS_INITIALIZED: { + return (byte) 1; + } + case SET_MEMOIZED_IS_INITIALIZED: { + return null; + } + } + throw new UnsupportedOperationException(); + } + + + // @@protoc_insertion_point(class_scope:google.protobuf.Option) + private static final com.google.protobuf.Option DEFAULT_INSTANCE; + static { + Option defaultInstance = new Option(); + // New instances are implicitly immutable so no need to make + // immutable. + DEFAULT_INSTANCE = defaultInstance; + com.google.protobuf.GeneratedMessageLite.registerDefaultInstance( + Option.class, defaultInstance); + } + + public static com.google.protobuf.Option getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static volatile com.google.protobuf.Parser