pub struct Serializer<'a> { /* private fields */ }Expand description
Writes FIX tag-value fields into a caller-provided byte buffer.
The buffer is the message size limit: nothing is ever allocated, and a
message that does not fit fails with
SerializeError::MaxMessageSizeExceeded rather than growing. Size the
buffer for the largest message the session may emit.
A field is three calls - tag prefix, typed value, delimiter:
let mut buf = [0u8; 64];
let mut serializer = Serializer::new(&mut buf);
serializer.put_slice(b"49=")?;
serializer.serialize_string(fix_str!("SENDER"))?;
serializer.put_soh()?;
assert_eq!(serializer.written(), b"49=SENDER\x01");A whole message additionally brackets the body with
serialize_body_len (which reserves the
BodyLength(9) placeholder) and serialize_checksum
(which patches that placeholder and appends CheckSum(10)).
Implementations§
Source§impl<'a> Serializer<'a>
impl<'a> Serializer<'a>
Sourcepub fn new(output: &'a mut [u8]) -> Serializer<'a>
pub fn new(output: &'a mut [u8]) -> Serializer<'a>
Wraps output, whose length becomes this message’s size limit.
Sourcepub fn put_soh(&mut self) -> Result<(), SerializeError>
pub fn put_soh(&mut self) -> Result<(), SerializeError>
Write the FIX field delimiter (SOH, 0x01).
Sourcepub fn serialize_body_len(&mut self) -> Result<(), SerializeError>
pub fn serialize_body_len(&mut self) -> Result<(), SerializeError>
Write the BodyLength(9) field as an all-zero placeholder and mark the body start.
The placeholder width comes from the buffer size, not from the message,
so the real length is patched in later by
serialize_checksum. Call this once,
directly after BeginString(8).
Sourcepub fn serialize_checksum(&mut self) -> Result<(), SerializeError>
pub fn serialize_checksum(&mut self) -> Result<(), SerializeError>
Close the message: patch the real body length into the placeholder, then append CheckSum(10) over every byte written before it.
Returns SerializeError::MaxMessageSizeExceeded when the body length
needs more digits than the placeholder reserved - including the case
where serialize_body_len was never
called, which leaves no placeholder to patch.
Sourcepub fn serialize_tag_num(
&mut self,
tag_num: &TagNum,
) -> Result<(), SerializeError>
pub fn serialize_tag_num( &mut self, tag_num: &TagNum, ) -> Result<(), SerializeError>
Serialize sequence of character digits without commas or decimals. Value must be positive and may not contain leading zeros.
Sourcepub fn serialize_int(&mut self, int: &Int) -> Result<(), SerializeError>
pub fn serialize_int(&mut self, int: &Int) -> Result<(), SerializeError>
Serialize sequence of character digits without commas or decimals
and optional sign character (characters - and 0 - 9).
The sign character utilizes one octet (i.e., positive int is 99999
while negative int is -99999).
Sourcepub fn serialize_seq_num(
&mut self,
seq_num: &SeqNum,
) -> Result<(), SerializeError>
pub fn serialize_seq_num( &mut self, seq_num: &SeqNum, ) -> Result<(), SerializeError>
Serialize sequence of character digits without commas or decimals.
Zero is a legal value here, unlike for the other digit types. Several
SeqNum-typed fields give it a meaning of their own: EndSeqNo(16) and
ApplEndSeqNum(1183) use it for “no upper bound”, and
LastMsgSeqNumProcessed(369) for “nothing processed yet”. Which zeros
are legal is a per-tag question the codec has no way to answer -
Deserializer::deserialize_seq_num already accepts every one of
them, and rejecting them on the way out would leave the codec able to
read messages it cannot write.
Sequence-number validity belongs to the session layer, which owns the counters and checks them against protocol state.
Sourcepub fn serialize_num_in_group(
&mut self,
num_in_group: &NumInGroup,
) -> Result<(), SerializeError>
pub fn serialize_num_in_group( &mut self, num_in_group: &NumInGroup, ) -> Result<(), SerializeError>
Serialize sequence of character digits without commas or decimals. Value must be positive.
Sourcepub fn serialize_day_of_month(
&mut self,
day_of_month: DayOfMonth,
) -> Result<(), SerializeError>
pub fn serialize_day_of_month( &mut self, day_of_month: DayOfMonth, ) -> Result<(), SerializeError>
Serialize sequence of character digits without commas or decimals (values 1 to 31).
Sourcepub fn serialize_float(&mut self, float: &Float) -> Result<(), SerializeError>
pub fn serialize_float(&mut self, float: &Float) -> Result<(), SerializeError>
Serialize sequence of character digits with optional decimal point
and sign character (characters -, 0 - 9 and .);
the absence of the decimal point within the string will be interpreted
as the float representation of an integer value. Note that float values
may contain leading zeros (e.g. 00023.23 = 23.23) and may contain
or omit trailing zeros after the decimal point
(e.g. 23.0 = 23.0000 = 23 = 23.).
All float fields must accommodate up to fifteen significant digits. The number of decimal places used should be a factor of business/market needs and mutual agreement between counterparties.
Sourcepub fn serialize_qty(&mut self, qty: &Qty) -> Result<(), SerializeError>
pub fn serialize_qty(&mut self, qty: &Qty) -> Result<(), SerializeError>
Serialize a Qty - the Float grammar under a different name.
Sourcepub fn serialize_price(&mut self, price: &Price) -> Result<(), SerializeError>
pub fn serialize_price(&mut self, price: &Price) -> Result<(), SerializeError>
Serialize a Price - the Float grammar under a different name.
Sourcepub fn serialize_price_offset(
&mut self,
price_offset: &PriceOffset,
) -> Result<(), SerializeError>
pub fn serialize_price_offset( &mut self, price_offset: &PriceOffset, ) -> Result<(), SerializeError>
Serialize a PriceOffset - the Float grammar under a different name.
Sourcepub fn serialize_amt(&mut self, amt: &Amt) -> Result<(), SerializeError>
pub fn serialize_amt(&mut self, amt: &Amt) -> Result<(), SerializeError>
Serialize an Amt - the Float grammar under a different name.
Sourcepub fn serialize_percentage(
&mut self,
percentage: &Percentage,
) -> Result<(), SerializeError>
pub fn serialize_percentage( &mut self, percentage: &Percentage, ) -> Result<(), SerializeError>
Serialize a Percentage - the Float grammar under a different name.
Sourcepub fn serialize_boolean(
&mut self,
boolean: &Boolean,
) -> Result<(), SerializeError>
pub fn serialize_boolean( &mut self, boolean: &Boolean, ) -> Result<(), SerializeError>
Serialize a single-character boolean: Y for true, N for false.
Sourcepub fn serialize_char(&mut self, c: &Char) -> Result<(), SerializeError>
pub fn serialize_char(&mut self, c: &Char) -> Result<(), SerializeError>
Use any ASCII character except control characters.
Sourcepub fn serialize_multiple_char_value(
&mut self,
mcv: &MultipleCharValue,
) -> Result<(), SerializeError>
pub fn serialize_multiple_char_value( &mut self, mcv: &MultipleCharValue, ) -> Result<(), SerializeError>
Serialize string containing one or more space-delimited single
character values, e.g. 2 A F.
Sourcepub fn serialize_string(&mut self, input: &FixStr) -> Result<(), SerializeError>
pub fn serialize_string(&mut self, input: &FixStr) -> Result<(), SerializeError>
Serialize alphanumeric free-format strings can include any character except control characters.
Sourcepub fn serialize_multiple_string_value(
&mut self,
input: &MultipleStringValue,
) -> Result<(), SerializeError>
pub fn serialize_multiple_string_value( &mut self, input: &MultipleStringValue, ) -> Result<(), SerializeError>
Serialize string containing one or more space-delimited multiple
character values, e.g. AV AN A.
Sourcepub fn serialize_country(
&mut self,
country: &Country,
) -> Result<(), SerializeError>
pub fn serialize_country( &mut self, country: &Country, ) -> Result<(), SerializeError>
Serialize ISO 3166-1:2013 Codes for the representation of names of countries and their subdivision (2-character code).
Returns SerializeError::EmptyValue when the country is unspecified.
Sourcepub fn serialize_currency(
&mut self,
currency: &Currency,
) -> Result<(), SerializeError>
pub fn serialize_currency( &mut self, currency: &Currency, ) -> Result<(), SerializeError>
Serialize ISO 4217:2015 Codes for the representation of currencies and funds (3-character code).
Returns SerializeError::EmptyValue when the currency is unspecified.
Sourcepub fn serialize_exchange(
&mut self,
exchange: &Exchange,
) -> Result<(), SerializeError>
pub fn serialize_exchange( &mut self, exchange: &Exchange, ) -> Result<(), SerializeError>
Serialize ISO 10383:2012 Securities and related financial instruments - Codes for exchanges and market identification (MIC) (4-character code).
Returns SerializeError::EmptyValue when the code is not set.
Sourcepub fn serialize_month_year(
&mut self,
input: &MonthYear,
) -> Result<(), SerializeError>
pub fn serialize_month_year( &mut self, input: &MonthYear, ) -> Result<(), SerializeError>
Sourcepub fn serialize_language(
&mut self,
input: &Language,
) -> Result<(), SerializeError>
pub fn serialize_language( &mut self, input: &Language, ) -> Result<(), SerializeError>
Serialize ISO 639-1:2002 Codes for the representation of names of languages (2-character code).
Returns SerializeError::EmptyValue when the language is unspecified.
Sourcepub fn serialize_utc_timestamp(
&mut self,
input: &UtcTimestamp,
) -> Result<(), SerializeError>
pub fn serialize_utc_timestamp( &mut self, input: &UtcTimestamp, ) -> Result<(), SerializeError>
Serialize string representing time/date combination represented in UTC (Universal Time Coordinated) in either YYYYMMDD-HH:MM:SS (whole seconds) or YYYYMMDD-HH:MM:SS.sss* format, colons, dash, and period required.
§Valid values:
- YYYY = 0000-9999,
- MM = 01-12,
- DD = 01-31,
- HH = 00-23,
- MM = 0059,
- SS = 00-60 (60 only if UTC leap second),
- sss* fractions of seconds. The fractions of seconds may be empty when no fractions of seconds are conveyed (in such a case the period is not conveyed), it may include 3 digits to convey milliseconds, 6 digits to convey microseconds, 9 digits to convey nanoseconds, 12 digits to convey picoseconds;
Sourcepub fn serialize_utc_time_only(
&mut self,
input: &UtcTimeOnly,
) -> Result<(), SerializeError>
pub fn serialize_utc_time_only( &mut self, input: &UtcTimeOnly, ) -> Result<(), SerializeError>
Serialize string representing time-only represented in UTC (Universal Time Coordinated) in either HH:MM:SS (whole seconds) or HH:MM:SS.sss* (milliseconds) format, colons, and period required.
This special-purpose field is paired with UTCDateOnly to form a proper UTCTimestamp for bandwidth-sensitive messages.
§Valid values:
- HH = 00-23,
- MM = 00-59,
- SS = 00-60 (60 only if UTC leap second),
- sss* fractions of seconds. The fractions of seconds may be empty when no fractions of seconds are conveyed (in such a case the period is not conveyed), it may include 3 digits to convey milliseconds, 6 digits to convey microseconds, 9 digits to convey nanoseconds, 12 digits to convey picoseconds;
Sourcepub fn serialize_utc_date_only(
&mut self,
input: &UtcDateOnly,
) -> Result<(), SerializeError>
pub fn serialize_utc_date_only( &mut self, input: &UtcDateOnly, ) -> Result<(), SerializeError>
Serialize date represented in UTC (Universal Time Coordinated) in YYYYMMDD format.
§Valid values:
- YYYY = 0000-9999,
- MM = 01-12,
- DD = 01-31.
Sourcepub fn serialize_local_mkt_time(
&mut self,
input: &LocalMktTime,
) -> Result<(), SerializeError>
pub fn serialize_local_mkt_time( &mut self, input: &LocalMktTime, ) -> Result<(), SerializeError>
Serialize time local to a market center. Used where offset to UTC varies throughout the year and the defining market center is identified in a corresponding field.
Format is HH:MM:SS where:
- HH = 00-23 hours,
- MM = 00-59 minutes,
- SS = 00-59 seconds.
In general only the hour token is non-zero.
Sourcepub fn serialize_local_mkt_date(
&mut self,
input: &LocalMktDate,
) -> Result<(), SerializeError>
pub fn serialize_local_mkt_date( &mut self, input: &LocalMktDate, ) -> Result<(), SerializeError>
Serialize date of local market (as opposed to UTC) in YYYYMMDD format.
§Valid values:
- YYYY = 0000-9999,
- MM = 01-12,
- DD = 01-31.
Sourcepub fn serialize_tz_timestamp(
&mut self,
input: &TzTimestamp,
) -> Result<(), SerializeError>
pub fn serialize_tz_timestamp( &mut self, input: &TzTimestamp, ) -> Result<(), SerializeError>
Serialize string representing a time/date combination representing local time with an offset to UTC to allow identification of local time and time zone offset of that time.
The representation is based on ISO 8601.
Format is YYYYMMDD-HH:MM:SS.sss*[Z | [ + | - hh[:mm]]] where:
- YYYY = 0000 to 9999,
- MM = 01-12,
- DD = 01-31 HH = 00-23 hours,
- MM = 00-59 minutes,
- SS = 00-59 seconds,
- hh = 01-12 offset hours,
- mm = 00-59 offset minutes,
- sss* fractions of seconds. The fractions of seconds may be empty when no fractions of seconds are conveyed (in such a case the period is not conveyed), it may include 3 digits to convey milliseconds, 6 digits to convey microseconds, 9 digits to convey nanoseconds, 12 digits to convey picoseconds;
Sourcepub fn serialize_tz_timeonly(
&mut self,
input: &TzTimeOnly,
) -> Result<(), SerializeError>
pub fn serialize_tz_timeonly( &mut self, input: &TzTimeOnly, ) -> Result<(), SerializeError>
Serialize time of day with timezone. Time represented based on ISO 8601. This is the time with a UTC offset to allow identification of local time and time zone of that time.
Format is HH:MM[:SS][Z | [ + | - hh[:mm]]] where:
- HH = 00-23 hours,
- MM = 00-59 minutes,
- SS = 00-59 seconds,
- hh = 01-12 offset hours,
- mm = 00-59 offset minutes.
Sourcepub fn serialize_length(
&mut self,
length: &Length,
) -> Result<(), SerializeError>
pub fn serialize_length( &mut self, length: &Length, ) -> Result<(), SerializeError>
Serialize sequence of character digits without commas or decimals.
Sourcepub fn serialize_data(&mut self, data: &Data) -> Result<(), SerializeError>
pub fn serialize_data(&mut self, data: &Data) -> Result<(), SerializeError>
Serialize raw data with no format or content restrictions, or a character string encoded as specified by MessageEncoding(347).
Sourcepub fn serialize_xml(
&mut self,
xml_data: &XmlData,
) -> Result<(), SerializeError>
pub fn serialize_xml( &mut self, xml_data: &XmlData, ) -> Result<(), SerializeError>
Serialize XML document.
Sourcepub fn serialize_tenor(&mut self, input: &Tenor) -> Result<(), SerializeError>
pub fn serialize_tenor(&mut self, input: &Tenor) -> Result<(), SerializeError>
Serialize a tenor: the unit code (D, M, W or Y) followed by its
value, e.g. M3 for three months.
Sourcepub fn serialize_enum<T>(&mut self, value: &T) -> Result<(), SerializeError>
pub fn serialize_enum<T>(&mut self, value: &T) -> Result<(), SerializeError>
Serialize an enum as its FIX wire value.
The value is a &'static [u8] held in read-only memory, so this is a
single copy with nothing allocated.
Sourcepub fn serialize_enum_collection<T>(
&mut self,
values: &[T],
) -> Result<(), SerializeError>
pub fn serialize_enum_collection<T>( &mut self, values: &[T], ) -> Result<(), SerializeError>
Serialize enums as a space-delimited list of their FIX wire values.
An empty slice is SerializeError::EmptyValue - a FIX field must
carry at least one byte.