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
e2dd39b3
Commit
e2dd39b3
authored
Dec 10, 2014
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extend previous change for flat arrays as well.
parent
ae225aa7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
0 deletions
+38
-0
serialize-test.c++
c++/src/capnp/serialize-test.c++
+16
-0
serialize.c++
c++/src/capnp/serialize.c++
+7
-0
serialize.h
c++/src/capnp/serialize.h
+15
-0
No files found.
c++/src/capnp/serialize-test.c++
View file @
e2dd39b3
...
...
@@ -74,6 +74,14 @@ TEST(Serialize, FlatArray) {
EXPECT_EQ
(
serialized
.
end
(),
reader
.
getEnd
());
}
{
MallocMessageBuilder
builder2
;
auto
remaining
=
initMessageBuilderFromFlatArrayCopy
(
serialized
,
builder2
);
checkTestMessage
(
builder2
.
getRoot
<
TestAllTypes
>
());
EXPECT_EQ
(
serialized
.
end
(),
remaining
.
begin
());
EXPECT_EQ
(
serialized
.
end
(),
remaining
.
end
());
}
kj
::
Array
<
word
>
serializedWithSuffix
=
kj
::
heapArray
<
word
>
(
serialized
.
size
()
+
5
);
memcpy
(
serializedWithSuffix
.
begin
(),
serialized
.
begin
(),
serialized
.
size
()
*
sizeof
(
word
));
...
...
@@ -82,6 +90,14 @@ TEST(Serialize, FlatArray) {
checkTestMessage
(
reader
.
getRoot
<
TestAllTypes
>
());
EXPECT_EQ
(
serializedWithSuffix
.
end
()
-
5
,
reader
.
getEnd
());
}
{
MallocMessageBuilder
builder2
;
auto
remaining
=
initMessageBuilderFromFlatArrayCopy
(
serializedWithSuffix
,
builder2
);
checkTestMessage
(
builder2
.
getRoot
<
TestAllTypes
>
());
EXPECT_EQ
(
serializedWithSuffix
.
end
()
-
5
,
remaining
.
begin
());
EXPECT_EQ
(
serializedWithSuffix
.
end
(),
remaining
.
end
());
}
}
TEST
(
Serialize
,
FlatArrayOddSegmentCount
)
{
...
...
c++/src/capnp/serialize.c++
View file @
e2dd39b3
...
...
@@ -90,6 +90,13 @@ kj::ArrayPtr<const word> FlatArrayMessageReader::getSegment(uint id) {
}
}
kj
::
ArrayPtr
<
const
word
>
initMessageBuilderFromFlatArrayCopy
(
kj
::
ArrayPtr
<
const
word
>
array
,
MessageBuilder
&
target
,
ReaderOptions
options
)
{
FlatArrayMessageReader
reader
(
array
,
options
);
target
.
setRoot
(
reader
.
getRoot
<
AnyPointer
>
());
return
kj
::
arrayPtr
(
reader
.
getEnd
(),
array
.
end
());
}
kj
::
Array
<
word
>
messageToFlatArray
(
kj
::
ArrayPtr
<
const
kj
::
ArrayPtr
<
const
word
>>
segments
)
{
kj
::
Array
<
word
>
result
=
kj
::
heapArray
<
word
>
(
computeSerializedSizeInWords
(
segments
));
...
...
c++/src/capnp/serialize.h
View file @
e2dd39b3
...
...
@@ -73,6 +73,21 @@ private:
const
word
*
end
;
};
kj
::
ArrayPtr
<
const
word
>
initMessageBuilderFromFlatArrayCopy
(
kj
::
ArrayPtr
<
const
word
>
array
,
MessageBuilder
&
target
,
ReaderOptions
options
=
ReaderOptions
());
// Convenience function which reads a message using `FlatArrayMessageReader` then copies the
// content into the target `MessageBuilder`, verifying that the message structure is valid
// (although not necessarily that it matches the desired schema).
//
// Returns an ArrayPtr containing any words left over in the array after consuming the whole
// message. This is useful when reading multiple messages that have been concatenated. See also
// FlatArrayMessageReader::getEnd().
//
// (Note that it's also possible to initialize a `MessageBuilder` directly without a copy using one
// of `MessageBuilder`'s constructors. However, this approach skips the validation step and is not
// safe to use on untrusted input. Therefore, we do not provide a convenience method for it.)
kj
::
Array
<
word
>
messageToFlatArray
(
MessageBuilder
&
builder
);
// Constructs a flat array containing the entire content of the given message.
//
...
...
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