INET Framework for OMNeT++/OMNEST
inet::physicallayer::ApskPhyHeaderSerializer Class Reference

#include <ApskPhyHeaderSerializer.h>

Inheritance diagram for inet::physicallayer::ApskPhyHeaderSerializer:
inet::ChunkSerializer

Public Member Functions

virtual void serialize (MemoryOutputStream &stream, const Ptr< const Chunk > &chunk, b offset, b length) const
 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
 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)
 

Member Function Documentation

◆ deserialize()

const Ptr< Chunk > inet::physicallayer::ApskPhyHeaderSerializer::deserialize ( MemoryInputStream stream,
const std::type_info &  typeInfo 
) const
virtual

Deserializes a chunk from a stream by reading the bytes at the current position of the stream.

The returned chunk will be an instance of the provided type. The current stream position is updated according to the length of the returned chunk.

Implements inet::ChunkSerializer.

39 {
40  auto startPosition = stream.getPosition();
41  auto phyHeader = makeShared<ApskPhyHeader>();
42  b headerLength = b(stream.readUint16Be());
43  phyHeader->setHeaderLengthField(headerLength);
44  phyHeader->setChunkLength(headerLength);
45  phyHeader->setPayloadLengthField(b(stream.readUint16Be()));
46  auto crc = stream.readUint16Be();
47  phyHeader->setCrc(crc);
48  phyHeader->setCrcMode(crc == 0 ? CRC_DISABLED : CRC_COMPUTED);
49  // TODO read protocol
50 
51  b curLength = stream.getPosition() - startPosition;
52  b remainders = headerLength - curLength;
53  if (remainders < b(0)) {
54  phyHeader->markIncorrect();
55  }
56  else {
57  uint8_t remainderbits = remainders.get() % 8;
58  stream.readByteRepeatedly('?', B(remainders - b(remainderbits)).get());
59  stream.readBitRepeatedly(false, remainderbits);
60  }
61  phyHeader->setChunkLength(stream.getPosition() - startPosition);
62  return phyHeader;
63 }

◆ serialize()

void inet::physicallayer::ApskPhyHeaderSerializer::serialize ( MemoryOutputStream stream,
const Ptr< const Chunk > &  chunk,
b  offset,
b  length 
) const
virtual

Serializes a chunk into a stream by writing the bytes representing the chunk at the end of the stream.

The offset and length parameters allow to write only a part of the data.

Implements inet::ChunkSerializer.

19 {
20  auto startPosition = stream.getLength();
21  const auto& phyHeader = staticPtrCast<const ApskPhyHeader>(chunk);
22  stream.writeUint16Be(b(phyHeader->getHeaderLengthField()).get());
23  stream.writeUint16Be(b(phyHeader->getPayloadLengthField()).get());
24  auto crcMode = phyHeader->getCrcMode();
25  if (crcMode != CRC_DISABLED && crcMode != CRC_COMPUTED)
26  throw cRuntimeError("Cannot serialize Apsk Phy header without turned off or properly computed CRC, try changing the value of crcMode parameter for Udp");
27  stream.writeUint16Be(phyHeader->getCrc());
28  // TODO write protocol
29 
30  b remainders = phyHeader->getChunkLength() - (stream.getLength() - startPosition);
31  if (remainders < b(0))
32  throw cRuntimeError("ApskPhyHeader length = %d smaller than required %d bytes", (int)B(phyHeader->getChunkLength()).get(), (int)B(stream.getLength() - startPosition).get());
33  uint8_t remainderbits = remainders.get() % 8;
34  stream.writeByteRepeatedly('?', B(remainders - b(remainderbits)).get());
35  stream.writeBitRepeatedly(false, remainderbits);
36 }

The documentation for this class was generated from the following files:
inet::CRC_COMPUTED
@ CRC_COMPUTED
Definition: CrcMode_m.h:59
inet::CRC_DISABLED
@ CRC_DISABLED
Definition: CrcMode_m.h:56
inet::units::units::B
intscale< b, 1, 8 > B
Definition: Units.h:1168
inet::units::values::b
value< int64_t, units::b > b
Definition: Units.h:1241