56 return "unknown status";
88 char *begin =
const_cast<char *
>(
reinterpret_cast<const char *
>(data));
89 setg(begin, begin, begin + size);
93 return static_cast<std::size_t
>(egptr() - gptr());
98 void WritePod(std::ostream &out,
const T &value) {
99 static_assert(std::is_trivially_copyable_v<T>,
"only plain values go on the wire");
100 out.write(
reinterpret_cast<const char *
>(&value),
sizeof(T));
103 template <
typename T>
105 static_assert(std::is_trivially_copyable_v<T>,
"only plain values go on the wire");
106 in.read(
reinterpret_cast<char *
>(&value),
sizeof(T));
120 out.write(payload.data(),
static_cast<std::streamsize
>(payload.size()));
129 template <
typename ReadPacket>
132 std::size_t offset = 0u;
133 while (offset < size) {
140 uint32_t payload_size = 0u;
141 std::memcpy(&
id, data + offset,
sizeof(
id));
142 std::memcpy(&payload_size, data + offset +
sizeof(
id),
sizeof(payload_size));
146 if (payload_size > size - payload) {
152 std::istream in(&buffer);
157 result.
frame = frame;
160#ifndef LIBCARLA_NO_EXCEPTIONS
163 known = read_packet(
id, in, payload_size);
164#ifndef LIBCARLA_NO_EXCEPTIONS
165 }
catch (
const std::exception &) {
176 }
else if (in.fail()) {
182 offset = payload + payload_size;
207 template <
typename T>
212 _remaining -=
static_cast<uint32_t
>(
sizeof(T));
220 _in.read(
static_cast<char *
>(out),
static_cast<std::streamsize
>(bytes));
232 _in.ignore(
static_cast<std::streamsize
>(bytes));
233 if (
static_cast<uint32_t
>(
_in.gcount()) != bytes) {
242 template <
typename F>
259 if (!
Read(count) || !
Read(record_size)) {
262 if ((record_size < min_record_size) ||
263 (
static_cast<uint64_t
>(count) * record_size >
_remaining)) {
282 template <
typename F>
291 template <
typename F>
318 _in.setstate(std::ios_base::failbit);
339 out.write(bytes.data(),
static_cast<std::streamsize
>(bytes.size()));
342 inline void WriteField(std::ostream &out, uint8_t kind,
const std::string &value) {
Reads the fields of one packet (or one record inside it) without ever consuming more than its declare...
bool ReadFixedListHeader(uint16_t min_record_size, uint32_t &count, uint16_t &record_size)
Header of a list of fixed-size records, checked against the bytes left.
bool Skip(uint32_t bytes)
bool ReadRecord(uint32_t bytes, F &&read)
Runs read(record) on the next bytes as a reader of their own, then skips what it left unread (a recor...
uint32_t Remaining() const
bool ReadSizedRecord(F &&read)
Reads one [u32 record_size][record] entry of a variable-size list.
BoundedReader(std::istream &in, uint32_t size)
bool ReadVariableListCount(uint32_t &count)
Count of a list of variable-size records, checked against the bytes left.
bool ReadBytes(void *out, uint32_t bytes)
bool ReadFields(F &&read)
Reads TLV fields until the reader is exhausted.
Read-only stream buffer over one packet's payload.
std::size_t Remaining() const
PayloadBuffer(const uint8_t *data, std::size_t size)
bool ReadPod(std::istream &in, T &value)
void WritePod(std::ostream &out, const T &value)
void WriteFixedListHeader(std::ostream &out, uint32_t count, uint16_t record_size)
Header of a list of fixed-size records.
@ Inconsistent
Packets that contradict each other (set by the reader's owner, e.g.
FrameDataReadResult ReadFrameData(const uint8_t *data, std::size_t size, ReadPacket &&read_packet)
Walks the packets of one frame.
constexpr std::size_t kFrameDataHeaderSize
Frame data (the SEND_FRAME payload) is a sequence of packets [uint8 id][uint32 payload size][payload]...
const char * FrameDataStatusName(FrameDataStatus status)
void WriteField(std::ostream &out, uint8_t kind, const std::string &value)
void WriteFrameDataHeader(std::ostream &out, uint8_t id, uint32_t payload_size)
void WriteSizedBytes(std::ostream &out, const std::string &bytes)
One [u32 size][bytes] entry: a variable-size record or, after a kind byte, a TLV value.
constexpr uint8_t kFrameCounterPacketId
Id of the frame counter packet, the last packet of every complete frame.
constexpr uint8_t kMultiGpuProtocolVersion
Version of the whole Multi-GPU wire format, carried in every frame.
void WriteFrameDataPacket(std::ostream &out, uint8_t id, const std::string &payload)
Writes a packet whose payload was built beforehand.
This file contains definitions of common data structures used in traffic manager.
bool IsComplete() const
Only a complete frame may be played.
uint32_t skipped
Packets whose id this build does not know.
std::optional< uint64_t > frame
Value of the frame counter packet, if it was read.
uint32_t grown
Known packets with trailing bytes this build does not read (written by a newer build).
uint8_t packet_id
Id, offset and declared size of the last packet looked at.