34#ifndef _UTILS_SYNCSTREAM_HXX_
35#define _UTILS_SYNCSTREAM_HXX_
59 virtual ssize_t
write(
const void *data,
size_t len) = 0;
79 auto ret =
write(d, len);
97 static const uint8_t *
to_8(
const void *d)
99 return static_cast<const uint8_t *
>(d);
105 return static_cast<uint8_t *
>(d);
122 ssize_t
write(
const void *data,
size_t len)
override
132 memcpy(
data_, data, len);
201 ssize_t
write(
const void *data,
size_t len)
override
211 ssize_t ret =
delegate_->write(data, len);
232 unsigned min_write_length, uint8_t fill_byte,
SyncStream *delegate)
243 unsigned min_write_length,
SyncStream *delegate)
258 ssize_t
write(
const void *data,
size_t len)
override
291 memcpy(buffer_, data, len);
337 void set_output(std::string* output) {
341 ssize_t
write(
const void *data,
size_t len)
override {
342 output_->append((
const char*)data, len);
347 std::string* output_;
355 ssize_t
write(
const void *data,
size_t len)
override
365 ssize_t ret =
delegate_->write(data, len);
Stream implementation that allows running a state machine of different streams, typically alternating...
ssize_t write(const void *data, size_t len) override
Main entry point to the data consumption.
virtual void on_eof()
This function will be called when the delegate returns EOF.
std::unique_ptr< SyncStream > delegate_
Stream implementation to delegate the logic to.
Stream wrapper that limits the number of bytes sent to the child stream, and reports EOF after the gi...
ssize_t write(const void *data, size_t len) override
Main entry point to the data consumption.
size_t remaining_
How many bytes we still have to write.
MaxLengthStream(size_t length, SyncStream *delegate)
Stream wrapper that contains a small internal buffer to ensure that all writes are at least a certain...
unsigned bufLength_
Number of used bytes in the buffer.
uint8_t fillByte_
What byte to append to the stream at finalize time when we still have bytes to send onwards.
unsigned minWriteLength_
Total length of the buffer.
ssize_t write(const void *data, size_t len) override
Main entry point to the data consumption.
int finalize(int status) override
Called once after all data has been written to close the stream and release resources.
uint8_t needsFill_
Whether to do fill (1: yes, 0: no).
Simple stream implementation that appends all data to a given std::string.
StringAppendStream(std::string *output)
ssize_t write(const void *data, size_t len) override
Main entry point to the data consumption.
virtual int finalize(int status)
Called once after all data has been written to close the stream and release resources.
static const uint8_t * to_8(const void *d)
Converts a void pointer to an equivalent byte pointer.
virtual ssize_t write(const void *data, size_t len)=0
Main entry point to the data consumption.
ssize_t write_all(const void *data, size_t len)
Repeatedly writes until all data has been consumed or an error occurs.
static uint8_t * to_8(void *d)
Converts a void pointer to an equivalent byte pointer.
Helper class for defining streams that forward data to another stream internally.
void set_delegate(SyncStream *delegate)
Overrides the target where to send the incoming data onwards.
int finalize(int status) override
Called once after all data has been written to close the stream and release resources.
std::unique_ptr< SyncStream > delegate_
Where to write the data to.
#define LOG(level, message...)
Conditionally write a message to the logging output.
static const int INFO
Loglevel that is printed by default, reporting some status information.
#define HASSERT(x)
Checks that the value of expression x is true, else terminates the current process.