![]() |
libghostty
|
Synchronous callback interfaces used by APIs that consume or produce byte streams. The callback and userdata pointers must remain valid for the full lifetime documented by the API receiving a GhosttyReader or GhosttyWriter.
Typedefs | |
| typedef bool(*) | GhosttyReaderFn(void *userdata, uint8_t *buffer, size_t capacity, size_t *out_read) |
| typedef bool(*) | GhosttyWriterFn(void *userdata, const uint8_t *data, size_t len) |
| typedef bool(*) | GhosttyMimeReaderFn(void *userdata, GhosttyString mime, GhosttyWriter writer) |
Data Structures | |
| struct | GhosttyReader |
| struct | GhosttyWriter |
| struct | GhosttyMimeReader |
| typedef bool(*) GhosttyMimeReaderFn(void *userdata, GhosttyString mime, GhosttyWriter writer) |
Read one MIME-typed representation of some content, streaming its bytes to a writer.
The library calls this with the MIME type of the representation it needs. The callback writes all of that representation's data to writer, in as many calls to writer.write(writer.userdata, data,
len) as is convenient (one call with everything or many small pieces both work), and returns true. Nothing written is retained beyond each write call, so the data may be borrowed from anywhere: a pasteboard item, a file being read, a stream.
Returning false reports that the data could not be read. If the writer refuses a write (returns false), stop and return false without writing more.
All pointer arguments, the mime, and the writer are borrowed and valid only for the duration of the callback. The callback is invoked synchronously on the calling thread. The API receiving the GhosttyMimeReader defines which MIME types are requested, how many times, and any consistency requirements across repeated reads.
| userdata | Opaque userdata from GhosttyMimeReader |
| mime | The MIME type of the representation to read |
| writer | Where to write the data; valid only during this call |
| typedef bool(*) GhosttyReaderFn(void *userdata, uint8_t *buffer, size_t capacity, size_t *out_read) |
Read bytes from a source.
The callback must set out_read to a value no greater than capacity when returning true. A positive value reports progress; it may be less than capacity and does not indicate end-of-file. A zero value is definitive end-of-file. It must not be used to report temporary input starvation or a would-block condition.
Returning false reports a fatal read error and the value of out_read is ignored. The library does not inspect or modify errno.
All pointer arguments are borrowed and valid only for the duration of the callback. The callback is invoked synchronously on the calling thread.
| userdata | Opaque userdata from GhosttyReader | |
| buffer | Destination for read bytes; always non-NULL | |
| capacity | Writable capacity of buffer; always greater than zero | |
| [out] | out_read | Number of bytes read when returning true; non-NULL |
| typedef bool(*) GhosttyWriterFn(void *userdata, const uint8_t *data, size_t len) |
Write bytes to a destination.
Returning true means all len bytes were accepted. Returning false reports a fatal write error. A callback wrapping an interface that permits partial writes must retry internally until the full slice is accepted or an error occurs.
On failure, the destination may already contain a prefix of the bytes. The calling operation fails and must not be resumed from that partial output. The library does not inspect or modify errno.
data is borrowed and valid only for the duration of the callback. The callback is invoked synchronously on the calling thread. Successful return means the bytes were handed to the destination; it does not imply that the destination was flushed or made durable.
| userdata | Opaque userdata from GhosttyWriter |
| data | Source bytes; always non-NULL |
| len | Number of source bytes; always greater than zero |