#include <ApskPhyHeaderSerializer.h>
◆ deserialize()
| const Ptr< Chunk > inet::physicallayer::ApskPhyHeaderSerializer::deserialize |
( |
MemoryInputStream & |
stream, |
|
|
const std::type_info & |
typeInfo |
|
) |
| const |
|
virtual |
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.
40 auto startPosition = stream.getPosition();
41 auto phyHeader = makeShared<ApskPhyHeader>();
42 b headerLength =
b(stream.readUint16Be());
43 phyHeader->setHeaderLengthField(headerLength);
44 phyHeader->setChunkLength(headerLength);
45 phyHeader->setPayloadLengthField(
b(stream.readUint16Be()));
46 auto crc = stream.readUint16Be();
47 phyHeader->setCrc(crc);
51 b curLength = stream.getPosition() - startPosition;
52 b remainders = headerLength - curLength;
53 if (remainders <
b(0)) {
54 phyHeader->markIncorrect();
57 uint8_t remainderbits = remainders.get() % 8;
58 stream.readByteRepeatedly(
'?',
B(remainders -
b(remainderbits)).get());
59 stream.readBitRepeatedly(
false, remainderbits);
61 phyHeader->setChunkLength(stream.getPosition() - startPosition);
◆ serialize()
| void inet::physicallayer::ApskPhyHeaderSerializer::serialize |
( |
MemoryOutputStream & |
stream, |
|
|
const Ptr< const Chunk > & |
chunk, |
|
|
b |
offset, |
|
|
b |
length |
|
) |
| const |
|
virtual |
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.
20 auto startPosition = stream.getLength();
21 const auto& phyHeader = staticPtrCast<const ApskPhyHeader>(chunk);
22 stream.writeUint16Be(
b(phyHeader->getHeaderLengthField()).get());
23 stream.writeUint16Be(
b(phyHeader->getPayloadLengthField()).get());
24 auto crcMode = phyHeader->getCrcMode();
26 throw cRuntimeError(
"Cannot serialize Apsk Phy header without turned off or properly computed CRC, try changing the value of crcMode parameter for Udp");
27 stream.writeUint16Be(phyHeader->getCrc());
30 b remainders = phyHeader->getChunkLength() - (stream.getLength() - startPosition);
31 if (remainders <
b(0))
32 throw cRuntimeError(
"ApskPhyHeader length = %d smaller than required %d bytes", (
int)
B(phyHeader->getChunkLength()).get(), (int)
B(stream.getLength() - startPosition).get());
33 uint8_t remainderbits = remainders.get() % 8;
34 stream.writeByteRepeatedly(
'?',
B(remainders -
b(remainderbits)).get());
35 stream.writeBitRepeatedly(
false, remainderbits);
The documentation for this class was generated from the following files: