Parsing API
From raw bytes to structure: the parser and its result shapes, the lexical tokenizers underneath it, frame splitting for multi-message buffers, and per-value datatype coercion. Generated from @boarteam/fix 0.5.2 as installed; the doc text is the library’s own. Guide: Parsing FIX messages.
parsefunctionsince 0.1.0
function parse(raw: string | Uint8Array, dict: Dictionary | FixtDictionaries, options?: ParseOptions): ParseResultSource: packages/fix/src/codec/parse.ts:120
Parse one FIX message into a structured ParsedMessage with nested repeating groups and coerced field values, returning diagnostics as data. Never throws — every problem (malformed field, unknown tag, group-count mismatch, bad checksum, …) is a returned FixIssue.
If the input holds several concatenated messages, only the first frame is parsed; use parseAll for the whole buffer.
The parse is dictionary-driven: groups are reconstructed using each group's first body field as the entry boundary (FIX has no group delimiters), and data fields whose value may embed the separator are read by their preceding Length field. Field order in the input is tolerated; the structure is what matters.
When the MsgType is unknown to the dictionary (or absent), the message is parsed flat — fields are kept at the top level with no group reconstruction, and a repeated tag is reported (parse/duplicate-tag) keeping the first. A parse/unknown-msgtype issue is also emitted.
dict may also be a FIXT transport/application pair (FixtDictionaries): the message is then parsed over the pair's merged view — envelope and session messages from the transport, bodies from the application dictionary, with begin-string-mismatch comparing against the transport's FIXT.1.1. With a resolveApp hook, each message's ApplVerID(1128) (falling back to the pair's defaultApplVerID) routes it to the right application dictionary.
| Parameter | Type | Description |
|---|---|---|
| raw | string | Uint8Array | One message as a string or UTF-8 bytes; extra frames are ignored (use parseAll). |
| dict | Dictionary | FixtDictionaries | The dictionary — or FIXT pair — that names fields and drives group reconstruction. |
| options? | ParseOptions | Separator and framing checks (ParseOptions). |
Returns ParseResult — The structured message plus every diagnostic, as data.
parseAllfunctionsince 0.1.0
function parseAll(raw: string | Uint8Array, dict: Dictionary | FixtDictionaries, options?: ParseOptions): ParseResult[]Source: packages/fix/src/codec/parse.ts:140
Parse every message in a buffer of concatenated frames. Returns one ParseResult per message, in order; an empty array for empty input. Never throws.
| Parameter | Type | Description |
|---|---|---|
| raw | string | Uint8Array | The whole buffer, one or many concatenated frames. |
| dict | Dictionary | FixtDictionaries | The dictionary — or FIXT pair — each frame is parsed against. |
| options? | ParseOptions | Separator and framing checks, applied to every frame. |
Returns ParseResult[] — One ParseResult per detected message, in wire order.
ParseOptionsinterfacesince 0.1.0
interface ParseOptionsSource: packages/fix/src/codec/parse.ts:74
soh?: stringField separator. Defaults to
SOH. Pass'|'to read pipe-delimited logs.checkFraming?: booleanVerify the transport frame: the 8/9/35 leading triple,
BodyLength, andCheckSum. Defaults totrue. Findings are returned as issues; the parse is never rejected. Setfalsefor fragments or pipe-delimited logs where framing is not meaningful.
ParseResultinterfacesince 0.1.0
interface ParseResultSource: packages/fix/src/codec/parse.ts:66
The result of parse: the structured message plus any diagnostics.
message: ParsedMessageThe structured message, built as far as the bytes allowed.
issues: FixIssue[]Every problem found on the way — framing, structure, value coercion. Never thrown.
ParsedMessageinterfacesince 0.1.0
interface ParsedMessageSource: packages/fix/src/codec/parse.ts:47
A parsed FIX message: a structured, nested view of one frame. Repeating groups are reconstructed as arrays of objects (not parallel arrays). The shape mirrors EncodeMessage so it re-encodes cheaply via toEncodeMessage.
msgType: stringThe
MsgType(tag 35) value, or""when absent.name?: stringThe message's dictionary name, when the
MsgTypeis known.beginString?: stringThe
BeginString(tag 8) value, when present.framed: booleantruewhen a well-formed frame was recognised: tags 8/9/35 lead in order and aCheckSum(10) terminates it. Does not imply the checksum matched — see the issues.fields: Record<number, ParsedField>Top-level scalar fields keyed by tag (includes framing fields 8/9/35/10).
groups: Record<number, ParsedGroupEntry[]>Top-level repeating groups keyed by counter tag.
ParsedFieldinterfacesince 0.1.0
interface ParsedFieldSource: packages/fix/src/codec/parse.ts:17
One parsed scalar field. raw is the verbatim wire value and the source of truth for re-encoding (so leading-zero codes, float formatting, and binary data round-trip exactly); value is the typed convenience form, never used for re-encode.
tag: numberThe field's numeric tag.
name?: stringThe field's dictionary name, when the tag is known.
raw: stringThe wire value between
=and the terminating separator, decoded as UTF-8. This is the source of truth for re-encoding and round-trips exactly for textual values (ASCII, UTF-8, Base64). Known limitation: adatafield carrying non-UTF-8 binary is decoded lossily (invalid bytes become U+FFFD) and is therefore not byte-preserved — a byte-clean path would require representing values as bytes end-to-end.value: DecodedValueThe coerced value (see
DecodedValue); equalsrawfor string types.
ParsedGroupEntryinterfacesince 0.1.0
interface ParsedGroupEntrySource: packages/fix/src/codec/parse.ts:35
One entry of a repeating group: its own fields and any nested groups, keyed by tag.
fields: Record<number, ParsedField>Scalar fields of this entry, keyed by tag.
groups: Record<number, ParsedGroupEntry[]>Nested repeating groups within this entry, keyed by counter tag.
toEncodeMessagefunctionsince 0.1.0
function toEncodeMessage(message: ParsedMessage): EncodeMessageSource: packages/fix/src/codec/parse.ts:191
Convert a ParsedMessage back into an EncodeMessage suitable for encode, using each field's verbatim ParsedField.raw value so the round-trip preserves the exact wire content. Framing fields (8/9/10) are carried but ignored by the encoder, which recomputes them.
| Parameter | Type | Description |
|---|---|---|
| message | ParsedMessage | The parsed message to convert. |
Returns EncodeMessage — A tag-keyed EncodeMessage carrying each field’s verbatim raw value.
decodeValuefunctionsince 0.1.0
function decodeValue(raw: string, field: FieldDef, dict: Dictionary, path?: string): DecodeResultSource: packages/fix/src/codec/datatypes.ts:63
Coerce one raw wire value to its typed form per the field's datatype.
Design rules:
- Multi-value lists split first. A
MultipleValueStringfield (e.g.ExecInst) splits into astring[]of its space-delimited tokens before enum opacity applies, because such fields are enumerated per token — the result is a list of opaque enum tokens ("1 2 5"→["1", "2", "5"]) the M3 validator can check element-by-element. - Enumerated single values are opaque. A non-list field with an
enumValuestable keeps its raw string ("1","004","USD") — never a number — so leading-zero codes survive and enum membership (checked by the M3 validator) compares like-for-like. - Dates/times stay strings.
UTCTimestamp/UTCDateOnly/LocalMktDate/month-yearare returned verbatim; the engine is pure and deterministic and does not introduce aDate(which would entangle time zones and lose the on-the-wire form). - Floats keep their wire form for re-encode via the raw string the parser retains alongside this value; the
numberhere is a convenience that may lose insignificant digits ("23.0"→23), so it is never the source of truth for round-tripping.
Never throws.
| Parameter | Type | Description |
|---|---|---|
| raw | string | The verbatim characters between = and the terminating separator. |
| field | FieldDef | The field definition that types the value. |
| dict | Dictionary | The dictionary, used to resolve the datatype's base and flags. |
| path? | string | Dotted location for any reported issue (e.g. "NoMDEntries[1].MDEntryPx"). |
Returns DecodeResult — The coerced value plus any diagnostics; the raw string is kept on coercion failure.
DecodeResultinterfacesince 0.1.0
interface DecodeResultSource: packages/fix/src/codec/datatypes.ts:20
The result of coercing one wire value: the decoded value plus any diagnostics.
value: DecodedValueThe coerced value; equals the raw string whenever coercion could not apply.
issues: FixIssue[]Diagnostics raised by the coercion; empty when the value read clean.
DecodedValuetypesince 0.1.0
type DecodedValue = number | boolean | string | string[]Source: packages/fix/src/codec/datatypes.ts:17
A FIX field value after datatype coercion:
numberforint/floatfamilies,booleanforBoolean,string[]forMultipleValueString,stringfor everything else (plain strings, enums, dates, currency/country codes, anddata— all kept verbatim).
When a value cannot be coerced to its declared type (e.g. "x" for an int field), the raw string is returned unchanged and an error FixIssue is reported, so a single malformed field never corrupts the rest of the parse and re-encoding still round-trips.
tokenizefunctionsince 0.1.0
function tokenize(raw: string | Uint8Array, options?: TokenizeOptions): Token[]Source: packages/fix/src/codec/tokenize.ts:44
Split a raw FIX message into ordered [tag, value] pairs.
This is a purely lexical pass: it preserves field order (so repeating groups can be reconstructed downstream), keeps duplicate tags as separate entries, and never throws. Two correctness fixes over the original implementation:
=in values. The tag/value boundary is the first=, found withString.indexOf, notsplit('=')— so a value that itself contains=(common indata/Textpayloads and Base64) survives intact.- Bytes in, text out. A
Uint8Arrayis decoded as UTF-8, so non-ASCII field values round-trip withoutBuffer.
Note: a trailing separator after the final field (the normal on-the-wire form) yields no empty token; input with no separators yields at most one token. Length-prefixed data fields whose value embeds a raw SOH are not special-cased here — that requires dictionary knowledge and is handled by the parser.
| Parameter | Type | Description |
|---|---|---|
| raw | string | Uint8Array | The message as a string or UTF-8 bytes. |
| options? | TokenizeOptions | Optional separator override. |
Returns Token[] — Ordered [tag, value] tokens; an empty array for empty input.
TokenizeOptionsinterfacesince 0.1.0
interface TokenizeOptionsSource: packages/fix/src/codec/tokenize.ts:17
Options for tokenize.
soh?: stringField separator. Defaults to
SOH. Pass'|'to read pipe-delimited logs.
Tokentypesince 0.1.0
type Token = [tag: number, value: string]Source: packages/fix/src/codec/tokenize.ts:14
A single decoded FIX field: its numeric tag and its raw, still-encoded value.
The value is the verbatim characters between = and the terminating SOH; no datatype coercion, trimming, or enum resolution is applied here (that is the dictionary-driven parser's job). The tag is NaN when the tag portion was not a valid integer — callers decide whether that is an error.
scanFieldsfunctionsince 0.1.0
function scanFields(raw: string | Uint8Array, dict: Dictionary, options?: FrameOptions): Token[]Source: packages/fix/src/codec/frame.ts:88
Tokenize a single message into ordered [tag, value] pairs with length-aware handling of data fields: when a Length field (one that some data field points to via FieldDef.lengthField) is read, the immediately following data field's value is taken as exactly that many UTF-8 bytes — even if it contains the SOH separator — so binary payloads survive intact. For every other field this matches tokenize.
Like tokenize, it is purely lexical and never throws: it preserves field order and duplicates, skips empty segments, and emits a NaN tag for a segment with no =.
| Parameter | Type | Description |
|---|---|---|
| raw | string | Uint8Array | The single message as a string or UTF-8 bytes. |
| dict | Dictionary | The dictionary, used to locate Length→data field pairs. |
| options? | FrameOptions | Optional separator override. |
Returns Token[] — Ordered [tag, value] tokens, with data payloads read length-exactly.
splitMessagesfunctionsince 0.1.0
function splitMessages(raw: string | Uint8Array, options?: FrameOptions): Uint8Array[]Source: packages/fix/src/codec/frame.ts:35
Split a buffer that may hold several concatenated FIX messages into one byte slice per message. This fixes the legacy behaviour where only the first message in a buffer survived.
Boundaries are computed from each message's BodyLength (tag 9), which is the only robust method: a data field value may itself embed the SOH separator or even a 8=/10= byte sequence, so scanning for those markers would mis-split. The math is byte-accurate (operates on UTF-8 bytes, not string code units). When a message's BodyLength is missing or unusable, it falls back to slicing up to the next SOH+8= boundary so malformed input still degrades gracefully instead of being lost.
Leading/trailing bytes outside any 8=…10= frame are ignored. Never throws.
| Parameter | Type | Description |
|---|---|---|
| raw | string | Uint8Array | The buffer to split, as a string or UTF-8 bytes. |
| options? | FrameOptions | Separator override (FrameOptions). |
Returns Uint8Array[] — one Uint8Array per detected message, in order; empty for empty input.
FrameOptionsinterfacesince 0.1.0
interface FrameOptionsSource: packages/fix/src/codec/frame.ts:12
Options for splitMessages and scanFields.
soh?: stringField separator. Defaults to
SOH. Must be a single byte (e.g.SOHor'|').