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
impl Msg
Sourcepub fn new(id: MsgId, ty: MsgType, is_request: bool) -> Self
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());Sourcepub fn keys(&self) -> &[KeyPos]
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());Sourcepub fn parser_state(&self) -> u32
pub fn parser_state(&self) -> u32
Protocol-specific parser state index. Each parser defines
its own state alphabet keyed on this u32.
Sourcepub fn set_parser_state(&mut self, s: u32)
pub fn set_parser_state(&mut self, s: u32)
Set the protocol parser state index.
Sourcepub fn parser_pos(&self) -> usize
pub fn parser_pos(&self) -> usize
Cursor offset into the input buffer where the next byte should be read.
Sourcepub fn set_parser_pos(&mut self, p: usize)
pub fn set_parser_pos(&mut self, p: usize)
Set the parser cursor offset.
Sourcepub fn parser_token(&self) -> Option<usize>
pub fn parser_token(&self) -> Option<usize>
Optional token marker offset.
Sourcepub fn set_parser_token(&mut self, t: Option<usize>)
pub fn set_parser_token(&mut self, t: Option<usize>)
Set the optional token marker offset.
Sourcepub fn rlen(&self) -> u32
pub fn rlen(&self) -> u32
Remaining length of the bulk argument the parser is currently consuming.
Sourcepub fn set_rntokens(&mut self, n: u32)
pub fn set_rntokens(&mut self, n: u32)
Set the remaining-token counter.
Sourcepub fn set_ntokens(&mut self, n: u32)
pub fn set_ntokens(&mut self, n: u32)
Set the total parsed token count.
Sourcepub fn set_integer(&mut self, v: i64)
pub fn set_integer(&mut self, v: i64)
Set the integer response value.
Sourcepub fn end_marker(&self) -> Option<usize>
pub fn end_marker(&self) -> Option<usize>
Offset of the multi-bulk END marker in the response, if any.
Sourcepub fn set_end_marker(&mut self, m: Option<usize>)
pub fn set_end_marker(&mut self, m: Option<usize>)
Set the response END marker offset.
Sourcepub fn ntoken_start(&self) -> Option<usize>
pub fn ntoken_start(&self) -> Option<usize>
Start offset of the multi-bulk argument count token.
Sourcepub fn ntoken_end(&self) -> Option<usize>
pub fn ntoken_end(&self) -> Option<usize>
End offset (exclusive) of the multi-bulk argument count token.
Sourcepub fn set_ntoken_span(&mut self, start: Option<usize>, end: Option<usize>)
pub fn set_ntoken_span(&mut self, start: Option<usize>, end: Option<usize>)
Set the multi-bulk argument count span.
Sourcepub fn frag_id(&self) -> u64
pub fn frag_id(&self) -> u64
Fragment id grouping all sub-messages produced from a multi-key request.
Sourcepub fn set_frag_id(&mut self, id: u64)
pub fn set_frag_id(&mut self, id: u64)
Set the fragment id.
Sourcepub fn id(&self) -> MsgId
pub fn id(&self) -> MsgId
Message id.
§Examples
use dynomite::msg::{Msg, MsgType};
assert_eq!(Msg::new(99, MsgType::Unknown, true).id(), 99);Sourcepub fn parent_id(&self) -> MsgId
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);Sourcepub fn set_parent_id(&mut self, parent: MsgId)
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);Sourcepub fn ty(&self) -> MsgType
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);Sourcepub fn set_type(&mut self, ty: MsgType)
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);Sourcepub fn orig_type(&self) -> MsgType
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,
);Sourcepub fn is_request(&self) -> bool
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());Sourcepub fn mbufs(&self) -> &MbufQueue
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());Sourcepub fn mbufs_mut(&mut self) -> &mut MbufQueue
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);Sourcepub fn mlen(&self) -> u32
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);Sourcepub fn recompute_mlen(&mut self)
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);Sourcepub fn set_mlen(&mut self, mlen: u32)
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);Sourcepub fn parse_result(&self) -> MsgParseResult
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,
);Sourcepub fn set_parse_result(&mut self, r: MsgParseResult)
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);Sourcepub fn dyn_parse_state(&self) -> DynParseState
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,
);Sourcepub fn set_dyn_parse_state(&mut self, state: DynParseState)
pub fn set_dyn_parse_state(&mut self, state: DynParseState)
Set the DNODE parser state.
Sourcepub fn dmsg(&self) -> Option<&Dmsg>
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());Sourcepub fn routing(&self) -> MsgRouting
pub fn routing(&self) -> MsgRouting
Routing override.
Sourcepub fn set_routing(&mut self, routing: MsgRouting)
pub fn set_routing(&mut self, routing: MsgRouting)
Set the routing override.
Sourcepub fn consistency(&self) -> ConsistencyLevel
pub fn consistency(&self) -> ConsistencyLevel
Consistency level for this message.
Sourcepub fn set_consistency(&mut self, level: ConsistencyLevel)
pub fn set_consistency(&mut self, level: ConsistencyLevel)
Set the consistency level.
Sourcepub fn timestamp_us(&self) -> u64
pub fn timestamp_us(&self) -> u64
Microsecond timestamp recorded at request creation.
Sourcepub fn set_timestamp_us(&mut self, ts: u64)
pub fn set_timestamp_us(&mut self, ts: u64)
Update the request timestamp.
Sourcepub fn error_code(&self) -> i32
pub fn error_code(&self) -> i32
Datastore-level error code (errno-shaped).
Sourcepub fn set_error_code(&mut self, e: i32)
pub fn set_error_code(&mut self, e: i32)
Set the datastore error code.
Sourcepub fn dyn_error_code(&self) -> DynErrorCode
pub fn dyn_error_code(&self) -> DynErrorCode
Dynomite-level error code.
Sourcepub fn set_dyn_error_code(&mut self, e: DynErrorCode)
pub fn set_dyn_error_code(&mut self, e: DynErrorCode)
Set the Dynomite error code.
Sourcepub fn awaiting_rsps(&self) -> u32
pub fn awaiting_rsps(&self) -> u32
Number of replies the request is still waiting on.
Sourcepub fn incr_awaiting_rsps(&mut self)
pub fn incr_awaiting_rsps(&mut self)
Increment awaiting_rsps.
Sourcepub fn decr_awaiting_rsps(&mut self)
pub fn decr_awaiting_rsps(&mut self)
Decrement awaiting_rsps.
Sourcepub fn set_awaiting_rsps(&mut self, n: u32)
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.
Sourcepub fn fragment_ids(&self) -> &[MsgId] ⓘ
pub fn fragment_ids(&self) -> &[MsgId] ⓘ
Borrow the fragment-id list.
Sourcepub fn push_fragment_id(&mut self, id: MsgId)
pub fn push_fragment_id(&mut self, id: MsgId)
Append id to the fragment-id list.
Sourcepub fn response_ids(&self) -> &[MsgId] ⓘ
pub fn response_ids(&self) -> &[MsgId] ⓘ
Borrow the response-id list.
Sourcepub fn push_response_id(&mut self, id: MsgId)
pub fn push_response_id(&mut self, id: MsgId)
Append id to the response-id list.
Sourcepub fn selected_rsp(&self) -> Option<MsgId>
pub fn selected_rsp(&self) -> Option<MsgId>
Currently-selected response id.
Sourcepub fn set_selected_rsp(&mut self, id: Option<MsgId>)
pub fn set_selected_rsp(&mut self, id: Option<MsgId>)
Set the currently-selected response id.
Sourcepub fn set_swallow(&mut self, on: bool)
pub fn set_swallow(&mut self, on: bool)
Set the swallow flag.
Sourcepub fn set_is_error(&mut self, on: bool)
pub fn set_is_error(&mut self, on: bool)
Set the is_error flag.
Sourcepub fn rspmgr(&self) -> Option<&ResponseMgr>
pub fn rspmgr(&self) -> Option<&ResponseMgr>
Borrow the local-DC response manager.
Sourcepub fn rspmgr_mut(&mut self) -> Option<&mut ResponseMgr>
pub fn rspmgr_mut(&mut self) -> Option<&mut ResponseMgr>
Mutably borrow the local-DC response manager.
Sourcepub fn set_rspmgr(&mut self, mgr: ResponseMgr)
pub fn set_rspmgr(&mut self, mgr: ResponseMgr)
Install a fresh response manager for the local DC.
Sourcepub fn additional_rspmgrs(&self) -> &[ResponseMgr]
pub fn additional_rspmgrs(&self) -> &[ResponseMgr]
Borrow the per-remote-DC response managers.
Sourcepub fn additional_rspmgrs_mut(&mut self) -> &mut Vec<ResponseMgr>
pub fn additional_rspmgrs_mut(&mut self) -> &mut Vec<ResponseMgr>
Mutably borrow the per-remote-DC response managers.
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.