Skip to main content

Encoder

Struct Encoder 

Source
pub struct Encoder { /* private fields */ }
Expand description

FIX message encoder.

The encoder builds FIX messages by appending fields in tag=value format. It handles BeginString, BodyLength, and Checksum fields automatically.

Implementations§

Source§

impl Encoder

Source

pub fn new(begin_string: &'static str) -> Encoder

Creates a new encoder with the specified BeginString.

§Arguments
  • begin_string - The FIX version string (e.g., “FIX.4.4”)
Source

pub fn with_capacity(begin_string: &'static str, capacity: usize) -> Encoder

Creates a new encoder with pre-allocated capacity.

§Arguments
  • begin_string - The FIX version string
  • capacity - Initial buffer capacity in bytes
Source

pub fn put_str(&mut self, tag: u32, value: &str)

Appends a field with a string value.

§Arguments
  • tag - The field tag number
  • value - The field value
Source

pub fn put_int(&mut self, tag: u32, value: i64)

Appends a field with an integer value.

§Arguments
  • tag - The field tag number
  • value - The field value
Source

pub fn put_uint(&mut self, tag: u32, value: u64)

Appends a field with an unsigned integer value.

§Arguments
  • tag - The field tag number
  • value - The field value
Source

pub fn put_bool(&mut self, tag: u32, value: bool)

Appends a field with a boolean value (Y/N).

§Arguments
  • tag - The field tag number
  • value - The field value
Source

pub fn put_char(&mut self, tag: u32, value: char)

Appends a field with a single character value.

§Arguments
  • tag - The field tag number
  • value - The field value
Source

pub fn put_raw(&mut self, tag: u32, value: &[u8])

Appends a field with raw bytes.

§Arguments
  • tag - The field tag number
  • value - The field value bytes
Source

pub fn finish(self) -> BytesMut

Finalizes the message and returns the complete encoded bytes.

This method:

  1. Prepends BeginString (tag 8) and BodyLength (tag 9)
  2. Appends Checksum (tag 10)
§Returns

The complete FIX message as bytes.

Source

pub fn body_len(&self) -> usize

Returns the current body length.

Source

pub fn clear(&mut self)

Clears the encoder for reuse.

Trait Implementations§

Source§

impl Debug for Encoder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for Encoder

Source§

fn default() -> Encoder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.