SPSP
Simple publish-subscribe protocol. Connects low power IoT clients to MQTT.
All Classes Files Functions Variables Typedefs Enumerations
local_addr.hpp
Go to the documentation of this file.
1 
10 #pragma once
11 
12 #include <string>
13 #include <vector>
14 
15 namespace SPSP
16 {
25  struct LocalAddr
26  {
27  std::vector<uint8_t> addr;
28  std::string str;
29 
30  bool operator==(const LocalAddr& other) const
31  {
32  return addr == other.addr;
33  }
34 
35  bool operator!=(const LocalAddr& other) const
36  {
37  return !this->operator==(other);
38  }
39 
46  inline bool empty() const
47  {
48  return addr.empty();
49  }
50  };
51 }
52 
53 // Define hasher function
54 template<>
55 struct std::hash<SPSP::LocalAddr>
56 {
57  std::size_t operator()(SPSP::LocalAddr const& addr) const noexcept
58  {
59  // Convert internal representation to string
60  std::string addrStr(addr.addr.begin(), addr.addr.end());
61 
62  // Hash it
63  return std::hash<std::string>{}(addrStr);
64  }
65 };
SPSP::LocalAddr
Local layer address container.
Definition: local_addr.hpp:25
SPSP::LocalAddr::empty
bool empty() const
Checks whether the address is empty.
Definition: local_addr.hpp:46
SPSP::LocalAddr::addr
std::vector< uint8_t > addr
Internal address representation.
Definition: local_addr.hpp:27
SPSP::LocalAddr::str
std::string str
Printable string (also used in MQTT topic)
Definition: local_addr.hpp:28