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
7c4bbf07
Commit
7c4bbf07
authored
Jan 14, 2015
by
Chris Fallin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support oneofs in the Ruby code generator.
parent
fcd8889d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
18 deletions
+46
-18
ruby_generator.cc
src/google/protobuf/compiler/ruby/ruby_generator.cc
+46
-18
No files found.
src/google/protobuf/compiler/ruby/ruby_generator.cc
View file @
7c4bbf07
...
@@ -100,6 +100,45 @@ std::string TypeName(const google::protobuf::FieldDescriptor* field) {
...
@@ -100,6 +100,45 @@ std::string TypeName(const google::protobuf::FieldDescriptor* field) {
}
}
}
}
void
GenerateField
(
const
google
::
protobuf
::
FieldDescriptor
*
field
,
google
::
protobuf
::
io
::
Printer
*
printer
)
{
printer
->
Print
(
"$label$ :$name$, "
,
"label"
,
LabelForField
(
field
),
"name"
,
field
->
name
());
printer
->
Print
(
":$type$, $number$"
,
"type"
,
TypeName
(
field
),
"number"
,
IntToString
(
field
->
number
()));
if
(
field
->
cpp_type
()
==
FieldDescriptor
::
CPPTYPE_MESSAGE
)
{
printer
->
Print
(
",
\"
$subtype$
\"\n
"
,
"subtype"
,
field
->
message_type
()
->
full_name
());
}
else
if
(
field
->
cpp_type
()
==
FieldDescriptor
::
CPPTYPE_ENUM
)
{
printer
->
Print
(
",
\"
$subtype$
\"\n
"
,
"subtype"
,
field
->
enum_type
()
->
full_name
());
}
else
{
printer
->
Print
(
"
\n
"
);
}
}
void
GenerateOneof
(
const
google
::
protobuf
::
OneofDescriptor
*
oneof
,
google
::
protobuf
::
io
::
Printer
*
printer
)
{
printer
->
Print
(
"oneof :$name$ do
\n
"
,
"name"
,
oneof
->
name
());
printer
->
Indent
();
for
(
int
i
=
0
;
i
<
oneof
->
field_count
();
i
++
)
{
const
FieldDescriptor
*
field
=
oneof
->
field
(
i
);
GenerateField
(
field
,
printer
);
}
printer
->
Outdent
();
printer
->
Print
(
"end
\n
"
);
}
void
GenerateMessage
(
const
google
::
protobuf
::
Descriptor
*
message
,
void
GenerateMessage
(
const
google
::
protobuf
::
Descriptor
*
message
,
google
::
protobuf
::
io
::
Printer
*
printer
)
{
google
::
protobuf
::
io
::
Printer
*
printer
)
{
printer
->
Print
(
printer
->
Print
(
...
@@ -109,27 +148,16 @@ void GenerateMessage(const google::protobuf::Descriptor* message,
...
@@ -109,27 +148,16 @@ void GenerateMessage(const google::protobuf::Descriptor* message,
for
(
int
i
=
0
;
i
<
message
->
field_count
();
i
++
)
{
for
(
int
i
=
0
;
i
<
message
->
field_count
();
i
++
)
{
const
FieldDescriptor
*
field
=
message
->
field
(
i
);
const
FieldDescriptor
*
field
=
message
->
field
(
i
);
printer
->
Print
(
if
(
!
field
->
containing_oneof
())
{
"$label$ :$name$, "
,
GenerateField
(
field
,
printer
);
"label"
,
LabelForField
(
field
),
"name"
,
field
->
name
());
printer
->
Print
(
":$type$, $number$"
,
"type"
,
TypeName
(
field
),
"number"
,
IntToString
(
field
->
number
()));
if
(
field
->
cpp_type
()
==
FieldDescriptor
::
CPPTYPE_MESSAGE
)
{
printer
->
Print
(
",
\"
$subtype$
\"\n
"
,
"subtype"
,
field
->
message_type
()
->
full_name
());
}
else
if
(
field
->
cpp_type
()
==
FieldDescriptor
::
CPPTYPE_ENUM
)
{
printer
->
Print
(
",
\"
$subtype$
\"\n
"
,
"subtype"
,
field
->
enum_type
()
->
full_name
());
}
else
{
printer
->
Print
(
"
\n
"
);
}
}
}
}
for
(
int
i
=
0
;
i
<
message
->
oneof_decl_count
();
i
++
)
{
const
OneofDescriptor
*
oneof
=
message
->
oneof_decl
(
i
);
GenerateOneof
(
oneof
,
printer
);
}
printer
->
Outdent
();
printer
->
Outdent
();
printer
->
Print
(
"end
\n
"
);
printer
->
Print
(
"end
\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