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
8a2bd42f
Commit
8a2bd42f
authored
May 13, 2014
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add computeSerializedSizeInWords() utility function.
parent
c449295b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
9 deletions
+23
-9
serialize.c++
c++/src/capnp/serialize.c++
+13
-9
serialize.h
c++/src/capnp/serialize.h
+10
-0
No files found.
c++/src/capnp/serialize.c++
View file @
8a2bd42f
...
@@ -91,15 +91,7 @@ kj::ArrayPtr<const word> FlatArrayMessageReader::getSegment(uint id) {
...
@@ -91,15 +91,7 @@ kj::ArrayPtr<const word> FlatArrayMessageReader::getSegment(uint id) {
}
}
kj
::
Array
<
word
>
messageToFlatArray
(
kj
::
ArrayPtr
<
const
kj
::
ArrayPtr
<
const
word
>>
segments
)
{
kj
::
Array
<
word
>
messageToFlatArray
(
kj
::
ArrayPtr
<
const
kj
::
ArrayPtr
<
const
word
>>
segments
)
{
KJ_REQUIRE
(
segments
.
size
()
>
0
,
"Tried to serialize uninitialized message."
);
kj
::
Array
<
word
>
result
=
kj
::
heapArray
<
word
>
(
computeSerializedSizeInWords
(
segments
));
size_t
totalSize
=
segments
.
size
()
/
2
+
1
;
for
(
auto
&
segment
:
segments
)
{
totalSize
+=
segment
.
size
();
}
kj
::
Array
<
word
>
result
=
kj
::
heapArray
<
word
>
(
totalSize
);
_
::
WireValue
<
uint32_t
>*
table
=
_
::
WireValue
<
uint32_t
>*
table
=
reinterpret_cast
<
_
::
WireValue
<
uint32_t
>*>
(
result
.
begin
());
reinterpret_cast
<
_
::
WireValue
<
uint32_t
>*>
(
result
.
begin
());
...
@@ -130,6 +122,18 @@ kj::Array<word> messageToFlatArray(kj::ArrayPtr<const kj::ArrayPtr<const word>>
...
@@ -130,6 +122,18 @@ kj::Array<word> messageToFlatArray(kj::ArrayPtr<const kj::ArrayPtr<const word>>
return
kj
::
mv
(
result
);
return
kj
::
mv
(
result
);
}
}
size_t
computeSerializedSizeInWords
(
kj
::
ArrayPtr
<
const
kj
::
ArrayPtr
<
const
word
>>
segments
)
{
KJ_REQUIRE
(
segments
.
size
()
>
0
,
"Tried to serialize uninitialized message."
);
size_t
totalSize
=
segments
.
size
()
/
2
+
1
;
for
(
auto
&
segment
:
segments
)
{
totalSize
+=
segment
.
size
();
}
return
totalSize
;
}
// =======================================================================================
// =======================================================================================
InputStreamMessageReader
::
InputStreamMessageReader
(
InputStreamMessageReader
::
InputStreamMessageReader
(
...
...
c++/src/capnp/serialize.h
View file @
8a2bd42f
...
@@ -77,6 +77,12 @@ kj::Array<word> messageToFlatArray(MessageBuilder& builder);
...
@@ -77,6 +77,12 @@ kj::Array<word> messageToFlatArray(MessageBuilder& builder);
kj
::
Array
<
word
>
messageToFlatArray
(
kj
::
ArrayPtr
<
const
kj
::
ArrayPtr
<
const
word
>>
segments
);
kj
::
Array
<
word
>
messageToFlatArray
(
kj
::
ArrayPtr
<
const
kj
::
ArrayPtr
<
const
word
>>
segments
);
// Version of messageToFlatArray that takes a raw segment array.
// Version of messageToFlatArray that takes a raw segment array.
size_t
computeSerializedSizeInWords
(
MessageBuilder
&
builder
);
// Returns the size, in words, that will be needed to serialize the message, including the header.
size_t
computeSerializedSizeInWords
(
kj
::
ArrayPtr
<
const
kj
::
ArrayPtr
<
const
word
>>
segments
);
// Version of computeSerializedSizeInWords that takes a raw segment array.
// =======================================================================================
// =======================================================================================
class
InputStreamMessageReader
:
public
MessageReader
{
class
InputStreamMessageReader
:
public
MessageReader
{
...
@@ -151,6 +157,10 @@ inline kj::Array<word> messageToFlatArray(MessageBuilder& builder) {
...
@@ -151,6 +157,10 @@ inline kj::Array<word> messageToFlatArray(MessageBuilder& builder) {
return
messageToFlatArray
(
builder
.
getSegmentsForOutput
());
return
messageToFlatArray
(
builder
.
getSegmentsForOutput
());
}
}
inline
size_t
computeSerializedSizeInWords
(
MessageBuilder
&
builder
)
{
return
computeSerializedSizeInWords
(
builder
.
getSegmentsForOutput
());
}
inline
void
writeMessage
(
kj
::
OutputStream
&
output
,
MessageBuilder
&
builder
)
{
inline
void
writeMessage
(
kj
::
OutputStream
&
output
,
MessageBuilder
&
builder
)
{
writeMessage
(
output
,
builder
.
getSegmentsForOutput
());
writeMessage
(
output
,
builder
.
getSegmentsForOutput
());
}
}
...
...
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