44 class EMANE::DownstreamPacket::Implementation
48 pShared_{std::make_shared<Shared>()}{}
50 Implementation(
const PacketInfo & info,
const void * buf,
size_t size):
51 pShared_{std::make_shared<Shared>()}
53 const unsigned char * c =
static_cast<const unsigned char *
>(buf);
54 pShared_->segment_ = PacketSegment(&c[0],&c[size]);
55 pShared_->info_ = info;
56 totalLengthBytes_ += size;
59 void prepend(
const void * buf,
size_t size)
61 const unsigned char * c =
static_cast<const unsigned char *
>(buf);
63 segments_.emplace_front(&c[0],&c[size]);
65 totalLengthBytes_ += size;
70 std::uint16_t u16LengthNet{
HTONS(u16Length)};
72 auto c =
reinterpret_cast<const std::uint8_t *
>(&u16LengthNet);
74 segments_.emplace_front(&c[0],&c[
sizeof(u16Length)]);
76 totalLengthBytes_ +=
sizeof(u16Length);
81 return totalLengthBytes_;
86 return pShared_->info_;
93 vectorIO.reserve(segments_.size() + 1);
95 for(
const auto & segment : segments_)
97 vectorIO.push_back({
reinterpret_cast<std::uint8_t *
>(
const_cast<char *
>(segment.c_str())),
101 vectorIO.push_back({
reinterpret_cast<std::uint8_t *
>(
const_cast<char *
>(pShared_->segment_.c_str())),
102 pShared_->segment_.size()});
109 attachedEvents_.push_back(std::make_tuple(nemId,
116 return attachedEvents_;
120 using PacketSegment = std::string;
121 using Segments = std::deque<PacketSegment>;
122 using AttachedEvents = std::list<std::tuple<NEMId,EventId,std::string>>;
127 PacketSegment segment_{};
128 PacketInfo info_{0,0,0,{}};
131 Segments segments_{};
132 PacketSegment::size_type totalLengthBytes_{};
133 AttachedEvents attachedEvents_{};
134 std::shared_ptr<Shared> pShared_;
140 pImpl_{
new Implementation{info,buf,size}}{}
144 pImpl_{
new Implementation{*pkt.pImpl_}}{}
147 pImpl_{std::move(pkt.pImpl_)}{}
153 pImpl_.reset(
new Implementation{*pkt.pImpl_});
159 pImpl_ = std::move(pkt.pImpl_);
165 pImpl_->prepend(buf,size);
170 pImpl_->prependLengthPrefixFraming(u16Length);
176 return pImpl_->getVectorIO();
181 return pImpl_->length();
186 return pImpl_->getPacketInfo();
191 pImpl_->attachEvent(nemId,event);
197 return pImpl_->getEventSerializations();
const PacketInfo & getPacketInfo() const
void attachEvent(NEMId nemId, const Event &event)
Event interface is the base for all events.
void prepend(const void *buf, size_t size)
std::vector< iovec > VectorIO
Store source, destination, creation time and priority information for a packet.
DownstreamPacket & operator=(const DownstreamPacket &pkt)
Specialized packet the allows downstream processing to add layer specific headers as the packet trave...
std::list< std::tuple< EMANE::NEMId, EMANE::EventId, Serialization > > EventSerializations
constexpr std::uint16_t HTONS(std::uint16_t x)
DownstreamPacket(const PacketInfo &info, const void *buf, size_t size)
const EventSerializations & getEventSerializations() const
Utils::VectorIO getVectorIO() const
void prependLengthPrefixFraming(std::uint16_t u16Length)