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

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

#include <CsmaCaMacHeaderSerializer.h>

Inheritance diagram for inet::CsmaCaMacHeaderSerializer:
inet::FieldsChunkSerializer inet::ChunkSerializer

Public Member Functions

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

Constructor & Destructor Documentation

◆ CsmaCaMacHeaderSerializer()

inet::CsmaCaMacHeaderSerializer::CsmaCaMacHeaderSerializer ( )
inline
26 : FieldsChunkSerializer() {}

Member Function Documentation

◆ deserialize()

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

47 {
48  auto startPos = stream.getPosition();
49  CsmaCaMacHeaderType type = static_cast<CsmaCaMacHeaderType>(stream.readUint8());
50  uint8_t length = stream.readUint8();
51  switch (type) {
52  case CSMA_DATA: {
53  auto macHeader = makeShared<CsmaCaMacDataHeader>();
54  macHeader->setType(type);
55  macHeader->setHeaderLengthField(length);
56  macHeader->setReceiverAddress(stream.readMacAddress());
57  macHeader->setTransmitterAddress(stream.readMacAddress());
58  macHeader->setNetworkProtocol(stream.readUint16Be());
59  macHeader->setPriority(stream.readByte());
60  if (B(length) > stream.getPosition() - startPos)
61  stream.readByteRepeatedly('?', length - B(stream.getPosition() - startPos).get());
62  return macHeader;
63  }
64  case CSMA_ACK: {
65  auto macHeader = makeShared<CsmaCaMacAckHeader>();
66  macHeader->setType(type);
67  macHeader->setHeaderLengthField(length);
68  macHeader->setReceiverAddress(stream.readMacAddress());
69  macHeader->setTransmitterAddress(stream.readMacAddress());
70  if (B(length) > stream.getPosition() - startPos)
71  stream.readByteRepeatedly('?', length - B(stream.getPosition() - startPos).get());
72  return macHeader;
73  }
74  default:
75  throw cRuntimeError("CsmaCaMacSerializer: cannot deserialize chunk");
76  }
77  return nullptr;
78 }

◆ serialize()

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

20 {
21  auto startPos = stream.getLength();
22  if (auto macHeader = dynamicPtrCast<const CsmaCaMacDataHeader>(chunk)) {
23  stream.writeUint8(macHeader->getType());
24  auto length = macHeader->getHeaderLengthField();
25  stream.writeUint8(length);
26  stream.writeMacAddress(macHeader->getReceiverAddress());
27  stream.writeMacAddress(macHeader->getTransmitterAddress());
28  stream.writeUint16Be(macHeader->getNetworkProtocol());
29  stream.writeByte(macHeader->getPriority());
30  if (macHeader->getChunkLength() > stream.getLength() - startPos)
31  stream.writeByteRepeatedly('?', B(macHeader->getChunkLength() - (stream.getLength() - startPos)).get());
32  }
33  else if (auto macHeader = dynamicPtrCast<const CsmaCaMacAckHeader>(chunk)) {
34  stream.writeUint8(0x01);
35  auto length = macHeader->getHeaderLengthField();
36  stream.writeUint8(length);
37  stream.writeMacAddress(macHeader->getReceiverAddress());
38  stream.writeMacAddress(macHeader->getTransmitterAddress());
39  if (macHeader->getChunkLength() > stream.getLength() - startPos)
40  stream.writeByteRepeatedly('?', B(macHeader->getChunkLength() - (stream.getLength() - startPos)).get());
41  }
42  else
43  throw cRuntimeError("CsmaCaMacSerializer: cannot serialize chunk");
44 }

The documentation for this class was generated from the following files:
inet::CsmaCaMacHeaderType
CsmaCaMacHeaderType
Enum generated from inet/linklayer/csmaca/CsmaCaMacHeader.msg:14 by opp_msgtool.
Definition: CsmaCaMacHeader_m.h:61
inet::units::units::B
intscale< b, 1, 8 > B
Definition: Units.h:1168
type
removed type
Definition: IUdp-gates.txt:7
inet::CSMA_ACK
@ CSMA_ACK
Definition: CsmaCaMacHeader_m.h:63
inet::CSMA_DATA
@ CSMA_DATA
Definition: CsmaCaMacHeader_m.h:62