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
0e7f7116
Commit
0e7f7116
authored
Jan 22, 2015
by
Jason Paryani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow DynamicStruct::Reader/Builder.as<AnyStruct>
Also fix AnyStruct::Reader/Builder as methods
parent
223d5363
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
1 deletion
+35
-1
any-test.c++
c++/src/capnp/any-test.c++
+6
-0
any.h
c++/src/capnp/any.h
+9
-1
dynamic-test.c++
c++/src/capnp/dynamic-test.c++
+9
-0
dynamic.h
c++/src/capnp/dynamic.h
+11
-0
No files found.
c++/src/capnp/any-test.c++
View file @
0e7f7116
...
...
@@ -114,6 +114,12 @@ TEST(Any, AnyStruct) {
checkTestMessage
(
root
.
getAnyPointerField
().
getAs
<
TestAllTypes
>
());
checkTestMessage
(
root
.
asReader
().
getAnyPointerField
().
getAs
<
TestAllTypes
>
());
auto
all_types
=
root
.
getAnyPointerField
().
getAs
<
AnyStruct
>
().
as
<
TestAllTypes
>
();
auto
all_types_reader
=
root
.
getAnyPointerField
().
getAs
<
AnyStruct
>
().
asReader
().
as
<
TestAllTypes
>
();
all_types
.
setInt32Field
(
100
);
EXPECT_EQ
(
100
,
all_types
.
getInt32Field
());
EXPECT_EQ
(
100
,
all_types_reader
.
getInt32Field
());
EXPECT_EQ
(
48
,
root
.
getAnyPointerField
().
getAs
<
AnyStruct
>
().
getDataSection
().
size
());
EXPECT_EQ
(
20
,
root
.
getAnyPointerField
().
getAs
<
AnyStruct
>
().
getPointerSection
().
size
());
...
...
c++/src/capnp/any.h
View file @
0e7f7116
...
...
@@ -436,7 +436,9 @@ public:
}
template
<
typename
T
>
ReaderFor
<
T
>
as
();
ReaderFor
<
T
>
as
()
const
{
return
typename
T
::
Reader
(
_reader
);
}
// T must be a struct type.
private
:
_
::
StructReader
_reader
;
...
...
@@ -465,6 +467,12 @@ public:
inline
operator
Reader
()
const
{
return
Reader
(
_builder
.
asReader
());
}
inline
Reader
asReader
()
const
{
return
Reader
(
_builder
.
asReader
());
}
template
<
typename
T
>
BuilderFor
<
T
>
as
()
{
return
typename
T
::
Builder
(
_builder
);
}
// T must be a struct type.
private
:
_
::
StructBuilder
_builder
;
friend
class
Orphanage
;
...
...
c++/src/capnp/dynamic-test.c++
View file @
0e7f7116
...
...
@@ -222,6 +222,15 @@ TEST(DynamicApi, DynamicAnyPointers) {
}
}
TEST
(
DynamicApi
,
DynamicAnyStructs
)
{
MallocMessageBuilder
builder
;
auto
root
=
builder
.
initRoot
<
DynamicStruct
>
(
Schema
::
from
<
TestAllTypes
>
());
root
.
as
<
AnyStruct
>
().
as
<
TestAllTypes
>
().
setInt8Field
(
123
);
EXPECT_EQ
(
root
.
get
(
"int8Field"
).
as
<
int8_t
>
(),
123
);
EXPECT_EQ
(
root
.
asReader
().
as
<
AnyStruct
>
().
as
<
TestAllTypes
>
().
getInt8Field
(),
123
);
}
#define EXPECT_MAYBE_EQ(name, exp, expected, actual) \
KJ_IF_MAYBE(name, exp) { \
EXPECT_EQ(expected, actual); \
...
...
c++/src/capnp/dynamic.h
View file @
0e7f7116
...
...
@@ -1435,6 +1435,7 @@ typename T::Reader DynamicStruct::Reader::as() const {
schema
.
requireUsableAs
<
T
>
();
return
typename
T
::
Reader
(
reader
);
}
template
<
typename
T
>
typename
T
::
Builder
DynamicStruct
::
Builder
::
as
()
{
static_assert
(
kind
<
T
>
()
==
Kind
::
STRUCT
,
...
...
@@ -1456,6 +1457,16 @@ inline DynamicStruct::Reader DynamicStruct::Builder::asReader() const {
return
DynamicStruct
::
Reader
(
schema
,
builder
.
asReader
());
}
template
<>
inline
AnyStruct
::
Reader
DynamicStruct
::
Reader
::
as
<
AnyStruct
>
()
const
{
return
AnyStruct
::
Reader
(
reader
);
}
template
<>
inline
AnyStruct
::
Builder
DynamicStruct
::
Builder
::
as
<
AnyStruct
>
()
{
return
AnyStruct
::
Builder
(
builder
);
}
template
<
typename
T
>
typename
T
::
Pipeline
DynamicStruct
::
Pipeline
::
releaseAs
()
{
static_assert
(
kind
<
T
>
()
==
Kind
::
STRUCT
,
...
...
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