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 std::uint32_t u32LengthNet{
HTONL(u32Length)};
83 auto c =
reinterpret_cast<const std::uint8_t *
>(&u32LengthNet);
85 segments_.emplace_front(&c[0],&c[
sizeof(u32Length)]);
87 totalLengthBytes_ +=
sizeof(u32Length);
92 return totalLengthBytes_;
97 return pShared_->info_;
104 vectorIO.reserve(segments_.size() + 1);
106 for(
const auto & segment : segments_)
108 vectorIO.push_back({
reinterpret_cast<std::uint8_t *
>(
const_cast<char *
>(segment.c_str())),
112 vectorIO.push_back({
reinterpret_cast<std::uint8_t *
>(
const_cast<char *
>(pShared_->segment_.c_str())),
113 pShared_->segment_.size()});
120 attachedEvents_.push_back(std::make_tuple(nemId,
127 return attachedEvents_;
131 using PacketSegment = std::string;
132 using Segments = std::deque<PacketSegment>;
133 using AttachedEvents = std::list<std::tuple<NEMId,EventId,std::string>>;
138 PacketSegment segment_{};
139 PacketInfo info_{0,0,0,{}};
142 Segments segments_{};
143 PacketSegment::size_type totalLengthBytes_{};
144 AttachedEvents attachedEvents_{};
145 std::shared_ptr<Shared> pShared_;
151 pImpl_{
new Implementation{info,buf,size}}{}
155 pImpl_{
new Implementation{*pkt.pImpl_}}{}
158 pImpl_{std::move(pkt.pImpl_)}{}
164 pImpl_.reset(
new Implementation{*pkt.pImpl_});
170 pImpl_ = std::move(pkt.pImpl_);
176 pImpl_->prepend(buf,size);
181 pImpl_->prependLengthPrefixFraming(u16Length);
186 pImpl_->prependLengthPrefixFramingLong(u32Length);
191 return pImpl_->getVectorIO();
196 return pImpl_->length();
201 return pImpl_->getPacketInfo();
206 pImpl_->attachEvent(nemId,event);
212 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)
constexpr std::uint32_t HTONL(std::uint32_t x)
void prependLengthPrefixFramingLong(std::uint32_t u32Length)