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

#include <Ieee8022LlcHeaderSerializer.h>

Inheritance diagram for inet::Ieee8022LlcHeaderSerializer:
inet::FieldsChunkSerializer inet::ChunkSerializer

Public Member Functions

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

◆ Ieee8022LlcHeaderSerializer()

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

Member Function Documentation

◆ deserialize()

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

37 {
38  Ptr<Ieee8022LlcHeader> llcHeader = nullptr;
39  uint8_t ssap = stream.readByte();
40  uint8_t dsap = stream.readByte();
41  uint16_t ctrl = stream.readByte();
42  if ((ctrl & 3) != 3)
43  ctrl |= ((uint16_t)stream.readByte()) << 8;
44  if (dsap == 0xAA && ssap == 0xAA && ctrl == 0x03) {
45  auto snapHeader = makeShared<Ieee8022LlcSnapHeader>();
46  snapHeader->setOui(((uint32_t)stream.readByte() << 16) + stream.readUint16Be());
47  snapHeader->setProtocolId(stream.readUint16Be());
48  llcHeader = snapHeader;
49  }
50  else
51  llcHeader = makeShared<Ieee8022LlcHeader>();
52  llcHeader->setDsap(dsap);
53  llcHeader->setSsap(ssap);
54  llcHeader->setControl(ctrl);
55  return llcHeader;
56 }

◆ serialize()

void inet::Ieee8022LlcHeaderSerializer::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  const auto& llcHeader = CHK(dynamicPtrCast<const Ieee8022LlcHeader>(chunk));
22  stream.writeByte(llcHeader->getSsap());
23  stream.writeByte(llcHeader->getDsap());
24  auto control = llcHeader->getControl();
25  stream.writeByte(control);
26  if ((control & 3) != 3)
27  stream.writeByte(control >> 8);
28  if (auto snapHeader = dynamicPtrCast<const Ieee8022LlcSnapHeader>(chunk)) {
29  stream.writeByte(snapHeader->getOui() >> 16);
30  stream.writeByte(snapHeader->getOui() >> 8);
31  stream.writeByte(snapHeader->getOui());
32  stream.writeUint16Be(snapHeader->getProtocolId());
33  }
34 }

The documentation for this class was generated from the following files:
CHK
#define CHK(x)
Definition: INETDefs.h:87
ctrl
removed ctrl
Definition: IUdp-gates.txt:7