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
5f07c032
Commit
5f07c032
authored
Nov 09, 2014
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Mass-rename capnp::_::FieldSize -> capnp::ElementSize.
parent
9c54bce6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
179 additions
and
184 deletions
+179
-184
capability.h
c++/src/capnp/capability.h
+3
-3
dynamic.c++
c++/src/capnp/dynamic.c++
+30
-30
layout-test.c++
c++/src/capnp/layout-test.c++
+10
-10
layout.c++
c++/src/capnp/layout.c++
+97
-97
layout.h
c++/src/capnp/layout.h
+32
-37
list.h
c++/src/capnp/list.h
+7
-7
No files found.
c++/src/capnp/capability.h
View file @
5f07c032
...
...
@@ -564,14 +564,14 @@ struct List<T, Kind::INTERFACE> {
private
:
inline
static
_
::
ListBuilder
initPointer
(
_
::
PointerBuilder
builder
,
uint
size
)
{
return
builder
.
initList
(
_
::
Field
Size
::
POINTER
,
size
*
ELEMENTS
);
return
builder
.
initList
(
Element
Size
::
POINTER
,
size
*
ELEMENTS
);
}
inline
static
_
::
ListBuilder
getFromPointer
(
_
::
PointerBuilder
builder
,
const
word
*
defaultValue
)
{
return
builder
.
getList
(
_
::
Field
Size
::
POINTER
,
defaultValue
);
return
builder
.
getList
(
Element
Size
::
POINTER
,
defaultValue
);
}
inline
static
_
::
ListReader
getFromPointer
(
const
_
::
PointerReader
&
reader
,
const
word
*
defaultValue
)
{
return
reader
.
getList
(
_
::
Field
Size
::
POINTER
,
defaultValue
);
return
reader
.
getList
(
Element
Size
::
POINTER
,
defaultValue
);
}
template
<
typename
U
,
Kind
k
>
...
...
c++/src/capnp/dynamic.c++
View file @
5f07c032
...
...
@@ -67,32 +67,32 @@ inline uint64_t bitCast<uint64_t, double>(double value) {
return
result
;
}
_
::
Field
Size
elementSizeFor
(
schema
::
Type
::
Which
elementType
)
{
Element
Size
elementSizeFor
(
schema
::
Type
::
Which
elementType
)
{
switch
(
elementType
)
{
case
schema
:
:
Type
::
VOID
:
return
_
::
Field
Size
::
VOID
;
case
schema
:
:
Type
::
BOOL
:
return
_
::
Field
Size
::
BIT
;
case
schema
:
:
Type
::
INT8
:
return
_
::
Field
Size
::
BYTE
;
case
schema
:
:
Type
::
INT16
:
return
_
::
Field
Size
::
TWO_BYTES
;
case
schema
:
:
Type
::
INT32
:
return
_
::
Field
Size
::
FOUR_BYTES
;
case
schema
:
:
Type
::
INT64
:
return
_
::
Field
Size
::
EIGHT_BYTES
;
case
schema
:
:
Type
::
UINT8
:
return
_
::
Field
Size
::
BYTE
;
case
schema
:
:
Type
::
UINT16
:
return
_
::
Field
Size
::
TWO_BYTES
;
case
schema
:
:
Type
::
UINT32
:
return
_
::
Field
Size
::
FOUR_BYTES
;
case
schema
:
:
Type
::
UINT64
:
return
_
::
Field
Size
::
EIGHT_BYTES
;
case
schema
:
:
Type
::
FLOAT32
:
return
_
::
Field
Size
::
FOUR_BYTES
;
case
schema
:
:
Type
::
FLOAT64
:
return
_
::
Field
Size
::
EIGHT_BYTES
;
case
schema
:
:
Type
::
TEXT
:
return
_
::
Field
Size
::
POINTER
;
case
schema
:
:
Type
::
DATA
:
return
_
::
Field
Size
::
POINTER
;
case
schema
:
:
Type
::
LIST
:
return
_
::
Field
Size
::
POINTER
;
case
schema
:
:
Type
::
ENUM
:
return
_
::
Field
Size
::
TWO_BYTES
;
case
schema
:
:
Type
::
STRUCT
:
return
_
::
Field
Size
::
INLINE_COMPOSITE
;
case
schema
:
:
Type
::
INTERFACE
:
return
_
::
Field
Size
::
POINTER
;
case
schema
:
:
Type
::
VOID
:
return
Element
Size
::
VOID
;
case
schema
:
:
Type
::
BOOL
:
return
Element
Size
::
BIT
;
case
schema
:
:
Type
::
INT8
:
return
Element
Size
::
BYTE
;
case
schema
:
:
Type
::
INT16
:
return
Element
Size
::
TWO_BYTES
;
case
schema
:
:
Type
::
INT32
:
return
Element
Size
::
FOUR_BYTES
;
case
schema
:
:
Type
::
INT64
:
return
Element
Size
::
EIGHT_BYTES
;
case
schema
:
:
Type
::
UINT8
:
return
Element
Size
::
BYTE
;
case
schema
:
:
Type
::
UINT16
:
return
Element
Size
::
TWO_BYTES
;
case
schema
:
:
Type
::
UINT32
:
return
Element
Size
::
FOUR_BYTES
;
case
schema
:
:
Type
::
UINT64
:
return
Element
Size
::
EIGHT_BYTES
;
case
schema
:
:
Type
::
FLOAT32
:
return
Element
Size
::
FOUR_BYTES
;
case
schema
:
:
Type
::
FLOAT64
:
return
Element
Size
::
EIGHT_BYTES
;
case
schema
:
:
Type
::
TEXT
:
return
Element
Size
::
POINTER
;
case
schema
:
:
Type
::
DATA
:
return
Element
Size
::
POINTER
;
case
schema
:
:
Type
::
LIST
:
return
Element
Size
::
POINTER
;
case
schema
:
:
Type
::
ENUM
:
return
Element
Size
::
TWO_BYTES
;
case
schema
:
:
Type
::
STRUCT
:
return
Element
Size
::
INLINE_COMPOSITE
;
case
schema
:
:
Type
::
INTERFACE
:
return
Element
Size
::
POINTER
;
case
schema
:
:
Type
::
ANY_POINTER
:
KJ_FAIL_ASSERT
(
"List(AnyPointer) not supported."
);
break
;
}
// Unknown type. Treat it as zero-size.
return
_
::
Field
Size
::
VOID
;
return
Element
Size
::
VOID
;
}
inline
_
::
StructSize
structSizeFromSchema
(
StructSchema
schema
)
{
...
...
@@ -1293,15 +1293,15 @@ Orphan<DynamicValue> DynamicList::Builder::disown(uint index) {
case
schema
:
:
Type
::
ENUM
:
{
auto
result
=
Orphan
<
DynamicValue
>
(
operator
[](
index
),
_
::
OrphanBuilder
());
switch
(
elementSizeFor
(
schema
.
whichElementType
()))
{
case
_
:
:
Field
Size
::
VOID
:
break
;
case
_
:
:
Field
Size
::
BIT
:
builder
.
setDataElement
<
bool
>
(
index
*
ELEMENTS
,
false
);
break
;
case
_
:
:
Field
Size
::
BYTE
:
builder
.
setDataElement
<
uint8_t
>
(
index
*
ELEMENTS
,
0
);
break
;
case
_
:
:
Field
Size
::
TWO_BYTES
:
builder
.
setDataElement
<
uint16_t
>
(
index
*
ELEMENTS
,
0
);
break
;
case
_
:
:
Field
Size
::
FOUR_BYTES
:
builder
.
setDataElement
<
uint32_t
>
(
index
*
ELEMENTS
,
0
);
break
;
case
_
:
:
Field
Size
::
EIGHT_BYTES
:
builder
.
setDataElement
<
uint64_t
>
(
index
*
ELEMENTS
,
0
);
break
;
case
_
:
:
Field
Size
::
POINTER
:
case
_
:
:
Field
Size
::
INLINE_COMPOSITE
:
case
Element
Size
:
:
VOID
:
break
;
case
Element
Size
:
:
BIT
:
builder
.
setDataElement
<
bool
>
(
index
*
ELEMENTS
,
false
);
break
;
case
Element
Size
:
:
BYTE
:
builder
.
setDataElement
<
uint8_t
>
(
index
*
ELEMENTS
,
0
);
break
;
case
Element
Size
:
:
TWO_BYTES
:
builder
.
setDataElement
<
uint16_t
>
(
index
*
ELEMENTS
,
0
);
break
;
case
Element
Size
:
:
FOUR_BYTES
:
builder
.
setDataElement
<
uint32_t
>
(
index
*
ELEMENTS
,
0
);
break
;
case
Element
Size
:
:
EIGHT_BYTES
:
builder
.
setDataElement
<
uint64_t
>
(
index
*
ELEMENTS
,
0
);
break
;
case
Element
Size
:
:
POINTER
:
case
Element
Size
:
:
INLINE_COMPOSITE
:
KJ_UNREACHABLE
;
}
return
kj
::
mv
(
result
);
...
...
c++/src/capnp/layout-test.c++
View file @
5f07c032
...
...
@@ -124,7 +124,7 @@ static void setupStruct(StructBuilder builder) {
{
ListBuilder
list
=
builder
.
getPointerField
(
1
*
POINTERS
)
.
initList
(
Field
Size
::
FOUR_BYTES
,
3
*
ELEMENTS
);
.
initList
(
Element
Size
::
FOUR_BYTES
,
3
*
ELEMENTS
);
EXPECT_EQ
(
3
*
ELEMENTS
,
list
.
size
());
list
.
setDataElement
<
int32_t
>
(
0
*
ELEMENTS
,
200
);
list
.
setDataElement
<
int32_t
>
(
1
*
ELEMENTS
,
201
);
...
...
@@ -146,11 +146,11 @@ static void setupStruct(StructBuilder builder) {
{
ListBuilder
list
=
builder
.
getPointerField
(
3
*
POINTERS
)
.
initList
(
Field
Size
::
POINTER
,
5
*
ELEMENTS
);
.
initList
(
Element
Size
::
POINTER
,
5
*
ELEMENTS
);
EXPECT_EQ
(
5
*
ELEMENTS
,
list
.
size
());
for
(
uint
i
=
0
;
i
<
5
;
i
++
)
{
ListBuilder
element
=
list
.
getPointerElement
(
i
*
ELEMENTS
)
.
initList
(
Field
Size
::
TWO_BYTES
,
(
i
+
1
)
*
ELEMENTS
);
.
initList
(
Element
Size
::
TWO_BYTES
,
(
i
+
1
)
*
ELEMENTS
);
EXPECT_EQ
((
i
+
1
)
*
ELEMENTS
,
element
.
size
());
for
(
uint
j
=
0
;
j
<=
i
;
j
++
)
{
element
.
setDataElement
<
uint16_t
>
(
j
*
ELEMENTS
,
500
+
j
);
...
...
@@ -181,7 +181,7 @@ static void checkStruct(StructBuilder builder) {
{
ListBuilder
list
=
builder
.
getPointerField
(
1
*
POINTERS
)
.
getList
(
Field
Size
::
FOUR_BYTES
,
nullptr
);
.
getList
(
Element
Size
::
FOUR_BYTES
,
nullptr
);
ASSERT_EQ
(
3
*
ELEMENTS
,
list
.
size
());
EXPECT_EQ
(
200
,
list
.
getDataElement
<
int32_t
>
(
0
*
ELEMENTS
));
EXPECT_EQ
(
201
,
list
.
getDataElement
<
int32_t
>
(
1
*
ELEMENTS
));
...
...
@@ -204,11 +204,11 @@ static void checkStruct(StructBuilder builder) {
}
{
ListBuilder
list
=
builder
.
getPointerField
(
3
*
POINTERS
).
getList
(
Field
Size
::
POINTER
,
nullptr
);
ListBuilder
list
=
builder
.
getPointerField
(
3
*
POINTERS
).
getList
(
Element
Size
::
POINTER
,
nullptr
);
ASSERT_EQ
(
5
*
ELEMENTS
,
list
.
size
());
for
(
uint
i
=
0
;
i
<
5
;
i
++
)
{
ListBuilder
element
=
list
.
getPointerElement
(
i
*
ELEMENTS
)
.
getList
(
Field
Size
::
TWO_BYTES
,
nullptr
);
.
getList
(
Element
Size
::
TWO_BYTES
,
nullptr
);
ASSERT_EQ
((
i
+
1
)
*
ELEMENTS
,
element
.
size
());
for
(
uint
j
=
0
;
j
<=
i
;
j
++
)
{
EXPECT_EQ
(
500u
+
j
,
element
.
getDataElement
<
uint16_t
>
(
j
*
ELEMENTS
));
...
...
@@ -238,7 +238,7 @@ static void checkStruct(StructReader reader) {
}
{
ListReader
list
=
reader
.
getPointerField
(
1
*
POINTERS
).
getList
(
Field
Size
::
FOUR_BYTES
,
nullptr
);
ListReader
list
=
reader
.
getPointerField
(
1
*
POINTERS
).
getList
(
Element
Size
::
FOUR_BYTES
,
nullptr
);
ASSERT_EQ
(
3
*
ELEMENTS
,
list
.
size
());
EXPECT_EQ
(
200
,
list
.
getDataElement
<
int32_t
>
(
0
*
ELEMENTS
));
EXPECT_EQ
(
201
,
list
.
getDataElement
<
int32_t
>
(
1
*
ELEMENTS
));
...
...
@@ -247,7 +247,7 @@ static void checkStruct(StructReader reader) {
{
ListReader
list
=
reader
.
getPointerField
(
2
*
POINTERS
)
.
getList
(
Field
Size
::
INLINE_COMPOSITE
,
nullptr
);
.
getList
(
Element
Size
::
INLINE_COMPOSITE
,
nullptr
);
ASSERT_EQ
(
4
*
ELEMENTS
,
list
.
size
());
for
(
int
i
=
0
;
i
<
4
;
i
++
)
{
StructReader
element
=
list
.
getStructElement
(
i
*
ELEMENTS
);
...
...
@@ -260,11 +260,11 @@ static void checkStruct(StructReader reader) {
}
{
ListReader
list
=
reader
.
getPointerField
(
3
*
POINTERS
).
getList
(
Field
Size
::
POINTER
,
nullptr
);
ListReader
list
=
reader
.
getPointerField
(
3
*
POINTERS
).
getList
(
Element
Size
::
POINTER
,
nullptr
);
ASSERT_EQ
(
5
*
ELEMENTS
,
list
.
size
());
for
(
uint
i
=
0
;
i
<
5
;
i
++
)
{
ListReader
element
=
list
.
getPointerElement
(
i
*
ELEMENTS
)
.
getList
(
Field
Size
::
TWO_BYTES
,
nullptr
);
.
getList
(
Element
Size
::
TWO_BYTES
,
nullptr
);
ASSERT_EQ
((
i
+
1
)
*
ELEMENTS
,
element
.
size
());
for
(
uint
j
=
0
;
j
<=
i
;
j
++
)
{
EXPECT_EQ
(
500u
+
j
,
element
.
getDataElement
<
uint16_t
>
(
j
*
ELEMENTS
));
...
...
c++/src/capnp/layout.c++
View file @
5f07c032
...
...
@@ -199,8 +199,8 @@ struct WirePointer {
struct
ListRef
{
WireValue
<
uint32_t
>
elementSizeAndCount
;
KJ_ALWAYS_INLINE
(
Field
Size
elementSize
()
const
)
{
return
static_cast
<
Field
Size
>
(
elementSizeAndCount
.
get
()
&
7
);
KJ_ALWAYS_INLINE
(
Element
Size
elementSize
()
const
)
{
return
static_cast
<
Element
Size
>
(
elementSizeAndCount
.
get
()
&
7
);
}
KJ_ALWAYS_INLINE
(
ElementCount
elementCount
()
const
)
{
return
(
elementSizeAndCount
.
get
()
>>
3
)
*
ELEMENTS
;
...
...
@@ -209,7 +209,7 @@ struct WirePointer {
return
elementCount
()
*
(
1
*
WORDS
/
ELEMENTS
);
}
KJ_ALWAYS_INLINE
(
void
set
(
Field
Size
es
,
ElementCount
ec
))
{
KJ_ALWAYS_INLINE
(
void
set
(
Element
Size
es
,
ElementCount
ec
))
{
KJ_DREQUIRE
(
ec
<
(
1
<<
29
)
*
ELEMENTS
,
"Lists are limited to 2**29 elements."
);
elementSizeAndCount
.
set
(((
ec
/
ELEMENTS
)
<<
3
)
|
static_cast
<
int
>
(
es
));
}
...
...
@@ -217,7 +217,7 @@ struct WirePointer {
KJ_ALWAYS_INLINE
(
void
setInlineComposite
(
WordCount
wc
))
{
KJ_DREQUIRE
(
wc
<
(
1
<<
29
)
*
WORDS
,
"Inline composite lists are limited to 2**29 words."
);
elementSizeAndCount
.
set
(((
wc
/
WORDS
)
<<
3
)
|
static_cast
<
int
>
(
Field
Size
::
INLINE_COMPOSITE
));
static_cast
<
int
>
(
Element
Size
::
INLINE_COMPOSITE
));
}
};
...
...
@@ -521,20 +521,20 @@ struct WireHelpers {
}
case
WirePointer
:
:
LIST
:
{
switch
(
tag
->
listRef
.
elementSize
())
{
case
Field
Size
:
:
VOID
:
case
Element
Size
:
:
VOID
:
// Nothing.
break
;
case
Field
Size
:
:
BIT
:
case
Field
Size
:
:
BYTE
:
case
Field
Size
:
:
TWO_BYTES
:
case
Field
Size
:
:
FOUR_BYTES
:
case
Field
Size
:
:
EIGHT_BYTES
:
case
Element
Size
:
:
BIT
:
case
Element
Size
:
:
BYTE
:
case
Element
Size
:
:
TWO_BYTES
:
case
Element
Size
:
:
FOUR_BYTES
:
case
Element
Size
:
:
EIGHT_BYTES
:
memset
(
ptr
,
0
,
roundBitsUpToWords
(
ElementCount64
(
tag
->
listRef
.
elementCount
())
*
dataBitsPerElement
(
tag
->
listRef
.
elementSize
()))
*
BYTES_PER_WORD
/
BYTES
);
break
;
case
Field
Size
:
:
POINTER
:
{
case
Element
Size
:
:
POINTER
:
{
uint
count
=
tag
->
listRef
.
elementCount
()
/
ELEMENTS
;
for
(
uint
i
=
0
;
i
<
count
;
i
++
)
{
zeroObject
(
segment
,
reinterpret_cast
<
WirePointer
*>
(
ptr
)
+
i
);
...
...
@@ -542,7 +542,7 @@ struct WireHelpers {
memset
(
ptr
,
0
,
POINTER_SIZE_IN_WORDS
*
count
*
BYTES_PER_WORD
/
BYTES
);
break
;
}
case
Field
Size
:
:
INLINE_COMPOSITE
:
{
case
Element
Size
:
:
INLINE_COMPOSITE
:
{
WirePointer
*
elementTag
=
reinterpret_cast
<
WirePointer
*>
(
ptr
);
KJ_ASSERT
(
elementTag
->
kind
()
==
WirePointer
::
STRUCT
,
...
...
@@ -634,14 +634,14 @@ struct WireHelpers {
}
case
WirePointer
:
:
LIST
:
{
switch
(
ref
->
listRef
.
elementSize
())
{
case
Field
Size
:
:
VOID
:
case
Element
Size
:
:
VOID
:
// Nothing.
break
;
case
Field
Size
:
:
BIT
:
case
Field
Size
:
:
BYTE
:
case
Field
Size
:
:
TWO_BYTES
:
case
Field
Size
:
:
FOUR_BYTES
:
case
Field
Size
:
:
EIGHT_BYTES
:
{
case
Element
Size
:
:
BIT
:
case
Element
Size
:
:
BYTE
:
case
Element
Size
:
:
TWO_BYTES
:
case
Element
Size
:
:
FOUR_BYTES
:
case
Element
Size
:
:
EIGHT_BYTES
:
{
WordCount64
totalWords
=
roundBitsUpToWords
(
ElementCount64
(
ref
->
listRef
.
elementCount
())
*
dataBitsPerElement
(
ref
->
listRef
.
elementSize
()));
...
...
@@ -652,7 +652,7 @@ struct WireHelpers {
result
.
wordCount
+=
totalWords
;
break
;
}
case
Field
Size
:
:
POINTER
:
{
case
Element
Size
:
:
POINTER
:
{
WirePointerCount
count
=
ref
->
listRef
.
elementCount
()
*
(
POINTERS
/
ELEMENTS
);
KJ_REQUIRE
(
boundsCheck
(
segment
,
ptr
,
ptr
+
count
*
WORDS_PER_POINTER
),
...
...
@@ -668,7 +668,7 @@ struct WireHelpers {
}
break
;
}
case
Field
Size
:
:
INLINE_COMPOSITE
:
{
case
Element
Size
:
:
INLINE_COMPOSITE
:
{
WordCount
wordCount
=
ref
->
listRef
.
inlineCompositeWordCount
();
KJ_REQUIRE
(
boundsCheck
(
segment
,
ptr
,
ptr
+
wordCount
+
POINTER_SIZE_IN_WORDS
),
"Message contained out-of-bounds list pointer."
)
{
...
...
@@ -766,12 +766,12 @@ struct WireHelpers {
}
case
WirePointer
:
:
LIST
:
{
switch
(
src
->
listRef
.
elementSize
())
{
case
Field
Size
:
:
VOID
:
case
Field
Size
:
:
BIT
:
case
Field
Size
:
:
BYTE
:
case
Field
Size
:
:
TWO_BYTES
:
case
Field
Size
:
:
FOUR_BYTES
:
case
Field
Size
:
:
EIGHT_BYTES
:
{
case
Element
Size
:
:
VOID
:
case
Element
Size
:
:
BIT
:
case
Element
Size
:
:
BYTE
:
case
Element
Size
:
:
TWO_BYTES
:
case
Element
Size
:
:
FOUR_BYTES
:
case
Element
Size
:
:
EIGHT_BYTES
:
{
WordCount
wordCount
=
roundBitsUpToWords
(
ElementCount64
(
src
->
listRef
.
elementCount
())
*
dataBitsPerElement
(
src
->
listRef
.
elementSize
()));
...
...
@@ -783,7 +783,7 @@ struct WireHelpers {
return
dstPtr
;
}
case
Field
Size
:
:
POINTER
:
{
case
Element
Size
:
:
POINTER
:
{
const
WirePointer
*
srcRefs
=
reinterpret_cast
<
const
WirePointer
*>
(
src
->
target
());
WirePointer
*
dstRefs
=
reinterpret_cast
<
WirePointer
*>
(
allocate
(
dst
,
segment
,
src
->
listRef
.
elementCount
()
*
...
...
@@ -797,11 +797,11 @@ struct WireHelpers {
copyMessage
(
subSegment
,
dstRef
,
srcRefs
+
i
);
}
dst
->
listRef
.
set
(
Field
Size
::
POINTER
,
src
->
listRef
.
elementCount
());
dst
->
listRef
.
set
(
Element
Size
::
POINTER
,
src
->
listRef
.
elementCount
());
return
reinterpret_cast
<
word
*>
(
dstRefs
);
}
case
Field
Size
:
:
INLINE_COMPOSITE
:
{
case
Element
Size
:
:
INLINE_COMPOSITE
:
{
const
word
*
srcPtr
=
src
->
target
();
word
*
dstPtr
=
allocate
(
dst
,
segment
,
src
->
listRef
.
inlineCompositeWordCount
()
+
POINTER_SIZE_IN_WORDS
,
...
...
@@ -998,8 +998,8 @@ struct WireHelpers {
static
KJ_ALWAYS_INLINE
(
ListBuilder
initListPointer
(
WirePointer
*
ref
,
SegmentBuilder
*
segment
,
ElementCount
elementCount
,
Field
Size
elementSize
,
BuilderArena
*
orphanArena
=
nullptr
))
{
KJ_DREQUIRE
(
elementSize
!=
Field
Size
::
INLINE_COMPOSITE
,
Element
Size
elementSize
,
BuilderArena
*
orphanArena
=
nullptr
))
{
KJ_DREQUIRE
(
elementSize
!=
Element
Size
::
INLINE_COMPOSITE
,
"Should have called initStructListPointer() instead."
);
BitCount
dataSize
=
dataBitsPerElement
(
elementSize
)
*
ELEMENTS
;
...
...
@@ -1042,20 +1042,20 @@ struct WireHelpers {
// Build the ListBuilder.
return
ListBuilder
(
segment
,
ptr
,
wordsPerElement
*
BITS_PER_WORD
,
elementCount
,
elementSize
.
data
*
BITS_PER_WORD
,
elementSize
.
pointers
,
Field
Size
::
INLINE_COMPOSITE
);
Element
Size
::
INLINE_COMPOSITE
);
}
static
KJ_ALWAYS_INLINE
(
ListBuilder
getWritableListPointer
(
WirePointer
*
origRef
,
SegmentBuilder
*
origSegment
,
Field
Size
elementSize
,
WirePointer
*
origRef
,
SegmentBuilder
*
origSegment
,
Element
Size
elementSize
,
const
word
*
defaultValue
))
{
return
getWritableListPointer
(
origRef
,
origRef
->
target
(),
origSegment
,
elementSize
,
defaultValue
);
}
static
KJ_ALWAYS_INLINE
(
ListBuilder
getWritableListPointer
(
WirePointer
*
origRef
,
word
*
origRefTarget
,
SegmentBuilder
*
origSegment
,
Field
Size
elementSize
,
WirePointer
*
origRef
,
word
*
origRefTarget
,
SegmentBuilder
*
origSegment
,
Element
Size
elementSize
,
const
word
*
defaultValue
,
BuilderArena
*
orphanArena
=
nullptr
))
{
KJ_DREQUIRE
(
elementSize
!=
Field
Size
::
INLINE_COMPOSITE
,
KJ_DREQUIRE
(
elementSize
!=
Element
Size
::
INLINE_COMPOSITE
,
"Use getStructList{Element,Field}() for structs."
);
if
(
origRef
->
isNull
())
{
...
...
@@ -1083,9 +1083,9 @@ struct WireHelpers {
goto
useDefault
;
}
Field
Size
oldSize
=
ref
->
listRef
.
elementSize
();
Element
Size
oldSize
=
ref
->
listRef
.
elementSize
();
if
(
oldSize
==
Field
Size
::
INLINE_COMPOSITE
)
{
if
(
oldSize
==
Element
Size
::
INLINE_COMPOSITE
)
{
// The existing element size is INLINE_COMPOSITE, though we expected a list of primitives.
// The existing data must have been written with a newer version of the protocol. We
// therefore never need to upgrade the data in this case, but we do need to validate that it
...
...
@@ -1101,11 +1101,11 @@ struct WireHelpers {
WirePointerCount
pointerCount
=
tag
->
structRef
.
ptrCount
.
get
();
switch
(
elementSize
)
{
case
Field
Size
:
:
VOID
:
case
Element
Size
:
:
VOID
:
// Anything is a valid upgrade from Void.
break
;
case
Field
Size
:
:
BIT
:
case
Element
Size
:
:
BIT
:
KJ_FAIL_REQUIRE
(
"Found struct list where bit list was expected; upgrading boolean lists to structs "
"is no longer supported."
)
{
...
...
@@ -1113,17 +1113,17 @@ struct WireHelpers {
}
break
;
case
Field
Size
:
:
BYTE
:
case
Field
Size
:
:
TWO_BYTES
:
case
Field
Size
:
:
FOUR_BYTES
:
case
Field
Size
:
:
EIGHT_BYTES
:
case
Element
Size
:
:
BYTE
:
case
Element
Size
:
:
TWO_BYTES
:
case
Element
Size
:
:
FOUR_BYTES
:
case
Element
Size
:
:
EIGHT_BYTES
:
KJ_REQUIRE
(
dataSize
>=
1
*
WORDS
,
"Existing list value is incompatible with expected type."
)
{
goto
useDefault
;
}
break
;
case
Field
Size
:
:
POINTER
:
case
Element
Size
:
:
POINTER
:
KJ_REQUIRE
(
pointerCount
>=
1
*
POINTERS
,
"Existing list value is incompatible with expected type."
)
{
goto
useDefault
;
...
...
@@ -1132,7 +1132,7 @@ struct WireHelpers {
ptr
+=
dataSize
;
break
;
case
Field
Size
:
:
INLINE_COMPOSITE
:
case
Element
Size
:
:
INLINE_COMPOSITE
:
KJ_UNREACHABLE
;
}
...
...
@@ -1141,18 +1141,18 @@ struct WireHelpers {
return
ListBuilder
(
segment
,
ptr
,
tag
->
structRef
.
wordSize
()
*
BITS_PER_WORD
/
ELEMENTS
,
tag
->
inlineCompositeListElementCount
(),
dataSize
*
BITS_PER_WORD
,
pointerCount
,
Field
Size
::
INLINE_COMPOSITE
);
dataSize
*
BITS_PER_WORD
,
pointerCount
,
Element
Size
::
INLINE_COMPOSITE
);
}
else
{
BitCount
dataSize
=
dataBitsPerElement
(
oldSize
)
*
ELEMENTS
;
WirePointerCount
pointerCount
=
pointersPerElement
(
oldSize
)
*
ELEMENTS
;
if
(
elementSize
==
Field
Size
::
BIT
)
{
KJ_REQUIRE
(
oldSize
==
Field
Size
::
BIT
,
if
(
elementSize
==
Element
Size
::
BIT
)
{
KJ_REQUIRE
(
oldSize
==
Element
Size
::
BIT
,
"Found non-bit list where bit list was expected."
)
{
goto
useDefault
;
}
}
else
{
KJ_REQUIRE
(
oldSize
!=
Field
Size
::
BIT
,
KJ_REQUIRE
(
oldSize
!=
Element
Size
::
BIT
,
"Found bit list where non-bit list was expected."
)
{
goto
useDefault
;
}
...
...
@@ -1200,9 +1200,9 @@ struct WireHelpers {
goto
useDefault
;
}
Field
Size
elementSize
=
ref
->
listRef
.
elementSize
();
Element
Size
elementSize
=
ref
->
listRef
.
elementSize
();
if
(
elementSize
==
Field
Size
::
INLINE_COMPOSITE
)
{
if
(
elementSize
==
Element
Size
::
INLINE_COMPOSITE
)
{
// Read the tag to get the actual element count.
WirePointer
*
tag
=
reinterpret_cast
<
WirePointer
*>
(
ptr
);
KJ_REQUIRE
(
tag
->
kind
()
==
WirePointer
::
STRUCT
,
...
...
@@ -1213,7 +1213,7 @@ struct WireHelpers {
tag
->
structRef
.
wordSize
()
*
BITS_PER_WORD
/
ELEMENTS
,
tag
->
inlineCompositeListElementCount
(),
tag
->
structRef
.
dataSize
.
get
()
*
BITS_PER_WORD
,
tag
->
structRef
.
ptrCount
.
get
(),
Field
Size
::
INLINE_COMPOSITE
);
tag
->
structRef
.
ptrCount
.
get
(),
Element
Size
::
INLINE_COMPOSITE
);
}
else
{
BitCount
dataSize
=
dataBitsPerElement
(
elementSize
)
*
ELEMENTS
;
WirePointerCount
pointerCount
=
pointersPerElement
(
elementSize
)
*
ELEMENTS
;
...
...
@@ -1255,9 +1255,9 @@ struct WireHelpers {
goto
useDefault
;
}
Field
Size
oldSize
=
oldRef
->
listRef
.
elementSize
();
Element
Size
oldSize
=
oldRef
->
listRef
.
elementSize
();
if
(
oldSize
==
Field
Size
::
INLINE_COMPOSITE
)
{
if
(
oldSize
==
Element
Size
::
INLINE_COMPOSITE
)
{
// Existing list is INLINE_COMPOSITE, but we need to verify that the sizes match.
WirePointer
*
oldTag
=
reinterpret_cast
<
WirePointer
*>
(
oldPtr
);
...
...
@@ -1276,7 +1276,7 @@ struct WireHelpers {
// Old size is at least as large as we need. Ship it.
return
ListBuilder
(
oldSegment
,
oldPtr
,
oldStep
*
BITS_PER_WORD
,
elementCount
,
oldDataSize
*
BITS_PER_WORD
,
oldPointerCount
,
Field
Size
::
INLINE_COMPOSITE
);
Element
Size
::
INLINE_COMPOSITE
);
}
// The structs in this list are smaller than expected, probably written using an older
...
...
@@ -1321,7 +1321,7 @@ struct WireHelpers {
memset
(
oldPtr
,
0
,
oldStep
*
elementCount
*
BYTES_PER_WORD
/
BYTES
);
return
ListBuilder
(
origSegment
,
newPtr
,
newStep
*
BITS_PER_WORD
,
elementCount
,
newDataSize
*
BITS_PER_WORD
,
newPointerCount
,
Field
Size
::
INLINE_COMPOSITE
);
newDataSize
*
BITS_PER_WORD
,
newPointerCount
,
Element
Size
::
INLINE_COMPOSITE
);
}
else
{
// We're upgrading from a non-struct list.
...
...
@@ -1330,13 +1330,13 @@ struct WireHelpers {
auto
oldStep
=
(
oldDataSize
+
oldPointerCount
*
BITS_PER_POINTER
)
/
ELEMENTS
;
ElementCount
elementCount
=
oldRef
->
listRef
.
elementCount
();
if
(
oldSize
==
Field
Size
::
VOID
)
{
if
(
oldSize
==
Element
Size
::
VOID
)
{
// Nothing to copy, just allocate a new list.
return
initStructListPointer
(
origRef
,
origSegment
,
elementCount
,
elementSize
);
}
else
{
// Upgrading to an inline composite list.
KJ_REQUIRE
(
oldSize
!=
Field
Size
::
BIT
,
KJ_REQUIRE
(
oldSize
!=
Element
Size
::
BIT
,
"Found bit list where struct list was expected; upgrading boolean lists to structs "
"is no longer supported."
)
{
goto
useDefault
;
...
...
@@ -1345,7 +1345,7 @@ struct WireHelpers {
WordCount
newDataSize
=
elementSize
.
data
;
WirePointerCount
newPointerCount
=
elementSize
.
pointers
;
if
(
oldSize
==
Field
Size
::
POINTER
)
{
if
(
oldSize
==
Element
Size
::
POINTER
)
{
newPointerCount
=
std
::
max
(
newPointerCount
,
1
*
POINTERS
);
}
else
{
// Old list contains data elements, so we need at least 1 word of data.
...
...
@@ -1367,7 +1367,7 @@ struct WireHelpers {
tag
->
structRef
.
set
(
newDataSize
,
newPointerCount
);
newPtr
+=
POINTER_SIZE_IN_WORDS
;
if
(
oldSize
==
Field
Size
::
POINTER
)
{
if
(
oldSize
==
Element
Size
::
POINTER
)
{
WirePointer
*
dst
=
reinterpret_cast
<
WirePointer
*>
(
newPtr
+
newDataSize
);
WirePointer
*
src
=
reinterpret_cast
<
WirePointer
*>
(
oldPtr
);
for
(
uint
i
=
0
;
i
<
elementCount
/
ELEMENTS
;
i
++
)
{
...
...
@@ -1375,7 +1375,7 @@ struct WireHelpers {
dst
+=
newStep
/
WORDS_PER_POINTER
*
(
1
*
ELEMENTS
);
++
src
;
}
}
else
if
(
oldSize
==
Field
Size
::
BIT
)
{
}
else
if
(
oldSize
==
Element
Size
::
BIT
)
{
word
*
dst
=
newPtr
;
char
*
src
=
reinterpret_cast
<
char
*>
(
oldPtr
);
for
(
uint
i
=
0
;
i
<
elementCount
/
ELEMENTS
;
i
++
)
{
...
...
@@ -1398,7 +1398,7 @@ struct WireHelpers {
return
ListBuilder
(
origSegment
,
newPtr
,
newStep
*
BITS_PER_WORD
,
elementCount
,
newDataSize
*
BITS_PER_WORD
,
newPointerCount
,
Field
Size
::
INLINE_COMPOSITE
);
Element
Size
::
INLINE_COMPOSITE
);
}
}
}
...
...
@@ -1414,7 +1414,7 @@ struct WireHelpers {
ref
,
segment
,
roundBytesUpToWords
(
byteSize
),
WirePointer
::
LIST
,
orphanArena
);
// Initialize the pointer.
ref
->
listRef
.
set
(
Field
Size
::
BYTE
,
byteSize
*
(
1
*
ELEMENTS
/
BYTES
));
ref
->
listRef
.
set
(
Element
Size
::
BYTE
,
byteSize
*
(
1
*
ELEMENTS
/
BYTES
));
// Build the Text::Builder. This will initialize the NUL terminator.
return
{
segment
,
Text
::
Builder
(
reinterpret_cast
<
char
*>
(
ptr
),
size
/
BYTES
)
};
...
...
@@ -1450,7 +1450,7 @@ struct WireHelpers {
KJ_REQUIRE
(
ref
->
kind
()
==
WirePointer
::
LIST
,
"Called getText{Field,Element}() but existing pointer is not a list."
);
KJ_REQUIRE
(
ref
->
listRef
.
elementSize
()
==
Field
Size
::
BYTE
,
KJ_REQUIRE
(
ref
->
listRef
.
elementSize
()
==
Element
Size
::
BYTE
,
"Called getText{Field,Element}() but existing list pointer is not byte-sized."
);
// Subtract 1 from the size for the NUL terminator.
...
...
@@ -1465,7 +1465,7 @@ struct WireHelpers {
word
*
ptr
=
allocate
(
ref
,
segment
,
roundBytesUpToWords
(
size
),
WirePointer
::
LIST
,
orphanArena
);
// Initialize the pointer.
ref
->
listRef
.
set
(
Field
Size
::
BYTE
,
size
*
(
1
*
ELEMENTS
/
BYTES
));
ref
->
listRef
.
set
(
Element
Size
::
BYTE
,
size
*
(
1
*
ELEMENTS
/
BYTES
));
// Build the Data::Builder.
return
{
segment
,
Data
::
Builder
(
reinterpret_cast
<
byte
*>
(
ptr
),
size
/
BYTES
)
};
...
...
@@ -1501,7 +1501,7 @@ struct WireHelpers {
KJ_REQUIRE
(
ref
->
kind
()
==
WirePointer
::
LIST
,
"Called getData{Field,Element}() but existing pointer is not a list."
);
KJ_REQUIRE
(
ref
->
listRef
.
elementSize
()
==
Field
Size
::
BYTE
,
KJ_REQUIRE
(
ref
->
listRef
.
elementSize
()
==
Element
Size
::
BYTE
,
"Called getData{Field,Element}() but existing list pointer is not byte-sized."
);
return
Data
::
Builder
(
reinterpret_cast
<
byte
*>
(
ptr
),
ref
->
listRef
.
elementCount
()
/
ELEMENTS
);
...
...
@@ -1549,13 +1549,13 @@ struct WireHelpers {
BuilderArena
*
orphanArena
=
nullptr
)
{
WordCount
totalSize
=
roundBitsUpToWords
(
value
.
elementCount
*
value
.
step
);
if
(
value
.
elementSize
!=
Field
Size
::
INLINE_COMPOSITE
)
{
if
(
value
.
elementSize
!=
Element
Size
::
INLINE_COMPOSITE
)
{
// List of non-structs.
word
*
ptr
=
allocate
(
ref
,
segment
,
totalSize
,
WirePointer
::
LIST
,
orphanArena
);
if
(
value
.
elementSize
==
Field
Size
::
POINTER
)
{
if
(
value
.
elementSize
==
Element
Size
::
POINTER
)
{
// List of pointers.
ref
->
listRef
.
set
(
Field
Size
::
POINTER
,
value
.
elementCount
);
ref
->
listRef
.
set
(
Element
Size
::
POINTER
,
value
.
elementCount
);
for
(
uint
i
=
0
;
i
<
value
.
elementCount
/
ELEMENTS
;
i
++
)
{
copyPointer
(
segment
,
reinterpret_cast
<
WirePointer
*>
(
ptr
)
+
i
,
value
.
segment
,
reinterpret_cast
<
const
WirePointer
*>
(
value
.
ptr
)
+
i
,
...
...
@@ -1647,14 +1647,14 @@ struct WireHelpers {
orphanArena
);
case
WirePointer
:
:
LIST
:
{
Field
Size
elementSize
=
src
->
listRef
.
elementSize
();
Element
Size
elementSize
=
src
->
listRef
.
elementSize
();
KJ_REQUIRE
(
nestingLimit
>
0
,
"Message is too deeply-nested or contains cycles. See capnp::ReaderOptions."
)
{
goto
useDefault
;
}
if
(
elementSize
==
Field
Size
::
INLINE_COMPOSITE
)
{
if
(
elementSize
==
Element
Size
::
INLINE_COMPOSITE
)
{
WordCount
wordCount
=
src
->
listRef
.
inlineCompositeWordCount
();
const
WirePointer
*
tag
=
reinterpret_cast
<
const
WirePointer
*>
(
ptr
);
ptr
+=
POINTER_SIZE_IN_WORDS
;
...
...
@@ -1680,7 +1680,7 @@ struct WireHelpers {
return
setListPointer
(
dstSegment
,
dst
,
ListReader
(
srcSegment
,
ptr
,
elementCount
,
wordsPerElement
*
BITS_PER_WORD
,
tag
->
structRef
.
dataSize
.
get
()
*
BITS_PER_WORD
,
tag
->
structRef
.
ptrCount
.
get
(),
Field
Size
::
INLINE_COMPOSITE
,
tag
->
structRef
.
ptrCount
.
get
(),
Element
Size
::
INLINE_COMPOSITE
,
nestingLimit
-
1
),
orphanArena
);
}
else
{
...
...
@@ -1862,14 +1862,14 @@ struct WireHelpers {
static
KJ_ALWAYS_INLINE
(
ListReader
readListPointer
(
SegmentReader
*
segment
,
const
WirePointer
*
ref
,
const
word
*
defaultValue
,
Field
Size
expectedElementSize
,
int
nestingLimit
,
bool
checkElementSize
=
true
))
{
Element
Size
expectedElementSize
,
int
nestingLimit
,
bool
checkElementSize
=
true
))
{
return
readListPointer
(
segment
,
ref
,
ref
->
target
(),
defaultValue
,
expectedElementSize
,
nestingLimit
,
checkElementSize
);
}
static
KJ_ALWAYS_INLINE
(
ListReader
readListPointer
(
SegmentReader
*
segment
,
const
WirePointer
*
ref
,
const
word
*
refTarget
,
const
word
*
defaultValue
,
Field
Size
expectedElementSize
,
int
nestingLimit
,
const
word
*
defaultValue
,
Element
Size
expectedElementSize
,
int
nestingLimit
,
bool
checkElementSize
=
true
))
{
if
(
ref
->
isNull
())
{
useDefault
:
...
...
@@ -1899,8 +1899,8 @@ struct WireHelpers {
goto
useDefault
;
}
Field
Size
elementSize
=
ref
->
listRef
.
elementSize
();
if
(
elementSize
==
Field
Size
::
INLINE_COMPOSITE
)
{
Element
Size
elementSize
=
ref
->
listRef
.
elementSize
();
if
(
elementSize
==
Element
Size
::
INLINE_COMPOSITE
)
{
decltype
(
WORDS
/
ELEMENTS
)
wordsPerElement
;
ElementCount
size
;
...
...
@@ -1936,10 +1936,10 @@ struct WireHelpers {
// Check whether the size is compatible.
switch
(
expectedElementSize
)
{
case
Field
Size
:
:
VOID
:
case
Element
Size
:
:
VOID
:
break
;
case
Field
Size
:
:
BIT
:
case
Element
Size
:
:
BIT
:
KJ_FAIL_REQUIRE
(
"Found struct list where bit list was expected; upgrading boolean lists to structs "
"is no longer supported."
)
{
...
...
@@ -1947,17 +1947,17 @@ struct WireHelpers {
}
break
;
case
Field
Size
:
:
BYTE
:
case
Field
Size
:
:
TWO_BYTES
:
case
Field
Size
:
:
FOUR_BYTES
:
case
Field
Size
:
:
EIGHT_BYTES
:
case
Element
Size
:
:
BYTE
:
case
Element
Size
:
:
TWO_BYTES
:
case
Element
Size
:
:
FOUR_BYTES
:
case
Element
Size
:
:
EIGHT_BYTES
:
KJ_REQUIRE
(
tag
->
structRef
.
dataSize
.
get
()
>
0
*
WORDS
,
"Expected a primitive list, but got a list of pointer-only structs."
)
{
goto
useDefault
;
}
break
;
case
Field
Size
:
:
POINTER
:
case
Element
Size
:
:
POINTER
:
// We expected a list of pointers but got a list of structs. Assuming the first field
// in the struct is the pointer we were looking for, we want to munge the pointer to
// point at the first element's pointer section.
...
...
@@ -1968,7 +1968,7 @@ struct WireHelpers {
}
break
;
case
Field
Size
:
:
INLINE_COMPOSITE
:
case
Element
Size
:
:
INLINE_COMPOSITE
:
break
;
}
}
...
...
@@ -1976,7 +1976,7 @@ struct WireHelpers {
return
ListReader
(
segment
,
ptr
,
size
,
wordsPerElement
*
BITS_PER_WORD
,
tag
->
structRef
.
dataSize
.
get
()
*
BITS_PER_WORD
,
tag
->
structRef
.
ptrCount
.
get
(),
Field
Size
::
INLINE_COMPOSITE
,
tag
->
structRef
.
ptrCount
.
get
(),
Element
Size
::
INLINE_COMPOSITE
,
nestingLimit
-
1
);
}
else
{
...
...
@@ -1994,7 +1994,7 @@ struct WireHelpers {
}
if
(
checkElementSize
)
{
if
(
elementSize
==
FieldSize
::
BIT
&&
expectedElementSize
!=
Field
Size
::
BIT
)
{
if
(
elementSize
==
ElementSize
::
BIT
&&
expectedElementSize
!=
Element
Size
::
BIT
)
{
KJ_FAIL_REQUIRE
(
"Found bit list where struct list was expected; upgrading boolean lists to structs "
"is no longer supported."
)
{
...
...
@@ -2055,7 +2055,7 @@ struct WireHelpers {
goto
useDefault
;
}
KJ_REQUIRE
(
ref
->
listRef
.
elementSize
()
==
Field
Size
::
BYTE
,
KJ_REQUIRE
(
ref
->
listRef
.
elementSize
()
==
Element
Size
::
BYTE
,
"Message contains list pointer of non-bytes where text was expected."
)
{
goto
useDefault
;
}
...
...
@@ -2108,7 +2108,7 @@ struct WireHelpers {
goto
useDefault
;
}
KJ_REQUIRE
(
ref
->
listRef
.
elementSize
()
==
Field
Size
::
BYTE
,
KJ_REQUIRE
(
ref
->
listRef
.
elementSize
()
==
Element
Size
::
BYTE
,
"Message contains list pointer of non-bytes where data was expected."
)
{
goto
useDefault
;
}
...
...
@@ -2135,7 +2135,7 @@ StructBuilder PointerBuilder::getStruct(StructSize size, const word* defaultValu
return
WireHelpers
::
getWritableStructPointer
(
pointer
,
segment
,
size
,
defaultValue
);
}
ListBuilder
PointerBuilder
::
initList
(
Field
Size
elementSize
,
ElementCount
elementCount
)
{
ListBuilder
PointerBuilder
::
initList
(
Element
Size
elementSize
,
ElementCount
elementCount
)
{
return
WireHelpers
::
initListPointer
(
pointer
,
segment
,
elementCount
,
elementSize
);
}
...
...
@@ -2143,7 +2143,7 @@ ListBuilder PointerBuilder::initStructList(ElementCount elementCount, StructSize
return
WireHelpers
::
initStructListPointer
(
pointer
,
segment
,
elementCount
,
elementSize
);
}
ListBuilder
PointerBuilder
::
getList
(
Field
Size
elementSize
,
const
word
*
defaultValue
)
{
ListBuilder
PointerBuilder
::
getList
(
Element
Size
elementSize
,
const
word
*
defaultValue
)
{
return
WireHelpers
::
getWritableListPointer
(
pointer
,
segment
,
elementSize
,
defaultValue
);
}
...
...
@@ -2273,7 +2273,7 @@ StructReader PointerReader::getStruct(const word* defaultValue) const {
return
WireHelpers
::
readStructPointer
(
segment
,
ref
,
defaultValue
,
nestingLimit
);
}
ListReader
PointerReader
::
getList
(
Field
Size
expectedElementSize
,
const
word
*
defaultValue
)
const
{
ListReader
PointerReader
::
getList
(
Element
Size
expectedElementSize
,
const
word
*
defaultValue
)
const
{
const
WirePointer
*
ref
=
pointer
==
nullptr
?
&
zero
.
pointer
:
pointer
;
return
WireHelpers
::
readListPointer
(
segment
,
ref
,
defaultValue
,
expectedElementSize
,
nestingLimit
);
...
...
@@ -2282,7 +2282,7 @@ ListReader PointerReader::getList(FieldSize expectedElementSize, const word* def
ListReader
PointerReader
::
getListAnySize
(
const
word
*
defaultValue
)
const
{
const
WirePointer
*
ref
=
pointer
==
nullptr
?
&
zero
.
pointer
:
pointer
;
return
WireHelpers
::
readListPointer
(
segment
,
ref
,
defaultValue
,
Field
Size
::
VOID
/* dummy */
,
nestingLimit
,
false
);
segment
,
ref
,
defaultValue
,
Element
Size
::
VOID
/* dummy */
,
nestingLimit
,
false
);
}
template
<>
...
...
@@ -2580,7 +2580,7 @@ OrphanBuilder OrphanBuilder::initStruct(BuilderArena* arena, StructSize size) {
}
OrphanBuilder
OrphanBuilder
::
initList
(
BuilderArena
*
arena
,
ElementCount
elementCount
,
Field
Size
elementSize
)
{
BuilderArena
*
arena
,
ElementCount
elementCount
,
Element
Size
elementSize
)
{
OrphanBuilder
result
;
ListBuilder
builder
=
WireHelpers
::
initListPointer
(
result
.
tagAsPtr
(),
nullptr
,
elementCount
,
elementSize
,
arena
);
...
...
@@ -2677,7 +2677,7 @@ OrphanBuilder OrphanBuilder::referenceExternalData(BuilderArena* arena, Data::Re
OrphanBuilder
result
;
result
.
tagAsPtr
()
->
setKindForOrphan
(
WirePointer
::
LIST
);
result
.
tagAsPtr
()
->
listRef
.
set
(
Field
Size
::
BYTE
,
data
.
size
()
*
ELEMENTS
);
result
.
tagAsPtr
()
->
listRef
.
set
(
Element
Size
::
BYTE
,
data
.
size
()
*
ELEMENTS
);
result
.
segment
=
arena
->
addExternalSegment
(
words
);
// const_cast OK here because we will check whether the segment is writable when we try to get
...
...
@@ -2699,7 +2699,7 @@ StructBuilder OrphanBuilder::asStruct(StructSize size) {
return
result
;
}
ListBuilder
OrphanBuilder
::
asList
(
Field
Size
elementSize
)
{
ListBuilder
OrphanBuilder
::
asList
(
Element
Size
elementSize
)
{
KJ_DASSERT
(
tagAsPtr
()
->
isNull
()
==
(
location
==
nullptr
));
ListBuilder
result
=
WireHelpers
::
getWritableListPointer
(
...
...
@@ -2745,7 +2745,7 @@ StructReader OrphanBuilder::asStructReader(StructSize size) const {
segment
,
tagAsPtr
(),
location
,
nullptr
,
kj
::
maxValue
);
}
ListReader
OrphanBuilder
::
asListReader
(
Field
Size
elementSize
)
const
{
ListReader
OrphanBuilder
::
asListReader
(
Element
Size
elementSize
)
const
{
KJ_DASSERT
(
tagAsPtr
()
->
isNull
()
==
(
location
==
nullptr
));
return
WireHelpers
::
readListPointer
(
segment
,
tagAsPtr
(),
location
,
nullptr
,
elementSize
,
kj
::
maxValue
);
...
...
@@ -2780,7 +2780,7 @@ void OrphanBuilder::truncate(ElementCount size, bool isText) {
}
// TODO(soon): Implement truncation of all sizes.
KJ_ASSERT
(
ref
->
listRef
.
elementSize
()
==
Field
Size
::
BYTE
,
KJ_ASSERT
(
ref
->
listRef
.
elementSize
()
==
Element
Size
::
BYTE
,
"Not implemented: truncate non-blob."
);
auto
oldSize
=
ref
->
listRef
.
elementCount
();
...
...
c++/src/capnp/layout.h
View file @
5f07c032
...
...
@@ -78,11 +78,6 @@ class BuilderArena;
// =============================================================================
using
FieldSize
=
capnp
::
ElementSize
;
// Legacy typedef.
//
// TODO(cleanup): Replace all uses.
typedef
decltype
(
BITS
/
ELEMENTS
)
BitsPerElement
;
typedef
decltype
(
POINTERS
/
ELEMENTS
)
PointersPerElement
;
...
...
@@ -97,48 +92,48 @@ static constexpr BitsPerElement BITS_PER_ELEMENT_TABLE[8] = {
0
*
BITS
/
ELEMENTS
};
inline
constexpr
BitsPerElement
dataBitsPerElement
(
Field
Size
size
)
{
inline
constexpr
BitsPerElement
dataBitsPerElement
(
Element
Size
size
)
{
return
_
::
BITS_PER_ELEMENT_TABLE
[
static_cast
<
int
>
(
size
)];
}
inline
constexpr
PointersPerElement
pointersPerElement
(
Field
Size
size
)
{
return
size
==
Field
Size
::
POINTER
?
1
*
POINTERS
/
ELEMENTS
:
0
*
POINTERS
/
ELEMENTS
;
inline
constexpr
PointersPerElement
pointersPerElement
(
Element
Size
size
)
{
return
size
==
Element
Size
::
POINTER
?
1
*
POINTERS
/
ELEMENTS
:
0
*
POINTERS
/
ELEMENTS
;
}
template
<
size_t
size
>
struct
ElementSizeForByteSize
;
template
<>
struct
ElementSizeForByteSize
<
1
>
{
static
constexpr
FieldSize
value
=
Field
Size
::
BYTE
;
};
template
<>
struct
ElementSizeForByteSize
<
2
>
{
static
constexpr
FieldSize
value
=
Field
Size
::
TWO_BYTES
;
};
template
<>
struct
ElementSizeForByteSize
<
4
>
{
static
constexpr
FieldSize
value
=
Field
Size
::
FOUR_BYTES
;
};
template
<>
struct
ElementSizeForByteSize
<
8
>
{
static
constexpr
FieldSize
value
=
Field
Size
::
EIGHT_BYTES
;
};
template
<>
struct
ElementSizeForByteSize
<
1
>
{
static
constexpr
ElementSize
value
=
Element
Size
::
BYTE
;
};
template
<>
struct
ElementSizeForByteSize
<
2
>
{
static
constexpr
ElementSize
value
=
Element
Size
::
TWO_BYTES
;
};
template
<>
struct
ElementSizeForByteSize
<
4
>
{
static
constexpr
ElementSize
value
=
Element
Size
::
FOUR_BYTES
;
};
template
<>
struct
ElementSizeForByteSize
<
8
>
{
static
constexpr
ElementSize
value
=
Element
Size
::
EIGHT_BYTES
;
};
template
<
typename
T
>
struct
ElementSizeForType
{
static
constexpr
Field
Size
value
=
static
constexpr
Element
Size
value
=
// Primitive types that aren't special-cased below can be determined from sizeof().
CAPNP_KIND
(
T
)
==
Kind
::
PRIMITIVE
?
ElementSizeForByteSize
<
sizeof
(
T
)
>::
value
:
CAPNP_KIND
(
T
)
==
Kind
::
ENUM
?
Field
Size
::
TWO_BYTES
:
CAPNP_KIND
(
T
)
==
Kind
::
STRUCT
?
Field
Size
::
INLINE_COMPOSITE
:
CAPNP_KIND
(
T
)
==
Kind
::
ENUM
?
Element
Size
::
TWO_BYTES
:
CAPNP_KIND
(
T
)
==
Kind
::
STRUCT
?
Element
Size
::
INLINE_COMPOSITE
:
// Everything else is a pointer.
Field
Size
::
POINTER
;
Element
Size
::
POINTER
;
};
// Void and bool are special.
template
<>
struct
ElementSizeForType
<
Void
>
{
static
constexpr
FieldSize
value
=
Field
Size
::
VOID
;
};
template
<>
struct
ElementSizeForType
<
bool
>
{
static
constexpr
FieldSize
value
=
Field
Size
::
BIT
;
};
template
<>
struct
ElementSizeForType
<
Void
>
{
static
constexpr
ElementSize
value
=
Element
Size
::
VOID
;
};
template
<>
struct
ElementSizeForType
<
bool
>
{
static
constexpr
ElementSize
value
=
Element
Size
::
BIT
;
};
// Lists and blobs are pointers, not structs.
template
<
typename
T
,
bool
b
>
struct
ElementSizeForType
<
List
<
T
,
b
>>
{
static
constexpr
FieldSize
value
=
Field
Size
::
POINTER
;
static
constexpr
ElementSize
value
=
Element
Size
::
POINTER
;
};
template
<>
struct
ElementSizeForType
<
Text
>
{
static
constexpr
FieldSize
value
=
Field
Size
::
POINTER
;
static
constexpr
ElementSize
value
=
Element
Size
::
POINTER
;
};
template
<>
struct
ElementSizeForType
<
Data
>
{
static
constexpr
FieldSize
value
=
Field
Size
::
POINTER
;
static
constexpr
ElementSize
value
=
Element
Size
::
POINTER
;
};
template
<
typename
T
>
inline
constexpr
Field
Size
elementSizeForType
()
{
inline
constexpr
Element
Size
elementSizeForType
()
{
return
ElementSizeForType
<
T
>::
value
;
}
...
...
@@ -287,7 +282,7 @@ public:
bool
isList
();
StructBuilder
getStruct
(
StructSize
size
,
const
word
*
defaultValue
);
ListBuilder
getList
(
Field
Size
elementSize
,
const
word
*
defaultValue
);
ListBuilder
getList
(
Element
Size
elementSize
,
const
word
*
defaultValue
);
ListBuilder
getStructList
(
StructSize
elementSize
,
const
word
*
defaultValue
);
ListBuilder
getListAnySize
(
const
word
*
defaultValue
);
template
<
typename
T
>
typename
T
::
Builder
getBlob
(
const
void
*
defaultValue
,
ByteCount
defaultSize
);
...
...
@@ -299,7 +294,7 @@ public:
// simple byte array for blobs.
StructBuilder
initStruct
(
StructSize
size
);
ListBuilder
initList
(
Field
Size
elementSize
,
ElementCount
elementCount
);
ListBuilder
initList
(
Element
Size
elementSize
,
ElementCount
elementCount
);
ListBuilder
initStructList
(
ElementCount
elementCount
,
StructSize
size
);
template
<
typename
T
>
typename
T
::
Builder
initBlob
(
ByteCount
size
);
// Init methods: Initialize the pointer to a newly-allocated object, discarding the existing
...
...
@@ -368,7 +363,7 @@ public:
bool
isList
()
const
;
StructReader
getStruct
(
const
word
*
defaultValue
)
const
;
ListReader
getList
(
Field
Size
expectedElementSize
,
const
word
*
defaultValue
)
const
;
ListReader
getList
(
Element
Size
expectedElementSize
,
const
word
*
defaultValue
)
const
;
ListReader
getListAnySize
(
const
word
*
defaultValue
)
const
;
template
<
typename
T
>
typename
T
::
Reader
getBlob
(
const
void
*
defaultValue
,
ByteCount
defaultSize
)
const
;
...
...
@@ -566,7 +561,7 @@ public:
inline
word
*
getLocation
()
{
// Get the object's location.
if
(
elementSize
==
Field
Size
::
INLINE_COMPOSITE
)
{
if
(
elementSize
==
Element
Size
::
INLINE_COMPOSITE
)
{
return
reinterpret_cast
<
word
*>
(
ptr
)
-
POINTER_SIZE_IN_WORDS
;
}
else
{
return
reinterpret_cast
<
word
*>
(
ptr
);
...
...
@@ -616,14 +611,14 @@ private:
// The struct properties to use when interpreting the elements as structs. All lists can be
// interpreted as struct lists, so these are always filled in.
Field
Size
elementSize
;
// The element size as a
Field
Size. This is only really needed to disambiguate INLINE_COMPOSITE
Element
Size
elementSize
;
// The element size as a
Element
Size. This is only really needed to disambiguate INLINE_COMPOSITE
// from other types when the overall size is exactly zero or one words.
inline
ListBuilder
(
SegmentBuilder
*
segment
,
void
*
ptr
,
decltype
(
BITS
/
ELEMENTS
)
step
,
ElementCount
size
,
BitCount
structDataSize
,
WirePointerCount
structPointerCount
,
Field
Size
elementSize
)
Element
Size
elementSize
)
:
segment
(
segment
),
ptr
(
reinterpret_cast
<
byte
*>
(
ptr
)),
elementCount
(
size
),
step
(
step
),
structDataSize
(
structDataSize
),
structPointerCount
(
structPointerCount
),
elementSize
(
elementSize
)
{}
...
...
@@ -672,8 +667,8 @@ private:
// The struct properties to use when interpreting the elements as structs. All lists can be
// interpreted as struct lists, so these are always filled in.
Field
Size
elementSize
;
// The element size as a
Field
Size. This is only really needed to disambiguate INLINE_COMPOSITE
Element
Size
elementSize
;
// The element size as a
Element
Size. This is only really needed to disambiguate INLINE_COMPOSITE
// from other types when the overall size is exactly zero or one words.
int
nestingLimit
;
...
...
@@ -683,7 +678,7 @@ private:
inline
ListReader
(
SegmentReader
*
segment
,
const
void
*
ptr
,
ElementCount
elementCount
,
decltype
(
BITS
/
ELEMENTS
)
step
,
BitCount
structDataSize
,
WirePointerCount
structPointerCount
,
Field
Size
elementSize
,
int
nestingLimit
)
Element
Size
elementSize
,
int
nestingLimit
)
:
segment
(
segment
),
ptr
(
reinterpret_cast
<
const
byte
*>
(
ptr
)),
elementCount
(
elementCount
),
step
(
step
),
structDataSize
(
structDataSize
),
structPointerCount
(
structPointerCount
),
elementSize
(
elementSize
),
...
...
@@ -706,7 +701,7 @@ public:
static
OrphanBuilder
initStruct
(
BuilderArena
*
arena
,
StructSize
size
);
static
OrphanBuilder
initList
(
BuilderArena
*
arena
,
ElementCount
elementCount
,
Field
Size
elementSize
);
Element
Size
elementSize
);
static
OrphanBuilder
initStructList
(
BuilderArena
*
arena
,
ElementCount
elementCount
,
StructSize
elementSize
);
static
OrphanBuilder
initText
(
BuilderArena
*
arena
,
ByteCount
size
);
...
...
@@ -732,7 +727,7 @@ public:
StructBuilder
asStruct
(
StructSize
size
);
// Interpret as a struct, or throw an exception if not a struct.
ListBuilder
asList
(
Field
Size
elementSize
);
ListBuilder
asList
(
Element
Size
elementSize
);
// Interpret as a list, or throw an exception if not a list. elementSize cannot be
// INLINE_COMPOSITE -- use asStructList() instead.
...
...
@@ -744,7 +739,7 @@ public:
// Interpret as a blob, or throw an exception if not a blob.
StructReader
asStructReader
(
StructSize
size
)
const
;
ListReader
asListReader
(
Field
Size
elementSize
)
const
;
ListReader
asListReader
(
Element
Size
elementSize
)
const
;
#if !CAPNP_LITE
kj
::
Own
<
ClientHook
>
asCapability
()
const
;
#endif // !CAPNP_LITE
...
...
@@ -821,7 +816,7 @@ inline Data::Builder StructBuilder::getDataSectionAsBlob() {
inline
_
::
ListBuilder
StructBuilder
::
getPointerSectionAsList
()
{
return
_
::
ListBuilder
(
segment
,
pointers
,
pointerCount
*
BITS_PER_POINTER
/
ELEMENTS
,
pointerCount
*
(
1
*
ELEMENTS
/
POINTERS
),
0
*
BITS
,
1
*
POINTERS
,
Field
Size
::
POINTER
);
0
*
BITS
,
1
*
POINTERS
,
Element
Size
::
POINTER
);
}
template
<
typename
T
>
...
...
@@ -905,7 +900,7 @@ inline Data::Reader StructReader::getDataSectionAsBlob() {
inline
_
::
ListReader
StructReader
::
getPointerSectionAsList
()
{
return
_
::
ListReader
(
segment
,
pointers
,
pointerCount
*
(
1
*
ELEMENTS
/
POINTERS
),
pointerCount
*
BITS_PER_POINTER
/
ELEMENTS
,
0
*
BITS
,
1
*
POINTERS
,
Field
Size
::
POINTER
,
nestingLimit
);
0
*
BITS
,
1
*
POINTERS
,
Element
Size
::
POINTER
,
nestingLimit
);
}
template
<
typename
T
>
...
...
c++/src/capnp/list.h
View file @
5f07c032
...
...
@@ -302,7 +302,7 @@ private:
}
inline
static
_
::
ListReader
getFromPointer
(
const
_
::
PointerReader
&
reader
,
const
word
*
defaultValue
)
{
return
reader
.
getList
(
_
::
Field
Size
::
INLINE_COMPOSITE
,
defaultValue
);
return
reader
.
getList
(
Element
Size
::
INLINE_COMPOSITE
,
defaultValue
);
}
template
<
typename
U
,
Kind
k
>
...
...
@@ -406,14 +406,14 @@ struct List<List<T>, Kind::LIST> {
private
:
inline
static
_
::
ListBuilder
initPointer
(
_
::
PointerBuilder
builder
,
uint
size
)
{
return
builder
.
initList
(
_
::
Field
Size
::
POINTER
,
size
*
ELEMENTS
);
return
builder
.
initList
(
Element
Size
::
POINTER
,
size
*
ELEMENTS
);
}
inline
static
_
::
ListBuilder
getFromPointer
(
_
::
PointerBuilder
builder
,
const
word
*
defaultValue
)
{
return
builder
.
getList
(
_
::
Field
Size
::
POINTER
,
defaultValue
);
return
builder
.
getList
(
Element
Size
::
POINTER
,
defaultValue
);
}
inline
static
_
::
ListReader
getFromPointer
(
const
_
::
PointerReader
&
reader
,
const
word
*
defaultValue
)
{
return
reader
.
getList
(
_
::
Field
Size
::
POINTER
,
defaultValue
);
return
reader
.
getList
(
Element
Size
::
POINTER
,
defaultValue
);
}
template
<
typename
U
,
Kind
k
>
...
...
@@ -504,14 +504,14 @@ struct List<T, Kind::BLOB> {
private
:
inline
static
_
::
ListBuilder
initPointer
(
_
::
PointerBuilder
builder
,
uint
size
)
{
return
builder
.
initList
(
_
::
Field
Size
::
POINTER
,
size
*
ELEMENTS
);
return
builder
.
initList
(
Element
Size
::
POINTER
,
size
*
ELEMENTS
);
}
inline
static
_
::
ListBuilder
getFromPointer
(
_
::
PointerBuilder
builder
,
const
word
*
defaultValue
)
{
return
builder
.
getList
(
_
::
Field
Size
::
POINTER
,
defaultValue
);
return
builder
.
getList
(
Element
Size
::
POINTER
,
defaultValue
);
}
inline
static
_
::
ListReader
getFromPointer
(
const
_
::
PointerReader
&
reader
,
const
word
*
defaultValue
)
{
return
reader
.
getList
(
_
::
Field
Size
::
POINTER
,
defaultValue
);
return
reader
.
getList
(
Element
Size
::
POINTER
,
defaultValue
);
}
template
<
typename
U
,
Kind
k
>
...
...
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