Skip to main content

parse_req

Function parse_req 

Source
pub fn parse_req(msg: &mut Msg) -> MsgParseResult
Expand description

Sync byte parser that drives a request message’s DNODE header state machine.

The parser walks the contiguous bytes spanning the message’s mbuf chain and updates the Msg in place. On a fully parsed header, the function attaches the Dmsg to the message and returns MsgParseResult::Ok. On truncated input the parser returns MsgParseResult::Again. On invalid bytes the parser records MsgParseResult::Error and surfaces the same value.

The async wrapping (per-connection task scheduling, decryption hand-off when the encryption bit is set) ships in Stage 9.

§Examples

use dynomite::io::mbuf::MbufPool;
use dynomite::msg::{Msg, MsgType};
use dynomite::proto::dnode::{parse_req, DmsgType, DynParseState};

let pool = MbufPool::default();
let mut msg = Msg::new(0, MsgType::Unknown, true);
let mut mb = pool.get();
mb.recv(b"$2014$ 1 3 0 1 1 *1 d *0\r\n");
msg.mbufs_mut().push_back(mb);
msg.recompute_mlen();
let result = parse_req(&mut msg);
assert_eq!(msg.dyn_parse_state(), DynParseState::Done);
assert_eq!(msg.dmsg().unwrap().ty, DmsgType::Req);
drop(result);