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

Converts between UnitDiskPhyHeader and binary (network byte order) application packet. More...

#include <UnitDiskPhyHeaderSerializer.h>

Inheritance diagram for inet::UnitDiskPhyHeaderSerializer:
inet::FieldsChunkSerializer inet::ChunkSerializer

Public Member Functions

 UnitDiskPhyHeaderSerializer ()
 
- 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 UnitDiskPhyHeader and binary (network byte order) application packet.

Constructor & Destructor Documentation

◆ UnitDiskPhyHeaderSerializer()

inet::UnitDiskPhyHeaderSerializer::UnitDiskPhyHeaderSerializer ( )
inline
25 : FieldsChunkSerializer() {}

Member Function Documentation

◆ deserialize()

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

30 {
31  auto startPosition = stream.getPosition();
32  auto header = makeShared<UnitDiskPhyHeader>();
33  b dataLength = b(stream.readUint16Be());
34  header->setChunkLength(dataLength);
35  header->setPayloadProtocol(Protocol::findProtocol(stream.readUint16Be()));
36  b remainders = dataLength - (stream.getPosition() - startPosition);
37  ASSERT(remainders >= b(0));
38  stream.readBitRepeatedly(false, b(remainders).get());
39  return header;
40 }

◆ serialize()

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

18 {
19  auto startPosition = stream.getLength();
20  const auto& header = staticPtrCast<const UnitDiskPhyHeader>(chunk);
21  stream.writeUint16Be(b(header->getChunkLength()).get());
22  stream.writeUint16Be(header->getPayloadProtocol()->getId());
23  int64_t remainders = b(header->getChunkLength() - (stream.getLength() - startPosition)).get();
24  if (remainders < 0)
25  throw cRuntimeError("UnitDiskPhyHeader length = %d bits is smaller than required %d bits", (int)b(header->getChunkLength()).get(), (int)b(stream.getLength() - startPosition).get());
26  stream.writeBitRepeatedly(false, remainders);
27 }

The documentation for this class was generated from the following files:
inet::units::values::b
value< int64_t, units::b > b
Definition: Units.h:1241
inet::Protocol::findProtocol
static const Protocol * findProtocol(int id)
Definition: Protocol.cc:44