11#include <promeki/config.h>
12#if PROMEKI_ENABLE_CORE
23PROMEKI_NAMESPACE_BEGIN
62 PROMEKI_DATATYPE(EUI64, DataTypeEUI64, 1)
65 Error writeToStream(DataStream &s) const;
67 template <uint32_t V> static Result<EUI64> readFromStream(DataStream &s);
70 using DataFormat = Array<uint8_t, 8>;
85 static Result<EUI64> fromString(const String &str);
97 static EUI64 fromMacAddress(const MacAddress &mac);
106 explicit EUI64(
const DataFormat &bytes) : _addr(bytes) {}
111 EUI64(uint8_t a, uint8_t b, uint8_t c, uint8_t d, uint8_t e, uint8_t f, uint8_t g, uint8_t h)
112 : _addr{DataFormat{a, b, c, d, e, f, g, h}} {}
115 bool isNull()
const {
return _addr.isZero(); }
121 const DataFormat &data()
const {
return _addr; }
127 const uint8_t *raw()
const {
return _addr.data(); }
134 uint8_t octet(
int index)
const {
135 if (index < 0 || index > 7)
return 0;
146 bool hasMacAddress()
const {
return _addr[3] == 0xFF && _addr[4] == 0xFE; }
158 MacAddress toMacAddress()
const;
164 String toString()
const;
171 String toString(
const EUI64Format &fmt)
const;
174 bool operator==(
const EUI64 &other)
const {
return _addr == other._addr; }
176 bool operator!=(
const EUI64 &other)
const {
return _addr != other._addr; }
178 bool operator<(
const EUI64 &other)
const {
179 return std::memcmp(_addr.data(), other._addr.data(), 8) < 0;
187TextStream &operator<<(TextStream &stream,
const EUI64 &addr);
206template <>
struct std::formatter<promeki::EUI64> {
209 constexpr auto parse(std::format_parse_context &ctx) {
210 auto it = ctx.begin();
211 if (it != ctx.end() && *it !=
'}') {
215 }
else if (*it ==
'o') {
218 }
else if (*it ==
'v') {
226 template <
typename FormatContext>
auto format(
const promeki::EUI64 &v, FormatContext &ctx)
const {
227 promeki::EUI64Format fmt(_spec);
228 promeki::String s = v.toString(fmt);
229 return std::format_to(ctx.out(),
"{}", std::string_view(s.cstr(), s.byteCount()));