diff options
author | Jeff Davidson <jpd@google.com> | 2014-04-22 23:25:53 -0700 |
---|---|---|
committer | Jeff Davidson <jpd@google.com> | 2014-04-25 14:34:55 -0700 |
commit | 721ea491a8e3e9ea5a130965dc5761fc335c3e61 (patch) | |
tree | 195940ae75bbcb5b64f644c5ecfc4074eef34486 /src/google | |
parent | 829f6c014ce69d04593d30652c8acc2f7a793851 (diff) | |
download | external_protobuf-721ea491a8e3e9ea5a130965dc5761fc335c3e61.zip external_protobuf-721ea491a8e3e9ea5a130965dc5761fc335c3e61.tar.gz external_protobuf-721ea491a8e3e9ea5a130965dc5761fc335c3e61.tar.bz2 |
Support generation of Parcelable nano messages.
This CL adds the "parcelable_messages" option. When enabled, all
generated message classes will conform to the Android Parcelable
contract. This is achieved by introducing a new parent class for
generated classes which implements the required functionality.
Since the store_unknown_fields option also makes use of a superclass,
ExtendableMessageNano, we have two versions of the new Parcelable
superclass: one extending MessageNano, and one extending
ExtendableMessageNano. These classes are otherwise identical.
As these classes depend on Android framework jars, they are not
included in the host .jar build of the nanoproto library.
Finally, add a test suite for running tests of Android-specific
functionality, as this cannot be done on a desktop JVM.
Change-Id: Icc2a257f03317e947f7078dbb9857c3286857497
Diffstat (limited to 'src/google')
3 files changed, 20 insertions, 2 deletions
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 |