Converts between UnitDiskPhyHeader and binary (network byte order) application packet.
More...
#include <UnitDiskPhyHeaderSerializer.h>
Converts between UnitDiskPhyHeader and binary (network byte order) application packet.
◆ UnitDiskPhyHeaderSerializer()
| inet::UnitDiskPhyHeaderSerializer::UnitDiskPhyHeaderSerializer |
( |
| ) |
|
|
inline |
25 : FieldsChunkSerializer() {}
◆ deserialize()
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.
31 auto startPosition = stream.getPosition();
32 auto header = makeShared<UnitDiskPhyHeader>();
33 b dataLength =
b(stream.readUint16Be());
34 header->setChunkLength(dataLength);
36 b remainders = dataLength - (stream.getPosition() - startPosition);
37 ASSERT(remainders >=
b(0));
38 stream.readBitRepeatedly(
false,
b(remainders).get());
◆ 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.
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();
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);
The documentation for this class was generated from the following files: