Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions trafix-codec/src/constants/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Constants used during encoding and decoding.

/// ASCII SOH delimiter (0x01) used as field terminator in FIX messages.
pub(crate) const SOH: u8 = b'\x01';

Expand Down
24 changes: 21 additions & 3 deletions trafix-codec/src/decoder/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,27 @@ pub enum Error {
#[error(
"calculated and expected checksums don't match 'calculated({calculated}) != ({expected})'"
)]
ChecksumMismatch { calculated: u8, expected: u8 },
ChecksumMismatch {
/// Checksum calculated from the message.
calculated: u8,

/// Expected checksum that was extracted from the FIX message.
expected: u8,
},

/// Message contains invalid tag values.
#[error("invalid tag: {}", .0)]
BadTag(u16),

/// Message body length does not match what was received.
#[error("expected body length {expected} but received {received} bytes")]
BodyLength { received: usize, expected: usize },
BodyLength {
/// `BodyLength` received in the message.
received: usize,

/// Expected `BodyLength` as per the FIX protocols defined algorithm.
expected: usize,
},

/// Message contains invalid bytes.
#[error("encountered error while parsing tokens: {}", .0)]
Expand All @@ -71,7 +83,13 @@ pub enum Error {
pub enum LexError {
/// Found different byte than what was expected.
#[error("Expected '{expected}' but got {but_got}")]
Unexpected { expected: u8, but_got: u8 },
Unexpected {
/// Byte value that was expected at the current lexer position.
expected: u8,

/// Byte value that was encountered instead of the expected one.
but_got: u8,
},

/// EOI reached but not expected.
#[error("Unexpected end of input")]
Expand Down
3 changes: 3 additions & 0 deletions trafix-codec/src/decoder/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//! Implementation of the [`Message`] decoder.
//!
//! [`Message`]: crate::message::Message
mod decode;
pub mod num;

Expand Down
2 changes: 2 additions & 0 deletions trafix-codec/src/decoder/num.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Integer parsing utilities for FIX decoding.

/// The error type returned on failed parsing of integers from byte slices.
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
pub(crate) enum ParseIntError {
Expand Down
4 changes: 4 additions & 0 deletions trafix-codec/src/digest.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Implementation of a lightweight, stateful FIX checksum (Digest) calculator.

/// The [`Digest`] maintains a running checksum by performing modulo-256 addition over all
/// processed bytes, exactly as defined by the FIX checksum algorithm. This is typically used while
/// encoding and decoding FIX messages.
Expand All @@ -18,6 +20,8 @@
/// ```
#[derive(Default)]
pub(crate) struct Digest {
/// Accumulated checksum value computed as the modulo-256 sum of all bytes
/// processed, per the FIX protocol checksum definition.
checksum: u8,
}

Expand Down
4 changes: 3 additions & 1 deletion trafix-codec/src/encoder/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//! Implementation of the Message encoder.
//! Implementation of the [`Message`] encoder.
//!
//! [`Message`]: crate::message::Message

use bytes::{BufMut, Bytes, BytesMut};

Expand Down
3 changes: 2 additions & 1 deletion trafix-codec/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![warn(clippy::pedantic)]
#![warn(missing_docs)]
#![warn(clippy::missing_docs_in_private_items)]
#![forbid(unsafe_code)]

//! `trafix-codec` is a low-level library for high-performance parsing,
Expand All @@ -9,5 +10,5 @@ mod digest;

pub(crate) mod constants;
pub(crate) mod decoder;
pub mod encoder;
pub(crate) mod encoder;
pub mod message;