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
08a72268
Commit
08a72268
authored
Jan 07, 2018
by
gejun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add docs on map fields
parent
9597389c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
0 deletions
+15
-0
json2pb.md
docs/cn/json2pb.md
+15
-0
No files found.
docs/cn/json2pb.md
View file @
08a72268
...
...
@@ -34,6 +34,21 @@ repeated int32 numbers = 1;
{
"numbers"
:
[
12
,
17
,
1
,
24
]
}
```
## map
满足如下条件的repeated MSG被视作json map :
-
MSG包含一个名为key的字段,类型为string,tag为1。
-
MSG包含一个名为value的字段,tag为2。
-
不包含其他字段。
这种"map"的属性有:
-
自然不能确保key有序或不重复,用户视需求自行检查。
-
与protobuf 3.x中的map二进制兼容,故3.x中的map使用pb2json也会正确地转化为json map。
如果符合所有条件的repeated MSG并不需要被认为是json map,打破上面任一条件就行了: 在MSG中加入optional int32 this_message_is_not_map_entry = 3; 这个办法破坏了“不包含其他字段”这项,且不影响二进制兼容。也可以调换key和value的tag值,让前者为2后者为1,也使条件不再满足。
## integers
rapidjson会根据值打上对应的类型标记,比如:
...
...
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