summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Android.mk61
-rw-r--r--build.gradle21
-rw-r--r--java/README.txt11
-rw-r--r--java/src/device/main/java/com/google/protobuf/nano/android/ParcelableExtendableMessageNano.java69
-rw-r--r--java/src/device/main/java/com/google/protobuf/nano/android/ParcelableMessageNano.java67
-rw-r--r--java/src/device/main/java/com/google/protobuf/nano/android/ParcelingUtil.java72
-rw-r--r--java/src/device/test/AndroidManifest.xml50
-rw-r--r--java/src/device/test/java/com/google/protobuf/nano/NanoAndroidTest.java87
-rw-r--r--src/google/protobuf/compiler/javanano/javanano_generator.cc2
-rw-r--r--src/google/protobuf/compiler/javanano/javanano_message.cc9
-rw-r--r--src/google/protobuf/compiler/javanano/javanano_params.h11
11 files changed, 454 insertions, 6 deletions
diff --git a/Android.mk b/Android.mk
index ec28bec..faf6e39 100644
--- a/Android.mk
+++ b/Android.mk
@@ -142,6 +142,7 @@ LOCAL_MODULE_TAGS := optional
LOCAL_SDK_VERSION := 8
LOCAL_SRC_FILES := $(call all-java-files-under, java/src/main/java/com/google/protobuf/nano)
+LOCAL_SRC_FILES += $(call all-java-files-under, java/src/device/main/java/com/google/protobuf/nano)
include $(BUILD_STATIC_JAVA_LIBRARY)
@@ -379,3 +380,63 @@ LOCAL_PROTO_JAVA_OUTPUT_PARAMS := \
java_outer_classname = $(LOCAL_PATH)/src/google/protobuf/unittest_import_nano.proto|UnittestImportNano
include $(BUILD_STATIC_JAVA_LIBRARY)
+
+# To test Android-specific nanoproto features.
+# =======================================================
+include $(CLEAR_VARS)
+
+# Parcelable messages
+LOCAL_MODULE := android-nano-test-parcelable
+LOCAL_MODULE_TAGS := tests
+LOCAL_SDK_VERSION := current
+
+LOCAL_PROTOC_OPTIMIZE_TYPE := nano
+
+LOCAL_SRC_FILES := src/google/protobuf/unittest_simple_nano.proto
+
+LOCAL_PROTOC_FLAGS := --proto_path=$(LOCAL_PATH)/src
+
+LOCAL_PROTO_JAVA_OUTPUT_PARAMS := \
+ parcelable_messages = true
+
+include $(BUILD_STATIC_JAVA_LIBRARY)
+
+include $(CLEAR_VARS)
+
+# Parcelable and extendable messages
+LOCAL_MODULE := android-nano-test-parcelable-extendable
+LOCAL_MODULE_TAGS := tests
+LOCAL_SDK_VERSION := current
+
+LOCAL_PROTOC_OPTIMIZE_TYPE := nano
+
+LOCAL_SRC_FILES := src/google/protobuf/unittest_extension_nano.proto
+
+LOCAL_PROTOC_FLAGS := --proto_path=$(LOCAL_PATH)/src
+
+LOCAL_PROTO_JAVA_OUTPUT_PARAMS := \
+ parcelable_messages = true, \
+ store_unknown_fields = true
+
+include $(BUILD_STATIC_JAVA_LIBRARY)
+
+include $(CLEAR_VARS)
+
+# Test APK
+LOCAL_PACKAGE_NAME := NanoAndroidTest
+
+LOCAL_SDK_VERSION := 8
+
+LOCAL_MODULE_TAGS := tests
+
+LOCAL_SRC_FILES := $(call all-java-files-under, java/src/device/test/java/com/google/protobuf/nano)
+
+LOCAL_MANIFEST_FILE := java/src/device/test/AndroidManifest.xml
+
+LOCAL_STATIC_JAVA_LIBRARIES := libprotobuf-java-2.3.0-nano \
+ android-nano-test-parcelable \
+ android-nano-test-parcelable-extendable
+
+WITH_DEXPREOPT := false
+
+include $(BUILD_PACKAGE)
diff --git a/build.gradle b/build.gradle
index 1efd4bf..95c9b1d 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,4 +1,3 @@
-=======
/*
* Copyright (C) 2013 The Android Open Source Project
*
@@ -25,17 +24,33 @@ configurations {
sourceSets {
micro {
java {
- srcDirs = ['java/src/main/java/com/google/protobuf/micro']
+ srcDirs = ['java/src/main/java/']
+ include("com/google/protobuf/micro/*")
}
}
nano {
java {
- srcDirs = ['java/src/main/java/com/google/protobuf/nano']
+ srcDirs = [
+ 'java/src/main/java/',
+ 'java/src/device/main/java/'
+ ]
+ include("com/google/protobuf/nano/**")
}
}
}
+if (project == rootProject) {
+ ext.getAndroidPrebuilt = { apiLevel ->
+ files("$rootDir/../../prebuilts/sdk/$apiLevel/android.jar")
+ }
+}
+
+dependencies {
+ compile getAndroidPrebuilt('8')
+ nanoCompile getAndroidPrebuilt('8')
+}
+
jar {
from sourceSets.nano.output, sourceSets.micro.output
baseName "libprotobuf"
diff --git a/java/README.txt b/java/README.txt
index f922c4b..c693313 100644
--- a/java/README.txt
+++ b/java/README.txt
@@ -476,6 +476,7 @@ java_nano_generate_has -> true or false [DEPRECATED]
optional_field_style -> default or accessors
enum_style -> c or java
ignore_services -> true or false
+parcelable_messages -> true or false
java_package:
java_outer_classname:
@@ -588,6 +589,9 @@ ignore_services={true,false} (default: false)
it will generate a compilation error. If this flag is set to true,
services will be silently ignored, instead.
+parcelable_messages={true,false} (default: false)
+ Android-specific option to generate Parcelable messages.
+
To use nano protobufs within the Android repo:
@@ -638,8 +642,13 @@ Please run the following steps to test:
- cd ../../..
- . build/envsetup.sh
- lunch 1
-- "make -j12 aprotoc libprotobuf-java-2.3.0-nano aprotoc-test-nano-params" and
+- "make -j12 aprotoc libprotobuf-java-2.3.0-nano aprotoc-test-nano-params NanoAndroidTest" and
check for build errors.
+- Plug in an Android device or start an emulator.
+- adb install -r out/target/product/generic/data/app/NanoAndroidTest.apk
+- Run:
+ "adb shell am instrument -w com.google.protobuf.nano.test/android.test.InstrumentationTestRunner"
+ and verify all tests pass.
- repo sync -c -j256
- "make -j12" and check for build errors
diff --git a/java/src/device/main/java/com/google/protobuf/nano/android/ParcelableExtendableMessageNano.java b/java/src/device/main/java/com/google/protobuf/nano/android/ParcelableExtendableMessageNano.java
new file mode 100644
index 0000000..f3b82ed
--- /dev/null
+++ b/java/src/device/main/java/com/google/protobuf/nano/android/ParcelableExtendableMessageNano.java
@@ -0,0 +1,69 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2014 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.nano.android;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import com.google.protobuf.nano.ExtendableMessageNano;
+
+/**
+ * Base class for Parcelable Protocol Buffer messages which also need to store unknown
+ * fields, such as extensions.
+ */
+public abstract class ParcelableExtendableMessageNano<M extends ExtendableMessageNano<M>>
+ extends ExtendableMessageNano<M> implements Parcelable {
+
+ // Used by Parcelable
+ @SuppressWarnings({"unused"})
+ public static final Creator<ParcelableExtendableMessageNano<?>> CREATOR =
+ new Creator<ParcelableExtendableMessageNano<?>>() {
+ @Override
+ public ParcelableExtendableMessageNano<?> createFromParcel(Parcel in) {
+ return ParcelingUtil.createFromParcel(in);
+ }
+
+ @Override
+ public ParcelableExtendableMessageNano<?>[] newArray(int size) {
+ return new ParcelableExtendableMessageNano<?>[size];
+ }
+ };
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel out, int flags) {
+ ParcelingUtil.writeToParcel(getClass(), this, out);
+ }
+}
diff --git a/java/src/device/main/java/com/google/protobuf/nano/android/ParcelableMessageNano.java b/java/src/device/main/java/com/google/protobuf/nano/android/ParcelableMessageNano.java
new file mode 100644
index 0000000..b07f1d6
--- /dev/null
+++ b/java/src/device/main/java/com/google/protobuf/nano/android/ParcelableMessageNano.java
@@ -0,0 +1,67 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2014 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.nano.android;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import com.google.protobuf.nano.MessageNano;
+
+/**
+ * Base class for Parcelable Protocol Buffer messages.
+ */
+public abstract class ParcelableMessageNano extends MessageNano implements Parcelable {
+
+ // Used by Parcelable
+ @SuppressWarnings("unused")
+ public static final Creator<ParcelableMessageNano> CREATOR =
+ new Creator<ParcelableMessageNano>() {
+ @Override
+ public ParcelableMessageNano createFromParcel(Parcel in) {
+ return ParcelingUtil.createFromParcel(in);
+ }
+
+ @Override
+ public ParcelableMessageNano[] newArray(int size) {
+ return new ParcelableMessageNano[size];
+ }
+ };
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel out, int flags) {
+ ParcelingUtil.writeToParcel(getClass(), this, out);
+ }
+}
diff --git a/java/src/device/main/java/com/google/protobuf/nano/android/ParcelingUtil.java b/java/src/device/main/java/com/google/protobuf/nano/android/ParcelingUtil.java
new file mode 100644
index 0000000..1eb84ee
--- /dev/null
+++ b/java/src/device/main/java/com/google/protobuf/nano/android/ParcelingUtil.java
@@ -0,0 +1,72 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2014 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.nano.android;
+
+import android.os.Parcel;
+import android.util.Log;
+
+import com.google.protobuf.nano.InvalidProtocolBufferNanoException;
+import com.google.protobuf.nano.MessageNano;
+
+final class ParcelingUtil {
+ private static final String TAG = "ParcelingUtil";
+
+ @SuppressWarnings("unchecked")
+ static <T extends MessageNano> T createFromParcel(Parcel in) {
+ String className = in.readString();
+ byte[] data = in.createByteArray();
+
+ T proto = null;
+
+ try {
+ Class<?> clazz = Class.forName(className);
+ Object instance = clazz.newInstance();
+ proto = (T) instance;
+ MessageNano.mergeFrom(proto, data);
+ } catch (ClassNotFoundException e) {
+ Log.e(TAG, "Exception trying to create proto from parcel", e);
+ } catch (IllegalAccessException e) {
+ Log.e(TAG, "Exception trying to create proto from parcel", e);
+ } catch (InstantiationException e) {
+ Log.e(TAG, "Exception trying to create proto from parcel", e);
+ } catch (InvalidProtocolBufferNanoException e) {
+ Log.e(TAG, "Exception trying to create proto from parcel", e);
+ }
+
+ return proto;
+ }
+
+ static <T extends MessageNano> void writeToParcel(Class<T> clazz, MessageNano message,
+ Parcel out) {
+ out.writeString(clazz.getName());
+ out.writeByteArray(MessageNano.toByteArray(message));
+ }
+}
diff --git a/java/src/device/test/AndroidManifest.xml b/java/src/device/test/AndroidManifest.xml
new file mode 100644
index 0000000..cc54e57
--- /dev/null
+++ b/java/src/device/test/AndroidManifest.xml
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Protocol Buffers - Google's data interchange format
+ Copyright 2014 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.
+-->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.google.protobuf.nano.test"
+ android:versionCode="1"
+ android:versionName="1.0">
+
+ <uses-sdk
+ android:minSdkVersion="8"
+ android:targetSdkVersion="8" />
+
+ <instrumentation
+ android:name="android.test.InstrumentationTestRunner"
+ android:targetPackage="com.google.protobuf.nano.test" />
+
+ <application>
+ <uses-library android:name="android.test.runner" />
+ </application>
+
+</manifest>
diff --git a/java/src/device/test/java/com/google/protobuf/nano/NanoAndroidTest.java b/java/src/device/test/java/com/google/protobuf/nano/NanoAndroidTest.java
new file mode 100644
index 0000000..7092485
--- /dev/null
+++ b/java/src/device/test/java/com/google/protobuf/nano/NanoAndroidTest.java
@@ -0,0 +1,87 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2014 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.nano;
+
+import android.os.Parcel;
+
+import com.google.protobuf.nano.Extensions.ContainerMessage;
+import com.google.protobuf.nano.Extensions.ExtendableMessage;
+import com.google.protobuf.nano.UnittestSimpleNano.SimpleMessageNano;
+import com.google.protobuf.nano.UnittestSimpleNano.SimpleMessageNano.NestedMessage;
+
+import junit.framework.TestCase;
+
+public class NanoAndroidTest extends TestCase {
+ public void testParceling() {
+ SimpleMessageNano message = new SimpleMessageNano();
+ message.d = 54321;
+ message.nestedMsg = new NestedMessage();
+ message.nestedMsg.bb = 12345;
+ message.defaultNestedEnum = SimpleMessageNano.FOO;
+
+ Parcel parcel = null;
+ try {
+ parcel = Parcel.obtain();
+ parcel.writeParcelable(message, 0);
+ parcel.setDataPosition(0);
+ message = parcel.readParcelable(getClass().getClassLoader());
+ } finally {
+ if (parcel != null) {
+ parcel.recycle();
+ }
+ }
+
+ assertEquals(54321, message.d);
+ assertEquals(12345, message.nestedMsg.bb);
+ assertEquals(SimpleMessageNano.FOO, message.defaultNestedEnum);
+ }
+
+ public void testExtendableParceling() {
+ ExtendableMessage message = new ExtendableMessage();
+ message.field = 12345;
+ message.setExtension(ContainerMessage.anotherThing, true);
+
+ Parcel parcel = null;
+ try {
+ parcel = Parcel.obtain();
+ parcel.writeParcelable(message, 0);
+ parcel.setDataPosition(0);
+ message = parcel.readParcelable(getClass().getClassLoader());
+ } finally {
+ if (parcel != null) {
+ parcel.recycle();
+ }
+ }
+
+ assertEquals(12345, message.field);
+ assertTrue((boolean) message.getExtension(ContainerMessage.anotherThing));
+ }
+}
diff --git a/src/google/protobuf/compiler/javanano/javanano_generator.cc b/src/google/protobuf/compiler/javanano/javanano_generator.cc
index 0e12103..61ef2ca 100644
--- a/src/google/protobuf/compiler/javanano/javanano_generator.cc
+++ b/src/google/protobuf/compiler/javanano/javanano_generator.cc
@@ -144,6 +144,8 @@ bool JavaNanoGenerator::Generate(const FileDescriptor* file,
params.set_generate_equals(option_value == "true");
} else if (option_name == "ignore_services") {
params.set_ignore_services(option_value == "true");
+ } else if (option_name == "parcelable_messages") {
+ params.set_parcelable_messages(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 3a1b5a5..0cf9f97 100644
--- a/src/google/protobuf/compiler/javanano/javanano_message.cc
+++ b/src/google/protobuf/compiler/javanano/javanano_message.cc
@@ -132,10 +132,17 @@ void MessageGenerator::Generate(io::Printer* printer) {
"public static final class $classname$ extends\n",
"classname", descriptor_->name());
}
- if (params_.store_unknown_fields()) {
+ if (params_.store_unknown_fields() && params_.parcelable_messages()) {
+ printer->Print(
+ " com.google.protobuf.nano.android.ParcelableExtendableMessageNano<$classname$> {\n",
+ "classname", descriptor_->name());
+ } else if (params_.store_unknown_fields()) {
printer->Print(
" com.google.protobuf.nano.ExtendableMessageNano<$classname$> {\n",
"classname", descriptor_->name());
+ } else if (params_.parcelable_messages()) {
+ printer->Print(
+ " com.google.protobuf.nano.android.ParcelableMessageNano {\n");
} else {
printer->Print(
" com.google.protobuf.nano.MessageNano {\n");
diff --git a/src/google/protobuf/compiler/javanano/javanano_params.h b/src/google/protobuf/compiler/javanano/javanano_params.h
index 889395e..d0626a2 100644
--- a/src/google/protobuf/compiler/javanano/javanano_params.h
+++ b/src/google/protobuf/compiler/javanano/javanano_params.h
@@ -63,6 +63,7 @@ class Params {
bool use_reference_types_for_primitives_;
bool generate_equals_;
bool ignore_services_;
+ bool parcelable_messages_;
public:
Params(const string & base_name) :
@@ -75,7 +76,8 @@ class Params {
optional_field_accessors_(false),
use_reference_types_for_primitives_(false),
generate_equals_(false),
- ignore_services_(false) {
+ ignore_services_(false),
+ parcelable_messages_(false) {
}
const string& base_name() const {
@@ -204,6 +206,13 @@ class Params {
bool ignore_services() const {
return ignore_services_;
}
+
+ void set_parcelable_messages(bool value) {
+ parcelable_messages_ = value;
+ }
+ bool parcelable_messages() const {
+ return parcelable_messages_;
+ }
};
} // namespace javanano