Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
c72d3d51
Commit
c72d3d51
authored
Feb 18, 2015
by
Jisi Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Oneof message level elements (consts, case getter/clear) and messsage type field oneof support.
parent
7794a98f
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
106 additions
and
18 deletions
+106
-18
unittest_nano.proto
...rc/test/java/com/google/protobuf/nano/unittest_nano.proto
+1
-1
javanano_field.cc
src/google/protobuf/compiler/javanano/javanano_field.cc
+5
-3
javanano_message.cc
src/google/protobuf/compiler/javanano/javanano_message.cc
+24
-4
javanano_message_field.cc
...ogle/protobuf/compiler/javanano/javanano_message_field.cc
+63
-0
javanano_message_field.h
...oogle/protobuf/compiler/javanano/javanano_message_field.h
+8
-0
javanano_primitive_field.cc
...le/protobuf/compiler/javanano/javanano_primitive_field.cc
+5
-10
No files found.
javanano/src/test/java/com/google/protobuf/nano/unittest_nano.proto
View file @
c72d3d51
...
...
@@ -170,7 +170,7 @@ message TestAllTypesNano {
oneof
oneof_field
{
uint32
oneof_uint32
=
111
;
//
NestedMessage oneof_nested_message = 112;
NestedMessage
oneof_nested_message
=
112
;
// string oneof_string = 123;
// bytes oneof_bytes = 124;
fixed64
oneof_fixed64
=
115
;
...
...
src/google/protobuf/compiler/javanano/javanano_field.cc
View file @
c72d3d51
...
...
@@ -159,11 +159,13 @@ void SetCommonOneofVariables(const FieldDescriptor* descriptor,
(
*
variables
)[
"oneof_index"
]
=
SimpleItoa
(
descriptor
->
containing_oneof
()
->
index
());
(
*
variables
)[
"set_oneof_case"
]
=
(
*
variables
)[
"oneof_name"
]
+
"Case_ = "
+
SimpleItoa
(
descriptor
->
number
());
"this."
+
(
*
variables
)[
"oneof_name"
]
+
"Case_ = "
+
SimpleItoa
(
descriptor
->
number
());
(
*
variables
)[
"clear_oneof_case"
]
=
(
*
variables
)[
"oneof_name"
]
+
"Case_ = 0"
;
"this."
+
(
*
variables
)[
"oneof_name"
]
+
"Case_ = 0"
;
(
*
variables
)[
"has_oneof_case"
]
=
(
*
variables
)[
"oneof_name"
]
+
"Case_ == "
+
SimpleItoa
(
descriptor
->
number
());
"this."
+
(
*
variables
)[
"oneof_name"
]
+
"Case_ == "
+
SimpleItoa
(
descriptor
->
number
());
}
}
// namespace javanano
...
...
src/google/protobuf/compiler/javanano/javanano_message.cc
View file @
c72d3d51
...
...
@@ -167,16 +167,36 @@ void MessageGenerator::Generate(io::Printer* printer) {
// oneof
map
<
string
,
string
>
vars
;
vars
[
"message_name"
]
=
descriptor_
->
name
();
for
(
int
i
=
0
;
i
<
descriptor_
->
oneof_decl_count
();
i
++
)
{
vars
[
"oneof_name"
]
=
UnderscoresToCamelCase
(
descriptor_
->
oneof_decl
(
i
));
const
OneofDescriptor
*
oneof_desc
=
descriptor_
->
oneof_decl
(
i
);
vars
[
"oneof_name"
]
=
UnderscoresToCamelCase
(
oneof_desc
);
vars
[
"oneof_capitalized_name"
]
=
UnderscoresToCapitalizedCamelCase
(
descriptor_
->
oneof_decl
(
i
));
vars
[
"oneof_index"
]
=
SimpleItoa
(
descriptor_
->
oneof_decl
(
i
)
->
index
());
UnderscoresToCapitalizedCamelCase
(
oneof_desc
);
vars
[
"oneof_index"
]
=
SimpleItoa
(
oneof_desc
->
index
());
// Oneof Constants
for
(
int
j
=
0
;
j
<
oneof_desc
->
field_count
();
j
++
)
{
const
FieldDescriptor
*
field
=
oneof_desc
->
field
(
j
);
vars
[
"number"
]
=
SimpleItoa
(
field
->
number
());
vars
[
"cap_field_name"
]
=
ToUpper
(
field
->
name
());
printer
->
Print
(
vars
,
"public static final int $cap_field_name$_FIELD_NUMBER = $number$;
\n
"
);
}
// oneofCase_ and oneof_
printer
->
Print
(
vars
,
"private int $oneof_name$Case_ = 0;
\n
"
"private java.lang.Object $oneof_name$_;
\n
"
);
// OneofCase enum
printer
->
Print
(
vars
,
"public int get$oneof_capitalized_name$Case() {
\n
"
" return this.$oneof_name$Case_;
\n
"
"}
\n
"
);
// Oneof clear
printer
->
Print
(
vars
,
"public $message_name$ clear$oneof_capitalized_name$() {
\n
"
" this.$oneof_name$Case_ = 0;
\n
"
" this.$oneof_name$_ = null;
\n
"
" return this;
\n
"
"}
\n
"
);
}
// Lazy initialization of otherwise static final fields can help prevent the
...
...
src/google/protobuf/compiler/javanano/javanano_message_field.cc
View file @
c72d3d51
...
...
@@ -157,6 +157,69 @@ MessageOneofFieldGenerator::MessageOneofFieldGenerator(
MessageOneofFieldGenerator
::~
MessageOneofFieldGenerator
()
{}
void
MessageOneofFieldGenerator
::
GenerateMembers
(
io
::
Printer
*
printer
,
bool
/* unused lazy_init */
)
const
{
printer
->
Print
(
variables_
,
"public boolean has$capitalized_name$() {
\n
"
" return $has_oneof_case$;
\n
"
"}
\n
"
"public $type$ get$capitalized_name$() {
\n
"
" if ($has_oneof_case$) {
\n
"
" return ($type$) this.$oneof_name$_;
\n
"
" }
\n
"
" return null;
\n
"
"}
\n
"
"public $message_name$ set$capitalized_name$($type$ value) {
\n
"
" if (value == null) { throw new java.lang.NullPointerException(); }
\n
"
" $set_oneof_case$;
\n
"
" this.$oneof_name$_ = value;
\n
"
" return this;
\n
"
"}
\n
"
);
}
void
MessageOneofFieldGenerator
::
GenerateClearCode
(
io
::
Printer
*
printer
)
const
{
// No clear method for oneof fields.
}
void
MessageOneofFieldGenerator
::
GenerateMergingCode
(
io
::
Printer
*
printer
)
const
{
printer
->
Print
(
variables_
,
"if (!($has_oneof_case$)) {
\n
"
" this.$oneof_name$_ = new $type$();
\n
"
"}
\n
"
"input.readMessage(
\n
"
" (com.google.protobuf.nano.MessageNano) this.$oneof_name$_);
\n
"
"$set_oneof_case$;
\n
"
);
}
void
MessageOneofFieldGenerator
::
GenerateSerializationCode
(
io
::
Printer
*
printer
)
const
{
printer
->
Print
(
variables_
,
"if ($has_oneof_case$) {
\n
"
" output.writeMessage($number$,
\n
"
" (com.google.protobuf.nano.MessageNano) this.$oneof_name$_);
\n
"
"}
\n
"
);
}
void
MessageOneofFieldGenerator
::
GenerateSerializedSizeCode
(
io
::
Printer
*
printer
)
const
{
printer
->
Print
(
variables_
,
"if ($has_oneof_case$) {
\n
"
" size += com.google.protobuf.nano.CodedOutputByteBufferNano
\n
"
" .computeMessageSize($number$,
\n
"
" (com.google.protobuf.nano.MessageNano) this.$oneof_name$_);
\n
"
"}
\n
"
);
}
void
MessageOneofFieldGenerator
::
GenerateEqualsCode
(
io
::
Printer
*
printer
)
const
{
}
void
MessageOneofFieldGenerator
::
GenerateHashCodeCode
(
io
::
Printer
*
printer
)
const
{
}
// ===================================================================
RepeatedMessageFieldGenerator
::
RepeatedMessageFieldGenerator
(
...
...
src/google/protobuf/compiler/javanano/javanano_message_field.h
View file @
c72d3d51
...
...
@@ -73,6 +73,14 @@ class MessageOneofFieldGenerator : public FieldGenerator {
~
MessageOneofFieldGenerator
();
// implements FieldGenerator ---------------------------------------
void
GenerateMembers
(
io
::
Printer
*
printer
,
bool
lazy_init
)
const
;
void
GenerateClearCode
(
io
::
Printer
*
printer
)
const
;
void
GenerateMergingCode
(
io
::
Printer
*
printer
)
const
;
void
GenerateSerializationCode
(
io
::
Printer
*
printer
)
const
;
void
GenerateSerializedSizeCode
(
io
::
Printer
*
printer
)
const
;
void
GenerateEqualsCode
(
io
::
Printer
*
printer
)
const
;
void
GenerateHashCodeCode
(
io
::
Printer
*
printer
)
const
;
private
:
const
FieldDescriptor
*
descriptor_
;
map
<
string
,
string
>
variables_
;
...
...
src/google/protobuf/compiler/javanano/javanano_primitive_field.cc
View file @
c72d3d51
...
...
@@ -723,18 +723,13 @@ void PrimitiveOneofFieldGenerator::GenerateMembers(
"}
\n
"
"public $type$ get$capitalized_name$() {
\n
"
" if ($has_oneof_case$) {
\n
"
" return ($type$) ($boxed_type$) $oneof_name$_;
\n
"
" return ($type$) ($boxed_type$)
this.
$oneof_name$_;
\n
"
" }
\n
"
" return $default$;
\n
"
"}
\n
"
"public $message_name$ set$capitalized_name$($type$ value) {
\n
"
" $set_oneof_case$;
\n
"
" $oneof_name$_ = value;
\n
"
" return this;
\n
"
"}
\n
"
"public $message_name$ clear$capitalized_name$() {
\n
"
" $clear_oneof_case$;
\n
"
" $oneof_name$_ = null;
\n
"
" this.$oneof_name$_ = value;
\n
"
" return this;
\n
"
"}
\n
"
);
}
...
...
@@ -747,7 +742,7 @@ void PrimitiveOneofFieldGenerator::GenerateClearCode(
void
PrimitiveOneofFieldGenerator
::
GenerateMergingCode
(
io
::
Printer
*
printer
)
const
{
printer
->
Print
(
variables_
,
"$oneof_name$_ = input.read$capitalized_type$();
\n
"
"
this.
$oneof_name$_ = input.read$capitalized_type$();
\n
"
"$set_oneof_case$;
\n
"
);
}
...
...
@@ -756,7 +751,7 @@ void PrimitiveOneofFieldGenerator::GenerateSerializationCode(
printer
->
Print
(
variables_
,
"if ($has_oneof_case$) {
\n
"
" output.write$capitalized_type$(
\n
"
" $number$, ($boxed_type$) $oneof_name$_);
\n
"
" $number$, ($boxed_type$)
this.
$oneof_name$_);
\n
"
"}
\n
"
);
}
...
...
@@ -766,7 +761,7 @@ void PrimitiveOneofFieldGenerator::GenerateSerializedSizeCode(
"if ($has_oneof_case$) {
\n
"
" size += com.google.protobuf.nano.CodedOutputByteBufferNano
\n
"
" .compute$capitalized_type$Size(
\n
"
" $number$, ($boxed_type$) $oneof_name$_);
\n
"
" $number$, ($boxed_type$)
this.
$oneof_name$_);
\n
"
"}
\n
"
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment