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

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

#include <EtherAppPacketSerializer.h>

Inheritance diagram for inet::EtherAppReqSerializer:
inet::FieldsChunkSerializer inet::ChunkSerializer

Public Member Functions

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

Constructor & Destructor Documentation

◆ EtherAppReqSerializer()

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

Member Function Documentation

◆ deserialize()

const Ptr< Chunk > inet::EtherAppReqSerializer::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 etherAppReq = makeShared<EtherAppReq>();
35  B dataLength = B(stream.readUint32Be());
36  etherAppReq->setChunkLength(dataLength);
37  etherAppReq->setRequestId(stream.readUint32Be());
38  etherAppReq->setResponseBytes(stream.readUint32Be());
39  B remainders = dataLength - (stream.getPosition() - startPosition);
40  ASSERT(remainders >= B(0));
41  stream.readByteRepeatedly('?', B(remainders).get());
42  return etherAppReq;
43 }

◆ serialize()

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

19 {
20  auto startPosition = stream.getLength();
21  const auto& etherAppReq = staticPtrCast<const EtherAppReq>(chunk);
22  stream.writeUint32Be(B(etherAppReq->getChunkLength()).get());
23  stream.writeUint32Be(etherAppReq->getRequestId());
24  stream.writeUint32Be(etherAppReq->getResponseBytes());
25  int64_t remainders = B(etherAppReq->getChunkLength() - (stream.getLength() - startPosition)).get();
26  if (remainders < 0)
27  throw cRuntimeError("EtherAppReq length = %d smaller than required %d bytes", (int)B(etherAppReq->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