Skip to main content

memcache_parse_req

Function memcache_parse_req 

Source
pub fn memcache_parse_req(r: &mut Msg, input: &[u8]) -> MsgParseResult
Expand description

Parse a Memcached request from input and update r in place.

The function reproduces the reference engine’s memcache_parse_req state machine. On success, r.ty() is set to the recognised command, parsed keys are appended to Msg::keys, and the parser cursor (parser_pos) advances just past the trailing LF. On truncated input the function returns MsgParseResult::Again and stores the partial state on r for resumption. Invalid bytes return MsgParseResult::Error.

hash_tag, when set, configures the routing-tag delimiters used when populating KeyPos::tag.

§Examples

use dynomite::msg::{Msg, MsgParseResult, MsgType};
use dynomite::proto::memcache::memcache_parse_req;

let mut r = Msg::new(0, MsgType::Unknown, true);
let res = memcache_parse_req(&mut r, b"set foo 0 0 3\r\nbar\r\n");
assert_eq!(res, MsgParseResult::Ok);
assert_eq!(r.ty(), MsgType::ReqMcSet);
assert_eq!(r.keys()[0].key(), b"foo");
assert_eq!(r.vlen(), 3);

The state machine intentionally lives in a single function to match the reference engine’s parser shape.