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
c13d6ad9
Commit
c13d6ad9
authored
8 years ago
by
Matthew Maurer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change canonicalize interface
parent
6de429bb
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
18 deletions
+18
-18
canonicalize-test.c++
c++/src/capnp/canonicalize-test.c++
+3
-5
message.h
c++/src/capnp/message.h
+15
-13
No files found.
c++/src/capnp/canonicalize-test.c++
View file @
c13d6ad9
...
@@ -35,9 +35,8 @@ KJ_TEST("canonicalize yields cannonical message") {
...
@@ -35,9 +35,8 @@ KJ_TEST("canonicalize yields cannonical message") {
initTestMessage
(
root
);
initTestMessage
(
root
);
MallocMessageBuilder
canonicalMessage
;
canonicalize
(
builder
);
canonicalMessage
.
canonicalRoot
(
builder
.
getRoot
<
AnyPointer
>
().
asReader
());
//Will assert if canonicalize failed to do so
KJ_ASSERT
(
canonicalMessage
.
isCanonical
());
}
}
KJ_TEST
(
"isCanonical requires pointer preorder"
)
{
KJ_TEST
(
"isCanonical requires pointer preorder"
)
{
...
@@ -119,8 +118,7 @@ KJ_TEST("isCanonical requires truncation of 0-valued struct fields") {
...
@@ -119,8 +118,7 @@ KJ_TEST("isCanonical requires truncation of 0-valued struct fields") {
KJ_ASSERT
(
!
nonTruncated
.
isCanonical
());
KJ_ASSERT
(
!
nonTruncated
.
isCanonical
());
}
}
KJ_TEST
(
"isCanonical requires truncation of 0-valued struct fields\
KJ_TEST
(
"isCanonical requires truncation of 0-valued struct fields in all list members"
)
{
in all list members"
)
{
AlignedData
<
6
>
nonTruncatedList
=
{{
AlignedData
<
6
>
nonTruncatedList
=
{{
//List pointer, composite,
//List pointer, composite,
0x01
,
0x00
,
0x00
,
0x00
,
0x27
,
0x00
,
0x00
,
0x00
,
0x01
,
0x00
,
0x00
,
0x00
,
0x27
,
0x00
,
0x00
,
0x00
,
...
...
This diff is collapsed.
Click to expand it.
c++/src/capnp/message.h
View file @
c13d6ad9
...
@@ -199,12 +199,6 @@ public:
...
@@ -199,12 +199,6 @@ public:
void
setRoot
(
Reader
&&
value
);
void
setRoot
(
Reader
&&
value
);
// Set the root struct to a deep copy of the given struct.
// Set the root struct to a deep copy of the given struct.
template
<
typename
Reader
>
void
canonicalRoot
(
Reader
&&
value
);
// Set the root to a canonical deep copy of the struct.
// will likely only work if the builder has not yet been used, and has
// been set up with an arena with a segment as big as value.targetSize();
template
<
typename
RootType
>
template
<
typename
RootType
>
typename
RootType
::
Builder
getRoot
();
typename
RootType
::
Builder
getRoot
();
// Get the root struct of the message, interpreting it as the given struct type.
// Get the root struct of the message, interpreting it as the given struct type.
...
@@ -427,6 +421,21 @@ private:
...
@@ -427,6 +421,21 @@ private:
bool
allocated
;
bool
allocated
;
};
};
template
<
typename
MR
>
kj
::
Array
<
word
>
canonicalize
(
MR
&&
reader
)
{
AnyPointer
::
Reader
root
=
reader
.
template
getRoot
<
AnyPointer
>
();
WordCount
size
=
root
.
targetSize
().
wordCount
*
WORDS
+
POINTER_SIZE_IN_WORDS
;
kj
::
Array
<
word
>
backing
=
kj
::
heapArray
<
word
>
(
size
/
WORDS
);
bzero
(
backing
.
begin
(),
backing
.
asBytes
().
size
());
FlatMessageBuilder
builder
(
backing
);
builder
.
initRoot
<
AnyPointer
>
().
setCanonical
(
root
);
KJ_ASSERT
(
builder
.
isCanonical
());
auto
output
=
builder
.
getSegmentsForOutput
()[
0
];
kj
::
Array
<
word
>
trunc
=
kj
::
heapArray
<
word
>
(
output
.
size
());
memcpy
(
trunc
.
begin
(),
output
.
begin
(),
output
.
asBytes
().
size
());
return
trunc
;
}
// =======================================================================================
// =======================================================================================
// implementation details
// implementation details
...
@@ -474,13 +483,6 @@ typename RootType::Builder MessageBuilder::initRoot(SchemaType schema) {
...
@@ -474,13 +483,6 @@ typename RootType::Builder MessageBuilder::initRoot(SchemaType schema) {
return
getRootInternal
().
initAs
<
RootType
>
(
schema
);
return
getRootInternal
().
initAs
<
RootType
>
(
schema
);
}
}
template
<
typename
Reader
>
void
MessageBuilder
::
canonicalRoot
(
Reader
&&
value
)
{
auto
target
=
initRoot
<
AnyPointer
>
();
target
.
setCanonical
(
value
);
KJ_ASSERT
(
isCanonical
());
}
template
<
typename
RootType
>
template
<
typename
RootType
>
typename
RootType
::
Reader
readMessageUnchecked
(
const
word
*
data
)
{
typename
RootType
::
Reader
readMessageUnchecked
(
const
word
*
data
)
{
return
AnyPointer
::
Reader
(
_
::
PointerReader
::
getRootUnchecked
(
data
)).
getAs
<
RootType
>
();
return
AnyPointer
::
Reader
(
_
::
PointerReader
::
getRootUnchecked
(
data
)).
getAs
<
RootType
>
();
...
...
This diff is collapsed.
Click to expand it.
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