|
|
@ -29,9 +29,12 @@ use crate::corestore::Data;
|
|
|
|
use crate::dbnet::connection::prelude::*;
|
|
|
|
use crate::dbnet::connection::prelude::*;
|
|
|
|
use crate::kvengine::listmap::LockedVec;
|
|
|
|
use crate::kvengine::listmap::LockedVec;
|
|
|
|
use crate::kvengine::KVTable;
|
|
|
|
use crate::kvengine::KVTable;
|
|
|
|
|
|
|
|
use crate::resp::writer;
|
|
|
|
use crate::resp::writer::TypedArrayWriter;
|
|
|
|
use crate::resp::writer::TypedArrayWriter;
|
|
|
|
|
|
|
|
|
|
|
|
const LEN: &[u8] = "LEN".as_bytes();
|
|
|
|
const LEN: &[u8] = "LEN".as_bytes();
|
|
|
|
|
|
|
|
const LIMIT: &[u8] = "LIMIT".as_bytes();
|
|
|
|
|
|
|
|
const VALUEAT: &[u8] = "VALUEAT".as_bytes();
|
|
|
|
|
|
|
|
|
|
|
|
macro_rules! listmap {
|
|
|
|
macro_rules! listmap {
|
|
|
|
($tbl:expr, $con:expr) => {
|
|
|
|
($tbl:expr, $con:expr) => {
|
|
|
@ -42,6 +45,17 @@ macro_rules! listmap {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
macro_rules! writelist {
|
|
|
|
|
|
|
|
($con:expr, $listmap:expr, $items:expr) => {
|
|
|
|
|
|
|
|
let mut typed_array_writer =
|
|
|
|
|
|
|
|
unsafe { TypedArrayWriter::new($con, $listmap.get_payload_tsymbol(), $items.len()) }
|
|
|
|
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
for item in $items {
|
|
|
|
|
|
|
|
typed_array_writer.write_element(item).await?;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
action! {
|
|
|
|
action! {
|
|
|
|
/// Handle an `LSET` query for the list model
|
|
|
|
/// Handle an `LSET` query for the list model
|
|
|
|
/// Syntax: `LSET <listname> <values ...>`
|
|
|
|
/// Syntax: `LSET <listname> <values ...>`
|
|
|
@ -80,6 +94,14 @@ action! {
|
|
|
|
// get the list name
|
|
|
|
// get the list name
|
|
|
|
let listname = unsafe { act.next_unchecked() };
|
|
|
|
let listname = unsafe { act.next_unchecked() };
|
|
|
|
// now let us see what we need to do
|
|
|
|
// now let us see what we need to do
|
|
|
|
|
|
|
|
macro_rules! get_numeric_count {
|
|
|
|
|
|
|
|
() => {
|
|
|
|
|
|
|
|
match unsafe { String::from_utf8_lossy(act.next_unchecked()) }.parse::<usize>() {
|
|
|
|
|
|
|
|
Ok(int) => int,
|
|
|
|
|
|
|
|
Err(_) => return conwrite!(con, groups::WRONGTYPE_ERR),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
match act.next_uppercase().as_ref() {
|
|
|
|
match act.next_uppercase().as_ref() {
|
|
|
|
None => {
|
|
|
|
None => {
|
|
|
|
// just return everything in the list
|
|
|
|
// just return everything in the list
|
|
|
@ -88,12 +110,7 @@ action! {
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return conwrite!(con, groups::NIL);
|
|
|
|
return conwrite!(con, groups::NIL);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
let mut typed_array_writer = unsafe {
|
|
|
|
writelist!(con, listmap, items);
|
|
|
|
TypedArrayWriter::new(con, listmap.get_payload_tsymbol(), items.len())
|
|
|
|
|
|
|
|
}.await?;
|
|
|
|
|
|
|
|
for item in items {
|
|
|
|
|
|
|
|
typed_array_writer.write_element(item).await?;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Some(subaction) => {
|
|
|
|
Some(subaction) => {
|
|
|
|
match subaction.as_ref() {
|
|
|
|
match subaction.as_ref() {
|
|
|
@ -104,6 +121,41 @@ action! {
|
|
|
|
conwrite!(con, groups::NIL)?;
|
|
|
|
conwrite!(con, groups::NIL)?;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LIMIT => {
|
|
|
|
|
|
|
|
err_if_len_is!(act, con, not 1);
|
|
|
|
|
|
|
|
let count = get_numeric_count!();
|
|
|
|
|
|
|
|
let items = if let Some(keys) = listmap.get_cloned(listname, count) {
|
|
|
|
|
|
|
|
keys
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return conwrite!(con, groups::NIL);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
writelist!(con, listmap, items);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUEAT => {
|
|
|
|
|
|
|
|
err_if_len_is!(act, con, not 1);
|
|
|
|
|
|
|
|
let idx = get_numeric_count!();
|
|
|
|
|
|
|
|
let maybe_value = listmap.get(listname).map(|list| {
|
|
|
|
|
|
|
|
let readlist = list.read();
|
|
|
|
|
|
|
|
let get = readlist.get(idx).cloned();
|
|
|
|
|
|
|
|
get
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
match maybe_value {
|
|
|
|
|
|
|
|
Some(Some(value)) => {
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
|
|
|
|
// tsymbol is verified
|
|
|
|
|
|
|
|
writer::write_raw_mono(con, listmap.get_payload_tsymbol(), &value).await?;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Some(None) => {
|
|
|
|
|
|
|
|
// bad index
|
|
|
|
|
|
|
|
conwrite!(con, groups::LISTMAP_BAD_INDEX)?;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
None => {
|
|
|
|
|
|
|
|
// not found
|
|
|
|
|
|
|
|
conwrite!(con, groups::NIL)?;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
_ => conwrite!(con, groups::UNKNOWN_ACTION)?,
|
|
|
|
_ => conwrite!(con, groups::UNKNOWN_ACTION)?,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|