5#include "../macros.hpp"
8namespace hi::inline
v1 {
12 ssize_t _totalNrBytes;
38 return packets.size();
55 return {packets.back().end(),
nrBytes};
64 if (packets.empty() || (packets.back().writeSize() <
nrBytes)) {
67 return {packets.back().end(),
nrBytes};
82 packets.back().push();
95 if (packets.empty() || size() <
nrBytes) {
100 if (packets.front().readSize() >=
nrBytes) {
101 return {packets.front().readSize(), ssize(packets)};
105 hi_assert(packets.front().size() >=
nrBytes);
120 ssize_t packetNr = 0;
124 hi_check(byteNr <
nrBytes,
"New-line not found within {} bytes",
nrBytes);
126 if (i == ssize(packets[packetNr])) {
132 hilet c = packets[packetNr][i]
if (c ==
'\n' || c ==
'\0')
135 hilet bspan =
peek(byteNr + 1);
136 return {
reinterpret_cast<char *
>(bspan.data()), byteNr + 1};
157 hilet packet_size = ssize(packets.front());
162 hi_assert(ssize(packets.front()) > 0);
164 nrBytes -= ssize(packets_size);
DOXYGEN BUG.
Definition algorithm.hpp:16
Definition packet_buffer.hpp:10
void read(ssize_t nrBytes) noexcept
Consume the data from the buffer.
Definition packet_buffer.hpp:152
std::span< std::byte > getNewpacket(ssize_t nrBytes) noexcept
Get a new packet to write a message into.
Definition packet_buffer.hpp:51
std::string_view peekLine(ssize_t nrBytes=1024)
Peek into the data a single text-line without consuming.
Definition packet_buffer.hpp:118
std::span< std::byte const > peek(ssize_t nrBytes)
Peek into the data without consuming.
Definition packet_buffer.hpp:93
bool closed() const noexcept
Connection is closed.
Definition packet_buffer.hpp:19
std::span< std::byte > getpacket(ssize_t nrBytes) noexcept
Get a packet to write a stream of bytes into.
Definition packet_buffer.hpp:61
void close() noexcept
Close the connection on this side.
Definition packet_buffer.hpp:43
void write(ssize_t nrBytes, bool push=true) noexcept
Write the data added to the packet.
Definition packet_buffer.hpp:77
ssize_t nrBytes() const noexcept
Total number of bytes in the buffer.
Definition packet_buffer.hpp:26
ssize_t nrpackets() const noexcept
Total number of packets in the buffer.
Definition packet_buffer.hpp:36