diff --git a/OsmAnd-java/.classpath b/OsmAnd-java/.classpath
new file mode 100644
index 0000000000..7b0914ce10
--- /dev/null
+++ b/OsmAnd-java/.classpath
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/OsmAnd-java/.gitignore b/OsmAnd-java/.gitignore
new file mode 100644
index 0000000000..ba077a4031
--- /dev/null
+++ b/OsmAnd-java/.gitignore
@@ -0,0 +1 @@
+bin
diff --git a/OsmAnd-java/.project b/OsmAnd-java/.project
new file mode 100644
index 0000000000..e7cfa33984
--- /dev/null
+++ b/OsmAnd-java/.project
@@ -0,0 +1,30 @@
+
+
+ OsmAnd-java
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
+
+ android
+ 2
+ OSMAND_TRUNK/android/OsmAnd/gen
+
+
+
+
+ OSMAND_TRUNK
+ $%7BPARENT-2-PROJECT_LOC%7D
+
+
+
diff --git a/OsmAnd-java/.settings/org.eclipse.jdt.core.prefs b/OsmAnd-java/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000000..8000cd6ca6
--- /dev/null
+++ b/OsmAnd-java/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/OsmAnd-java/build.xml b/OsmAnd-java/build.xml
new file mode 100644
index 0000000000..a8876aae1f
--- /dev/null
+++ b/OsmAnd-java/build.xml
@@ -0,0 +1,77 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ list is ${lib.list}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/OsmAnd-java/libs/bsh-core-2.0b4.jar b/OsmAnd-java/libs/bsh-core-2.0b4.jar
new file mode 100644
index 0000000000..a1b8e47288
Binary files /dev/null and b/OsmAnd-java/libs/bsh-core-2.0b4.jar differ
diff --git a/OsmAnd-java/libs/bzip2-20090327.jar b/OsmAnd-java/libs/bzip2-20090327.jar
new file mode 100644
index 0000000000..5a0f290a07
Binary files /dev/null and b/OsmAnd-java/libs/bzip2-20090327.jar differ
diff --git a/OsmAnd-java/libs/commons-logging-1.1.1.jar b/OsmAnd-java/libs/commons-logging-1.1.1.jar
new file mode 100644
index 0000000000..1deef144cb
Binary files /dev/null and b/OsmAnd-java/libs/commons-logging-1.1.1.jar differ
diff --git a/OsmAnd-java/libs/gnu-trove-osmand.jar b/OsmAnd-java/libs/gnu-trove-osmand.jar
new file mode 100644
index 0000000000..1bdfd836e0
Binary files /dev/null and b/OsmAnd-java/libs/gnu-trove-osmand.jar differ
diff --git a/OsmAnd-java/libs/icu4j-49_1.jar b/OsmAnd-java/libs/icu4j-49_1.jar
new file mode 100644
index 0000000000..ed1950c2b5
Binary files /dev/null and b/OsmAnd-java/libs/icu4j-49_1.jar differ
diff --git a/OsmAnd-java/libs/json-20090211.jar b/OsmAnd-java/libs/json-20090211.jar
new file mode 100644
index 0000000000..ef29094093
Binary files /dev/null and b/OsmAnd-java/libs/json-20090211.jar differ
diff --git a/OsmAnd-java/libs/junidecode-0.1.jar b/OsmAnd-java/libs/junidecode-0.1.jar
new file mode 100644
index 0000000000..7c79c879e5
Binary files /dev/null and b/OsmAnd-java/libs/junidecode-0.1.jar differ
diff --git a/OsmAnd-java/libs/kxml2-2.3.0.jar b/OsmAnd-java/libs/kxml2-2.3.0.jar
new file mode 100644
index 0000000000..647095222a
Binary files /dev/null and b/OsmAnd-java/libs/kxml2-2.3.0.jar differ
diff --git a/OsmAnd-java/libs/simple-logging.jar b/OsmAnd-java/libs/simple-logging.jar
new file mode 100644
index 0000000000..89d3a05766
Binary files /dev/null and b/OsmAnd-java/libs/simple-logging.jar differ
diff --git a/OsmAnd-java/libs/tuprolog.jar b/OsmAnd-java/libs/tuprolog.jar
new file mode 100644
index 0000000000..529887697a
Binary files /dev/null and b/OsmAnd-java/libs/tuprolog.jar differ
diff --git a/OsmAnd-java/src/com/google/protobuf/AbstractMessage.java b/OsmAnd-java/src/com/google/protobuf/AbstractMessage.java
new file mode 100644
index 0000000000..faf0980407
--- /dev/null
+++ b/OsmAnd-java/src/com/google/protobuf/AbstractMessage.java
@@ -0,0 +1,714 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import com.google.protobuf.Descriptors.Descriptor;
+import com.google.protobuf.Descriptors.FieldDescriptor;
+
+/**
+ * A partial implementation of the {@link Message} interface which implements
+ * as many methods of that interface as possible in terms of other methods.
+ *
+ * @author kenton@google.com Kenton Varda
+ */
+public abstract class AbstractMessage extends AbstractMessageLite
+ implements Message {
+ @Override
+@SuppressWarnings("unchecked")
+ public boolean isInitialized() {
+ // Check that all required fields are present.
+ for (final FieldDescriptor field : getDescriptorForType().getFields()) {
+ if (field.isRequired()) {
+ if (!hasField(field)) {
+ return false;
+ }
+ }
+ }
+
+ // Check that embedded messages are initialized.
+ for (final Map.Entry entry :
+ getAllFields().entrySet()) {
+ final FieldDescriptor field = entry.getKey();
+ if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
+ if (field.isRepeated()) {
+ for (final Message element : (List) entry.getValue()) {
+ if (!element.isInitialized()) {
+ return false;
+ }
+ }
+ } else {
+ if (!((Message) entry.getValue()).isInitialized()) {
+ return false;
+ }
+ }
+ }
+ }
+
+ return true;
+ }
+
+ @Override
+ public final String toString() {
+ return TextFormat.printToString(this);
+ }
+
+ @Override
+public void writeTo(final CodedOutputStream output) throws IOException {
+ final boolean isMessageSet =
+ getDescriptorForType().getOptions().getMessageSetWireFormat();
+
+ for (final Map.Entry entry :
+ getAllFields().entrySet()) {
+ final FieldDescriptor field = entry.getKey();
+ final Object value = entry.getValue();
+ if (isMessageSet && field.isExtension() &&
+ field.getType() == FieldDescriptor.Type.MESSAGE &&
+ !field.isRepeated()) {
+ output.writeMessageSetExtension(field.getNumber(), (Message) value);
+ } else {
+ FieldSet.writeField(field, value, output);
+ }
+ }
+
+ final UnknownFieldSet unknownFields = getUnknownFields();
+ if (isMessageSet) {
+ unknownFields.writeAsMessageSetTo(output);
+ } else {
+ unknownFields.writeTo(output);
+ }
+ }
+
+ private int memoizedSize = -1;
+
+ @Override
+public int getSerializedSize() {
+ int size = memoizedSize;
+ if (size != -1) {
+ return size;
+ }
+
+ size = 0;
+ final boolean isMessageSet =
+ getDescriptorForType().getOptions().getMessageSetWireFormat();
+
+ for (final Map.Entry entry :
+ getAllFields().entrySet()) {
+ final FieldDescriptor field = entry.getKey();
+ final Object value = entry.getValue();
+ if (isMessageSet && field.isExtension() &&
+ field.getType() == FieldDescriptor.Type.MESSAGE &&
+ !field.isRepeated()) {
+ size += CodedOutputStream.computeMessageSetExtensionSize(
+ field.getNumber(), (Message) value);
+ } else {
+ size += FieldSet.computeFieldSize(field, value);
+ }
+ }
+
+ final UnknownFieldSet unknownFields = getUnknownFields();
+ if (isMessageSet) {
+ size += unknownFields.getSerializedSizeAsMessageSet();
+ } else {
+ size += unknownFields.getSerializedSize();
+ }
+
+ memoizedSize = size;
+ return size;
+ }
+
+ @Override
+ public boolean equals(final Object other) {
+ if (other == this) {
+ return true;
+ }
+ if (!(other instanceof Message)) {
+ return false;
+ }
+ final Message otherMessage = (Message) other;
+ if (getDescriptorForType() != otherMessage.getDescriptorForType()) {
+ return false;
+ }
+ return getAllFields().equals(otherMessage.getAllFields()) &&
+ getUnknownFields().equals(otherMessage.getUnknownFields());
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 41;
+ hash = (19 * hash) + getDescriptorForType().hashCode();
+ hash = (53 * hash) + getAllFields().hashCode();
+ hash = (29 * hash) + getUnknownFields().hashCode();
+ return hash;
+ }
+
+ // =================================================================
+
+ /**
+ * 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 static abstract class Builder
+ extends AbstractMessageLite.Builder
+ implements Message.Builder {
+ // The compiler produces an error if this is not declared explicitly.
+ @Override
+ public abstract BuilderType clone();
+
+ @Override
+ public BuilderType clear() {
+ for (final Map.Entry entry :
+ getAllFields().entrySet()) {
+ clearField(entry.getKey());
+ }
+ return (BuilderType) this;
+ }
+
+ @Override
+ public BuilderType mergeFrom(final Message other) {
+ if (other.getDescriptorForType() != getDescriptorForType()) {
+ throw new IllegalArgumentException(
+ "mergeFrom(Message) can only merge messages of the same type.");
+ }
+
+ // Note: We don't attempt to verify that other's fields have valid
+ // types. Doing so would be a losing battle. We'd have to verify
+ // all sub-messages as well, and we'd have to make copies of all of
+ // them to insure that they don't change after verification (since
+ // the Message interface itself cannot enforce immutability of
+ // implementations).
+ // TODO(kenton): Provide a function somewhere called makeDeepCopy()
+ // which allows people to make secure deep copies of messages.
+
+ for (final Map.Entry entry :
+ other.getAllFields().entrySet()) {
+ final FieldDescriptor field = entry.getKey();
+ if (field.isRepeated()) {
+ for (final Object element : (List)entry.getValue()) {
+ addRepeatedField(field, element);
+ }
+ } else if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
+ final Message existingValue = (Message)getField(field);
+ if (existingValue == existingValue.getDefaultInstanceForType()) {
+ setField(field, entry.getValue());
+ } else {
+ setField(field,
+ existingValue.newBuilderForType()
+ .mergeFrom(existingValue)
+ .mergeFrom((Message)entry.getValue())
+ .build());
+ }
+ } else {
+ setField(field, entry.getValue());
+ }
+ }
+
+ mergeUnknownFields(other.getUnknownFields());
+
+ return (BuilderType) this;
+ }
+
+ @Override
+ public BuilderType mergeFrom(final CodedInputStream input)
+ throws IOException {
+ return mergeFrom(input, ExtensionRegistry.getEmptyRegistry());
+ }
+
+ @Override
+ public BuilderType mergeFrom(
+ final CodedInputStream input,
+ final ExtensionRegistryLite extensionRegistry)
+ throws IOException {
+ final UnknownFieldSet.Builder unknownFields =
+ UnknownFieldSet.newBuilder(getUnknownFields());
+ while (true) {
+ final int tag = input.readTag();
+ if (tag == 0) {
+ break;
+ }
+
+ if (!mergeFieldFrom(input, unknownFields, extensionRegistry,
+ this, tag)) {
+ // end group tag
+ break;
+ }
+ }
+ setUnknownFields(unknownFields.build());
+ return (BuilderType) this;
+ }
+
+ /**
+ * Like {@link #mergeFrom(CodedInputStream, UnknownFieldSet.Builder,
+ * ExtensionRegistryLite, Message.Builder)}, but parses a single field.
+ * Package-private because it is used by GeneratedMessage.ExtendableMessage.
+ * @param tag The tag, which should have already been read.
+ * @return {@code true} unless the tag is an end-group tag.
+ */
+ static boolean mergeFieldFrom(
+ final CodedInputStream input,
+ final UnknownFieldSet.Builder unknownFields,
+ final ExtensionRegistryLite extensionRegistry,
+ final Message.Builder builder,
+ final int tag) throws IOException {
+ final Descriptor type = builder.getDescriptorForType();
+
+ if (type.getOptions().getMessageSetWireFormat() &&
+ tag == WireFormat.MESSAGE_SET_ITEM_TAG) {
+ mergeMessageSetExtensionFromCodedStream(
+ input, unknownFields, extensionRegistry, builder);
+ return true;
+ }
+
+ final int wireType = WireFormat.getTagWireType(tag);
+ final int fieldNumber = WireFormat.getTagFieldNumber(tag);
+
+ final FieldDescriptor field;
+ Message defaultInstance = null;
+
+ if (type.isExtensionNumber(fieldNumber)) {
+ // extensionRegistry may be either ExtensionRegistry or
+ // ExtensionRegistryLite. Since the type we are parsing is a full
+ // message, only a full ExtensionRegistry could possibly contain
+ // extensions of it. Otherwise we will treat the registry as if it
+ // were empty.
+ if (extensionRegistry instanceof ExtensionRegistry) {
+ final ExtensionRegistry.ExtensionInfo extension =
+ ((ExtensionRegistry) extensionRegistry)
+ .findExtensionByNumber(type, fieldNumber);
+ if (extension == null) {
+ field = null;
+ } else {
+ field = extension.descriptor;
+ defaultInstance = extension.defaultInstance;
+ if (defaultInstance == null &&
+ field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
+ throw new IllegalStateException(
+ "Message-typed extension lacked default instance: " +
+ field.getFullName());
+ }
+ }
+ } else {
+ field = null;
+ }
+ } else {
+ field = type.findFieldByNumber(fieldNumber);
+ }
+
+ boolean unknown = false;
+ boolean packed = false;
+ if (field == null) {
+ unknown = true; // Unknown field.
+ } else if (wireType == FieldSet.getWireFormatForFieldType(
+ field.getLiteType(),
+ false /* isPacked */)) {
+ packed = false;
+ } else if (field.isPackable() &&
+ wireType == FieldSet.getWireFormatForFieldType(
+ field.getLiteType(),
+ true /* isPacked */)) {
+ packed = true;
+ } else {
+ unknown = true; // Unknown wire type.
+ }
+
+ if (unknown) { // Unknown field or wrong wire type. Skip.
+ return unknownFields.mergeFieldFrom(tag, input);
+ }
+
+ if (packed) {
+ final int length = input.readRawVarint32();
+ final int limit = input.pushLimit(length);
+ if (field.getLiteType() == WireFormat.FieldType.ENUM) {
+ while (input.getBytesUntilLimit() > 0) {
+ final int rawValue = input.readEnum();
+ final Object value = field.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;
+ }
+ builder.addRepeatedField(field, value);
+ }
+ } else {
+ while (input.getBytesUntilLimit() > 0) {
+ final Object value =
+ FieldSet.readPrimitiveField(input, field.getLiteType());
+ builder.addRepeatedField(field, value);
+ }
+ }
+ input.popLimit(limit);
+ } else {
+ final Object value;
+ switch (field.getType()) {
+ case GROUP: {
+ final Message.Builder subBuilder;
+ if (defaultInstance != null) {
+ subBuilder = defaultInstance.newBuilderForType();
+ } else {
+ subBuilder = builder.newBuilderForField(field);
+ }
+ if (!field.isRepeated()) {
+ subBuilder.mergeFrom((Message) builder.getField(field));
+ }
+ input.readGroup(field.getNumber(), subBuilder, extensionRegistry);
+ value = subBuilder.build();
+ break;
+ }
+ case MESSAGE: {
+ final Message.Builder subBuilder;
+ if (defaultInstance != null) {
+ subBuilder = defaultInstance.newBuilderForType();
+ } else {
+ subBuilder = builder.newBuilderForField(field);
+ }
+ if (!field.isRepeated()) {
+ subBuilder.mergeFrom((Message) builder.getField(field));
+ }
+ input.readMessage(subBuilder, extensionRegistry);
+ value = subBuilder.build();
+ break;
+ }
+ case ENUM:
+ final int rawValue = input.readEnum();
+ value = field.getEnumType().findValueByNumber(rawValue);
+ // If the number isn't recognized as a valid value for this enum,
+ // drop it.
+ if (value == null) {
+ unknownFields.mergeVarintField(fieldNumber, rawValue);
+ return true;
+ }
+ break;
+ default:
+ value = FieldSet.readPrimitiveField(input, field.getLiteType());
+ break;
+ }
+
+ if (field.isRepeated()) {
+ builder.addRepeatedField(field, value);
+ } else {
+ builder.setField(field, value);
+ }
+ }
+
+ return true;
+ }
+
+ /** Called by {@code #mergeFieldFrom()} to parse a MessageSet extension. */
+ private static void mergeMessageSetExtensionFromCodedStream(
+ final CodedInputStream input,
+ final UnknownFieldSet.Builder unknownFields,
+ final ExtensionRegistryLite extensionRegistry,
+ final Message.Builder builder) throws IOException {
+ final Descriptor type = builder.getDescriptorForType();
+
+ // 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"
+ Message.Builder subBuilder = null;
+ FieldDescriptor field = null;
+
+ while (true) {
+ final int tag = input.readTag();
+ if (tag == 0) {
+ break;
+ }
+
+ if (tag == WireFormat.MESSAGE_SET_TYPE_ID_TAG) {
+ typeId = input.readUInt32();
+ // Zero is not a valid type ID.
+ if (typeId != 0) {
+ final ExtensionRegistry.ExtensionInfo extension;
+
+ // extensionRegistry may be either ExtensionRegistry or
+ // ExtensionRegistryLite. Since the type we are parsing is a full
+ // message, only a full ExtensionRegistry could possibly contain
+ // extensions of it. Otherwise we will treat the registry as if it
+ // were empty.
+ if (extensionRegistry instanceof ExtensionRegistry) {
+ extension = ((ExtensionRegistry) extensionRegistry)
+ .findExtensionByNumber(type, typeId);
+ } else {
+ extension = null;
+ }
+
+ if (extension != null) {
+ field = extension.descriptor;
+ subBuilder = extension.defaultInstance.newBuilderForType();
+ final Message originalMessage = (Message)builder.getField(field);
+ if (originalMessage != null) {
+ subBuilder.mergeFrom(originalMessage);
+ }
+ if (rawBytes != null) {
+ // We already encountered the message. Parse it now.
+ subBuilder.mergeFrom(
+ CodedInputStream.newInstance(rawBytes.newInput()));
+ rawBytes = null;
+ }
+ } else {
+ // Unknown extension number. If we already saw data, put it
+ // in rawBytes.
+ if (rawBytes != null) {
+ unknownFields.mergeField(typeId,
+ UnknownFieldSet.Field.newBuilder()
+ .addLengthDelimited(rawBytes)
+ .build());
+ rawBytes = null;
+ }
+ }
+ }
+ } else if (tag == WireFormat.MESSAGE_SET_MESSAGE_TAG) {
+ if (typeId == 0) {
+ // We haven't seen a type ID yet, so we have to store the raw bytes
+ // for now.
+ rawBytes = input.readBytes();
+ } else if (subBuilder == null) {
+ // We don't know how to parse this. Ignore it.
+ unknownFields.mergeField(typeId,
+ UnknownFieldSet.Field.newBuilder()
+ .addLengthDelimited(input.readBytes())
+ .build());
+ } else {
+ // We already know the type, so we can parse directly from the input
+ // with no copying. Hooray!
+ input.readMessage(subBuilder, extensionRegistry);
+ }
+ } else {
+ // Unknown tag. Skip it.
+ if (!input.skipField(tag)) {
+ break; // end of group
+ }
+ }
+ }
+
+ input.checkLastTagWas(WireFormat.MESSAGE_SET_ITEM_END_TAG);
+
+ if (subBuilder != null) {
+ builder.setField(field, subBuilder.build());
+ }
+ }
+
+ @Override
+ public BuilderType mergeUnknownFields(final UnknownFieldSet unknownFields) {
+ setUnknownFields(
+ UnknownFieldSet.newBuilder(getUnknownFields())
+ .mergeFrom(unknownFields)
+ .build());
+ return (BuilderType) this;
+ }
+
+ /**
+ * Construct an UninitializedMessageException reporting missing fields in
+ * the given message.
+ */
+ protected static UninitializedMessageException
+ newUninitializedMessageException(Message message) {
+ return new UninitializedMessageException(findMissingFields(message));
+ }
+
+ /**
+ * Populates {@code this.missingFields} with the full "path" of each
+ * missing required field in the given message.
+ */
+ private static List findMissingFields(final Message message) {
+ final List results = new ArrayList();
+ findMissingFields(message, "", results);
+ return results;
+ }
+
+ /** Recursive helper implementing {@link #findMissingFields(Message)}. */
+ private static void findMissingFields(final Message message,
+ final String prefix,
+ final List results) {
+ for (final FieldDescriptor field :
+ message.getDescriptorForType().getFields()) {
+ if (field.isRequired() && !message.hasField(field)) {
+ results.add(prefix + field.getName());
+ }
+ }
+
+ for (final Map.Entry entry :
+ message.getAllFields().entrySet()) {
+ final FieldDescriptor field = entry.getKey();
+ final Object value = entry.getValue();
+
+ if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
+ if (field.isRepeated()) {
+ int i = 0;
+ for (final Object element : (List) value) {
+ findMissingFields((Message) element,
+ subMessagePrefix(prefix, field, i++),
+ results);
+ }
+ } else {
+ if (message.hasField(field)) {
+ findMissingFields((Message) value,
+ subMessagePrefix(prefix, field, -1),
+ results);
+ }
+ }
+ }
+ }
+ }
+
+ private static String subMessagePrefix(final String prefix,
+ final FieldDescriptor field,
+ final int index) {
+ final StringBuilder result = new StringBuilder(prefix);
+ if (field.isExtension()) {
+ result.append('(')
+ .append(field.getFullName())
+ .append(')');
+ } else {
+ result.append(field.getName());
+ }
+ if (index != -1) {
+ result.append('[')
+ .append(index)
+ .append(']');
+ }
+ result.append('.');
+ return result.toString();
+ }
+
+ // ===============================================================
+ // The following definitions seem to be required in order to make javac
+ // not produce weird errors like:
+ //
+ // java/com/google/protobuf/DynamicMessage.java:203: types
+ // com.google.protobuf.AbstractMessage.Builder<
+ // com.google.protobuf.DynamicMessage.Builder> and
+ // com.google.protobuf.AbstractMessage.Builder<
+ // com.google.protobuf.DynamicMessage.Builder> are incompatible; both
+ // define mergeFrom(com.google.protobuf.ByteString), but with unrelated
+ // return types.
+ //
+ // Strangely, these lines are only needed if javac is invoked separately
+ // on AbstractMessage.java and AbstractMessageLite.java. If javac is
+ // invoked on both simultaneously, it works. (Or maybe the important
+ // point is whether or not DynamicMessage.java is compiled together with
+ // AbstractMessageLite.java -- not sure.) I suspect this is a compiler
+ // bug.
+
+ @Override
+ public BuilderType mergeFrom(final ByteString data)
+ throws InvalidProtocolBufferException {
+ return super.mergeFrom(data);
+ }
+
+ @Override
+ public BuilderType mergeFrom(
+ final ByteString data,
+ final ExtensionRegistryLite extensionRegistry)
+ throws InvalidProtocolBufferException {
+ return super.mergeFrom(data, extensionRegistry);
+ }
+
+ @Override
+ public BuilderType mergeFrom(final byte[] data)
+ throws InvalidProtocolBufferException {
+ return super.mergeFrom(data);
+ }
+
+ @Override
+ public BuilderType mergeFrom(
+ final byte[] data, final int off, final int len)
+ throws InvalidProtocolBufferException {
+ return super.mergeFrom(data, off, len);
+ }
+
+ @Override
+ public BuilderType mergeFrom(
+ final byte[] data,
+ final ExtensionRegistryLite extensionRegistry)
+ throws InvalidProtocolBufferException {
+ return super.mergeFrom(data, extensionRegistry);
+ }
+
+ @Override
+ public BuilderType mergeFrom(
+ final byte[] data, final int off, final int len,
+ final ExtensionRegistryLite extensionRegistry)
+ throws InvalidProtocolBufferException {
+ return super.mergeFrom(data, off, len, extensionRegistry);
+ }
+
+ @Override
+ public BuilderType mergeFrom(final InputStream input)
+ throws IOException {
+ return super.mergeFrom(input);
+ }
+
+ @Override
+ public BuilderType mergeFrom(
+ final InputStream input,
+ final ExtensionRegistryLite extensionRegistry)
+ throws IOException {
+ return super.mergeFrom(input, extensionRegistry);
+ }
+
+ @Override
+ public boolean mergeDelimitedFrom(final InputStream input)
+ throws IOException {
+ return super.mergeDelimitedFrom(input);
+ }
+
+ @Override
+ public boolean mergeDelimitedFrom(
+ final InputStream input,
+ final ExtensionRegistryLite extensionRegistry)
+ throws IOException {
+ return super.mergeDelimitedFrom(input, extensionRegistry);
+ }
+
+ }
+}
diff --git a/OsmAnd-java/src/com/google/protobuf/AbstractMessageLite.java b/OsmAnd-java/src/com/google/protobuf/AbstractMessageLite.java
new file mode 100644
index 0000000000..f0abb68849
--- /dev/null
+++ b/OsmAnd-java/src/com/google/protobuf/AbstractMessageLite.java
@@ -0,0 +1,342 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.FilterInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Collection;
+
+/**
+ * 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 implements MessageLite {
+ @Override
+public ByteString toByteString() {
+ try {
+ final ByteString.CodedBuilder out =
+ ByteString.newCodedBuilder(getSerializedSize());
+ writeTo(out.getCodedOutput());
+ return out.build();
+ } catch (IOException e) {
+ throw new RuntimeException(
+ "Serializing to a ByteString threw an IOException (should " +
+ "never happen).", 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(
+ "Serializing to a byte array threw an IOException " +
+ "(should never happen).", 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();
+ }
+
+ /**
+ * 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 static abstract class 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(
+ "Reading from a ByteString threw an IOException (should " +
+ "never happen).", 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(
+ "Reading from a ByteString threw an IOException (should " +
+ "never happen).", 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(
+ "Reading from a byte array threw an IOException (should " +
+ "never happen).", 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(
+ "Reading from a byte array threw an IOException (should " +
+ "never happen).", 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());
+ }
+
+ /**
+ * Construct an UninitializedMessageException reporting missing fields in
+ * the given message.
+ */
+ protected static UninitializedMessageException
+ newUninitializedMessageException(MessageLite message) {
+ return new UninitializedMessageException(message);
+ }
+
+ /**
+ * Adds the {@code values} to the {@code list}. This is a helper method
+ * used by generated code. Users should ignore it.
+ *
+ * @throws NullPointerException if any of the elements of {@code values} is
+ * null.
+ */
+ protected static void addAll(final Iterable values,
+ final Collection super T> list) {
+ for (final T value : values) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ }
+ if (values instanceof Collection) {
+ final
+ Collection collection = (Collection) values;
+ list.addAll(collection);
+ } else {
+ for (final T value : values) {
+ list.add(value);
+ }
+ }
+ }
+ }
+}
diff --git a/OsmAnd-java/src/com/google/protobuf/BlockingRpcChannel.java b/OsmAnd-java/src/com/google/protobuf/BlockingRpcChannel.java
new file mode 100644
index 0000000000..1e81143aea
--- /dev/null
+++ b/OsmAnd-java/src/com/google/protobuf/BlockingRpcChannel.java
@@ -0,0 +1,51 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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;
+
+/**
+ *
Abstract interface for a blocking RPC channel. {@code BlockingRpcChannel}
+ * is the blocking equivalent to {@link RpcChannel}.
+ *
+ * @author kenton@google.com Kenton Varda
+ * @author cpovirk@google.com Chris Povirk
+ */
+public interface BlockingRpcChannel {
+ /**
+ * Call the given method of the remote service and blocks until it returns.
+ * {@code callBlockingMethod()} is the blocking equivalent to
+ * {@link RpcChannel#callMethod}.
+ */
+ Message callBlockingMethod(
+ Descriptors.MethodDescriptor method,
+ RpcController controller,
+ Message request,
+ Message responsePrototype) throws ServiceException;
+}
diff --git a/OsmAnd-java/src/com/google/protobuf/BlockingService.java b/OsmAnd-java/src/com/google/protobuf/BlockingService.java
new file mode 100644
index 0000000000..ecc80096f5
--- /dev/null
+++ b/OsmAnd-java/src/com/google/protobuf/BlockingService.java
@@ -0,0 +1,64 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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;
+
+/**
+ * Blocking equivalent to {@link Service}.
+ *
+ * @author kenton@google.com Kenton Varda
+ * @author cpovirk@google.com Chris Povirk
+ */
+public interface BlockingService {
+ /**
+ * Equivalent to {@link Service#getDescriptorForType}.
+ */
+ Descriptors.ServiceDescriptor getDescriptorForType();
+
+ /**
+ * Equivalent to {@link Service#callMethod}, except that
+ * {@code callBlockingMethod()} returns the result of the RPC or throws a
+ * {@link ServiceException} if there is a failure, rather than passing the
+ * information to a callback.
+ */
+ Message callBlockingMethod(Descriptors.MethodDescriptor method,
+ RpcController controller,
+ Message request) throws ServiceException;
+
+ /**
+ * Equivalent to {@link Service#getRequestPrototype}.
+ */
+ Message getRequestPrototype(Descriptors.MethodDescriptor method);
+
+ /**
+ * Equivalent to {@link Service#getResponsePrototype}.
+ */
+ Message getResponsePrototype(Descriptors.MethodDescriptor method);
+}
diff --git a/OsmAnd-java/src/com/google/protobuf/ByteString.java b/OsmAnd-java/src/com/google/protobuf/ByteString.java
new file mode 100644
index 0000000000..2eabc71aa8
--- /dev/null
+++ b/OsmAnd-java/src/com/google/protobuf/ByteString.java
@@ -0,0 +1,391 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.FilterOutputStream;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.nio.ByteBuffer;
+import java.util.List;
+
+/**
+ * Immutable array of bytes.
+ *
+ * @author crazybob@google.com Bob Lee
+ * @author kenton@google.com Kenton Varda
+ */
+public final class ByteString {
+ private final byte[] bytes;
+
+ private ByteString(final byte[] bytes) {
+ this.bytes = bytes;
+ }
+
+ /**
+ * Gets the byte at the given index.
+ *
+ * @throws ArrayIndexOutOfBoundsException {@code index} is < 0 or >= size
+ */
+ public byte byteAt(final int index) {
+ return bytes[index];
+ }
+
+ /**
+ * Gets the number of bytes.
+ */
+ public int size() {
+ return bytes.length;
+ }
+
+ /**
+ * Returns {@code true} if the size is {@code 0}, {@code false} otherwise.
+ */
+ public boolean isEmpty() {
+ return bytes.length == 0;
+ }
+
+ // =================================================================
+ // byte[] -> ByteString
+
+ /**
+ * Empty ByteString.
+ */
+ public static final ByteString EMPTY = new ByteString(new byte[0]);
+
+ /**
+ * Copies the given bytes into a {@code ByteString}.
+ */
+ public static ByteString copyFrom(final byte[] bytes, final int offset,
+ final int size) {
+ final byte[] copy = new byte[size];
+ System.arraycopy(bytes, offset, copy, 0, size);
+ return new ByteString(copy);
+ }
+
+ /**
+ * Copies the given bytes into a {@code ByteString}.
+ */
+ public static ByteString copyFrom(final byte[] bytes) {
+ return copyFrom(bytes, 0, bytes.length);
+ }
+
+ /**
+ * Copies {@code size} bytes from a {@code java.nio.ByteBuffer} into
+ * a {@code ByteString}.
+ */
+ public static ByteString copyFrom(final ByteBuffer bytes, final int size) {
+ final byte[] copy = new byte[size];
+ bytes.get(copy);
+ return new ByteString(copy);
+ }
+
+ /**
+ * Copies the remaining bytes from a {@code java.nio.ByteBuffer} into
+ * a {@code ByteString}.
+ */
+ public static ByteString copyFrom(final 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}.
+ */
+ public static ByteString copyFrom(final String text, final String charsetName)
+ throws UnsupportedEncodingException {
+ return new ByteString(text.getBytes(charsetName));
+ }
+
+ /**
+ * Encodes {@code text} into a sequence of UTF-8 bytes and returns the
+ * result as a {@code ByteString}.
+ */
+ public static ByteString copyFromUtf8(final String text) {
+ try {
+ return new ByteString(text.getBytes("UTF-8"));
+ } catch (UnsupportedEncodingException e) {
+ throw new RuntimeException("UTF-8 not supported?", e);
+ }
+ }
+
+ /**
+ * Concatenates all byte strings in the list and returns the result.
+ *
+ *
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.
+ */
+ public static ByteString copyFrom(List list) {
+ if (list.size() == 0) {
+ return EMPTY;
+ } else if (list.size() == 1) {
+ return list.get(0);
+ }
+
+ int size = 0;
+ for (ByteString str : list) {
+ size += str.size();
+ }
+ byte[] bytes = new byte[size];
+ int pos = 0;
+ for (ByteString str : list) {
+ System.arraycopy(str.bytes, 0, bytes, pos, str.size());
+ pos += str.size();
+ }
+ return new ByteString(bytes);
+ }
+
+ // =================================================================
+ // ByteString -> byte[]
+
+ /**
+ * Copies bytes into a buffer at the given offset.
+ *
+ * @param target buffer to copy into
+ * @param offset in the target buffer
+ */
+ public void copyTo(final byte[] target, final int offset) {
+ System.arraycopy(bytes, 0, target, offset, bytes.length);
+ }
+
+ /**
+ * 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 size number of bytes to copy
+ */
+ public void copyTo(final byte[] target, final int sourceOffset,
+ final int targetOffset,
+ final int size) {
+ System.arraycopy(bytes, sourceOffset, target, targetOffset, size);
+ }
+
+ /**
+ * Copies bytes to a {@code byte[]}.
+ */
+ public byte[] toByteArray() {
+ final int size = bytes.length;
+ final byte[] copy = new byte[size];
+ System.arraycopy(bytes, 0, copy, 0, size);
+ return copy;
+ }
+
+ /**
+ * Constructs a new read-only {@code java.nio.ByteBuffer} with the
+ * same backing byte array.
+ */
+ public ByteBuffer asReadOnlyByteBuffer() {
+ final ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
+ return byteBuffer.asReadOnlyBuffer();
+ }
+
+ /**
+ * Constructs a new {@code String} by decoding the bytes using the
+ * specified charset.
+ */
+ public String toString(final String charsetName)
+ throws UnsupportedEncodingException {
+ return new String(bytes, charsetName);
+ }
+
+ /**
+ * Constructs a new {@code String} by decoding the bytes as UTF-8.
+ */
+ public String toStringUtf8() {
+ try {
+ return new String(bytes, "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ throw new RuntimeException("UTF-8 not supported?", e);
+ }
+ }
+
+ // =================================================================
+ // equals() and hashCode()
+
+ @Override
+ public boolean equals(final Object o) {
+ if (o == this) {
+ return true;
+ }
+
+ if (!(o instanceof ByteString)) {
+ return false;
+ }
+
+ final ByteString other = (ByteString) o;
+ final int size = bytes.length;
+ if (size != other.bytes.length) {
+ return false;
+ }
+
+ final byte[] thisBytes = bytes;
+ final byte[] otherBytes = other.bytes;
+ for (int i = 0; i < size; i++) {
+ if (thisBytes[i] != otherBytes[i]) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ private volatile int hash = 0;
+
+ @Override
+ public int hashCode() {
+ int h = hash;
+
+ if (h == 0) {
+ final byte[] thisBytes = bytes;
+ final int size = bytes.length;
+
+ h = size;
+ for (int i = 0; i < size; i++) {
+ h = h * 31 + thisBytes[i];
+ }
+ if (h == 0) {
+ h = 1;
+ }
+
+ hash = h;
+ }
+
+ return h;
+ }
+
+ // =================================================================
+ // Input stream
+
+ /**
+ * Creates an {@code InputStream} which can be used to read the bytes.
+ */
+ public InputStream newInput() {
+ return new ByteArrayInputStream(bytes);
+ }
+
+ /**
+ * Creates a {@link CodedInputStream} which can be used to read the bytes.
+ * Using this is more efficient than creating a {@link CodedInputStream}
+ * wrapping the result of {@link #newInput()}.
+ */
+ public CodedInputStream newCodedInput() {
+ // We trust CodedInputStream not to modify the bytes, or to give anyone
+ // else access to them.
+ return CodedInputStream.newInstance(bytes);
+ }
+
+ // =================================================================
+ // Output stream
+
+ /**
+ * Creates a new {@link Output} with the given initial capacity.
+ */
+ public static Output newOutput(final int initialCapacity) {
+ return new Output(new ByteArrayOutputStream(initialCapacity));
+ }
+
+ /**
+ * Creates a new {@link Output}.
+ */
+ public static Output newOutput() {
+ return newOutput(32);
+ }
+
+ /**
+ * Outputs to a {@code ByteString} instance. Call {@link #toByteString()} to
+ * create the {@code ByteString} instance.
+ */
+ public static final class Output extends FilterOutputStream {
+ private final ByteArrayOutputStream bout;
+
+ /**
+ * Constructs a new output with the given initial capacity.
+ */
+ private Output(final ByteArrayOutputStream bout) {
+ super(bout);
+ this.bout = bout;
+ }
+
+ /**
+ * Creates a {@code ByteString} instance from this {@code Output}.
+ */
+ public ByteString toByteString() {
+ final byte[] byteArray = bout.toByteArray();
+ return new ByteString(byteArray);
+ }
+ }
+
+ /**
+ * Constructs a new 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.
+ */
+ static CodedBuilder newCodedBuilder(final 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(final 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 ByteString(buffer);
+ }
+
+ public CodedOutputStream getCodedOutput() {
+ return output;
+ }
+ }
+}
diff --git a/OsmAnd-java/src/com/google/protobuf/CodedInputStream.java b/OsmAnd-java/src/com/google/protobuf/CodedInputStream.java
new file mode 100644
index 0000000000..45004e2e28
--- /dev/null
+++ b/OsmAnd-java/src/com/google/protobuf/CodedInputStream.java
@@ -0,0 +1,924 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.io.InputStream;
+import java.io.RandomAccessFile;
+import java.util.ArrayList;
+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 final class CodedInputStream {
+ /**
+ * Create a new CodedInputStream wrapping the given InputStream.
+ */
+ public static CodedInputStream newInstance(final InputStream input) {
+ return new CodedInputStream(input);
+ }
+
+ /**
+ * 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 new CodedInputStream(buf, off, len);
+ }
+
+ // -----------------------------------------------------------------
+ // begin osmand change
+ public static CodedInputStream newInstance(RandomAccessFile raf) {
+ return new CodedInputStream(raf);
+ }
+ // end osmand change
+
+
+ /**
+ * 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 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;
+ }
+
+ /**
+ * 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 void checkLastTagWas(final int value)
+ throws InvalidProtocolBufferException {
+ if (lastTag != value) {
+ throw InvalidProtocolBufferException.invalidEndTag();
+ }
+ }
+
+ /**
+ * 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 boolean skipField(final int tag) throws IOException {
+ switch (WireFormat.getTagWireType(tag)) {
+ case WireFormat.WIRETYPE_VARINT:
+ readInt32();
+ return true;
+ case WireFormat.WIRETYPE_FIXED64:
+ readRawLittleEndian64();
+ 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:
+ readRawLittleEndian32();
+ return true;
+ default:
+ throw InvalidProtocolBufferException.invalidWireType();
+ }
+ }
+
+ /**
+ * Reads and discards an entire message. This will read either until EOF
+ * or until an endgroup tag, whichever comes first.
+ */
+ public void skipMessage() throws IOException {
+ while (true) {
+ final int tag = readTag();
+ if (tag == 0 || !skipField(tag)) {
+ return;
+ }
+ }
+ }
+
+ // -----------------------------------------------------------------
+
+ /** Read a {@code double} field value from the stream. */
+ public double readDouble() throws IOException {
+ return Double.longBitsToDouble(readRawLittleEndian64());
+ }
+
+ /** Read a {@code float} field value from the stream. */
+ public float readFloat() throws IOException {
+ return Float.intBitsToFloat(readRawLittleEndian32());
+ }
+
+ /** Read a {@code uint64} field value from the stream. */
+ public long readUInt64() throws IOException {
+ return readRawVarint64();
+ }
+
+ /** Read an {@code int64} field value from the stream. */
+ public long readInt64() throws IOException {
+ return readRawVarint64();
+ }
+
+ /** Read an {@code int32} field value from the stream. */
+ public int readInt32() throws IOException {
+ return readRawVarint32();
+ }
+
+ /** Read a {@code fixed64} field value from the stream. */
+ public long readFixed64() throws IOException {
+ return readRawLittleEndian64();
+ }
+
+ /** Read a {@code fixed32} field value from the stream. */
+ public int readFixed32() throws IOException {
+ return readRawLittleEndian32();
+ }
+
+ /** Read a {@code bool} field value from the stream. */
+ public boolean readBool() throws IOException {
+ return readRawVarint32() != 0;
+ }
+
+ /** Read a {@code string} field value from the stream. */
+ public String readString() throws IOException {
+ final int size = readRawVarint32();
+ if (size <= (bufferSize - bufferPos) && size > 0) {
+ // Fast path: We already have the bytes in a contiguous buffer, so
+ // just copy directly from it.
+ final String result = new String(buffer, bufferPos, size, "UTF-8");
+ bufferPos += size;
+ return result;
+ } else {
+ // Slow path: Build a byte array first then copy it.
+ return new String(readRawBytes(size), "UTF-8");
+ }
+ }
+
+ /** Read a {@code group} field value from the stream. */
+ 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;
+ }
+
+ /**
+ * 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 void readUnknownGroup(final int fieldNumber,
+ final MessageLite.Builder builder)
+ throws IOException {
+ // We know that UnknownFieldSet will ignore any ExtensionRegistry so it
+ // is safe to pass null here. (We can't call
+ // ExtensionRegistry.getEmptyRegistry() because that would make this
+ // class depend on ExtensionRegistry, which is not part of the lite
+ // library.)
+ readGroup(fieldNumber, builder, null);
+ }
+
+ /** Read an embedded message field value from the stream. */
+ 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);
+ }
+
+ /** Read a {@code bytes} field value from the stream. */
+ public ByteString readBytes() throws IOException {
+ final int size = readRawVarint32();
+ if (size <= (bufferSize - bufferPos) && 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, bufferPos, size);
+ bufferPos += size;
+ return result;
+ } else {
+ // Slow path: Build a byte array first then copy it.
+ return ByteString.copyFrom(readRawBytes(size));
+ }
+ }
+
+ /** Read a {@code uint32} field value from the stream. */
+ public int readUInt32() throws IOException {
+ return readRawVarint32();
+ }
+
+ /**
+ * Read an enum field value from the stream. Caller is responsible
+ * for converting the numeric value to an actual enum.
+ */
+ public int readEnum() throws IOException {
+ return readRawVarint32();
+ }
+
+ /** Read an {@code sfixed32} field value from the stream. */
+ public int readSFixed32() throws IOException {
+ return readRawLittleEndian32();
+ }
+
+ /** Read an {@code sfixed64} field value from the stream. */
+ public long readSFixed64() throws IOException {
+ return readRawLittleEndian64();
+ }
+
+ /** Read an {@code sint32} field value from the stream. */
+ public int readSInt32() throws IOException {
+ return decodeZigZag32(readRawVarint32());
+ }
+
+ /** Read an {@code sint64} field value from the stream. */
+ public long readSInt64() throws IOException {
+ return decodeZigZag64(readRawVarint64());
+ }
+
+ // =================================================================
+
+ /**
+ * Read a raw Varint from the stream. If larger than 32 bits, discard the
+ * upper bits.
+ */
+ public int readRawVarint32() throws IOException {
+ byte tmp = readRawByte();
+ if (tmp >= 0) {
+ return tmp;
+ }
+ int result = tmp & 0x7f;
+ if ((tmp = readRawByte()) >= 0) {
+ result |= tmp << 7;
+ } else {
+ result |= (tmp & 0x7f) << 7;
+ if ((tmp = readRawByte()) >= 0) {
+ result |= tmp << 14;
+ } else {
+ result |= (tmp & 0x7f) << 14;
+ if ((tmp = readRawByte()) >= 0) {
+ result |= tmp << 21;
+ } else {
+ result |= (tmp & 0x7f) << 21;
+ result |= (tmp = readRawByte()) << 28;
+ if (tmp < 0) {
+ // Discard upper 32 bits.
+ for (int i = 0; i < 5; i++) {
+ if (readRawByte() >= 0) {
+ return result;
+ }
+ }
+ throw InvalidProtocolBufferException.malformedVarint();
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+ /**
+ * 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);
+ }
+
+ /**
+ * 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.
+ */
+ 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();
+ }
+
+ /** Read a raw Varint from the stream. */
+ public long readRawVarint64() throws IOException {
+ int shift = 0;
+ long result = 0;
+ while (shift < 64) {
+ final byte b = readRawByte();
+ result |= (long)(b & 0x7F) << shift;
+ if ((b & 0x80) == 0) {
+ return result;
+ }
+ shift += 7;
+ }
+ throw InvalidProtocolBufferException.malformedVarint();
+ }
+
+ /** Read a 32-bit little-endian integer from the stream. */
+ public int readRawLittleEndian32() throws IOException {
+ final byte b1 = readRawByte();
+ final byte b2 = readRawByte();
+ final byte b3 = readRawByte();
+ final byte b4 = readRawByte();
+ return (((int)b1 & 0xff) ) |
+ (((int)b2 & 0xff) << 8) |
+ (((int)b3 & 0xff) << 16) |
+ (((int)b4 & 0xff) << 24);
+ }
+
+ /** Read a 64-bit little-endian integer from the stream. */
+ public long readRawLittleEndian64() throws IOException {
+ final byte b1 = readRawByte();
+ final byte b2 = readRawByte();
+ final byte b3 = readRawByte();
+ final byte b4 = readRawByte();
+ final byte b5 = readRawByte();
+ final byte b6 = readRawByte();
+ final byte b7 = readRawByte();
+ final byte b8 = readRawByte();
+ return (((long)b1 & 0xff) ) |
+ (((long)b2 & 0xff) << 8) |
+ (((long)b3 & 0xff) << 16) |
+ (((long)b4 & 0xff) << 24) |
+ (((long)b5 & 0xff) << 32) |
+ (((long)b6 & 0xff) << 40) |
+ (((long)b7 & 0xff) << 48) |
+ (((long)b8 & 0xff) << 56);
+ }
+
+ /**
+ * 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);
+ }
+
+ // -----------------------------------------------------------------
+
+ private final byte[] buffer;
+ private RandomAccessFile raf;
+ private int bufferSize;
+ private int bufferSizeAfterLimit;
+ private int bufferPos;
+ private final InputStream input;
+ 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 + bufferPos}. 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;
+
+ /** See setRecursionLimit() */
+ private int recursionDepth;
+ private int recursionLimit = DEFAULT_RECURSION_LIMIT;
+
+ /** See setSizeLimit() */
+ private int sizeLimit = DEFAULT_SIZE_LIMIT;
+
+ private static final int DEFAULT_RECURSION_LIMIT = 64;
+ private static final int DEFAULT_SIZE_LIMIT = 64 << 20; // 64MB
+ private static final int BUFFER_SIZE = 5 * 1024;
+
+
+ private CodedInputStream(final byte[] buffer, final int off, final int len) {
+ this.buffer = buffer;
+ bufferSize = off + len;
+ bufferPos = off;
+ totalBytesRetired = -off;
+ input = null;
+ }
+
+ private CodedInputStream(final InputStream input) {
+ buffer = new byte[BUFFER_SIZE];
+ bufferSize = 0;
+ bufferPos = 0;
+ totalBytesRetired = 0;
+ this.input = input;
+ }
+
+ private CodedInputStream(final RandomAccessFile raf) {
+ buffer = new byte[BUFFER_SIZE];
+ this.bufferSize = 0;
+ bufferPos = 0;
+ totalBytesRetired = 0;
+ this.raf = raf;
+ input = null;
+ }
+
+ /**
+ * 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 64.
+ *
+ * @return the old limit.
+ */
+ public 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;
+ }
+
+ /**
+ * 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 64MB. 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 (nor with
+ * {@link ByteString#newCodedInput}).
+ *
+ * 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 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;
+ }
+
+ /**
+ * Resets the current size counter to zero (see {@link #setSizeLimit(int)}).
+ */
+ public void resetSizeCounter() {
+ totalBytesRetired = -bufferPos;
+ }
+
+ /**
+ * 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 you {@code InputStream}
+ * which limits the amount of data that can be read from it.
+ *
+ * @return the old limit.
+ */
+ public int pushLimit(int byteLimit) throws InvalidProtocolBufferException {
+ if (byteLimit < 0) {
+ throw InvalidProtocolBufferException.negativeSize();
+ }
+ byteLimit += totalBytesRetired + bufferPos;
+ 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;
+ }
+ }
+
+ /**
+ * Discards the current limit, returning to the previous limit.
+ *
+ * @param oldLimit The old limit, as returned by {@code pushLimit}.
+ */
+ public void popLimit(final int oldLimit) {
+ currentLimit = oldLimit;
+ recomputeBufferSizeAfterLimit();
+ }
+
+ /**
+ * Returns the number of bytes to be read before the current limit.
+ * If no limit is set, returns -1.
+ */
+ public int getBytesUntilLimit() {
+ if (currentLimit == Integer.MAX_VALUE) {
+ return -1;
+ }
+
+ final int currentAbsolutePosition = totalBytesRetired + bufferPos;
+ return currentLimit - currentAbsolutePosition;
+ }
+
+ /**
+ * 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)}.
+ */
+ public boolean isAtEnd() throws IOException {
+ return bufferPos == bufferSize && !refillBuffer(false);
+ }
+
+ /**
+ * The total bytes read up to the current position. Calling
+ * {@link #resetSizeCounter()} resets this value to zero.
+ */
+ public int getTotalBytesRead() {
+ return totalBytesRetired + bufferPos;
+ }
+
+ /**
+ * Called with {@code this.buffer} is empty to read more bytes from the
+ * input. If {@code mustSucceed} is true, refillBuffer() gurantees that
+ * either there will be at least one byte in the buffer when it returns
+ * or it will throw an exception. If {@code mustSucceed} is false,
+ * refillBuffer() returns false if no more bytes were available.
+ */
+ private boolean refillBuffer(final boolean mustSucceed) throws IOException {
+ if (bufferPos < bufferSize) {
+ throw new IllegalStateException(
+ "refillBuffer() called when buffer wasn't empty.");
+ }
+
+ if (totalBytesRetired + bufferSize == currentLimit) {
+ // Oops, we hit a limit.
+ if (mustSucceed) {
+ throw InvalidProtocolBufferException.truncatedMessage();
+ } else {
+ return false;
+ }
+ }
+
+ totalBytesRetired += bufferSize;
+
+ bufferPos = 0;
+ if (raf != null) {
+ // osmand change
+ long remain = raf.length() - raf.getFilePointer();
+ bufferSize = (int) Math.min(remain, buffer.length);
+ if(bufferSize > 0) {
+ raf.readFully(buffer, 0, bufferSize);
+ } else {
+ bufferSize = -1;
+ }
+ } else {
+ bufferSize = (input == null) ? -1 : input.read(buffer);
+ }
+ if (bufferSize == 0 || bufferSize < -1) {
+ throw new IllegalStateException(
+ "InputStream#read(byte[]) returned invalid result: " + bufferSize +
+ "\nThe InputStream implementation is buggy.");
+ }
+ if (bufferSize == -1) {
+ bufferSize = 0;
+ if (mustSucceed) {
+ throw InvalidProtocolBufferException.truncatedMessage();
+ } else {
+ return false;
+ }
+ } else {
+ recomputeBufferSizeAfterLimit();
+ final int totalBytesRead =
+ totalBytesRetired + bufferSize + bufferSizeAfterLimit;
+ if (totalBytesRead > sizeLimit || totalBytesRead < 0) {
+ throw InvalidProtocolBufferException.sizeLimitExceeded();
+ }
+ return true;
+ }
+ }
+
+ /**
+ * Read one byte from the input.
+ *
+ * @throws InvalidProtocolBufferException The end of the stream or the current
+ * limit was reached.
+ */
+ public byte readRawByte() throws IOException {
+ if (bufferPos == bufferSize) {
+ refillBuffer(true);
+ }
+ return buffer[bufferPos++];
+ }
+
+ /**
+ * Read a fixed size of bytes from the input.
+ *
+ * @throws InvalidProtocolBufferException The end of the stream or the current
+ * limit was reached.
+ */
+ public byte[] readRawBytes(final int size) throws IOException {
+ if (size < 0) {
+ throw InvalidProtocolBufferException.negativeSize();
+ }
+
+ if (totalBytesRetired + bufferPos + size > currentLimit) {
+ // Read to the end of the stream anyway.
+ skipRawBytes(currentLimit - totalBytesRetired - bufferPos);
+ // Then fail.
+ throw InvalidProtocolBufferException.truncatedMessage();
+ }
+
+ if (size <= bufferSize - bufferPos) {
+ // We have all the bytes we need already.
+ final byte[] bytes = new byte[size];
+ System.arraycopy(buffer, bufferPos, bytes, 0, size);
+ bufferPos += size;
+ return bytes;
+ } else if (size < BUFFER_SIZE) {
+ // Reading more bytes than are in the buffer, but not an excessive number
+ // of bytes. We can safely allocate the resulting array ahead of time.
+
+ // First copy what we have.
+ final byte[] bytes = new byte[size];
+ int pos = bufferSize - bufferPos;
+ System.arraycopy(buffer, bufferPos, bytes, 0, pos);
+ bufferPos = bufferSize;
+
+ // We want to use refillBuffer() and then copy from the buffer into our
+ // byte array rather than reading directly into our byte array because
+ // the input may be unbuffered.
+ refillBuffer(true);
+
+ while (size - pos > bufferSize) {
+ System.arraycopy(buffer, 0, bytes, pos, bufferSize);
+ pos += bufferSize;
+ bufferPos = bufferSize;
+ refillBuffer(true);
+ }
+
+ System.arraycopy(buffer, 0, bytes, pos, size - pos);
+ bufferPos = size - pos;
+
+ return bytes;
+ } else {
+ // 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.
+
+ // Remember the buffer markers since we'll have to copy the bytes out of
+ // it later.
+ final int originalBufferPos = bufferPos;
+ final int originalBufferSize = bufferSize;
+
+ // Mark the current buffer consumed.
+ totalBytesRetired += bufferSize;
+ bufferPos = 0;
+ bufferSize = 0;
+
+ // Read all the rest of the bytes we need.
+ int sizeLeft = size - (originalBufferSize - originalBufferPos);
+ final List chunks = new ArrayList();
+
+ while (sizeLeft > 0) {
+ final byte[] chunk = new byte[Math.min(sizeLeft, BUFFER_SIZE)];
+ int pos = 0;
+ while (pos < chunk.length) {
+
+ final int n;
+ // osmand change
+ if(raf != null) {
+ raf.readFully(chunk, pos, chunk.length - pos);
+ n = chunk.length - pos;
+ } else {
+ n = (input == null) ? -1 :
+ input.read(chunk, pos, chunk.length - pos);
+ }
+ if (n == -1) {
+ throw InvalidProtocolBufferException.truncatedMessage();
+ }
+ totalBytesRetired += n;
+ pos += n;
+ }
+ sizeLeft -= chunk.length;
+ chunks.add(chunk);
+ }
+
+ // 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.
+ int pos = originalBufferSize - originalBufferPos;
+ System.arraycopy(buffer, originalBufferPos, bytes, 0, pos);
+
+ // And now all the chunks.
+ for (final byte[] chunk : chunks) {
+ System.arraycopy(chunk, 0, bytes, pos, chunk.length);
+ pos += chunk.length;
+ }
+ // Done.
+ return bytes;
+ }
+ }
+
+ /**
+ * Reads and discards {@code size} bytes.
+ *
+ * @throws InvalidProtocolBufferException The end of the stream or the current
+ * limit was reached.
+ */
+ public void skipRawBytes(final int size) throws IOException {
+ if (size < 0) {
+ throw InvalidProtocolBufferException.negativeSize();
+ }
+
+ if (totalBytesRetired + bufferPos + size > currentLimit) {
+ // Read to the end of the stream anyway.
+ skipRawBytes(currentLimit - totalBytesRetired - bufferPos);
+ // Then fail.
+ throw InvalidProtocolBufferException.truncatedMessage();
+ }
+
+ if (size <= bufferSize - bufferPos) {
+ // We have all the bytes we need already.
+ bufferPos += size;
+ } else {
+ // Skipping more bytes than are in the buffer. First skip what we have.
+ int pos = bufferSize - bufferPos;
+ totalBytesRetired += bufferSize; // ? pos incorrect
+ bufferPos = 0;
+ bufferSize = 0;
+
+ // Then skip directly from the InputStream for the rest.
+ while (pos < size) {
+ // osmand change
+ final int n ;
+ if(raf != null) {
+ n = raf.skipBytes(size - pos);
+ } else {
+ n = (input == null) ? -1 : (int) input.skip(size - pos);
+ }
+ if (n <= 0) {
+ throw InvalidProtocolBufferException.truncatedMessage();
+ }
+ pos += n;
+ totalBytesRetired += n;
+ }
+ }
+ }
+
+ // osmand change
+ public void seek(long pointer) throws IOException {
+ if (pointer - totalBytesRetired >= 0 && pointer - totalBytesRetired < bufferSize) {
+ if (pointer > currentLimit) {
+ // Then fail.
+ throw InvalidProtocolBufferException.truncatedMessage();
+ }
+ bufferPos = (int) (pointer - totalBytesRetired);
+ } else {
+ totalBytesRetired = (int) pointer;
+ bufferSizeAfterLimit = 0;
+ raf.seek(pointer);
+ bufferPos = 0;
+ bufferSize = 0;
+ }
+ }
+}
diff --git a/OsmAnd-java/src/com/google/protobuf/CodedInputStreamRAF.java b/OsmAnd-java/src/com/google/protobuf/CodedInputStreamRAF.java
new file mode 100644
index 0000000000..02c1ee5d0f
--- /dev/null
+++ b/OsmAnd-java/src/com/google/protobuf/CodedInputStreamRAF.java
@@ -0,0 +1,825 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.EOFException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.RandomAccessFile;
+import java.util.ArrayList;
+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
+ * OSMAND change
+ */
+public final class CodedInputStreamRAF {
+ /**
+ * Create a new CodedInputStream wrapping the given InputStream.
+ */
+ public static CodedInputStreamRAF newInstance(RandomAccessFile raf) {
+ return new CodedInputStreamRAF(raf, BUFFER_SIZE_DEF);
+ }
+
+ public static CodedInputStreamRAF newInstance(RandomAccessFile raf, int bufferSize) {
+ return new CodedInputStreamRAF(raf, bufferSize);
+ }
+
+
+ // -----------------------------------------------------------------
+
+ /**
+ * 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 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;
+ }
+
+ /**
+ * 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 void checkLastTagWas(final int value)
+ throws InvalidProtocolBufferException {
+ if (lastTag != value) {
+ throw InvalidProtocolBufferException.invalidEndTag();
+ }
+ }
+
+ /**
+ * 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 boolean skipField(final int tag) throws IOException {
+ switch (WireFormat.getTagWireType(tag)) {
+ case WireFormat.WIRETYPE_VARINT:
+ readInt32();
+ return true;
+ case WireFormat.WIRETYPE_FIXED64:
+ readRawLittleEndian64();
+ 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:
+ readRawLittleEndian32();
+ return true;
+ default:
+ throw InvalidProtocolBufferException.invalidWireType();
+ }
+ }
+
+ /**
+ * Reads and discards an entire message. This will read either until EOF
+ * or until an endgroup tag, whichever comes first.
+ */
+ public void skipMessage() throws IOException {
+ while (true) {
+ final int tag = readTag();
+ if (tag == 0 || !skipField(tag)) {
+ return;
+ }
+ }
+ }
+
+ // -----------------------------------------------------------------
+
+ /** Read a {@code double} field value from the stream. */
+ public double readDouble() throws IOException {
+ return Double.longBitsToDouble(readRawLittleEndian64());
+ }
+
+ /** Read a {@code float} field value from the stream. */
+ public float readFloat() throws IOException {
+ return Float.intBitsToFloat(readRawLittleEndian32());
+ }
+
+ /** Read a {@code uint64} field value from the stream. */
+ public long readUInt64() throws IOException {
+ return readRawVarint64();
+ }
+
+ /** Read an {@code int64} field value from the stream. */
+ public long readInt64() throws IOException {
+ return readRawVarint64();
+ }
+
+ /** Read an {@code int32} field value from the stream. */
+ public int readInt32() throws IOException {
+ return readRawVarint32();
+ }
+
+ /** Read a {@code fixed64} field value from the stream. */
+ public long readFixed64() throws IOException {
+ return readRawLittleEndian64();
+ }
+
+ /** Read a {@code fixed32} field value from the stream. */
+ public int readFixed32() throws IOException {
+ return readRawLittleEndian32();
+ }
+
+ /** Read a {@code bool} field value from the stream. */
+ public boolean readBool() throws IOException {
+ return readRawVarint32() != 0;
+ }
+
+ /** Read a {@code string} field value from the stream. */
+ public String readString() throws IOException {
+ final int size = readRawVarint32();
+ if (size <= (bufferSize - bufferPos) && size > 0) {
+ // Fast path: We already have the bytes in a contiguous buffer, so
+ // just copy directly from it.
+ final String result = new String(buffer, bufferPos, size, "UTF-8");
+ bufferPos += size;
+ return result;
+ } else {
+ // Slow path: Build a byte array first then copy it.
+ return new String(readRawBytes(size), "UTF-8");
+ }
+ }
+
+
+
+
+ /** Read a {@code bytes} field value from the stream. */
+ public ByteString readBytes() throws IOException {
+ final int size = readRawVarint32();
+ if (size <= (bufferSize - bufferPos) && 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, bufferPos, size);
+ bufferPos += size;
+ return result;
+ } else {
+ // Slow path: Build a byte array first then copy it.
+ return ByteString.copyFrom(readRawBytes(size));
+ }
+ }
+
+ /** Read a {@code uint32} field value from the stream. */
+ public int readUInt32() throws IOException {
+ return readRawVarint32();
+ }
+
+ /**
+ * Read an enum field value from the stream. Caller is responsible
+ * for converting the numeric value to an actual enum.
+ */
+ public int readEnum() throws IOException {
+ return readRawVarint32();
+ }
+
+ /** Read an {@code sfixed32} field value from the stream. */
+ public int readSFixed32() throws IOException {
+ return readRawLittleEndian32();
+ }
+
+ /** Read an {@code sfixed64} field value from the stream. */
+ public long readSFixed64() throws IOException {
+ return readRawLittleEndian64();
+ }
+
+ /** Read an {@code sint32} field value from the stream. */
+ public int readSInt32() throws IOException {
+ return decodeZigZag32(readRawVarint32());
+ }
+
+ /** Read an {@code sint64} field value from the stream. */
+ public long readSInt64() throws IOException {
+ return decodeZigZag64(readRawVarint64());
+ }
+
+ // =================================================================
+
+ /**
+ * Read a raw Varint from the stream. If larger than 32 bits, discard the
+ * upper bits.
+ */
+ public int readRawVarint32() throws IOException {
+ byte tmp = readRawByte();
+ if (tmp >= 0) {
+ return tmp;
+ }
+ int result = tmp & 0x7f;
+ if ((tmp = readRawByte()) >= 0) {
+ result |= tmp << 7;
+ } else {
+ result |= (tmp & 0x7f) << 7;
+ if ((tmp = readRawByte()) >= 0) {
+ result |= tmp << 14;
+ } else {
+ result |= (tmp & 0x7f) << 14;
+ if ((tmp = readRawByte()) >= 0) {
+ result |= tmp << 21;
+ } else {
+ result |= (tmp & 0x7f) << 21;
+ result |= (tmp = readRawByte()) << 28;
+ if (tmp < 0) {
+ // Discard upper 32 bits.
+ for (int i = 0; i < 5; i++) {
+ if (readRawByte() >= 0) {
+ return result;
+ }
+ }
+ throw InvalidProtocolBufferException.malformedVarint();
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+ /**
+ * 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);
+ }
+
+ /**
+ * 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.
+ */
+ 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();
+ }
+
+ /** Read a raw Varint from the stream. */
+ public long readRawVarint64() throws IOException {
+ int shift = 0;
+ long result = 0;
+ while (shift < 64) {
+ final byte b = readRawByte();
+ result |= (long)(b & 0x7F) << shift;
+ if ((b & 0x80) == 0) {
+ return result;
+ }
+ shift += 7;
+ }
+ throw InvalidProtocolBufferException.malformedVarint();
+ }
+
+ /** Read a 32-bit little-endian integer from the stream. */
+ public int readRawLittleEndian32() throws IOException {
+ final byte b1 = readRawByte();
+ final byte b2 = readRawByte();
+ final byte b3 = readRawByte();
+ final byte b4 = readRawByte();
+ return (((int)b1 & 0xff) ) |
+ (((int)b2 & 0xff) << 8) |
+ (((int)b3 & 0xff) << 16) |
+ (((int)b4 & 0xff) << 24);
+ }
+
+ /** Read a 64-bit little-endian integer from the stream. */
+ public long readRawLittleEndian64() throws IOException {
+ final byte b1 = readRawByte();
+ final byte b2 = readRawByte();
+ final byte b3 = readRawByte();
+ final byte b4 = readRawByte();
+ final byte b5 = readRawByte();
+ final byte b6 = readRawByte();
+ final byte b7 = readRawByte();
+ final byte b8 = readRawByte();
+ return (((long)b1 & 0xff) ) |
+ (((long)b2 & 0xff) << 8) |
+ (((long)b3 & 0xff) << 16) |
+ (((long)b4 & 0xff) << 24) |
+ (((long)b5 & 0xff) << 32) |
+ (((long)b6 & 0xff) << 40) |
+ (((long)b7 & 0xff) << 48) |
+ (((long)b8 & 0xff) << 56);
+ }
+
+ /**
+ * 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);
+ }
+
+ // -----------------------------------------------------------------
+
+ private final byte[] buffer;
+ private int bufferSize;
+ private int bufferSizeAfterLimit;
+ private int bufferPos;
+ private final RandomAccessFile raf;
+ 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 + bufferPos}. 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;
+
+ /** See setRecursionLimit() */
+ private int recursionDepth;
+ private int recursionLimit = DEFAULT_RECURSION_LIMIT;
+
+ /** See setSizeLimit() */
+ private int sizeLimit = DEFAULT_SIZE_LIMIT;
+
+ private static final int DEFAULT_RECURSION_LIMIT = 64;
+ private static final int DEFAULT_SIZE_LIMIT = 64 << 20; // 64MB
+ private static final int BUFFER_SIZE_DEF = 4096;
+ private int BUFFER_SIZE = BUFFER_SIZE_DEF;
+
+
+ private CodedInputStreamRAF(final RandomAccessFile raf, int bufferSize) {
+ BUFFER_SIZE = bufferSize;
+ buffer = new byte[BUFFER_SIZE];
+ this.bufferSize = 0;
+ bufferPos = 0;
+ totalBytesRetired = 0;
+ this.raf = raf;
+ }
+
+ /**
+ * 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 64.
+ *
+ * @return the old limit.
+ */
+ public 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;
+ }
+
+ /**
+ * 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 64MB. 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 (nor with
+ * {@link ByteString#newCodedInput}).
+ *
+ * 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 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;
+ }
+
+ /**
+ * Resets the current size counter to zero (see {@link #setSizeLimit(int)}).
+ */
+ public void resetSizeCounter() {
+ totalBytesRetired = -bufferPos;
+ }
+
+ /**
+ * 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 you {@code InputStream}
+ * which limits the amount of data that can be read from it.
+ *
+ * @return the old limit.
+ */
+ public int pushLimit(int byteLimit) throws InvalidProtocolBufferException {
+ if (byteLimit < 0) {
+ throw InvalidProtocolBufferException.negativeSize();
+ }
+ byteLimit += totalBytesRetired + bufferPos;
+ 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;
+ }
+ }
+
+ /**
+ * Discards the current limit, returning to the previous limit.
+ *
+ * @param oldLimit The old limit, as returned by {@code pushLimit}.
+ */
+ public void popLimit(final int oldLimit) {
+ currentLimit = oldLimit;
+ recomputeBufferSizeAfterLimit();
+ }
+
+ /**
+ * Returns the number of bytes to be read before the current limit.
+ * If no limit is set, returns -1.
+ */
+ public int getBytesUntilLimit() {
+ if (currentLimit == Integer.MAX_VALUE) {
+ return -1;
+ }
+
+ final int currentAbsolutePosition = totalBytesRetired + bufferPos;
+ return currentLimit - currentAbsolutePosition;
+ }
+
+ /**
+ * 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)}.
+ */
+ public boolean isAtEnd() throws IOException {
+ return bufferPos == bufferSize && !refillBuffer(false);
+ }
+
+ /**
+ * The total bytes read up to the current position. Calling
+ * {@link #resetSizeCounter()} resets this value to zero.
+ */
+ public int getTotalBytesRead() {
+ return totalBytesRetired + bufferPos;
+ }
+
+ /**
+ * Called with {@code this.buffer} is empty to read more bytes from the
+ * input. If {@code mustSucceed} is true, refillBuffer() gurantees that
+ * either there will be at least one byte in the buffer when it returns
+ * or it will throw an exception. If {@code mustSucceed} is false,
+ * refillBuffer() returns false if no more bytes were available.
+ */
+ private boolean refillBuffer(final boolean mustSucceed) throws IOException {
+ if (bufferPos < bufferSize) {
+ throw new IllegalStateException(
+ "refillBuffer() called when buffer wasn't empty.");
+ }
+
+ if (totalBytesRetired + bufferSize == currentLimit) {
+ // Oops, we hit a limit.
+ if (mustSucceed) {
+ throw InvalidProtocolBufferException.truncatedMessage();
+ } else {
+ return false;
+ }
+ }
+
+ totalBytesRetired += bufferSize;
+
+ bufferPos = 0;
+ // osmand change
+ bufferSize = raf.read(buffer);
+ if (bufferSize == 0 || bufferSize < -1) {
+ throw new IllegalStateException(
+ "InputStream#read(byte[]) returned invalid result: " + bufferSize +
+ "\nThe InputStream implementation is buggy.");
+ }
+ if (bufferSize == -1) {
+ bufferSize = 0;
+ if (mustSucceed) {
+ throw InvalidProtocolBufferException.truncatedMessage();
+ } else {
+ return false;
+ }
+ } else {
+ recomputeBufferSizeAfterLimit();
+ final int totalBytesRead =
+ totalBytesRetired + bufferSize + bufferSizeAfterLimit;
+ if (totalBytesRead > sizeLimit || totalBytesRead < 0) {
+ throw InvalidProtocolBufferException.sizeLimitExceeded();
+ }
+ return true;
+ }
+ }
+
+ /**
+ * Read one byte from the input.
+ *
+ * @throws InvalidProtocolBufferException The end of the stream or the current
+ * limit was reached.
+ */
+ public byte readRawByte() throws IOException {
+ if (bufferPos == bufferSize) {
+ refillBuffer(true);
+ }
+ return buffer[bufferPos++];
+ }
+
+ /**
+ * Read a fixed size of bytes from the input.
+ *
+ * @throws InvalidProtocolBufferException The end of the stream or the current
+ * limit was reached.
+ */
+ public byte[] readRawBytes(final int size) throws IOException {
+ if (size < 0) {
+ throw InvalidProtocolBufferException.negativeSize();
+ }
+
+ if (totalBytesRetired + bufferPos + size > currentLimit) {
+ // Read to the end of the stream anyway.
+ skipRawBytes(currentLimit - totalBytesRetired - bufferPos);
+ // Then fail.
+ throw InvalidProtocolBufferException.truncatedMessage();
+ }
+
+ if (size <= bufferSize - bufferPos) {
+ // We have all the bytes we need already.
+ final byte[] bytes = new byte[size];
+ System.arraycopy(buffer, bufferPos, bytes, 0, size);
+ bufferPos += size;
+ return bytes;
+ } else if (size < BUFFER_SIZE) {
+ // Reading more bytes than are in the buffer, but not an excessive number
+ // of bytes. We can safely allocate the resulting array ahead of time.
+
+ // First copy what we have.
+ final byte[] bytes = new byte[size];
+ int pos = bufferSize - bufferPos;
+ System.arraycopy(buffer, bufferPos, bytes, 0, pos);
+ bufferPos = bufferSize;
+
+ // We want to use refillBuffer() and then copy from the buffer into our
+ // byte array rather than reading directly into our byte array because
+ // the input may be unbuffered.
+ refillBuffer(true);
+
+ while (size - pos > bufferSize) {
+ System.arraycopy(buffer, 0, bytes, pos, bufferSize);
+ pos += bufferSize;
+ bufferPos = bufferSize;
+ refillBuffer(true);
+ }
+
+ System.arraycopy(buffer, 0, bytes, pos, size - pos);
+ bufferPos = size - pos;
+
+ return bytes;
+ } else {
+ // 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.
+
+ // Remember the buffer markers since we'll have to copy the bytes out of
+ // it later.
+ final int originalBufferPos = bufferPos;
+ final int originalBufferSize = bufferSize;
+
+ // Mark the current buffer consumed.
+ totalBytesRetired += bufferSize;
+ bufferPos = 0;
+ bufferSize = 0;
+
+ // Read all the rest of the bytes we need.
+ int sizeLeft = size - (originalBufferSize - originalBufferPos);
+ final List chunks = new ArrayList();
+
+ while (sizeLeft > 0) {
+ final byte[] chunk = new byte[Math.min(sizeLeft, BUFFER_SIZE)];
+ int pos = 0;
+ while (pos < chunk.length) {
+ // osmand change
+ final int n = raf.read(chunk, pos, chunk.length - pos);
+ if (n == -1) {
+ throw InvalidProtocolBufferException.truncatedMessage();
+ }
+ totalBytesRetired += n;
+ pos += n;
+ }
+ sizeLeft -= chunk.length;
+ chunks.add(chunk);
+ }
+
+ // 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.
+ int pos = originalBufferSize - originalBufferPos;
+ System.arraycopy(buffer, originalBufferPos, bytes, 0, pos);
+
+ // And now all the chunks.
+ for (final byte[] chunk : chunks) {
+ System.arraycopy(chunk, 0, bytes, pos, chunk.length);
+ pos += chunk.length;
+ }
+
+ // Done.
+ return bytes;
+ }
+ }
+
+ /**
+ * Reads and discards {@code size} bytes.
+ *
+ * @throws InvalidProtocolBufferException The end of the stream or the current
+ * limit was reached.
+ */
+ public void skipRawBytes(final int size) throws IOException {
+ if (size < 0) {
+ throw InvalidProtocolBufferException.negativeSize();
+ }
+
+ if (totalBytesRetired + bufferPos + size > currentLimit) {
+ // Read to the end of the stream anyway.
+ skipRawBytes(currentLimit - totalBytesRetired - bufferPos);
+ // Then fail.
+ throw InvalidProtocolBufferException.truncatedMessage();
+ }
+
+ if (size <= bufferSize - bufferPos) {
+ // We have all the bytes we need already.
+ bufferPos += size;
+ } else {
+ // Skipping more bytes than are in the buffer. First skip what we have.
+ int pos = bufferSize - bufferPos;
+ totalBytesRetired += bufferSize;
+ bufferPos = 0;
+ bufferSize = 0;
+
+ // Then skip directly from the InputStream for the rest.
+ while (pos < size) {
+ // osmand change
+ final int n = raf.skipBytes(size - pos);
+ if (n <= 0) {
+ throw InvalidProtocolBufferException.truncatedMessage();
+ }
+ pos += n;
+ totalBytesRetired += n;
+ }
+ }
+ }
+
+ // osmand change
+ public void seek(long pointer) throws IOException{
+ if(pointer - totalBytesRetired >= 0 && pointer - totalBytesRetired < bufferSize){
+ if (pointer > currentLimit) {
+ // Then fail.
+ throw InvalidProtocolBufferException.truncatedMessage();
+ }
+ bufferPos = (int) (pointer - totalBytesRetired);
+ } else {
+ totalBytesRetired = (int) pointer;
+ bufferSizeAfterLimit = 0;
+ raf.seek(pointer);
+ bufferPos = 0;
+ bufferSize = 0;
+ }
+ }
+}
diff --git a/OsmAnd-java/src/com/google/protobuf/CodedOutputStream.java b/OsmAnd-java/src/com/google/protobuf/CodedOutputStream.java
new file mode 100644
index 0000000000..6e81b981d9
--- /dev/null
+++ b/OsmAnd-java/src/com/google/protobuf/CodedOutputStream.java
@@ -0,0 +1,1040 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+
+/**
+ * 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.
+ *
+ * @author kneton@google.com Kenton Varda
+ */
+public final class CodedOutputStream {
+ private final byte[] buffer;
+ private final int limit;
+ private int position;
+ // + Change
+ private long writtenBytes = 0;
+
+ private final OutputStream output;
+
+ /**
+ * 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;
+ }
+
+ private CodedOutputStream(final byte[] buffer, final int offset,
+ final int length) {
+ output = null;
+ this.buffer = buffer;
+ position = offset;
+ limit = offset + length;
+ }
+
+ private CodedOutputStream(final OutputStream output, final byte[] buffer) {
+ this.output = output;
+ this.buffer = buffer;
+ position = 0;
+ limit = buffer.length;
+ }
+
+ /**
+ * Create a new {@code CodedOutputStream} wrapping the given
+ * {@code OutputStream}.
+ */
+ 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.
+ */
+ public static CodedOutputStream newInstance(final OutputStream output,
+ final int bufferSize) {
+ return new CodedOutputStream(output, new byte[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 CodedOutputStream(flatArray, offset, length);
+ }
+
+ // -----------------------------------------------------------------
+
+ /** Write a {@code double} field, including tag, to the stream. */
+ public void writeDouble(final int fieldNumber, final double value)
+ throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED64);
+ writeDoubleNoTag(value);
+ }
+
+ /** Write a {@code float} field, including tag, to the stream. */
+ public void writeFloat(final int fieldNumber, final float value)
+ throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED32);
+ writeFloatNoTag(value);
+ }
+
+ /** Write a {@code uint64} field, including tag, to the stream. */
+ public void writeUInt64(final int fieldNumber, final long value)
+ throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
+ writeUInt64NoTag(value);
+ }
+
+ /** Write an {@code int64} field, including tag, to the stream. */
+ public void writeInt64(final int fieldNumber, final long value)
+ throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
+ writeInt64NoTag(value);
+ }
+
+ /** Write an {@code int32} field, including tag, to the stream. */
+ public void writeInt32(final int fieldNumber, final int value)
+ throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
+ writeInt32NoTag(value);
+ }
+
+ /** Write a {@code fixed64} field, including tag, to the stream. */
+ public void writeFixed64(final int fieldNumber, final long value)
+ throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED64);
+ writeFixed64NoTag(value);
+ }
+
+ /** Write a {@code fixed32} field, including tag, to the stream. */
+ public void writeFixed32(final int fieldNumber, final int value)
+ throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED32);
+ writeFixed32NoTag(value);
+ }
+
+ /** Write a {@code bool} field, including tag, to the stream. */
+ public void writeBool(final int fieldNumber, final boolean value)
+ throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
+ writeBoolNoTag(value);
+ }
+
+ /** Write a {@code string} field, including tag, to the stream. */
+ public void writeString(final int fieldNumber, final String value)
+ throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED);
+ writeStringNoTag(value);
+ }
+
+ /** Write a {@code group} field, including tag, to the stream. */
+ public 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 group represented by an {@link UnknownFieldSet}.
+ *
+ * @deprecated UnknownFieldSet now implements MessageLite, so you can just
+ * call {@link #writeGroup}.
+ */
+ @Deprecated
+ public void writeUnknownGroup(final int fieldNumber,
+ final MessageLite value)
+ throws IOException {
+ writeGroup(fieldNumber, value);
+ }
+
+ /** Write an embedded message field, including tag, to the stream. */
+ public void writeMessage(final int fieldNumber, final MessageLite value)
+ throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED);
+ writeMessageNoTag(value);
+ }
+
+ /** Write a {@code bytes} field, including tag, to the stream. */
+ public void writeBytes(final int fieldNumber, final ByteString value)
+ throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED);
+ writeBytesNoTag(value);
+ }
+
+ /** Write a {@code uint32} field, including tag, to the stream. */
+ public void writeUInt32(final int fieldNumber, final int value)
+ throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
+ writeUInt32NoTag(value);
+ }
+
+ /**
+ * Write an enum field, including tag, to the stream. Caller is responsible
+ * for converting the enum value to its numeric value.
+ */
+ public void writeEnum(final int fieldNumber, final int value)
+ throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
+ writeEnumNoTag(value);
+ }
+
+ /** Write an {@code sfixed32} field, including tag, to the stream. */
+ public void writeSFixed32(final int fieldNumber, final int value)
+ throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED32);
+ writeSFixed32NoTag(value);
+ }
+
+ /** Write an {@code sfixed64} field, including tag, to the stream. */
+ public void writeSFixed64(final int fieldNumber, final long value)
+ throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED64);
+ writeSFixed64NoTag(value);
+ }
+
+ /** Write an {@code sint32} field, including tag, to the stream. */
+ public void writeSInt32(final int fieldNumber, final int value)
+ throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
+ writeSInt32NoTag(value);
+ }
+
+ /** Write an {@code sint64} field, including tag, to the stream. */
+ public void writeSInt64(final int fieldNumber, final long value)
+ throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
+ writeSInt64NoTag(value);
+ }
+
+ /**
+ * Write a MessageSet extension field to the stream. For historical reasons,
+ * the wire format differs from normal fields.
+ */
+ 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);
+ }
+
+ /**
+ * Write an unparsed MessageSet extension field to the stream. For
+ * historical reasons, the wire format differs from normal fields.
+ */
+ 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);
+ }
+
+ // -----------------------------------------------------------------
+
+ /** Write a {@code double} field to the stream. */
+ public void writeDoubleNoTag(final double value) throws IOException {
+ writeRawLittleEndian64(Double.doubleToRawLongBits(value));
+ }
+
+ /** Write a {@code float} field to the stream. */
+ public void writeFloatNoTag(final float value) throws IOException {
+ writeRawLittleEndian32(Float.floatToRawIntBits(value));
+ }
+
+ /** Write a {@code uint64} field to the stream. */
+ public void writeUInt64NoTag(final long value) throws IOException {
+ writeRawVarint64(value);
+ }
+
+ /** Write an {@code int64} field to the stream. */
+ public void writeInt64NoTag(final long value) throws IOException {
+ writeRawVarint64(value);
+ }
+
+ /** Write an {@code int32} field to the stream. */
+ public void writeInt32NoTag(final int value) throws IOException {
+ if (value >= 0) {
+ writeRawVarint32(value);
+ } else {
+ // Must sign-extend.
+ writeRawVarint64(value);
+ }
+ }
+
+ /** Write a {@code fixed64} field to the stream. */
+ public void writeFixed64NoTag(final long value) throws IOException {
+ writeRawLittleEndian64(value);
+ }
+
+ /** Write a {@code fixed32} field to the stream. */
+ public void writeFixed32NoTag(final int value) throws IOException {
+ writeRawLittleEndian32(value);
+ }
+
+ /** Write a {@code bool} field to the stream. */
+ public void writeBoolNoTag(final boolean value) throws IOException {
+ writeRawByte(value ? 1 : 0);
+ }
+
+ /** Write a {@code string} field to the stream. */
+ public void writeStringNoTag(final String value) throws IOException {
+ // 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.
+ final byte[] bytes = value.getBytes("UTF-8");
+ writeRawVarint32(bytes.length);
+ writeRawBytes(bytes);
+ }
+
+ /** Write a {@code group} field to the stream. */
+ public void writeGroupNoTag(final MessageLite value) throws IOException {
+ value.writeTo(this);
+ }
+
+ /**
+ * Write a group represented by an {@link UnknownFieldSet}.
+ *
+ * @deprecated UnknownFieldSet now implements MessageLite, so you can just
+ * call {@link #writeGroupNoTag}.
+ */
+ @Deprecated
+ public void writeUnknownGroupNoTag(final MessageLite value)
+ throws IOException {
+ writeGroupNoTag(value);
+ }
+
+ /** Write an embedded message field to the stream. */
+ public void writeMessageNoTag(final MessageLite value) throws IOException {
+ writeRawVarint32(value.getSerializedSize());
+ value.writeTo(this);
+ }
+
+ /** Write a {@code bytes} field to the stream. */
+ public void writeBytesNoTag(final ByteString value) throws IOException {
+ final byte[] bytes = value.toByteArray();
+ writeRawVarint32(bytes.length);
+ writeRawBytes(bytes);
+ }
+
+ /** Write a {@code uint32} field to the stream. */
+ public void writeUInt32NoTag(final int value) throws IOException {
+ writeRawVarint32(value);
+ }
+
+ /**
+ * Write an enum field to the stream. Caller is responsible
+ * for converting the enum value to its numeric value.
+ */
+ public void writeEnumNoTag(final int value) throws IOException {
+ writeRawVarint32(value);
+ }
+
+ /** Write an {@code sfixed32} field to the stream. */
+ public void writeSFixed32NoTag(final int value) throws IOException {
+ writeRawLittleEndian32(value);
+ }
+
+ /** Write an {@code sfixed64} field to the stream. */
+ public void writeSFixed64NoTag(final long value) throws IOException {
+ writeRawLittleEndian64(value);
+ }
+
+ /** Write an {@code sint32} field to the stream. */
+ public void writeSInt32NoTag(final int value) throws IOException {
+ writeRawVarint32(encodeZigZag32(value));
+ }
+
+ /** Write an {@code sint64} field to the stream. */
+ public void writeSInt64NoTag(final long value) throws IOException {
+ writeRawVarint64(encodeZigZag64(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 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 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 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 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 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 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 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 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 group} field, including tag.
+ */
+ 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 represented by an {@code UnknownFieldSet}, including
+ * tag.
+ *
+ * @deprecated UnknownFieldSet now implements MessageLite, so you can just
+ * call {@link #computeGroupSize}.
+ */
+ @Deprecated
+ public static int computeUnknownGroupSize(final int fieldNumber,
+ final MessageLite value) {
+ return computeGroupSize(fieldNumber, 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 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 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
+ * enum field, including tag. Caller is responsible for converting the
+ * enum value to its numeric 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 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 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 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 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
+ * 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 a
+ * {@code double} field, including tag.
+ */
+ public static int computeDoubleSizeNoTag(final double value) {
+ return LITTLE_ENDIAN_64_SIZE;
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code float} field, including tag.
+ */
+ public static int computeFloatSizeNoTag(final float value) {
+ return LITTLE_ENDIAN_32_SIZE;
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code uint64} field, including tag.
+ */
+ public static int computeUInt64SizeNoTag(final long value) {
+ return computeRawVarint64Size(value);
+ }
+
+ /**
+ * 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 computeRawVarint64Size(value);
+ }
+
+ /**
+ * 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 computeRawVarint32Size(value);
+ } else {
+ // Must sign-extend.
+ return 10;
+ }
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code fixed64} field.
+ */
+ public static int computeFixed64SizeNoTag(final long value) {
+ return LITTLE_ENDIAN_64_SIZE;
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code fixed32} field.
+ */
+ public static int computeFixed32SizeNoTag(final int value) {
+ return LITTLE_ENDIAN_32_SIZE;
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code bool} field.
+ */
+ public static int computeBoolSizeNoTag(final boolean value) {
+ return 1;
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code string} field.
+ */
+ public static int computeStringSizeNoTag(final String value) {
+ try {
+ final byte[] bytes = value.getBytes("UTF-8");
+ return computeRawVarint32Size(bytes.length) +
+ bytes.length;
+ } catch (UnsupportedEncodingException e) {
+ throw new RuntimeException("UTF-8 not supported.", e);
+ }
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code group} field.
+ */
+ 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 represented by an {@code UnknownFieldSet}, including
+ * tag.
+ *
+ * @deprecated UnknownFieldSet now implements MessageLite, so you can just
+ * call {@link #computeUnknownGroupSizeNoTag}.
+ */
+ @Deprecated
+ public static int computeUnknownGroupSizeNoTag(final MessageLite value) {
+ return computeGroupSizeNoTag(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode an embedded
+ * message field.
+ */
+ public static int computeMessageSizeNoTag(final MessageLite value) {
+ final int size = value.getSerializedSize();
+ return computeRawVarint32Size(size) + size;
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code bytes} field.
+ */
+ public static int computeBytesSizeNoTag(final ByteString value) {
+ return computeRawVarint32Size(value.size()) +
+ value.size();
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code uint32} field.
+ */
+ public static int computeUInt32SizeNoTag(final int value) {
+ return computeRawVarint32Size(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode an enum field.
+ * Caller is responsible for converting the enum value to its numeric value.
+ */
+ public static int computeEnumSizeNoTag(final int value) {
+ return computeRawVarint32Size(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode an
+ * {@code sfixed32} field.
+ */
+ public static int computeSFixed32SizeNoTag(final int value) {
+ return LITTLE_ENDIAN_32_SIZE;
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode an
+ * {@code sfixed64} field.
+ */
+ public static int computeSFixed64SizeNoTag(final long value) {
+ return LITTLE_ENDIAN_64_SIZE;
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode an
+ * {@code sint32} field.
+ */
+ public static int computeSInt32SizeNoTag(final int value) {
+ return computeRawVarint32Size(encodeZigZag32(value));
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode an
+ * {@code sint64} field.
+ */
+ public static int computeSInt64SizeNoTag(final long value) {
+ return computeRawVarint64Size(encodeZigZag64(value));
+ }
+
+ // =================================================================
+
+ /**
+ * Internal helper that writes the current buffer to the output. The
+ * buffer position is reset to its initial value when this returns.
+ */
+ private void refreshBuffer() throws IOException {
+ if (output == null) {
+ // We're writing to a single buffer.
+ throw new OutOfSpaceException();
+ }
+
+ // Since we have an output stream, this is our buffer
+ // and buffer offset == 0
+ output.write(buffer, 0, position);
+ writtenBytes += position;
+ position = 0;
+ }
+
+ /**
+ * Flushes the stream and forces any buffered bytes to be written. This
+ * does not flush the underlying OutputStream.
+ */
+ public void flush() throws IOException {
+ if (output != null) {
+ refreshBuffer();
+ }
+ }
+
+ /**
+ * @return current offset in the output file
+ */
+ public long getWrittenBytes() {
+ return writtenBytes + position;
+ }
+
+ /**
+ * If writing to a flat array, return the space left in the array.
+ * Otherwise, throws {@code UnsupportedOperationException}.
+ */
+ public int spaceLeft() {
+ if (output == null) {
+ return limit - position;
+ } else {
+ throw new UnsupportedOperationException(
+ "spaceLeft() can only be called on CodedOutputStreams that are " +
+ "writing to a flat array.");
+ }
+ }
+
+ /**
+ * 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 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;
+
+ OutOfSpaceException() {
+ super("CodedOutputStream was writing to a flat byte array and ran " +
+ "out of space.");
+ }
+ }
+
+ /** Write a single byte. */
+ public void writeRawByte(final byte value) throws IOException {
+ if (position == limit) {
+ refreshBuffer();
+ }
+
+ buffer[position++] = value;
+ }
+
+ /** Write a single byte, represented by an integer value. */
+ public void writeRawByte(final int value) throws IOException {
+ writeRawByte((byte) value);
+ }
+
+ /** Write an array of bytes. */
+ public void writeRawBytes(final byte[] value) throws IOException {
+ writeRawBytes(value, 0, value.length);
+ }
+
+ /** Write part of an array of bytes. */
+ public void writeRawBytes(final 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;
+ } 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;
+ refreshBuffer();
+
+ // 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.
+ output.write(value, offset, length);
+ writtenBytes += length;
+ }
+ }
+ }
+
+ /** Encode and write a tag. */
+ public void writeTag(final int fieldNumber, final int wireType)
+ throws IOException {
+ writeRawVarint32(WireFormat.makeTag(fieldNumber, wireType));
+ }
+
+ /** Compute the number of bytes that would be needed to encode a tag. */
+ public static int computeTagSize(final int fieldNumber) {
+ return computeRawVarint32Size(WireFormat.makeTag(fieldNumber, 0));
+ }
+
+ /**
+ * Encode and write a varint. {@code value} is treated as
+ * unsigned, so it won't be sign-extended if negative.
+ */
+ public void writeRawVarint32(int value) throws IOException {
+ while (true) {
+ if ((value & ~0x7F) == 0) {
+ writeRawByte(value);
+ return;
+ } else {
+ writeRawByte((value & 0x7F) | 0x80);
+ value >>>= 7;
+ }
+ }
+ }
+
+ /**
+ * 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.
+ */
+ public static int computeRawVarint32Size(final int value) {
+ if ((value & (0xffffffff << 7)) == 0) return 1;
+ if ((value & (0xffffffff << 14)) == 0) return 2;
+ if ((value & (0xffffffff << 21)) == 0) return 3;
+ if ((value & (0xffffffff << 28)) == 0) return 4;
+ return 5;
+ }
+
+ /** Encode and write a varint. */
+ public void writeRawVarint64(long value) throws IOException {
+ while (true) {
+ if ((value & ~0x7FL) == 0) {
+ writeRawByte((int)value);
+ return;
+ } else {
+ writeRawByte(((int)value & 0x7F) | 0x80);
+ value >>>= 7;
+ }
+ }
+ }
+
+ /** Compute the number of bytes that would be needed to encode a varint. */
+ public static int computeRawVarint64Size(final long value) {
+ if ((value & (0xffffffffffffffffL << 7)) == 0) return 1;
+ if ((value & (0xffffffffffffffffL << 14)) == 0) return 2;
+ if ((value & (0xffffffffffffffffL << 21)) == 0) return 3;
+ if ((value & (0xffffffffffffffffL << 28)) == 0) return 4;
+ if ((value & (0xffffffffffffffffL << 35)) == 0) return 5;
+ if ((value & (0xffffffffffffffffL << 42)) == 0) return 6;
+ if ((value & (0xffffffffffffffffL << 49)) == 0) return 7;
+ if ((value & (0xffffffffffffffffL << 56)) == 0) return 8;
+ if ((value & (0xffffffffffffffffL << 63)) == 0) return 9;
+ return 10;
+ }
+
+ /** Write a little-endian 32-bit integer. */
+ public void writeRawLittleEndian32(final int value) throws IOException {
+ writeRawByte((value ) & 0xFF);
+ writeRawByte((value >> 8) & 0xFF);
+ writeRawByte((value >> 16) & 0xFF);
+ writeRawByte((value >> 24) & 0xFF);
+ }
+
+ public static final int LITTLE_ENDIAN_32_SIZE = 4;
+
+ /** Write a little-endian 64-bit integer. */
+ public void writeRawLittleEndian64(final long value) throws IOException {
+ writeRawByte((int)(value ) & 0xFF);
+ writeRawByte((int)(value >> 8) & 0xFF);
+ writeRawByte((int)(value >> 16) & 0xFF);
+ writeRawByte((int)(value >> 24) & 0xFF);
+ writeRawByte((int)(value >> 32) & 0xFF);
+ writeRawByte((int)(value >> 40) & 0xFF);
+ writeRawByte((int)(value >> 48) & 0xFF);
+ writeRawByte((int)(value >> 56) & 0xFF);
+ }
+
+ public static final int LITTLE_ENDIAN_64_SIZE = 8;
+
+ /**
+ * 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);
+ }
+}
diff --git a/OsmAnd-java/src/com/google/protobuf/DescriptorProtos.java b/OsmAnd-java/src/com/google/protobuf/DescriptorProtos.java
new file mode 100644
index 0000000000..fcaea4368a
--- /dev/null
+++ b/OsmAnd-java/src/com/google/protobuf/DescriptorProtos.java
@@ -0,0 +1,9411 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/descriptor.proto
+
+package com.google.protobuf;
+
+public final class DescriptorProtos {
+ private DescriptorProtos() {}
+ public static void registerAllExtensions(
+ com.google.protobuf.ExtensionRegistry registry) {
+ }
+ public static final class FileDescriptorSet extends
+ com.google.protobuf.GeneratedMessage {
+ // Use FileDescriptorSet.newBuilder() to construct.
+ private FileDescriptorSet() {
+ initFields();
+ }
+ private FileDescriptorSet(boolean noInit) {}
+
+ private static final FileDescriptorSet defaultInstance;
+ public static FileDescriptorSet getDefaultInstance() {
+ return defaultInstance;
+ }
+
+ @Override
+ public FileDescriptorSet getDefaultInstanceForType() {
+ return defaultInstance;
+ }
+
+ public static final com.google.protobuf.Descriptors.Descriptor
+ getDescriptor() {
+ return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_FileDescriptorSet_descriptor;
+ }
+
+ @Override
+ protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
+ internalGetFieldAccessorTable() {
+ return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_FileDescriptorSet_fieldAccessorTable;
+ }
+
+ // repeated .google.protobuf.FileDescriptorProto file = 1;
+ public static final int FILE_FIELD_NUMBER = 1;
+ private java.util.List file_ =
+ java.util.Collections.emptyList();
+ public java.util.List getFileList() {
+ return file_;
+ }
+ public int getFileCount() { return file_.size(); }
+ public com.google.protobuf.DescriptorProtos.FileDescriptorProto getFile(int index) {
+ return file_.get(index);
+ }
+
+ private void initFields() {
+ }
+ @Override
+ public final boolean isInitialized() {
+ for (com.google.protobuf.DescriptorProtos.FileDescriptorProto element : getFileList()) {
+ if (!element.isInitialized()) return false;
+ }
+ return true;
+ }
+
+ @Override
+ public void writeTo(com.google.protobuf.CodedOutputStream output)
+ throws java.io.IOException {
+ getSerializedSize();
+ for (com.google.protobuf.DescriptorProtos.FileDescriptorProto element : getFileList()) {
+ output.writeMessage(1, element);
+ }
+ getUnknownFields().writeTo(output);
+ }
+
+ private int memoizedSerializedSize = -1;
+ @Override
+ public int getSerializedSize() {
+ int size = memoizedSerializedSize;
+ if (size != -1) return size;
+
+ size = 0;
+ for (com.google.protobuf.DescriptorProtos.FileDescriptorProto element : getFileList()) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeMessageSize(1, element);
+ }
+ size += getUnknownFields().getSerializedSize();
+ memoizedSerializedSize = size;
+ return size;
+ }
+
+ public static com.google.protobuf.DescriptorProtos.FileDescriptorSet parseFrom(
+ com.google.protobuf.ByteString data)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return newBuilder().mergeFrom(data).buildParsed();
+ }
+ public static com.google.protobuf.DescriptorProtos.FileDescriptorSet parseFrom(
+ com.google.protobuf.ByteString data,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return newBuilder().mergeFrom(data, extensionRegistry)
+ .buildParsed();
+ }
+ public static com.google.protobuf.DescriptorProtos.FileDescriptorSet parseFrom(byte[] data)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return newBuilder().mergeFrom(data).buildParsed();
+ }
+ public static com.google.protobuf.DescriptorProtos.FileDescriptorSet parseFrom(
+ byte[] data,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return newBuilder().mergeFrom(data, extensionRegistry)
+ .buildParsed();
+ }
+ public static com.google.protobuf.DescriptorProtos.FileDescriptorSet parseFrom(java.io.InputStream input)
+ throws java.io.IOException {
+ return newBuilder().mergeFrom(input).buildParsed();
+ }
+ public static com.google.protobuf.DescriptorProtos.FileDescriptorSet parseFrom(
+ java.io.InputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return newBuilder().mergeFrom(input, extensionRegistry)
+ .buildParsed();
+ }
+ public static com.google.protobuf.DescriptorProtos.FileDescriptorSet parseDelimitedFrom(java.io.InputStream input)
+ throws java.io.IOException {
+ Builder builder = newBuilder();
+ if (builder.mergeDelimitedFrom(input)) {
+ return builder.buildParsed();
+ } else {
+ return null;
+ }
+ }
+ public static com.google.protobuf.DescriptorProtos.FileDescriptorSet parseDelimitedFrom(
+ java.io.InputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ Builder builder = newBuilder();
+ if (builder.mergeDelimitedFrom(input, extensionRegistry)) {
+ return builder.buildParsed();
+ } else {
+ return null;
+ }
+ }
+ public static com.google.protobuf.DescriptorProtos.FileDescriptorSet parseFrom(
+ com.google.protobuf.CodedInputStream input)
+ throws java.io.IOException {
+ return newBuilder().mergeFrom(input).buildParsed();
+ }
+ public static com.google.protobuf.DescriptorProtos.FileDescriptorSet parseFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return newBuilder().mergeFrom(input, extensionRegistry)
+ .buildParsed();
+ }
+
+ public static Builder newBuilder() { return Builder.create(); }
+ @Override
+ public Builder newBuilderForType() { return newBuilder(); }
+ public static Builder newBuilder(com.google.protobuf.DescriptorProtos.FileDescriptorSet prototype) {
+ return newBuilder().mergeFrom(prototype);
+ }
+ @Override
+ public Builder toBuilder() { return newBuilder(this); }
+
+ public static final class Builder extends
+ com.google.protobuf.GeneratedMessage.Builder {
+ private com.google.protobuf.DescriptorProtos.FileDescriptorSet result;
+
+ // Construct using com.google.protobuf.DescriptorProtos.FileDescriptorSet.newBuilder()
+ private Builder() {}
+
+ private static Builder create() {
+ Builder builder = new Builder();
+ builder.result = new com.google.protobuf.DescriptorProtos.FileDescriptorSet();
+ return builder;
+ }
+
+ @Override
+ protected com.google.protobuf.DescriptorProtos.FileDescriptorSet internalGetResult() {
+ return result;
+ }
+
+ @Override
+ public Builder clear() {
+ if (result == null) {
+ throw new IllegalStateException(
+ "Cannot call clear() after build().");
+ }
+ result = new com.google.protobuf.DescriptorProtos.FileDescriptorSet();
+ return this;
+ }
+
+ @Override
+ public Builder clone() {
+ return create().mergeFrom(result);
+ }
+
+ @Override
+ public com.google.protobuf.Descriptors.Descriptor
+ getDescriptorForType() {
+ return com.google.protobuf.DescriptorProtos.FileDescriptorSet.getDescriptor();
+ }
+
+ @Override
+ public com.google.protobuf.DescriptorProtos.FileDescriptorSet getDefaultInstanceForType() {
+ return com.google.protobuf.DescriptorProtos.FileDescriptorSet.getDefaultInstance();
+ }
+
+ @Override
+ public boolean isInitialized() {
+ return result.isInitialized();
+ }
+ @Override
+ public com.google.protobuf.DescriptorProtos.FileDescriptorSet build() {
+ if (result != null && !isInitialized()) {
+ throw newUninitializedMessageException(result);
+ }
+ return buildPartial();
+ }
+
+ private com.google.protobuf.DescriptorProtos.FileDescriptorSet buildParsed()
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ if (!isInitialized()) {
+ throw newUninitializedMessageException(
+ result).asInvalidProtocolBufferException();
+ }
+ return buildPartial();
+ }
+
+ @Override
+ public com.google.protobuf.DescriptorProtos.FileDescriptorSet buildPartial() {
+ if (result == null) {
+ throw new IllegalStateException(
+ "build() has already been called on this Builder.");
+ }
+ if (result.file_ != java.util.Collections.EMPTY_LIST) {
+ result.file_ =
+ java.util.Collections.unmodifiableList(result.file_);
+ }
+ com.google.protobuf.DescriptorProtos.FileDescriptorSet returnMe = result;
+ result = null;
+ return returnMe;
+ }
+
+ @Override
+ public Builder mergeFrom(com.google.protobuf.Message other) {
+ if (other instanceof com.google.protobuf.DescriptorProtos.FileDescriptorSet) {
+ return mergeFrom((com.google.protobuf.DescriptorProtos.FileDescriptorSet)other);
+ } else {
+ super.mergeFrom(other);
+ return this;
+ }
+ }
+
+ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.FileDescriptorSet other) {
+ if (other == com.google.protobuf.DescriptorProtos.FileDescriptorSet.getDefaultInstance()) return this;
+ if (!other.file_.isEmpty()) {
+ if (result.file_.isEmpty()) {
+ result.file_ = new java.util.ArrayList();
+ }
+ result.file_.addAll(other.file_);
+ }
+ this.mergeUnknownFields(other.getUnknownFields());
+ return this;
+ }
+
+ @Override
+ public Builder mergeFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ com.google.protobuf.UnknownFieldSet.Builder unknownFields =
+ com.google.protobuf.UnknownFieldSet.newBuilder(
+ this.getUnknownFields());
+ while (true) {
+ int tag = input.readTag();
+ switch (tag) {
+ case 0:
+ this.setUnknownFields(unknownFields.build());
+ return this;
+ default: {
+ if (!parseUnknownField(input, unknownFields,
+ extensionRegistry, tag)) {
+ this.setUnknownFields(unknownFields.build());
+ return this;
+ }
+ break;
+ }
+ case 10: {
+ com.google.protobuf.DescriptorProtos.FileDescriptorProto.Builder subBuilder = com.google.protobuf.DescriptorProtos.FileDescriptorProto.newBuilder();
+ input.readMessage(subBuilder, extensionRegistry);
+ addFile(subBuilder.buildPartial());
+ break;
+ }
+ }
+ }
+ }
+
+
+ // repeated .google.protobuf.FileDescriptorProto file = 1;
+ public java.util.List getFileList() {
+ return java.util.Collections.unmodifiableList(result.file_);
+ }
+ public int getFileCount() {
+ return result.getFileCount();
+ }
+ public com.google.protobuf.DescriptorProtos.FileDescriptorProto getFile(int index) {
+ return result.getFile(index);
+ }
+ public Builder setFile(int index, com.google.protobuf.DescriptorProtos.FileDescriptorProto value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ result.file_.set(index, value);
+ return this;
+ }
+ public Builder setFile(int index, com.google.protobuf.DescriptorProtos.FileDescriptorProto.Builder builderForValue) {
+ result.file_.set(index, builderForValue.build());
+ return this;
+ }
+ public Builder addFile(com.google.protobuf.DescriptorProtos.FileDescriptorProto value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ if (result.file_.isEmpty()) {
+ result.file_ = new java.util.ArrayList();
+ }
+ result.file_.add(value);
+ return this;
+ }
+ public Builder addFile(com.google.protobuf.DescriptorProtos.FileDescriptorProto.Builder builderForValue) {
+ if (result.file_.isEmpty()) {
+ result.file_ = new java.util.ArrayList();
+ }
+ result.file_.add(builderForValue.build());
+ return this;
+ }
+ public Builder addAllFile(
+ java.lang.Iterable extends com.google.protobuf.DescriptorProtos.FileDescriptorProto> values) {
+ if (result.file_.isEmpty()) {
+ result.file_ = new java.util.ArrayList();
+ }
+ super.addAll(values, result.file_);
+ return this;
+ }
+ public Builder clearFile() {
+ result.file_ = java.util.Collections.emptyList();
+ return this;
+ }
+
+ // @@protoc_insertion_point(builder_scope:google.protobuf.FileDescriptorSet)
+ }
+
+ static {
+ defaultInstance = new FileDescriptorSet(true);
+ com.google.protobuf.DescriptorProtos.internalForceInit();
+ defaultInstance.initFields();
+ }
+
+ // @@protoc_insertion_point(class_scope:google.protobuf.FileDescriptorSet)
+ }
+
+ public static final class FileDescriptorProto extends
+ com.google.protobuf.GeneratedMessage {
+ // Use FileDescriptorProto.newBuilder() to construct.
+ private FileDescriptorProto() {
+ initFields();
+ }
+ private FileDescriptorProto(boolean noInit) {}
+
+ private static final FileDescriptorProto defaultInstance;
+ public static FileDescriptorProto getDefaultInstance() {
+ return defaultInstance;
+ }
+
+ @Override
+ public FileDescriptorProto getDefaultInstanceForType() {
+ return defaultInstance;
+ }
+
+ public static final com.google.protobuf.Descriptors.Descriptor
+ getDescriptor() {
+ return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_FileDescriptorProto_descriptor;
+ }
+
+ @Override
+ protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
+ internalGetFieldAccessorTable() {
+ return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_FileDescriptorProto_fieldAccessorTable;
+ }
+
+ // optional string name = 1;
+ public static final int NAME_FIELD_NUMBER = 1;
+ private boolean hasName;
+ private java.lang.String name_ = "";
+ public boolean hasName() { return hasName; }
+ public java.lang.String getName() { return name_; }
+
+ // optional string package = 2;
+ public static final int PACKAGE_FIELD_NUMBER = 2;
+ private boolean hasPackage;
+ private java.lang.String package_ = "";
+ public boolean hasPackage() { return hasPackage; }
+ public java.lang.String getPackage() { return package_; }
+
+ // repeated string dependency = 3;
+ public static final int DEPENDENCY_FIELD_NUMBER = 3;
+ private java.util.List dependency_ =
+ java.util.Collections.emptyList();
+ public java.util.List getDependencyList() {
+ return dependency_;
+ }
+ public int getDependencyCount() { return dependency_.size(); }
+ public java.lang.String getDependency(int index) {
+ return dependency_.get(index);
+ }
+
+ // repeated .google.protobuf.DescriptorProto message_type = 4;
+ public static final int MESSAGE_TYPE_FIELD_NUMBER = 4;
+ private java.util.List messageType_ =
+ java.util.Collections.emptyList();
+ public java.util.List getMessageTypeList() {
+ return messageType_;
+ }
+ public int getMessageTypeCount() { return messageType_.size(); }
+ public com.google.protobuf.DescriptorProtos.DescriptorProto getMessageType(int index) {
+ return messageType_.get(index);
+ }
+
+ // repeated .google.protobuf.EnumDescriptorProto enum_type = 5;
+ public static final int ENUM_TYPE_FIELD_NUMBER = 5;
+ private java.util.List enumType_ =
+ java.util.Collections.emptyList();
+ public java.util.List getEnumTypeList() {
+ return enumType_;
+ }
+ public int getEnumTypeCount() { return enumType_.size(); }
+ public com.google.protobuf.DescriptorProtos.EnumDescriptorProto getEnumType(int index) {
+ return enumType_.get(index);
+ }
+
+ // repeated .google.protobuf.ServiceDescriptorProto service = 6;
+ public static final int SERVICE_FIELD_NUMBER = 6;
+ private java.util.List service_ =
+ java.util.Collections.emptyList();
+ public java.util.List getServiceList() {
+ return service_;
+ }
+ public int getServiceCount() { return service_.size(); }
+ public com.google.protobuf.DescriptorProtos.ServiceDescriptorProto getService(int index) {
+ return service_.get(index);
+ }
+
+ // repeated .google.protobuf.FieldDescriptorProto extension = 7;
+ public static final int EXTENSION_FIELD_NUMBER = 7;
+ private java.util.List extension_ =
+ java.util.Collections.emptyList();
+ public java.util.List getExtensionList() {
+ return extension_;
+ }
+ public int getExtensionCount() { return extension_.size(); }
+ public com.google.protobuf.DescriptorProtos.FieldDescriptorProto getExtension(int index) {
+ return extension_.get(index);
+ }
+
+ // optional .google.protobuf.FileOptions options = 8;
+ public static final int OPTIONS_FIELD_NUMBER = 8;
+ private boolean hasOptions;
+ private com.google.protobuf.DescriptorProtos.FileOptions options_;
+ public boolean hasOptions() { return hasOptions; }
+ public com.google.protobuf.DescriptorProtos.FileOptions getOptions() { return options_; }
+
+ private void initFields() {
+ options_ = com.google.protobuf.DescriptorProtos.FileOptions.getDefaultInstance();
+ }
+ @Override
+ public final boolean isInitialized() {
+ for (com.google.protobuf.DescriptorProtos.DescriptorProto element : getMessageTypeList()) {
+ if (!element.isInitialized()) return false;
+ }
+ for (com.google.protobuf.DescriptorProtos.EnumDescriptorProto element : getEnumTypeList()) {
+ if (!element.isInitialized()) return false;
+ }
+ for (com.google.protobuf.DescriptorProtos.ServiceDescriptorProto element : getServiceList()) {
+ if (!element.isInitialized()) return false;
+ }
+ for (com.google.protobuf.DescriptorProtos.FieldDescriptorProto element : getExtensionList()) {
+ if (!element.isInitialized()) return false;
+ }
+ if (hasOptions()) {
+ if (!getOptions().isInitialized()) return false;
+ }
+ return true;
+ }
+
+ @Override
+ public void writeTo(com.google.protobuf.CodedOutputStream output)
+ throws java.io.IOException {
+ getSerializedSize();
+ if (hasName()) {
+ output.writeString(1, getName());
+ }
+ if (hasPackage()) {
+ output.writeString(2, getPackage());
+ }
+ for (java.lang.String element : getDependencyList()) {
+ output.writeString(3, element);
+ }
+ for (com.google.protobuf.DescriptorProtos.DescriptorProto element : getMessageTypeList()) {
+ output.writeMessage(4, element);
+ }
+ for (com.google.protobuf.DescriptorProtos.EnumDescriptorProto element : getEnumTypeList()) {
+ output.writeMessage(5, element);
+ }
+ for (com.google.protobuf.DescriptorProtos.ServiceDescriptorProto element : getServiceList()) {
+ output.writeMessage(6, element);
+ }
+ for (com.google.protobuf.DescriptorProtos.FieldDescriptorProto element : getExtensionList()) {
+ output.writeMessage(7, element);
+ }
+ if (hasOptions()) {
+ output.writeMessage(8, getOptions());
+ }
+ getUnknownFields().writeTo(output);
+ }
+
+ private int memoizedSerializedSize = -1;
+ @Override
+ public int getSerializedSize() {
+ int size = memoizedSerializedSize;
+ if (size != -1) return size;
+
+ size = 0;
+ if (hasName()) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeStringSize(1, getName());
+ }
+ if (hasPackage()) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeStringSize(2, getPackage());
+ }
+ {
+ int dataSize = 0;
+ for (java.lang.String element : getDependencyList()) {
+ dataSize += com.google.protobuf.CodedOutputStream
+ .computeStringSizeNoTag(element);
+ }
+ size += dataSize;
+ size += 1 * getDependencyList().size();
+ }
+ for (com.google.protobuf.DescriptorProtos.DescriptorProto element : getMessageTypeList()) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeMessageSize(4, element);
+ }
+ for (com.google.protobuf.DescriptorProtos.EnumDescriptorProto element : getEnumTypeList()) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeMessageSize(5, element);
+ }
+ for (com.google.protobuf.DescriptorProtos.ServiceDescriptorProto element : getServiceList()) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeMessageSize(6, element);
+ }
+ for (com.google.protobuf.DescriptorProtos.FieldDescriptorProto element : getExtensionList()) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeMessageSize(7, element);
+ }
+ if (hasOptions()) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeMessageSize(8, getOptions());
+ }
+ size += getUnknownFields().getSerializedSize();
+ memoizedSerializedSize = size;
+ return size;
+ }
+
+ public static com.google.protobuf.DescriptorProtos.FileDescriptorProto parseFrom(
+ com.google.protobuf.ByteString data)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return newBuilder().mergeFrom(data).buildParsed();
+ }
+ public static com.google.protobuf.DescriptorProtos.FileDescriptorProto parseFrom(
+ com.google.protobuf.ByteString data,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return newBuilder().mergeFrom(data, extensionRegistry)
+ .buildParsed();
+ }
+ public static com.google.protobuf.DescriptorProtos.FileDescriptorProto parseFrom(byte[] data)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return newBuilder().mergeFrom(data).buildParsed();
+ }
+ public static com.google.protobuf.DescriptorProtos.FileDescriptorProto parseFrom(
+ byte[] data,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return newBuilder().mergeFrom(data, extensionRegistry)
+ .buildParsed();
+ }
+ public static com.google.protobuf.DescriptorProtos.FileDescriptorProto parseFrom(java.io.InputStream input)
+ throws java.io.IOException {
+ return newBuilder().mergeFrom(input).buildParsed();
+ }
+ public static com.google.protobuf.DescriptorProtos.FileDescriptorProto parseFrom(
+ java.io.InputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return newBuilder().mergeFrom(input, extensionRegistry)
+ .buildParsed();
+ }
+ public static com.google.protobuf.DescriptorProtos.FileDescriptorProto parseDelimitedFrom(java.io.InputStream input)
+ throws java.io.IOException {
+ Builder builder = newBuilder();
+ if (builder.mergeDelimitedFrom(input)) {
+ return builder.buildParsed();
+ } else {
+ return null;
+ }
+ }
+ public static com.google.protobuf.DescriptorProtos.FileDescriptorProto parseDelimitedFrom(
+ java.io.InputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ Builder builder = newBuilder();
+ if (builder.mergeDelimitedFrom(input, extensionRegistry)) {
+ return builder.buildParsed();
+ } else {
+ return null;
+ }
+ }
+ public static com.google.protobuf.DescriptorProtos.FileDescriptorProto parseFrom(
+ com.google.protobuf.CodedInputStream input)
+ throws java.io.IOException {
+ return newBuilder().mergeFrom(input).buildParsed();
+ }
+ public static com.google.protobuf.DescriptorProtos.FileDescriptorProto parseFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return newBuilder().mergeFrom(input, extensionRegistry)
+ .buildParsed();
+ }
+
+ public static Builder newBuilder() { return Builder.create(); }
+ @Override
+ public Builder newBuilderForType() { return newBuilder(); }
+ public static Builder newBuilder(com.google.protobuf.DescriptorProtos.FileDescriptorProto prototype) {
+ return newBuilder().mergeFrom(prototype);
+ }
+ @Override
+ public Builder toBuilder() { return newBuilder(this); }
+
+ public static final class Builder extends
+ com.google.protobuf.GeneratedMessage.Builder {
+ private com.google.protobuf.DescriptorProtos.FileDescriptorProto result;
+
+ // Construct using com.google.protobuf.DescriptorProtos.FileDescriptorProto.newBuilder()
+ private Builder() {}
+
+ private static Builder create() {
+ Builder builder = new Builder();
+ builder.result = new com.google.protobuf.DescriptorProtos.FileDescriptorProto();
+ return builder;
+ }
+
+ @Override
+ protected com.google.protobuf.DescriptorProtos.FileDescriptorProto internalGetResult() {
+ return result;
+ }
+
+ @Override
+ public Builder clear() {
+ if (result == null) {
+ throw new IllegalStateException(
+ "Cannot call clear() after build().");
+ }
+ result = new com.google.protobuf.DescriptorProtos.FileDescriptorProto();
+ return this;
+ }
+
+ @Override
+ public Builder clone() {
+ return create().mergeFrom(result);
+ }
+
+ @Override
+ public com.google.protobuf.Descriptors.Descriptor
+ getDescriptorForType() {
+ return com.google.protobuf.DescriptorProtos.FileDescriptorProto.getDescriptor();
+ }
+
+ @Override
+ public com.google.protobuf.DescriptorProtos.FileDescriptorProto getDefaultInstanceForType() {
+ return com.google.protobuf.DescriptorProtos.FileDescriptorProto.getDefaultInstance();
+ }
+
+ @Override
+ public boolean isInitialized() {
+ return result.isInitialized();
+ }
+ @Override
+ public com.google.protobuf.DescriptorProtos.FileDescriptorProto build() {
+ if (result != null && !isInitialized()) {
+ throw newUninitializedMessageException(result);
+ }
+ return buildPartial();
+ }
+
+ private com.google.protobuf.DescriptorProtos.FileDescriptorProto buildParsed()
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ if (!isInitialized()) {
+ throw newUninitializedMessageException(
+ result).asInvalidProtocolBufferException();
+ }
+ return buildPartial();
+ }
+
+ @Override
+ public com.google.protobuf.DescriptorProtos.FileDescriptorProto buildPartial() {
+ if (result == null) {
+ throw new IllegalStateException(
+ "build() has already been called on this Builder.");
+ }
+ if (result.dependency_ != java.util.Collections.EMPTY_LIST) {
+ result.dependency_ =
+ java.util.Collections.unmodifiableList(result.dependency_);
+ }
+ if (result.messageType_ != java.util.Collections.EMPTY_LIST) {
+ result.messageType_ =
+ java.util.Collections.unmodifiableList(result.messageType_);
+ }
+ if (result.enumType_ != java.util.Collections.EMPTY_LIST) {
+ result.enumType_ =
+ java.util.Collections.unmodifiableList(result.enumType_);
+ }
+ if (result.service_ != java.util.Collections.EMPTY_LIST) {
+ result.service_ =
+ java.util.Collections.unmodifiableList(result.service_);
+ }
+ if (result.extension_ != java.util.Collections.EMPTY_LIST) {
+ result.extension_ =
+ java.util.Collections.unmodifiableList(result.extension_);
+ }
+ com.google.protobuf.DescriptorProtos.FileDescriptorProto returnMe = result;
+ result = null;
+ return returnMe;
+ }
+
+ @Override
+ public Builder mergeFrom(com.google.protobuf.Message other) {
+ if (other instanceof com.google.protobuf.DescriptorProtos.FileDescriptorProto) {
+ return mergeFrom((com.google.protobuf.DescriptorProtos.FileDescriptorProto)other);
+ } else {
+ super.mergeFrom(other);
+ return this;
+ }
+ }
+
+ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.FileDescriptorProto other) {
+ if (other == com.google.protobuf.DescriptorProtos.FileDescriptorProto.getDefaultInstance()) return this;
+ if (other.hasName()) {
+ setName(other.getName());
+ }
+ if (other.hasPackage()) {
+ setPackage(other.getPackage());
+ }
+ if (!other.dependency_.isEmpty()) {
+ if (result.dependency_.isEmpty()) {
+ result.dependency_ = new java.util.ArrayList();
+ }
+ result.dependency_.addAll(other.dependency_);
+ }
+ if (!other.messageType_.isEmpty()) {
+ if (result.messageType_.isEmpty()) {
+ result.messageType_ = new java.util.ArrayList();
+ }
+ result.messageType_.addAll(other.messageType_);
+ }
+ if (!other.enumType_.isEmpty()) {
+ if (result.enumType_.isEmpty()) {
+ result.enumType_ = new java.util.ArrayList();
+ }
+ result.enumType_.addAll(other.enumType_);
+ }
+ if (!other.service_.isEmpty()) {
+ if (result.service_.isEmpty()) {
+ result.service_ = new java.util.ArrayList();
+ }
+ result.service_.addAll(other.service_);
+ }
+ if (!other.extension_.isEmpty()) {
+ if (result.extension_.isEmpty()) {
+ result.extension_ = new java.util.ArrayList();
+ }
+ result.extension_.addAll(other.extension_);
+ }
+ if (other.hasOptions()) {
+ mergeOptions(other.getOptions());
+ }
+ this.mergeUnknownFields(other.getUnknownFields());
+ return this;
+ }
+
+ @Override
+ public Builder mergeFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ com.google.protobuf.UnknownFieldSet.Builder unknownFields =
+ com.google.protobuf.UnknownFieldSet.newBuilder(
+ this.getUnknownFields());
+ while (true) {
+ int tag = input.readTag();
+ switch (tag) {
+ case 0:
+ this.setUnknownFields(unknownFields.build());
+ return this;
+ default: {
+ if (!parseUnknownField(input, unknownFields,
+ extensionRegistry, tag)) {
+ this.setUnknownFields(unknownFields.build());
+ return this;
+ }
+ break;
+ }
+ case 10: {
+ setName(input.readString());
+ break;
+ }
+ case 18: {
+ setPackage(input.readString());
+ break;
+ }
+ case 26: {
+ addDependency(input.readString());
+ break;
+ }
+ case 34: {
+ com.google.protobuf.DescriptorProtos.DescriptorProto.Builder subBuilder = com.google.protobuf.DescriptorProtos.DescriptorProto.newBuilder();
+ input.readMessage(subBuilder, extensionRegistry);
+ addMessageType(subBuilder.buildPartial());
+ break;
+ }
+ case 42: {
+ com.google.protobuf.DescriptorProtos.EnumDescriptorProto.Builder subBuilder = com.google.protobuf.DescriptorProtos.EnumDescriptorProto.newBuilder();
+ input.readMessage(subBuilder, extensionRegistry);
+ addEnumType(subBuilder.buildPartial());
+ break;
+ }
+ case 50: {
+ com.google.protobuf.DescriptorProtos.ServiceDescriptorProto.Builder subBuilder = com.google.protobuf.DescriptorProtos.ServiceDescriptorProto.newBuilder();
+ input.readMessage(subBuilder, extensionRegistry);
+ addService(subBuilder.buildPartial());
+ break;
+ }
+ case 58: {
+ com.google.protobuf.DescriptorProtos.FieldDescriptorProto.Builder subBuilder = com.google.protobuf.DescriptorProtos.FieldDescriptorProto.newBuilder();
+ input.readMessage(subBuilder, extensionRegistry);
+ addExtension(subBuilder.buildPartial());
+ break;
+ }
+ case 66: {
+ com.google.protobuf.DescriptorProtos.FileOptions.Builder subBuilder = com.google.protobuf.DescriptorProtos.FileOptions.newBuilder();
+ if (hasOptions()) {
+ subBuilder.mergeFrom(getOptions());
+ }
+ input.readMessage(subBuilder, extensionRegistry);
+ setOptions(subBuilder.buildPartial());
+ break;
+ }
+ }
+ }
+ }
+
+
+ // optional string name = 1;
+ public boolean hasName() {
+ return result.hasName();
+ }
+ public java.lang.String getName() {
+ return result.getName();
+ }
+ public Builder setName(java.lang.String value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ result.hasName = true;
+ result.name_ = value;
+ return this;
+ }
+ public Builder clearName() {
+ result.hasName = false;
+ result.name_ = getDefaultInstance().getName();
+ return this;
+ }
+
+ // optional string package = 2;
+ public boolean hasPackage() {
+ return result.hasPackage();
+ }
+ public java.lang.String getPackage() {
+ return result.getPackage();
+ }
+ public Builder setPackage(java.lang.String value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ result.hasPackage = true;
+ result.package_ = value;
+ return this;
+ }
+ public Builder clearPackage() {
+ result.hasPackage = false;
+ result.package_ = getDefaultInstance().getPackage();
+ return this;
+ }
+
+ // repeated string dependency = 3;
+ public java.util.List getDependencyList() {
+ return java.util.Collections.unmodifiableList(result.dependency_);
+ }
+ public int getDependencyCount() {
+ return result.getDependencyCount();
+ }
+ public java.lang.String getDependency(int index) {
+ return result.getDependency(index);
+ }
+ public Builder setDependency(int index, java.lang.String value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ result.dependency_.set(index, value);
+ return this;
+ }
+ public Builder addDependency(java.lang.String value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ if (result.dependency_.isEmpty()) {
+ result.dependency_ = new java.util.ArrayList();
+ }
+ result.dependency_.add(value);
+ return this;
+ }
+ public Builder addAllDependency(
+ java.lang.Iterable extends java.lang.String> values) {
+ if (result.dependency_.isEmpty()) {
+ result.dependency_ = new java.util.ArrayList();
+ }
+ super.addAll(values, result.dependency_);
+ return this;
+ }
+ public Builder clearDependency() {
+ result.dependency_ = java.util.Collections.emptyList();
+ return this;
+ }
+
+ // repeated .google.protobuf.DescriptorProto message_type = 4;
+ public java.util.List getMessageTypeList() {
+ return java.util.Collections.unmodifiableList(result.messageType_);
+ }
+ public int getMessageTypeCount() {
+ return result.getMessageTypeCount();
+ }
+ public com.google.protobuf.DescriptorProtos.DescriptorProto getMessageType(int index) {
+ return result.getMessageType(index);
+ }
+ public Builder setMessageType(int index, com.google.protobuf.DescriptorProtos.DescriptorProto value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ result.messageType_.set(index, value);
+ return this;
+ }
+ public Builder setMessageType(int index, com.google.protobuf.DescriptorProtos.DescriptorProto.Builder builderForValue) {
+ result.messageType_.set(index, builderForValue.build());
+ return this;
+ }
+ public Builder addMessageType(com.google.protobuf.DescriptorProtos.DescriptorProto value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ if (result.messageType_.isEmpty()) {
+ result.messageType_ = new java.util.ArrayList();
+ }
+ result.messageType_.add(value);
+ return this;
+ }
+ public Builder addMessageType(com.google.protobuf.DescriptorProtos.DescriptorProto.Builder builderForValue) {
+ if (result.messageType_.isEmpty()) {
+ result.messageType_ = new java.util.ArrayList();
+ }
+ result.messageType_.add(builderForValue.build());
+ return this;
+ }
+ public Builder addAllMessageType(
+ java.lang.Iterable extends com.google.protobuf.DescriptorProtos.DescriptorProto> values) {
+ if (result.messageType_.isEmpty()) {
+ result.messageType_ = new java.util.ArrayList();
+ }
+ super.addAll(values, result.messageType_);
+ return this;
+ }
+ public Builder clearMessageType() {
+ result.messageType_ = java.util.Collections.emptyList();
+ return this;
+ }
+
+ // repeated .google.protobuf.EnumDescriptorProto enum_type = 5;
+ public java.util.List getEnumTypeList() {
+ return java.util.Collections.unmodifiableList(result.enumType_);
+ }
+ public int getEnumTypeCount() {
+ return result.getEnumTypeCount();
+ }
+ public com.google.protobuf.DescriptorProtos.EnumDescriptorProto getEnumType(int index) {
+ return result.getEnumType(index);
+ }
+ public Builder setEnumType(int index, com.google.protobuf.DescriptorProtos.EnumDescriptorProto value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ result.enumType_.set(index, value);
+ return this;
+ }
+ public Builder setEnumType(int index, com.google.protobuf.DescriptorProtos.EnumDescriptorProto.Builder builderForValue) {
+ result.enumType_.set(index, builderForValue.build());
+ return this;
+ }
+ public Builder addEnumType(com.google.protobuf.DescriptorProtos.EnumDescriptorProto value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ if (result.enumType_.isEmpty()) {
+ result.enumType_ = new java.util.ArrayList();
+ }
+ result.enumType_.add(value);
+ return this;
+ }
+ public Builder addEnumType(com.google.protobuf.DescriptorProtos.EnumDescriptorProto.Builder builderForValue) {
+ if (result.enumType_.isEmpty()) {
+ result.enumType_ = new java.util.ArrayList();
+ }
+ result.enumType_.add(builderForValue.build());
+ return this;
+ }
+ public Builder addAllEnumType(
+ java.lang.Iterable extends com.google.protobuf.DescriptorProtos.EnumDescriptorProto> values) {
+ if (result.enumType_.isEmpty()) {
+ result.enumType_ = new java.util.ArrayList();
+ }
+ super.addAll(values, result.enumType_);
+ return this;
+ }
+ public Builder clearEnumType() {
+ result.enumType_ = java.util.Collections.emptyList();
+ return this;
+ }
+
+ // repeated .google.protobuf.ServiceDescriptorProto service = 6;
+ public java.util.List getServiceList() {
+ return java.util.Collections.unmodifiableList(result.service_);
+ }
+ public int getServiceCount() {
+ return result.getServiceCount();
+ }
+ public com.google.protobuf.DescriptorProtos.ServiceDescriptorProto getService(int index) {
+ return result.getService(index);
+ }
+ public Builder setService(int index, com.google.protobuf.DescriptorProtos.ServiceDescriptorProto value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ result.service_.set(index, value);
+ return this;
+ }
+ public Builder setService(int index, com.google.protobuf.DescriptorProtos.ServiceDescriptorProto.Builder builderForValue) {
+ result.service_.set(index, builderForValue.build());
+ return this;
+ }
+ public Builder addService(com.google.protobuf.DescriptorProtos.ServiceDescriptorProto value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ if (result.service_.isEmpty()) {
+ result.service_ = new java.util.ArrayList();
+ }
+ result.service_.add(value);
+ return this;
+ }
+ public Builder addService(com.google.protobuf.DescriptorProtos.ServiceDescriptorProto.Builder builderForValue) {
+ if (result.service_.isEmpty()) {
+ result.service_ = new java.util.ArrayList();
+ }
+ result.service_.add(builderForValue.build());
+ return this;
+ }
+ public Builder addAllService(
+ java.lang.Iterable extends com.google.protobuf.DescriptorProtos.ServiceDescriptorProto> values) {
+ if (result.service_.isEmpty()) {
+ result.service_ = new java.util.ArrayList();
+ }
+ super.addAll(values, result.service_);
+ return this;
+ }
+ public Builder clearService() {
+ result.service_ = java.util.Collections.emptyList();
+ return this;
+ }
+
+ // repeated .google.protobuf.FieldDescriptorProto extension = 7;
+ public java.util.List getExtensionList() {
+ return java.util.Collections.unmodifiableList(result.extension_);
+ }
+ public int getExtensionCount() {
+ return result.getExtensionCount();
+ }
+ public com.google.protobuf.DescriptorProtos.FieldDescriptorProto getExtension(int index) {
+ return result.getExtension(index);
+ }
+ public Builder setExtension(int index, com.google.protobuf.DescriptorProtos.FieldDescriptorProto value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ result.extension_.set(index, value);
+ return this;
+ }
+ public Builder setExtension(int index, com.google.protobuf.DescriptorProtos.FieldDescriptorProto.Builder builderForValue) {
+ result.extension_.set(index, builderForValue.build());
+ return this;
+ }
+ public Builder addExtension(com.google.protobuf.DescriptorProtos.FieldDescriptorProto value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ if (result.extension_.isEmpty()) {
+ result.extension_ = new java.util.ArrayList();
+ }
+ result.extension_.add(value);
+ return this;
+ }
+ public Builder addExtension(com.google.protobuf.DescriptorProtos.FieldDescriptorProto.Builder builderForValue) {
+ if (result.extension_.isEmpty()) {
+ result.extension_ = new java.util.ArrayList();
+ }
+ result.extension_.add(builderForValue.build());
+ return this;
+ }
+ public Builder addAllExtension(
+ java.lang.Iterable extends com.google.protobuf.DescriptorProtos.FieldDescriptorProto> values) {
+ if (result.extension_.isEmpty()) {
+ result.extension_ = new java.util.ArrayList();
+ }
+ super.addAll(values, result.extension_);
+ return this;
+ }
+ public Builder clearExtension() {
+ result.extension_ = java.util.Collections.emptyList();
+ return this;
+ }
+
+ // optional .google.protobuf.FileOptions options = 8;
+ public boolean hasOptions() {
+ return result.hasOptions();
+ }
+ public com.google.protobuf.DescriptorProtos.FileOptions getOptions() {
+ return result.getOptions();
+ }
+ public Builder setOptions(com.google.protobuf.DescriptorProtos.FileOptions value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ result.hasOptions = true;
+ result.options_ = value;
+ return this;
+ }
+ public Builder setOptions(com.google.protobuf.DescriptorProtos.FileOptions.Builder builderForValue) {
+ result.hasOptions = true;
+ result.options_ = builderForValue.build();
+ return this;
+ }
+ public Builder mergeOptions(com.google.protobuf.DescriptorProtos.FileOptions value) {
+ if (result.hasOptions() &&
+ result.options_ != com.google.protobuf.DescriptorProtos.FileOptions.getDefaultInstance()) {
+ result.options_ =
+ com.google.protobuf.DescriptorProtos.FileOptions.newBuilder(result.options_).mergeFrom(value).buildPartial();
+ } else {
+ result.options_ = value;
+ }
+ result.hasOptions = true;
+ return this;
+ }
+ public Builder clearOptions() {
+ result.hasOptions = false;
+ result.options_ = com.google.protobuf.DescriptorProtos.FileOptions.getDefaultInstance();
+ return this;
+ }
+
+ // @@protoc_insertion_point(builder_scope:google.protobuf.FileDescriptorProto)
+ }
+
+ static {
+ defaultInstance = new FileDescriptorProto(true);
+ com.google.protobuf.DescriptorProtos.internalForceInit();
+ defaultInstance.initFields();
+ }
+
+ // @@protoc_insertion_point(class_scope:google.protobuf.FileDescriptorProto)
+ }
+
+ public static final class DescriptorProto extends
+ com.google.protobuf.GeneratedMessage {
+ // Use DescriptorProto.newBuilder() to construct.
+ private DescriptorProto() {
+ initFields();
+ }
+ private DescriptorProto(boolean noInit) {}
+
+ private static final DescriptorProto defaultInstance;
+ public static DescriptorProto getDefaultInstance() {
+ return defaultInstance;
+ }
+
+ @Override
+ public DescriptorProto getDefaultInstanceForType() {
+ return defaultInstance;
+ }
+
+ public static final com.google.protobuf.Descriptors.Descriptor
+ getDescriptor() {
+ return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_DescriptorProto_descriptor;
+ }
+
+ @Override
+ protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
+ internalGetFieldAccessorTable() {
+ return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_DescriptorProto_fieldAccessorTable;
+ }
+
+ public static final class ExtensionRange extends
+ com.google.protobuf.GeneratedMessage {
+ // Use ExtensionRange.newBuilder() to construct.
+ private ExtensionRange() {
+ initFields();
+ }
+ private ExtensionRange(boolean noInit) {}
+
+ private static final ExtensionRange defaultInstance;
+ public static ExtensionRange getDefaultInstance() {
+ return defaultInstance;
+ }
+
+ @Override
+ public ExtensionRange getDefaultInstanceForType() {
+ return defaultInstance;
+ }
+
+ public static final com.google.protobuf.Descriptors.Descriptor
+ getDescriptor() {
+ return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_DescriptorProto_ExtensionRange_descriptor;
+ }
+
+ @Override
+ protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
+ internalGetFieldAccessorTable() {
+ return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_DescriptorProto_ExtensionRange_fieldAccessorTable;
+ }
+
+ // optional int32 start = 1;
+ public static final int START_FIELD_NUMBER = 1;
+ private boolean hasStart;
+ private int start_ = 0;
+ public boolean hasStart() { return hasStart; }
+ public int getStart() { return start_; }
+
+ // optional int32 end = 2;
+ public static final int END_FIELD_NUMBER = 2;
+ private boolean hasEnd;
+ private int end_ = 0;
+ public boolean hasEnd() { return hasEnd; }
+ public int getEnd() { return end_; }
+
+ private void initFields() {
+ }
+ @Override
+ public final boolean isInitialized() {
+ return true;
+ }
+
+ @Override
+ public void writeTo(com.google.protobuf.CodedOutputStream output)
+ throws java.io.IOException {
+ getSerializedSize();
+ if (hasStart()) {
+ output.writeInt32(1, getStart());
+ }
+ if (hasEnd()) {
+ output.writeInt32(2, getEnd());
+ }
+ getUnknownFields().writeTo(output);
+ }
+
+ private int memoizedSerializedSize = -1;
+ @Override
+ public int getSerializedSize() {
+ int size = memoizedSerializedSize;
+ if (size != -1) return size;
+
+ size = 0;
+ if (hasStart()) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeInt32Size(1, getStart());
+ }
+ if (hasEnd()) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeInt32Size(2, getEnd());
+ }
+ size += getUnknownFields().getSerializedSize();
+ memoizedSerializedSize = size;
+ return size;
+ }
+
+ public static com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange parseFrom(
+ com.google.protobuf.ByteString data)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return newBuilder().mergeFrom(data).buildParsed();
+ }
+ public static com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange parseFrom(
+ com.google.protobuf.ByteString data,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return newBuilder().mergeFrom(data, extensionRegistry)
+ .buildParsed();
+ }
+ public static com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange parseFrom(byte[] data)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return newBuilder().mergeFrom(data).buildParsed();
+ }
+ public static com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange parseFrom(
+ byte[] data,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return newBuilder().mergeFrom(data, extensionRegistry)
+ .buildParsed();
+ }
+ public static com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange parseFrom(java.io.InputStream input)
+ throws java.io.IOException {
+ return newBuilder().mergeFrom(input).buildParsed();
+ }
+ public static com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange parseFrom(
+ java.io.InputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return newBuilder().mergeFrom(input, extensionRegistry)
+ .buildParsed();
+ }
+ public static com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange parseDelimitedFrom(java.io.InputStream input)
+ throws java.io.IOException {
+ Builder builder = newBuilder();
+ if (builder.mergeDelimitedFrom(input)) {
+ return builder.buildParsed();
+ } else {
+ return null;
+ }
+ }
+ public static com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange parseDelimitedFrom(
+ java.io.InputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ Builder builder = newBuilder();
+ if (builder.mergeDelimitedFrom(input, extensionRegistry)) {
+ return builder.buildParsed();
+ } else {
+ return null;
+ }
+ }
+ public static com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange parseFrom(
+ com.google.protobuf.CodedInputStream input)
+ throws java.io.IOException {
+ return newBuilder().mergeFrom(input).buildParsed();
+ }
+ public static com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange parseFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return newBuilder().mergeFrom(input, extensionRegistry)
+ .buildParsed();
+ }
+
+ public static Builder newBuilder() { return Builder.create(); }
+ @Override
+ public Builder newBuilderForType() { return newBuilder(); }
+ public static Builder newBuilder(com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange prototype) {
+ return newBuilder().mergeFrom(prototype);
+ }
+ @Override
+ public Builder toBuilder() { return newBuilder(this); }
+
+ public static final class Builder extends
+ com.google.protobuf.GeneratedMessage.Builder {
+ private com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange result;
+
+ // Construct using com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange.newBuilder()
+ private Builder() {}
+
+ private static Builder create() {
+ Builder builder = new Builder();
+ builder.result = new com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange();
+ return builder;
+ }
+
+ @Override
+ protected com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange internalGetResult() {
+ return result;
+ }
+
+ @Override
+ public Builder clear() {
+ if (result == null) {
+ throw new IllegalStateException(
+ "Cannot call clear() after build().");
+ }
+ result = new com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange();
+ return this;
+ }
+
+ @Override
+ public Builder clone() {
+ return create().mergeFrom(result);
+ }
+
+ @Override
+ public com.google.protobuf.Descriptors.Descriptor
+ getDescriptorForType() {
+ return com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange.getDescriptor();
+ }
+
+ @Override
+ public com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange getDefaultInstanceForType() {
+ return com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange.getDefaultInstance();
+ }
+
+ @Override
+ public boolean isInitialized() {
+ return result.isInitialized();
+ }
+ @Override
+ public com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange build() {
+ if (result != null && !isInitialized()) {
+ throw newUninitializedMessageException(result);
+ }
+ return buildPartial();
+ }
+
+ private com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange buildParsed()
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ if (!isInitialized()) {
+ throw newUninitializedMessageException(
+ result).asInvalidProtocolBufferException();
+ }
+ return buildPartial();
+ }
+
+ @Override
+ public com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange buildPartial() {
+ if (result == null) {
+ throw new IllegalStateException(
+ "build() has already been called on this Builder.");
+ }
+ com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange returnMe = result;
+ result = null;
+ return returnMe;
+ }
+
+ @Override
+ public Builder mergeFrom(com.google.protobuf.Message other) {
+ if (other instanceof com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange) {
+ return mergeFrom((com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange)other);
+ } else {
+ super.mergeFrom(other);
+ return this;
+ }
+ }
+
+ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange other) {
+ if (other == com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange.getDefaultInstance()) return this;
+ if (other.hasStart()) {
+ setStart(other.getStart());
+ }
+ if (other.hasEnd()) {
+ setEnd(other.getEnd());
+ }
+ this.mergeUnknownFields(other.getUnknownFields());
+ return this;
+ }
+
+ @Override
+ public Builder mergeFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ com.google.protobuf.UnknownFieldSet.Builder unknownFields =
+ com.google.protobuf.UnknownFieldSet.newBuilder(
+ this.getUnknownFields());
+ while (true) {
+ int tag = input.readTag();
+ switch (tag) {
+ case 0:
+ this.setUnknownFields(unknownFields.build());
+ return this;
+ default: {
+ if (!parseUnknownField(input, unknownFields,
+ extensionRegistry, tag)) {
+ this.setUnknownFields(unknownFields.build());
+ return this;
+ }
+ break;
+ }
+ case 8: {
+ setStart(input.readInt32());
+ break;
+ }
+ case 16: {
+ setEnd(input.readInt32());
+ break;
+ }
+ }
+ }
+ }
+
+
+ // optional int32 start = 1;
+ public boolean hasStart() {
+ return result.hasStart();
+ }
+ public int getStart() {
+ return result.getStart();
+ }
+ public Builder setStart(int value) {
+ result.hasStart = true;
+ result.start_ = value;
+ return this;
+ }
+ public Builder clearStart() {
+ result.hasStart = false;
+ result.start_ = 0;
+ return this;
+ }
+
+ // optional int32 end = 2;
+ public boolean hasEnd() {
+ return result.hasEnd();
+ }
+ public int getEnd() {
+ return result.getEnd();
+ }
+ public Builder setEnd(int value) {
+ result.hasEnd = true;
+ result.end_ = value;
+ return this;
+ }
+ public Builder clearEnd() {
+ result.hasEnd = false;
+ result.end_ = 0;
+ return this;
+ }
+
+ // @@protoc_insertion_point(builder_scope:google.protobuf.DescriptorProto.ExtensionRange)
+ }
+
+ static {
+ defaultInstance = new ExtensionRange(true);
+ com.google.protobuf.DescriptorProtos.internalForceInit();
+ defaultInstance.initFields();
+ }
+
+ // @@protoc_insertion_point(class_scope:google.protobuf.DescriptorProto.ExtensionRange)
+ }
+
+ // optional string name = 1;
+ public static final int NAME_FIELD_NUMBER = 1;
+ private boolean hasName;
+ private java.lang.String name_ = "";
+ public boolean hasName() { return hasName; }
+ public java.lang.String getName() { return name_; }
+
+ // repeated .google.protobuf.FieldDescriptorProto field = 2;
+ public static final int FIELD_FIELD_NUMBER = 2;
+ private java.util.List field_ =
+ java.util.Collections.emptyList();
+ public java.util.List getFieldList() {
+ return field_;
+ }
+ public int getFieldCount() { return field_.size(); }
+ public com.google.protobuf.DescriptorProtos.FieldDescriptorProto getField(int index) {
+ return field_.get(index);
+ }
+
+ // repeated .google.protobuf.FieldDescriptorProto extension = 6;
+ public static final int EXTENSION_FIELD_NUMBER = 6;
+ private java.util.List extension_ =
+ java.util.Collections.emptyList();
+ public java.util.List getExtensionList() {
+ return extension_;
+ }
+ public int getExtensionCount() { return extension_.size(); }
+ public com.google.protobuf.DescriptorProtos.FieldDescriptorProto getExtension(int index) {
+ return extension_.get(index);
+ }
+
+ // repeated .google.protobuf.DescriptorProto nested_type = 3;
+ public static final int NESTED_TYPE_FIELD_NUMBER = 3;
+ private java.util.List nestedType_ =
+ java.util.Collections.emptyList();
+ public java.util.List getNestedTypeList() {
+ return nestedType_;
+ }
+ public int getNestedTypeCount() { return nestedType_.size(); }
+ public com.google.protobuf.DescriptorProtos.DescriptorProto getNestedType(int index) {
+ return nestedType_.get(index);
+ }
+
+ // repeated .google.protobuf.EnumDescriptorProto enum_type = 4;
+ public static final int ENUM_TYPE_FIELD_NUMBER = 4;
+ private java.util.List enumType_ =
+ java.util.Collections.emptyList();
+ public java.util.List getEnumTypeList() {
+ return enumType_;
+ }
+ public int getEnumTypeCount() { return enumType_.size(); }
+ public com.google.protobuf.DescriptorProtos.EnumDescriptorProto getEnumType(int index) {
+ return enumType_.get(index);
+ }
+
+ // repeated .google.protobuf.DescriptorProto.ExtensionRange extension_range = 5;
+ public static final int EXTENSION_RANGE_FIELD_NUMBER = 5;
+ private java.util.List extensionRange_ =
+ java.util.Collections.emptyList();
+ public java.util.List getExtensionRangeList() {
+ return extensionRange_;
+ }
+ public int getExtensionRangeCount() { return extensionRange_.size(); }
+ public com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange getExtensionRange(int index) {
+ return extensionRange_.get(index);
+ }
+
+ // optional .google.protobuf.MessageOptions options = 7;
+ public static final int OPTIONS_FIELD_NUMBER = 7;
+ private boolean hasOptions;
+ private com.google.protobuf.DescriptorProtos.MessageOptions options_;
+ public boolean hasOptions() { return hasOptions; }
+ public com.google.protobuf.DescriptorProtos.MessageOptions getOptions() { return options_; }
+
+ private void initFields() {
+ options_ = com.google.protobuf.DescriptorProtos.MessageOptions.getDefaultInstance();
+ }
+ @Override
+ public final boolean isInitialized() {
+ for (com.google.protobuf.DescriptorProtos.FieldDescriptorProto element : getFieldList()) {
+ if (!element.isInitialized()) return false;
+ }
+ for (com.google.protobuf.DescriptorProtos.FieldDescriptorProto element : getExtensionList()) {
+ if (!element.isInitialized()) return false;
+ }
+ for (com.google.protobuf.DescriptorProtos.DescriptorProto element : getNestedTypeList()) {
+ if (!element.isInitialized()) return false;
+ }
+ for (com.google.protobuf.DescriptorProtos.EnumDescriptorProto element : getEnumTypeList()) {
+ if (!element.isInitialized()) return false;
+ }
+ if (hasOptions()) {
+ if (!getOptions().isInitialized()) return false;
+ }
+ return true;
+ }
+
+ @Override
+ public void writeTo(com.google.protobuf.CodedOutputStream output)
+ throws java.io.IOException {
+ getSerializedSize();
+ if (hasName()) {
+ output.writeString(1, getName());
+ }
+ for (com.google.protobuf.DescriptorProtos.FieldDescriptorProto element : getFieldList()) {
+ output.writeMessage(2, element);
+ }
+ for (com.google.protobuf.DescriptorProtos.DescriptorProto element : getNestedTypeList()) {
+ output.writeMessage(3, element);
+ }
+ for (com.google.protobuf.DescriptorProtos.EnumDescriptorProto element : getEnumTypeList()) {
+ output.writeMessage(4, element);
+ }
+ for (com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange element : getExtensionRangeList()) {
+ output.writeMessage(5, element);
+ }
+ for (com.google.protobuf.DescriptorProtos.FieldDescriptorProto element : getExtensionList()) {
+ output.writeMessage(6, element);
+ }
+ if (hasOptions()) {
+ output.writeMessage(7, getOptions());
+ }
+ getUnknownFields().writeTo(output);
+ }
+
+ private int memoizedSerializedSize = -1;
+ @Override
+ public int getSerializedSize() {
+ int size = memoizedSerializedSize;
+ if (size != -1) return size;
+
+ size = 0;
+ if (hasName()) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeStringSize(1, getName());
+ }
+ for (com.google.protobuf.DescriptorProtos.FieldDescriptorProto element : getFieldList()) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeMessageSize(2, element);
+ }
+ for (com.google.protobuf.DescriptorProtos.DescriptorProto element : getNestedTypeList()) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeMessageSize(3, element);
+ }
+ for (com.google.protobuf.DescriptorProtos.EnumDescriptorProto element : getEnumTypeList()) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeMessageSize(4, element);
+ }
+ for (com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange element : getExtensionRangeList()) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeMessageSize(5, element);
+ }
+ for (com.google.protobuf.DescriptorProtos.FieldDescriptorProto element : getExtensionList()) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeMessageSize(6, element);
+ }
+ if (hasOptions()) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeMessageSize(7, getOptions());
+ }
+ size += getUnknownFields().getSerializedSize();
+ memoizedSerializedSize = size;
+ return size;
+ }
+
+ public static com.google.protobuf.DescriptorProtos.DescriptorProto parseFrom(
+ com.google.protobuf.ByteString data)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return newBuilder().mergeFrom(data).buildParsed();
+ }
+ public static com.google.protobuf.DescriptorProtos.DescriptorProto parseFrom(
+ com.google.protobuf.ByteString data,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return newBuilder().mergeFrom(data, extensionRegistry)
+ .buildParsed();
+ }
+ public static com.google.protobuf.DescriptorProtos.DescriptorProto parseFrom(byte[] data)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return newBuilder().mergeFrom(data).buildParsed();
+ }
+ public static com.google.protobuf.DescriptorProtos.DescriptorProto parseFrom(
+ byte[] data,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return newBuilder().mergeFrom(data, extensionRegistry)
+ .buildParsed();
+ }
+ public static com.google.protobuf.DescriptorProtos.DescriptorProto parseFrom(java.io.InputStream input)
+ throws java.io.IOException {
+ return newBuilder().mergeFrom(input).buildParsed();
+ }
+ public static com.google.protobuf.DescriptorProtos.DescriptorProto parseFrom(
+ java.io.InputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return newBuilder().mergeFrom(input, extensionRegistry)
+ .buildParsed();
+ }
+ public static com.google.protobuf.DescriptorProtos.DescriptorProto parseDelimitedFrom(java.io.InputStream input)
+ throws java.io.IOException {
+ Builder builder = newBuilder();
+ if (builder.mergeDelimitedFrom(input)) {
+ return builder.buildParsed();
+ } else {
+ return null;
+ }
+ }
+ public static com.google.protobuf.DescriptorProtos.DescriptorProto parseDelimitedFrom(
+ java.io.InputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ Builder builder = newBuilder();
+ if (builder.mergeDelimitedFrom(input, extensionRegistry)) {
+ return builder.buildParsed();
+ } else {
+ return null;
+ }
+ }
+ public static com.google.protobuf.DescriptorProtos.DescriptorProto parseFrom(
+ com.google.protobuf.CodedInputStream input)
+ throws java.io.IOException {
+ return newBuilder().mergeFrom(input).buildParsed();
+ }
+ public static com.google.protobuf.DescriptorProtos.DescriptorProto parseFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return newBuilder().mergeFrom(input, extensionRegistry)
+ .buildParsed();
+ }
+
+ public static Builder newBuilder() { return Builder.create(); }
+ @Override
+ public Builder newBuilderForType() { return newBuilder(); }
+ public static Builder newBuilder(com.google.protobuf.DescriptorProtos.DescriptorProto prototype) {
+ return newBuilder().mergeFrom(prototype);
+ }
+ @Override
+ public Builder toBuilder() { return newBuilder(this); }
+
+ public static final class Builder extends
+ com.google.protobuf.GeneratedMessage.Builder {
+ private com.google.protobuf.DescriptorProtos.DescriptorProto result;
+
+ // Construct using com.google.protobuf.DescriptorProtos.DescriptorProto.newBuilder()
+ private Builder() {}
+
+ private static Builder create() {
+ Builder builder = new Builder();
+ builder.result = new com.google.protobuf.DescriptorProtos.DescriptorProto();
+ return builder;
+ }
+
+ @Override
+ protected com.google.protobuf.DescriptorProtos.DescriptorProto internalGetResult() {
+ return result;
+ }
+
+ @Override
+ public Builder clear() {
+ if (result == null) {
+ throw new IllegalStateException(
+ "Cannot call clear() after build().");
+ }
+ result = new com.google.protobuf.DescriptorProtos.DescriptorProto();
+ return this;
+ }
+
+ @Override
+ public Builder clone() {
+ return create().mergeFrom(result);
+ }
+
+ @Override
+ public com.google.protobuf.Descriptors.Descriptor
+ getDescriptorForType() {
+ return com.google.protobuf.DescriptorProtos.DescriptorProto.getDescriptor();
+ }
+
+ @Override
+ public com.google.protobuf.DescriptorProtos.DescriptorProto getDefaultInstanceForType() {
+ return com.google.protobuf.DescriptorProtos.DescriptorProto.getDefaultInstance();
+ }
+
+ @Override
+ public boolean isInitialized() {
+ return result.isInitialized();
+ }
+ @Override
+ public com.google.protobuf.DescriptorProtos.DescriptorProto build() {
+ if (result != null && !isInitialized()) {
+ throw newUninitializedMessageException(result);
+ }
+ return buildPartial();
+ }
+
+ private com.google.protobuf.DescriptorProtos.DescriptorProto buildParsed()
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ if (!isInitialized()) {
+ throw newUninitializedMessageException(
+ result).asInvalidProtocolBufferException();
+ }
+ return buildPartial();
+ }
+
+ @Override
+ public com.google.protobuf.DescriptorProtos.DescriptorProto buildPartial() {
+ if (result == null) {
+ throw new IllegalStateException(
+ "build() has already been called on this Builder.");
+ }
+ if (result.field_ != java.util.Collections.EMPTY_LIST) {
+ result.field_ =
+ java.util.Collections.unmodifiableList(result.field_);
+ }
+ if (result.extension_ != java.util.Collections.EMPTY_LIST) {
+ result.extension_ =
+ java.util.Collections.unmodifiableList(result.extension_);
+ }
+ if (result.nestedType_ != java.util.Collections.EMPTY_LIST) {
+ result.nestedType_ =
+ java.util.Collections.unmodifiableList(result.nestedType_);
+ }
+ if (result.enumType_ != java.util.Collections.EMPTY_LIST) {
+ result.enumType_ =
+ java.util.Collections.unmodifiableList(result.enumType_);
+ }
+ if (result.extensionRange_ != java.util.Collections.EMPTY_LIST) {
+ result.extensionRange_ =
+ java.util.Collections.unmodifiableList(result.extensionRange_);
+ }
+ com.google.protobuf.DescriptorProtos.DescriptorProto returnMe = result;
+ result = null;
+ return returnMe;
+ }
+
+ @Override
+ public Builder mergeFrom(com.google.protobuf.Message other) {
+ if (other instanceof com.google.protobuf.DescriptorProtos.DescriptorProto) {
+ return mergeFrom((com.google.protobuf.DescriptorProtos.DescriptorProto)other);
+ } else {
+ super.mergeFrom(other);
+ return this;
+ }
+ }
+
+ public Builder mergeFrom(com.google.protobuf.DescriptorProtos.DescriptorProto other) {
+ if (other == com.google.protobuf.DescriptorProtos.DescriptorProto.getDefaultInstance()) return this;
+ if (other.hasName()) {
+ setName(other.getName());
+ }
+ if (!other.field_.isEmpty()) {
+ if (result.field_.isEmpty()) {
+ result.field_ = new java.util.ArrayList();
+ }
+ result.field_.addAll(other.field_);
+ }
+ if (!other.extension_.isEmpty()) {
+ if (result.extension_.isEmpty()) {
+ result.extension_ = new java.util.ArrayList();
+ }
+ result.extension_.addAll(other.extension_);
+ }
+ if (!other.nestedType_.isEmpty()) {
+ if (result.nestedType_.isEmpty()) {
+ result.nestedType_ = new java.util.ArrayList();
+ }
+ result.nestedType_.addAll(other.nestedType_);
+ }
+ if (!other.enumType_.isEmpty()) {
+ if (result.enumType_.isEmpty()) {
+ result.enumType_ = new java.util.ArrayList();
+ }
+ result.enumType_.addAll(other.enumType_);
+ }
+ if (!other.extensionRange_.isEmpty()) {
+ if (result.extensionRange_.isEmpty()) {
+ result.extensionRange_ = new java.util.ArrayList();
+ }
+ result.extensionRange_.addAll(other.extensionRange_);
+ }
+ if (other.hasOptions()) {
+ mergeOptions(other.getOptions());
+ }
+ this.mergeUnknownFields(other.getUnknownFields());
+ return this;
+ }
+
+ @Override
+ public Builder mergeFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ com.google.protobuf.UnknownFieldSet.Builder unknownFields =
+ com.google.protobuf.UnknownFieldSet.newBuilder(
+ this.getUnknownFields());
+ while (true) {
+ int tag = input.readTag();
+ switch (tag) {
+ case 0:
+ this.setUnknownFields(unknownFields.build());
+ return this;
+ default: {
+ if (!parseUnknownField(input, unknownFields,
+ extensionRegistry, tag)) {
+ this.setUnknownFields(unknownFields.build());
+ return this;
+ }
+ break;
+ }
+ case 10: {
+ setName(input.readString());
+ break;
+ }
+ case 18: {
+ com.google.protobuf.DescriptorProtos.FieldDescriptorProto.Builder subBuilder = com.google.protobuf.DescriptorProtos.FieldDescriptorProto.newBuilder();
+ input.readMessage(subBuilder, extensionRegistry);
+ addField(subBuilder.buildPartial());
+ break;
+ }
+ case 26: {
+ com.google.protobuf.DescriptorProtos.DescriptorProto.Builder subBuilder = com.google.protobuf.DescriptorProtos.DescriptorProto.newBuilder();
+ input.readMessage(subBuilder, extensionRegistry);
+ addNestedType(subBuilder.buildPartial());
+ break;
+ }
+ case 34: {
+ com.google.protobuf.DescriptorProtos.EnumDescriptorProto.Builder subBuilder = com.google.protobuf.DescriptorProtos.EnumDescriptorProto.newBuilder();
+ input.readMessage(subBuilder, extensionRegistry);
+ addEnumType(subBuilder.buildPartial());
+ break;
+ }
+ case 42: {
+ com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange.Builder subBuilder = com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange.newBuilder();
+ input.readMessage(subBuilder, extensionRegistry);
+ addExtensionRange(subBuilder.buildPartial());
+ break;
+ }
+ case 50: {
+ com.google.protobuf.DescriptorProtos.FieldDescriptorProto.Builder subBuilder = com.google.protobuf.DescriptorProtos.FieldDescriptorProto.newBuilder();
+ input.readMessage(subBuilder, extensionRegistry);
+ addExtension(subBuilder.buildPartial());
+ break;
+ }
+ case 58: {
+ com.google.protobuf.DescriptorProtos.MessageOptions.Builder subBuilder = com.google.protobuf.DescriptorProtos.MessageOptions.newBuilder();
+ if (hasOptions()) {
+ subBuilder.mergeFrom(getOptions());
+ }
+ input.readMessage(subBuilder, extensionRegistry);
+ setOptions(subBuilder.buildPartial());
+ break;
+ }
+ }
+ }
+ }
+
+
+ // optional string name = 1;
+ public boolean hasName() {
+ return result.hasName();
+ }
+ public java.lang.String getName() {
+ return result.getName();
+ }
+ public Builder setName(java.lang.String value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ result.hasName = true;
+ result.name_ = value;
+ return this;
+ }
+ public Builder clearName() {
+ result.hasName = false;
+ result.name_ = getDefaultInstance().getName();
+ return this;
+ }
+
+ // repeated .google.protobuf.FieldDescriptorProto field = 2;
+ public java.util.List getFieldList() {
+ return java.util.Collections.unmodifiableList(result.field_);
+ }
+ public int getFieldCount() {
+ return result.getFieldCount();
+ }
+ public com.google.protobuf.DescriptorProtos.FieldDescriptorProto getField(int index) {
+ return result.getField(index);
+ }
+ public Builder setField(int index, com.google.protobuf.DescriptorProtos.FieldDescriptorProto value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ result.field_.set(index, value);
+ return this;
+ }
+ public Builder setField(int index, com.google.protobuf.DescriptorProtos.FieldDescriptorProto.Builder builderForValue) {
+ result.field_.set(index, builderForValue.build());
+ return this;
+ }
+ public Builder addField(com.google.protobuf.DescriptorProtos.FieldDescriptorProto value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ if (result.field_.isEmpty()) {
+ result.field_ = new java.util.ArrayList();
+ }
+ result.field_.add(value);
+ return this;
+ }
+ public Builder addField(com.google.protobuf.DescriptorProtos.FieldDescriptorProto.Builder builderForValue) {
+ if (result.field_.isEmpty()) {
+ result.field_ = new java.util.ArrayList();
+ }
+ result.field_.add(builderForValue.build());
+ return this;
+ }
+ public Builder addAllField(
+ java.lang.Iterable extends com.google.protobuf.DescriptorProtos.FieldDescriptorProto> values) {
+ if (result.field_.isEmpty()) {
+ result.field_ = new java.util.ArrayList();
+ }
+ super.addAll(values, result.field_);
+ return this;
+ }
+ public Builder clearField() {
+ result.field_ = java.util.Collections.emptyList();
+ return this;
+ }
+
+ // repeated .google.protobuf.FieldDescriptorProto extension = 6;
+ public java.util.List getExtensionList() {
+ return java.util.Collections.unmodifiableList(result.extension_);
+ }
+ public int getExtensionCount() {
+ return result.getExtensionCount();
+ }
+ public com.google.protobuf.DescriptorProtos.FieldDescriptorProto getExtension(int index) {
+ return result.getExtension(index);
+ }
+ public Builder setExtension(int index, com.google.protobuf.DescriptorProtos.FieldDescriptorProto value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ result.extension_.set(index, value);
+ return this;
+ }
+ public Builder setExtension(int index, com.google.protobuf.DescriptorProtos.FieldDescriptorProto.Builder builderForValue) {
+ result.extension_.set(index, builderForValue.build());
+ return this;
+ }
+ public Builder addExtension(com.google.protobuf.DescriptorProtos.FieldDescriptorProto value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ if (result.extension_.isEmpty()) {
+ result.extension_ = new java.util.ArrayList();
+ }
+ result.extension_.add(value);
+ return this;
+ }
+ public Builder addExtension(com.google.protobuf.DescriptorProtos.FieldDescriptorProto.Builder builderForValue) {
+ if (result.extension_.isEmpty()) {
+ result.extension_ = new java.util.ArrayList();
+ }
+ result.extension_.add(builderForValue.build());
+ return this;
+ }
+ public Builder addAllExtension(
+ java.lang.Iterable extends com.google.protobuf.DescriptorProtos.FieldDescriptorProto> values) {
+ if (result.extension_.isEmpty()) {
+ result.extension_ = new java.util.ArrayList();
+ }
+ super.addAll(values, result.extension_);
+ return this;
+ }
+ public Builder clearExtension() {
+ result.extension_ = java.util.Collections.emptyList();
+ return this;
+ }
+
+ // repeated .google.protobuf.DescriptorProto nested_type = 3;
+ public java.util.List getNestedTypeList() {
+ return java.util.Collections.unmodifiableList(result.nestedType_);
+ }
+ public int getNestedTypeCount() {
+ return result.getNestedTypeCount();
+ }
+ public com.google.protobuf.DescriptorProtos.DescriptorProto getNestedType(int index) {
+ return result.getNestedType(index);
+ }
+ public Builder setNestedType(int index, com.google.protobuf.DescriptorProtos.DescriptorProto value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ result.nestedType_.set(index, value);
+ return this;
+ }
+ public Builder setNestedType(int index, com.google.protobuf.DescriptorProtos.DescriptorProto.Builder builderForValue) {
+ result.nestedType_.set(index, builderForValue.build());
+ return this;
+ }
+ public Builder addNestedType(com.google.protobuf.DescriptorProtos.DescriptorProto value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ if (result.nestedType_.isEmpty()) {
+ result.nestedType_ = new java.util.ArrayList();
+ }
+ result.nestedType_.add(value);
+ return this;
+ }
+ public Builder addNestedType(com.google.protobuf.DescriptorProtos.DescriptorProto.Builder builderForValue) {
+ if (result.nestedType_.isEmpty()) {
+ result.nestedType_ = new java.util.ArrayList();
+ }
+ result.nestedType_.add(builderForValue.build());
+ return this;
+ }
+ public Builder addAllNestedType(
+ java.lang.Iterable extends com.google.protobuf.DescriptorProtos.DescriptorProto> values) {
+ if (result.nestedType_.isEmpty()) {
+ result.nestedType_ = new java.util.ArrayList();
+ }
+ super.addAll(values, result.nestedType_);
+ return this;
+ }
+ public Builder clearNestedType() {
+ result.nestedType_ = java.util.Collections.emptyList();
+ return this;
+ }
+
+ // repeated .google.protobuf.EnumDescriptorProto enum_type = 4;
+ public java.util.List getEnumTypeList() {
+ return java.util.Collections.unmodifiableList(result.enumType_);
+ }
+ public int getEnumTypeCount() {
+ return result.getEnumTypeCount();
+ }
+ public com.google.protobuf.DescriptorProtos.EnumDescriptorProto getEnumType(int index) {
+ return result.getEnumType(index);
+ }
+ public Builder setEnumType(int index, com.google.protobuf.DescriptorProtos.EnumDescriptorProto value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ result.enumType_.set(index, value);
+ return this;
+ }
+ public Builder setEnumType(int index, com.google.protobuf.DescriptorProtos.EnumDescriptorProto.Builder builderForValue) {
+ result.enumType_.set(index, builderForValue.build());
+ return this;
+ }
+ public Builder addEnumType(com.google.protobuf.DescriptorProtos.EnumDescriptorProto value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ if (result.enumType_.isEmpty()) {
+ result.enumType_ = new java.util.ArrayList();
+ }
+ result.enumType_.add(value);
+ return this;
+ }
+ public Builder addEnumType(com.google.protobuf.DescriptorProtos.EnumDescriptorProto.Builder builderForValue) {
+ if (result.enumType_.isEmpty()) {
+ result.enumType_ = new java.util.ArrayList();
+ }
+ result.enumType_.add(builderForValue.build());
+ return this;
+ }
+ public Builder addAllEnumType(
+ java.lang.Iterable extends com.google.protobuf.DescriptorProtos.EnumDescriptorProto> values) {
+ if (result.enumType_.isEmpty()) {
+ result.enumType_ = new java.util.ArrayList();
+ }
+ super.addAll(values, result.enumType_);
+ return this;
+ }
+ public Builder clearEnumType() {
+ result.enumType_ = java.util.Collections.emptyList();
+ return this;
+ }
+
+ // repeated .google.protobuf.DescriptorProto.ExtensionRange extension_range = 5;
+ public java.util.List getExtensionRangeList() {
+ return java.util.Collections.unmodifiableList(result.extensionRange_);
+ }
+ public int getExtensionRangeCount() {
+ return result.getExtensionRangeCount();
+ }
+ public com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange getExtensionRange(int index) {
+ return result.getExtensionRange(index);
+ }
+ public Builder setExtensionRange(int index, com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ result.extensionRange_.set(index, value);
+ return this;
+ }
+ public Builder setExtensionRange(int index, com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange.Builder builderForValue) {
+ result.extensionRange_.set(index, builderForValue.build());
+ return this;
+ }
+ public Builder addExtensionRange(com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ if (result.extensionRange_.isEmpty()) {
+ result.extensionRange_ = new java.util.ArrayList();
+ }
+ result.extensionRange_.add(value);
+ return this;
+ }
+ public Builder addExtensionRange(com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange.Builder builderForValue) {
+ if (result.extensionRange_.isEmpty()) {
+ result.extensionRange_ = new java.util.ArrayList();
+ }
+ result.extensionRange_.add(builderForValue.build());
+ return this;
+ }
+ public Builder addAllExtensionRange(
+ java.lang.Iterable extends com.google.protobuf.DescriptorProtos.DescriptorProto.ExtensionRange> values) {
+ if (result.extensionRange_.isEmpty()) {
+ result.extensionRange_ = new java.util.ArrayList();
+ }
+ super.addAll(values, result.extensionRange_);
+ return this;
+ }
+ public Builder clearExtensionRange() {
+ result.extensionRange_ = java.util.Collections.emptyList();
+ return this;
+ }
+
+ // optional .google.protobuf.MessageOptions options = 7;
+ public boolean hasOptions() {
+ return result.hasOptions();
+ }
+ public com.google.protobuf.DescriptorProtos.MessageOptions getOptions() {
+ return result.getOptions();
+ }
+ public Builder setOptions(com.google.protobuf.DescriptorProtos.MessageOptions value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ result.hasOptions = true;
+ result.options_ = value;
+ return this;
+ }
+ public Builder setOptions(com.google.protobuf.DescriptorProtos.MessageOptions.Builder builderForValue) {
+ result.hasOptions = true;
+ result.options_ = builderForValue.build();
+ return this;
+ }
+ public Builder mergeOptions(com.google.protobuf.DescriptorProtos.MessageOptions value) {
+ if (result.hasOptions() &&
+ result.options_ != com.google.protobuf.DescriptorProtos.MessageOptions.getDefaultInstance()) {
+ result.options_ =
+ com.google.protobuf.DescriptorProtos.MessageOptions.newBuilder(result.options_).mergeFrom(value).buildPartial();
+ } else {
+ result.options_ = value;
+ }
+ result.hasOptions = true;
+ return this;
+ }
+ public Builder clearOptions() {
+ result.hasOptions = false;
+ result.options_ = com.google.protobuf.DescriptorProtos.MessageOptions.getDefaultInstance();
+ return this;
+ }
+
+ // @@protoc_insertion_point(builder_scope:google.protobuf.DescriptorProto)
+ }
+
+ static {
+ defaultInstance = new DescriptorProto(true);
+ com.google.protobuf.DescriptorProtos.internalForceInit();
+ defaultInstance.initFields();
+ }
+
+ // @@protoc_insertion_point(class_scope:google.protobuf.DescriptorProto)
+ }
+
+ public static final class FieldDescriptorProto extends
+ com.google.protobuf.GeneratedMessage {
+ // Use FieldDescriptorProto.newBuilder() to construct.
+ private FieldDescriptorProto() {
+ initFields();
+ }
+ private FieldDescriptorProto(boolean noInit) {}
+
+ private static final FieldDescriptorProto defaultInstance;
+ public static FieldDescriptorProto getDefaultInstance() {
+ return defaultInstance;
+ }
+
+ @Override
+ public FieldDescriptorProto getDefaultInstanceForType() {
+ return defaultInstance;
+ }
+
+ public static final com.google.protobuf.Descriptors.Descriptor
+ getDescriptor() {
+ return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_FieldDescriptorProto_descriptor;
+ }
+
+ @Override
+ protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
+ internalGetFieldAccessorTable() {
+ return com.google.protobuf.DescriptorProtos.internal_static_google_protobuf_FieldDescriptorProto_fieldAccessorTable;
+ }
+
+ public enum Type
+ implements com.google.protobuf.ProtocolMessageEnum {
+ TYPE_DOUBLE(0, 1),
+ TYPE_FLOAT(1, 2),
+ TYPE_INT64(2, 3),
+ TYPE_UINT64(3, 4),
+ TYPE_INT32(4, 5),
+ TYPE_FIXED64(5, 6),
+ TYPE_FIXED32(6, 7),
+ TYPE_BOOL(7, 8),
+ TYPE_STRING(8, 9),
+ TYPE_GROUP(9, 10),
+ TYPE_MESSAGE(10, 11),
+ TYPE_BYTES(11, 12),
+ TYPE_UINT32(12, 13),
+ TYPE_ENUM(13, 14),
+ TYPE_SFIXED32(14, 15),
+ TYPE_SFIXED64(15, 16),
+ TYPE_SINT32(16, 17),
+ TYPE_SINT64(17, 18),
+ ;
+
+
+ @Override
+ public final int getNumber() { return value; }
+
+ public static Type valueOf(int value) {
+ switch (value) {
+ 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 com.google.protobuf.Internal.EnumLiteMap
+ internalValueMap =
+ new com.google.protobuf.Internal.EnumLiteMap() {
+ @Override
+ public Type findValueByNumber(int number) {
+ return Type.valueOf(number)
+ ; }
+ };
+
+ @Override
+ public final com.google.protobuf.Descriptors.EnumValueDescriptor
+ getValueDescriptor() {
+ return getDescriptor().getValues().get(index);
+ }
+ @Override
+ public final com.google.protobuf.Descriptors.EnumDescriptor
+ getDescriptorForType() {
+ return getDescriptor();
+ }
+ public static final com.google.protobuf.Descriptors.EnumDescriptor
+ getDescriptor() {
+ return com.google.protobuf.DescriptorProtos.FieldDescriptorProto.getDescriptor().getEnumTypes().get(0);
+ }
+
+ private static final Type[] VALUES = {
+ TYPE_DOUBLE, TYPE_FLOAT, TYPE_INT64, TYPE_UINT64, TYPE_INT32, TYPE_FIXED64, TYPE_FIXED32, TYPE_BOOL, TYPE_STRING, TYPE_GROUP, TYPE_MESSAGE, TYPE_BYTES, TYPE_UINT32, TYPE_ENUM, TYPE_SFIXED32, TYPE_SFIXED64, TYPE_SINT32, TYPE_SINT64,
+ };
+ public static Type valueOf(
+ com.google.protobuf.Descriptors.EnumValueDescriptor desc) {
+ if (desc.getType() != getDescriptor()) {
+ throw new java.lang.IllegalArgumentException(
+ "EnumValueDescriptor is not for this type.");
+ }
+ return VALUES[desc.getIndex()];
+ }
+ private final int index;
+ private final int value;
+ private Type(int index, int value) {
+ this.index = index;
+ this.value = value;
+ }
+
+ static {
+ com.google.protobuf.DescriptorProtos.getDescriptor();
+ }
+
+ // @@protoc_insertion_point(enum_scope:google.protobuf.FieldDescriptorProto.Type)
+ }
+
+ public enum Label
+ implements com.google.protobuf.ProtocolMessageEnum {
+ LABEL_OPTIONAL(0, 1),
+ LABEL_REQUIRED(1, 2),
+ LABEL_REPEATED(2, 3),
+ ;
+
+
+ @Override
+ public final int getNumber() { return value; }
+
+ public static Label valueOf(int value) {
+ switch (value) {
+ case 1: return LABEL_OPTIONAL;
+ case 2: return LABEL_REQUIRED;
+ case 3: return LABEL_REPEATED;
+ default: return null;
+ }
+ }
+
+ public static com.google.protobuf.Internal.EnumLiteMap