fastlib 0.3.7

FAST (FIX Adapted for STreaming protocol) is a space and processing efficient encoding method for message oriented data streams.
Documentation
use crate::Value;
use crate::{Result, ValueType};

/// Defines the interface for message factories.
///
/// The callback functions are called when the specific event occurs during message processing.
///
pub trait MessageFactory {
    /// Called when a \<template> processing is started.
    /// * `id` is the template id;
    /// * `name` is the template name.
    fn start_template(&mut self, id: u32, name: &str);

    /// Called when a \<template> processing is finished.
    fn stop_template(&mut self);

    /// Called when a field element is processed.
    /// * `id` is the field instruction id;
    /// * `name` is the field name;
    /// * `value` is the field value which is optional.
    fn set_value(&mut self, id: u32, name: &str, value: Option<Value>);

    /// Called when a \<sequence> element processing is started.
    /// * `id` is the sequence instruction id; can be `0` if id is not specified;
    /// * `name` is the sequence name;
    /// * `length` is the sequence length.
    fn start_sequence(&mut self, id: u32, name: &str, length: u32);

    /// Called when a sequence item processing is started.
    /// * `index` is the sequence item index.
    fn start_sequence_item(&mut self, index: u32);

    /// Called when a sequence item processing is finished.
    fn stop_sequence_item(&mut self);

    /// Called when a \<sequence> processing is finished.
    fn stop_sequence(&mut self);

    /// Called when a \<group> element processing is started.
    /// * `name` is the group name.
    fn start_group(&mut self, name: &str);

    /// Called when a \<group> element processing is finished.
    fn stop_group(&mut self);

    /// Called when a template reference (\<templateRef>) processing is started.
    /// * `name` is the template name;
    /// * `dynamic` is `true` if the template reference is dynamic.
    fn start_template_ref(&mut self, name: &str, dynamic: bool);

    /// Called when a template reference (\<templateRef>) processing is finished.
    fn stop_template_ref(&mut self);
}

/// Defines the interface for message visitors.
///
/// The callback functions are called when the specific information required during message processing.
///
#[allow(clippy::missing_errors_doc)]
pub trait MessageVisitor {
    fn get_template_name(&mut self) -> Result<String>;

    fn get_value(&mut self, name: &str, type_: &ValueType) -> Result<Option<Value>>;

    fn select_group(&mut self, name: &str) -> Result<bool>;

    fn release_group(&mut self) -> Result<()>;

    fn select_sequence(&mut self, name: &str) -> Result<Option<usize>>;

    fn select_sequence_item(&mut self, index: usize) -> Result<()>;

    fn release_sequence_item(&mut self) -> Result<()>;

    fn release_sequence(&mut self) -> Result<()>;

    fn select_template_ref(&mut self, name: &str, dynamic: bool) -> Result<Option<String>>;

    fn release_template_ref(&mut self) -> Result<()>;
}