Rust

parser

Module

Decodes server operations from the byte stream.

Contents

use utopia_nats::protocol::parser::Parser;
Rust
pub struct Parser

Reads server operations off a Transport, buffering what it read past the current operation.

A frame body that fails half way (its header line consumed, its payload not) poisons the parser: every later call fails with Error::Connection until the connection builds a new one.

Rust
use utopia_nats::protocol::{Op, Parser};
let mut transport = Script(b"PING\r\nMSG orders.new 1 5\r\nhello\r\n".to_vec());
let mut parser = Parser::new();
assert_eq!(parser.next(&mut transport, None).await?, Op::Ping);
let Op::Msg(msg) = parser.next(&mut transport, None).await? else { unreachable!() };
assert_eq!((msg.subject.as_str(), msg.payload.as_slice()), ("orders.new", &b"hello"[..]));
use utopia_nats::protocol::parser::RawMessage;
Rust
pub struct RawMessage

A MSG or HMSG frame as read, before it becomes a crate::Message.

use utopia_nats::protocol::parser::Op;
Rust
pub enum Op

One operation read from the server.