#[non_exhaustive]pub struct UnknownTemplateMessage {
pub template_id: i32,
pub payload: Bytes,
}Expand description
A frame whose template_id this crate has no message definition for.
The payload is kept as received, so a template this crate doesn’t map can
still be handled downstream: decode_as decodes it into a
type you generate yourself, and payload_hex dumps it
for later.
§Examples
A frame off a subscription stream arrives as
RithmicMessage::UnknownTemplate
with error: None. Log it, then decode it into a type generated in your own
crate from the .proto; crate::prost is re-exported so the generated
code can’t drift from the version this crate decodes with.
use rithmic_rs::prost;
use rithmic_rs::rti::messages::RithmicMessage;
// Generated in your crate by prost-build, once you know what 358 maps to.
#[derive(Clone, PartialEq, prost::Message)]
pub struct Template358 {
#[prost(string, optional, tag = "110100")]
pub symbol: Option<String>,
}
fn on_message(message: &RithmicMessage) {
let RithmicMessage::UnknownTemplate(frame) = message else {
return;
};
// template_id=358 (84 bytes) a2e135054d45535536aae13503434d45…+52B
tracing::warn!(payload = %frame.payload_hex(), "unmapped template: {frame}");
if frame.template_id == 358 {
if let Ok(decoded) = frame.decode_as::<Template358>() {
println!("{:?}", decoded.symbol);
}
}
}payload_hex is untruncated, so a frame captured in
production can be replayed in a test through
from_payload_hex.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.template_id: i32The template_id read from the frame header.
payload: BytesThe complete message body, exactly as received.
Only the 4-byte big-endian length prefix is stripped, as every other
decoder here does; it carries nothing beyond payload.len().
Implementations§
Source§impl UnknownTemplateMessage
impl UnknownTemplateMessage
Sourcepub fn new(template_id: i32, payload: Bytes) -> Self
pub fn new(template_id: i32, payload: Bytes) -> Self
Build a frame from its template_id and body.
Sourcepub fn decode_as<M: Message + Default>(&self) -> Result<M, DecodeError>
pub fn decode_as<M: Message + Default>(&self) -> Result<M, DecodeError>
Decode the payload into a caller-supplied protobuf type.
Generate the type from the .proto in your own crate and decode into it.
Uses the crate::prost re-export, so types generated against
rithmic_rs::prost are compatible by construction.
§Errors
prost::DecodeError when the bytes are structurally incompatible with
M, such as a wire-type conflict on a field M declares.
Ok is not proof the type was guessed right. Protobuf skips fields the
target doesn’t declare, so an unrelated payload usually decodes into a
mostly-empty value.
Sourcepub fn payload_hex(&self) -> String
pub fn payload_hex(&self) -> String
The whole payload as lowercase hex, no truncation, no 0x prefix.
Display elides the payload to stay readable in a log line; this
doesn’t.
Sourcepub fn from_payload_hex(template_id: i32, hex: &str) -> Option<Self>
pub fn from_payload_hex(template_id: i32, hex: &str) -> Option<Self>
Rebuild a frame from a payload_hex dump.
Ignores a leading 0x and any whitespace, including newlines from a
wrapped log line. None unless hex holds an even number of hex
digits; empty input yields an empty payload.
Trait Implementations§
Source§impl Clone for UnknownTemplateMessage
impl Clone for UnknownTemplateMessage
Source§fn clone(&self) -> UnknownTemplateMessage
fn clone(&self) -> UnknownTemplateMessage
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more