11#include <promeki/config.h>
12#if PROMEKI_ENABLE_CORE
22PROMEKI_NAMESPACE_BEGIN
69 PROMEKI_DATATYPE(UMID, DataTypeUMID, 1)
72 Error writeToStream(DataStream &s) const;
74 template <uint32_t V> static Result<UMID> readFromStream(DataStream &s);
84 static constexpr size_t BasicSize = 32;
87 static constexpr size_t ExtendedSize = 64;
90 static constexpr size_t UniversalLabelSize = 12;
93 using DataFormat = Array<uint8_t, ExtendedSize>;
108 static UMID generate(Length len = Extended);
125 static Result<UMID> fromString(
const String &str);
140 static UMID fromBytes(
const uint8_t *bytes,
size_t byteLen);
143 UMID() : d{}, _length(Invalid) {}
146 UMID(
const UMID &other) : d(other.d), _length(other._length) {}
149 UMID &operator=(
const UMID &other) {
151 _length = other._length;
159 bool isValid()
const {
return _length != Invalid; }
165 Length length()
const {
return _length; }
171 size_t byteSize()
const {
return static_cast<size_t>(_length); }
174 bool isExtended()
const {
return _length == Extended; }
185 String toString()
const;
188 operator String()
const {
return toString(); }
198 const DataFormat &data()
const {
return d; }
206 const uint8_t *raw()
const {
return d.data(); }
209 bool operator==(
const UMID &other)
const {
210 if (_length != other._length)
return false;
211 return std::memcmp(d.data(), other.d.data(),
static_cast<size_t>(_length)) == 0;
215 bool operator!=(
const UMID &other)
const {
return !(*
this == other); }
218 bool operator<(
const UMID &other)
const {
219 if (_length != other._length)
return _length < other._length;
220 return std::memcmp(d.data(), other.d.data(),
static_cast<size_t>(_length)) < 0;
224 bool operator>(
const UMID &other)
const {
return other < *
this; }
227 bool operator<=(
const UMID &other)
const {
return !(other < *
this); }
230 bool operator>=(
const UMID &other)
const {
return !(*
this < other); }
239PROMEKI_FORMAT_VIA_TOSTRING(promeki::UMID);