GHS
Leader Election Based on GHS Minimum Spanning Tree
src
demo
ghs-demo-msgutils.h
Go to the documentation of this file.
1
37
#ifndef GHS_DEMO_MSGUTILS
38
#define GHS_DEMO_MSGUTILS
39
40
#include "
ghs/msg.h
"
41
#include <cstring>
42
43
using
le::ghs::Msg
;
44
using
le::ghs::MAX_MSG_SZ
;
45
52
template
<std::
size_t
NUM>
53
Msg
from_bytes
(
unsigned
char
b[NUM]){
54
static_assert(NUM>=
MAX_MSG_SZ
,
"from_bytes only accepts statically-sized arrays >= sizeof(Msg)"
);
55
Msg
r;
56
void
* rp = (
void
*)&r;
57
memmove(rp,(
void
*)b,
MAX_MSG_SZ
);
58
return
r;
59
}
60
68
template
<std::
size_t
NUM>
69
void
to_bytes
(
const
Msg
&m,
unsigned
char
b[NUM]){
70
static_assert(NUM>=
MAX_MSG_SZ
,
"from_bytes only accepts statically-sized arrays >= sizeof(Msg)"
);
71
void
* mp = (
void
*)&m;
72
void
* bp = (
void
*)&b[0];
73
memmove(bp,mp,
MAX_MSG_SZ
);
74
return
;
75
}
76
87
Msg
from_bytes
(
unsigned
char
*b,
size_t
b_sz);
88
99
void
to_bytes
(
const
Msg
&m,
unsigned
char
* b,
size_t
&b_sz);
100
101
#endif
from_bytes
Msg from_bytes(unsigned char b[NUM])
quick and dirty static-sized message move
Definition:
ghs-demo-msgutils.h:53
msg.h
provides the defs for the struct le::ghs::msg
le::ghs::Msg
An aggregate type containing all the data to exchange with to/from information.
Definition:
msg.h:143
le::ghs::MAX_MSG_SZ
const unsigned int MAX_MSG_SZ
Definition:
msg.h:195
to_bytes
void to_bytes(const Msg &m, unsigned char b[NUM])
quick and dirty static-sized message move
Definition:
ghs-demo-msgutils.h:69
Generated by
1.8.17