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 
62  Resource::Type getType() const;
63 
67  uint16_t getClass() const;
68 
72  bool isCachedFlush() const;
73 
77  uint32_t getTtl() const;
78 
82  String getRecordString() const;
83 
85  {
86  return message;
87  }
88 
89  uint8_t* getRecord() const;
90 
95  {
96  return namePtr + nameLen + 10;
97  }
98 
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 
Helper class for reading/writing packet content.
Definition: Packet.h:18
bool isCachedFlush() const
Flush cache of records matching this name.
bool parse(Packet &pkt)
Name getName() const
Object, domain or zone name.
Definition: Answer.h:54
Message & getResponse() const
Definition: Answer.h:84
uint32_t getTtl() const
ResourceRecord Time To Live: Number of seconds ths should be remembered.
The String class.
Definition: WString.h:136
A single mDNS Answer.
Definition: Answer.h:25
uint16_t getClass() const
ResourceRecord Class: Normally the value 1 for Internet (“IN”)
Definition: Answer.h:17
Answer(Message &message, Kind kind)
Definition: Answer.h:37
String toString(mDNS::Answer::Kind kind)
uint8_t * getRecord() const
Kind
Definition: Answer.h:31
Base class template for linked items with type casting.
Definition: LinkedObject.h:56
Encapsulates a message packet for flexible introspection.
Definition: Message.h:28
void allocate(uint16_t size)
uint16_t getRecordPtr() const
Get pointer to Resource Record data.
Definition: Answer.h:94
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
Type
Definition: Resource.h:41
Kind getKind() const
Identifies what kind of answer this is.
Definition: Answer.h:46
String getRecordString() const
Get content of record as string.
Resource::Type getType() const
ResourceRecord type.
Encoded DNS name.
Definition: Name.h:37