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
43abe32e
Commit
43abe32e
authored
Sep 04, 2017
by
Kenton Varda
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of github.com:kentonv/capnproto
parents
2ef919b2
e987b815
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
5 deletions
+19
-5
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
array.h
c++/src/kj/array.h
+8
-2
No files found.
c++/src/capnp/serialize-packed-test.c++
View file @
43abe32e
...
...
@@ -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
...
...
c++/src/capnp/serialize-packed.c++
View file @
43abe32e
...
...
@@ -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.
...
...
c++/src/capnp/serialize-packed.h
View file @
43abe32e
...
...
@@ -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
);
...
...
c++/src/kj/array.h
View file @
43abe32e
...
...
@@ -450,11 +450,17 @@ public:
// check might catch bugs. Probably people should use Vector if they want to build arrays
// without knowing the final size in advance.
KJ_IREQUIRE
(
pos
==
endPtr
,
"ArrayBuilder::finish() called prematurely."
);
Array
<
T
>
result
(
reinterpret_cast
<
T
*>
(
ptr
),
pos
-
ptr
,
*
disposer
);
const
ptrdiff_t
size
=
pos
-
ptr
;
T
*
start
=
reinterpret_cast
<
T
*>
(
ptr
);
ptr
=
nullptr
;
pos
=
nullptr
;
endPtr
=
nullptr
;
return
result
;
if
(
size
==
0
)
{
// `disposer` possibly does not point to anything, so don't pass `*disposer` to `Array`.
return
Array
<
T
>
();
}
else
{
return
Array
<
T
>
(
start
,
size
,
*
disposer
);
}
}
inline
bool
isFull
()
const
{
...
...
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