Commit Graph

25 Commits

Author SHA1 Message Date
Juan Silveira
79f19eb9f1 Keep pointers to extension values.
The current implementation of getExtension deserialises the field from bytes
and returns a new object every time. This means that changes to those objects
are reflected when the messages is serialised unless setExtension is called. It
also means that every call to getExtension and setExtension is expensive.

This change introduces a FieldData class that contains everything that's known
about the field at the time. This can be all the tag/byte[] pairs associated
with a given field or an Extension and a value object. This is so that two
messages with a repeated extension can be compared even if the extension
has been deserialised in one of them but not the other.

This change also adds FieldArray class based on SparseArray from the Android
compatibility library. This is used in ExtendableMessageNano to make lookup
of FieldDatas by their field number faster.

Implications:
* calling getExtension multiple times deserialises the field only once and
  returns the same object.
* calling setExtension doesn't cause the object to be serialised immediately,
  that only happens when the container message is serialised.
* getExtension is no longer a read-only thread-safe operation. README.txt has
  been updated to relfect that.
* comparison using equals and hashCode continues to work.

Bug: 10863158

Change-Id: I81c7cb0c73cc0611a1f7c1eabf5eed259738e8bc
2014-07-14 16:54:28 +01:00
Jeff Davidson
ec4b1ce0b6 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
2014-04-25 14:34:55 -07:00
Jie Dai
d9425a6218 Adds --ignore_service nano proto compiler flag
Nano proto compiler normally throws an error if any service is
defined. If --ignore-services=true is set, no error is thrown and the
service is simply skipped.

Change-Id: Id82583555085cc55550d03a485d3f0189885240b
2014-04-23 09:27:07 -07:00
Dave Hawkey
598087ef53 Don't reset cachedSize to 0 in getSerializedSize
This avoids a race-condition when cachedSize is momentarily set to 0
for non-empty messages if multiple threads call getSerializedSize
(e.g. during serialization).

This is a retry of https://android-review.googlesource.com/#/c/88570/.
getSerializedSize() has been kept non-final so that messages generated
with a previous version of the compiler will not break.

Change-Id: I8d8154a10938cde579ae19c55eae55b1e70e0bda
2014-04-10 08:21:44 -06:00
Wink Saville
b7dd7d9294 Revert "Don't reset cachedSize to 0 in getSerializedSize"
This reverts commit c6e12c6702ca764486f952654ba1568f00efe813.
2014-03-21 18:05:10 -07:00
Dave Hawkey
5090f19ea7 Don't reset cachedSize to 0 in getSerializedSize
This avoids a race-condition when cachedSize is momentarily set to 0
for non-empty messages if multiple threads call getSerializedSize
(e.g. during serialization).

Change-Id: I15a8ded92edbf41bf1c8d787960c5bbbc8a323c5
2014-03-21 09:27:23 -06:00
Max Cai
e005be6554 Add validation when parsing enum fields.
Invalid values from the wire are silently ignored.
Unlike full/lite, the invalid values are not stored into the
unknown fields, because there's no way to get them out from
Nano's unknown fields without a matching Extension.

Edited README and slightly moved it towards a standalone
section for Nano, independent of the Micro section.

Change-Id: I2c1eb07f4d6d8f3aea242b8ddd95b9c966f3f177
2014-01-16 12:41:15 +00:00
Max Cai
bc8eec3d2b Allow whitespace in nano codegen options.
So we don't need to keep all option in a single line in the .mk files.

Change-Id: I786b879b334cac4cd13b32fabcb76efe53b4ac80
2014-01-14 15:03:05 +00:00
Andrew Flynn
c997c136bb Nano: don't generate accessor methods for nested methods
For nested message objects, don't generate accessor methods because they have
a default value that is not a valid value (null), so there is no reason to have
get/set/has/clear methods for them. Clients and protos (while serializing) can
check against the invalid value to see if it's been set.

Change-Id: Ic63400889581271b8cbcd9c45c84519d4921fd4b
2013-12-09 11:40:03 -08:00
Max Cai
adf2449a6d Align with main: two ways of parsing repeated packable fields.
It is a requirement for parsing code to handle packed and unpacked
forms on the wire for repeated packable fields. This change aligns
the javanano's behavior with the java's.

Bonus: optimize array length calculation when parsing repeated
fixed-size-element-type fields.

Bonus 2: lose "xMemoizedSerializedSize" for repeated enum fields,
and make the serialized size calculation match that for repeated
int32 fields.

Change-Id: I8a06103d9290234adb46b0971b5ed155544fe86a
2013-11-18 11:47:25 +00:00
Max Cai
8c65bb7c50 Add missing README parts for enum_style and in-repo usage
Change-Id: I7934a5b0444017aeda787501ebf8d9f9ba295c73
2013-10-10 16:09:48 +01:00
Brian Duff
10107cbc7a Add reftypes field generator option.
This option generates fields as reference types, and serializes
based on nullness.

Change-Id: Ic32e0eebff59d14016cc9a19e15a9bb08ae0bba5
Signed-off-by: Brian Duff <bduff@google.com>
2013-10-07 16:25:55 -07:00
Max Cai
1479c7ab1b Implement enum_style=java option.
This javanano_out command line option creates a container interface
at the normal place where the enum constants would reside, per enum
definition. The java_multiple_files flag would now affect the file-
scope enums with the shells. If the flag is true then file-scope
container interfaces are created in their own files.

