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

Converts between ApplicationPacket and binary (network byte order) application packet. More...

#include <ApplicationPacketSerializer.h>

Inheritance diagram for inet::ApplicationPacketSerializer:
inet::FieldsChunkSerializer inet::ChunkSerializer

Public Member Functions

 ApplicationPacketSerializer ()
 
- 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 ApplicationPacket and binary (network byte order) application packet.

Constructor & Destructor Documentation

◆ ApplicationPacketSerializer()

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

Member Function Documentation

◆ deserialize()

const Ptr< Chunk > inet::ApplicationPacketSerializer::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 startPosition = stream.getPosition();
32  auto applicationPacket = makeShared<ApplicationPacket>();
33  B dataLength = B(stream.readUint32Be());
34  applicationPacket->setSequenceNumber(stream.readUint32Be());
35  B remainders = dataLength - (stream.getPosition() - startPosition);
36  ASSERT(remainders >= B(0));
37  stream.readByteRepeatedly('?', B(remainders).get());
38  return applicationPacket;
39 }

◆ serialize()

void inet::ApplicationPacketSerializer::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  auto startPosition = stream.getLength();
20  const auto& applicationPacket = staticPtrCast<const ApplicationPacket>(chunk);
21  stream.writeUint32Be(B(applicationPacket->getChunkLength()).get());
22  stream.writeUint32Be(applicationPacket->getSequenceNumber());
23  int64_t remainders = B(applicationPacket->getChunkLength() - (stream.getLength() - startPosition)).get();
24  if (remainders < 0)
25  throw cRuntimeError("ApplicationPacket length = %d smaller than required %d bytes", (int)B(applicationPacket->getChunkLength()).get(), (int)B(stream.getLength() - startPosition).get());
26  stream.writeByteRepeatedly('?', remainders);
27 }

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