use std::sync::Arc;
use crate::msgpack::encoder::pack_cdt_op;
use crate::operations::cdt::{CdtArgument, CdtOperation};
use crate::operations::cdt_context::{CdtContext, DEFAULT_CTX};
use crate::operations::{Operation, OperationBin, OperationData, OperationType};
use crate::value::MapLike;
use crate::Value;
#[derive(Debug, Clone, Copy)]
pub(crate) enum CdtMapOpType {
SetType = 64,
Add = 65,
AddItems = 66,
Put = 67,
PutItems = 68,
Replace = 69,
ReplaceItems = 70,
Increment = 73,
Decrement = 74,
Clear = 75,
RemoveByKey = 76,
RemoveByIndex = 77,
RemoveByRank = 79,
RemoveKeyList = 81,
RemoveByValue = 82,
RemoveValueList = 83,
RemoveByKeyInterval = 84,
RemoveByIndexRange = 85,
RemoveByValueInterval = 86,
RemoveByRankRange = 87,
RemoveByKeyRelIndexRange = 88,
RemoveByValueRelRankRange = 89,
Size = 96,
GetByKey = 97,
GetByIndex = 98,
GetByRank = 100,
GetByValue = 102,
GetByKeyInterval = 103,
GetByIndexRange = 104,
GetByValueInterval = 105,
GetByRankRange = 106,
GetByKeyList = 107,
GetByValueList = 108,
GetByKeyRelIndexRange = 109,
GetByValueRelRankRange = 110,
}
#[derive(Debug, Clone, Copy)]
pub enum MapOrder {
Unordered = 0,
KeyOrdered = 1,
KeyValueOrdered = 3,
}
impl MapOrder {
pub(crate) const fn flag(self) -> u8 {
match self {
MapOrder::Unordered => 0x40,
MapOrder::KeyOrdered => 0x80,
MapOrder::KeyValueOrdered => 0xc0,
}
}
}
#[derive(Debug, Clone, Copy)]
pub enum MapReturnType {
None = 0,
Index = 1,
ReverseIndex = 2,
Rank = 3,
ReverseRank = 4,
Count = 5,
Key = 6,
Value = 7,
KeyValue = 8,
Exists = 13,
UnorderedMap = 16,
OrderedMap = 17,
Inverted = 0x10000,
}
#[derive(Debug, Clone, Copy)]
pub struct InvertedMapReturn(MapReturnType);
pub trait ToMapReturnTypeBitmask {
fn to_bitmask(self) -> i64;
}
impl ToMapReturnTypeBitmask for MapReturnType {
fn to_bitmask(self) -> i64 {
self as i64
}
}
impl ToMapReturnTypeBitmask for InvertedMapReturn {
fn to_bitmask(self) -> i64 {
MapReturnType::Inverted as i64 ^ self.0.to_bitmask()
}
}
#[allow(non_snake_case)]
pub mod MapWriteFlags {
pub const DEFAULT: u8 = 0;
pub const CREATE_ONLY: u8 = 1;
pub const UPDATE_ONLY: u8 = 2;
pub const NO_FAIL: u8 = 4;
pub const PARTIAL: u8 = 8;
}
#[derive(Debug, Clone, Copy)]
pub enum MapWriteMode {
Update,
UpdateOnly,
CreateOnly,
}
#[derive(Debug, Clone, Copy)]
pub struct MapPolicy {
pub order: MapOrder,
pub write_mode: MapWriteMode,
pub flags: u8,
pub persist_index: bool,
}
impl MapPolicy {
pub const fn new(order: MapOrder, write_mode: MapWriteMode) -> Self {
MapPolicy {
order,
write_mode,
flags: MapWriteFlags::DEFAULT,
persist_index: false,
}
}
pub const fn new_with_flags(order: MapOrder, flags: u8) -> Self {
MapPolicy {
order,
write_mode: MapWriteMode::Update,
flags,
persist_index: false,
}
}
pub const fn new_with_flags_and_persisted_index(order: MapOrder, flags: u8) -> Self {
MapPolicy {
order,
write_mode: MapWriteMode::Update,
flags,
persist_index: true,
}
}
pub(crate) const fn order_attr(self) -> u8 {
if self.persist_index {
self.order as u8 | 0x10
} else {
self.order as u8
}
}
}
impl Default for MapPolicy {
fn default() -> Self {
MapPolicy::new(MapOrder::Unordered, MapWriteMode::Update)
}
}
#[allow(clippy::trivially_copy_pass_by_ref)]
pub(crate) const fn map_write_op(policy: &MapPolicy, multi: bool) -> CdtMapOpType {
match policy.write_mode {
MapWriteMode::Update => {
if multi {
CdtMapOpType::PutItems
} else {
CdtMapOpType::Put
}
}
MapWriteMode::UpdateOnly => {
if multi {
CdtMapOpType::ReplaceItems
} else {
CdtMapOpType::Replace
}
}
MapWriteMode::CreateOnly => {
if multi {
CdtMapOpType::AddItems
} else {
CdtMapOpType::Add
}
}
}
}
#[allow(clippy::trivially_copy_pass_by_ref)]
const fn map_order_arg(policy: &MapPolicy) -> Option<CdtArgument> {
match policy.write_mode {
MapWriteMode::UpdateOnly => None,
_ => Some(CdtArgument::Byte(policy.order_attr())),
}
}
pub fn create(bin: &str, map_order: MapOrder, ctx: Vec<CdtContext>) -> Operation {
if ctx.is_empty() {
return set_order(bin, map_order);
}
let cdt_op = CdtOperation {
op: CdtMapOpType::SetType as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![
CdtArgument::Byte(map_order.flag()),
CdtArgument::Byte(map_order as u8),
],
};
Operation {
op: OperationType::CdtWrite,
ctx,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn create_with_index(bin: &str, map_order: MapOrder) -> Operation {
let cdt_op = CdtOperation {
op: CdtMapOpType::SetType as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![CdtArgument::Byte(map_order as u8 | 0x10)],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn set_policy(policy: &MapPolicy, bin: &str, ctx: Vec<CdtContext>) -> Operation {
let mut attr = policy.order_attr();
if !ctx.is_empty() {
attr &= !0x10;
}
let cdt_op = CdtOperation {
op: CdtMapOpType::SetType as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![CdtArgument::Byte(attr)],
};
Operation {
op: OperationType::CdtWrite,
ctx,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn set_order(bin: &str, map_order: MapOrder) -> Operation {
let cdt_op = CdtOperation {
op: CdtMapOpType::SetType as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![CdtArgument::Byte(map_order as u8)],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn put(policy: &MapPolicy, bin: &str, key: Value, val: Value) -> Operation {
if policy.flags != 0 {
let args = vec![
CdtArgument::Value(key),
CdtArgument::Value(val),
CdtArgument::Byte(policy.order_attr()),
CdtArgument::Byte(policy.flags),
];
let cdt_op = CdtOperation {
op: CdtMapOpType::Put as u8,
encoder: Arc::new(pack_cdt_op),
args,
};
return Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtMapOp(cdt_op),
};
}
let mut args = vec![CdtArgument::Value(key)];
if !val.is_nil() {
args.push(CdtArgument::Value(val));
}
if let Some(arg) = map_order_arg(policy) {
args.push(arg);
}
let cdt_op = CdtOperation {
op: map_write_op(policy, false) as u8,
encoder: Arc::new(pack_cdt_op),
args,
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtMapOp(cdt_op),
}
}
#[allow(clippy::implicit_hasher)]
pub fn put_items<M: MapLike<Value, Value>>(policy: &MapPolicy, bin: &str, items: M) -> Operation {
let items = match items.value() {
(Some(hm), None) => CdtArgument::Map(hm),
(None, Some(btm)) => CdtArgument::OrderedMap(btm),
_ => unreachable!(),
};
if policy.flags != 0 {
let args = vec![
items,
CdtArgument::Byte(policy.order_attr()),
CdtArgument::Byte(policy.flags),
];
let cdt_op = CdtOperation {
op: CdtMapOpType::PutItems as u8,
encoder: Arc::new(pack_cdt_op),
args,
};
return Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtMapOp(cdt_op),
};
}
let mut args = vec![items];
if let Some(arg) = map_order_arg(policy) {
args.push(arg);
}
let cdt_op = CdtOperation {
op: map_write_op(policy, true) as u8,
encoder: Arc::new(pack_cdt_op),
args,
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn increment_value(policy: &MapPolicy, bin: &str, key: Value, incr: Value) -> Operation {
let mut args = vec![CdtArgument::Value(key)];
if !incr.is_nil() {
args.push(CdtArgument::Value(incr));
}
if let Some(arg) = map_order_arg(policy) {
args.push(arg);
}
let cdt_op = CdtOperation {
op: CdtMapOpType::Increment as u8,
encoder: Arc::new(pack_cdt_op),
args,
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn decrement_value(policy: &MapPolicy, bin: &str, key: Value, decr: Value) -> Operation {
let mut args = vec![CdtArgument::Value(key)];
if !decr.is_nil() {
args.push(CdtArgument::Value(decr));
}
if let Some(arg) = map_order_arg(policy) {
args.push(arg);
}
let cdt_op = CdtOperation {
op: CdtMapOpType::Decrement as u8,
encoder: Arc::new(pack_cdt_op),
args,
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn clear(bin: &str) -> Operation {
let cdt_op = CdtOperation {
op: CdtMapOpType::Clear as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn remove_by_key<TMR: ToMapReturnTypeBitmask>(
bin: &str,
key: Value,
return_type: TMR,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtMapOpType::RemoveByKey as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![
CdtArgument::Int(return_type.to_bitmask()),
CdtArgument::Value(key),
],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn remove_by_key_list<TMR: ToMapReturnTypeBitmask>(
bin: &str,
keys: Vec<Value>,
return_type: TMR,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtMapOpType::RemoveKeyList as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![
CdtArgument::Int(return_type.to_bitmask()),
CdtArgument::List(keys),
],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn remove_by_key_range<TMR: ToMapReturnTypeBitmask>(
bin: &str,
begin: Value,
end: Value,
return_type: TMR,
) -> Operation {
let mut args = vec![
CdtArgument::Int(return_type.to_bitmask()),
CdtArgument::Value(begin),
];
if !end.is_nil() {
args.push(CdtArgument::Value(end));
}
let cdt_op = CdtOperation {
op: CdtMapOpType::RemoveByKeyInterval as u8,
encoder: Arc::new(pack_cdt_op),
args,
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn remove_by_value<TMR: ToMapReturnTypeBitmask>(
bin: &str,
value: Value,
return_type: TMR,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtMapOpType::RemoveByValue as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![
CdtArgument::Int(return_type.to_bitmask()),
CdtArgument::Value(value),
],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn remove_by_value_list<TMR: ToMapReturnTypeBitmask>(
bin: &str,
values: Vec<Value>,
return_type: TMR,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtMapOpType::RemoveValueList as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![
CdtArgument::Int(return_type.to_bitmask()),
CdtArgument::List(values),
],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn remove_by_value_range<TMR: ToMapReturnTypeBitmask>(
bin: &str,
begin: Value,
end: Value,
return_type: TMR,
) -> Operation {
let mut args = vec![
CdtArgument::Int(return_type.to_bitmask()),
CdtArgument::Value(begin),
];
if !end.is_nil() {
args.push(CdtArgument::Value(end));
}
let cdt_op = CdtOperation {
op: CdtMapOpType::RemoveByValueInterval as u8,
encoder: Arc::new(pack_cdt_op),
args,
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn remove_by_index<TMR: ToMapReturnTypeBitmask>(
bin: &str,
index: i64,
return_type: TMR,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtMapOpType::RemoveByIndex as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![
CdtArgument::Int(return_type.to_bitmask()),
CdtArgument::Int(index),
],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn remove_by_index_range<TMR: ToMapReturnTypeBitmask>(
bin: &str,
index: i64,
count: i64,
return_type: TMR,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtMapOpType::RemoveByIndexRange as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![
CdtArgument::Int(return_type.to_bitmask()),
CdtArgument::Int(index),
CdtArgument::Int(count),
],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn remove_by_index_range_from<TMR: ToMapReturnTypeBitmask>(
bin: &str,
index: i64,
return_type: TMR,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtMapOpType::RemoveByIndexRange as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![
CdtArgument::Int(return_type.to_bitmask()),
CdtArgument::Int(index),
],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn remove_by_rank<TMR: ToMapReturnTypeBitmask>(
bin: &str,
rank: i64,
return_type: TMR,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtMapOpType::RemoveByRank as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![
CdtArgument::Int(return_type.to_bitmask()),
CdtArgument::Int(rank),
],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn remove_by_rank_range<TMR: ToMapReturnTypeBitmask>(
bin: &str,
rank: i64,
count: i64,
return_type: TMR,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtMapOpType::RemoveByRankRange as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![
CdtArgument::Int(return_type.to_bitmask()),
CdtArgument::Int(rank),
CdtArgument::Int(count),
],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn remove_by_rank_range_from<TMR: ToMapReturnTypeBitmask>(
bin: &str,
rank: i64,
return_type: TMR,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtMapOpType::RemoveByRankRange as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![
CdtArgument::Int(return_type.to_bitmask()),
CdtArgument::Int(rank),
],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn size(bin: &str) -> Operation {
let cdt_op = CdtOperation {
op: CdtMapOpType::Size as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![],
};
Operation {
op: OperationType::CdtRead,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn get_by_key<TMR: ToMapReturnTypeBitmask>(
bin: &str,
key: Value,
return_type: TMR,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtMapOpType::GetByKey as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![
CdtArgument::Int(return_type.to_bitmask()),
CdtArgument::Value(key),
],
};
Operation {
op: OperationType::CdtRead,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn get_by_key_range<TMR: ToMapReturnTypeBitmask>(
bin: &str,
begin: Value,
end: Value,
return_type: TMR,
) -> Operation {
let mut args = vec![
CdtArgument::Int(return_type.to_bitmask()),
CdtArgument::Value(begin),
];
if !end.is_nil() {
args.push(CdtArgument::Value(end));
}
let cdt_op = CdtOperation {
op: CdtMapOpType::GetByKeyInterval as u8,
encoder: Arc::new(pack_cdt_op),
args,
};
Operation {
op: OperationType::CdtRead,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn get_by_value<TMR: ToMapReturnTypeBitmask>(
bin: &str,
value: Value,
return_type: TMR,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtMapOpType::GetByValue as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![
CdtArgument::Int(return_type.to_bitmask()),
CdtArgument::Value(value),
],
};
Operation {
op: OperationType::CdtRead,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn get_by_value_range<TMR: ToMapReturnTypeBitmask>(
bin: &str,
begin: Value,
end: Value,
return_type: TMR,
) -> Operation {
let mut args = vec![
CdtArgument::Int(return_type.to_bitmask()),
CdtArgument::Value(begin),
];
if !end.is_nil() {
args.push(CdtArgument::Value(end));
}
let cdt_op = CdtOperation {
op: CdtMapOpType::GetByValueInterval as u8,
encoder: Arc::new(pack_cdt_op),
args,
};
Operation {
op: OperationType::CdtRead,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn get_by_index<TMR: ToMapReturnTypeBitmask>(
bin: &str,
index: i64,
return_type: TMR,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtMapOpType::GetByIndex as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![
CdtArgument::Int(return_type.to_bitmask()),
CdtArgument::Int(index),
],
};
Operation {
op: OperationType::CdtRead,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn get_by_index_range<TMR: ToMapReturnTypeBitmask>(
bin: &str,
index: i64,
count: i64,
return_type: TMR,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtMapOpType::GetByIndexRange as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![
CdtArgument::Int(return_type.to_bitmask()),
CdtArgument::Int(index),
CdtArgument::Int(count),
],
};
Operation {
op: OperationType::CdtRead,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn get_by_index_range_from<TMR: ToMapReturnTypeBitmask>(
bin: &str,
index: i64,
return_type: TMR,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtMapOpType::GetByIndexRange as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![
CdtArgument::Int(return_type.to_bitmask()),
CdtArgument::Int(index),
],
};
Operation {
op: OperationType::CdtRead,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn get_by_rank<TMR: ToMapReturnTypeBitmask>(
bin: &str,
rank: i64,
return_type: TMR,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtMapOpType::GetByRank as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![
CdtArgument::Int(return_type.to_bitmask()),
CdtArgument::Int(rank),
],
};
Operation {
op: OperationType::CdtRead,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn get_by_rank_range<TMR: ToMapReturnTypeBitmask>(
bin: &str,
rank: i64,
count: i64,
return_type: TMR,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtMapOpType::GetByRankRange as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![
CdtArgument::Int(return_type.to_bitmask()),
CdtArgument::Int(rank),
CdtArgument::Int(count),
],
};
Operation {
op: OperationType::CdtRead,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn get_by_rank_range_from<TMR: ToMapReturnTypeBitmask>(
bin: &str,
rank: i64,
return_type: TMR,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtMapOpType::GetByRankRange as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![
CdtArgument::Int(return_type.to_bitmask()),
CdtArgument::Int(rank),
],
};
Operation {
op: OperationType::CdtRead,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn remove_by_key_relative_index_range<TMR: ToMapReturnTypeBitmask>(
bin: &str,
key: Value,
index: i64,
return_type: TMR,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtMapOpType::RemoveByKeyRelIndexRange as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![
CdtArgument::Int(return_type.to_bitmask()),
CdtArgument::Value(key),
CdtArgument::Int(index),
],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn remove_by_key_relative_index_range_count<TMR: ToMapReturnTypeBitmask>(
bin: &str,
key: Value,
index: i64,
count: i64,
return_type: TMR,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtMapOpType::RemoveByKeyRelIndexRange as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![
CdtArgument::Int(return_type.to_bitmask()),
CdtArgument::Value(key),
CdtArgument::Int(index),
CdtArgument::Int(count),
],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn remove_by_value_relative_rank_range<TMR: ToMapReturnTypeBitmask>(
bin: &str,
value: Value,
rank: i64,
return_type: TMR,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtMapOpType::RemoveByValueRelRankRange as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![
CdtArgument::Int(return_type.to_bitmask()),
CdtArgument::Value(value),
CdtArgument::Int(rank),
],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn remove_by_value_relative_rank_range_count<TMR: ToMapReturnTypeBitmask>(
bin: &str,
value: Value,
rank: i64,
count: i64,
return_type: TMR,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtMapOpType::RemoveByValueRelRankRange as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![
CdtArgument::Int(return_type.to_bitmask()),
CdtArgument::Value(value),
CdtArgument::Int(rank),
CdtArgument::Int(count),
],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn get_by_key_list<TMR: ToMapReturnTypeBitmask>(
bin: &str,
keys: Vec<Value>,
return_type: TMR,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtMapOpType::GetByKeyList as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![
CdtArgument::Int(return_type.to_bitmask()),
CdtArgument::List(keys),
],
};
Operation {
op: OperationType::CdtRead,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn get_by_value_list<TMR: ToMapReturnTypeBitmask>(
bin: &str,
values: Vec<Value>,
return_type: TMR,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtMapOpType::GetByValueList as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![
CdtArgument::Int(return_type.to_bitmask()),
CdtArgument::List(values),
],
};
Operation {
op: OperationType::CdtRead,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn get_by_key_relative_index_range<TMR: ToMapReturnTypeBitmask>(
bin: &str,
key: Value,
index: i64,
return_type: TMR,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtMapOpType::GetByKeyRelIndexRange as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![
CdtArgument::Int(return_type.to_bitmask()),
CdtArgument::Value(key),
CdtArgument::Int(index),
],
};
Operation {
op: OperationType::CdtRead,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn get_by_key_relative_index_range_count<TMR: ToMapReturnTypeBitmask>(
bin: &str,
key: Value,
index: i64,
count: i64,
return_type: TMR,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtMapOpType::GetByKeyRelIndexRange as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![
CdtArgument::Int(return_type.to_bitmask()),
CdtArgument::Value(key),
CdtArgument::Int(index),
CdtArgument::Int(count),
],
};
Operation {
op: OperationType::CdtRead,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn get_by_value_relative_rank_range<TMR: ToMapReturnTypeBitmask>(
bin: &str,
value: Value,
rank: i64,
return_type: TMR,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtMapOpType::GetByValueRelRankRange as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![
CdtArgument::Int(return_type.to_bitmask()),
CdtArgument::Value(value),
CdtArgument::Int(rank),
],
};
Operation {
op: OperationType::CdtRead,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn get_by_value_relative_rank_range_count<TMR: ToMapReturnTypeBitmask>(
bin: &str,
value: Value,
rank: i64,
count: i64,
return_type: TMR,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtMapOpType::GetByValueRelRankRange as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![
CdtArgument::Int(return_type.to_bitmask()),
CdtArgument::Value(value),
CdtArgument::Int(rank),
CdtArgument::Int(count),
],
};
Operation {
op: OperationType::CdtRead,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtMapOp(cdt_op),
}
}