Commit Graph

190 Commits

Author SHA1 Message Date
Max Cai
2fb3cdf9bb Merge "Don't serialize required fields whose 'has' flags are unset." 2014-01-13 13:19:56 +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
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
Max Cai
9d3016b821 am afaf74ce: Merge "Fix repeated field merging semantics."
* commit 'afaf74ce55f4aff63dc30e7045a7cd6c1cf232dc':
  Fix repeated field merging semantics.
2013-10-16 03:17:13 -07:00
Max Cai
665d99f4bc Merge "Fix repeated field merging semantics." 2013-10-16 10:12:58 +00:00
Max Cai
cd3c68b255 Fix repeated field merging semantics.
The public doc states that repeated fields are simply concatenated
and doesn't impose a different semantics for packed fields. This
CL fixes this for packed fields and adds tests covering all cases.

Also fixed a bit of missed null-repeated-field treatments.

Change-Id: Ie35277bb1a9f0b8171dc9d07b6adf9b9d3308de2
2013-10-15 18:11:56 +01:00
Max Cai
6beadab124 am 63e819ad: Merge "Protect against null repeated fields."
* commit '63e819adbb4d2d8215f5d3d8297dc50bf2fe3329':
  Protect against null repeated fields.
2013-10-15 08:47:51 -07:00
Max Cai
80dcae757e Merge "Protect against null repeated fields." 2013-10-15 15:41:53 +00:00
Max Cai
bb2a648d77 am c85806ba: Merge remote-tracking branch \'goog/klp-dev-plus-aosp\' into tomerge
* commit 'c85806baedfc98ad5759a990b35ea5b5f1ac4edb':
2013-10-15 08:38:10 -07:00
Brian Duff
34547de99c Protect against null repeated fields.
There's no distinction between a repeated field being null and being
empty. In both cases, nothing is sent on the wire. Clients might for
whatever reason inadvertently set a repeated field to null, so
protect against that and treat it just as if the field was empty.

Change-Id: Ic3846f7f2189d6cfff6f8ef3ca217daecc3c8be7
2013-10-14 23:14:58 -07:00
Max Cai
a142dc2c7a am 39cee9f1: Merge "Remove all field initializers and let ctor call clear()."
* commit '39cee9f1f5cd513a53ac5100eb208ed431f99af0':
  Remove all field initializers and let ctor call clear().
2013-10-11 13:39:49 -07:00
Max Cai
f18868306f Merge "Remove all field initializers and let ctor call clear()." 2013-10-11 20:36:01 +00:00
Max Cai
39b3008709 Merge remote-tracking branch 'goog/klp-dev-plus-aosp' into tomerge 2013-10-11 17:14:08 +01:00
Max Cai
0652d70174 Remove all field initializers and let ctor call clear().
The field initializers have basically caused the compiled <init> method
to inline the whole clear() method, which means if ProGuard is not used
or failed to inline or remove clear(), there are two big chunks of code
that do the same thing. So why not just call clear() from the ctor.

Change-Id: Ief71e2b03db2e059b3bfa98309649368089ffab0
2013-10-11 16:44:40 +01:00
Ulas Kirazci
941bc6e8f1 am cbb08132: Merge "Add missing README parts for enum_style and in-repo usage"
* commit 'cbb08132821cb56f4e6c5e5f8a0b32f51879782a':
  Add missing README parts for enum_style and in-repo usage
2013-10-10 10:40:04 -07:00
Ulas Kirazci
3289fe1a86 Merge "Add missing README parts for enum_style and in-repo usage" 2013-10-10 17:12:16 +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
Ulas Kirazci
15d23f93ae am c4a1b547: Merge "Add reftypes field generator option."
* commit 'c4a1b547c91178d79f5d2cc2e00b8be922c22fe8':
  Add reftypes field generator option.
2013-10-09 10:56:13 -07:00
Ulas Kirazci
2b51f83a83 Merge "Add reftypes field generator option." 2013-10-09 17:51:07 +00:00
Wink Saville
19e465df3d am 44cbb06c: Merge "Fix some indenting issues with set__() function"
* commit '44cbb06c725fbba00464bba9f19dc0ea295406b1':
  Fix some indenting issues with set__() function
2013-10-09 08:59:38 -07:00