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

Converts between MplsPacket and binary (network byte order) MPLS packet. More...

#include <MplsPacketSerializer.h>

Inheritance diagram for inet::MplsPacketSerializer:
inet::FieldsChunkSerializer inet::ChunkSerializer

Public Member Functions

 MplsPacketSerializer ()
 
- 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 MplsPacket and binary (network byte order) MPLS packet.

Constructor & Destructor Documentation

◆ MplsPacketSerializer()

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

Member Function Documentation

◆ deserialize()

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

27 {
28  auto mplsHeader = makeShared<MplsHeader>();
29  mplsHeader->setLabel(stream.readNBitsToUint64Be(20));
30  mplsHeader->setTc(stream.readNBitsToUint64Be(3));
31  mplsHeader->setS(stream.readBit());
32  mplsHeader->setTtl(stream.readUint8());
33  return mplsHeader;
34 }

◆ serialize()

void inet::MplsPacketSerializer::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& mplsHeader = staticPtrCast<const MplsHeader>(chunk);
20  stream.writeNBitsOfUint64Be(mplsHeader->getLabel(), 20);
21  stream.writeNBitsOfUint64Be(mplsHeader->getTc(), 3);
22  stream.writeBit(mplsHeader->getS());
23  stream.writeUint8(mplsHeader->getTtl());
24 }

The documentation for this class was generated from the following files: