Skip to main content

Msg

Struct Msg 

Source
pub struct Msg { /* private fields */ }
Expand description

One Dynomite message: the in-memory representation of a request or a response on its way through the engine.

Implementations§

Source§

impl Msg

Source

pub fn new(id: MsgId, ty: MsgType, is_request: bool) -> Self

Construct a new message with id, type tag ty, and the request/response orientation is_request. The mbuf chain starts empty and the parser is reset to DynParseState::Start.

§Examples
use dynomite::msg::{Msg, MsgType};
let m = Msg::new(1, MsgType::ReqRedisGet, true);
assert_eq!(m.id(), 1);
assert!(m.is_request());
Source

pub fn keys(&self) -> &[KeyPos]

Borrow the parsed key list. Populated by the protocol parsers.

§Examples
use dynomite::msg::{Msg, MsgType};
assert!(Msg::new(1, MsgType::Unknown, true).keys().is_empty());
Source

pub fn keys_mut(&mut self) -> &mut Vec<KeyPos>

Mutably borrow the parsed key list.

Source

pub fn push_key(&mut self, k: KeyPos)

Append a parsed key. Used by the protocol parsers.

Source

pub fn args(&self) -> &[ArgPos]

Borrow the parsed argument list.

Source

pub fn args_mut(&mut self) -> &mut Vec<ArgPos>

Mutably borrow the parsed argument list.

Source

pub fn push_arg(&mut self, a: ArgPos)

Append a parsed argument.

Source

pub fn parser_state(&self) -> u32

Protocol-specific parser state index. Each parser defines its own state alphabet keyed on this u32.

Source

pub fn set_parser_state(&mut self, s: u32)

Set the protocol parser state index.

Source

pub fn parser_pos(&self) -> usize

Cursor offset into the input buffer where the next byte should be read.

Source

pub fn set_parser_pos(&mut self, p: usize)

Set the parser cursor offset.

Source

pub fn parser_token(&self) -> Option<usize>

Optional token marker offset.

Source

pub fn set_parser_token(&mut self, t: Option<usize>)

Set the optional token marker offset.

Source

pub fn rlen(&self) -> u32

Remaining length of the bulk argument the parser is currently consuming.

Source

pub fn set_rlen(&mut self, n: u32)

Set the bulk-argument remaining length.

Source

pub fn rntokens(&self) -> u32

Remaining unprocessed token count for the current parse.

Source

pub fn set_rntokens(&mut self, n: u32)

Set the remaining-token counter.

Source

pub fn ntokens(&self) -> u32

Total parsed token count for the current message.

Source

pub fn set_ntokens(&mut self, n: u32)

Set the total parsed token count.

Source

pub fn nkeys(&self) -> u32

Number of keys the script (EVAL/EVALSHA) declared.

Source

pub fn set_nkeys(&mut self, n: u32)

Set the script-key count.

Source

pub fn vlen(&self) -> u32

Storage-command value length.

Source

pub fn set_vlen(&mut self, n: u32)

Set the storage-command value length.

Source

pub fn integer(&self) -> i64

Integer value carried by the response (:n\r\n).

Source

pub fn set_integer(&mut self, v: i64)

Set the integer response value.

Source

pub fn end_marker(&self) -> Option<usize>

Offset of the multi-bulk END marker in the response, if any.

Source

pub fn set_end_marker(&mut self, m: Option<usize>)

Set the response END marker offset.

Source

pub fn ntoken_start(&self) -> Option<usize>

Start offset of the multi-bulk argument count token.

Source

pub fn ntoken_end(&self) -> Option<usize>

End offset (exclusive) of the multi-bulk argument count token.

Source

pub fn set_ntoken_span(&mut self, start: Option<usize>, end: Option<usize>)

Set the multi-bulk argument count span.

Source

pub fn frag_id(&self) -> u64

Fragment id grouping all sub-messages produced from a multi-key request.

Source

pub fn set_frag_id(&mut self, id: u64)

Set the fragment id.

Source

pub fn id(&self) -> MsgId

Message id.

§Examples
use dynomite::msg::{Msg, MsgType};
assert_eq!(Msg::new(99, MsgType::Unknown, true).id(), 99);
Source

pub fn parent_id(&self) -> MsgId

Parent id (zero when not a fragment).

§Examples
use dynomite::msg::{Msg, MsgType};
assert_eq!(Msg::new(1, MsgType::Unknown, true).parent_id(), 0);
Source

pub fn set_parent_id(&mut self, parent: MsgId)

Set the parent id.

§Examples
use dynomite::msg::{Msg, MsgType};
let mut m = Msg::new(2, MsgType::Unknown, true);
m.set_parent_id(1);
assert_eq!(m.parent_id(), 1);
Source

pub fn ty(&self) -> MsgType

Message type tag.

§Examples
use dynomite::msg::{Msg, MsgType};
assert_eq!(Msg::new(1, MsgType::ReqMcGet, true).ty(), MsgType::ReqMcGet);
Source

pub fn set_type(&mut self, ty: MsgType)

Override the message type. The previous value is preserved as the original type so query rewriters can recover it.

§Examples
use dynomite::msg::{Msg, MsgType};
let mut m = Msg::new(1, MsgType::ReqRedisGet, true);
m.set_type(MsgType::ReqRedisSet);
assert_eq!(m.ty(), MsgType::ReqRedisSet);
assert_eq!(m.orig_type(), MsgType::ReqRedisGet);
Source

pub fn orig_type(&self) -> MsgType

Original message type before any rewrite.

§Examples
use dynomite::msg::{Msg, MsgType};
assert_eq!(
    Msg::new(1, MsgType::ReqRedisGet, true).orig_type(),
    MsgType::Unknown,
);
Source

pub fn is_request(&self) -> bool

True for requests.

§Examples
use dynomite::msg::{Msg, MsgType};
assert!(Msg::new(1, MsgType::ReqMcGet, true).is_request());
assert!(!Msg::new(1, MsgType::RspMcStored, false).is_request());
Source

pub fn mbufs(&self) -> &MbufQueue

Borrow the underlying mbuf chain.

§Examples
use dynomite::msg::{Msg, MsgType};
let m = Msg::new(1, MsgType::Unknown, true);
assert!(m.mbufs().is_empty());
Source

pub fn mbufs_mut(&mut self) -> &mut MbufQueue

Mutably borrow the mbuf chain.

§Examples
use dynomite::io::mbuf::MbufPool;
use dynomite::msg::{Msg, MsgType};

let pool = MbufPool::default();
let mut m = Msg::new(1, MsgType::Unknown, true);
m.mbufs_mut().push_back(pool.get());
assert_eq!(m.mbufs().len(), 1);
Source

pub fn mlen(&self) -> u32

Cumulative readable byte count of the chain (mlen).

§Examples
use dynomite::msg::{Msg, MsgType};
assert_eq!(Msg::new(1, MsgType::Unknown, true).mlen(), 0);
Source

pub fn recompute_mlen(&mut self)

Refresh mlen from the current chain.

The parser updates the length as it consumes bytes; callers that mutate the chain directly call this to keep the cached length consistent with the actual chain content.

§Examples
use dynomite::io::mbuf::MbufPool;
use dynomite::msg::{Msg, MsgType};

let pool = MbufPool::default();
let mut m = Msg::new(1, MsgType::Unknown, true);
let mut buf = pool.get();
buf.recv(b"hi");
m.mbufs_mut().push_back(buf);
m.recompute_mlen();
assert_eq!(m.mlen(), 2);
Source

pub fn set_mlen(&mut self, mlen: u32)

Direct setter for mlen. Use Msg::recompute_mlen when the chain has been mutated; this entry point exists for parsers that adjust the value as they consume bytes.

§Examples
use dynomite::msg::{Msg, MsgType};
let mut m = Msg::new(1, MsgType::Unknown, true);
m.set_mlen(123);
assert_eq!(m.mlen(), 123);
Source

pub fn parse_result(&self) -> MsgParseResult

Last parse outcome.

§Examples
use dynomite::msg::{Msg, MsgParseResult, MsgType};
assert_eq!(
    Msg::new(1, MsgType::Unknown, true).parse_result(),
    MsgParseResult::Ok,
);
Source

pub fn set_parse_result(&mut self, r: MsgParseResult)

Set the parse outcome.

§Examples
use dynomite::msg::{Msg, MsgParseResult, MsgType};
let mut m = Msg::new(1, MsgType::Unknown, true);
m.set_parse_result(MsgParseResult::Again);
assert_eq!(m.parse_result(), MsgParseResult::Again);
Source

pub fn dyn_parse_state(&self) -> DynParseState

Current DNODE parser state.

