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

#include <BytesChunkSerializer.h>

Inheritance diagram for inet::BytesChunkSerializer:
inet::ChunkSerializer

Public Member Functions

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...
 

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::BytesChunkSerializer::deserialize ( MemoryInputStream stream,
const std::type_info &  typeInfo 
) const
overridevirtual

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.

26 {
27  auto bytesChunk = makeShared<BytesChunk>();
28  B length = stream.getRemainingLength();
29  std::vector<uint8_t> chunkBytes;
30  stream.readBytes(chunkBytes, length);
31  bytesChunk->setBytes(chunkBytes);
33  return bytesChunk;
34 }

◆ serialize()

void inet::BytesChunkSerializer::serialize ( MemoryOutputStream stream,
const Ptr< const Chunk > &  chunk,
b  offset,
b  length 
) const
overridevirtual

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.

18 {
19  const auto& bytesChunk = staticPtrCast<const BytesChunk>(chunk);
20  b serializedLength = length == b(-1) ? bytesChunk->getChunkLength() - offset : length;
21  stream.writeBytes(bytesChunk->getBytes(), offset, serializedLength);
22  ChunkSerializer::totalSerializedLength += serializedLength;
23 }

The documentation for this class was generated from the following files:
inet::units::units::B
intscale< b, 1, 8 > B
Definition: Units.h:1168
inet::ChunkSerializer::totalSerializedLength
static b totalSerializedLength
Definition: ChunkSerializer.h:20
inet::units::values::b
value< int64_t, units::b > b
Definition: Units.h:1241
inet::ChunkSerializer::totalDeserializedLength
static b totalDeserializedLength
Definition: ChunkSerializer.h:21