libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
mdnsservicetype.h
Go to the documentation of this file.
1
8#pragma once
9
10
11#include <promeki/config.h>
12#if PROMEKI_ENABLE_MDNS
13#include <cstdint>
14#include <promeki/namespace.h>
15#include <promeki/datatype.h>
16#include <promeki/string.h>
17#include <promeki/stringlist.h>
18#include <promeki/result.h>
19#include <promeki/error.h>
20
21PROMEKI_NAMESPACE_BEGIN
22
23class DataStream;
24class TextStream;
25
74class MdnsServiceType {
75 public:
76 PROMEKI_DATATYPE(MdnsServiceType, DataTypeMdnsServiceType, 1)
77
78
79 Error writeToStream(DataStream &s) const;
81 template <uint32_t V> static Result<MdnsServiceType> readFromStream(DataStream &s);
82
91 enum class Protocol : uint8_t {
92 Invalid = 0,
93 Tcp = 1,
94 Udp = 2,
95 };
96
98 static constexpr const char *DefaultDomain = "local";
99
101 static constexpr int MaxAppLabelLen = 15;
102
104 MdnsServiceType() = default;
105
121 MdnsServiceType(const String &app, Protocol proto,
122 const String &domain = String(DefaultDomain));
123
137 static Result<MdnsServiceType> fromString(const String &s);
138
140 const String &app() const { return _app; }
141
143 Protocol proto() const { return _proto; }
144
146 const String &domain() const { return _domain; }
147
149 bool isValid() const { return _proto != Protocol::Invalid && !_app.isEmpty(); }
150
158 String toString() const;
159
167 String toFqdn() const;
168
182 String toSubtypeBrowseFqdn(const String &subtype) const;
183
185 static String protocolToString(Protocol p);
186
188 static Protocol protocolFromString(const String &s);
189
191 bool operator==(const MdnsServiceType &other) const;
192 bool operator!=(const MdnsServiceType &other) const { return !(*this == other); }
193 bool operator<(const MdnsServiceType &other) const;
194
195 private:
196 String _app;
197 Protocol _proto = Protocol::Invalid;
198 String _domain = String(DefaultDomain);
199};
200
202TextStream &operator<<(TextStream &stream, const MdnsServiceType &t);
203
204PROMEKI_NAMESPACE_END
205
206#endif // PROMEKI_ENABLE_MDNS