refix-codegen 0.6.0

Code generator for typed FIX protocol messages, for the ReFIX engine
Documentation
use refix_dictionary::Dictionary;

use super::layout::{MAX_WIDTH, slice};
use crate::dialect::length_tags;

/// The `DIALECT` constant, with every length tag the dictionary links.
pub(super) fn emit_dialect(dictionary: &Dictionary) -> String {
    let tags: Vec<String> = length_tags(dictionary)
        .iter()
        .map(|tag| format!("Tag({tag})"))
        .collect();
    let constant = if tags.is_empty() {
        "pub const DIALECT: Dialect<'static> = Dialect::new();\n".to_owned()
    } else {
        slice(
            "pub const DIALECT: Dialect<'static> = Dialect::new().with_extra_length_tags(",
            &tags,
            ");",
            MAX_WIDTH,
        )
    };
    format!("/// The dialect of this dictionary.\n{constant}")
}