Commit Graph

207 Commits

Author SHA1 Message Date
Max Cai
f1019531a6 Merge "Adds --ignore_service nano proto compiler flag" 2014-04-24 18:51:56 +00: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
Max Cai
56cba8eeae Merge "Don't reset cachedSize to 0 in getSerializedSize" 2014-04-14 14:57:54 +00: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
dc2ab87569 Merge "Revert "Don't reset cachedSize to 0 in getSerializedSize"" 2014-03-22 01:09:34 +00: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
Wink Saville
ddc98d6dd0 Merge "Don't reset cachedSize to 0 in getSerializedSize" 2014-03-21 17:08:31 +00: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
3a2109246f Merge "Extension overhaul." 2014-02-17 15:28:08 +00:00
Max Cai
a2d72a5853 Merge changes I9fecff3c,I2c1eb07f
* changes:
  Fix repeated packed field merging code for non-packed data.
  Add validation when parsing enum fields.
2014-02-10 14:04:23 +00:00
Max Cai
74959d4796 Fix repeated packed field merging code for non-packed data.
Enum fix is already included in the previous commit.

Bug: https://code.google.com/p/android/issues/detail?id=64893
Change-Id: I9fecff3c8822918a019028eb57fa39b361a2c960
2014-01-16 12:41:26 +00: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
a793c09b6f Merge "Allow whitespace in nano codegen options." 2014-01-14 18:08:45 +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
Max Cai
0eecf0b83f Merge "Correctness: floating point equality using bits instead of ==." 2014-01-13 13:20:00 +00:00
Max Cai
2fb3cdf9bb Merge "Don't serialize required fields whose 'has' flags are unset." 2014-01-13 13:19:56 +00:00
Max Cai
79b311c163 Correctness: floating point equality using bits instead of ==.
Special values for float and double make it inaccurate to test the equality with ==.
The main Java library uses the standard Object.equals() implementation for all fields,
which for floating point fields means Float.equals() or Double.equals(). They define
equality as bitwise equality, with all NaN representations normalized to the same bit
sequence (and therefore equal to each other). This test checks that the nano
implementation complies with Object.equals(), so NaN == NaN and +0.0 != -0.0.

Change-Id: I97bb4a3687223d8a212c70cd736436b9dd80c1d7
2014-01-10 18:11:07 +00:00
Max Cai
1b1735ceb1 Don't serialize required fields whose 'has' flags are unset.
Change-Id: Ibbe944fff83e44a8f2206e18ee9ec6f10661297a
2014-01-10 14:43:32 +00:00
Max Cai
e3714f0001 Extension overhaul.
- Get rid of TypeLiteral<T>. It was introduced to read the component
  type of a List<T> at runtime. But we use arrays everywhere else,
  and we can always read the component type of an array type at
  runtime.
- Properly read/write "minor" types (e.g. sint32, sfixed32). The old
  implementation could only read/write data as the "typical" types
  (one per Java type), e.g. java.lang.Integer -> int32, java.lang.Long
  -> int64. So if e.g. an extension specifies sfixed32 as the type, it
  would be read/written in the totally incompatible int32 format.
- Properly serialize repeated packed fields. The old implementation
  doesn't do packed serialization. As an added bonus, and to be more
  aligned with the rest of protobuf nano / main, repeated packable
  extensions can deserialize both packed and non-packed data.
- Split Extension class into a hierarchy so under typical usage a
  large chunk of code dealing with primitive type extensions can be
  removed by ProGuard.

Bug: https://code.google.com/p/android/issues/detail?id=62586
Change-Id: I0d692f35cc2a8ad3a5a1cb3ce001282b2356b041
2014-01-10 11:50:32 +00:00
Andrew Flynn
0c0f8c7ef0 Merge "Fix MessageNanoPrinter for accessors" 2013-12-19 19:19:33 +00:00
Andrew Flynn
02a9ea00d1 Fix MessageNanoPrinter for accessors
accessors mode switches proto fields away from being public fields (which is
how MessageNanoPrinter found which fields to print via reflection). Add a
pass through the methods looking for generated accessor methods to print
those as well.

