SNode.C
Loading...
Searching...
No Matches
iot::mqtt_fast::ControlPacketFactory Class Reference

#include <ControlPacketFactory.h>

Collaboration diagram for iot::mqtt_fast::ControlPacketFactory:

Public Member Functions

 ControlPacketFactory (core::socket::SocketContext *socketContext)
 
std::size_t construct ()
 
bool isComplete () const
 
bool isError () const
 
iot::mqtt_fast::types::BinarygetPacket ()
 
uint8_t getPacketType ()
 
uint8_t getPacketFlags ()
 
uint64_t getRemainingLength ()
 
void reset ()
 

Private Attributes

bool completed = false
 
bool error = false
 
int state = 0
 
iot::mqtt_fast::types::Int_1 typeFlags
 
iot::mqtt_fast::types::Int_V remainingLength
 
iot::mqtt_fast::types::Binary data
 

Detailed Description

Definition at line 62 of file ControlPacketFactory.h.

Constructor & Destructor Documentation

◆ ControlPacketFactory()

iot::mqtt_fast::ControlPacketFactory::ControlPacketFactory ( core::socket::SocketContext socketContext)
explicit

Definition at line 52 of file ControlPacketFactory.cpp.

53 : typeFlags(socketContext)
54 , remainingLength(socketContext)
55 , data(socketContext) {
56 }
iot::mqtt_fast::types::Binary data
iot::mqtt_fast::types::Int_V remainingLength
iot::mqtt_fast::types::Int_1 typeFlags

References iot::mqtt_fast::types::Binary::Binary(), data, iot::mqtt_fast::types::Int_1::Int_1(), iot::mqtt_fast::types::Int_V::Int_V(), remainingLength, and typeFlags.

Referenced by iot::mqtt_fast::SocketContext::SocketContext().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Function Documentation

◆ construct()

std::size_t iot::mqtt_fast::ControlPacketFactory::construct ( )

Definition at line 58 of file ControlPacketFactory.cpp.

58 {
59 std::size_t consumed = 0;
60
61 switch (state) {
62 case 0: // Type - Flags
63 consumed = typeFlags.construct();
64 if (typeFlags.isComplete()) {
65 state++;
66 } else {
68 }
69 break;
70 case 1: // Remaining length
71 consumed = remainingLength.construct();
75 state++;
76 } else {
78 }
79 break;
80 case 2: // Var-Header + Payload
81 consumed = data.construct();
82 if (data.isComplete()) {
83 completed = true;
84 state++;
85 } else {
86 error = data.isError();
87 }
88 break;
89 }
90
91 return consumed;
92 }
std::size_t construct() override
Definition Binary.cpp:66
void setLength(std::vector< char >::size_type length)
Definition Binary.cpp:56
std::size_t construct() override
Definition Int_1.cpp:54
uint32_t getValue() const
Definition Int_V.cpp:77
std::size_t construct() override
Definition Int_V.cpp:54

References completed, iot::mqtt_fast::types::Binary::construct(), iot::mqtt_fast::types::Int_1::construct(), iot::mqtt_fast::types::Int_V::construct(), data, error, iot::mqtt_fast::types::Int_V::getValue(), iot::mqtt_fast::types::TypeBase::isComplete(), iot::mqtt_fast::types::TypeBase::isError(), remainingLength, iot::mqtt_fast::types::Binary::setLength(), state, and typeFlags.

Referenced by iot::mqtt_fast::SocketContext::onReceivedFromPeer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getPacket()

iot::mqtt_fast::types::Binary & iot::mqtt_fast::ControlPacketFactory::getPacket ( )

Definition at line 102 of file ControlPacketFactory.cpp.

102 {
103 return data;
104 }

References data.

Referenced by iot::mqtt_fast::ControlPacket::ControlPacket(), and iot::mqtt_fast::SocketContext::onReceivedFromPeer().

Here is the caller graph for this function:

◆ getPacketFlags()