§Examples
use dynomite::msg::{Msg, MsgType};
use dynomite::proto::dnode::DynParseState;
assert_eq!(
    Msg::new(1, MsgType::Unknown, true).dyn_parse_state(),
    DynParseState::Start,
);
Source

pub fn set_dyn_parse_state(&mut self, state: DynParseState)

Set the DNODE parser state.

Source

pub fn dmsg(&self) -> Option<&Dmsg>

Borrow the parsed DNODE header, if any.

§Examples
use dynomite::msg::{Msg, MsgType};
assert!(Msg::new(1, MsgType::Unknown, true).dmsg().is_none());
Source

pub fn dmsg_mut(&mut self) -> Option<&mut Dmsg>

Mutably borrow the parsed DNODE header.

Source

pub fn set_dmsg(&mut self, dmsg: Dmsg)

Attach a parsed DNODE header.

Source

pub fn routing(&self) -> MsgRouting

Routing override.

Source

pub fn set_routing(&mut self, routing: MsgRouting)

Set the routing override.

Source

pub fn consistency(&self) -> ConsistencyLevel

Consistency level for this message.

Source

pub fn set_consistency(&mut self, level: ConsistencyLevel)

Set the consistency level.

Source

pub fn timestamp_us(&self) -> u64

Microsecond timestamp recorded at request creation.

Source

pub fn set_timestamp_us(&mut self, ts: u64)

Update the request timestamp.

Source

pub fn error_code(&self) -> i32

Datastore-level error code (errno-shaped).

Source

pub fn set_error_code(&mut self, e: i32)

Set the datastore error code.

Source

pub fn dyn_error_code(&self) -> DynErrorCode

Dynomite-level error code.

Source

pub fn set_dyn_error_code(&mut self, e: DynErrorCode)

Set the Dynomite error code.

Source

pub fn awaiting_rsps(&self) -> u32

Number of replies the request is still waiting on.

Source

pub fn incr_awaiting_rsps(&mut self)

Increment awaiting_rsps.

Source

pub fn decr_awaiting_rsps(&mut self)

Decrement awaiting_rsps.

Source

pub fn set_awaiting_rsps(&mut self, n: u32)

Set awaiting_rsps directly. Used by the response manager initialiser to seed the per-DC count.

Source

pub fn fragment_ids(&self) -> &[MsgId]

Borrow the fragment-id list.

Source

pub fn push_fragment_id(&mut self, id: MsgId)

Append id to the fragment-id list.

Source

pub fn response_ids(&self) -> &[MsgId]

Borrow the response-id list.

Source

pub fn push_response_id(&mut self, id: MsgId)

Append id to the response-id list.

Source

pub fn selected_rsp(&self) -> Option<MsgId>

Currently-selected response id.

Source

pub fn set_selected_rsp(&mut self, id: Option<MsgId>)

Set the currently-selected response id.

Source

pub fn owner(&self) -> Option<ConnId>

Owner connection id (placeholder until Stage 9).

Source

pub fn set_owner(&mut self, owner: Option<ConnId>)

Set the owner connection id.

Source

pub fn flags(&self) -> &MsgFlags

Borrow the lifecycle flags.

Source

pub fn flags_mut(&mut self) -> &mut MsgFlags

Mutably borrow the lifecycle flags.

Source

pub fn set_swallow(&mut self, on: bool)

Set the swallow flag.

Source

pub fn set_done(&mut self, on: bool)

Set the done flag.

Source

pub fn set_is_error(&mut self, on: bool)

Set the is_error flag.

Source

pub fn rspmgr(&self) -> Option<&ResponseMgr>

Borrow the local-DC response manager.

Source

pub fn rspmgr_mut(&mut self) -> Option<&mut ResponseMgr>

Mutably borrow the local-DC response manager.

Source

pub fn set_rspmgr(&mut self, mgr: ResponseMgr)

Install a fresh response manager for the local DC.

Source

pub fn additional_rspmgrs(&self) -> &[ResponseMgr]

Borrow the per-remote-DC response managers.

Source

pub fn additional_rspmgrs_mut(&mut self) -> &mut Vec<ResponseMgr>

Mutably borrow the per-remote-DC response managers.

Trait Implementations§

Source§

impl Debug for Msg

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Msg

§

impl RefUnwindSafe for Msg

§

impl Send for Msg

§

impl Sync for Msg

§

impl Unpin for Msg

§

impl UnsafeUnpin for Msg

§

impl UnwindSafe for Msg

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,