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

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

#include <EtherAppPacketSerializer.h>

Inheritance diagram for inet::EtherAppRespSerializer:
inet::FieldsChunkSerializer inet::ChunkSerializer

Public Member Functions

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

Constructor & Destructor Documentation

◆ EtherAppRespSerializer()

inet::EtherAppRespSerializer::EtherAppRespSerializer ( )
inline
38 : FieldsChunkSerializer() {}

Member Function Documentation

◆ deserialize()

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

59 {
60  auto startPosition = stream.getPosition();
61  auto etherAppResp = makeShared<EtherAppResp>();
62  B dataLength = B(stream.readUint32Be());
63  etherAppResp->setChunkLength(dataLength);
64  etherAppResp->setRequestId(stream.readUint32Be());
65  etherAppResp->setNumFrames(stream.readUint32Be());
66  B remainders = dataLength - (stream.getPosition() - startPosition);
67  ASSERT(remainders >= B(0));
68  stream.readByteRepeatedly('?', B(remainders).get());
69  return etherAppResp;
70 }

◆ serialize()

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

46 {
47  auto startPosition = stream.getLength();
48  const auto& etherAppResp = staticPtrCast<const EtherAppResp>(chunk);
49  stream.writeUint32Be(B(etherAppResp->getChunkLength()).get());
50  stream.writeUint32Be(etherAppResp->getRequestId());
51  stream.writeUint32Be(etherAppResp->getNumFrames());
52  int64_t remainders = B(etherAppResp->getChunkLength() - (stream.getLength() - startPosition)).get();
53  if (remainders < 0)
54  throw cRuntimeError("EtherAppResp length = %d smaller than required %d bytes", (int)B(etherAppResp->getChunkLength()).get(), (int)B(stream.getLength() - startPosition).get());
55  stream.writeByteRepeatedly('?', remainders);
56 }

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