Change-Id: I7c47853ecbd5534086f44b25a89dbbe56f63ed03
2013-12-12 09:43:55 -08:00
Max Cai
b3bc6095b2 Merge "Avoid class initializers to help ProGuard." 2013-12-10 18:33:40 +00:00
Max Cai
04feb76f94 Avoid class initializers to help ProGuard.
Class initializers prevent ProGuard from inlining any methods
because it thinks the class initializer may have side effects.
This is true for static methods, but instance methods can still
be inlined, because to have an instance you will have touched
the class and any class initializers would have run. But
ProGuard only starts inlining instance methods of classes with
class initializers from v4.11b6, and Android uses v4.4 now.

This change tries to avoid the class initializers as much as
possible, by delaying the initialization of the empty array and
some fields' saved defaults until when they're needed. However,
if the message hosts any extensions, they must be public static
final and therefore introducing the class initializer. In that
case we won't bother with lazy initialization.

Change-Id: I00d8296f6eb0023112b93ee135cdb28dbd52b0b8
2013-12-10 16:46:22 +00:00
Max Cai
482bf5245d Merge "Nano: don't generate accessor methods for nested methods" 2013-12-10 12:56:23 +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
The Android Open Source Project
cb64a63f0b Merge commit '0afd5a4d782037ea641d75d595cf5d38ed6978ac' into HEAD 2013-12-05 12:38:12 -08:00
The Android Open Source Project
2d2557ea70 Merge commit '7cb6b37f3799affce9e1be39977d4419283df795' into HEAD 2013-11-22 10:35:14 -08:00
Max Cai
7c6ab9ac93 Merge "Align with main: two ways of parsing repeated packable fields." 2013-11-18 12:52:46 +00: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
5bafef2a49 am 3e0d99fa: Merge "Update MessageNano#toString() to return mostly valid TextFormat."
* commit '3e0d99fab8c1da2a8f36637b7bf5e8581143e36a':
  Update MessageNano#toString() to return mostly valid TextFormat.
2013-11-15 09:41:58 -08:00
Max Cai
190edd7ef6 Merge "Update MessageNano#toString() to return mostly valid TextFormat." 2013-11-15 17:15:55 +00:00
Nicholas Seckar
904c81ee97 Update MessageNano#toString() to return mostly valid TextFormat.
The output of toString is now aligned with that used by non-nano and C++
runtimes, with the exception of groups. Groups should be serialized using a
camelized name (e.g. "FooBar" rather than "foo_bar") however the nano runtime
does not have information on which fields are groups.

Changes are:
  - bytes fields are output within double-quotes, non-printable characters are
    output as octal escape sequences (i.e. \NNN);
  - field identifiers are output in underscored format;
  - unset fields are not output (rather than printing "null");
  - the type name of the root message is not output.

With these changes the nano toString, normal toString, and C++'s DebugString all
produce equivalent output when given the same message. (Provided that message
uses no deprecated features.)

Change-Id: Id4791d73822846db29344db9f7bc3781c3e183a6
2013-11-15 07:54:07 -08:00
Max Cai
52b74c5290 am 332076f0: Merge "Fix warnings warnings in header files, hide others."
* commit '332076f08a9d46b772fee755832a0e09dd8cb6aa':
  Fix warnings warnings in header files, hide others.
2013-11-15 07:07:25 -08:00
Max Cai
558af24207 Merge "Fix warnings warnings in header files, hide others." 2013-11-15 14:29:36 +00:00
Kristian Monsen
eee1dd7bbf Fix warnings warnings in header files, hide others.
Follow upstream where they have any changes in 2.5.0

Change-Id: I3466e9c11242f533a9dff8c1afef4202dd100f2e
2013-11-13 12:06:41 -08:00
Max Cai
1bca0c0cb9 am ac8e2e15: Merge "Minimize method count for nanoproto."
* commit 'ac8e2e150716784a707587ae6e2c8b3a291a2ae7':
  Minimize method count for nanoproto.
2013-11-12 09:15:57 -08:00
Max Cai
335140f28a Merge "Minimize method count for nanoproto." 2013-11-12 17:02:56 +00:00
Tom Chao
28b4dec79b Minimize method count for nanoproto.
- Migrates getCachedSize to the MessageNano parent class to save one method per message.
- Create ExtendableMessageNano parent class for protos with extensions, this saves the
getExtension and setExtension methods on the relevant messages.
- getSerializedSize's default case (with no fields to serialize) also migrate to the
parent class, which saves methods on empty messages.
- Container classes become interfaces to save the constructor.

