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

Converts between UdpHeader and binary (network byte order) Udp header. More...

#include <UdpHeaderSerializer.h>

Inheritance diagram for inet::UdpHeaderSerializer:
inet::FieldsChunkSerializer inet::ChunkSerializer

Public Member Functions

 UdpHeaderSerializer ()
 
- 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 UdpHeader and binary (network byte order) Udp header.

Constructor & Destructor Documentation

◆ UdpHeaderSerializer()

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

Member Function Documentation

◆ deserialize()

const Ptr< Chunk > inet::UdpHeaderSerializer::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.

30 {
31  auto udpHeader = makeShared<UdpHeader>();
32  udpHeader->setSourcePort(stream.readUint16Be());
33  udpHeader->setDestinationPort(stream.readUint16Be());
34  udpHeader->setTotalLengthField(B(stream.readUint16Be()));
35  auto crc = stream.readUint16Be();
36  udpHeader->setCrc(crc);
37  udpHeader->setCrcMode(crc == 0 ? CRC_DISABLED : CRC_COMPUTED);
38  return udpHeader;
39 }

◆ serialize()

void inet::UdpHeaderSerializer::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.

18 {
19  const auto& udpHeader = staticPtrCast<const UdpHeader>(chunk);
20  stream.writeUint16Be(udpHeader->getSourcePort());
21  stream.writeUint16Be(udpHeader->getDestinationPort());
22  stream.writeUint16Be(B(udpHeader->getTotalLengthField()).get());
23  auto crcMode = udpHeader->getCrcMode();
24  if (crcMode != CRC_DISABLED && crcMode != CRC_COMPUTED)
25  throw cRuntimeError("Cannot serialize UDP header without turned off or properly computed CRC, try changing the value of crcMode parameter for Udp");
26  stream.writeUint16Be(udpHeader->getCrc());
27 }

The documentation for this class was generated from the following files:
inet::CRC_COMPUTED
@ CRC_COMPUTED
Definition: CrcMode_m.h:59
inet::CRC_DISABLED
@ CRC_DISABLED
Definition: CrcMode_m.h:56
inet::units::units::B
intscale< b, 1, 8 > B
Definition: Units.h:1168