Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
capnproto
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
capnproto
Commits
1ccd2dcb
Commit
1ccd2dcb
authored
Jun 28, 2018
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Honor JSON annotations when using `capnp convert`.
parent
0a2d1e0c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
0 deletions
+29
-0
capnp-test.sh
c++/src/capnp/compiler/capnp-test.sh
+4
-0
capnp.c++
c++/src/capnp/compiler/capnp.c++
+9
-0
annotated-json.binary
c++/src/capnp/testdata/annotated-json.binary
+0
-0
annotated.json
c++/src/capnp/testdata/annotated.json
+16
-0
No files found.
c++/src/capnp/compiler/capnp-test.sh
View file @
1ccd2dcb
...
...
@@ -38,6 +38,7 @@ else
fi
SCHEMA
=
`
dirname
"
$0
"
`
/../test.capnp
JSON_SCHEMA
=
`
dirname
"
$0
"
`
/../compat/json-test.capnp
TESTDATA
=
`
dirname
"
$0
"
`
/../testdata
SUFFIX
=
${
TESTDATA
#*/src/
}
...
...
@@ -74,6 +75,9 @@ $CAPNP convert binary:json --short $SCHEMA TestAllTypes < $TESTDATA/binary | cmp
$CAPNP
convert json:binary
$SCHEMA
TestAllTypes <
$TESTDATA
/pretty.json | cmp
$TESTDATA
/binary -
||
fail json to binary
$CAPNP
convert json:binary
$SCHEMA
TestAllTypes <
$TESTDATA
/short.json | cmp
$TESTDATA
/binary -
||
fail short json to binary
$CAPNP
convert json:binary
$JSON_SCHEMA
TestJsonAnnotations <
$TESTDATA
/annotated.json | cmp
$TESTDATA
/annotated-json.binary
||
fail annotated json to binary
$CAPNP
convert binary:json
$JSON_SCHEMA
TestJsonAnnotations <
$TESTDATA
/annotated-json.binary | cmp
$TESTDATA
/annotated.json
||
fail annotated json to binary
# ========================================================================================
# DEPRECATED encode/decode
...
...
c++/src/capnp/compiler/capnp.c++
View file @
1ccd2dcb
...
...
@@ -714,6 +714,13 @@ public:
return
kj
::
str
(
"unknown format: "
,
to
);
}
if
(
convertFrom
==
Format
::
JSON
||
convertTo
==
Format
::
JSON
)
{
// We need annotations to process JSON.
// TODO(someday): Find a way that we can process annotations from json.capnp without
// requiring other annotation-only imports like c++.capnp
annotationFlag
=
Compiler
::
COMPILE_ANNOTATIONS
;
}
return
true
;
}
else
{
return
"invalid conversion, format is: <from>:<to>"
;
...
...
@@ -1038,6 +1045,7 @@ private:
MallocMessageBuilder
message
;
JsonCodec
codec
;
codec
.
setPrettyPrint
(
pretty
);
codec
.
handleByAnnotation
(
rootType
);
auto
root
=
message
.
initRoot
<
DynamicStruct
>
(
rootType
);
codec
.
decode
(
text
,
root
);
return
writeConversion
(
root
.
asReader
(),
output
);
...
...
@@ -1096,6 +1104,7 @@ private:
case
Format
:
:
JSON
:
{
JsonCodec
codec
;
codec
.
setPrettyPrint
(
pretty
);
codec
.
handleByAnnotation
(
rootType
);
auto
text
=
codec
.
encode
(
reader
.
as
<
DynamicStruct
>
(
rootType
));
output
.
write
({
text
.
asBytes
(),
kj
::
StringPtr
(
"
\n
"
).
asBytes
()});
return
;
...
...
c++/src/capnp/testdata/annotated-json.binary
0 → 100644
View file @
1ccd2dcb
File added
c++/src/capnp/testdata/annotated.json
0 → 100644
View file @
1ccd2dcb
{
"names-can_contain!anything Really"
:
"foo"
,
"flatFoo"
:
123
,
"flatBar"
:
"abc"
,
"renamed-flatBaz"
:
{
"hello"
:
true
},
"flatQux"
:
"cba"
,
"pfx.foo"
:
"this is a long string in order to force multi-line pretty printing"
,
"pfx.renamed-bar"
:
321
,
"pfx.baz"
:
{
"hello"
:
true
},
"pfx.xfp.qux"
:
"fed"
,
"union-type"
:
"renamed-bar"
,
"barMember"
:
789
,
"multiMember"
:
"ghi"
,
"dependency"
:
{
"renamed-foo"
:
"corge"
},
"simpleGroup"
:
{
"renamed-grault"
:
"garply"
},
"enums"
:
[
"qux"
,
"renamed-bar"
,
"foo"
,
"renamed-baz"
],
"innerJson"
:
[
123
,
"hello"
,
{
"object"
:
true
}]
}
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