11#include <promeki/config.h>
12#if PROMEKI_ENABLE_MDNS
24PROMEKI_NAMESPACE_BEGIN
83 PROMEKI_DATATYPE(MdnsTxtRecord, DataTypeMdnsTxtRecord, 1)
86 Error writeToStream(DataStream &s) const;
88 template <uint32_t V> static Result<MdnsTxtRecord> readFromStream(DataStream &s);
97 enum class Presence : uint8_t {
105 static constexpr int MaxEntryBytes = 255;
108 MdnsTxtRecord() =
default;
118 void set(
const String &key,
const String &value);
128 void setKey(
const String &key);
138 void setEmpty(
const String &key);
145 void remove(
const String &key);
148 void clear() { _entries.clear(); }
151 Presence presence(
const String &key)
const;
154 bool contains(
const String &key)
const {
return presence(key) != Presence::Absent; }
164 String value(
const String &key,
const String &defaultValue = String())
const;
167 bool isEmpty()
const {
return _entries.isEmpty(); }
170 int count()
const {
return static_cast<int>(_entries.size()); }
173 StringList keys()
const;
182 void forEach(Function<
void(
const String &key, Presence p,
const String &value)> func)
const;
201 Buffer encode()
const;
214 static Result<MdnsTxtRecord> decode(
const Buffer &b);
217 static Result<MdnsTxtRecord> decode(
const uint8_t *bytes,
size_t len);
220 bool operator==(
const MdnsTxtRecord &other)
const;
221 bool operator!=(
const MdnsTxtRecord &other)
const {
return !(*
this == other); }
225 using List = ::promeki::List<Entry>;
227 Presence presence = Presence::Absent;
233 int findEntry(
const String &key)
const;
240 static String entryToWire(
const Entry &e);
242 Entry::List _entries;
246TextStream &operator<<(TextStream &stream,
const MdnsTxtRecord &txt);