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

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

#include <GenericAppMsgSerializer.h>

Inheritance diagram for inet::GenericAppMsgSerializer:
inet::FieldsChunkSerializer inet::ChunkSerializer

Public Member Functions

 GenericAppMsgSerializer ()
 
- 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

◆ GenericAppMsgSerializer()

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

Member Function Documentation

◆ deserialize()

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

32 {
33  auto startPosition = stream.getPosition();
34  auto msg = makeShared<GenericAppMsg>();
35  B dataLength = B(stream.readUint32Be());
36  msg->setExpectedReplyLength(B(stream.readUint32Be()));
37  int64_t delayraw = stream.readUint64Be();
38  msg->setReplyDelay(SimTime(delayraw).dbl());
39  msg->setServerClose(stream.readByte() ? true : false);
40  B remainders = dataLength - (stream.getPosition() - startPosition);
41  ASSERT(remainders >= B(0));
42  stream.readByteRepeatedly('?', remainders.get());
43  return msg;
44 }

◆ serialize()

void inet::GenericAppMsgSerializer::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& msg = staticPtrCast<const GenericAppMsg>(chunk);
21  stream.writeUint32Be(B(msg->getChunkLength()).get());
22  stream.writeUint32Be(B(msg->getExpectedReplyLength()).get());
23  stream.writeUint64Be(SimTime(msg->getReplyDelay()).raw());
24  stream.writeByte(msg->getServerClose());
25  int64_t remainders = B(msg->getChunkLength() - (stream.getLength() - startPosition)).get();
26  if (remainders < 0)
27  throw cRuntimeError("GenericAppMsg length = %d smaller than required %d bytes", (int)B(msg->getChunkLength()).get(), (int)B(stream.getLength() - startPosition).get());
28  stream.writeByteRepeatedly('?', remainders);
29 }

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