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

#include <EthernetControlFrameSerializer.h>

Inheritance diagram for inet::EthernetControlFrameSerializer:
inet::FieldsChunkSerializer inet::ChunkSerializer

Public Member Functions

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

Constructor & Destructor Documentation

◆ EthernetControlFrameSerializer()

inet::EthernetControlFrameSerializer::EthernetControlFrameSerializer ( )
inline
22 : FieldsChunkSerializer() {}

Member Function Documentation

◆ deserialize()

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

34 {
35  Ptr<EthernetControlFrameBase> controlFrame = nullptr;
36  uint16_t opCode = stream.readUint16Be();
37  if (opCode == ETHERNET_CONTROL_PAUSE) {
38  auto pauseFrame = makeShared<EthernetPauseFrame>();
39  pauseFrame->setOpCode(opCode);
40  pauseFrame->setPauseTime(stream.readUint16Be());
41  controlFrame = pauseFrame;
42  }
43  else {
44  controlFrame = makeShared<EthernetControlFrameBase>();
45  controlFrame->setOpCode(opCode);
46  controlFrame->markImproperlyRepresented();
47  }
48  return controlFrame;
49 }

◆ serialize()

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

21 {
22  const auto& frame = staticPtrCast<const EthernetControlFrameBase>(chunk);
23  stream.writeUint16Be(frame->getOpCode());
24  if (frame->getOpCode() == ETHERNET_CONTROL_PAUSE) {
25  auto pauseFrame = dynamicPtrCast<const EthernetPauseFrame>(frame);
26  ASSERT(pauseFrame != nullptr);
27  stream.writeUint16Be(pauseFrame->getPauseTime());
28  }
29  else
30  throw cRuntimeError("Cannot serialize '%s' (EthernetControlFrame with opCode = %d)", frame->getClassName(), frame->getOpCode());
31 }

The documentation for this class was generated from the following files:
inet::ETHERNET_CONTROL_PAUSE
@ ETHERNET_CONTROL_PAUSE
Definition: EthernetControlFrame_m.h:55