libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
umid.h
Go to the documentation of this file.
1
8#pragma once
9
10
11#include <promeki/config.h>
12#if PROMEKI_ENABLE_CORE
13#include <cstdint>
14#include <cstring>
15#include <promeki/namespace.h>
16#include <promeki/string.h>
17#include <promeki/error.h>
18#include <promeki/result.h>
19#include <promeki/array.h>
20#include <promeki/datatype.h>
21
22PROMEKI_NAMESPACE_BEGIN
23
24class DataStream;
25
67class UMID {
68 public:
69 PROMEKI_DATATYPE(UMID, DataTypeUMID, 1)
70
71
72 Error writeToStream(DataStream &s) const;
74 template <uint32_t V> static Result<UMID> readFromStream(DataStream &s);
75
77 enum Length {
78 Invalid = 0,
79 Basic = 32,
80 Extended = 64
81 };
82
84 static constexpr size_t BasicSize = 32;
85
87 static constexpr size_t ExtendedSize = 64;
88
90 static constexpr size_t UniversalLabelSize = 12;
91
93 using DataFormat = Array<uint8_t, ExtendedSize>;
94
108 static UMID generate(Length len = Extended);
109
125 static Result<UMID> fromString(const String &str);
126
140 static UMID fromBytes(const uint8_t *bytes, size_t byteLen);
141
143 UMID() : d{}, _length(Invalid) {}
144
146 UMID(const UMID &other) : d(other.d), _length(other._length) {}
147
149 UMID &operator=(const UMID &other) {
150 d = other.d;
151 _length = other._length;
152 return *this;
153 }
154
159 bool isValid() const { return _length != Invalid; }
160
165 Length length() const { return _length; }
166
171 size_t byteSize() const { return static_cast<size_t>(_length); }
172
174 bool isExtended() const { return _length == Extended; }
175
185 String toString() const;
186
188 operator String() const { return toString(); }
189
198 const DataFormat &data() const { return d; }
199
206 const uint8_t *raw() const { return d.data(); }
207
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;
212 }
213
215 bool operator!=(const UMID &other) const { return !(*this == other); }
216
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;
221 }
222
224 bool operator>(const UMID &other) const { return other < *this; }
225
227 bool operator<=(const UMID &other) const { return !(other < *this); }
228
230 bool operator>=(const UMID &other) const { return !(*this < other); }
231
232 private:
233 DataFormat d;
234 Length _length;
235};
236
237PROMEKI_NAMESPACE_END
238
239PROMEKI_FORMAT_VIA_TOSTRING(promeki::UMID);
240
241#endif // PROMEKI_ENABLE_CORE