7#include "../macros.hpp"
9hi_export_module(hikogui.net.packet_buffer);
11hi_export
namespace hi::inline
v1 {
15 ssize_t _totalNrBytes;
41 return packets.size();
58 return {packets.back().end(),
nrBytes};
67 if (packets.empty() || (packets.back().writeSize() <
nrBytes)) {
70 return {packets.back().end(),
nrBytes};
85 packets.back().push();
98 if (packets.empty() || size() <
nrBytes) {
103 if (packets.front().readSize() >=
nrBytes) {
104 return {packets.front().readSize(), ssize(packets)};
108 hi_assert(packets.front().size() >=
nrBytes);
123 ssize_t packetNr = 0;
127 hi_check(byteNr <
nrBytes,
"New-line not found within {} bytes",
nrBytes);
129 if (i == ssize(packets[packetNr])) {
135 auto const c = packets[packetNr][i]
if (c ==
'\n' || c ==
'\0')
138 auto const bspan =
peek(byteNr + 1);
139 return {
reinterpret_cast<char *
>(bspan.data()), byteNr + 1};
160 auto const packet_size = ssize(packets.front());
165 hi_assert(ssize(packets.front()) > 0);
167 nrBytes -= ssize(packets_size);
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
Definition packet_buffer.hpp:13
void read(ssize_t nrBytes) noexcept
Consume the data from the buffer.
Definition packet_buffer.hpp:155
std::span< std::byte > getNewpacket(ssize_t nrBytes) noexcept
Get a new packet to write a message into.
Definition packet_buffer.hpp:54
std::string_view peekLine(ssize_t nrBytes=1024)
Peek into the data a single text-line without consuming.
Definition packet_buffer.hpp:121
std::span< std::byte const > peek(ssize_t nrBytes)
Peek into the data without consuming.
Definition packet_buffer.hpp:96
bool closed() const noexcept
Connection is closed.
Definition packet_buffer.hpp:22
std::span< std::byte > getpacket(ssize_t nrBytes) noexcept
Get a packet to write a stream of bytes into.
Definition packet_buffer.hpp:64
void close() noexcept
Close the connection on this side.
Definition packet_buffer.hpp:46
void write(ssize_t nrBytes, bool push=true) noexcept
Write the data added to the packet.
Definition packet_buffer.hpp:80
ssize_t nrBytes() const noexcept
Total number of bytes in the buffer.
Definition packet_buffer.hpp:29
ssize_t nrpackets() const noexcept
Total number of packets in the buffer.
Definition packet_buffer.hpp:39