summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Davidson <jpd@google.com>2015-04-06 16:29:19 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2015-04-06 16:29:20 +0000
commitff882b4094995bc7dd9b183951cf84aa04527361 (patch)
treef8b252def86c4bd71be3454b2542f72b9cd2a416
parent00c7607ce445af504021447068d6237ba8100716 (diff)
parentbae6b59812ac972c9792605d521d6ada069288b2 (diff)
downloadexternal_protobuf-gradle_1.2.1.zip
external_protobuf-gradle_1.2.1.tar.gz
external_protobuf-gradle_1.2.1.tar.bz2
Merge "Generate a CREATOR for each Parcelable message."gradle_1.2.1gradle_1.2.0-rc1gradle_1.2.0android-wear-5.1.1_r1android-wear-5.1.0_r1
-rw-r--r--java/src/device/main/java/com/google/protobuf/nano/android/ParcelableExtendableMessageNano.java17
-rw-r--r--java/src/device/main/java/com/google/protobuf/nano/android/ParcelableMessageNano.java17
-rw-r--r--java/src/device/main/java/com/google/protobuf/nano/android/ParcelableMessageNanoCreator.java (renamed from java/src/device/main/java/com/google/protobuf/nano/android/ParcelingUtil.java)25
-rw-r--r--src/google/protobuf/compiler/javanano/javanano_message.cc11
4 files changed, 34 insertions, 36 deletions
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
index f3b82ed..739ff18 100644
--- 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
@@ -42,21 +42,6 @@ import com.google.protobuf.nano.ExtendableMessageNano;
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;
@@ -64,6 +49,6 @@ public abstract class ParcelableExtendableMessageNano<M extends ExtendableMessag
@Override
public void writeToParcel(Parcel out, int flags) {
- ParcelingUtil.writeToParcel(getClass(), this, out);
+ ParcelableMessageNanoCreator.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
index b07f1d6..83f973d 100644
--- 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
@@ -40,21 +40,6 @@ import com.google.protobuf.nano.MessageNano;
*/
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;
@@ -62,6 +47,6 @@ public abstract class ParcelableMessageNano extends MessageNano implements Parce
@Override
public void writeToParcel(Parcel out, int flags) {
- ParcelingUtil.writeToParcel(getClass(), this, out);
+ ParcelableMessageNanoCreator.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/ParcelableMessageNanoCreator.java
index 1eb84ee..5a4b70c 100644
--- a/java/src/device/main/java/com/google/protobuf/nano/android/ParcelingUtil.java
+++ b/java/src/device/main/java/com/google/protobuf/nano/android/ParcelableMessageNanoCreator.java
@@ -1,5 +1,5 @@
// Protocol Buffers - Google's data interchange format
-// Copyright 2014 Google Inc. All rights reserved.
+// Copyright 2015 Google Inc. All rights reserved.
// http://code.google.com/p/protobuf/
//
// Redistribution and use in source and binary forms, with or without
@@ -31,16 +31,27 @@
package com.google.protobuf.nano.android;
import android.os.Parcel;
+import android.os.Parcelable;
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";
+import java.lang.reflect.Array;
+
+public final class ParcelableMessageNanoCreator<T extends MessageNano>
+ implements Parcelable.Creator<T> {
+ private static final String TAG = "PMNCreator";
+
+ private final Class<T> mClazz;
+
+ public ParcelableMessageNanoCreator(Class<T> clazz) {
+ mClazz = clazz;
+ }
@SuppressWarnings("unchecked")
- static <T extends MessageNano> T createFromParcel(Parcel in) {
+ @Override
+ public T createFromParcel(Parcel in) {
String className = in.readString();
byte[] data = in.createByteArray();
@@ -64,6 +75,12 @@ final class ParcelingUtil {
return proto;
}
+ @SuppressWarnings("unchecked")
+ @Override
+ public T[] newArray(int i) {
+ return (T[]) Array.newInstance(mClazz, i);
+ }
+
static <T extends MessageNano> void writeToParcel(Class<T> clazz, MessageNano message,
Parcel out) {
out.writeString(clazz.getName());
diff --git a/src/google/protobuf/compiler/javanano/javanano_message.cc b/src/google/protobuf/compiler/javanano/javanano_message.cc
index 4026031..758c9e8 100644
--- a/src/google/protobuf/compiler/javanano/javanano_message.cc
+++ b/src/google/protobuf/compiler/javanano/javanano_message.cc
@@ -154,6 +154,17 @@ void MessageGenerator::Generate(io::Printer* printer) {
}
printer->Indent();
+ if (params_.parcelable_messages()) {
+ printer->Print(
+ "\n"
+ "// Used by Parcelable\n"
+ "@SuppressWarnings({\"unused\"})\n"
+ "public static final android.os.Parcelable.Creator<$classname$> CREATOR =\n"
+ " new com.google.protobuf.nano.android.ParcelableMessageNanoCreator<\n"
+ " $classname$>($classname$.class);\n",
+ "classname", descriptor_->name());
+ }
+
// Nested types and extensions
for (int i = 0; i < descriptor_->extension_count(); i++) {
ExtensionGenerator(descriptor_->extension(i), params_).Generate(printer);