7namespace hi::inline
v1 {
11 ssize_t _totalNrBytes;
37 return packets.
size();
54 return {packets.
back().end(), nrBytes};
60 std::span<std::byte>
getpacket(ssize_t nrBytes)
noexcept
63 if (packets.
empty() || (packets.
back().writeSize() < nrBytes)) {
66 return {packets.
back().end(), nrBytes};
76 void write(ssize_t nrBytes,
bool push =
true) noexcept
79 packets.
back().write(nrBytes);
81 packets.
back().push();
83 _totalNrBytes += nrBytes;
92 std::span<std::byte const>
peek(ssize_t nrBytes)
94 if (packets.
empty() || size() < nrBytes) {
99 if (packets.
front().readSize() >= nrBytes) {
100 return {packets.
front().readSize(), ssize(packets)};
119 ssize_t packetNr = 0;
122 while (packetNr < nrpackets()) {
123 hi_check(byteNr < nrBytes,
"New-line not found within {} bytes", nrBytes);
125 if (i == ssize(packets[packetNr])) {
131 hilet c = packets[packetNr][i]
if (
c ==
'\n' ||
c ==
'\0')
134 hilet bspan = peek(byteNr + 1);
135 return {
reinterpret_cast<char *
>(bspan.data()), byteNr + 1};
151 void read(ssize_t nrBytes)
noexcept
157 if (nrBytes >= packet_size) {
160 packets.
front().read(nrBytes);
163 nrBytes -= ssize(packets_size);
#define hi_check(expression, message,...)
Check if the expression is valid, or throw a parse_error.
Definition assert.hpp:95
#define hi_assert(expression,...)
Assert if expression is true.
Definition assert.hpp:184
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
DOXYGEN BUG.
Definition algorithm.hpp:13
Definition packet_buffer.hpp:9
void read(ssize_t nrBytes) noexcept
Consume the data from the buffer.
Definition packet_buffer.hpp:151
std::span< std::byte > getNewpacket(ssize_t nrBytes) noexcept
Get a new packet to write a message into.
Definition packet_buffer.hpp:50
std::string_view peekLine(ssize_t nrBytes=1024)
Peek into the data a single text-line without consuming.
Definition packet_buffer.hpp:117
std::span< std::byte const > peek(ssize_t nrBytes)
Peek into the data without consuming.
Definition packet_buffer.hpp:92
bool closed() const noexcept
Connection is closed.
Definition packet_buffer.hpp:18
std::span< std::byte > getpacket(ssize_t nrBytes) noexcept
Get a packet to write a stream of bytes into.
Definition packet_buffer.hpp:60
void close() noexcept
Close the connection on this side.
Definition packet_buffer.hpp:42
void write(ssize_t nrBytes, bool push=true) noexcept
Write the data added to the packet.
Definition packet_buffer.hpp:76
ssize_t nrBytes() const noexcept
Total number of bytes in the buffer.
Definition packet_buffer.hpp:25
ssize_t nrpackets() const noexcept
Total number of packets in the buffer.
Definition packet_buffer.hpp:35
T emplace_back(T... args)