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);
117 return cached_.recv_response(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
PDU wrapper that caches the result of the wrapped PDU's serialization.
Definition pdu_cacher.h:56
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
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
T cached_type
Definition pdu_cacher.h:61
uint32_t header_size() const
Definition pdu_cacher.h:86
Base class for protocol data units.
Definition pdu.h:107
PDUType
Enum which identifies each type of PDU.
Definition pdu.h:127
byte_array serialization_type
Definition pdu.h:112
Sends packets through a network interface.
Definition packet_sender.h:118
The Tins namespace.
Definition address_range.h:38