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
2444c9eb
Commit
2444c9eb
authored
Aug 14, 2017
by
Kenton Varda
Committed by
GitHub
Aug 14, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #536 from zombiezen/convertcanonical
Add canonical format to capnp convert
parents
ea89b50d
33cb4f43
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
1 deletion
+15
-1
capnp.c++
c++/src/capnp/compiler/capnp.c++
+15
-1
No files found.
c++/src/capnp/compiler/capnp.c++
View file @
2444c9eb
...
@@ -127,6 +127,7 @@ public:
...
@@ -127,6 +127,7 @@ public:
" packed packed binary format (deflates zeroes)
\n
"
" packed packed binary format (deflates zeroes)
\n
"
" flat binary single segment, no segment table (rare)
\n
"
" flat binary single segment, no segment table (rare)
\n
"
" flat-packed flat and packed
\n
"
" flat-packed flat and packed
\n
"
" canonical canonicalized binary single segment, no segment table
\n
"
" text schema language struct literal format
\n
"
" text schema language struct literal format
\n
"
" json JSON format
\n
"
" json JSON format
\n
"
"When using
\"
text
\"
or
\"
json
\"
format, you must specify <schema-file> and <type> "
"When using
\"
text
\"
or
\"
json
\"
format, you must specify <schema-file> and <type> "
...
@@ -641,6 +642,7 @@ private:
...
@@ -641,6 +642,7 @@ private:
PACKED
,
PACKED
,
FLAT
,
FLAT
,
FLAT_PACKED
,
FLAT_PACKED
,
CANONICAL
,
TEXT
,
TEXT
,
JSON
JSON
};
};
...
@@ -650,6 +652,7 @@ private:
...
@@ -650,6 +652,7 @@ private:
if
(
name
==
"packed"
)
return
Format
::
PACKED
;
if
(
name
==
"packed"
)
return
Format
::
PACKED
;
if
(
name
==
"flat"
)
return
Format
::
FLAT
;
if
(
name
==
"flat"
)
return
Format
::
FLAT
;
if
(
name
==
"flat-packed"
)
return
Format
::
FLAT_PACKED
;
if
(
name
==
"flat-packed"
)
return
Format
::
FLAT_PACKED
;
if
(
name
==
"canonical"
)
return
Format
::
CANONICAL
;
if
(
name
==
"text"
)
return
Format
::
TEXT
;
if
(
name
==
"text"
)
return
Format
::
TEXT
;
if
(
name
==
"json"
)
return
Format
::
JSON
;
if
(
name
==
"json"
)
return
Format
::
JSON
;
...
@@ -662,6 +665,7 @@ private:
...
@@ -662,6 +665,7 @@ private:
case
Format
:
:
PACKED
:
return
"packed"
;
case
Format
:
:
PACKED
:
return
"packed"
;
case
Format
:
:
FLAT
:
return
"flat"
;
case
Format
:
:
FLAT
:
return
"flat"
;
case
Format
:
:
FLAT_PACKED
:
return
"flat-packed"
;
case
Format
:
:
FLAT_PACKED
:
return
"flat-packed"
;
case
Format
:
:
CANONICAL
:
return
"canonical"
;
case
Format
:
:
TEXT
:
return
"text"
;
case
Format
:
:
TEXT
:
return
"text"
;
case
Format
:
:
JSON
:
return
"json"
;
case
Format
:
:
JSON
:
return
"json"
;
}
}
...
@@ -989,7 +993,8 @@ private:
...
@@ -989,7 +993,8 @@ private:
capnp
::
PackedMessageReader
message
(
input
,
options
);
capnp
::
PackedMessageReader
message
(
input
,
options
);
return
writeConversion
(
message
.
getRoot
<
AnyStruct
>
(),
output
);
return
writeConversion
(
message
.
getRoot
<
AnyStruct
>
(),
output
);
}
}
case
Format
:
:
FLAT
:
{
case
Format
:
:
FLAT
:
case
Format
:
:
CANONICAL
:
{
auto
allBytes
=
readAll
(
input
);
auto
allBytes
=
readAll
(
input
);
// Technically we don't know if the bytes are aligned so we'd better copy them to a new
// Technically we don't know if the bytes are aligned so we'd better copy them to a new
...
@@ -1001,6 +1006,9 @@ private:
...
@@ -1001,6 +1006,9 @@ private:
kj
::
ArrayPtr
<
const
word
>
segments
[
1
]
=
{
words
};
kj
::
ArrayPtr
<
const
word
>
segments
[
1
]
=
{
words
};
SegmentArrayMessageReader
message
(
segments
,
options
);
SegmentArrayMessageReader
message
(
segments
,
options
);
if
(
convertFrom
==
Format
::
CANONICAL
)
{
KJ_REQUIRE
(
message
.
isCanonical
());
}
return
writeConversion
(
message
.
getRoot
<
AnyStruct
>
(),
output
);
return
writeConversion
(
message
.
getRoot
<
AnyStruct
>
(),
output
);
}
}
case
Format
:
:
FLAT_PACKED
:
{
case
Format
:
:
FLAT_PACKED
:
{
...
@@ -1074,6 +1082,11 @@ private:
...
@@ -1074,6 +1082,11 @@ private:
packed
.
write
(
words
.
begin
(),
words
.
asBytes
().
size
());
packed
.
write
(
words
.
begin
(),
words
.
asBytes
().
size
());
return
;
return
;
}
}
case
Format
:
:
CANONICAL
:
{
auto
words
=
reader
.
canonicalize
();
output
.
write
(
words
.
begin
(),
words
.
asBytes
().
size
());
return
;
}
case
Format
:
:
TEXT
:
{
case
Format
:
:
TEXT
:
{
TextCodec
codec
;
TextCodec
codec
;
codec
.
setPrettyPrint
(
pretty
);
codec
.
setPrettyPrint
(
pretty
);
...
@@ -1449,6 +1462,7 @@ private:
...
@@ -1449,6 +1462,7 @@ private:
case
Format
:
:
PACKED
:
return
isPlausiblyPacked
(
prefix
);
case
Format
:
:
PACKED
:
return
isPlausiblyPacked
(
prefix
);
case
Format
:
:
FLAT
:
return
isPlausiblyFlat
(
prefix
);
case
Format
:
:
FLAT
:
return
isPlausiblyFlat
(
prefix
);
case
Format
:
:
FLAT_PACKED
:
return
isPlausiblyPackedFlat
(
prefix
);
case
Format
:
:
FLAT_PACKED
:
return
isPlausiblyPackedFlat
(
prefix
);
case
Format
:
:
CANONICAL
:
return
isPlausiblyFlat
(
prefix
);
case
Format
:
:
TEXT
:
return
isPlausiblyText
(
prefix
);
case
Format
:
:
TEXT
:
return
isPlausiblyText
(
prefix
);
case
Format
:
:
JSON
:
return
isPlausiblyJson
(
prefix
);
case
Format
:
:
JSON
:
return
isPlausiblyJson
(
prefix
);
}
}
...
...
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