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;
use std::collections::HashMap;
#[derive(Debug, Clone, Copy)]
#[doc(hidden)]
pub 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,
}
#[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,
Inverted = 0x10000,
}
#[derive(Debug, Clone, Copy)]
pub enum MapWriteMode {
Update,
UpdateOnly,
CreateOnly,
}
#[derive(Debug, Clone, Copy)]
pub struct MapPolicy {
pub order: MapOrder,
pub write_mode: MapWriteMode,
}
impl MapPolicy {
pub const fn new(order: MapOrder, write_mode: MapWriteMode) -> Self {
MapPolicy { order, write_mode }
}
}
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 as u8)),
}
}
#[doc(hidden)]
pub const fn map_order_flag(order: MapOrder) -> u8 {
match order {
MapOrder::KeyOrdered => 0x80,
MapOrder::Unordered => 0x40,
MapOrder::KeyValueOrdered => 0xc0
}
}
pub fn set_order(bin: &str, map_order: MapOrder) -> Operation {
let cdt_op = CdtOperation {
op: CdtMapOpType::SetType as u8,
encoder: Box::new(pack_cdt_op),
args: vec![CdtArgument::Byte(map_order as u8)],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn put<'a>(
policy: &'a MapPolicy,
bin: &'a str,
key: &'a Value,
val: &'a Value,
) -> Operation<'a> {
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: Box::new(pack_cdt_op),
args,
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin),
data: OperationData::CdtMapOp(cdt_op),
}
}
#[allow(clippy::implicit_hasher)]
pub fn put_items<'a>(
policy: &'a MapPolicy,
bin: &'a str,
items: &'a HashMap<Value, Value>,
) -> Operation<'a> {
let mut args = vec![CdtArgument::Map(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: Box::new(pack_cdt_op),
args,
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn increment_value<'a>(
policy: &'a MapPolicy,
bin: &'a str,
key: &'a Value,
incr: &'a Value,
) -> Operation<'a> {
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: Box::new(pack_cdt_op),
args,
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn decrement_value<'a>(
policy: &'a MapPolicy,
bin: &'a str,
key: &'a Value,
decr: &'a Value,
) -> Operation<'a> {
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: Box::new(pack_cdt_op),
args,
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn clear(bin: &str) -> Operation {
let cdt_op = CdtOperation {
op: CdtMapOpType::Clear as u8,
encoder: Box::new(pack_cdt_op),
args: vec![],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn remove_by_key<'a>(
bin: &'a str,
key: &'a Value,
return_type: MapReturnType,
) -> Operation<'a> {
let cdt_op = CdtOperation {
op: CdtMapOpType::RemoveByKey as u8,
encoder: Box::new(pack_cdt_op),
args: vec![
CdtArgument::Byte(return_type as u8),
CdtArgument::Value(key),
],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn remove_by_key_list<'a>(
bin: &'a str,
keys: &'a [Value],
return_type: MapReturnType,
) -> Operation<'a> {
let cdt_op = CdtOperation {
op: CdtMapOpType::RemoveKeyList as u8,
encoder: Box::new(pack_cdt_op),
args: vec![
CdtArgument::Byte(return_type as u8),
CdtArgument::List(keys),
],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn remove_by_key_range<'a>(
bin: &'a str,
begin: &'a Value,
end: &'a Value,
return_type: MapReturnType,
) -> Operation<'a> {
let mut args = vec![
CdtArgument::Byte(return_type as u8),
CdtArgument::Value(begin),
];
if !end.is_nil() {
args.push(CdtArgument::Value(end));
}
let cdt_op = CdtOperation {
op: CdtMapOpType::RemoveByKeyInterval as u8,
encoder: Box::new(pack_cdt_op),
args,
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn remove_by_value<'a>(
bin: &'a str,
value: &'a Value,
return_type: MapReturnType,
) -> Operation<'a> {
let cdt_op = CdtOperation {
op: CdtMapOpType::RemoveByValue as u8,
encoder: Box::new(pack_cdt_op),
args: vec![
CdtArgument::Byte(return_type as u8),
CdtArgument::Value(value),
],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn remove_by_value_list<'a>(
bin: &'a str,
values: &'a [Value],
return_type: MapReturnType,
) -> Operation<'a> {
let cdt_op = CdtOperation {
op: CdtMapOpType::RemoveValueList as u8,
encoder: Box::new(pack_cdt_op),
args: vec![
CdtArgument::Byte(return_type as u8),
CdtArgument::List(values),
],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn remove_by_value_range<'a>(
bin: &'a str,
begin: &'a Value,
end: &'a Value,
return_type: MapReturnType,
) -> Operation<'a> {
let mut args = vec![
CdtArgument::Byte(return_type as u8),
CdtArgument::Value(begin),
];
if !end.is_nil() {
args.push(CdtArgument::Value(end));
}
let cdt_op = CdtOperation {
op: CdtMapOpType::RemoveByValueInterval as u8,
encoder: Box::new(pack_cdt_op),
args,
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn remove_by_index(bin: &str, index: i64, return_type: MapReturnType) -> Operation {
let cdt_op = CdtOperation {
op: CdtMapOpType::RemoveByIndex as u8,
encoder: Box::new(pack_cdt_op),
args: vec![
CdtArgument::Byte(return_type as u8),
CdtArgument::Int(index),
],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn remove_by_index_range(
bin: &str,
index: i64,
count: i64,
return_type: MapReturnType,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtMapOpType::RemoveByIndexRange as u8,
encoder: Box::new(pack_cdt_op),
args: vec![
CdtArgument::Byte(return_type as u8),
CdtArgument::Int(index),
CdtArgument::Int(count),
],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn remove_by_index_range_from(bin: &str, index: i64, return_type: MapReturnType) -> Operation {
let cdt_op = CdtOperation {
op: CdtMapOpType::RemoveByIndexRange as u8,
encoder: Box::new(pack_cdt_op),
args: vec![
CdtArgument::Byte(return_type as u8),
CdtArgument::Int(index),
],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn remove_by_rank(bin: &str, rank: i64, return_type: MapReturnType) -> Operation {
let cdt_op = CdtOperation {
op: CdtMapOpType::RemoveByRank as u8,
encoder: Box::new(pack_cdt_op),
args: vec![CdtArgument::Byte(return_type as u8), CdtArgument::Int(rank)],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn remove_by_rank_range(
bin: &str,
rank: i64,
count: i64,
return_type: MapReturnType,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtMapOpType::RemoveByRankRange as u8,
encoder: Box::new(pack_cdt_op),
args: vec![
CdtArgument::Byte(return_type as u8),
CdtArgument::Int(rank),
CdtArgument::Int(count),
],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn remove_by_rank_range_from(bin: &str, rank: i64, return_type: MapReturnType) -> Operation {
let cdt_op = CdtOperation {
op: CdtMapOpType::RemoveByRankRange as u8,
encoder: Box::new(pack_cdt_op),
args: vec![CdtArgument::Byte(return_type as u8), CdtArgument::Int(rank)],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn size(bin: &str) -> Operation {
let cdt_op = CdtOperation {
op: CdtMapOpType::Size as u8,
encoder: Box::new(pack_cdt_op),
args: vec![],
};
Operation {
op: OperationType::CdtRead,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn get_by_key<'a>(bin: &'a str, key: &'a Value, return_type: MapReturnType) -> Operation<'a> {
let cdt_op = CdtOperation {
op: CdtMapOpType::GetByKey as u8,
encoder: Box::new(pack_cdt_op),
args: vec![
CdtArgument::Byte(return_type as u8),
CdtArgument::Value(key),
],
};
Operation {
op: OperationType::CdtRead,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn get_by_key_range<'a>(
bin: &'a str,
begin: &'a Value,
end: &'a Value,
return_type: MapReturnType,
) -> Operation<'a> {
let mut args = vec![
CdtArgument::Byte(return_type as u8),
CdtArgument::Value(begin),
];
if !end.is_nil() {
args.push(CdtArgument::Value(end));
}
let cdt_op = CdtOperation {
op: CdtMapOpType::GetByKeyInterval as u8,
encoder: Box::new(pack_cdt_op),
args,
};
Operation {
op: OperationType::CdtRead,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn get_by_value<'a>(
bin: &'a str,
value: &'a Value,
return_type: MapReturnType,
) -> Operation<'a> {
let cdt_op = CdtOperation {
op: CdtMapOpType::GetByValue as u8,
encoder: Box::new(pack_cdt_op),
args: vec![
CdtArgument::Byte(return_type as u8),
CdtArgument::Value(value),
],
};
Operation {
op: OperationType::CdtRead,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn get_by_value_range<'a>(
bin: &'a str,
begin: &'a Value,
end: &'a Value,
return_type: MapReturnType,
) -> Operation<'a> {
let mut args = vec![
CdtArgument::Byte(return_type as u8),
CdtArgument::Value(begin),
];
if !end.is_nil() {
args.push(CdtArgument::Value(end));
}
let cdt_op = CdtOperation {
op: CdtMapOpType::GetByValueInterval as u8,
encoder: Box::new(pack_cdt_op),
args,
};
Operation {
op: OperationType::CdtRead,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn get_by_index(bin: &str, index: i64, return_type: MapReturnType) -> Operation {
let cdt_op = CdtOperation {
op: CdtMapOpType::GetByIndex as u8,
encoder: Box::new(pack_cdt_op),
args: vec![
CdtArgument::Byte(return_type as u8),
CdtArgument::Int(index),
],
};
Operation {
op: OperationType::CdtRead,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn get_by_index_range(
bin: &str,
index: i64,
count: i64,
return_type: MapReturnType,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtMapOpType::GetByIndexRange as u8,
encoder: Box::new(pack_cdt_op),
args: vec![
CdtArgument::Byte(return_type as u8),
CdtArgument::Int(index),
CdtArgument::Int(count),
],
};
Operation {
op: OperationType::CdtRead,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn get_by_index_range_from(bin: &str, index: i64, return_type: MapReturnType) -> Operation {
let cdt_op = CdtOperation {
op: CdtMapOpType::GetByIndexRange as u8,
encoder: Box::new(pack_cdt_op),
args: vec![
CdtArgument::Byte(return_type as u8),
CdtArgument::Int(index),
],
};
Operation {
op: OperationType::CdtRead,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn get_by_rank(bin: &str, rank: i64, return_type: MapReturnType) -> Operation {
let cdt_op = CdtOperation {
op: CdtMapOpType::GetByRank as u8,
encoder: Box::new(pack_cdt_op),
args: vec![CdtArgument::Byte(return_type as u8), CdtArgument::Int(rank)],
};
Operation {
op: OperationType::CdtRead,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn get_by_rank_range(
bin: &str,
rank: i64,
count: i64,
return_type: MapReturnType,
) -> Operation {
let cdt_op = CdtOperation {
op: CdtMapOpType::GetByRankRange as u8,
encoder: Box::new(pack_cdt_op),
args: vec![
CdtArgument::Byte(return_type as u8),
CdtArgument::Int(rank),
CdtArgument::Int(count),
],
};
Operation {
op: OperationType::CdtRead,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn get_by_rank_range_from(bin: &str, rank: i64, return_type: MapReturnType) -> Operation {
let cdt_op = CdtOperation {
op: CdtMapOpType::GetByRankRange as u8,
encoder: Box::new(pack_cdt_op),
args: vec![CdtArgument::Byte(return_type as u8), CdtArgument::Int(rank)],
};
Operation {
op: OperationType::CdtRead,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn remove_by_key_relative_index_range<'a>(
bin: &'a str,
key: &'a Value,
index: i64,
return_type: MapReturnType,
) -> Operation<'a> {
let cdt_op = CdtOperation {
op: CdtMapOpType::RemoveByKeyRelIndexRange as u8,
encoder: Box::new(pack_cdt_op),
args: vec![
CdtArgument::Byte(return_type as u8),
CdtArgument::Value(key),
CdtArgument::Int(index),
],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn remove_by_key_relative_index_range_count<'a>(
bin: &'a str,
key: &'a Value,
index: i64,
count: i64,
return_type: MapReturnType,
) -> Operation<'a> {
let cdt_op = CdtOperation {
op: CdtMapOpType::RemoveByKeyRelIndexRange as u8,
encoder: Box::new(pack_cdt_op),
args: vec![
CdtArgument::Byte(return_type as u8),
CdtArgument::Value(key),
CdtArgument::Int(index),
CdtArgument::Int(count),
],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn remove_by_value_relative_rank_range<'a>(
bin: &'a str,
value: &'a Value,
rank: i64,
return_type: MapReturnType,
) -> Operation<'a> {
let cdt_op = CdtOperation {
op: CdtMapOpType::RemoveByValueRelRankRange as u8,
encoder: Box::new(pack_cdt_op),
args: vec![
CdtArgument::Byte(return_type as u8),
CdtArgument::Value(value),
CdtArgument::Int(rank),
],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn remove_by_value_relative_rank_range_count<'a>(
bin: &'a str,
value: &'a Value,
rank: i64,
count: i64,
return_type: MapReturnType,
) -> Operation<'a> {
let cdt_op = CdtOperation {
op: CdtMapOpType::RemoveByValueRelRankRange as u8,
encoder: Box::new(pack_cdt_op),
args: vec![
CdtArgument::Byte(return_type as u8),
CdtArgument::Value(value),
CdtArgument::Int(rank),
CdtArgument::Int(count),
],
};
Operation {
op: OperationType::CdtWrite,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn get_by_key_list<'a>(
bin: &'a str,
keys: &'a [Value],
return_type: MapReturnType,
) -> Operation<'a> {
let cdt_op = CdtOperation {
op: CdtMapOpType::GetByKeyList as u8,
encoder: Box::new(pack_cdt_op),
args: vec![
CdtArgument::Byte(return_type as u8),
CdtArgument::List(keys),
],
};
Operation {
op: OperationType::CdtRead,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn get_by_value_list<'a>(
bin: &'a str,
values: &'a [Value],
return_type: MapReturnType,
) -> Operation<'a> {
let cdt_op = CdtOperation {
op: CdtMapOpType::GetByValueList as u8,
encoder: Box::new(pack_cdt_op),
args: vec![
CdtArgument::Byte(return_type as u8),
CdtArgument::List(values),
],
};
Operation {
op: OperationType::CdtRead,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn get_by_key_relative_index_range<'a>(
bin: &'a str,
key: &'a Value,
index: i64,
return_type: MapReturnType,
) -> Operation<'a> {
let cdt_op = CdtOperation {
op: CdtMapOpType::GetByKeyRelIndexRange as u8,
encoder: Box::new(pack_cdt_op),
args: vec![
CdtArgument::Byte(return_type as u8),
CdtArgument::Value(key),
CdtArgument::Int(index),
],
};
Operation {
op: OperationType::CdtRead,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn get_by_key_relative_index_range_count<'a>(
bin: &'a str,
key: &'a Value,
index: i64,
count: i64,
return_type: MapReturnType,
) -> Operation<'a> {
let cdt_op = CdtOperation {
op: CdtMapOpType::GetByKeyRelIndexRange as u8,
encoder: Box::new(pack_cdt_op),
args: vec![
CdtArgument::Byte(return_type as u8),
CdtArgument::Value(key),
CdtArgument::Int(index),
CdtArgument::Int(count),
],
};
Operation {
op: OperationType::CdtRead,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn get_by_value_relative_rank_range<'a>(
bin: &'a str,
value: &'a Value,
rank: i64,
return_type: MapReturnType,
) -> Operation<'a> {
let cdt_op = CdtOperation {
op: CdtMapOpType::GetByValueRelRankRange as u8,
encoder: Box::new(pack_cdt_op),
args: vec![
CdtArgument::Byte(return_type as u8),
CdtArgument::Value(value),
CdtArgument::Int(rank),
],
};
Operation {
op: OperationType::CdtRead,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin),
data: OperationData::CdtMapOp(cdt_op),
}
}
pub fn get_by_value_relative_rank_range_count<'a>(
bin: &'a str,
value: &'a Value,
rank: i64,
count: i64,
return_type: MapReturnType,
) -> Operation<'a> {
let cdt_op = CdtOperation {
op: CdtMapOpType::GetByValueRelRankRange as u8,
encoder: Box::new(pack_cdt_op),
args: vec![
CdtArgument::Byte(return_type as u8),
CdtArgument::Value(value),
CdtArgument::Int(rank),
CdtArgument::Int(count),
],
};
Operation {
op: OperationType::CdtRead,
ctx: DEFAULT_CTX,
bin: OperationBin::Name(bin),
data: OperationData::CdtMapOp(cdt_op),
}
}