protocol
ModuleContents
2 submodules, and what the module defines itself.
use utopia_nats::protocol::Command;Rust
pub enum CommandThe operations a client sends.
use utopia_nats::protocol::ServerOp;Rust
pub enum ServerOpThe kinds of operation a server sends.
protocol::parser
Own pageDecodes server operations from the byte stream.
use utopia_nats::protocol::parser::Parser;Rust
pub struct ParserReads 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 RawMessageA MSG or HMSG frame as read, before it becomes a crate::Message.
use utopia_nats::protocol::parser::Op;Rust
pub enum OpOne operation read from the server.
protocol::writer
Own pageEncodes client operations.
use utopia_nats::protocol::writer::Writer;Rust
pub struct WriterEncodes the operations a client sends, byte for byte as the server expects them.
Rust
use utopia_nats::protocol::Writer;
assert_eq!(Writer::publish("orders.new", b"hi", Some("_INBOX.1")), b"PUB orders.new _INBOX.1 2\r\nhi\r\n");
assert_eq!(Writer::sub("orders.>", "7", Some("workers")), b"SUB orders.> workers 7\r\n");