Converts between ApplicationPacket and binary (network byte order) application packet.
More...
#include <ApplicationPacketSerializer.h>
Converts between ApplicationPacket and binary (network byte order) application packet.
◆ ApplicationPacketSerializer()
| inet::ApplicationPacketSerializer::ApplicationPacketSerializer |
( |
| ) |
|
|
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 applicationPacket = makeShared<ApplicationPacket>();
33 B dataLength =
B(stream.readUint32Be());
34 applicationPacket->setSequenceNumber(stream.readUint32Be());
35 B remainders = dataLength - (stream.getPosition() - startPosition);
36 ASSERT(remainders >=
B(0));
37 stream.readByteRepeatedly(
'?',
B(remainders).get());
38 return applicationPacket;
◆ serialize()
| void inet::ApplicationPacketSerializer::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& applicationPacket = staticPtrCast<const ApplicationPacket>(chunk);
21 stream.writeUint32Be(
B(applicationPacket->getChunkLength()).get());
22 stream.writeUint32Be(applicationPacket->getSequenceNumber());
23 int64_t remainders =
B(applicationPacket->getChunkLength() - (stream.getLength() - startPosition)).get();
25 throw cRuntimeError(
"ApplicationPacket length = %d smaller than required %d bytes", (
int)
B(applicationPacket->getChunkLength()).get(), (
int)
B(stream.getLength() - startPosition).get());
26 stream.writeByteRepeatedly(
'?', remainders);
The documentation for this class was generated from the following files: