4 #ifndef _3ESHEADERSTREAM_H_ 5 #define _3ESHEADERSTREAM_H_ 10 #include "3espacketheader.h" 18 template <
class HEADER>
83 const CrcType *
crcPtr()
const;
87 inline uint16_t
status()
const;
112 uint16_t
tell()
const;
119 const uint8_t *
payload()
const;
132 inline bool check()
const {
return false; }
141 inline bool check()
const {
return true; }
148 template <
class HEADER>
154 if (IsConst<HEADER>().check())
161 template <
class HEADER>
167 if (offset <= _packet.payloadSize)
169 _payloadPosition = offset;
175 if (offset >= 0 && offset + _payloadPosition <= _packet.payloadSize ||
176 offset < 0 && _payloadPosition >= -offset)
178 _payloadPosition += offset;
184 if (offset < _packet.payloadSize)
186 _payloadPosition = _packet.
payloadSize - 1 - offset;
199 template <
class HEADER>
204 uint8_t *pos =
const_cast<uint8_t*
>(
reinterpret_cast<const uint8_t*
>(&_packet)) +
sizeof(HEADER) + payloadSize();
205 return reinterpret_cast<CrcType*
>(pos);
209 template <
class HEADER>
213 const uint8_t *pos =
reinterpret_cast<const uint8_t*
>(&_packet) +
sizeof(HEADER) + payloadSize();
214 return reinterpret_cast<const CrcType*
>(pos);
218 template <
class HEADER>
224 template <
class HEADER>
230 template <
class HEADER>
233 return _payloadPosition;
236 template <
class HEADER>
239 return reinterpret_cast<const uint8_t*
>(&_packet) +
sizeof(HEADER);
243 #endif // _3ESHEADERSTREAM_H_ HEADER & packet() const
Access the head of the packet buffer, for direct PacketHeader access.
Definition: 3espacketstream.h:225
Type traits: is T const?
Definition: 3espacketstream.h:128
bool isOk() const
Status OK?
Definition: 3espacketstream.h:94
Read only stream?
Definition: 3espacketstream.h:43
uint16_t payloadSize() const
Fetch the payload size bytes in local endian.
Definition: 3espacketstream.h:64
Seek from the beginning of the stream.
Definition: 3espacketstream.h:28
End at of packet/stream.
Definition: 3espacketstream.h:39
Seek from the end of the stream.
Definition: 3espacketstream.h:30
uint16_t messageId() const
Fetch the message ID bytes in local endian.
Definition: 3espacketstream.h:73
bool isReadOnly() const
Read only stream?
Definition: 3espacketstream.h:100
bool isEop() const
At end of packet/stream?
Definition: 3espacketstream.h:91
Definition: 3esbounds.h:13
PacketStream(HEADER &packet)
Create a stream to read from beginning at packet.
Definition: 3espacketstream.h:149
uint16_t status() const
Report the Status bits.
Definition: 3espacketstream.h:219
uint16_t packetSize() const
Returns the size of the packet plus payload, giving the full data packet size including the CRC...
Definition: 3espacketstream.h:67
uint16_t tell() const
Tell the current stream position.
Definition: 3espacketstream.h:231
uint16_t _status
Status bits.
Definition: 3espacketstream.h:123
const uint8_t * payload() const
Direct payload pointer access.
Definition: 3espacketstream.h:237
Is the CRC valid?
Definition: 3espacketstream.h:45
A utility class used for managing read/write operations to a PacketHeader payload.
Definition: 3espacketstream.h:19
bool isCrcValid() const
CRC validated?
Definition: 3espacketstream.h:103
Status
Status bits.
Definition: 3espacketstream.h:34
SeekPos
Control values for seeking.
Definition: 3espacketstream.h:26
CrcType crc() const
Fetch the CRC bytes in local endian.
Definition: 3espacketstream.h:77
bool check() const
Check the traits.
Definition: 3espacketstream.h:141
uint16_t versionMajor() const
Fetch the major version bytes in local endian.
Definition: 3espacketstream.h:58
uint32_t marker() const
Fetch the marker bytes in local endian.
Definition: 3espacketstream.h:55
uint16_t routingId() const
Fetch the routing ID bytes in local endian.
Definition: 3espacketstream.h:70
bool check() const
Check the traits.
Definition: 3espacketstream.h:132
T networkEndianSwapValue(const T &data)
Return a copy of data with byte order switched if host byte order is not network byte order...
Definition: 3esendian.h:244
bool seek(int offset, SeekPos pos=Begin)
Seek to the indicated position.
Definition: 3espacketstream.h:162
Seek from the current position.
Definition: 3espacketstream.h:29
Marks a PacketHeader as missing its 16-bit CRC.
Definition: 3espacketheader.h:24
Set after an operation fails.
Definition: 3espacketstream.h:41
uint16_t _payloadPosition
Payload cursor.
Definition: 3espacketstream.h:124
uint16_t versionMinor() const
Fetch the minor version bytes in local endian.
Definition: 3espacketstream.h:61
uint16_t CrcType
Defies the packet CRC type.
Definition: 3espacketstream.h:23
CrcType * crcPtr()
Fetch a pointer to the CRC bytes.
Definition: 3espacketstream.h:200
No issues.
Definition: 3espacketstream.h:37
bool isFail() const
Fail bit set?
Definition: 3espacketstream.h:97
HEADER & _packet
Packet header and buffer start address.
Definition: 3espacketstream.h:122