30#ifndef TINS_PDU_CACHER_H
31#define TINS_PDU_CACHER_H
35#include <tins/macros.h>
66 static const PDU::PDUType pdu_flag = cached_type::pdu_flag;
79 : cached_(pdu), cached_size_() {}
87 if (cached_serialization_.empty()) {
88 cached_size_ = cached_.size();
108 cached_.send(sender, iface);
126 return cached_.matches_response(ptr, total_sz);
135 return cached_.matches_flag(flag);
144 return cached_.pdu_type();
147 void write_serialization(uint8_t* buffer, uint32_t total_sz) {
148 if (cached_serialization_.size() != total_sz) {
149 cached_serialization_ = cached_.serialize();
151 std::memcpy(buffer, &*cached_serialization_.begin(), cached_serialization_.size());
156 mutable uint32_t cached_size_;
Abstraction of a network interface.
Definition network_interface.h:47
PDUCacher(const cached_type &pdu)
Definition pdu_cacher.h:78
bool matches_response(const uint8_t *ptr, uint32_t total_sz) const
Definition pdu_cacher.h:125
bool matches_flag(PDUType flag) const
Definition pdu_cacher.h:134
T cached_type
Definition pdu_cacher.h:61
void send(PacketSender &sender, const NetworkInterface &iface)
Definition pdu_cacher.h:107
PDUCacher()
Definition pdu_cacher.h:71
PDU * recv_response(PacketSender &sender, const NetworkInterface &iface)
Definition pdu_cacher.h:116
PDUCacher * clone() const
Definition pdu_cacher.h:98
PDUType pdu_type() const
Definition pdu_cacher.h:143
uint32_t header_size() const
Definition pdu_cacher.h:86
PDU()
Default constructor.
Definition pdu.cpp:50
byte_array serialization_type
Definition pdu.h:112
PDUType
Enum which identifies each type of PDU.
Definition pdu.h:127
virtual PDU * recv_response(PacketSender &sender, const NetworkInterface &iface)
Receives a matching response for this packet.
Definition pdu.cpp:100
Sends packets through a network interface.
Definition packet_sender.h:118
The Tins namespace.
Definition address_range.h:38