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

Converts between AckingMacHeader and binary network byte order mac header. More...

#include <AckingMacHeaderSerializer.h>

Inheritance diagram for inet::AckingMacHeaderSerializer:
inet::FieldsChunkSerializer inet::ChunkSerializer

Public Member Functions

 AckingMacHeaderSerializer ()
 
- 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 AckingMacHeader and binary network byte order mac header.

Constructor & Destructor Documentation

◆ AckingMacHeaderSerializer()

inet::AckingMacHeaderSerializer::AckingMacHeaderSerializer ( )
inline
27 : FieldsChunkSerializer() {}

Member Function Documentation

◆ deserialize()

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

38 {
39  auto startPosition = stream.getPosition();
40  auto macHeader = makeShared<AckingMacHeader>();
41  uint8_t length = stream.readUint8();
42  macHeader->setChunkLength(B(length));
43  macHeader->setSrc(stream.readMacAddress());
44  macHeader->setDest(stream.readMacAddress());
45  macHeader->setNetworkProtocol(stream.readUint16Be());
46  macHeader->setSrcModuleId(stream.readUint64Be());
47  B remainders = B(length) - (stream.getPosition() - startPosition);
48  ASSERT(remainders >= B(0));
49  stream.readByteRepeatedly('?', B(remainders).get());
50  return macHeader;
51 }

◆ serialize()

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

23 {
24  auto startPosition = stream.getLength();
25  auto macHeader = staticPtrCast<const AckingMacHeader>(chunk);
26  stream.writeUint8(B(macHeader->getChunkLength()).get());
27  stream.writeMacAddress(macHeader->getSrc());
28  stream.writeMacAddress(macHeader->getDest());
29  stream.writeUint16Be(macHeader->getNetworkProtocol());
30  stream.writeUint64Be(macHeader->getSrcModuleId());
31  int64_t remainders = B(macHeader->getChunkLength() - (stream.getLength() - startPosition)).get();
32  if (remainders < 0)
33  throw cRuntimeError("AckingMacHeader length = %d smaller than required %d bytes", (int)B(macHeader->getChunkLength()).get(), (int)B(stream.getLength() - startPosition).get());
34  stream.writeByteRepeatedly('?', remainders);
35 }

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