28#ifdef __cpp_lib_expected
115 auto parse(
const char* data,
size_t size) -> std::vector<Message>;
130 auto parse(
const char* data,
size_t size,
const std::vector<char>& messages)
131 -> std::vector<Message>;
158 auto parse(std::istream& data) -> std::vector<Message>;
170 auto parse(std::istream& data,
const std::vector<char>& messages) -> std::vector<Message>;
190 auto parse(std::span<const std::byte> data) -> std::vector<Message>;
198 auto parse(std::span<const std::byte> data,
const std::vector<char>& messages)
199 -> std::vector<Message>;
201#ifdef __cpp_lib_expected
217 [[nodiscard]]
auto try_parse(std::span<const std::byte> data,
const MessageCallback& callback)
218 -> std::expected<void, ParseError>;
224 [[nodiscard]]
auto try_parse(std::span<const std::byte> data
225 ) -> std::expected<std::vector<Message>,
ParseError>;
242 return m_unknown_message_count;
251 return m_malformed_message_count;
256 m_unknown_message_count = 0;
257 m_malformed_message_count = 0;
268 auto parse_impl(
const char* data, std::size_t size,
const MessageCallback& callback)
269 -> std::optional<ParseError>;
279 std::uint64_t m_unknown_message_count {0};
280 std::uint64_t m_malformed_message_count {0};
295template <std::
integral IntType>
296[[nodiscard]]
constexpr auto swap_bytes(IntType value)
noexcept -> IntType {
297#ifdef __cpp_lib_byteswap
298 return std::byteswap(value);
300 if constexpr (
sizeof(IntType) == 1) {
303 auto bytes = std::bit_cast<std::array<std::byte,
sizeof(IntType)>>(value);
304 std::ranges::reverse(bytes);
305 return std::bit_cast<IntType>(bytes);
318template <std::
integral IntType>
319[[nodiscard]]
constexpr auto from_big_endian(IntType value)
noexcept -> IntType {
320 if constexpr (std::endian::native == std::endian::little) {
321 return swap_bytes(value);
334template <
typename ValueType>
335auto unpack(
const char* buffer, std::size_t& offset) -> ValueType;
343inline auto unpack_string(
const char* buffer, std::size_t& offset,
char* dest, std::size_t size)
351inline auto unpack_timestamp(
const char* buffer, std::size_t& offset) -> std::uint64_t;
A high-performance parser for the NASDAQ TotalView-ITCH 5.0 protocol.
auto parse(const char *data, size_t size, const MessageCallback &callback) -> void
Parses messages from a memory buffer and invokes a callback for each.
auto unknown_message_count() const noexcept -> std::uint64_t
The number of frames skipped because their type byte was unknown.
auto reset_diagnostics() noexcept -> void
Resets the accumulating diagnostics counters to zero.
auto set_error_callback(ErrorCallback callback) -> void
Registers a callback invoked for each recoverable framing problem.
Parser()=default
Constructs a Parser instance.
auto malformed_message_count() const noexcept -> std::uint64_t
The number of frames skipped because their declared length was too small for the message type.
Defines every ITCH 5.0 message struct, the Message variant, and the stream-printing helpers used to f...
ParseError
Categories of recoverable problems encountered while framing a feed.
@ truncated
The buffer ended in the middle of a frame.
@ size_mismatch
The declared length is shorter than the message type requires.
@ unknown_type
The message type byte does not correspond to a known message.
std::function< void(ParseError, char)> ErrorCallback
The signature for the optional diagnostics callback.
std::variant< SystemEventMessage, StockDirectoryMessage, StockTradingActionMessage, RegSHOMessage, MarketParticipantPositionMessage, MWCBDeclineLevelMessage, MWCBStatusMessage, IPOQuotingPeriodUpdateMessage, LULDAuctionCollarMessage, OperationalHaltMessage, AddOrderMessage, AddOrderMPIDAttributionMessage, OrderExecutedMessage, OrderExecutedWithPriceMessage, OrderCancelMessage, OrderDeleteMessage, OrderReplaceMessage, NonCrossTradeMessage, CrossTradeMessage, BrokenTradeMessage, NOIIMessage, RetailPriceImprovementIndicatorMessage, DLCRMessage > Message
A variant able to hold any one of the ITCH 5.0 message structs.
std::function< void(const Message &)> MessageCallback
The signature for the callback function used in streaming parse methods.