36std::string EUI48Sub::toString() const noexcept {
42 str.reserve(3 *
length - 1);
71 errmsg.append(
"EUI48 sub-string must be less or equal length 17 but "+
std::to_string(str_len)+
": "+str);
74 const char * str_ptr = str.c_str();
76 bool exp_colon =
false;
78 while( j+1 < str_len ) {
79 const bool is_colon =
':' == str[j];
80 if( exp_colon && !is_colon ) {
81 errmsg.append(
"EUI48Sub sub-string not in format '01:02:03:0A:0B:0C', but '"+str+
"', colon missing, pos "+
std::to_string(j)+
", len "+
std::to_string(str_len));
83 }
else if( is_colon ) {
87 if ( sscanf(str_ptr+j,
"%02hhx", &b_[dest.
length]) != 1 )
89 errmsg.append(
"EUI48Sub sub-string not in format '01:02:03:0A:0B:0C' but '"+str+
"', pos "+
std::to_string(j)+
", len "+
std::to_string(str_len));
98 for(j=0; j<dest.
length; ++j) {
99 dest.
b[j] = b_[dest.
length-1-j];
102 memcpy(dest.
b, b_, dest.
length);
116 const jau::nsize_t cpsz = std::max<jau::nsize_t>(
sizeof(b), len_);
130 const uint8_t needle_b[],
const jau::nsize_t needle_length,
132 if( 0 == needle_length ) {
135 if( haystack_length < needle_length ) {
138 const uint8_t first = needle_b[0];
139 const jau::nsize_t outerEnd = haystack_length - needle_length + 1;
143 while( haystack_b[i] != first ) {
144 if( ++i == outerEnd ) {
153 if( ++j == innerEnd ) {
158 return static_cast<jau::snsize_t>(5 - i - ( needle_length - 1 ));
161 }
while( haystack_b[j] == needle_b[++k] );
203 if( 17 != str.length() ) {
204 errmsg.append(
"EUI48 string not of length 17 but ");
206 errmsg.append(
": "+str);
211 scanres = sscanf(str.c_str(),
"%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
212 &dest.
b[5], &dest.
b[4], &dest.
b[3], &dest.
b[2], &dest.
b[1], &dest.
b[0]);
214 scanres = sscanf(str.c_str(),
"%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
215 &dest.
b[0], &dest.
b[1], &dest.
b[2], &dest.
b[3], &dest.
b[4], &dest.
b[5]);
217 if ( 6 != scanres ) {
218 errmsg.append(
"EUI48 string not in format '01:02:03:0A:0B:0C' but '"+str+
"'");
235 memcpy(b, source,
sizeof(b));
243 memcpy(sink, b,
sizeof(b));
static uint8_t _EUI48_LOCAL_DEVICE[]
static uint8_t _EUI48_ALL_DEVICE[]
constexpr uint16_t bswap(uint16_t const source) noexcept
lb_endian_t
Simplified reduced endian type only covering little- and big-endian.
constexpr bool is_little_endian(const endian_t byte_order) noexcept
Returns true if given byte_order equals endian::little, otherwise false.
@ native
Identifier for native platform type, one of the above.
@ little
Identifier for little endian, equivalent to endian::little.
std::string to_string(const alphabet &v) noexcept
uint_fast32_t nsize_t
Natural 'size_t' alternative using uint_fast32_t as its natural sized type.
int_fast32_t snsize_t
Natural 'ssize_t' alternative using int_fast32_t as its natural sized type.
static constexpr void bswap_6bytes(uint8_t *sink, const uint8_t *source) noexcept
std::string & byteHexString(std::string &dest, const uint8_t value, const bool lowerCase) noexcept
Produce a hexadecimal string representation of the given byte value.
__pack(...): Produces MSVC, clang and gcc compatible lead-in and -out macros.
A 48 bit EUI-48 sub-identifier, see EUI48.
jau::nsize_t length
The actual length in bytes of the EUI48 sub-address, less or equal 6 bytes.
constexpr EUI48Sub() noexcept
uint8_t b[6]
The <= 6 byte EUI48 sub-address.
static const EUI48Sub ALL_DEVICE
EUI48 MAC address matching all device, i.e.
static const EUI48Sub ANY_DEVICE
EUI48 MAC address matching any device, i.e.
static jau::snsize_t indexOf(const uint8_t haystack_b[], const jau::nsize_t haystack_length, const uint8_t needle_b[], const jau::nsize_t needle_length, const lb_endian_t byte_order) noexcept
Find index of needle within haystack in the given byte order.
void clear()
Method clears the underlying byte array b and sets length to zero.
static const EUI48Sub LOCAL_DEVICE
EUI48 MAC address matching local device, i.e.
static bool scanEUI48Sub(const std::string &str, EUI48Sub &dest, std::string &errmsg)
Fills given EUI48Sub instance via given string representation.
A packed 48 bit EUI-48 identifier, formerly known as MAC-48 or simply network device MAC address (Med...
static const EUI48 LOCAL_DEVICE
EUI48 MAC address matching local device, i.e.
static const EUI48 ANY_DEVICE
EUI48 MAC address matching any device, i.e.
static const EUI48 ALL_DEVICE
EUI48 MAC address matching all device, i.e.
static bool scanEUI48(const std::string &str, EUI48 &dest, std::string &errmsg)
jau::nsize_t put(uint8_t *const sink, const lb_endian_t byte_order) const noexcept
constexpr EUI48() noexcept
std::string toString() const noexcept