Change-Id: I81f1a1b6d6a660096835e9df3ea20456655aab4a
2013-11-11 11:22:02 -08:00
Max Cai
a2b27908ce am 8a15121c: Merge "Allow for ref-type arrays containing null elements."
* commit '8a15121c1077fe883f428bd27dee6b99e06e48b6':
  Allow for ref-type arrays containing null elements.
2013-11-06 16:10:08 -08:00
Max Cai
874d66c06a Merge "Allow for ref-type arrays containing null elements." 2013-11-06 17:35:07 +00:00
Aurash Mahbod
3f0c348033 Allow for ref-type arrays containing null elements.
Strip the null elements out before serializing the array.
This is helpful in the cases where the user wants to construct
an array of an inexact size for serialization. For example:
User constructs array of size 5 because they anticipate adding
more than 1 element before serialization. Only 3 get added, so
the array looks like [Obj, Obj, Obj, null, null]. This would
curently crash without this CL.

All repeated fields of ref-type elements can contain null
elements: repeated strings, repeated bytes, and repeated
messages/groups.

Change-Id: I117391c868c9a436536d70d6151780e9cc7e8227

Conflicts:
	src/google/protobuf/compiler/javanano/javanano_message_field.cc
2013-11-05 18:17:06 +00:00
Max Cai
500fbc548f am bb971d53: Merge "Implement hashCode() and equals() behind a generator option."
* commit 'bb971d53626cb286f8dc491c15d2731001c4891b':
  Implement hashCode() and equals() behind a generator option.
2013-10-25 14:13:04 -07:00
Max Cai
885f959b77 Merge "Implement hashCode() and equals() behind a generator option." 2013-10-25 21:09:15 +00:00
Brian Duff
56a37328ae Implement hashCode() and equals() behind a generator option.
The option is only called 'generate_equals' because:
- equals() is the main thing; hashCode() is there only to
  complement equals();
- it's shorter;
- toString() should not be included in this option because
  it's more for debugging and it's more likely to stop
  ProGuard from working well.

Also shortened the "has bit" expression; was
((bitField & mask) == mask), now ((bitField & mask) != 0).
Both the Java code and the bytecode are slightly shorter.

Change-Id: Ic309a08a60883bf454eb6612679aa99611620e76
2013-10-25 16:06:21 +01:00
Max Cai
6404b4fda5 am 42be1e79: Merge "Feature request: set() and clear() accessors return this"
* commit '42be1e79ccd670be36220222936aa7cacc6856f6':
  Feature request: set() and clear() accessors return this
2013-10-16 11:06:44 -07:00
Max Cai
461d4ac87a Merge "Feature request: set() and clear() accessors return this" 2013-10-16 18:02:22 +00:00
Max Cai
fba329d6d5 Feature request: set() and clear() accessors return this
Also pre-inlines set() and has() in serialization code. This could
theoretically help ProGuard: the message class size is usually large,
and because of this only, it may refuse to inline an accessor into
the serialization code, and as a result keeps the accessor intact.
Chances are, after pre-inlining all accessor calls within the message
class, those accessors become unused or single-use, so there are more
reasons for ProGuard to inline and then remove them.

Change-Id: I57decbe0b2533c1be21439de0aad15f49c7024dd
2013-10-16 16:28:03 +01:00
Max Cai
e69fae738b am c50f605c: Merge "Make generated code more aligned with Google Java style."
* commit 'c50f605c572a425b2fa696fedc5e61ac6f66d2a9':
  Make generated code more aligned with Google Java style.
2013-10-16 08:16:19 -07:00
Max Cai
1004093828 Merge "Make generated code more aligned with Google Java style." 2013-10-16 15:11:27 +00:00
Max Cai
9a93c5f593 Make generated code more aligned with Google Java style.
- Blank line after opening a message class (but not an enum interface).
- Let all code blocks insert blank lines before themselves. This applies to
  'package' statement, all message classes, enum classes or constant groups,
  extensions, bitfields, proto fields (one block per field; i.e. accessors
  don't have blank lines among them), and basic MessageNano methods. In this
  case we don't need to guess what the next block is and create blank lines
  for it.
- Fixed some newline/indent errors.
- Only one SuppressWarnings("hiding") per file.

Change-Id: I865f52ad4fb6ea3b3a98b97ac9d78d19fc46c858
2013-10-16 12:44:35 +01:00