summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--build.gradle44
-rw-r--r--java/src/main/java/com/google/protobuf/nano/ExtendableMessageNano.java25
-rw-r--r--java/src/main/java/com/google/protobuf/nano/FieldArray.java19
-rw-r--r--src/google/protobuf/compiler/javanano/javanano_generator.cc2
-rw-r--r--src/google/protobuf/compiler/javanano/javanano_message.cc10
5 files changed, 79 insertions, 21 deletions
diff --git a/build.gradle b/build.gradle
index 4684592..7aa8ac2 100644
--- a/build.gradle
+++ b/build.gradle
@@ -19,9 +19,11 @@ apply plugin: 'java'
configurations {
micro
nano
+ lite
}
sourceSets {
+
micro {
java {
srcDirs = ['java/src/main/java/']
@@ -29,6 +31,38 @@ sourceSets {
}
}
+ lite {
+ java {
+ srcDirs = ['java/src/main/java/']
+ include 'com/google/protobuf/UninitializedMessageException.java'
+ include 'com/google/protobuf/MessageLite.java'
+ include 'com/google/protobuf/InvalidProtocolBufferException.java'
+ include 'com/google/protobuf/CodedOutputStream.java'
+ include 'com/google/protobuf/ByteString.java'
+ include 'com/google/protobuf/CodedInputStream.java'
+ include 'com/google/protobuf/ExtensionRegistryLite.java'
+ include 'com/google/protobuf/AbstractMessageLite.java'
+ include 'com/google/protobuf/AbstractParser.java'
+ include 'com/google/protobuf/FieldSet.java'
+ include 'com/google/protobuf/Internal.java'
+ include 'com/google/protobuf/WireFormat.java'
+ include 'com/google/protobuf/GeneratedMessageLite.java'
+ include 'com/google/protobuf/BoundedByteString.java'
+ include 'com/google/protobuf/LazyField.java'
+ include 'com/google/protobuf/LazyFieldLite.java'
+ include 'com/google/protobuf/LazyStringList.java'
+ include 'com/google/protobuf/LazyStringArrayList.java'
+ include 'com/google/protobuf/UnmodifiableLazyStringList.java'
+ include 'com/google/protobuf/LiteralByteString.java'
+ include 'com/google/protobuf/MessageLiteOrBuilder.java'
+ include 'com/google/protobuf/Parser.java'
+ include 'com/google/protobuf/ProtocolStringList.java'
+ include 'com/google/protobuf/RopeByteString.java'
+ include 'com/google/protobuf/SmallSortedMap.java'
+ include 'com/google/protobuf/Utf8.java'
+ }
+ }
+
nano {
java {
srcDirs = [
@@ -77,8 +111,18 @@ task microJar(type: Jar) {
classifier "micro"
}
+task liteJar(type: Jar) {
+ from sourceSets.lite.output
+ dependsOn liteClasses
+ baseName "libprotobuf"
+ appendix "java"
+ version "2.3"
+ classifier "lite"
+}
+
artifacts {
micro microJar
nano nanoJar
+ lite liteJar
}
diff --git a/java/src/main/java/com/google/protobuf/nano/ExtendableMessageNano.java b/java/src/main/java/com/google/protobuf/nano/ExtendableMessageNano.java
index 4fe8dce..8244164 100644
--- a/java/src/main/java/com/google/protobuf/nano/ExtendableMessageNano.java
+++ b/java/src/main/java/com/google/protobuf/nano/ExtendableMessageNano.java
@@ -160,6 +160,31 @@ public abstract class ExtendableMessageNano<M extends ExtendableMessageNano<M>>
return true;
}
+ /**
+ * Returns whether the stored unknown field data in this message is equivalent to that in the
+ * other message.
+ *
+ * @param other the other message.
+ * @return whether the two sets of unknown field data are equal.
+ */
+ protected final boolean unknownFieldDataEquals(M other) {
+ if (unknownFieldData == null || unknownFieldData.isEmpty()) {
+ return other.unknownFieldData == null || other.unknownFieldData.isEmpty();
+ } else {
+ return unknownFieldData.equals(other.unknownFieldData);
+ }
+ }
+
+ /**
+ * Computes the hashcode representing the unknown field data stored in this message.
+ *
+ * @return the hashcode for the unknown field data.
+ */
+ protected final int unknownFieldDataHashCode() {
+ return (unknownFieldData == null || unknownFieldData.isEmpty()
+ ? 0 : unknownFieldData.hashCode());
+ }
+
@Override
public M clone() throws CloneNotSupportedException {
M cloned = (M) super.clone();
diff --git a/java/src/main/java/com/google/protobuf/nano/FieldArray.java b/java/src/main/java/com/google/protobuf/nano/FieldArray.java
index 5e8856d..473c161 100644
--- a/java/src/main/java/com/google/protobuf/nano/FieldArray.java
+++ b/java/src/main/java/com/google/protobuf/nano/FieldArray.java
@@ -35,12 +35,9 @@ package com.google.protobuf.nano;
* A custom version of {@link android.util.SparseArray} with the minimal API
* for storing {@link FieldData} objects.
*
- * <p>This class is an internal implementation detail of nano and should not
- * be called directly by clients.
- *
* Based on {@link android.support.v4.util.SpareArrayCompat}.
*/
-public final class FieldArray implements Cloneable {
+class FieldArray implements Cloneable {
private static final FieldData DELETED = new FieldData();
private boolean mGarbage = false;
@@ -51,7 +48,7 @@ public final class FieldArray implements Cloneable {
/**
* Creates a new FieldArray containing no fields.
*/
- FieldArray() {
+ public FieldArray() {
this(10);
}
@@ -60,7 +57,7 @@ public final class FieldArray implements Cloneable {
* require any additional memory allocation to store the specified
* number of mappings.
*/
- FieldArray(int initialCapacity) {
+ public FieldArray(int initialCapacity) {
initialCapacity = idealIntArraySize(initialCapacity);
mFieldNumbers = new int[initialCapacity];
mData = new FieldData[initialCapacity];
@@ -71,7 +68,7 @@ public final class FieldArray implements Cloneable {
* Gets the FieldData mapped from the specified fieldNumber, or <code>null</code>
* if no such mapping has been made.
*/
- FieldData get(int fieldNumber) {
+ public FieldData get(int fieldNumber) {
int i = binarySearch(fieldNumber);
if (i < 0 || mData[i] == DELETED) {
@@ -84,7 +81,7 @@ public final class FieldArray implements Cloneable {
/**
* Removes the data from the specified fieldNumber, if there was any.
*/
- void remove(int fieldNumber) {
+ public void remove(int fieldNumber) {
int i = binarySearch(fieldNumber);
if (i >= 0 && mData[i] != DELETED) {
@@ -121,7 +118,7 @@ public final class FieldArray implements Cloneable {
* Adds a mapping from the specified fieldNumber to the specified data,
* replacing the previous mapping if there was one.
*/
- void put(int fieldNumber, FieldData data) {
+ public void put(int fieldNumber, FieldData data) {
int i = binarySearch(fieldNumber);
if (i >= 0) {
@@ -170,7 +167,7 @@ public final class FieldArray implements Cloneable {
* Returns the number of key-value mappings that this FieldArray
* currently stores.
*/
- int size() {
+ public int size() {
if (mGarbage) {
gc();
}
@@ -187,7 +184,7 @@ public final class FieldArray implements Cloneable {
* the value from the <code>index</code>th key-value mapping that this
* FieldArray stores.
*/
- FieldData dataAt(int index) {
+ public FieldData dataAt(int index) {
if (mGarbage) {
gc();
}
diff --git a/src/google/protobuf/compiler/javanano/javanano_generator.cc b/src/google/protobuf/compiler/javanano/javanano_generator.cc
index 99ebe12..96e3e80 100644
--- a/src/google/protobuf/compiler/javanano/javanano_generator.cc
+++ b/src/google/protobuf/compiler/javanano/javanano_generator.cc
@@ -156,8 +156,6 @@ bool JavaNanoGenerator::Generate(const FileDescriptor* file,
params.set_generate_clone(option_value == "true");
} else if (option_name == "generate_intdefs") {
params.set_generate_intdefs(option_value == "true");
- } else if (option_name == "generate_clear") {
- params.set_generate_clear(option_value == "true");
} else {
*error = "Ignore unknown javanano generator option: " + option_name;
}
diff --git a/src/google/protobuf/compiler/javanano/javanano_message.cc b/src/google/protobuf/compiler/javanano/javanano_message.cc
index 4026031..dcfb870 100644
--- a/src/google/protobuf/compiler/javanano/javanano_message.cc
+++ b/src/google/protobuf/compiler/javanano/javanano_message.cc
@@ -552,11 +552,7 @@ void MessageGenerator::GenerateEquals(io::Printer* printer) {
if (params_.store_unknown_fields()) {
printer->Print(
- "if (unknownFieldData == null || unknownFieldData.isEmpty()) {\n"
- " return other.unknownFieldData == null || other.unknownFieldData.isEmpty();\n"
- "} else {\n"
- " return unknownFieldData.equals(other.unknownFieldData);\n"
- "}");
+ "return unknownFieldDataEquals(other);\n");
} else {
printer->Print(
"return true;\n");
@@ -586,9 +582,7 @@ void MessageGenerator::GenerateHashCode(io::Printer* printer) {
if (params_.store_unknown_fields()) {
printer->Print(
- "result = 31 * result + \n"
- " (unknownFieldData == null || unknownFieldData.isEmpty() ? 0 : \n"
- " unknownFieldData.hashCode());\n");
+ "result = 31 * result + unknownFieldDataHashCode();\n");
}
printer->Print("return result;\n");