36template <
typename FieldType>
37[[nodiscard]]
inline auto read_field(
const std::byte* base, std::size_t offset)
noexcept
40 std::memcpy(&value, base + offset,
sizeof(FieldType));
41 if constexpr (std::is_integral_v<FieldType> &&
sizeof(FieldType) > 1) {
42 return utils::from_big_endian(value);
53[[nodiscard]]
inline auto read_timestamp(
const std::byte* base, std::size_t offset)
noexcept
55 const auto high = read_field<std::uint16_t>(base, offset);
56 const auto low = read_field<std::uint32_t>(base, offset + 2);
57 constexpr int LOWER_SHIFT = 32;
58 return (
static_cast<std::uint64_t
>(high) << LOWER_SHIFT) | low;
66[[nodiscard]]
inline auto read_stock(
const std::byte* base, std::size_t offset)
noexcept
68 const void* raw = base + offset;
69 return std::string_view {
static_cast<const char*
>(raw), 8};
102 [[nodiscard]]
auto type() const noexcept ->
char {
103 return static_cast<char>(
static_cast<unsigned char>(
m_data[0]));
120 [[nodiscard]]
auto timestamp() const noexcept -> std::uint64_t {
126 [[nodiscard]]
auto size() const noexcept -> std::
size_t {
return m_size; }
130 [[nodiscard]]
auto data() const noexcept -> const std::
byte* {
return m_data; }
138 template <
typename FieldType>
139 [[nodiscard]]
auto read(std::size_t offset)
const noexcept -> FieldType {
140 return detail::read_field<FieldType>(
m_data, offset);
156 return read<std::uint64_t>(11);
165 [[nodiscard]]
auto shares() const noexcept -> std::uint32_t {
return read<std::uint32_t>(20); }
169 [[nodiscard]]
auto stock() const noexcept -> std::string_view {
175 [[nodiscard]]
auto price() const noexcept -> std::uint32_t {
return read<std::uint32_t>(32); }
186 return read<std::uint64_t>(11);
192 return read<std::uint32_t>(19);
198 return read<std::uint64_t>(23);
210 return read<std::uint64_t>(11);
216 return read<std::uint32_t>(19);
222 return read<std::uint64_t>(23);
227 [[nodiscard]]
auto printable() const noexcept ->
char {
return read<char>(31); }
232 return read<std::uint32_t>(32);
244 return read<std::uint64_t>(11);
250 return read<std::uint32_t>(19);
262 return read<std::uint64_t>(11);
274 return read<std::uint64_t>(11);
280 return read<std::uint64_t>(19);
285 [[nodiscard]]
auto shares() const noexcept -> std::uint32_t {
return read<std::uint32_t>(27); }
289 [[nodiscard]]
auto price() const noexcept -> std::uint32_t {
return read<std::uint32_t>(31); }
300 return read<std::uint64_t>(11);
309 [[nodiscard]]
auto shares() const noexcept -> std::uint32_t {
return read<std::uint32_t>(20); }
313 [[nodiscard]]
auto stock() const noexcept -> std::string_view {
319 [[nodiscard]]
auto price() const noexcept -> std::uint32_t {
return read<std::uint32_t>(32); }
324 return read<std::uint64_t>(36);
337 std::array<std::uint16_t, 256> table {};
338 auto add = [&table]<
typename MsgType>(
char type) {
339 table[
static_cast<unsigned char>(type)] =
340 static_cast<std::uint16_t
>(itch::detail::WIRE_SIZE<MsgType>);
361 std::uint64_t delivered = 0;
362 std::size_t offset = 0;
363 while (offset +
sizeof(std::uint16_t) <= data.size()) {
364 std::uint16_t length {};
365 std::memcpy(&length, data.data() + offset,
sizeof(length));
366 length = utils::from_big_endian(length);
367 offset +=
sizeof(std::uint16_t);
371 if (offset + length > data.size()) {
374 const std::byte* frame = data.data() + offset;
375 const auto message_type =
static_cast<unsigned char>(frame[0]);
379 if (expected == 0 || length < expected) {
Lazy view of an Add Order (A) message.
auto buy_sell_indicator() const noexcept -> char
'B' buy, 'S' sell.
auto shares() const noexcept -> std::uint32_t
Displayed share quantity.
auto stock() const noexcept -> std::string_view
Stock symbol, right padded with spaces.
auto price() const noexcept -> std::uint32_t
Display price (4 implied decimals).
auto order_reference_number() const noexcept -> std::uint64_t
Day-unique reference number for the order.
A zero-copy typed view over one raw ITCH frame.
auto timestamp() const noexcept -> std::uint64_t
The message timestamp (nanoseconds past midnight).
auto type() const noexcept -> char
The one-byte message type.
auto size() const noexcept -> std::size_t
The raw frame size in bytes.
auto read(std::size_t offset) const noexcept -> FieldType
Reads an arbitrary integral field at a byte offset, big-endian.
constexpr MessageView() noexcept=default
Constructs an empty view with no underlying frame.
auto stock_locate() const noexcept -> std::uint16_t
The locate code identifying the security.
auto data() const noexcept -> const std::byte *
Pointer to the raw frame (the type byte).
auto tracking_number() const noexcept -> std::uint16_t
The Nasdaq internal tracking number.
Lazy view of a Trade (P, non-cross) message.
auto order_reference_number() const noexcept -> std::uint64_t
Reference number of the non-displayed order.
auto match_number() const noexcept -> std::uint64_t
Day-unique match number for the trade.
auto price() const noexcept -> std::uint32_t
Trade price (4 implied decimals).
auto shares() const noexcept -> std::uint32_t
Number of shares traded.
auto buy_sell_indicator() const noexcept -> char
'B' buy, 'S' sell.
auto stock() const noexcept -> std::string_view
Stock symbol, right padded with spaces.
Lazy view of an Order Cancel (X) message.
auto order_reference_number() const noexcept -> std::uint64_t
Reference number of the cancelled order.
auto cancelled_shares() const noexcept -> std::uint32_t
Number of shares cancelled.
Lazy view of an Order Delete (D) message.
auto order_reference_number() const noexcept -> std::uint64_t
Reference number of the deleted order.
Lazy view of an Order Executed (E) message.
auto executed_shares() const noexcept -> std::uint32_t
Number of shares executed.
auto order_reference_number() const noexcept -> std::uint64_t
Reference number of the executed order.
auto match_number() const noexcept -> std::uint64_t
Day-unique match number for the execution.
Lazy view of an Order Executed With Price (C) message.
auto printable() const noexcept -> char
'Y' if the trade is printable to the tape, else 'N'.
auto match_number() const noexcept -> std::uint64_t
Day-unique match number for the execution.
auto execution_price() const noexcept -> std::uint32_t
Price at which the order executed (4 decimals).
auto order_reference_number() const noexcept -> std::uint64_t
Reference number of the executed order.
auto executed_shares() const noexcept -> std::uint32_t
Number of shares executed.
Lazy view of an Order Replace (U) message.
auto new_order_reference_number() const noexcept -> std::uint64_t
New reference number for the order.
auto original_order_reference_number() const noexcept -> std::uint64_t
Reference number being replaced.
auto price() const noexcept -> std::uint32_t
New display price (4 implied decimals).
auto shares() const noexcept -> std::uint32_t
New displayed share quantity.
constexpr auto for_each_message_type(Visitor &&visitor) -> void
Invokes visitor.template operator()<MsgType>(type_byte) once for each ITCH 5.0 message type,...
constexpr std::size_t STOCK_LOCATE_OFFSET
auto read_timestamp(const std::byte *base, std::size_t offset) noexcept -> std::uint64_t
Reads the 48-bit ITCH timestamp at offset into a 64-bit value.
constexpr std::size_t TIMESTAMP_OFFSET
auto read_field(const std::byte *base, std::size_t offset) noexcept -> FieldType
Reads an integral field of width sizeof(T) at offset, converting from network (big-endian) order on a...
auto read_stock(const std::byte *base, std::size_t offset) noexcept -> std::string_view
Views an 8-byte fixed-width stock field as a string_view (untrimmed).
constexpr std::size_t TRACKING_NUMBER_OFFSET
consteval auto build_size_table() -> std::array< std::uint16_t, 256 >
Builds the per-type expected wire-size table at compile time, mirroring the eager parser's so the ove...
auto for_each_message(std::span< const std::byte > data, const ViewCallback &callback) -> std::uint64_t
Frames a buffer and invokes callback with a zero-copy MessageView for each well-formed message.
std::function< void(const MessageView &)> ViewCallback
The signature for the overlay framing callback.
constexpr auto SIZE_TABLE
Public parsing interface for NASDAQ TotalView-ITCH 5.0 feeds, plus the low-level byte-unpacking utili...
Single source of truth for the ITCH 5.0 wire layout metadata shared by the eager parser,...