pub struct LogWriter {
pub(crate) raw: NonNull<TlwWriter>,
}Expand description
Fields§
§raw: NonNull<TlwWriter>The C handle; never null, and owned: closed exactly once, in Drop.
Implementations§
Source§impl LogWriter
impl LogWriter
Sourcepub fn create(
path: &Path,
config: &Config,
replace: bool,
) -> Result<Self, WriterError>
pub fn create( path: &Path, config: &Config, replace: bool, ) -> Result<Self, WriterError>
Creates a log at path for a tag with config, replacing an
existing file when replace is true.
§Errors
When the library was built from a different interface version, the path is not UTF-8 or contains a NUL, or the database cannot be created (the writer’s message says why).
Sourcepub fn write_header(&mut self, header: &LogHeader) -> Result<(), WriterError>
pub fn write_header(&mut self, header: &LogHeader) -> Result<(), WriterError>
Writes header: its parts, then the info, calibration and state
tables and the tag’s data tables. Call once, first.
The parts are passed one at a time (tlw_header_add) and written
together (tlw_write_header), so the C side never needs a header
message of its own and proto/ gains nothing for this interface. The
parts accumulate in the handle: a second call would pass them again
and the writer would fail creating tables that exist.
§Errors
When a part is rejected or the writer fails, for example because the
header’s tag type differs from the one given to
create.
Sourcepub fn write_info(
&mut self,
field: &str,
value: &str,
) -> Result<(), WriterError>
pub fn write_info( &mut self, field: &str, value: &str, ) -> Result<(), WriterError>
Adds a row to the info table, after the header.
§Errors
When a string contains a NUL byte, or the writer fails.
Sourcepub fn begin_log(&mut self) -> Result<(), WriterError>
pub fn begin_log(&mut self) -> Result<(), WriterError>
Sourcepub fn write_log(&mut self, ack: &Ack) -> Result<usize, WriterError>
pub fn write_log(&mut self, ack: &Ack) -> Result<usize, WriterError>
Decodes and writes one data-log page, the Ack as the tag returned it.
Returns how many log records the page consumed, which advances the index of the next page to request, or 0 at the end of the log. Both depend on the tag type, which is why the writer decides them, and why a download must call this synchronously, page by page: the next request cannot be formed until it returns.
§Errors
When the writer rejects the page or the database write fails.
Sourcepub fn end_log(&mut self) -> Result<(), WriterError>
pub fn end_log(&mut self) -> Result<(), WriterError>
Sourcepub(crate) fn add_part(
&mut self,
kind: c_int,
message: &impl Message,
) -> Result<(), WriterError>
pub(crate) fn add_part( &mut self, kind: c_int, message: &impl Message, ) -> Result<(), WriterError>
Passes one header part to the writer.
§Errors
When the library cannot parse the encoding (a version mismatch).
Sourcepub(crate) fn check(&self, status: c_int) -> Result<(), WriterError>
pub(crate) fn check(&self, status: c_int) -> Result<(), WriterError>
Turns a C status (1 success, 0 failure) into a Result.
§Errors
When status is not 1, with the handle’s last error.
Sourcepub(crate) fn last_error(&self) -> WriterError
pub(crate) fn last_error(&self) -> WriterError
The handle’s last error, copied out of the library.