Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
B
brpc
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
brpc
Commits
a62f7946
Commit
a62f7946
authored
Aug 30, 2018
by
wangyao02
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- fix compile error
parent
cf685def
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
3 deletions
+13
-3
pb_to_json.cpp
src/json2pb/pb_to_json.cpp
+5
-3
pb_to_json.h
src/json2pb/pb_to_json.h
+5
-0
protobuf_map.cpp
src/json2pb/protobuf_map.cpp
+3
-0
No files found.
src/json2pb/pb_to_json.cpp
View file @
a62f7946
...
...
@@ -20,10 +20,11 @@ Pb2JsonOptions::Pb2JsonOptions()
,
pretty_json
(
false
)
,
enable_protobuf_map
(
true
)
#ifdef BAIDU_INTERNAL
,
bytes_to_base64
(
false
)
{
,
bytes_to_base64
(
false
)
#else
,
bytes_to_base64
(
true
)
{
,
bytes_to_base64
(
true
)
#endif
,
jsonify_empty_array
(
false
)
{
}
class
PbToJsonConverter
{
...
...
@@ -89,7 +90,8 @@ bool PbToJsonConverter::Convert(const google::protobuf::Message& message, Handle
}
continue
;
}
else
if
(
field
->
is_repeated
()
&&
reflection
->
FieldSize
(
message
,
field
)
==
0
)
{
&&
reflection
->
FieldSize
(
message
,
field
)
==
0
&&
!
_option
.
jsonify_empty_array
)
{
// Repeated field that has no entry
continue
;
}
...
...
src/json2pb/pb_to_json.h
View file @
a62f7946
...
...
@@ -38,6 +38,11 @@ struct Pb2JsonOptions {
// encoding when this option is turned on.
// Default: false for baidu-internal, true otherwise.
bool
bytes_to_base64
;
// Convert the repeated field that has no entry
// to a empty array of json when this option is turned on.
// Default: false
bool
jsonify_empty_array
;
};
// Convert protobuf `messge' to `json' according to `options'.
...
...
src/json2pb/protobuf_map.cpp
View file @
a62f7946
...
...
@@ -13,6 +13,9 @@ bool IsProtobufMap(const FieldDescriptor* field) {
return
false
;
}
const
Descriptor
*
entry_desc
=
field
->
message_type
();
if
(
entry_desc
==
NULL
)
{
return
false
;
}
if
(
entry_desc
->
field_count
()
!=
2
)
{
return
false
;
}
...
...
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