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
61dac6d5
Commit
61dac6d5
authored
Jun 04, 2018
by
Yilun Chong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix
parent
193af9f4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
29 deletions
+36
-29
data_proto2_to_proto3_util.h
benchmarks/util/data_proto2_to_proto3_util.h
+1
-0
protoc-gen-proto2_to_proto3.cc
benchmarks/util/protoc-gen-proto2_to_proto3.cc
+34
-27
schema_proto2_to_proto3_util.h
benchmarks/util/schema_proto2_to_proto3_util.h
+1
-2
No files found.
benchmarks/util/data_proto2_to_proto3_util.h
View file @
61dac6d5
...
...
@@ -23,6 +23,7 @@ class DataStripper {
const
FieldDescriptor
*
field
=
set_fields
[
i
];
if
(
ShouldBeClear
(
field
))
{
reflection
->
ClearField
(
message
,
field
);
continue
;
}
if
(
field
->
type
()
==
FieldDescriptor
::
TYPE_MESSAGE
)
{
if
(
field
->
is_repeated
())
{
...
...
benchmarks/util/protoc-gen-proto2_to_proto3.cc
View file @
61dac6d5
...
...
@@ -23,42 +23,25 @@ namespace compiler {
namespace
{
string
StripProto
(
string
filename
)
{
if
(
filename
.
substr
(
filename
.
size
()
-
11
)
==
".protodevel"
)
{
// .protodevel
return
filename
.
substr
(
0
,
filename
.
size
()
-
11
);
}
else
{
// .proto
return
filename
.
substr
(
0
,
filename
.
size
()
-
6
);
}
return
filename
.
substr
(
0
,
filename
.
rfind
(
".proto"
));
}
DescriptorPool
new_pool_
;
DescriptorPool
*
GetPool
()
{
static
DescriptorPool
*
pool
=
new
DescriptorPool
();
return
pool
;
}
}
// namespace
class
Proto2ToProto3Generator
:
public
CodeGenerator
{
class
Proto2ToProto3Generator
final
:
public
CodeGenerator
{
public
:
virtual
bool
GenerateAll
(
const
std
::
vector
<
const
FileDescriptor
*>&
files
,
bool
GenerateAll
(
const
std
::
vector
<
const
FileDescriptor
*>&
files
,
const
string
&
parameter
,
GeneratorContext
*
context
,
string
*
error
)
const
{
for
(
int
i
=
0
;
i
<
files
.
size
();
i
++
)
{
for
(
auto
file
:
files
)
{
bool
can_generate
=
(
new_pool_
.
FindFileByName
(
file
->
name
())
==
nullptr
);
for
(
int
j
=
0
;
j
<
file
->
dependency_count
();
j
++
)
{
can_generate
&=
(
new_pool_
.
FindFileByName
(
file
->
dependency
(
j
)
->
name
())
!=
nullptr
);
}
for
(
int
j
=
0
;
j
<
file
->
public_dependency_count
();
j
++
)
{
can_generate
&=
(
new_pool_
.
FindFileByName
(
file
->
public_dependency
(
j
)
->
name
())
!=
nullptr
);
}
for
(
int
j
=
0
;
j
<
file
->
weak_dependency_count
();
j
++
)
{
can_generate
&=
(
new_pool_
.
FindFileByName
(
file
->
weak_dependency
(
j
)
->
name
())
!=
nullptr
);
}
if
(
can_generate
)
{
if
(
CanGenerate
(
file
))
{
Generate
(
file
,
parameter
,
context
,
error
);
break
;
}
...
...
@@ -68,7 +51,7 @@ class Proto2ToProto3Generator : public CodeGenerator {
return
true
;
}
virtual
bool
Generate
(
const
FileDescriptor
*
file
,
bool
Generate
(
const
FileDescriptor
*
file
,
const
string
&
parameter
,
GeneratorContext
*
context
,
string
*
error
)
const
{
...
...
@@ -90,10 +73,34 @@ class Proto2ToProto3Generator : public CodeGenerator {
std
::
unique_ptr
<
google
::
protobuf
::
io
::
ZeroCopyOutputStream
>
output
(
context
->
Open
(
basename
+
".proto"
));
string
content
=
new_pool_
.
BuildFile
(
new_file
)
->
DebugString
();
string
content
=
GetPool
()
->
BuildFile
(
new_file
)
->
DebugString
();
Printer
printer
(
output
.
get
(),
'$'
);
printer
.
WriteRaw
(
content
.
c_str
(),
content
.
size
());
return
true
;
}
private
:
bool
CanGenerate
(
const
FileDescriptor
*
file
)
const
{
if
(
GetPool
()
->
FindFileByName
(
file
->
name
())
!=
nullptr
)
{
return
false
;
}
for
(
int
j
=
0
;
j
<
file
->
dependency_count
();
j
++
)
{
if
(
GetPool
()
->
FindFileByName
(
file
->
dependency
(
j
)
->
name
())
==
nullptr
)
{
return
false
;
}
}
for
(
int
j
=
0
;
j
<
file
->
public_dependency_count
();
j
++
)
{
if
(
GetPool
()
->
FindFileByName
(
file
->
public_dependency
(
j
)
->
name
())
==
nullptr
)
{
return
false
;
}
}
for
(
int
j
=
0
;
j
<
file
->
weak_dependency_count
();
j
++
)
{
if
(
GetPool
()
->
FindFileByName
(
file
->
weak_dependency
(
j
)
->
name
())
==
nullptr
)
{
return
false
;
}
}
return
true
;
}
};
...
...
benchmarks/util/schema_proto2_to_proto3_util.h
View file @
61dac6d5
...
...
@@ -164,8 +164,7 @@ class FieldScrubber {
}
private
:
static
bool
ShouldClearLabel
(
const
FieldDescriptorProto
*
field
)
{
return
field
->
label
()
==
FieldDescriptorProto
::
LABEL_OPTIONAL
||
field
->
label
()
==
FieldDescriptorProto
::
LABEL_REQUIRED
;
return
field
->
label
()
==
FieldDescriptorProto
::
LABEL_REQUIRED
;
}
static
void
ScrubMessage
(
DescriptorProto
*
message_type
)
{
...
...
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