use kevy_resp::Argv;
use std::collections::HashMap;
use std::sync::{Arc, RwLock};
pub(crate) type KvPairs = Vec<(Vec<u8>, Vec<u8>)>;
pub(crate) type PubSubReg = Arc<RwLock<HashMap<Vec<u8>, (u32, u64)>>>;
pub(crate) type PubMsg = Arc<(Vec<u8>, Vec<u8>)>;
#[derive(Clone, Copy)]
pub(crate) enum GatherKind {
Str,
Set,
}
pub(crate) enum Gathered {
Str(Option<Vec<u8>>),
Members(Vec<Vec<u8>>),
WrongType,
}
#[derive(Clone, Copy)]
pub(crate) enum MultiOp {
Mget,
SInter,
SUnion,
SDiff,
}
pub(crate) enum Op {
Dispatch(Argv),
Del(Vec<Vec<u8>>),
Exists(Vec<Vec<u8>>),
Dbsize,
Flush,
Save,
RewriteAof,
MSet(KvPairs),
Gather(GatherKind, Vec<Vec<u8>>),
CollectKeys(Option<Vec<u8>>, Option<usize>),
}
#[derive(Clone, Copy)]
pub(crate) enum KeyShape {
Keys,
Scan,
Random,
}
pub(crate) enum Part {
Reply(Vec<u8>),
Int(i64),
Ok,
Gathered(Vec<(Vec<u8>, Gathered)>),
Keys(Vec<Vec<u8>>),
}
pub(crate) type ReqBatch = Vec<(u64, u64, Argv)>;
pub(crate) type RespBatch = Vec<(u64, u64, Part)>;
pub(crate) enum Inbound {
Request {
origin: usize,
conn: u64,
seq: u64,
op: Op,
},
Response {
conn: u64,
seq: u64,
part: Part,
},
RequestBatch {
origin: usize,
reqs: ReqBatch,
},
ResponseBatch(RespBatch),
DeliverPublish(Vec<PubMsg>),
}
pub(crate) enum Agg {
First(Option<Vec<u8>>),
SumInt(i64),
AllOk,
Gather {
op: MultiOp,
keys: Vec<Vec<u8>>,
got: HashMap<Vec<u8>, Gathered>,
},
Keys {
shape: KeyShape,
acc: Vec<Vec<u8>>,
},
}
pub(crate) struct PendingSlot {
pub(crate) remaining: u32,
pub(crate) agg: Agg,
pub(crate) done: Option<Vec<u8>>,
}