INET Framework for OMNeT++/OMNEST
inet::TransportPseudoHeaderSerializer Class Reference

Converts between TransportPseudoHeader and binary (network byte order) transport pseudo header. More...

#include <TransportPseudoHeaderSerializer.h>

Inheritance diagram for inet::TransportPseudoHeaderSerializer:
inet::FieldsChunkSerializer inet::ChunkSerializer

Public Member Functions

 TransportPseudoHeaderSerializer ()
 
- Public Member Functions inherited from inet::FieldsChunkSerializer
virtual void serialize (MemoryOutputStream &stream, const Ptr< const Chunk > &chunk, b offset, b length) const override
 Serializes a chunk into a stream by writing the bytes representing the chunk at the end of the stream. More...
 
virtual const Ptr< Chunkdeserialize (MemoryInputStream &stream, const std::type_info &typeInfo) const override
 Deserializes a chunk from a stream by reading the bytes at the current position of the stream. More...
 

Protected Member Functions

virtual void serialize (MemoryOutputStream &stream, const Ptr< const Chunk > &chunk) const override
 Serializes a chunk into a stream by writing all bytes representing the chunk at the end of the stream. More...
 
virtual const Ptr< Chunkdeserialize (MemoryInputStream &stream) const override
 Deserializes a chunk from a stream by reading the bytes at the current position of the stream. More...
 

Additional Inherited Members

- Static Public Attributes inherited from inet::ChunkSerializer
static b totalSerializedLength = b(0)
 
static b totalDeserializedLength = b(0)
 

Detailed Description

Converts between TransportPseudoHeader and binary (network byte order) transport pseudo header.

Constructor & Destructor Documentation

◆ TransportPseudoHeaderSerializer()

inet::TransportPseudoHeaderSerializer::TransportPseudoHeaderSerializer ( )
inline
25 : FieldsChunkSerializer() {}

Member Function Documentation

◆ deserialize()

const Ptr< Chunk > inet::TransportPseudoHeaderSerializer::deserialize ( MemoryInputStream stream) const
overrideprotectedvirtual

Deserializes a chunk from a stream by reading the bytes at the current position of the stream.

The current stream position is updated according to the length of the returned chunk.

Implements inet::FieldsChunkSerializer.

46 {
47  throw cRuntimeError("TransportPseudoHeader is not a valid deserializable data");
48 }

◆ serialize()

void inet::TransportPseudoHeaderSerializer::serialize ( MemoryOutputStream stream,
const Ptr< const Chunk > &  chunk 
) const
overrideprotectedvirtual

Serializes a chunk into a stream by writing all bytes representing the chunk at the end of the stream.

Implements inet::FieldsChunkSerializer.

19 {
20  // FIXME ipv6, generic ????
21  const auto& transportPseudoHeader = staticPtrCast<const TransportPseudoHeader>(chunk);
22  auto nwProtId = transportPseudoHeader->getNetworkProtocolId();
23  if (nwProtId == Protocol::ipv4.getId()) {
24  ASSERT(transportPseudoHeader->getChunkLength() == B(12));
25  stream.writeIpv4Address(transportPseudoHeader->getSrcAddress().toIpv4());
26  stream.writeIpv4Address(transportPseudoHeader->getDestAddress().toIpv4());
27  stream.writeByte(0);
28  stream.writeByte(transportPseudoHeader->getProtocolId());
29  stream.writeUint16Be(B(transportPseudoHeader->getPacketLength()).get());
30  }
31  else if (nwProtId == Protocol::ipv6.getId()) {
32  ASSERT(transportPseudoHeader->getChunkLength() == B(40));
33  stream.writeIpv6Address(transportPseudoHeader->getSrcAddress().toIpv6());
34  stream.writeIpv6Address(transportPseudoHeader->getDestAddress().toIpv6());
35  stream.writeUint32Be(B(transportPseudoHeader->getPacketLength()).get());
36  stream.writeByte(0);
37  stream.writeByte(0);
38  stream.writeByte(0);
39  stream.writeByte(transportPseudoHeader->getProtocolId());
40  }
41  else
42  throw cRuntimeError("Unknown network protocol: %d", nwProtId);
43 }

The documentation for this class was generated from the following files:
inet::Protocol::ipv4
static const Protocol ipv4
Definition: Protocol.h:93
inet::Protocol::ipv6
static const Protocol ipv6
Definition: Protocol.h:94
inet::units::units::B
intscale< b, 1, 8 > B
Definition: Units.h:1168