Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
EndianHelper.hxx
Go to the documentation of this file.
1
35#ifndef _OPENLCB_ENDIANHELPER_HXX_
36#define _OPENLCB_ENDIANHELPER_HXX_
37
38#include "endian.h"
39#include "openlcb/Defs.hxx"
40
41namespace openlcb {
42
45inline NodeID NetworkToNodeID(const uint8_t* data) {
46 uint64_t ret = 0;
47 memcpy(&ret, data, 6);
48 return be64toh(ret);
49}
50
53inline void NodeIDToNetwork(const NodeID id, uint8_t* dst) {
54 uint64_t be_id = htobe64(id);
55 memcpy(dst, &be_id, 6);
56}
57
60inline uint64_t NetworkToEventID(const void* data) {
61 uint64_t ret = 0;
62 memcpy(&ret, data, 8);
63 return be64toh(ret);
64}
65
67inline void EventIDToNetwork(const uint64_t event_id, void* dst) {
68 uint64_t be_id = htobe64(event_id);
69 memcpy(dst, &be_id, 8);
70}
71
74inline string EventIDToPayload(const uint64_t event_id) {
75 string v(8, 0);
76 EventIDToNetwork(event_id, &v[0]);
77 return v;
78}
79
80} // namespace NRMAnet
81
82#endif // _OPENLCB_ENDIANHELPER_HXX_
uint64_t NodeID
48-bit NMRAnet Node ID type
void EventIDToNetwork(const uint64_t event_id, void *dst)
Takes an event id from id, and copies it network-endian into *data.
uint64_t NetworkToEventID(const void *data)
Takes 8 bytes (big-endian) from *data, and returns the event id they represent.
string EventIDToPayload(const uint64_t event_id)
Takes an event ID and returns a network encoding of it in a payload buffer.
NodeID NetworkToNodeID(const uint8_t *data)
Takes six bytes (big-endian) from *data, and returns the node ID they represent.
void NodeIDToNetwork(const NodeID id, uint8_t *dst)
Takes a node id from.