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

Converts between EchoPacket and binary (network byte order) echo packet. More...

#include <EchoPacketSerializer.h>

Inheritance diagram for inet::EchoPacketSerializer:
inet::FieldsChunkSerializer inet::ChunkSerializer

Public Member Functions

 EchoPacketSerializer ()
 
- 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 EchoPacket and binary (network byte order) echo packet.

Constructor & Destructor Documentation

◆ EchoPacketSerializer()

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

Member Function Documentation

◆ deserialize()

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

26 {
27  auto echoPacket = makeShared<EchoPacket>();
28  echoPacket->setType(static_cast<inet::EchoProtocolType>(stream.readUint16Be()));
29  echoPacket->setIdentifier(stream.readUint16Be());
30  echoPacket->setSeqNumber(stream.readUint16Be());
31  return echoPacket;
32 }

◆ serialize()

void inet::EchoPacketSerializer::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& echoPacket = staticPtrCast<const EchoPacket>(chunk);
20  stream.writeUint16Be(echoPacket->getType());
21  stream.writeUint16Be(echoPacket->getIdentifier());
22  stream.writeUint16Be(echoPacket->getSeqNumber());
23 }

The documentation for this class was generated from the following files:
inet::EchoProtocolType
EchoProtocolType
Enum generated from inet/networklayer/common/EchoPacket.msg:16 by opp_msgtool.
Definition: EchoPacket_m.h:57