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
a33284be
Commit
a33284be
authored
Oct 05, 2020
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow builders to append elements from messages
parent
8e88d559
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
0 deletions
+44
-0
libcaf_core/caf/message_builder.hpp
libcaf_core/caf/message_builder.hpp
+6
-0
libcaf_core/src/message_builder.cpp
libcaf_core/src/message_builder.cpp
+38
-0
No files found.
libcaf_core/caf/message_builder.hpp
View file @
a33284be
...
...
@@ -68,6 +68,12 @@ public:
return
*
this
;
}
/// Adds elements `n` elements from `msg` to the buffer, starting at index
/// `first`.
/// @note Always appends *copies* of the elements.
message_builder
&
append_from
(
const
caf
::
message
&
msg
,
size_t
first
,
size_t
n
=
1
);
template
<
class
...
Ts
>
message_builder
&
append_all
(
Ts
&&
...
xs
)
{
(
append
(
std
::
forward
<
Ts
>
(
xs
)),
...);
...
...
libcaf_core/src/message_builder.cpp
View file @
a33284be
...
...
@@ -18,6 +18,7 @@
#include "caf/message_builder.hpp"
#include "caf/detail/meta_object.hpp"
#include "caf/raise_error.hpp"
namespace
caf
{
...
...
@@ -54,8 +55,45 @@ message to_message_impl(size_t storage_size, TypeListBuilder& types,
return
message
{
std
::
move
(
ptr
)};
}
class
message_builder_element_adapter
final
:
public
message_builder_element
{
public:
message_builder_element_adapter
(
message
src
,
size_t
index
)
:
src_
(
std
::
move
(
src
)),
index_
(
index
)
{
// nop
}
byte
*
copy_init
(
byte
*
storage
)
const
override
{
auto
*
meta
=
global_meta_object
(
src_
.
type_at
(
index_
));
meta
->
copy_construct
(
storage
,
src_
.
data
().
at
(
index_
));
return
storage
+
meta
->
padded_size
;
}
byte
*
move_init
(
byte
*
storage
)
override
{
return
copy_init
(
storage
);
}
private:
message
src_
;
size_t
index_
;
};
}
// namespace
message_builder
&
message_builder
::
append_from
(
const
caf
::
message
&
msg
,
size_t
first
,
size_t
n
)
{
if
(
!
msg
||
first
>=
msg
.
size
())
return
*
this
;
auto
end
=
std
::
min
(
msg
.
size
(),
first
+
n
);
for
(
size_t
index
=
first
;
index
<
end
;
++
index
)
{
auto
tid
=
msg
.
type_at
(
index
);
auto
*
meta
=
detail
::
global_meta_object
(
tid
);
storage_size_
+=
meta
->
padded_size
;
types_
.
push_back
(
tid
);
elements_
.
emplace_back
(
new
message_builder_element_adapter
(
msg
,
index
));
}
return
*
this
;
}
void
message_builder
::
clear
()
noexcept
{
storage_size_
=
0
;
types_
.
clear
();
...
...
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