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
2bcb6e69
Commit
2bcb6e69
authored
Mar 22, 2013
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify reuse strategy, add reuse comparisons to benchmarks.
parent
15aa868b
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
82 additions
and
184 deletions
+82
-184
arena.c++
c++/src/capnproto/arena.c++
+0
-20
arena.h
c++/src/capnproto/arena.h
+0
-5
benchmark-capnproto.c++
c++/src/capnproto/benchmark/benchmark-capnproto.c++
+0
-0
benchmark-protobuf.c++
c++/src/capnproto/benchmark/benchmark-protobuf.c++
+0
-0
message.c++
c++/src/capnproto/message.c++
+35
-21
message.h
c++/src/capnproto/message.h
+10
-11
serialize-test.c++
c++/src/capnproto/serialize-test.c++
+33
-127
serialize.c++
c++/src/capnproto/serialize.c++
+0
-0
serialize.h
c++/src/capnproto/serialize.h
+0
-0
type-safety.h
c++/src/capnproto/type-safety.h
+4
-0
No files found.
c++/src/capnproto/arena.c++
View file @
2bcb6e69
...
...
@@ -42,16 +42,6 @@ ReaderArena::ReaderArena(MessageReader* message)
ReaderArena
::~
ReaderArena
()
{}
void
ReaderArena
::
reset
()
{
readLimiter
.
reset
(
message
->
getOptions
().
traversalLimitInWords
*
WORDS
);
ignoreErrors
=
false
;
segment0
.
~
SegmentReader
();
new
(
&
segment0
)
SegmentReader
(
this
,
SegmentId
(
0
),
this
->
message
->
getSegment
(
0
),
&
readLimiter
);
// TODO: Reuse the rest of the SegmentReaders?
moreSegments
=
nullptr
;
}
SegmentReader
*
ReaderArena
::
tryGetSegment
(
SegmentId
id
)
{
if
(
id
==
SegmentId
(
0
))
{
if
(
segment0
.
getArray
()
==
nullptr
)
{
...
...
@@ -110,16 +100,6 @@ BuilderArena::BuilderArena(MessageBuilder* message)
:
message
(
message
),
segment0
(
nullptr
,
SegmentId
(
0
),
nullptr
,
nullptr
)
{}
BuilderArena
::~
BuilderArena
()
{}
void
BuilderArena
::
reset
()
{
segment0
.
reset
();
if
(
moreSegments
!=
nullptr
)
{
// TODO: As mentioned in another TODO below, only the last segment will only be reused.
for
(
auto
&
segment
:
moreSegments
->
builders
)
{
segment
->
reset
();
}
}
}
SegmentBuilder
*
BuilderArena
::
getSegment
(
SegmentId
id
)
{
// This method is allowed to crash if the segment ID is not valid.
if
(
id
==
SegmentId
(
0
))
{
...
...
c++/src/capnproto/arena.h
View file @
2bcb6e69
...
...
@@ -164,8 +164,6 @@ public:
~
ReaderArena
();
CAPNPROTO_DISALLOW_COPY
(
ReaderArena
);
void
reset
();
// implements Arena ------------------------------------------------
SegmentReader
*
tryGetSegment
(
SegmentId
id
)
override
;
void
reportInvalidData
(
const
char
*
description
)
override
;
...
...
@@ -189,9 +187,6 @@ public:
~
BuilderArena
();
CAPNPROTO_DISALLOW_COPY
(
BuilderArena
);
void
reset
();
// Resets all the segments to be empty, so that a new message can be started.
SegmentBuilder
*
getSegment
(
SegmentId
id
);
// Get the segment with the given id. Crashes or throws an exception if no such segment exists.
...
...
c++/src/capnproto/benchmark/benchmark-capnproto.c++
View file @
2bcb6e69
This diff is collapsed.
Click to expand it.
c++/src/capnproto/benchmark/benchmark-protobuf.c++
View file @
2bcb6e69
This diff is collapsed.
Click to expand it.
c++/src/capnproto/message.c++
View file @
2bcb6e69
...
...
@@ -38,10 +38,6 @@ MessageReader::~MessageReader() {
}
}
void
MessageReader
::
reset
()
{
if
(
allocatedArena
)
arena
()
->
reset
();
}
internal
::
StructReader
MessageReader
::
getRoot
(
const
word
*
defaultValue
)
{
if
(
!
allocatedArena
)
{
static_assert
(
sizeof
(
internal
::
ReaderArena
)
<=
sizeof
(
arenaSpace
),
...
...
@@ -71,35 +67,35 @@ MessageBuilder::~MessageBuilder() {
}
}
internal
::
SegmentBuilder
*
MessageBuilder
::
allocateRootSegment
()
{
if
(
!
allocatedArena
)
{
internal
::
SegmentBuilder
*
MessageBuilder
::
getRootSegment
()
{
if
(
allocatedArena
)
{
return
arena
()
->
getSegment
(
SegmentId
(
0
));
}
else
{
static_assert
(
sizeof
(
internal
::
BuilderArena
)
<=
sizeof
(
arenaSpace
),
"arenaSpace is too small to hold a BuilderArena. Please increase it. This will break "
"ABI compatibility."
);
new
(
arena
())
internal
::
BuilderArena
(
this
);
allocatedArena
=
true
;
}
WordCount
refSize
=
1
*
REFERENCES
*
WORDS_PER_REFERENCE
;
internal
::
SegmentBuilder
*
segment
=
arena
()
->
getSegmentWithAvailable
(
refSize
);
CAPNPROTO_ASSERT
(
segment
->
getSegmentId
()
==
SegmentId
(
0
),
"First allocated word of new arena was not in segment ID 0."
);
word
*
location
=
segment
->
allocate
(
refSize
);
CAPNPROTO_ASSERT
(
location
==
segment
->
getPtrUnchecked
(
0
*
WORDS
),
"First allocated word of new arena was not the first word in its segment."
);
return
segment
;
WordCount
refSize
=
1
*
REFERENCES
*
WORDS_PER_REFERENCE
;
internal
::
SegmentBuilder
*
segment
=
arena
()
->
getSegmentWithAvailable
(
refSize
);
CAPNPROTO_ASSERT
(
segment
->
getSegmentId
()
==
SegmentId
(
0
),
"First allocated word of new arena was not in segment ID 0."
);
word
*
location
=
segment
->
allocate
(
refSize
);
CAPNPROTO_ASSERT
(
location
==
segment
->
getPtrUnchecked
(
0
*
WORDS
),
"First allocated word of new arena was not the first word in its segment."
);
return
segment
;
}
}
internal
::
StructBuilder
MessageBuilder
::
initRoot
(
const
word
*
defaultValue
)
{
if
(
allocatedArena
)
arena
()
->
reset
();
internal
::
SegmentBuilder
*
rootSegment
=
allocateRootSegment
();
internal
::
SegmentBuilder
*
rootSegment
=
getRootSegment
();
return
internal
::
StructBuilder
::
initRoot
(
rootSegment
,
rootSegment
->
getPtrUnchecked
(
0
*
WORDS
),
defaultValue
);
}
internal
::
StructBuilder
MessageBuilder
::
getRoot
(
const
word
*
defaultValue
)
{
internal
::
SegmentBuilder
*
rootSegment
=
allocatedArena
?
arena
()
->
getSegment
(
SegmentId
(
0
))
:
allocateRootSegment
();
internal
::
SegmentBuilder
*
rootSegment
=
getRootSegment
();
return
internal
::
StructBuilder
::
getRoot
(
rootSegment
,
rootSegment
->
getPtrUnchecked
(
0
*
WORDS
),
defaultValue
);
}
...
...
@@ -200,10 +196,15 @@ struct MallocMessageBuilder::MoreSegments {
MallocMessageBuilder
::
MallocMessageBuilder
(
uint
firstSegmentWords
,
AllocationStrategy
allocationStrategy
)
:
nextSize
(
firstSegmentWords
),
allocationStrategy
(
allocationStrategy
),
firstSegment
(
nullptr
)
{}
ownFirstSegment
(
true
),
firstSegment
(
nullptr
)
{}
MallocMessageBuilder
::
MallocMessageBuilder
(
ArrayPtr
<
word
>
firstSegment
,
AllocationStrategy
allocationStrategy
)
:
nextSize
(
firstSegment
.
size
()),
allocationStrategy
(
allocationStrategy
),
ownFirstSegment
(
false
),
firstSegment
(
firstSegment
.
begin
())
{}
MallocMessageBuilder
::~
MallocMessageBuilder
()
{
free
(
firstSegment
);
if
(
ownFirstSegment
)
free
(
firstSegment
);
if
(
moreSegments
!=
nullptr
)
{
for
(
void
*
ptr
:
moreSegments
->
segments
)
{
free
(
ptr
);
...
...
@@ -212,6 +213,19 @@ MallocMessageBuilder::~MallocMessageBuilder() {
}
ArrayPtr
<
word
>
MallocMessageBuilder
::
allocateSegment
(
uint
minimumSize
)
{
if
(
!
ownFirstSegment
)
{
ArrayPtr
<
word
>
result
=
arrayPtr
(
reinterpret_cast
<
word
*>
(
firstSegment
),
nextSize
);
firstSegment
=
nullptr
;
ownFirstSegment
=
true
;
if
(
result
.
size
()
>=
minimumSize
)
{
memset
(
result
.
begin
(),
0
,
result
.
size
()
*
sizeof
(
word
));
return
result
;
}
// If the provided first segment wasn't big enough, we discard it and proceed to allocate
// our own. This never happens in practice since minimumSize is always 1 for the first
// segment.
}
uint
size
=
std
::
max
(
minimumSize
,
nextSize
);
void
*
result
=
calloc
(
size
,
sizeof
(
word
));
...
...
c++/src/capnproto/message.h
View file @
2bcb6e69
...
...
@@ -133,14 +133,6 @@ public:
template
<
typename
RootType
>
typename
RootType
::
Reader
getRoot
();
protected
:
void
reset
();
// Clear the cached segment table so that the reader can be reused to read another message.
// reset() may call getSegment() again before returning, so you must arrange for the new segment
// set to be active *before* calling this.
//
// This invalidates any Readers currently pointing into this message.
private
:
ReaderOptions
options
;
...
...
@@ -182,7 +174,7 @@ private:
bool
allocatedArena
=
false
;
internal
::
BuilderArena
*
arena
()
{
return
reinterpret_cast
<
internal
::
BuilderArena
*>
(
arenaSpace
);
}
internal
::
SegmentBuilder
*
allocate
RootSegment
();
internal
::
SegmentBuilder
*
get
RootSegment
();
internal
::
StructBuilder
initRoot
(
const
word
*
defaultValue
);
internal
::
StructBuilder
getRoot
(
const
word
*
defaultValue
);
};
...
...
@@ -232,7 +224,7 @@ private:
ArrayPtr
<
const
ArrayPtr
<
const
word
>>
segments
;
};
enum
class
AllocationStrategy
{
enum
class
AllocationStrategy
:
uint8_t
{
FIXED_SIZE
,
// The builder will prefer to allocate the same amount of space for each segment with no
// heuristic growth. It will still allocate larger segments when the preferred size is too small
...
...
@@ -257,7 +249,7 @@ class MallocMessageBuilder: public MessageBuilder {
// a specific location in memory.
public
:
MallocMessageBuilder
(
uint
firstSegmentWords
=
1024
,
explicit
MallocMessageBuilder
(
uint
firstSegmentWords
=
1024
,
AllocationStrategy
allocationStrategy
=
SUGGESTED_ALLOCATION_STRATEGY
);
// Creates a BuilderContext which allocates at least the given number of words for the first
// segment, and then uses the given strategy to decide how much to allocate for subsequent
...
...
@@ -271,6 +263,12 @@ public:
// The defaults have been chosen to be reasonable for most people, so don't change them unless you
// have reason to believe you need to.
explicit
MallocMessageBuilder
(
ArrayPtr
<
word
>
firstSegment
,
AllocationStrategy
allocationStrategy
=
SUGGESTED_ALLOCATION_STRATEGY
);
// This version always returns the given array for the first segment, and then proceeds with the
// allocation strategy. This is useful for optimization when building lots of small messages in
// a tight loop: you can reuse the space for the first segment.
CAPNPROTO_DISALLOW_COPY
(
MallocMessageBuilder
);
virtual
~
MallocMessageBuilder
();
...
...
@@ -280,6 +278,7 @@ private:
uint
nextSize
;
AllocationStrategy
allocationStrategy
;
bool
ownFirstSegment
;
void
*
firstSegment
;
struct
MoreSegments
;
...
...
c++/src/capnproto/serialize-test.c++
View file @
2bcb6e69
...
...
@@ -83,7 +83,7 @@ TEST(Serialize, FlatArrayOddSegmentCount) {
checkTestMessage
(
reader
.
getRoot
<
TestAllTypes
>
());
}
TEST
(
Serialize
,
FlatArrayEven
t
SegmentCount
)
{
TEST
(
Serialize
,
FlatArrayEvenSegmentCount
)
{
TestMessageBuilder
builder
(
10
);
initTestMessage
(
builder
.
initRoot
<
TestAllTypes
>
());
...
...
@@ -95,25 +95,24 @@ TEST(Serialize, FlatArrayEventSegmentCount) {
class
TestInputStream
:
public
InputStream
{
public
:
TestInputStream
(
ArrayPtr
<
const
word
>
data
)
TestInputStream
(
ArrayPtr
<
const
word
>
data
,
bool
lazy
)
:
pos
(
reinterpret_cast
<
const
char
*>
(
data
.
begin
())),
end
(
reinterpret_cast
<
const
char
*>
(
data
.
end
()))
{}
end
(
reinterpret_cast
<
const
char
*>
(
data
.
end
())),
lazy
(
lazy
)
{}
~
TestInputStream
()
{}
bool
read
(
void
*
buffer
,
size_t
size
)
override
{
if
(
size_t
(
end
-
pos
)
<
size
)
{
ADD_FAILURE
()
<<
"Overran end of stream."
;
return
false
;
}
else
{
memcpy
(
buffer
,
pos
,
size
);
pos
+=
size
;
return
true
;
}
size_t
read
(
void
*
buffer
,
size_t
minBytes
,
size_t
maxBytes
)
override
{
CAPNPROTO_ASSERT
(
maxBytes
<=
size_t
(
end
-
pos
),
"Overran end of stream."
);
size_t
amount
=
lazy
?
minBytes
:
maxBytes
;
memcpy
(
buffer
,
pos
,
amount
);
pos
+=
amount
;
return
amount
;
}
private
:
const
char
*
pos
;
const
char
*
end
;
bool
lazy
;
};
TEST
(
Serialize
,
InputStream
)
{
...
...
@@ -122,162 +121,81 @@ TEST(Serialize, InputStream) {
Array
<
word
>
serialized
=
messageToFlatArray
(
builder
);
TestInputStream
stream
(
serialized
.
asPtr
());
InputStreamMessageReader
reader
(
&
stream
,
ReaderOptions
(),
InputStrategy
::
EAGER
);
checkTestMessage
(
reader
.
getRoot
<
TestAllTypes
>
());
}
TEST
(
Serialize
,
InputStreamLazy
)
{
TestMessageBuilder
builder
(
1
);
initTestMessage
(
builder
.
initRoot
<
TestAllTypes
>
());
Array
<
word
>
serialized
=
messageToFlatArray
(
builder
);
TestInputStream
stream
(
serialized
.
asPtr
());
InputStreamMessageReader
reader
(
&
stream
,
ReaderOptions
(),
InputStrategy
::
LAZY
);
checkTestMessage
(
reader
.
getRoot
<
TestAllTypes
>
());
}
TEST
(
Serialize
,
InputStreamOddSegmentCount
)
{
TestMessageBuilder
builder
(
7
);
initTestMessage
(
builder
.
initRoot
<
TestAllTypes
>
());
Array
<
word
>
serialized
=
messageToFlatArray
(
builder
);
TestInputStream
stream
(
serialized
.
asPtr
());
InputStreamMessageReader
reader
(
&
stream
,
ReaderOptions
(),
InputStrategy
::
EAGER
);
checkTestMessage
(
reader
.
getRoot
<
TestAllTypes
>
());
}
TEST
(
Serialize
,
InputStreamOddSegmentCountLazy
)
{
TestMessageBuilder
builder
(
7
);
initTestMessage
(
builder
.
initRoot
<
TestAllTypes
>
());
Array
<
word
>
serialized
=
messageToFlatArray
(
builder
);
TestInputStream
stream
(
serialized
.
asPtr
());
InputStreamMessageReader
reader
(
&
stream
,
ReaderOptions
(),
InputStrategy
::
LAZY
);
checkTestMessage
(
reader
.
getRoot
<
TestAllTypes
>
());
}
TEST
(
Serialize
,
InputStreamEventSegmentCount
)
{
TestMessageBuilder
builder
(
10
);
initTestMessage
(
builder
.
initRoot
<
TestAllTypes
>
());
Array
<
word
>
serialized
=
messageToFlatArray
(
builder
);
TestInputStream
stream
(
serialized
.
asPtr
());
InputStreamMessageReader
reader
(
&
stream
,
ReaderOptions
(),
InputStrategy
::
EAGER
);
checkTestMessage
(
reader
.
getRoot
<
TestAllTypes
>
());
}
TEST
(
Serialize
,
InputStreamEventSegmentCountLazy
)
{
TestMessageBuilder
builder
(
10
);
initTestMessage
(
builder
.
initRoot
<
TestAllTypes
>
());
Array
<
word
>
serialized
=
messageToFlatArray
(
builder
);
TestInputStream
stream
(
serialized
.
asPtr
());
InputStreamMessageReader
reader
(
&
stream
,
ReaderOptions
(),
InputStrategy
::
LAZY
);
TestInputStream
stream
(
serialized
.
asPtr
(),
false
);
InputStreamMessageReader
reader
(
stream
,
ReaderOptions
());
checkTestMessage
(
reader
.
getRoot
<
TestAllTypes
>
());
}
class
TestInputFile
:
public
InputFile
{
public
:
TestInputFile
(
ArrayPtr
<
const
word
>
data
)
:
begin
(
reinterpret_cast
<
const
char
*>
(
data
.
begin
())),
size_
(
data
.
size
()
*
sizeof
(
word
))
{}
~
TestInputFile
()
{}
bool
read
(
size_t
offset
,
void
*
buffer
,
size_t
size
)
override
{
if
(
size_
<
offset
+
size
)
{
ADD_FAILURE
()
<<
"Overran end of file."
;
return
false
;
}
else
{
memcpy
(
buffer
,
begin
+
offset
,
size
);
return
true
;
}
}
private
:
const
char
*
begin
;
size_t
size_
;
};
TEST
(
Serialize
,
InputFile
)
{
TEST
(
Serialize
,
InputStreamScratchSpace
)
{
TestMessageBuilder
builder
(
1
);
initTestMessage
(
builder
.
initRoot
<
TestAllTypes
>
());
Array
<
word
>
serialized
=
messageToFlatArray
(
builder
);
TestInputFile
file
(
serialized
.
asPtr
());
InputFileMessageReader
reader
(
&
file
,
ReaderOptions
(),
InputStrategy
::
EAGER
);
word
scratch
[
4096
];
TestInputStream
stream
(
serialized
.
asPtr
(),
false
);
InputStreamMessageReader
reader
(
stream
,
ReaderOptions
(),
ArrayPtr
<
word
>
(
scratch
,
4096
));
checkTestMessage
(
reader
.
getRoot
<
TestAllTypes
>
());
}
TEST
(
Serialize
,
Input
File
Lazy
)
{
TEST
(
Serialize
,
Input
Stream
Lazy
)
{
TestMessageBuilder
builder
(
1
);
initTestMessage
(
builder
.
initRoot
<
TestAllTypes
>
());
Array
<
word
>
serialized
=
messageToFlatArray
(
builder
);
TestInput
File
file
(
serialized
.
asPtr
()
);
Input
FileMessageReader
reader
(
&
file
,
ReaderOptions
(),
InputStrategy
::
LAZY
);
TestInput
Stream
stream
(
serialized
.
asPtr
(),
true
);
Input
StreamMessageReader
reader
(
stream
,
ReaderOptions
()
);
checkTestMessage
(
reader
.
getRoot
<
TestAllTypes
>
());
}
TEST
(
Serialize
,
Input
File
OddSegmentCount
)
{
TEST
(
Serialize
,
Input
Stream
OddSegmentCount
)
{
TestMessageBuilder
builder
(
7
);
initTestMessage
(
builder
.
initRoot
<
TestAllTypes
>
());
Array
<
word
>
serialized
=
messageToFlatArray
(
builder
);
TestInput
File
file
(
serialized
.
asPtr
()
);
Input
FileMessageReader
reader
(
&
file
,
ReaderOptions
(),
InputStrategy
::
EAGER
);
TestInput
Stream
stream
(
serialized
.
asPtr
(),
false
);
Input
StreamMessageReader
reader
(
stream
,
ReaderOptions
()
);
checkTestMessage
(
reader
.
getRoot
<
TestAllTypes
>
());
}
TEST
(
Serialize
,
Input
File
OddSegmentCountLazy
)
{
TEST
(
Serialize
,
Input
Stream
OddSegmentCountLazy
)
{
TestMessageBuilder
builder
(
7
);
initTestMessage
(
builder
.
initRoot
<
TestAllTypes
>
());
Array
<
word
>
serialized
=
messageToFlatArray
(
builder
);
TestInput
File
file
(
serialized
.
asPtr
()
);
Input
FileMessageReader
reader
(
&
file
,
ReaderOptions
(),
InputStrategy
::
LAZY
);
TestInput
Stream
stream
(
serialized
.
asPtr
(),
true
);
Input
StreamMessageReader
reader
(
stream
,
ReaderOptions
()
);
checkTestMessage
(
reader
.
getRoot
<
TestAllTypes
>
());
}
TEST
(
Serialize
,
Input
FileEvent
SegmentCount
)
{
TEST
(
Serialize
,
Input
StreamEven
SegmentCount
)
{
TestMessageBuilder
builder
(
10
);
initTestMessage
(
builder
.
initRoot
<
TestAllTypes
>
());
Array
<
word
>
serialized
=
messageToFlatArray
(
builder
);
TestInput
File
file
(
serialized
.
asPtr
()
);
Input
FileMessageReader
reader
(
&
file
,
ReaderOptions
(),
InputStrategy
::
EAGER
);
TestInput
Stream
stream
(
serialized
.
asPtr
(),
false
);
Input
StreamMessageReader
reader
(
stream
,
ReaderOptions
()
);
checkTestMessage
(
reader
.
getRoot
<
TestAllTypes
>
());
}
TEST
(
Serialize
,
Input
FileEvent
SegmentCountLazy
)
{
TEST
(
Serialize
,
Input
StreamEven
SegmentCountLazy
)
{
TestMessageBuilder
builder
(
10
);
initTestMessage
(
builder
.
initRoot
<
TestAllTypes
>
());
Array
<
word
>
serialized
=
messageToFlatArray
(
builder
);
TestInput
File
file
(
serialized
.
asPtr
()
);
Input
FileMessageReader
reader
(
&
file
,
ReaderOptions
(),
InputStrategy
::
LAZY
);
TestInput
Stream
stream
(
serialized
.
asPtr
(),
true
);
Input
StreamMessageReader
reader
(
stream
,
ReaderOptions
()
);
checkTestMessage
(
reader
.
getRoot
<
TestAllTypes
>
());
}
...
...
@@ -324,7 +242,7 @@ TEST(Serialize, WriteMessageOddSegmentCount) {
EXPECT_TRUE
(
output
.
dataEquals
(
serialized
.
asPtr
()));
}
TEST
(
Serialize
,
WriteMessageEven
t
SegmentCount
)
{
TEST
(
Serialize
,
WriteMessageEvenSegmentCount
)
{
TestMessageBuilder
builder
(
10
);
initTestMessage
(
builder
.
initRoot
<
TestAllTypes
>
());
...
...
@@ -363,22 +281,10 @@ TEST(Serialize, FileDescriptors) {
checkTestMessage
(
reader
.
getRoot
<
TestAllTypes
>
());
}
{
FileFdMessageReader
reader
(
tmpfile
.
get
(),
0
);
checkTestMessage
(
reader
.
getRoot
<
TestAllTypes
>
());
}
size_t
secondStart
=
lseek
(
tmpfile
,
0
,
SEEK_CUR
);
{
StreamFdMessageReader
reader
(
tmpfile
.
get
());
EXPECT_EQ
(
"second message in file"
,
reader
.
getRoot
<
TestAllTypes
>
().
getTextField
());
}
{
FileFdMessageReader
reader
(
move
(
tmpfile
),
secondStart
);
EXPECT_EQ
(
"second message in file"
,
reader
.
getRoot
<
TestAllTypes
>
().
getTextField
());
}
}
// TODO: Test error cases.
...
...
c++/src/capnproto/serialize.c++
View file @
2bcb6e69
This diff is collapsed.
Click to expand it.
c++/src/capnproto/serialize.h
View file @
2bcb6e69
This diff is collapsed.
Click to expand it.
c++/src/capnproto/type-safety.h
View file @
2bcb6e69
...
...
@@ -80,6 +80,8 @@ public:
inline
T
*
begin
()
const
{
return
ptr
;
}
inline
T
*
end
()
const
{
return
ptr
+
size_
;
}
inline
T
&
front
()
const
{
return
*
ptr
;
}
inline
T
&
back
()
const
{
return
*
(
ptr
+
size_
-
1
);
}
inline
ArrayPtr
slice
(
size_t
start
,
size_t
end
)
{
CAPNPROTO_DEBUG_ASSERT
(
start
<=
end
&&
end
<=
size_
,
"Out-of-bounds ArrayPtr::slice()."
);
...
...
@@ -137,6 +139,8 @@ public:
inline
T
*
begin
()
const
{
return
ptr
;
}
inline
T
*
end
()
const
{
return
ptr
+
size_
;
}
inline
T
&
front
()
const
{
return
*
ptr
;
}
inline
T
&
back
()
const
{
return
*
(
ptr
+
size_
-
1
);
}
inline
ArrayPtr
<
T
>
slice
(
size_t
start
,
size_t
end
)
{
CAPNPROTO_DEBUG_ASSERT
(
start
<=
end
&&
end
<=
size_
,
"Out-of-bounds Array::slice()."
);
...
...
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