Change-Id: Id52258fcff8d3dee9db8f3d8022147a811bf3565
2013-09-25 19:44:27 +01:00
Max Cai
b337f25628 Accessor style for optional fields.
This CL implements the 'optional_field_style=accessors' option.
All optional fields will now be 1 Java field and 1 bit in a shared
bitfield behind get/set/has/clear accessor methods. The setter
performs null check for reference types (Strings and byte[]s).

Also decentralized the clear code generation.

Change-Id: I60ac78329e352e76c2f8139fba1f292383080ad3
2013-09-23 15:27:13 +01:00
Max Cai
06eed37ec6 Fix outer classname for javamicro/javanano.
- File class name is defined as the java_outer_classname option value
  or the file name ToCamelCase; never the single message's ClassName.
- File-scope enums are translated to constants in the file class,
  regardless of java_multiple_files.
- If java_multiple_files=true, and file's class name equals a message's
  class name, no error. This is done by detecting that the outer class
  is not needed and skipping the outer class codegen and clash checks.
  Note: there is a disparity between java[lite] and the previous
  java{micr|nan}o: when generating code for a single-message proto, the
  outer class is omitted by java{micr|nan}o if the file does not have
  java_outer_classname. This change makes java{micr|nan}o align with
  java[lite] codegen and create the outer class, but will print some
  info to warn of potential change of code.
- Also fixed the "is_own_file" detection and made all parseX() methods
  static. Previously, all messages in a java_multiple_files=true file
  are (incorrectly) considered to be in their own files, including
  nested messages, causing them to become inner classes (instance-
  bound) and forcing the parseX() methods to lose the static modifier.
- This change supersedes c/60164 and c/60086, which causes javanano to
  put enum values into enum shell classes if java_multiple_files=true.
  We now always use the parent class to host the enum values. A future
  change will add a command line option to provide more flexibility.
- Elaborated in java/README.txt.

Change-Id: I684932f90e0a028ef37c662b221def5ffa202439
2013-08-05 21:54:58 +01:00
Ulas Kirazci
e83bbbbe42 Add an option to inspect "has" state upon parse.
If has is set, also always serialize.

Change-Id: I2c8450f7ab9e837d722123dd1042991c0258ede3
2013-07-29 09:35:44 -07:00
Ulas Kirazci
2000cfdc2a Add test for passing in proto params.
Depends on Ia532647fe8811d39230a23ba3671685b0388cbe0

Change-Id: I0ba3ce3561aff31e246968a79b1d1053dec91d49
2013-07-25 12:53:36 -07:00
Ulas Kirazci
39799d09f1 Add contribution instructions for nano.
Change-Id: Ie110d182a84258ab5bb3ba1f67c6ada6be476c7e
2013-07-19 11:57:35 -07:00
Matt Thrailkill
adf95183f6 Fix typos in protobuf readme.
Change-Id: Ifa3c8674482ae9575df459a3e76e9f8b4a9296b5
Signed-off-by: Matt Thrailkill <mthrailkill@google.com>
2013-04-26 16:08:53 -07:00
Ulas Kirazci
2337023fd9 Nano protobufs.
Like micro protobufs except:

- No setter/getter/hazzer functions.
- Has state is not available. Outputs all fields != their default.
- CodedInputStream can only take byte[] (not InputStream).
- Repeated fields are in arrays, not ArrayList or Vector.
- Unset messages/groups are null, not "defaultInstance()".
- Required fields are always serialized.

To use:

- Link libprotobuf-java-2.3.0-nano runtime.
- Use LOCAL_PROTOC_OPTIMIZE_TYPE := nano

Change-Id: I7429015b3c5f7f38b7be01eb2d4927f7a9999c80
2013-04-01 14:55:45 -07:00
Wink Saville
b164b01203 Remove vestigial references to StringUtf8Micro.
Change-Id: Ica75231b03de4768c671bf046b92bd7630ecd5c8
2010-10-06 10:00:08 -07:00
Wink Saville
ce7a2b0149 Add support for Java micro protobuf's to protobuf-2.3.0.
See README.android for additional information.

Change-Id: I6693e405c0d651eacacd3227a876129865dd0d3c
2010-05-29 13:13:38 -07:00
Wink Saville
5ab6e29684 Add protobuf 2.3.0 sources
This is the contents of protobuf-2.3.0.tar.bz2 from
http://code.google.com/p/protobuf/downloads/list.

Change-Id: Idfde09ce7ef5ac027b07ee83f2674fbbed5c30b2
2010-05-29 13:00:38 -07:00
Wink Saville
e5566f8673 Add support for Java micro protobuf's to protobuf-2.2.0a.
See README.android for additional information.

Change-Id: I9c5ef2eec484cc87e32841f39060f8f27b8e8472
2010-05-28 11:49:52 -07:00
Wink Saville
3df2fda0e4 Add protobuf 2.2.0a sources
This is the contents of protobuf-2.2.0a.tar.bz2 from
http://code.google.com/p/protobuf/downloads/list and
is the base code for the javamicro code generator.

Change-Id: Ie9a0440a824d615086445b6636944484b3155afa
2010-05-27 16:25:37 -07:00