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
74812501
Commit
74812501
authored
Dec 21, 2014
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix serialization issue in `simple_broker` example
parent
4babcfbd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
6 deletions
+21
-6
examples/brokers/simple_broker.cpp
examples/brokers/simple_broker.cpp
+21
-6
No files found.
examples/brokers/simple_broker.cpp
View file @
74812501
...
...
@@ -67,12 +67,25 @@ void write_int(broker* self, connection_handle hdl, T value) {
self
->
flush
(
hdl
);
}
void
write_int
(
broker
*
self
,
connection_handle
hdl
,
uint64_t
value
)
{
// write two uint32 values instead (htonl does not work for 64bit integers)
write_int
(
self
,
hdl
,
static_cast
<
uint32_t
>
(
value
));
write_int
(
self
,
hdl
,
static_cast
<
uint32_t
>
(
value
>>
sizeof
(
uint32_t
)));
}
// utility function for reading an ingeger from incoming data
template
<
class
T
>
T
read_int
(
const
void
*
data
)
{
T
value
;
memcpy
(
&
value
,
data
,
sizeof
(
T
));
return
static_cast
<
T
>
(
ntohl
(
value
));
void
read_int
(
const
void
*
data
,
T
&
storage
)
{
memcpy
(
&
storage
,
data
,
sizeof
(
T
));
storage
=
static_cast
<
T
>
(
ntohl
(
storage
));
}
void
read_int
(
const
void
*
data
,
uint64_t
&
storage
)
{
uint32_t
first
;
uint32_t
second
;
read_int
(
data
,
first
);
read_int
(
reinterpret_cast
<
const
char
*>
(
data
)
+
sizeof
(
uint32_t
),
second
);
storage
=
first
|
(
static_cast
<
uint64_t
>
(
second
)
<<
sizeof
(
uint32_t
));
}
// implemenation of our broker
...
...
@@ -115,12 +128,14 @@ behavior broker_impl(broker* self, connection_handle hdl, const actor& buddy) {
},
[
=
](
const
new_data_msg
&
msg
)
{
// read the atom value as uint64_t from buffer
auto
atm_val
=
read_int
<
uint64_t
>
(
msg
.
buf
.
data
());
uint64_t
atm_val
;
read_int
(
msg
.
buf
.
data
(),
atm_val
);
// cast to original type
auto
atm
=
static_cast
<
atom_value
>
(
atm_val
);
// read integer value from buffer, jumping to the correct
// position via offset_data(...)
auto
ival
=
read_int
<
int32_t
>
(
msg
.
buf
.
data
()
+
sizeof
(
uint64_t
));
int32_t
ival
;
read_int
(
msg
.
buf
.
data
()
+
sizeof
(
uint64_t
),
ival
);
// show some output
aout
(
self
)
<<
"received {"
<<
to_string
(
atm
)
<<
", "
<<
ival
<<
"}"
<<
endl
;
...
...
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