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
8ba8d95b
Commit
8ba8d95b
authored
Jul 24, 2016
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Dynamic API: Allow setting an AnyPointer field from any pointer type.
parent
8a2dcdd0
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
3 deletions
+65
-3
dynamic-test.c++
c++/src/capnp/dynamic-test.c++
+31
-0
dynamic.c++
c++/src/capnp/dynamic.c++
+34
-3
No files found.
c++/src/capnp/dynamic-test.c++
View file @
8ba8d95b
...
...
@@ -158,6 +158,37 @@ TEST(DynamicApi, AnyPointers) {
checkList
<
uint32_t
>
(
root
.
getAnyPointerField
().
getAs
<
DynamicList
>
(
Schema
::
from
<
List
<
uint32_t
>>
()),
{
123u
,
456u
,
789u
,
123456789u
});
}
// Setting an AnyPointer to various types should work.
toDynamic
(
root
).
set
(
"anyPointerField"
,
capnp
::
Text
::
Reader
(
"foo"
));
EXPECT_EQ
(
"foo"
,
root
.
getAnyPointerField
().
getAs
<
Text
>
());
{
auto
orphan
=
builder
.
getOrphanage
().
newOrphan
<
TestAllTypes
>
();
initTestMessage
(
orphan
.
get
());
toDynamic
(
root
).
set
(
"anyPointerField"
,
orphan
.
getReader
());
checkTestMessage
(
root
.
getAnyPointerField
().
getAs
<
TestAllTypes
>
());
toDynamic
(
root
).
adopt
(
"anyPointerField"
,
kj
::
mv
(
orphan
));
checkTestMessage
(
root
.
getAnyPointerField
().
getAs
<
TestAllTypes
>
());
}
{
auto
lorphan
=
builder
.
getOrphanage
().
newOrphan
<
List
<
uint32_t
>>
(
3
);
lorphan
.
get
().
set
(
0
,
12
);
lorphan
.
get
().
set
(
1
,
34
);
lorphan
.
get
().
set
(
2
,
56
);
toDynamic
(
root
).
set
(
"anyPointerField"
,
lorphan
.
getReader
());
auto
l
=
root
.
getAnyPointerField
().
getAs
<
List
<
uint32_t
>>
();
ASSERT_EQ
(
3
,
l
.
size
());
EXPECT_EQ
(
12
,
l
[
0
]);
EXPECT_EQ
(
34
,
l
[
1
]);
EXPECT_EQ
(
56
,
l
[
2
]);
}
// Just compile this one.
toDynamic
(
root
).
set
(
"anyPointerField"
,
Capability
::
Client
(
nullptr
));
root
.
getAnyPointerField
().
getAs
<
Capability
>
();
}
TEST
(
DynamicApi
,
DynamicAnyPointers
)
{
...
...
c++/src/capnp/dynamic.c++
View file @
8ba8d95b
...
...
@@ -558,10 +558,41 @@ void DynamicStruct::Builder::set(StructSchema::Field field, const DynamicValue::
return
;
}
case
schema
:
:
Type
::
ANY_POINTER
:
AnyPointer
::
Builder
(
builder
.
getPointerField
(
slot
.
getOffset
()
*
POINTERS
))
.
set
(
value
.
as
<
AnyPointer
>
());
case
schema
:
:
Type
::
ANY_POINTER
:
{
auto
target
=
AnyPointer
::
Builder
(
builder
.
getPointerField
(
slot
.
getOffset
()
*
POINTERS
));
switch
(
value
.
getType
())
{
case
DynamicValue
:
:
Type
::
TEXT
:
target
.
setAs
<
Text
>
(
value
.
as
<
Text
>
());
return
;
case
DynamicValue
:
:
Type
::
DATA
:
target
.
setAs
<
Data
>
(
value
.
as
<
Data
>
());
return
;
case
DynamicValue
:
:
Type
::
LIST
:
target
.
setAs
<
DynamicList
>
(
value
.
as
<
DynamicList
>
());
return
;
case
DynamicValue
:
:
Type
::
STRUCT
:
target
.
setAs
<
DynamicStruct
>
(
value
.
as
<
DynamicStruct
>
());
return
;
case
DynamicValue
:
:
Type
::
CAPABILITY
:
target
.
setAs
<
DynamicCapability
>
(
value
.
as
<
DynamicCapability
>
());
return
;
case
DynamicValue
:
:
Type
::
ANY_POINTER
:
target
.
set
(
value
.
as
<
AnyPointer
>
());
return
;
case
DynamicValue
:
:
Type
::
UNKNOWN
:
case
DynamicValue
:
:
Type
::
VOID
:
case
DynamicValue
:
:
Type
::
BOOL
:
case
DynamicValue
:
:
Type
::
INT
:
case
DynamicValue
:
:
Type
::
UINT
:
case
DynamicValue
:
:
Type
::
FLOAT
:
case
DynamicValue
:
:
Type
::
ENUM
:
KJ_FAIL_ASSERT
(
"Value type mismatch; expected AnyPointer"
);
}
KJ_UNREACHABLE
;
}
case
schema
:
:
Type
::
INTERFACE
:
{
auto
interfaceType
=
type
.
asInterface
();
...
...
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