uint8_t iot::mqtt_fast::ControlPacketFactory::getPacketFlags ( )

Definition at line 110 of file ControlPacketFactory.cpp.

110 {
111 return static_cast<uint8_t>(typeFlags.getValue() & 0x0F);
112 }

References iot::mqtt_fast::types::Int_1::getValue(), and typeFlags.

Referenced by iot::mqtt_fast::ControlPacket::ControlPacket(), iot::mqtt_fast::SocketContext::onReceivedFromPeer(), and iot::mqtt_fast::packets::Publish::Publish().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getPacketType()

uint8_t iot::mqtt_fast::ControlPacketFactory::getPacketType ( )

Definition at line 106 of file ControlPacketFactory.cpp.

106 {
107 return static_cast<uint8_t>(typeFlags.getValue() >> 0x04);
108 }

References iot::mqtt_fast::types::Int_1::getValue(), and typeFlags.

Referenced by iot::mqtt_fast::ControlPacket::ControlPacket(), and iot::mqtt_fast::SocketContext::onReceivedFromPeer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getRemainingLength()

uint64_t iot::mqtt_fast::ControlPacketFactory::getRemainingLength ( )

Definition at line 114 of file ControlPacketFactory.cpp.

114 {
115 return data.getValue().size();
116 }
std::vector< char > & getValue()
Definition Binary.cpp:76

References data, and iot::mqtt_fast::types::Binary::getValue().

Referenced by iot::mqtt_fast::SocketContext::onReceivedFromPeer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isComplete()

bool iot::mqtt_fast::ControlPacketFactory::isComplete ( ) const

Definition at line 94 of file ControlPacketFactory.cpp.

94 {
95 return completed;
96 }

References completed.

Referenced by iot::mqtt_fast::SocketContext::onReceivedFromPeer().

Here is the caller graph for this function:

◆ isError()

bool iot::mqtt_fast::ControlPacketFactory::isError ( ) const

Definition at line 98 of file ControlPacketFactory.cpp.

98 {
99 return error;
100 }

References error.

Referenced by iot::mqtt_fast::SocketContext::onReceivedFromPeer().

Here is the caller graph for this function:

◆ reset()

void iot::mqtt_fast::ControlPacketFactory::reset ( )

Definition at line 118 of file ControlPacketFactory.cpp.

118 {
119 completed = false;
120 error = false;
121 state = 0;
122
125 data.reset();
126 }
void reset() override
Definition Int_1.cpp:67
void reset() override
Definition Int_V.cpp:81

References completed, data, error, remainingLength, iot::mqtt_fast::types::Binary::reset(), iot::mqtt_fast::types::Int_1::reset(), iot::mqtt_fast::types::Int_V::reset(), state, and typeFlags.

Referenced by iot::mqtt_fast::SocketContext::onReceivedFromPeer().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ completed

bool iot::mqtt_fast::ControlPacketFactory::completed = false
private

Definition at line 77 of file ControlPacketFactory.h.

Referenced by construct(), isComplete(), and reset().

◆ data

iot::mqtt_fast::types::Binary iot::mqtt_fast::ControlPacketFactory::data
private

◆ error

bool iot::mqtt_fast::ControlPacketFactory::error = false
private

Definition at line 78 of file ControlPacketFactory.h.

Referenced by construct(), isError(), and reset().

◆ remainingLength

iot::mqtt_fast::types::Int_V iot::mqtt_fast::ControlPacketFactory::remainingLength
private

Definition at line 82 of file ControlPacketFactory.h.

Referenced by construct(), ControlPacketFactory(), and reset().

◆ state

int iot::mqtt_fast::ControlPacketFactory::state = 0
private

Definition at line 79 of file ControlPacketFactory.h.

Referenced by construct(), and reset().

◆ typeFlags

iot::mqtt_fast::types::Int_1 iot::mqtt_fast::ControlPacketFactory::typeFlags
private

The documentation for this class was generated from the following files: