Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
3c9ca018
Commit
3c9ca018
authored
Feb 16, 2019
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow serializing type-erased tuples like messages
parent
7b51d55e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
5 deletions
+14
-5
libcaf_core/caf/message.hpp
libcaf_core/caf/message.hpp
+5
-0
libcaf_core/src/message.cpp
libcaf_core/src/message.cpp
+9
-5
No files found.
libcaf_core/caf/message.hpp
View file @
3c9ca018
...
@@ -266,6 +266,11 @@ public:
...
@@ -266,6 +266,11 @@ public:
return
*
vals_
;
return
*
vals_
;
}
}
/// Serializes the content of `x` as if `x` was an instance of `message`. The
/// resulting output of `sink` can then be used to deserialize a `message`
/// even if the serialized object had a different type.
static
error
save
(
serializer
&
sink
,
const
type_erased_tuple
&
x
);
/// @endcond
/// @endcond
private:
private:
...
...
libcaf_core/src/message.cpp
View file @
3c9ca018
...
@@ -156,19 +156,19 @@ error message::load(deserializer& source) {
...
@@ -156,19 +156,19 @@ error message::load(deserializer& source) {
return
none
;
return
none
;
}
}
error
message
::
save
(
serializer
&
sink
)
const
{
error
message
::
save
(
serializer
&
sink
,
const
type_erased_tuple
&
x
)
{
if
(
sink
.
context
()
==
nullptr
)
if
(
sink
.
context
()
==
nullptr
)
return
sec
::
no_context
;
return
sec
::
no_context
;
// build type name
// build type name
uint16_t
zero
=
0
;
uint16_t
zero
=
0
;
std
::
string
tname
=
"@<>"
;
std
::
string
tname
=
"@<>"
;
if
(
empty
())
if
(
x
.
empty
())
return
error
::
eval
([
&
]
{
return
sink
.
begin_object
(
zero
,
tname
);
},
return
error
::
eval
([
&
]
{
return
sink
.
begin_object
(
zero
,
tname
);
},
[
&
]
{
return
sink
.
end_object
();
});
[
&
]
{
return
sink
.
end_object
();
});
auto
&
types
=
sink
.
context
()
->
system
().
types
();
auto
&
types
=
sink
.
context
()
->
system
().
types
();
auto
n
=
size
();
auto
n
=
x
.
size
();
for
(
size_t
i
=
0
;
i
<
n
;
++
i
)
{
for
(
size_t
i
=
0
;
i
<
n
;
++
i
)
{
auto
rtti
=
cvals
()
->
type
(
i
);
auto
rtti
=
x
.
type
(
i
);
auto
ptr
=
types
.
portable_name
(
rtti
);
auto
ptr
=
types
.
portable_name
(
rtti
);
if
(
ptr
==
nullptr
)
{
if
(
ptr
==
nullptr
)
{
std
::
cerr
<<
"[ERROR]: cannot serialize message because a type was "
std
::
cerr
<<
"[ERROR]: cannot serialize message because a type was "
...
@@ -185,7 +185,7 @@ error message::save(serializer& sink) const {
...
@@ -185,7 +185,7 @@ error message::save(serializer& sink) const {
}
}
auto
save_loop
=
[
&
]()
->
error
{
auto
save_loop
=
[
&
]()
->
error
{
for
(
size_t
i
=
0
;
i
<
n
;
++
i
)
{
for
(
size_t
i
=
0
;
i
<
n
;
++
i
)
{
auto
e
=
cvals
()
->
save
(
i
,
sink
);
auto
e
=
x
.
save
(
i
,
sink
);
if
(
e
)
if
(
e
)
return
e
;
return
e
;
}
}
...
@@ -196,6 +196,10 @@ error message::save(serializer& sink) const {
...
@@ -196,6 +196,10 @@ error message::save(serializer& sink) const {
[
&
]
{
return
sink
.
end_object
();
});
[
&
]
{
return
sink
.
end_object
();
});
}
}
error
message
::
save
(
serializer
&
sink
)
const
{
return
save
(
sink
,
*
this
);
}
// -- factories ----------------------------------------------------------------
// -- factories ----------------------------------------------------------------
message
message
::
copy
(
const
type_erased_tuple
&
xs
)
{
message
message
::
copy
(
const
type_erased_tuple
&
xs
)
{
...
...
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