119 virtual bool read_bytes(
unsigned nbytes,
void* dst);
131 unsigned read_str(
unsigned dst_size,
char* dst);
141 {
return t.read_from(
this);}
211 : m_src((const u8*)src), m_len(len), m_rdidx(0) {}
213 : m_src((const u8*)src), m_len(len), m_rdidx(0) {}
219 : m_src(nullptr), m_len(0), m_rdidx(0) {}
231 void read_reset(
unsigned len);
236 const u8*
const m_src;
262 : m_src(src), m_rem(maxrd) {}
264 : m_src(src), m_rem(maxrd) {}
272 bool read_bytes(
unsigned nbytes,
void* dst)
override;
304 bool read_bytes(
unsigned nbytes,
void* dst)
override;
Ephemeral Readable interface for a simple array.
const u8 * buffer() const
Read-only access to the working buffer.
constexpr ArrayRead()
Create an empty ArrayRead object, empty constructor supports usage with util::optional.
constexpr ArrayRead(unsigned len, const void *src)
For ease of use, constructor accepts src/length or length/src.
constexpr ArrayRead(const void *src, unsigned len)
For ease of use, constructor accepts src/length or length/src.
Event-handler interface for newly received data.
virtual void data_unlink(satcat5::io::Readable *src)
Unlink this EventListener from the designated source, because the designated Readable object is being...
virtual void data_rcvd(satcat5::io::Readable *src)=0
The data_rcvd() callback is polled whenever data is available.
Limited read of next N bytes.
void read_reset(unsigned rem)
Children may reset the number of remaining bytes.
constexpr LimitedRead(satcat5::io::Readable *src, unsigned maxrd)
Explicitly set maximum read length in bytes.
constexpr LimitedRead(unsigned maxrd, satcat5::io::Readable *src)
Explicitly set maximum read length in bytes.
Readable object that never produces any data.
An EventListener object that immediately discards all received data.
Abstract API for reading byte-streams and packets.
constexpr Readable(satcat5::io::EventListener *callback=0)
Only children should create or destroy the base class.
virtual void read_underflow()
Optional error handling for read underflow.
bool read_obj(T &t)
Templated wrapper for any object with the following method: bool read_from(satcat5::io::Readable* rd)...
void poll_demand()
Event handler for on-demand polling.
unsigned read_str(unsigned dst_size, char *dst)
Safely read a null-terminated input string.
u8 read_u8()
One of many functions for reading integer/floating point values, see details.
virtual bool read_bytes(unsigned nbytes, void *dst)
Read 0 or more bytes into a buffer.
void read_notify()
Attempt notification by calling m_callback->data_rcvd().
virtual void read_finalize()
Consume any remaining bytes in this frame, if applicable.
virtual bool read_consume(unsigned nbytes)
Read and discard 0 or more bytes.
virtual u8 read_next()=0
Read the next byte from the underlying buffer or device.
bool copy_and_finalize(satcat5::io::Writeable *dst, satcat5::io::CopyMode mode=CopyMode::PACKET)
Copy data to a Writeable object, then finalize.
virtual void set_callback(satcat5::io::EventListener *callback)
Update registered callback for data_rcvd() events.
unsigned copy_to(satcat5::io::Writeable *dst)
Copy data to a Writeable object, without finalizing.
satcat5::io::EventListener * m_callback
Pointer to the callback object, or NULL.
virtual unsigned get_read_ready() const =0
How many bytes can be read without blocking?
Wrapper class for forwarding reads to another object.
constexpr ReadableRedirect(satcat5::io::Readable *src)
Constructor and destructor should only be called by the child.
void read_src(satcat5::io::Readable *src)
Children may reset the source object as needed.
Abstract API for writing byte-streams and packets.
An "OnDemand" object is polled only on request.
CopyMode
Specify read and write behavior for Readable::copy_and_finalize().
@ PACKET
PACKET mode (default) preserves packet boundaries.
@ STREAM
STREAM mode is used for non-packetized data.
@ ALWAYS
ALWAYS mode ensures write_finalize is always called.
satcat5::io::NullRead null_read
Global instances of the basic NullRead and NullSink objects.
satcat5::io::NullSink null_sink
Global instances of the basic NullRead and NullSink objects.
Core event-processing loop for SatCat5 software.
Basic type aliases and prototypes used throughout SatCat5.