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

Converts between CrcHeader and binary (network byte order) CRC header. More...

#include <CrcHeaderSerializer.h>

Inheritance diagram for inet::CrcHeaderSerializer:
inet::FieldsChunkSerializer inet::ChunkSerializer

Public Member Functions

 CrcHeaderSerializer ()
 
- 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 CrcHeader and binary (network byte order) CRC header.

Constructor & Destructor Documentation

◆ CrcHeaderSerializer()

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

Member Function Documentation

◆ deserialize()

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

27 {
28  auto crcHeader = makeShared<CrcHeader>();
29  auto crc = stream.readUint16Be();
30  crcHeader->setCrc(crc);
31  crcHeader->setCrcMode(crc == 0 ? CRC_DISABLED : CRC_COMPUTED);
32  return crcHeader;
33 }

◆ serialize()

void inet::CrcHeaderSerializer::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  const auto& crcHeader = staticPtrCast<const CrcHeader>(chunk);
20  auto crcMode = crcHeader->getCrcMode();
21  if (crcMode != CRC_DISABLED && crcMode != CRC_COMPUTED)
22  throw cRuntimeError("Cannot serialize CRC header without turned off or properly computed CRC, try changing the value of crcMode parameter for CrcHeaderInserter");
23  stream.writeUint16Be(crcHeader->getCrc());
24 }

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