pub struct FieldWriter { /* private fields */ }Expand description
Writes fields and gives them back as a RawMessage.
The fields are written in the order of the calls.
use refix_message::{Decimal, FieldWriter, Tag};
let mut body = FieldWriter::new();
body.write_str(Tag(11), "ORDER-1")?;
body.write_str(Tag(55), "ACME")?;
body.write_decimal(Tag(44), Decimal::new(10125, -2));
let body = body.finish();
assert_eq!(body.to_string(), "11=ORDER-1|55=ACME|44=101.25");
assert_eq!(body.get_str(Tag(55))?, Some("ACME"));Implementations§
Source§impl FieldWriter
impl FieldWriter
Sourcepub fn with_capacity(bytes: usize, fields: usize) -> Self
pub fn with_capacity(bytes: usize, fields: usize) -> Self
A writer with room for bytes bytes and fields fields.
Sourcepub fn write(&mut self, tag: Tag, value: &[u8]) -> Result<(), WriteError>
pub fn write(&mut self, tag: Tag, value: &[u8]) -> Result<(), WriteError>
Writes a field with value as its bytes.
An empty value and a value that holds the separator are errors. Nothing is written for them.
§Panics
If the fields written pass 4 GiB.
Sourcepub fn write_str(&mut self, tag: Tag, value: &str) -> Result<(), WriteError>
pub fn write_str(&mut self, tag: Tag, value: &str) -> Result<(), WriteError>
Writes a field with value as its text.
Fails and panics as write does.
Sourcepub fn write_int(&mut self, tag: Tag, value: i64)
pub fn write_int(&mut self, tag: Tag, value: i64)
Writes a field with value as an integer.
Panics as write does.
Sourcepub fn write_bool(&mut self, tag: Tag, value: bool)
pub fn write_bool(&mut self, tag: Tag, value: bool)
Writes a field with Y for true or N for false.
Panics as write does.
Sourcepub fn write_decimal(&mut self, tag: Tag, value: Decimal)
pub fn write_decimal(&mut self, tag: Tag, value: Decimal)
Writes a field with value as a decimal, keeping its scale.
A positive exponent is written as zeros, so Decimal::new(15, 3) is 15000.
Panics as write does.
Sourcepub fn write_date(&mut self, tag: Tag, value: Date)
pub fn write_date(&mut self, tag: Tag, value: Date)
Writes a field with value as a date, such as 20261103.
Panics as write does.
Sourcepub fn write_time(&mut self, tag: Tag, value: Time)
pub fn write_time(&mut self, tag: Tag, value: Time)
Writes a field with value as a time of day, such as 09:30:36.250.
The fraction has the digits of the value’s precision.
Digits past it are cut, not rounded.
Panics as write does.
Sourcepub fn write_utc_timestamp(&mut self, tag: Tag, value: UtcTimestamp)
pub fn write_utc_timestamp(&mut self, tag: Tag, value: UtcTimestamp)
Writes a field with value as a UTC timestamp, such as 20261103-09:30:36.250.
The fraction has the digits of the value’s precision.
Digits past it are cut, not rounded.
Panics as write does.
Sourcepub fn write_month_year(&mut self, tag: Tag, value: MonthYear)
pub fn write_month_year(&mut self, tag: Tag, value: MonthYear)
Writes a field with value as a month and year, such as 202612, 20261218 or 202612w3.
Panics as write does.
Sourcepub fn write_data(
&mut self,
length_tag: Tag,
tag: Tag,
value: &[u8],
) -> Result<(), WriteError>
pub fn write_data( &mut self, length_tag: Tag, tag: Tag, value: &[u8], ) -> Result<(), WriteError>
Writes a data field after the length field that counts its bytes.
The value may hold the separator. An empty value is an error, and nothing is written for it.
Panics as write does.
Sourcepub fn write_fields(&mut self, fields: &RawMessage)
pub fn write_fields(&mut self, fields: &RawMessage)
Sourcepub fn finish(self) -> RawMessage
pub fn finish(self) -> RawMessage
The fields written, as a message.