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
92a64de2
Commit
92a64de2
authored
Mar 01, 2013
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Standardize on Builder/Reader naming scheme.
parent
fce74ba5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
138 additions
and
136 deletions
+138
-136
wire-format.c++
c++/src/capnproto/wire-format.c++
+44
-43
wire-format.h
c++/src/capnproto/wire-format.h
+94
-93
No files found.
c++/src/capnproto/wire-format.c++
View file @
92a64de2
...
...
@@ -261,7 +261,7 @@ struct WireHelpers {
}
}
static
CAPNPROTO_ALWAYS_INLINE
(
Struct
Pt
r
initStructReference
(
static
CAPNPROTO_ALWAYS_INLINE
(
Struct
Builde
r
initStructReference
(
const
StructDescriptor
*
descriptor
,
WireReference
*
ref
,
SegmentBuilder
*
segment
))
{
if
(
ref
->
isNull
())
{
// Calculate the size of the struct.
...
...
@@ -276,8 +276,8 @@ struct WireHelpers {
// Initialize the reference.
ref
->
setStruct
(
descriptor
,
allocation
.
offset
);
// Build the Struct
Pt
r.
return
Struct
Pt
r
(
descriptor
,
segment
,
allocation
.
ptr
);
// Build the Struct
Builde
r.
return
Struct
Builde
r
(
descriptor
,
segment
,
allocation
.
ptr
);
}
else
{
followFars
(
ref
,
segment
);
...
...
@@ -290,11 +290,11 @@ struct WireHelpers {
CAPNPROTO_ASSERT
(
ref
->
structRef
.
refCount
==
fieldDescriptor
->
referenceCount
,
"Trying to update struct with incorrect reference count."
);
return
Struct
Pt
r
(
descriptor
,
segment
,
segment
->
getPtrUnchecked
(
ref
->
offset
()));
return
Struct
Builde
r
(
descriptor
,
segment
,
segment
->
getPtrUnchecked
(
ref
->
offset
()));
}
}
static
CAPNPROTO_ALWAYS_INLINE
(
List
Pt
r
initListReference
(
static
CAPNPROTO_ALWAYS_INLINE
(
List
Builde
r
initListReference
(
const
ListDescriptor
*
descriptor
,
WireReference
*
ref
,
SegmentBuilder
*
segment
,
uint32_t
elementCount
))
{
if
(
descriptor
->
elementSize
==
FieldSize
::
STRUCT
)
{
...
...
@@ -316,8 +316,8 @@ struct WireHelpers {
// Initialize the struct reference.
structRef
->
setStruct
(
elementDescriptor
,
allocation
.
offset
);
// Build the List
Pt
r.
return
List
Pt
r
(
descriptor
,
segment
,
structRef
,
elementCount
);
// Build the List
Builde
r.
return
List
Builde
r
(
descriptor
,
segment
,
structRef
,
elementCount
);
}
else
{
// Calculate size of the list.
uint32_t
size
=
divRoundingUp
<
uint32_t
>
(
...
...
@@ -329,15 +329,15 @@ struct WireHelpers {
// Initialize the reference.
ref
->
setList
(
descriptor
,
elementCount
,
allocation
.
offset
);
// Build the List
Pt
r.
return
List
Pt
r
(
descriptor
,
segment
,
allocation
.
ptr
,
elementCount
);
// Build the List
Builde
r.
return
List
Builde
r
(
descriptor
,
segment
,
allocation
.
ptr
,
elementCount
);
}
}
static
CAPNPROTO_ALWAYS_INLINE
(
List
Pt
r
getWritableListReference
(
static
CAPNPROTO_ALWAYS_INLINE
(
List
Builde
r
getWritableListReference
(
const
ListDescriptor
*
descriptor
,
WireReference
*
ref
,
SegmentBuilder
*
segment
))
{
if
(
ref
->
isNull
())
{
return
List
Pt
r
(
descriptor
,
segment
,
nullptr
,
0
);
return
List
Builde
r
(
descriptor
,
segment
,
nullptr
,
0
);
}
followFars
(
ref
,
segment
);
...
...
@@ -348,15 +348,15 @@ struct WireHelpers {
if
(
descriptor
->
elementSize
==
FieldSize
::
STRUCT
)
{
WireReference
*
structRef
=
reinterpret_cast
<
WireReference
*>
(
segment
->
getPtrUnchecked
(
ref
->
offset
()));
return
List
Pt
r
(
descriptor
,
segment
,
return
List
Builde
r
(
descriptor
,
segment
,
segment
->
getPtrUnchecked
(
structRef
->
offset
()),
ref
->
listRef
.
elementCount
());
}
else
{
return
List
Pt
r
(
descriptor
,
segment
,
return
List
Builde
r
(
descriptor
,
segment
,
segment
->
getPtrUnchecked
(
ref
->
offset
()),
ref
->
listRef
.
elementCount
());
}
}
static
CAPNPROTO_ALWAYS_INLINE
(
StructRead
Pt
r
readStructReference
(
static
CAPNPROTO_ALWAYS_INLINE
(
StructRead
e
r
readStructReference
(
const
StructDescriptor
*
descriptor
,
const
WireReference
*
ref
,
SegmentReader
*
segment
,
int
recursionLimit
))
{
do
{
...
...
@@ -398,14 +398,14 @@ struct WireHelpers {
break
;
}
return
StructRead
Pt
r
(
descriptor
,
segment
,
ptr
,
descriptor
->
defaultData
,
ref
->
structRef
.
fieldCount
.
get
(),
0
,
recursionLimit
-
1
);
return
StructRead
e
r
(
descriptor
,
segment
,
ptr
,
descriptor
->
defaultData
,
ref
->
structRef
.
fieldCount
.
get
(),
0
,
recursionLimit
-
1
);
}
while
(
false
);
return
StructRead
Pt
r
(
descriptor
,
segment
,
nullptr
,
descriptor
->
defaultData
,
0
,
0
,
0
);
return
StructRead
e
r
(
descriptor
,
segment
,
nullptr
,
descriptor
->
defaultData
,
0
,
0
,
0
);
}
static
CAPNPROTO_ALWAYS_INLINE
(
ListRead
Pt
r
readListReference
(
static
CAPNPROTO_ALWAYS_INLINE
(
ListRead
e
r
readListReference
(
const
ListDescriptor
*
descriptor
,
const
WireReference
*
ref
,
SegmentReader
*
segment
,
int
recursionLimit
))
{
do
{
...
...
@@ -500,7 +500,7 @@ struct WireHelpers {
break
;
}
return
ListRead
Pt
r
(
descriptor
,
segment
,
ptr
,
size
,
step
*
8
,
return
ListRead
e
r
(
descriptor
,
segment
,
ptr
,
size
,
step
*
8
,
ref
->
structRef
.
fieldCount
.
get
(),
recursionLimit
-
1
);
}
else
{
...
...
@@ -518,8 +518,8 @@ struct WireHelpers {
}
if
(
descriptor
->
elementSize
==
ref
->
listRef
.
elementSize
())
{
return
ListRead
Pt
r
(
descriptor
,
segment
,
ptr
,
ref
->
listRef
.
elementCount
(),
sizeInBits
(
ref
->
listRef
.
elementSize
()),
0
,
recursionLimit
);
return
ListRead
e
r
(
descriptor
,
segment
,
ptr
,
ref
->
listRef
.
elementCount
(),
sizeInBits
(
ref
->
listRef
.
elementSize
()),
0
,
recursionLimit
);
}
else
if
(
descriptor
->
elementSize
==
FieldSize
::
STRUCT
)
{
// We were expecting a struct, but we received a list of some other type. Perhaps a
// non-struct list was recently upgraded to a struct list, but the sender is using the
...
...
@@ -536,8 +536,8 @@ struct WireHelpers {
// Adjust the pointer to point where we expect it for a struct.
ptr
=
offsetPtr
<
uint8_t
>
(
ptr
,
byteOffsetForFieldZero
(
descriptor
->
elementSize
));
return
ListRead
Pt
r
(
descriptor
,
segment
,
ptr
,
ref
->
listRef
.
elementCount
(),
sizeInBits
(
ref
->
listRef
.
elementSize
()),
1
,
recursionLimit
);
return
ListRead
e
r
(
descriptor
,
segment
,
ptr
,
ref
->
listRef
.
elementCount
(),
sizeInBits
(
ref
->
listRef
.
elementSize
()),
1
,
recursionLimit
);
}
else
{
segment
->
getMessage
()
->
reportInvalidData
(
"A list had incompatible element type."
);
break
;
...
...
@@ -549,10 +549,10 @@ struct WireHelpers {
case
FieldSize
:
:
REFERENCE
:
case
FieldSize
:
:
KEY_REFERENCE
:
case
FieldSize
:
:
STRUCT
:
return
ListRead
Pt
r
(
descriptor
,
segment
,
nullptr
,
descriptor
->
defaultCount
,
0
,
0
,
return
ListRead
e
r
(
descriptor
,
segment
,
nullptr
,
descriptor
->
defaultCount
,
0
,
0
,
recursionLimit
-
1
);
default
:
return
ListRead
Pt
r
(
descriptor
,
segment
,
descriptor
->
defaultData
,
descriptor
->
defaultCount
,
return
ListRead
e
r
(
descriptor
,
segment
,
descriptor
->
defaultData
,
descriptor
->
defaultCount
,
sizeInBits
(
descriptor
->
elementSize
),
0
,
recursionLimit
-
1
);
}
}
...
...
@@ -560,30 +560,30 @@ struct WireHelpers {
// =======================================================================================
Struct
Ptr
StructPt
r
::
getStructFieldInternal
(
int
refIndex
)
const
{
Struct
Builder
StructBuilde
r
::
getStructFieldInternal
(
int
refIndex
)
const
{
return
WireHelpers
::
initStructReference
(
descriptor
->
defaultReferences
[
refIndex
]
->
asStruct
(),
reinterpret_cast
<
WireReference
*>
(
ptr
)
+
refIndex
,
segment
);
}
List
Ptr
StructPt
r
::
initListFieldInternal
(
int
refIndex
,
uint32_t
elementCount
)
const
{
List
Builder
StructBuilde
r
::
initListFieldInternal
(
int
refIndex
,
uint32_t
elementCount
)
const
{
return
WireHelpers
::
initListReference
(
descriptor
->
defaultReferences
[
refIndex
]
->
asList
(),
reinterpret_cast
<
WireReference
*>
(
ptr
)
+
refIndex
,
segment
,
elementCount
);
}
List
Ptr
StructPt
r
::
getListFieldInternal
(
int
refIndex
)
const
{
List
Builder
StructBuilde
r
::
getListFieldInternal
(
int
refIndex
)
const
{
return
WireHelpers
::
getWritableListReference
(
descriptor
->
defaultReferences
[
refIndex
]
->
asList
(),
reinterpret_cast
<
WireReference
*>
(
ptr
)
+
refIndex
,
segment
);
}
StructRead
Ptr
StructPtr
::
asReadPt
r
()
const
{
return
StructRead
Pt
r
(
descriptor
,
segment
,
ptr
,
descriptor
->
defaultData
,
descriptor
->
fieldCount
,
0
,
1
<<
30
);
StructRead
er
StructBuilder
::
asReade
r
()
const
{
return
StructRead
e
r
(
descriptor
,
segment
,
ptr
,
descriptor
->
defaultData
,
descriptor
->
fieldCount
,
0
,
1
<<
30
);
}
StructRead
Ptr
StructReadPt
r
::
getStructFieldInternal
(
int
fieldNumber
,
unsigned
int
refIndex
)
const
{
StructRead
er
StructReade
r
::
getStructFieldInternal
(
int
fieldNumber
,
unsigned
int
refIndex
)
const
{
return
WireHelpers
::
readStructReference
(
descriptor
->
defaultReferences
[
refIndex
]
->
asStruct
(),
fieldNumber
<
fieldCount
...
...
@@ -592,7 +592,7 @@ StructReadPtr StructReadPtr::getStructFieldInternal(int fieldNumber, unsigned in
segment
,
recursionLimit
);
}
ListRead
Ptr
StructReadPt
r
::
getListFieldInternal
(
int
fieldNumber
,
unsigned
int
refIndex
)
const
{
ListRead
er
StructReade
r
::
getListFieldInternal
(
int
fieldNumber
,
unsigned
int
refIndex
)
const
{
return
WireHelpers
::
readListReference
(
descriptor
->
defaultReferences
[
refIndex
]
->
asList
(),
fieldNumber
<
fieldCount
...
...
@@ -601,35 +601,36 @@ ListReadPtr StructReadPtr::getListFieldInternal(int fieldNumber, unsigned int re
segment
,
recursionLimit
);
}
StructPtr
ListPtr
::
getStructElementInternal
(
unsigned
int
index
,
uint32_t
elementWordSize
)
const
{
return
StructPtr
(
StructBuilder
ListBuilder
::
getStructElementInternal
(
unsigned
int
index
,
uint32_t
elementWordSize
)
const
{
return
StructBuilder
(
descriptor
->
elementDescriptor
->
asStruct
(),
segment
,
offsetPtr
<
uint64_t
>
(
ptr
,
elementWordSize
*
index
));
}
List
Ptr
ListPt
r
::
initListElementInternal
(
unsigned
int
index
,
uint32_t
size
)
const
{
List
Builder
ListBuilde
r
::
initListElementInternal
(
unsigned
int
index
,
uint32_t
size
)
const
{
return
WireHelpers
::
initListReference
(
descriptor
->
elementDescriptor
->
asList
(),
reinterpret_cast
<
WireReference
*>
(
ptr
)
+
index
,
segment
,
size
);
}
List
Ptr
ListPt
r
::
getListElementInternal
(
unsigned
int
index
)
const
{
List
Builder
ListBuilde
r
::
getListElementInternal
(
unsigned
int
index
)
const
{
return
WireHelpers
::
getWritableListReference
(
descriptor
->
elementDescriptor
->
asList
(),
reinterpret_cast
<
WireReference
*>
(
ptr
)
+
index
,
segment
);
}
ListRead
Ptr
ListPtr
::
asReadPt
r
()
const
{
return
ListRead
Pt
r
(
descriptor
,
segment
,
ptr
,
elementCount
,
ListRead
er
ListBuilder
::
asReade
r
()
const
{
return
ListRead
e
r
(
descriptor
,
segment
,
ptr
,
elementCount
,
sizeInBits
(
descriptor
->
elementSize
),
descriptor
->
elementSize
==
FieldSize
::
STRUCT
?
descriptor
->
elementDescriptor
->
asStruct
()
->
fieldCount
:
0
,
1
<<
30
);
}
StructRead
Ptr
ListReadPt
r
::
getStructElementInternal
(
unsigned
int
index
)
const
{
StructRead
er
ListReade
r
::
getStructElementInternal
(
unsigned
int
index
)
const
{
const
StructDescriptor
*
elementDescriptor
;
if
(
ptr
==
nullptr
)
{
elementDescriptor
=
descriptor
->
defaultReferences
()[
index
]
->
asStruct
();
...
...
@@ -641,16 +642,16 @@ StructReadPtr ListReadPtr::getStructElementInternal(unsigned int index) const {
"Message is too deeply-nested or contains cycles."
);
}
else
{
uint64_t
indexBit
=
static_cast
<
uint64_t
>
(
index
)
*
stepBits
;
return
StructRead
Pt
r
(
return
StructRead
e
r
(
elementDescriptor
,
segment
,
offsetPtr
<
uint8_t
>
(
ptr
,
indexBit
/
8
),
descriptor
->
defaultData
,
structFieldCount
,
indexBit
%
8
,
recursionLimit
-
1
);
}
}
return
StructRead
Pt
r
(
elementDescriptor
,
segment
,
nullptr
,
descriptor
->
defaultData
,
0
,
0
,
0
);
return
StructRead
e
r
(
elementDescriptor
,
segment
,
nullptr
,
descriptor
->
defaultData
,
0
,
0
,
0
);
}
ListRead
Ptr
ListReadPt
r
::
getListElementInternal
(
unsigned
int
index
,
uint32_t
size
)
const
{
ListRead
er
ListReade
r
::
getListElementInternal
(
unsigned
int
index
,
uint32_t
size
)
const
{
if
(
ptr
==
nullptr
)
{
return
WireHelpers
::
readListReference
(
descriptor
->
defaultReferences
()[
index
]
->
asList
(),
...
...
c++/src/capnproto/wire-format.h
View file @
92a64de2
...
...
@@ -65,10 +65,10 @@ namespace debug {
bool
elementsAreData
(
const
ListDescriptor
*
descriptor
,
int
bitSize
);
}
// namespace debug
class
Struct
Pt
r
;
class
StructRead
Pt
r
;
class
List
Pt
r
;
class
ListRead
Pt
r
;
class
Struct
Builde
r
;
class
StructRead
e
r
;
class
List
Builde
r
;
class
ListRead
e
r
;
struct
WireReference
;
struct
WireHelpers
;
...
...
@@ -99,7 +99,7 @@ private:
T
value
;
};
class
Struct
Pt
r
{
class
Struct
Builde
r
{
public
:
template
<
typename
T
>
inline
T
getDataField
(
unsigned
int
offset
)
const
;
...
...
@@ -110,41 +110,41 @@ public:
inline
void
setDataField
(
unsigned
int
offset
,
T
value
)
const
;
// Set the data field value at the given offset. Be careful to use the correct type.
CAPNPROTO_ALWAYS_INLINE
(
Struct
Pt
r
getStructField
(
int
refIndex
)
const
);
CAPNPROTO_ALWAYS_INLINE
(
Struct
Builde
r
getStructField
(
int
refIndex
)
const
);
// Get the struct field at the given index in the reference segment. Allocates space for the
// struct if necessary.
CAPNPROTO_ALWAYS_INLINE
(
List
Pt
r
initListField
(
int
refIndex
,
uint32_t
size
)
const
);
CAPNPROTO_ALWAYS_INLINE
(
List
Builde
r
initListField
(
int
refIndex
,
uint32_t
size
)
const
);
// Allocate a new list of the given size for the field at the given index in the reference
// segment, and return a pointer to it.
CAPNPROTO_ALWAYS_INLINE
(
List
Pt
r
getListField
(
int
refIndex
)
const
);
CAPNPROTO_ALWAYS_INLINE
(
List
Builde
r
getListField
(
int
refIndex
)
const
);
// Get the already-allocated list field for the given reference index. Returns an empty list --
// NOT necessarily the default value -- if the field is not initialized.
StructRead
Ptr
asReadPt
r
()
const
;
// Get a StructRead
Pt
r pointing at the same memory.
StructRead
er
asReade
r
()
const
;
// Get a StructRead
e
r pointing at the same memory.
private
:
const
StructDescriptor
*
descriptor
;
// Descriptor for the struct.
SegmentBuilder
*
segment
;
// Memory segment in which the struct resides.
void
*
ptr
;
// Pointer to the location between the struct's data and reference segments.
inline
Struct
Pt
r
(
const
StructDescriptor
*
descriptor
,
SegmentBuilder
*
segment
,
void
*
ptr
)
inline
Struct
Builde
r
(
const
StructDescriptor
*
descriptor
,
SegmentBuilder
*
segment
,
void
*
ptr
)
:
descriptor
(
descriptor
),
segment
(
segment
),
ptr
(
ptr
)
{}
Struct
Pt
r
getStructFieldInternal
(
int
refIndex
)
const
;
List
Pt
r
initListFieldInternal
(
int
refIndex
,
uint32_t
size
)
const
;
List
Pt
r
getListFieldInternal
(
int
refIndex
)
const
;
Struct
Builde
r
getStructFieldInternal
(
int
refIndex
)
const
;
List
Builde
r
initListFieldInternal
(
int
refIndex
,
uint32_t
size
)
const
;
List
Builde
r
getListFieldInternal
(
int
refIndex
)
const
;
// The public methods are inlined and simply wrap these "Internal" methods after doing debug
// asserts. This way, debugging is enabled by the caller's compiler flags rather than
// libcapnproto's debug flags.
friend
class
List
Pt
r
;
friend
class
List
Builde
r
;
friend
struct
WireHelpers
;
};
class
StructRead
Pt
r
{
class
StructRead
e
r
{
public
:
template
<
typename
T
>
inline
T
getDataField
(
int
fieldNumber
,
unsigned
int
offset
)
const
;
...
...
@@ -152,11 +152,11 @@ public:
// multiples of the field size, determined by the type.
CAPNPROTO_ALWAYS_INLINE
(
StructRead
Pt
r
getStructField
(
int
fieldNumber
,
unsigned
int
refIndex
)
const
);
StructRead
e
r
getStructField
(
int
fieldNumber
,
unsigned
int
refIndex
)
const
);
// Get the struct field at the given index in the reference segment, or the default value if not
// initialized.
CAPNPROTO_ALWAYS_INLINE
(
ListRead
Pt
r
getListField
(
int
fieldNumber
,
unsigned
int
refIndex
)
const
);
CAPNPROTO_ALWAYS_INLINE
(
ListRead
e
r
getListField
(
int
fieldNumber
,
unsigned
int
refIndex
)
const
);
// Get the list field at the given index in the reference segment, or the default value if not
// initialized.
...
...
@@ -180,26 +180,26 @@ private:
// Limits the depth of message structures to guard against stack-overflow-based DoS attacks.
// Once this reaches zero, further pointers will be pruned.
inline
StructRead
Pt
r
(
const
StructDescriptor
*
descriptor
,
SegmentReader
*
segment
,
const
void
*
ptr
,
const
void
*
defaultData
,
int
fieldCount
,
int
bit0Offset
,
int
recursionLimit
)
inline
StructRead
e
r
(
const
StructDescriptor
*
descriptor
,
SegmentReader
*
segment
,
const
void
*
ptr
,
const
void
*
defaultData
,
int
fieldCount
,
int
bit0Offset
,
int
recursionLimit
)
:
descriptor
(
descriptor
),
segment
(
segment
),
ptr
{
ptr
,
defaultData
},
fieldCount
(
fieldCount
),
bit0Offset
(
bit0Offset
),
recursionLimit
(
recursionLimit
)
{}
StructRead
Pt
r
getStructFieldInternal
(
int
fieldNumber
,
unsigned
int
refIndex
)
const
;
ListRead
Pt
r
getListFieldInternal
(
int
fieldNumber
,
unsigned
int
refIndex
)
const
;
StructRead
e
r
getStructFieldInternal
(
int
fieldNumber
,
unsigned
int
refIndex
)
const
;
ListRead
e
r
getListFieldInternal
(
int
fieldNumber
,
unsigned
int
refIndex
)
const
;
// The public methods are inlined and simply wrap these "Internal" methods after doing debug
// asserts. This way, debugging is enabled by the caller's compiler flags rather than
// libcapnproto's debug flags.
friend
class
ListRead
Pt
r
;
friend
class
Struct
Pt
r
;
friend
class
ListRead
e
r
;
friend
class
Struct
Builde
r
;
friend
struct
WireHelpers
;
};
// -------------------------------------------------------------------
class
List
Pt
r
{
class
List
Builde
r
{
public
:
inline
uint32_t
size
();
// The number of elements in the list.
...
...
@@ -213,18 +213,18 @@ public:
// Set the element at the given index. Be careful to use the correct type.
CAPNPROTO_ALWAYS_INLINE
(
Struct
Pt
r
getStructElement
(
unsigned
int
index
,
uint32_t
elementWordSize
)
const
);
Struct
Builde
r
getStructElement
(
unsigned
int
index
,
uint32_t
elementWordSize
)
const
);
// Get the struct element at the given index. elementWordSize is the size, in 64-bit words, of
// each element.
CAPNPROTO_ALWAYS_INLINE
(
List
Pt
r
initListElement
(
unsigned
int
index
,
uint32_t
size
)
const
);
CAPNPROTO_ALWAYS_INLINE
(
List
Builde
r
initListElement
(
unsigned
int
index
,
uint32_t
size
)
const
);
// Create a new list element of the given size at the given index.
CAPNPROTO_ALWAYS_INLINE
(
List
Pt
r
getListElement
(
unsigned
int
index
)
const
);
CAPNPROTO_ALWAYS_INLINE
(
List
Builde
r
getListElement
(
unsigned
int
index
)
const
);
// Get the existing list element at the given index.
ListRead
Ptr
asReadPt
r
()
const
;
// Get a ListRead
Pt
r pointing at the same memory.
ListRead
er
asReade
r
()
const
;
// Get a ListRead
e
r pointing at the same memory.
private
:
const
ListDescriptor
*
descriptor
;
// Descriptor for the list.
...
...
@@ -232,22 +232,22 @@ private:
void
*
ptr
;
// Pointer to the beginning of the list.
uint32_t
elementCount
;
// Number of elements in the list.
inline
List
Pt
r
(
const
ListDescriptor
*
descriptor
,
SegmentBuilder
*
segment
,
void
*
ptr
,
uint32_t
size
)
inline
List
Builde
r
(
const
ListDescriptor
*
descriptor
,
SegmentBuilder
*
segment
,
void
*
ptr
,
uint32_t
size
)
:
descriptor
(
descriptor
),
segment
(
segment
),
ptr
(
ptr
),
elementCount
(
size
)
{}
Struct
Pt
r
getStructElementInternal
(
unsigned
int
index
,
uint32_t
elementWordSize
)
const
;
List
Pt
r
initListElementInternal
(
unsigned
int
index
,
uint32_t
size
)
const
;
List
Pt
r
getListElementInternal
(
unsigned
int
index
)
const
;
Struct
Builde
r
getStructElementInternal
(
unsigned
int
index
,
uint32_t
elementWordSize
)
const
;
List
Builde
r
initListElementInternal
(
unsigned
int
index
,
uint32_t
size
)
const
;
List
Builde
r
getListElementInternal
(
unsigned
int
index
)
const
;
// The public methods are inlined and simply wrap these "Internal" methods after doing debug
// asserts. This way, debugging is enabled by the caller's compiler flags rather than
// libcapnproto's debug flags.
friend
class
Struct
Pt
r
;
friend
class
Struct
Builde
r
;
friend
struct
WireHelpers
;
};
class
ListRead
Pt
r
{
class
ListRead
e
r
{
public
:
inline
uint32_t
size
();
// The number of elements in the list.
...
...
@@ -256,10 +256,10 @@ public:
CAPNPROTO_ALWAYS_INLINE
(
T
getDataElement
(
unsigned
int
index
)
const
);
// Get the element of the given type at the given index.
CAPNPROTO_ALWAYS_INLINE
(
StructRead
Pt
r
getStructElement
(
unsigned
int
index
)
const
);
CAPNPROTO_ALWAYS_INLINE
(
StructRead
e
r
getStructElement
(
unsigned
int
index
)
const
);
// Get the struct element at the given index.
CAPNPROTO_ALWAYS_INLINE
(
ListRead
Pt
r
getListElement
(
unsigned
int
index
,
uint32_t
size
)
const
);
CAPNPROTO_ALWAYS_INLINE
(
ListRead
e
r
getListElement
(
unsigned
int
index
,
uint32_t
size
)
const
);
// Get the list element at the given index.
private
:
...
...
@@ -283,20 +283,20 @@ private:
// Limits the depth of message structures to guard against stack-overflow-based DoS attacks.
// Once this reaches zero, further pointers will be pruned.
inline
ListRead
Pt
r
(
const
ListDescriptor
*
descriptor
,
SegmentReader
*
segment
,
const
void
*
ptr
,
uint32_t
size
,
int
stepBits
,
int
structFieldCount
,
int
recursionLimit
)
inline
ListRead
e
r
(
const
ListDescriptor
*
descriptor
,
SegmentReader
*
segment
,
const
void
*
ptr
,
uint32_t
size
,
int
stepBits
,
int
structFieldCount
,
int
recursionLimit
)
:
descriptor
(
descriptor
),
segment
(
segment
),
ptr
(
ptr
),
elementCount
(
size
),
stepBits
(
stepBits
),
structFieldCount
(
structFieldCount
),
recursionLimit
(
recursionLimit
)
{}
StructRead
Pt
r
getStructElementInternal
(
unsigned
int
index
)
const
;
ListRead
Pt
r
getListElementInternal
(
unsigned
int
index
,
uint32_t
size
)
const
;
StructRead
e
r
getStructElementInternal
(
unsigned
int
index
)
const
;
ListRead
e
r
getListElementInternal
(
unsigned
int
index
,
uint32_t
size
)
const
;
// The public methods are inlined and simply wrap these "Internal" methods after doing debug
// asserts. This way, debugging is enabled by the caller's compiler flags rather than
// libcapnproto's debug flags.
friend
class
StructRead
Pt
r
;
friend
class
List
Pt
r
;
friend
class
StructRead
e
r
;
friend
class
List
Builde
r
;
friend
struct
WireHelpers
;
};
...
...
@@ -304,69 +304,69 @@ private:
// Internal implementation details...
template
<
typename
T
>
inline
T
Struct
Pt
r
::
getDataField
(
unsigned
int
offset
)
const
{
inline
T
Struct
Builde
r
::
getDataField
(
unsigned
int
offset
)
const
{
CAPNPROTO_DEBUG_ASSERT
(
debug
::
dataFieldInRange
(
descriptor
,
offset
,
sizeof
(
T
)),
"Struct
Pt
r::getDataField() type mismatch."
);
"Struct
Builde
r::getDataField() type mismatch."
);
return
reinterpret_cast
<
WireValue
<
T
>*>
(
ptr
)[
-
offset
].
get
();
}
template
<>
inline
bool
Struct
Pt
r
::
getDataField
<
bool
>
(
unsigned
int
offset
)
const
{
inline
bool
Struct
Builde
r
::
getDataField
<
bool
>
(
unsigned
int
offset
)
const
{
CAPNPROTO_DEBUG_ASSERT
(
debug
::
bitFieldInRange
(
descriptor
,
offset
),
"Struct
Pt
r::getDataField<bool>() type mismatch."
);
"Struct
Builde
r::getDataField<bool>() type mismatch."
);
uint8_t
byte
=
*
(
reinterpret_cast
<
uint8_t
*>
(
ptr
)
-
(
offset
/
8
)
-
1
);
return
(
byte
&
(
1
<<
(
offset
%
8
)))
!=
0
;
}
template
<
typename
T
>
inline
void
Struct
Pt
r
::
setDataField
(
unsigned
int
offset
,
T
value
)
const
{
inline
void
Struct
Builde
r
::
setDataField
(
unsigned
int
offset
,
T
value
)
const
{
CAPNPROTO_DEBUG_ASSERT
(
debug
::
dataFieldInRange
(
descriptor
,
offset
,
sizeof
(
T
)),
"Struct
Pt
r::setDataField() type mismatch."
);
"Struct
Builde
r::setDataField() type mismatch."
);
reinterpret_cast
<
WireValue
<
T
>*>
(
ptr
)[
-
offset
].
set
(
value
);
}
template
<>
inline
void
Struct
Pt
r
::
setDataField
<
bool
>
(
unsigned
int
offset
,
bool
value
)
const
{
inline
void
Struct
Builde
r
::
setDataField
<
bool
>
(
unsigned
int
offset
,
bool
value
)
const
{
CAPNPROTO_DEBUG_ASSERT
(
debug
::
bitFieldInRange
(
descriptor
,
offset
),
"Struct
Pt
r::setDataField<bool>() type mismatch."
);
"Struct
Builde
r::setDataField<bool>() type mismatch."
);
uint8_t
*
byte
=
reinterpret_cast
<
uint8_t
*>
(
ptr
)
-
(
offset
/
8
)
-
1
;
*
byte
=
(
*
byte
&
~
(
1
<<
(
offset
%
8
)))
|
(
static_cast
<
uint8_t
>
(
value
)
<<
(
offset
%
8
));
}
inline
Struct
Ptr
StructPt
r
::
getStructField
(
int
refIndex
)
const
{
inline
Struct
Builder
StructBuilde
r
::
getStructField
(
int
refIndex
)
const
{
CAPNPROTO_DEBUG_ASSERT
(
debug
::
refFieldIsStruct
(
descriptor
,
refIndex
),
"Struct
Pt
r::getStructField() type mismatch."
);
"Struct
Builde
r::getStructField() type mismatch."
);
return
getStructFieldInternal
(
refIndex
);
}
inline
List
Ptr
StructPt
r
::
initListField
(
int
refIndex
,
uint32_t
elementCount
)
const
{
inline
List
Builder
StructBuilde
r
::
initListField
(
int
refIndex
,
uint32_t
elementCount
)
const
{
CAPNPROTO_DEBUG_ASSERT
(
debug
::
refFieldIsList
(
descriptor
,
refIndex
),
"Struct
Pt
r::initListField() type mismatch."
);
"Struct
Builde
r::initListField() type mismatch."
);
return
initListFieldInternal
(
refIndex
,
elementCount
);
}
inline
List
Ptr
StructPt
r
::
getListField
(
int
refIndex
)
const
{
inline
List
Builder
StructBuilde
r
::
getListField
(
int
refIndex
)
const
{
CAPNPROTO_DEBUG_ASSERT
(
debug
::
refFieldIsList
(
descriptor
,
refIndex
),
"Struct
Pt
r::initListField() type mismatch."
);
"Struct
Builde
r::initListField() type mismatch."
);
return
getListFieldInternal
(
refIndex
);
}
// -------------------------------------------------------------------
template
<
typename
T
>
T
StructRead
Pt
r
::
getDataField
(
int
fieldNumber
,
unsigned
int
offset
)
const
{
T
StructRead
e
r
::
getDataField
(
int
fieldNumber
,
unsigned
int
offset
)
const
{
CAPNPROTO_DEBUG_ASSERT
(
debug
::
fieldIsData
(
descriptor
,
fieldNumber
,
offset
,
sizeof
(
T
)
*
8
),
"StructRead
Pt
r::getDataField() type mismatch."
);
"StructRead
e
r::getDataField() type mismatch."
);
const
void
*
dataPtr
=
ptr
[
fieldNumber
>=
fieldCount
];
return
reinterpret_cast
<
WireValue
<
T
>*>
(
dataPtr
)[
-
offset
].
get
();
}
template
<>
inline
bool
StructRead
Pt
r
::
getDataField
<
bool
>
(
int
fieldNumber
,
unsigned
int
offset
)
const
{
inline
bool
StructRead
e
r
::
getDataField
<
bool
>
(
int
fieldNumber
,
unsigned
int
offset
)
const
{
CAPNPROTO_DEBUG_ASSERT
(
debug
::
fieldIsData
(
descriptor
,
fieldNumber
,
offset
,
1
),
"StructRead
Pt
r::getDataField<bool>() type mismatch."
);
"StructRead
e
r::getDataField<bool>() type mismatch."
);
// This branch should always be optimized away when inlining.
if
(
offset
==
0
)
offset
=
bit0Offset
;
...
...
@@ -376,106 +376,107 @@ inline bool StructReadPtr::getDataField<bool>(int fieldNumber, unsigned int offs
return
(
byte
&
(
1
<<
(
offset
%
8
)))
!=
0
;
}
inline
StructRead
Ptr
StructReadPt
r
::
getStructField
(
int
fieldNumber
,
unsigned
int
refIndex
)
const
{
inline
StructRead
er
StructReade
r
::
getStructField
(
int
fieldNumber
,
unsigned
int
refIndex
)
const
{
CAPNPROTO_DEBUG_ASSERT
(
debug
::
fieldIsStruct
(
descriptor
,
fieldNumber
,
refIndex
),
"StructRead
Pt
r::getStructField() type mismatch."
);
"StructRead
e
r::getStructField() type mismatch."
);
return
getStructFieldInternal
(
fieldNumber
,
refIndex
);
}
inline
ListRead
Ptr
StructReadPt
r
::
getListField
(
int
fieldNumber
,
unsigned
int
refIndex
)
const
{
inline
ListRead
er
StructReade
r
::
getListField
(
int
fieldNumber
,
unsigned
int
refIndex
)
const
{
CAPNPROTO_DEBUG_ASSERT
(
debug
::
fieldIsList
(
descriptor
,
fieldNumber
,
refIndex
),
"StructRead
Pt
r::getListField() type mismatch."
);
"StructRead
e
r::getListField() type mismatch."
);
return
getListFieldInternal
(
fieldNumber
,
refIndex
);
}
// -------------------------------------------------------------------
inline
uint32_t
List
Pt
r
::
size
()
{
return
elementCount
;
}
inline
uint32_t
List
Builde
r
::
size
()
{
return
elementCount
;
}
template
<
typename
T
>
inline
T
List
Pt
r
::
getDataElement
(
unsigned
int
index
)
const
{
inline
T
List
Builde
r
::
getDataElement
(
unsigned
int
index
)
const
{
CAPNPROTO_DEBUG_ASSERT
(
debug
::
elementsAreData
(
descriptor
,
sizeof
(
T
)
*
8
),
"List
Pt
r::getDataElement() type mismatch."
);
"List
Builde
r::getDataElement() type mismatch."
);
return
reinterpret_cast
<
WireValue
<
T
>*>
(
ptr
)[
index
].
get
();
}
template
<>
inline
bool
List
Pt
r
::
getDataElement
<
bool
>
(
unsigned
int
index
)
const
{
inline
bool
List
Builde
r
::
getDataElement
<
bool
>
(
unsigned
int
index
)
const
{
CAPNPROTO_DEBUG_ASSERT
(
debug
::
elementsAreData
(
descriptor
,
1
),
"List
Pt
r::getDataElement<bool>() type mismatch."
);
"List
Builde
r::getDataElement<bool>() type mismatch."
);
uint8_t
byte
=
*
(
reinterpret_cast
<
uint8_t
*>
(
ptr
)
+
(
index
/
8
));
return
(
byte
&
(
1
<<
(
index
%
8
)))
!=
0
;
}
template
<
typename
T
>
inline
void
List
Pt
r
::
setDataElement
(
unsigned
int
index
,
T
value
)
const
{
inline
void
List
Builde
r
::
setDataElement
(
unsigned
int
index
,
T
value
)
const
{
CAPNPROTO_DEBUG_ASSERT
(
debug
::
elementsAreData
(
descriptor
,
sizeof
(
T
)
*
8
),
"List
Pt
r::setDataElement() type mismatch."
);
"List
Builde
r::setDataElement() type mismatch."
);
reinterpret_cast
<
WireValue
<
T
>*>
(
ptr
)[
index
].
set
(
value
);
}
template
<>
inline
void
List
Pt
r
::
setDataElement
<
bool
>
(
unsigned
int
index
,
bool
value
)
const
{
inline
void
List
Builde
r
::
setDataElement
<
bool
>
(
unsigned
int
index
,
bool
value
)
const
{
CAPNPROTO_DEBUG_ASSERT
(
debug
::
elementsAreData
(
descriptor
,
1
),
"List
Pt
r::setDataElement<bool>() type mismatch."
);
"List
Builde
r::setDataElement<bool>() type mismatch."
);
uint8_t
*
byte
=
reinterpret_cast
<
uint8_t
*>
(
ptr
)
+
(
index
/
8
);
*
byte
=
(
*
byte
&
~
(
1
<<
(
index
%
8
)))
|
(
static_cast
<
uint8_t
>
(
value
)
<<
(
index
%
8
));
}
inline
StructPtr
ListPtr
::
getStructElement
(
unsigned
int
index
,
uint32_t
elementWordSize
)
const
{
inline
StructBuilder
ListBuilder
::
getStructElement
(
unsigned
int
index
,
uint32_t
elementWordSize
)
const
{
CAPNPROTO_DEBUG_ASSERT
(
index
<
elementCount
,
"List index out of range."
);
CAPNPROTO_DEBUG_ASSERT
(
debug
::
elementsAreStructs
(
descriptor
,
elementWordSize
),
"List
Pt
r::getStructElement() type mismatch."
);
"List
Builde
r::getStructElement() type mismatch."
);
return
getStructElementInternal
(
index
,
elementWordSize
);
}
inline
List
Ptr
ListPt
r
::
initListElement
(
unsigned
int
index
,
uint32_t
size
)
const
{
inline
List
Builder
ListBuilde
r
::
initListElement
(
unsigned
int
index
,
uint32_t
size
)
const
{
CAPNPROTO_DEBUG_ASSERT
(
index
<
elementCount
,
"List index out of range."
);
CAPNPROTO_DEBUG_ASSERT
(
debug
::
elementsAreLists
(
descriptor
),
"List
Pt
r::initListElement() type mismatch."
);
"List
Builde
r::initListElement() type mismatch."
);
return
initListElementInternal
(
index
,
size
);
}
inline
List
Ptr
ListPt
r
::
getListElement
(
unsigned
int
index
)
const
{
inline
List
Builder
ListBuilde
r
::
getListElement
(
unsigned
int
index
)
const
{
CAPNPROTO_DEBUG_ASSERT
(
index
<
elementCount
,
"List index out of range."
);
CAPNPROTO_DEBUG_ASSERT
(
debug
::
elementsAreLists
(
descriptor
),
"List
Pt
r::getListElement() type mismatch."
);
"List
Builde
r::getListElement() type mismatch."
);
return
getListElementInternal
(
index
);
}
// -------------------------------------------------------------------
inline
uint32_t
ListRead
Pt
r
::
size
()
{
return
elementCount
;
}
inline
uint32_t
ListRead
e
r
::
size
()
{
return
elementCount
;
}
template
<
typename
T
>
inline
T
ListRead
Pt
r
::
getDataElement
(
unsigned
int
index
)
const
{
inline
T
ListRead
e
r
::
getDataElement
(
unsigned
int
index
)
const
{
CAPNPROTO_DEBUG_ASSERT
(
debug
::
elementsAreData
(
descriptor
,
sizeof
(
T
)
*
8
),
"ListRead
Pt
r::getDataElement() type mismatch."
);
"ListRead
e
r::getDataElement() type mismatch."
);
return
*
reinterpret_cast
<
const
T
*>
(
reinterpret_cast
<
const
uint8_t
*>
(
ptr
)
+
index
*
(
stepBits
/
8
));
}
template
<>
inline
bool
ListRead
Pt
r
::
getDataElement
<
bool
>
(
unsigned
int
index
)
const
{
inline
bool
ListRead
e
r
::
getDataElement
<
bool
>
(
unsigned
int
index
)
const
{
CAPNPROTO_DEBUG_ASSERT
(
debug
::
elementsAreData
(
descriptor
,
1
),
"ListRead
Pt
r::getDataElement<bool>() type mismatch."
);
"ListRead
e
r::getDataElement<bool>() type mismatch."
);
unsigned
int
bitIndex
=
index
*
stepBits
;
uint8_t
byte
=
*
(
reinterpret_cast
<
const
uint8_t
*>
(
ptr
)
+
(
bitIndex
/
8
));
return
(
byte
&
(
1
<<
(
bitIndex
%
8
)))
!=
0
;
}
inline
StructRead
Ptr
ListReadPt
r
::
getStructElement
(
unsigned
int
index
)
const
{
inline
StructRead
er
ListReade
r
::
getStructElement
(
unsigned
int
index
)
const
{
CAPNPROTO_DEBUG_ASSERT
(
index
<
elementCount
,
"List index out of range."
);
CAPNPROTO_DEBUG_ASSERT
(
debug
::
elementsAreStructs
(
descriptor
),
"ListRead
Pt
r::getStructElement() type mismatch."
);
"ListRead
e
r::getStructElement() type mismatch."
);
return
getStructElementInternal
(
index
);
}
inline
ListRead
Ptr
ListReadPt
r
::
getListElement
(
unsigned
int
index
,
uint32_t
size
)
const
{
inline
ListRead
er
ListReade
r
::
getListElement
(
unsigned
int
index
,
uint32_t
size
)
const
{
CAPNPROTO_DEBUG_ASSERT
(
index
<
elementCount
,
"List index out of range."
);
CAPNPROTO_DEBUG_ASSERT
(
debug
::
elementsAreLists
(
descriptor
),
"ListRead
Pt
r::getListElement() type mismatch."
);
"ListRead
e
r::getListElement() type mismatch."
);
return
getListElementInternal
(
index
,
size
);
}
...
...
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