FIX.Dictionary behaviour (fix_message v0.1.2)

Copy Markdown View Source

Behaviour and builder for FIX data dictionaries.

A dictionary gives the parser the version-specific tag knowledge it needs:

  • companion_data_tag/1 — which tags are length fields, and which data field tag must immediately follow each one. FIX data-type fields (RawData, EncodedText, ...) hold arbitrary bytes — including the SOH delimiter — so the parser slices them by the byte count declared in the companion length field instead of scanning for SOH.

  • header_tag?/1 and trailer_tag?/1 — which tags belong to the standard message header and trailer. The parser uses these to split the token stream into {header, body, trailer} sections: fields accumulate into the header until the first non-header tag, then into the body until the first trailer tag.

FIX.Dictionary.FIX44 covers the standard fields and is the parser's default. Counterparties that define custom data fields need their own dictionary:

defmodule MyBroker.Dictionary do
  use FIX.Dictionary, extends: FIX.Dictionary.FIX44

  # Bilaterally-agreed custom data fields
  data_field 5001, 5002
end

FIX.Parser.parse_message(buffer, MyBroker.Dictionary)

Declarations compile to literal function clauses (a jump table), so lookups stay constant-time regardless of dictionary size. Locally declared tags take precedence over the :extends base; tags unknown to both return nil from companion_data_tag/1 and false from the predicates.

Summary

Functions

Declares a length_tag => data_tag companion pair.

Declares a standard-header tag.

Declares a standard-trailer tag.

Callbacks

companion_data_tag(tag)

@callback companion_data_tag(FIX.Parser.tag()) :: FIX.Parser.tag() | nil

header_tag?(tag)

@callback header_tag?(FIX.Parser.tag()) :: boolean()

trailer_tag?(tag)

@callback trailer_tag?(FIX.Parser.tag()) :: boolean()

Functions

data_field(length_tag, data_tag)

(macro)

Declares a length_tag => data_tag companion pair.

The data field's value is exactly the number of bytes declared by the length field, and may contain SOH.

header_field(tag)

(macro)

Declares a standard-header tag.

The parser accumulates fields into the header section while tags satisfy header_tag?/1; the first tag that doesn't starts the body.

trailer_field(tag)

(macro)

Declares a standard-trailer tag.

The first tag satisfying trailer_tag?/1 starts the trailer section, which runs to the end of the message.