Add protobuf patch

This commit is contained in:
vshcherb 2013-11-11 01:06:14 +01:00
parent 2a736bcf07
commit 8af6fa9816
10 changed files with 184 additions and 183 deletions

View file

@ -1,6 +1,6 @@
bin
c-src
OsmAnd-core.jar
protobuf-src
protobuf-src/com
OsmAnd-core-android.jar
src/net/osmand/core/jni/*

View file

@ -37,6 +37,7 @@ index ad43f96..45004e2 100644
private static final int DEFAULT_SIZE_LIMIT = 64 << 20; // 64MB
- private static final int BUFFER_SIZE = 4096;
+ private static final int BUFFER_SIZE = 5 * 1024;
+
private CodedInputStream(final byte[] buffer, final int off, final int len) {
this.buffer = buffer;
@ -82,8 +83,9 @@ index ad43f96..45004e2 100644
while (pos < chunk.length) {
- final int n = (input == null) ? -1 :
- input.read(chunk, pos, chunk.length - pos);
+ // osmand change
+
+ final int n;
+ // osmand change
+ if(raf != null) {
+ raf.readFully(chunk, pos, chunk.length - pos);
+ n = chunk.length - pos;
@ -94,6 +96,14 @@ index ad43f96..45004e2 100644
if (n == -1) {
throw InvalidProtocolBufferException.truncatedMessage();
}
@@ -817,7 +854,6 @@ public final class CodedInputStream {
System.arraycopy(chunk, 0, bytes, pos, chunk.length);
pos += chunk.length;
}
-
// Done.
return bytes;
}
@@ -847,13 +883,19 @@ public final class CodedInputStream {
} else {
// Skipping more bytes than are in the buffer. First skip what we have.
@ -157,6 +167,7 @@ index ad43f96..02c1ee5 100644
* reading some other format of your own design, use the latter.
*
* @author kenton@google.com Kenton Varda
+ * OSMAND change
*/
-public final class CodedInputStream {
+public final class CodedInputStreamRAF {
@ -189,6 +200,63 @@ index ad43f96..02c1ee5 100644
// -----------------------------------------------------------------
@@ -210,55 +203,8 @@ public final class CodedInputStream {
}
}
- /** 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 {
@@ -480,7 +426,7 @@ public final class CodedInputStream {
private int bufferSize;
private int bufferSizeAfterLimit;
@ -291,6 +359,16 @@ diff --git b/OsmAnd-java/src/com/google/protobuf/CodedOutputStream.java a/OsmAnd
index 58dd150..6e81b98 100644
--- b/OsmAnd-java/src/com/google/protobuf/CodedOutputStream.java
+++ a/OsmAnd-java/src/com/google/protobuf/CodedOutputStream.java
@@ -30,8 +30,8 @@
package com.google.protobuf;
-import java.io.OutputStream;
import java.io.IOException;
+import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
/**
@@ -52,6 +52,8 @@ public final class CodedOutputStream {
private final byte[] buffer;
private final int limit;
@ -334,7 +412,7 @@ diff --git b/OsmAnd-java/src/com/google/protobuf/WireFormat.java a/OsmAnd-java/s
index c46f7b0..cca0b8e 100644
--- b/OsmAnd-java/src/com/google/protobuf/WireFormat.java
+++ a/OsmAnd-java/src/com/google/protobuf/WireFormat.java
@@ -51,12 +51,14 @@ public final class WireFormat {
@@ -51,11 +51,13 @@ public final class WireFormat {
static final int WIRETYPE_START_GROUP = 3;
static final int WIRETYPE_END_GROUP = 4;
static final int WIRETYPE_FIXED32 = 5;
@ -349,3 +427,4 @@ index c46f7b0..cca0b8e 100644
+ public static int getTagWireType(final int tag) {
return tag & TAG_TYPE_MASK;
}

View file

@ -0,0 +1,5 @@
#!/bin/bash
mkdir -p ../src/com
cp com/google/protobuf/CodedInputStream.java com/google/protobuf/CodedInputStreamRAF.java
cp -Rf com/* ../src/com/
git apply -v protobuf-2.3.patch

View file

@ -30,13 +30,13 @@
package com.google.protobuf;
import com.google.protobuf.Descriptors.Descriptor;
import com.google.protobuf.Descriptors.FieldDescriptor;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import com.google.protobuf.Descriptors.Descriptor;
import com.google.protobuf.Descriptors.FieldDescriptor;
/**
* A table of known extensions, searchable by name or field number. When
* parsing a protocol message that might have extensions, you must provide

View file

@ -30,13 +30,13 @@
package com.google.protobuf;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.TreeMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.io.IOException;
/**
* A class which represents an arbitrary set of fields of some message type.
@ -210,7 +210,7 @@ final class FieldSet<FieldDescriptorType extends
if (value == null) {
return 0;
} else {
return ((List<?>) value).size();
return ((List) value).size();
}
}
@ -218,7 +218,6 @@ final class FieldSet<FieldDescriptorType extends
* Useful for implementing
* {@link Message#getRepeatedField(Descriptors.FieldDescriptor,int)}.
*/
@SuppressWarnings("unchecked")
public Object getRepeatedField(final FieldDescriptorType descriptor,
final int index) {
if (!descriptor.isRepeated()) {
@ -558,7 +557,6 @@ public Object getRepeatedField(final FieldDescriptorType descriptor,
}
/** Write a single field. */
@SuppressWarnings("unchecked")
public static void writeField(final FieldDescriptorLite<?> descriptor,
final Object value,
final CodedOutputStream output)
@ -687,7 +685,6 @@ public static void writeField(final FieldDescriptorLite<?> descriptor,
/**
* Compute the number of bytes needed to encode a particular field.
*/
@SuppressWarnings("unchecked")
public static int computeFieldSize(final FieldDescriptorLite<?> descriptor,
final Object value) {
WireFormat.FieldType type = descriptor.getLiteType();

View file

@ -30,9 +30,13 @@
package com.google.protobuf;
import com.google.protobuf.Descriptors.Descriptor;
import com.google.protobuf.Descriptors.EnumValueDescriptor;
import com.google.protobuf.Descriptors.FieldDescriptor;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
@ -40,10 +44,6 @@ import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import com.google.protobuf.Descriptors.Descriptor;
import com.google.protobuf.Descriptors.EnumValueDescriptor;
import com.google.protobuf.Descriptors.FieldDescriptor;
/**
* All generated protocol message classes extend this class. This class
* implements most of the Message and Builder interfaces using Java reflection.
@ -64,13 +64,11 @@ public abstract class GeneratedMessage extends AbstractMessage {
*/
protected abstract FieldAccessorTable internalGetFieldAccessorTable();
@Override
public Descriptor getDescriptorForType() {
return internalGetFieldAccessorTable().descriptor;
}
/** Internal helper which returns a mutable map. */
@SuppressWarnings("unchecked")
private Map<FieldDescriptor, Object> getAllFieldsMutable() {
final TreeMap<FieldDescriptor, Object> result =
new TreeMap<FieldDescriptor, Object>();
@ -102,8 +100,7 @@ private Map<FieldDescriptor, Object> getAllFieldsMutable() {
// Check that embedded messages are initialized.
if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
if (field.isRepeated()) {
// Osmand fix (remove annotation)
final
@SuppressWarnings("unchecked") final
List<Message> messageList = (List<Message>) getField(field);
for (final Message element : messageList) {
if (!element.isInitialized()) {
@ -121,34 +118,28 @@ private Map<FieldDescriptor, Object> getAllFieldsMutable() {
return true;
}
@Override
public Map<FieldDescriptor, Object> getAllFields() {
return Collections.unmodifiableMap(getAllFieldsMutable());
}
@Override
public boolean hasField(final FieldDescriptor field) {
return internalGetFieldAccessorTable().getField(field).has(this);
}
@Override
public Object getField(final FieldDescriptor field) {
return internalGetFieldAccessorTable().getField(field).get(this);
}
@Override
public int getRepeatedFieldCount(final FieldDescriptor field) {
return internalGetFieldAccessorTable().getField(field)
.getRepeatedCount(this);
}
@Override
public Object getRepeatedField(final FieldDescriptor field, final int index) {
return internalGetFieldAccessorTable().getField(field)
.getRepeated(this, index);
}
@Override
public final UnknownFieldSet getUnknownFields() {
return unknownFields;
}
@ -182,28 +173,23 @@ public final UnknownFieldSet getUnknownFields() {
return internalGetResult().internalGetFieldAccessorTable();
}
@Override
public Descriptor getDescriptorForType() {
return internalGetFieldAccessorTable().descriptor;
}
@Override
public Map<FieldDescriptor, Object> getAllFields() {
return internalGetResult().getAllFields();
}
@Override
public Message.Builder newBuilderForField(
final FieldDescriptor field) {
return internalGetFieldAccessorTable().getField(field).newBuilder();
}
@Override
public boolean hasField(final FieldDescriptor field) {
return internalGetResult().hasField(field);
}
@Override
public Object getField(final FieldDescriptor field) {
if (field.isRepeated()) {
// The underlying list object is still modifiable at this point.
@ -215,31 +201,26 @@ public final UnknownFieldSet getUnknownFields() {
}
}
@Override
public BuilderType setField(final FieldDescriptor field,
final Object value) {
internalGetFieldAccessorTable().getField(field).set(this, value);
return (BuilderType) this;
}
@Override
public BuilderType clearField(final FieldDescriptor field) {
internalGetFieldAccessorTable().getField(field).clear(this);
return (BuilderType) this;
}
@Override
public int getRepeatedFieldCount(final FieldDescriptor field) {
return internalGetResult().getRepeatedFieldCount(field);
}
@Override
public Object getRepeatedField(final FieldDescriptor field,
final int index) {
return internalGetResult().getRepeatedField(field, index);
}
@Override
public BuilderType setRepeatedField(final FieldDescriptor field,
final int index, final Object value) {
internalGetFieldAccessorTable().getField(field)
@ -247,19 +228,16 @@ public final UnknownFieldSet getUnknownFields() {
return (BuilderType) this;
}
@Override
public BuilderType addRepeatedField(final FieldDescriptor field,
final Object value) {
internalGetFieldAccessorTable().getField(field).addRepeated(this, value);
return (BuilderType) this;
}
@Override
public final UnknownFieldSet getUnknownFields() {
return internalGetResult().unknownFields;
}
@Override
public final BuilderType setUnknownFields(
final UnknownFieldSet unknownFields) {
internalGetResult().unknownFields = unknownFields;
@ -277,7 +255,6 @@ public final UnknownFieldSet getUnknownFields() {
return (BuilderType) this;
}
@Override
public boolean isInitialized() {
return internalGetResult().isInitialized();
}
@ -361,7 +338,6 @@ public final UnknownFieldSet getUnknownFields() {
/** Get the number of elements in a repeated extension. */
public final <Type> int getExtensionCount(
// osmand fix >> -> > >
final GeneratedExtension<MessageType, List<Type>> extension) {
verifyExtensionContainingType(extension);
final FieldDescriptor descriptor = extension.getDescriptor();
@ -393,7 +369,6 @@ public final UnknownFieldSet getUnknownFields() {
/** Get one element of a repeated extension. */
@SuppressWarnings("unchecked")
public final <Type> Type getExtension(
// osmand fix >> -> > >
final GeneratedExtension<MessageType, List<Type>> extension,
final int index) {
verifyExtensionContainingType(extension);
@ -421,7 +396,7 @@ public final UnknownFieldSet getUnknownFields() {
protected class ExtensionWriter {
// Imagine how much simpler this code would be if Java iterators had
// a way to get the next element without advancing the iterator.
// osmand fix >> -> > >
private final Iterator<Map.Entry<FieldDescriptor, Object>> iter =
extensions.iterator();
private Map.Entry<FieldDescriptor, Object> next;
@ -604,7 +579,6 @@ public final UnknownFieldSet getUnknownFields() {
/** Get the number of elements in a repeated extension. */
public final <Type> int getExtensionCount(
// osmand fix >> -> > >
final GeneratedExtension<MessageType, List<Type>> extension) {
return internalGetResult().getExtensionCount(extension);
}
@ -617,7 +591,6 @@ public final UnknownFieldSet getUnknownFields() {
/** Get one element of a repeated extension. */
public final <Type> Type getExtension(
// osmand fix >> -> > >
final GeneratedExtension<MessageType, List<Type>> extension,
final int index) {
return internalGetResult().getExtension(extension, index);
@ -637,7 +610,6 @@ public final UnknownFieldSet getUnknownFields() {
/** Set the value of one element of a repeated extension. */
public final <Type> BuilderType setExtension(
// osmand fix >> -> > >
final GeneratedExtension<MessageType, List<Type>> extension,
final int index, final Type value) {
final ExtendableMessage<MessageType> message = internalGetResult();
@ -651,7 +623,6 @@ public final UnknownFieldSet getUnknownFields() {
/** Append a value to a repeated extension. */
public final <Type> BuilderType addExtension(
// osmand fix >> -> > >
final GeneratedExtension<MessageType, List<Type>> extension,
final Type value) {
final ExtendableMessage<MessageType> message = internalGetResult();
@ -1091,45 +1062,36 @@ public final UnknownFieldSet getUnknownFields() {
protected final Method hasMethod;
protected final Method clearMethod;
@Override
public Object get(final GeneratedMessage message) {
return invokeOrDie(getMethod, message);
}
@Override
public void set(final Builder builder, final Object value) {
invokeOrDie(setMethod, builder, value);
}
@Override
public Object getRepeated(final GeneratedMessage message,
final int index) {
throw new UnsupportedOperationException(
"getRepeatedField() called on a singular field.");
}
@Override
public void setRepeated(final Builder builder,
final int index, final Object value) {
throw new UnsupportedOperationException(
"setRepeatedField() called on a singular field.");
}
@Override
public void addRepeated(final Builder builder, final Object value) {
throw new UnsupportedOperationException(
"addRepeatedField() called on a singular field.");
}
@Override
public boolean has(final GeneratedMessage message) {
return (Boolean) invokeOrDie(hasMethod, message);
}
@Override
public int getRepeatedCount(final GeneratedMessage message) {
throw new UnsupportedOperationException(
"getRepeatedFieldSize() called on a singular field.");
}
@Override
public void clear(final Builder builder) {
invokeOrDie(clearMethod, builder);
}
@Override
public Message.Builder newBuilder() {
throw new UnsupportedOperationException(
"newBuilderForField() called on a non-Message type.");
@ -1166,11 +1128,9 @@ public final UnknownFieldSet getUnknownFields() {
protected final Method getCountMethod;
protected final Method clearMethod;
@Override
public Object get(final GeneratedMessage message) {
return invokeOrDie(getMethod, message);
}
@Override
public void set(final Builder builder, final Object value) {
// Add all the elements individually. This serves two purposes:
// 1) Verifies that each element has the correct type.
@ -1181,34 +1141,27 @@ public final UnknownFieldSet getUnknownFields() {
addRepeated(builder, element);
}
}
@Override
public Object getRepeated(final GeneratedMessage message,
final int index) {
return invokeOrDie(getRepeatedMethod, message, index);
}
@Override
public void setRepeated(final Builder builder,
final int index, final Object value) {
invokeOrDie(setRepeatedMethod, builder, index, value);
}
@Override
public void addRepeated(final Builder builder, final Object value) {
invokeOrDie(addRepeatedMethod, builder, value);
}
@Override
public boolean has(final GeneratedMessage message) {
throw new UnsupportedOperationException(
"hasField() called on a singular field.");
}
@Override
public int getRepeatedCount(final GeneratedMessage message) {
return (Integer) invokeOrDie(getCountMethod, message);
}
@Override
public void clear(final Builder builder) {
invokeOrDie(clearMethod, builder);
}
@Override
public Message.Builder newBuilder() {
throw new UnsupportedOperationException(
"newBuilderForField() called on a non-Message type.");

View file

@ -63,7 +63,6 @@ public abstract class GeneratedMessageLite extends AbstractMessageLite {
public abstract BuilderType mergeFrom(MessageType message);
// Defined here for return type covariance.
@Override
public abstract MessageType getDefaultInstanceForType();
/**
@ -447,44 +446,36 @@ public abstract class GeneratedMessageLite extends AbstractMessageLite {
private final boolean isRepeated;
private final boolean isPacked;
@Override
public int getNumber() {
return number;
}
@Override
public WireFormat.FieldType getLiteType() {
return type;
}
@Override
public WireFormat.JavaType getLiteJavaType() {
return type.getJavaType();
}
@Override
public boolean isRepeated() {
return isRepeated;
}
@Override
public boolean isPacked() {
return isPacked;
}
@Override
public Internal.EnumLiteMap<?> getEnumType() {
return enumTypeMap;
}
@Override
@SuppressWarnings("unchecked")
public MessageLite.Builder internalMergeFrom(
MessageLite.Builder to, MessageLite from) {
return ((Builder) to).mergeFrom((GeneratedMessageLite) from);
}
@Override
public int compareTo(ExtensionDescriptor other) {
return number - other.number;
}
@ -533,7 +524,6 @@ public abstract class GeneratedMessageLite extends AbstractMessageLite {
}
/** For use by generated code only. */
@SuppressWarnings("unchecked")
public void internalInitRepeated(
final ContainingType containingTypeDefaultInstance,
final MessageLite messageDefaultInstance,

View file

@ -59,7 +59,6 @@ public interface Message extends MessageLite {
Descriptors.Descriptor getDescriptorForType();
// (From MessageLite, re-declared here only for return type covariance.)
@Override
Message getDefaultInstanceForType();
/**
@ -153,9 +152,7 @@ Message getDefaultInstanceForType();
// Builders
// (From MessageLite, re-declared here only for return type covariance.)
@Override
Builder newBuilderForType();
@Override
Builder toBuilder();
/**
@ -164,7 +161,6 @@ Builder toBuilder();
interface Builder extends MessageLite.Builder {
// (From MessageLite.Builder, re-declared here only for return type
// covariance.)
@Override
Builder clear();
/**
@ -187,15 +183,10 @@ Builder toBuilder();
// (From MessageLite.Builder, re-declared here only for return type
// covariance.)
@Override
Message build();
@Override
Message buildPartial();
@Override
Builder clone();
@Override
Builder mergeFrom(CodedInputStream input) throws IOException;
@Override
Builder mergeFrom(CodedInputStream input,
ExtensionRegistryLite extensionRegistry)
throws IOException;
@ -208,7 +199,6 @@ Builder toBuilder();
// (From MessageLite.Builder, re-declared here only for return type
// covariance.)
@Override
Message getDefaultInstanceForType();
/**
@ -289,35 +279,25 @@ Builder toBuilder();
// (From MessageLite.Builder, re-declared here only for return type
// covariance.)
@Override
Builder mergeFrom(ByteString data) throws InvalidProtocolBufferException;
@Override
Builder mergeFrom(ByteString data,
ExtensionRegistryLite extensionRegistry)
throws InvalidProtocolBufferException;
@Override
Builder mergeFrom(byte[] data) throws InvalidProtocolBufferException;
@Override
Builder mergeFrom(byte[] data, int off, int len)
throws InvalidProtocolBufferException;
@Override
Builder mergeFrom(byte[] data,
ExtensionRegistryLite extensionRegistry)
throws InvalidProtocolBufferException;
@Override
Builder mergeFrom(byte[] data, int off, int len,
ExtensionRegistryLite extensionRegistry)
throws InvalidProtocolBufferException;
@Override
Builder mergeFrom(InputStream input) throws IOException;
@Override
Builder mergeFrom(InputStream input,
ExtensionRegistryLite extensionRegistry)
throws IOException;
@Override
boolean mergeDelimitedFrom(InputStream input)
throws IOException;
@Override
boolean mergeDelimitedFrom(InputStream input,
ExtensionRegistryLite extensionRegistry)
throws IOException;

View file

@ -42,7 +42,6 @@ public interface ProtocolMessageEnum extends Internal.EnumLite {
/**
* Return the value's numeric value as defined in the .proto file.
*/
@Override
int getNumber();
/**

View file

@ -71,7 +71,6 @@ public final class RpcUtil {
final Class<Type> originalClass,
final Type defaultInstance) {
return new RpcCallback<Message>() {
@Override
public void run(final Message parameter) {
Type typedParameter;
try {
@ -109,7 +108,6 @@ public final class RpcUtil {
return new RpcCallback<ParameterType>() {
private boolean alreadyCalled = false;
@Override
public void run(final ParameterType parameter) {
synchronized(this) {
if (alreadyCalled) {