40 class EMANE::UpstreamPacket::Implementation
45 pShared_{std::make_shared<Shared>()}{}
47 Implementation(
const PacketInfo & info,
const void * buf,
size_t len):
49 pShared_{std::make_shared<Shared>()}
51 const unsigned char * c =
static_cast<const unsigned char *
>(buf);
52 pShared_->info_ = info;
53 pShared_->packetSegment_.reserve(len);
54 pShared_->packetSegment_.insert(pShared_->packetSegment_.end(),&c[0],&c[len]);
57 Implementation(
const PacketInfo & info,
const Utils::VectorIO & vectorIO):
59 pShared_{std::make_shared<Shared>()}
61 pShared_->info_ = info;
63 for(
const auto & iov : vectorIO)
65 pShared_->packetSegment_.insert(pShared_->packetSegment_.end(),
66 &
static_cast<const std::uint8_t *
>(iov.iov_base)[0],
67 &static_cast<const std::uint8_t *>(iov.iov_base)[iov.iov_len]);
71 size_t strip(
size_t size)
73 if(head_ + size < pShared_->packetSegment_.size())
79 size = pShared_->packetSegment_.size() - head_;
89 std::uint16_t u16LengthPrefixFraming{};
91 if(head_ +
sizeof(uint16_t) < pShared_->packetSegment_.size())
93 u16LengthPrefixFraming =
94 NTOHS(*reinterpret_cast<const std::uint16_t *>(&pShared_->packetSegment_[head_]));
96 head_ +=
sizeof(uint16_t);
99 return u16LengthPrefixFraming;
104 std::uint32_t u32LengthPrefixFraming{};
106 if(head_ +
sizeof(uint32_t) < pShared_->packetSegment_.size())
108 u32LengthPrefixFraming =
109 NTOHL(*reinterpret_cast<const std::uint32_t *>(&pShared_->packetSegment_[head_]));
111 head_ +=
sizeof(uint32_t);
114 return u32LengthPrefixFraming;
118 const void *
get()
const 120 return(head_ < pShared_->packetSegment_.size()) ? &pShared_->packetSegment_[head_] : 0;
126 return pShared_->packetSegment_.size() - head_;
132 return pShared_->info_;
136 typedef std::vector<unsigned char> PacketSegment;
141 PacketSegment packetSegment_;
142 PacketInfo info_{0,0,0,{}};
145 PacketSegment::size_type head_;
146 std::shared_ptr<Shared> pShared_;
153 pImpl_{
new Implementation{info,buf,size}}{}
157 pImpl_{
new Implementation{info,vectorIO}}{}
160 pImpl_{
new Implementation{*pkt.pImpl_}}{}
163 pImpl_{std::move(pkt.pImpl_)}{}
169 pImpl_.reset(
new Implementation{*pkt.pImpl_});
175 pImpl_ = std::move(pkt.pImpl_);
182 return pImpl_->strip(size);
188 return pImpl_->stripLengthPrefixFraming();
193 return pImpl_->stripLengthPrefixFramingLong();
198 return pImpl_->get();
204 return pImpl_->length();
210 return pImpl_->getPacketInfo();
A Packet class that allows upstream processing to strip layer headers as the packet travels up the st...
UpstreamPacket(const PacketInfo &info, const void *buf, size_t len)
std::uint32_t stripLengthPrefixFramingLong()
constexpr std::uint32_t NTOHL(std::uint32_t x)
std::uint16_t stripLengthPrefixFraming()
size_t strip(size_t size)
std::vector< iovec > VectorIO
Store source, destination, creation time and priority information for a packet.
const PacketInfo & getPacketInfo() const
constexpr std::uint16_t NTOHS(std::uint16_t x)
UpstreamPacket & operator=(const UpstreamPacket &pkt)