key_value: change to real api

This commit is contained in:
hosted-fornet 2023-10-11 17:35:34 -07:00
parent 800c4c5bfa
commit 358e2cc447
3 changed files with 8 additions and 14 deletions

View File

@ -107,18 +107,17 @@ fn handle_message (
} }
}, },
// kt::KeyValueMessage::Write { ref key, .. } => { // kt::KeyValueMessage::Write { ref key, .. } => {
kt::KeyValueMessage::Write { ref key, ref val, .. } => { kt::KeyValueMessage::Write { ref key, .. } => {
let Some(db) = db else { let Some(db) = db else {
return Err(anyhow::anyhow!("cannot send New more than once")); return Err(anyhow::anyhow!("cannot send New more than once"));
}; };
// let Payload { mime: _, ref bytes } = get_payload().ok_or(anyhow::anyhow!("couldnt get bytes for Write"))?; let Payload { mime: _, ref bytes } = get_payload().ok_or(anyhow::anyhow!("couldnt get bytes for Write"))?;
let write_txn = db.begin_write()?; let write_txn = db.begin_write()?;
{ {
let mut table = write_txn.open_table(TABLE)?; let mut table = write_txn.open_table(TABLE)?;
// table.insert(&key[..], &bytes[..])?; table.insert(&key[..], &bytes[..])?;
table.insert(&key[..], &val[..])?;
} }
write_txn.commit()?; write_txn.commit()?;
@ -150,17 +149,15 @@ fn handle_message (
); );
}, },
Some(v) => { Some(v) => {
print_to_terminal(0, &format!("key_value_worker: key {:?} value {:?}", key, v.value().to_vec()));
send_response( send_response(
&Response { &Response {
ipc, ipc,
metadata: None, metadata: None,
}, },
None, Some(&Payload {
// Some(&Payload { mime: None,
// mime: None, bytes: v.value().to_vec(),
// bytes: v.value().to_vec(), }),
// }),
); );
}, },
}; };

View File

@ -313,8 +313,7 @@ impl VfsError {
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
pub enum KeyValueMessage { pub enum KeyValueMessage {
New { drive: String }, New { drive: String },
// Write { drive: String, key: Vec<u8> }, Write { drive: String, key: Vec<u8> },
Write { drive: String, key: Vec<u8>, val: Vec<u8> },
Read { drive: String, key: Vec<u8> }, Read { drive: String, key: Vec<u8> },
} }

View File

@ -610,11 +610,9 @@ pub enum KeyValueMessage {
New { New {
drive: String, drive: String,
}, },
// Write { drive: String, key: Vec<u8> },
Write { Write {
drive: String, drive: String,
key: Vec<u8>, key: Vec<u8>,
val: Vec<u8>,
}, },
Read { Read {
drive: String, drive: String,