use std::sync::Arc;
use crate::msgpack::encoder::pack_cdt_op;
use crate::operations::cdt::{CdtArgument, CdtOperation};
use crate::operations::cdt_context::DEFAULT_CTX;
use crate::operations::{Operation, OperationBin, OperationData, OperationType};
use crate::Value;
#[derive(Debug, Clone, Copy)]
pub(crate) enum CdtListOpType {
SetType = 0,
Append = 1,
AppendItems = 2,
Insert = 3,
InsertItems = 4,
Pop = 5,
PopRange = 6,
Remove = 7,
RemoveRange = 8,
Set = 9,
Trim = 10,
Clear = 11,
Increment = 12,
Sort = 13,
Size = 16,
Get = 17,
GetRange = 18,
GetByIndex = 19,
GetByRank = 21,
GetByValue = 22,
GetByValueList = 23,
GetByIndexRange = 24,
GetByValueInterval = 25,
GetByRankRange = 26,
GetByValueRelRankRange = 27,
RemoveByIndex = 32,
RemoveByRank = 34,
RemoveByValue = 35,
RemoveByValueList = 36,
RemoveByIndexRange = 37,
RemoveByValueInterval = 38,
RemoveByRankRange = 39,
RemoveByValueRelRankRange = 40,
}
#[derive(Debug, Clone, Copy)]
pub enum ListOrderType {
Unordered = 0,
Ordered = 1,
}
#[derive(Debug, Clone, Copy)]
pub enum ListReturnType {
None = 0,
Index = 1,
ReverseIndex = 2,
Rank = 3,
ReverseRank = 4,
Count = 5,
Values = 7,
Exists = 13,
Inverted = 0x10000,
}
#[derive(Debug, Clone, Copy)]
pub struct InvertedListReturn(ListReturnType);
pub trait ToListReturnTypeBitmask {
fn to_bitmask(self) -> i64;
}
impl ToListReturnTypeBitmask for ListReturnType {
fn to_bitmask(self) -> i64 {
self as i64
}
}
impl ToListReturnTypeBitmask for InvertedListReturn {
fn to_bitmask(self) -> i64 {
ListReturnType::Inverted as i64 ^ self.0.to_bitmask()
}
}
#[derive(Debug, Clone, Copy)]
pub enum ListSortFlags {
Default = 0,
Descending = 1,
DropDuplicates = 2,
}
#[derive(Debug, Clone, Copy)]
pub enum ListWriteFlags {
Default = 0,
AddUnique = 1,
InsertBounded = 2,
NoFail = 4,
Partial = 8,
}
#[derive(Debug, Clone, Copy)]
pub struct ListPolicy {
pub attributes: ListOrderType,
pub flags: u8,
}
pub trait ToListWriteFlagsBitmask {
fn to_bitmask(self) -> u8;
}
impl ToListWriteFlagsBitmask for ListWriteFlags {
fn to_bitmask(self) -> u8 {
self as u8
}
}
impl<T: IntoIterator<Item = ListWriteFlags>> ToListWriteFlagsBitmask for T {
fn to_bitmask(self) -> u8 {
let mut out = 0;
for val in self {
out |= val.to_bitmask();
}
out
}
}
impl ListPolicy {
pub const fn new(order: ListOrderType, write_flags: ListWriteFlags) -> Self {
ListPolicy {
attributes: order,
flags: write_flags as u8,
}
}
pub fn new_with_flags<LWF: ToListWriteFlagsBitmask>(
order: ListOrderType,
write_flags: LWF,
) -> Self {
ListPolicy {
attributes: order,
flags: write_flags.to_bitmask(),
}
}
}
impl Default for ListPolicy {
fn default() -> Self {
ListPolicy::new(ListOrderType::Unordered, ListWriteFlags::Default)
}
}
pub(crate) const fn list_order_flag(order: ListOrderType, pad: bool) -> u8 {
if matches!(order, ListOrderType::Ordered) {
return 0xc0;
}
if pad {
return 0x80;
}
0x40
}
pub fn create(bin: &str, list_order: ListOrderType, pad: bool) -> Operation {
let cdt_op = CdtOperation {
op: CdtListOpType::SetType as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![
CdtArgument::Byte(list_order_flag(list_order, pad)),
CdtArgument::Byte(list_order as u8),
],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtListOp(cdt_op),
}
}
pub fn create_with_index(bin: &str, list_order: ListOrderType) -> Operation {
set_order_with_index(bin, list_order)
}
pub fn set_order(bin: &str, list_order: ListOrderType) -> Operation {
let cdt_op = CdtOperation {
op: CdtListOpType::SetType as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![CdtArgument::Byte(list_order as u8)],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtListOp(cdt_op),
}
}
pub fn set_order_with_index(bin: &str, list_order: ListOrderType) -> Operation {
let cdt_op = CdtOperation {
op: CdtListOpType::SetType as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![CdtArgument::Byte(list_order as u8 | 0x10)],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtListOp(cdt_op),
}
}
pub fn append(policy: &ListPolicy, bin: &str, value: Value) -> Operation {
let cdt_op = CdtOperation {
op: CdtListOpType::Append as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![
CdtArgument::Value(value),
CdtArgument::Byte(policy.attributes as u8),
CdtArgument::Byte(policy.flags),
],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtListOp(cdt_op),
}
}
pub fn append_items(policy: &ListPolicy, bin: &str, values: Vec<Value>) -> Operation {
assert!(!values.is_empty());
let cdt_op = CdtOperation {
op: CdtListOpType::AppendItems as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![
CdtArgument::List(values),
CdtArgument::Byte(policy.attributes as u8),
CdtArgument::Byte(policy.flags),
],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtListOp(cdt_op),
}
}
pub fn insert(policy: &ListPolicy, bin: &str, index: i64, value: Value) -> Operation {
let cdt_op = CdtOperation {
op: CdtListOpType::Insert as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![
CdtArgument::Int(index),
CdtArgument::Value(value),
CdtArgument::Byte(policy.flags),
],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtListOp(cdt_op),
}
}
pub fn insert_items(policy: &ListPolicy, bin: &str, index: i64, values: Vec<Value>) -> Operation {
assert!(!values.is_empty());
let cdt_op = CdtOperation {
op: CdtListOpType::InsertItems as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![
CdtArgument::Int(index),
CdtArgument::List(values),
CdtArgument::Byte(policy.flags),
],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtListOp(cdt_op),
}
}
pub fn pop(bin: &str, index: i64) -> Operation {
let cdt_op = CdtOperation {
op: CdtListOpType::Pop as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![CdtArgument::Int(index)],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtListOp(cdt_op),
}
}
pub fn pop_range(bin: &str, index: i64, count: i64) -> Operation {
let cdt_op = CdtOperation {
op: CdtListOpType::PopRange as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![CdtArgument::Int(index), CdtArgument::Int(count)],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtListOp(cdt_op),
}
}
pub fn pop_range_from(bin: &str, index: i64) -> Operation {
let cdt_op = CdtOperation {
op: CdtListOpType::PopRange as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![CdtArgument::Int(index)],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtListOp(cdt_op),
}
}
pub fn remove(bin: &str, index: i64) -> Operation {
let cdt_op = CdtOperation {
op: CdtListOpType::Remove as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![CdtArgument::Int(index)],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtListOp(cdt_op),
}
}
pub fn remove_range(bin: &str, index: i64, count: i64) -> Operation {
let cdt_op = CdtOperation {
op: CdtListOpType::RemoveRange as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![CdtArgument::Int(index), CdtArgument::Int(count)],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtListOp(cdt_op),
}
}
pub fn remove_range_from(bin: &str, index: i64) -> Operation {
let cdt_op = CdtOperation {
op: CdtListOpType::RemoveRange as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![CdtArgument::Int(index)],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtListOp(cdt_op),
}
}
pub fn remove_by_value<TLR: ToListReturnTypeBitmask>(
bin: &str,
value: Value,
return_type: TLR,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtListOpType::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::CdtListOp(cdt_op),
}
}
pub fn remove_by_value_list<TLR: ToListReturnTypeBitmask>(
bin: &str,
values: Vec<Value>,
return_type: TLR,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtListOpType::RemoveByValueList 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::CdtListOp(cdt_op),
}
}
pub fn remove_by_value_range<TLR: ToListReturnTypeBitmask>(
bin: &str,
return_type: TLR,
begin: Value,
end: Value,
) -> 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: CdtListOpType::RemoveByValueInterval as u8,
encoder: Arc::new(pack_cdt_op),
args,
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtListOp(cdt_op),
}
}
pub fn remove_by_value_relative_rank_range<TLR: ToListReturnTypeBitmask>(
bin: &str,
return_type: TLR,
value: Value,
rank: i64,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtListOpType::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::CdtListOp(cdt_op),
}
}
pub fn remove_by_value_relative_rank_range_count<TLR: ToListReturnTypeBitmask>(
bin: &str,
return_type: TLR,
value: Value,
rank: i64,
count: i64,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtListOpType::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::CdtListOp(cdt_op),
}
}
pub fn remove_by_index<TLR: ToListReturnTypeBitmask>(
bin: &str,
index: i64,
return_type: TLR,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtListOpType::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::CdtListOp(cdt_op),
}
}
pub fn remove_by_index_range<TLR: ToListReturnTypeBitmask>(
bin: &str,
index: i64,
return_type: TLR,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtListOpType::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::CdtListOp(cdt_op),
}
}
pub fn remove_by_index_range_count<TLR: ToListReturnTypeBitmask>(
bin: &str,
index: i64,
count: i64,
return_type: TLR,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtListOpType::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::CdtListOp(cdt_op),
}
}
pub fn remove_by_rank<TLR: ToListReturnTypeBitmask>(
bin: &str,
rank: i64,
return_type: TLR,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtListOpType::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::CdtListOp(cdt_op),
}
}
pub fn remove_by_rank_range<TLR: ToListReturnTypeBitmask>(
bin: &str,
rank: i64,
return_type: TLR,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtListOpType::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::CdtListOp(cdt_op),
}
}
pub fn remove_by_rank_range_count<TLR: ToListReturnTypeBitmask>(
bin: &str,
rank: i64,
count: i64,
return_type: TLR,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtListOpType::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::CdtListOp(cdt_op),
}
}
pub fn set(bin: &str, index: i64, value: Value) -> Operation {
assert!(!value.is_nil());
let cdt_op = CdtOperation {
op: CdtListOpType::Set as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![CdtArgument::Int(index), CdtArgument::Value(value)],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtListOp(cdt_op),
}
}
pub fn set_with_policy(policy: &ListPolicy, bin: &str, index: i64, value: Value) -> Operation {
assert!(!value.is_nil());
let cdt_op = CdtOperation {
op: CdtListOpType::Set as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![
CdtArgument::Int(index),
CdtArgument::Value(value),
CdtArgument::Byte(policy.flags),
],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtListOp(cdt_op),
}
}
pub fn trim(bin: &str, index: i64, count: i64) -> Operation {
let cdt_op = CdtOperation {
op: CdtListOpType::Trim as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![CdtArgument::Int(index), CdtArgument::Int(count)],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtListOp(cdt_op),
}
}
pub fn clear(bin: &str) -> Operation {
let cdt_op = CdtOperation {
op: CdtListOpType::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::CdtListOp(cdt_op),
}
}
pub fn increment(policy: &ListPolicy, bin: &str, index: i64, value: i64) -> Operation {
let cdt_op = CdtOperation {
op: CdtListOpType::Increment as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![
CdtArgument::Int(index),
CdtArgument::Int(value),
CdtArgument::Byte(policy.flags),
],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtListOp(cdt_op),
}
}
pub fn increment_by_one(bin: &str, index: i64) -> Operation {
let cdt_op = CdtOperation {
op: CdtListOpType::Increment as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![CdtArgument::Int(index)],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtListOp(cdt_op),
}
}
pub fn increment_by_one_with_policy(policy: &ListPolicy, bin: &str, index: i64) -> Operation {
let cdt_op = CdtOperation {
op: CdtListOpType::Increment as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![
CdtArgument::Int(index),
CdtArgument::Int(1),
CdtArgument::Byte(policy.attributes as u8),
CdtArgument::Byte(policy.flags),
],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtListOp(cdt_op),
}
}
pub fn size(bin: &str) -> Operation {
let cdt_op = CdtOperation {
op: CdtListOpType::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::CdtListOp(cdt_op),
}
}
pub fn get(bin: &str, index: i64) -> Operation {
let cdt_op = CdtOperation {
op: CdtListOpType::Get as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![CdtArgument::Int(index)],
};
Operation {
op: OperationType::CdtRead,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtListOp(cdt_op),
}
}
pub fn get_range(bin: &str, index: i64, count: i64) -> Operation {
let cdt_op = CdtOperation {
op: CdtListOpType::GetRange as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![CdtArgument::Int(index), CdtArgument::Int(count)],
};
Operation {
op: OperationType::CdtRead,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtListOp(cdt_op),
}
}
pub fn get_range_from(bin: &str, index: i64) -> Operation {
let cdt_op = CdtOperation {
op: CdtListOpType::GetRange as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![CdtArgument::Int(index)],
};
Operation {
op: OperationType::CdtRead,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtListOp(cdt_op),
}
}
pub fn get_by_value<TLR: ToListReturnTypeBitmask>(
bin: &str,
value: Value,
return_type: TLR,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtListOpType::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::CdtListOp(cdt_op),
}
}
pub fn get_by_value_list<TLR: ToListReturnTypeBitmask>(
bin: &str,
values: Vec<Value>,
return_type: TLR,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtListOpType::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::CdtListOp(cdt_op),
}
}
pub fn get_by_value_range<TLR: ToListReturnTypeBitmask>(
bin: &str,
begin: Value,
end: Value,
return_type: TLR,
) -> 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: CdtListOpType::GetByValueInterval as u8,
encoder: Arc::new(pack_cdt_op),
args,
};
Operation {
op: OperationType::CdtRead,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtListOp(cdt_op),
}
}
pub fn get_by_index<TLR: ToListReturnTypeBitmask>(
bin: &str,
index: i64,
return_type: TLR,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtListOpType::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::CdtListOp(cdt_op),
}
}
pub fn get_by_index_range<TLR: ToListReturnTypeBitmask>(
bin: &str,
index: i64,
return_type: TLR,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtListOpType::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::CdtListOp(cdt_op),
}
}
pub fn get_by_index_range_count<TLR: ToListReturnTypeBitmask>(
bin: &str,
index: i64,
count: i64,
return_type: TLR,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtListOpType::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::CdtListOp(cdt_op),
}
}
pub fn get_by_rank<TLR: ToListReturnTypeBitmask>(
bin: &str,
rank: i64,
return_type: TLR,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtListOpType::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::CdtListOp(cdt_op),
}
}
pub fn get_by_rank_range<TLR: ToListReturnTypeBitmask>(
bin: &str,
rank: i64,
return_type: TLR,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtListOpType::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::CdtListOp(cdt_op),
}
}
pub fn get_by_rank_range_count<TLR: ToListReturnTypeBitmask>(
bin: &str,
rank: i64,
count: i64,
return_type: TLR,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtListOpType::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::CdtListOp(cdt_op),
}
}
pub fn get_by_value_relative_rank_range<TLR: ToListReturnTypeBitmask>(
bin: &str,
value: Value,
rank: i64,
return_type: TLR,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtListOpType::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::CdtListOp(cdt_op),
}
}
pub fn get_by_value_relative_rank_range_count<TLR: ToListReturnTypeBitmask>(
bin: &str,
value: Value,
rank: i64,
count: i64,
return_type: TLR,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtListOpType::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::CdtListOp(cdt_op),
}
}
pub fn sort(bin: &str, sort_flags: ListSortFlags) -> Operation {
let cdt_op = CdtOperation {
op: CdtListOpType::Sort as u8,
encoder: Arc::new(pack_cdt_op),
args: vec![CdtArgument::Byte(sort_flags as u8)],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin.into()),
data: OperationData::CdtListOp(cdt_op),
}
}