Answer.h
Go to the documentation of this file.
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/SmingHub/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * Answer.h
8  *
9  ****/
10 
11 #pragma once
12 
13 #include <Data/LinkedObjectList.h>
14 #include "Name.h"
15 #include "Resource.h"
16 
17 namespace mDNS
18 {
19 class Message;
20 struct Packet;
21 
25 class Answer : public LinkedObjectTemplate<Answer>
26 {
27 public:
30 
31  enum class Kind : uint8_t {
32  answer,
33  name,
34  additional,
35  };
36 
37  Answer(Message& message, Kind kind) : message(message), kind(kind)
38  {
39  }
40 
41  bool parse(Packet& pkt);
42 
46  Kind getKind() const
47  {
48  return kind;
49  }
50 
54  Name getName() const
55  {
56  return Name(message, namePtr);
57  }
58 
63 
67  uint16_t getClass() const;
68 
72  bool isCachedFlush() const;
73 
77  uint32_t getTtl() const;
78 
83 
85  {
86  return message;
87  }
88 
89  uint8_t* getRecord() const;
90 
94  uint16_t getRecordPtr() const
95  {
96  return namePtr + nameLen + 10;
97  }
98 
102  uint16_t getRecordSize() const
103  {
104  return recordSize;
105  }
106 
107  // Writing
108  uint16_t init(uint16_t namePtr, const String& name, Resource::Type type, uint16_t rclass, bool flush, uint32_t ttl);
109  uint16_t init(uint16_t namePtr, const Name& name, Resource::Type type, uint16_t rclass, bool flush, uint32_t ttl);
110  void allocate(uint16_t size);
111 
112 private:
113  Message& message;
114  uint16_t namePtr{0};
115  uint16_t recordSize{0};
116  uint16_t nameLen{0};
117  Kind kind;
118 };
119 
120 } // namespace mDNS
121 
String toString(mDNS::Answer::Kind kind)
Definition: LinkedObjectList.h:90
Base class template for linked items with type casting.
Definition: LinkedObject.h:62
The String class.
Definition: WString.h:137
A single mDNS Answer.
Definition: Answer.h:26
uint16_t init(uint16_t namePtr, const String &name, Resource::Type type, uint16_t rclass, bool flush, uint32_t ttl)
uint16_t getRecordSize() const
Get size of Resource Record.
Definition: Answer.h:102
uint16_t getRecordPtr() const
Get pointer to Resource Record data.
Definition: Answer.h:94
Kind getKind() const
Identifies what kind of answer this is.
Definition: Answer.h:46
Name getName() const
Object, domain or zone name.
Definition: Answer.h:54
uint16_t getClass() const
ResourceRecord Class: Normally the value 1 for Internet (“IN”)
bool parse(Packet &pkt)
uint16_t init(uint16_t namePtr, const Name &name, Resource::Type type, uint16_t rclass, bool flush, uint32_t ttl)
Message & getResponse() const
Definition: Answer.h:84
Answer(Message &message, Kind kind)
Definition: Answer.h:37
String getRecordString() const
Get content of record as string.
uint8_t * getRecord() const
bool isCachedFlush() const
Flush cache of records matching this name.
uint32_t getTtl() const
ResourceRecord Time To Live: Number of seconds this should be remembered.
Resource::Type getType() const
ResourceRecord type.
Kind
Definition: Answer.h:31
void allocate(uint16_t size)
Encapsulates a message packet for flexible introspection.
Definition: MDNS/src/include/Network/Mdns/Message.h:29
Encoded DNS name.
Definition: Name.h:38
Type
Definition: Resource.h:41
Definition: Answer.h:18
Helper class for reading/writing packet content.
Definition: Packet.h:18