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
7b801f80
Commit
7b801f80
authored
7 years ago
by
David Renshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
buffers passed to PackedOutputStream::write() must be word-aligned
parent
7a7c4007
master
v0.7.0
No related merge requests found
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
3 deletions
+11
-3
serialize-packed-test.c++
c++/src/capnp/serialize-packed-test.c++
+8
-2
serialize-packed.c++
c++/src/capnp/serialize-packed.c++
+2
-1
serialize-packed.h
c++/src/capnp/serialize-packed.h
+1
-0
No files found.
c++/src/capnp/serialize-packed-test.c++
View file @
7b801f80
...
...
@@ -86,10 +86,16 @@ private:
std
::
string
::
size_type
readPos
;
};
void
expectPacksTo
(
kj
::
ArrayPtr
<
const
byte
>
unpacked
,
kj
::
ArrayPtr
<
const
byte
>
packed
)
{
void
expectPacksTo
(
kj
::
ArrayPtr
<
const
byte
>
unpacked
Unaligned
,
kj
::
ArrayPtr
<
const
byte
>
packed
)
{
TestPipe
pipe
;
EXPECT_EQ
(
unpacked
.
size
(),
computeUnpackedSizeInWords
(
packed
)
*
sizeof
(
word
));
auto
unpackedSizeInWords
=
computeUnpackedSizeInWords
(
packed
);
EXPECT_EQ
(
unpackedUnaligned
.
size
(),
unpackedSizeInWords
*
sizeof
(
word
));
// Make a guaranteed-to-be-aligned copy of the unpacked buffer.
kj
::
Array
<
word
>
unpackedWords
=
kj
::
heapArray
<
word
>
(
unpackedSizeInWords
);
memcpy
(
unpackedWords
.
begin
(),
unpackedUnaligned
.
begin
(),
unpackedUnaligned
.
size
());
kj
::
ArrayPtr
<
const
byte
>
unpacked
=
unpackedWords
.
asBytes
();
// -----------------------------------------------------------------
// write
...
...
This diff is collapsed.
Click to expand it.
c++/src/capnp/serialize-packed.c++
View file @
7b801f80
...
...
@@ -351,7 +351,8 @@ void PackedOutputStream::write(const void* src, size_t size) {
// An all-zero word is followed by a count of consecutive zero words (not including the
// first one).
// We can check a whole word at a time.
// We can check a whole word at a time. (Here is where we use the assumption that
// `src` is word-aligned.)
const
uint64_t
*
inWord
=
reinterpret_cast
<
const
uint64_t
*>
(
in
);
// The count must fit it 1 byte, so limit to 255 words.
...
...
This diff is collapsed.
Click to expand it.
c++/src/capnp/serialize-packed.h
View file @
7b801f80
...
...
@@ -50,6 +50,7 @@ private:
};
class
PackedOutputStream
:
public
kj
::
OutputStream
{
// An output stream that packs data. Buffers passed to `write()` must be word-aligned.
public
:
explicit
PackedOutputStream
(
kj
::
BufferedOutputStream
&
inner
);
KJ_DISALLOW_COPY
(
PackedOutputStream
);
...
...
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