From 7e8ee5ed9cad6484e9f13f81731b102ced58402e Mon Sep 17 00:00:00 2001 From: Adam Carpenter Date: Tue, 9 Jul 2019 15:14:04 -0400 Subject: Init. --- meap/actionkv/Cargo.lock | 32 +++++++++++++++++++++ meap/actionkv/Cargo.toml | 18 ++++++++++++ meap/actionkv/src/akv_mem.rs | 52 ++++++++++++++++++++++++++++++++++ meap/actionkv/src/lib.rs | 7 +++++ meap/actionkv/target/.rustc_info.json | 1 + meap/actionkv/target/debug/.cargo-lock | 0 6 files changed, 110 insertions(+) create mode 100755 meap/actionkv/Cargo.lock create mode 100755 meap/actionkv/Cargo.toml create mode 100755 meap/actionkv/src/akv_mem.rs create mode 100755 meap/actionkv/src/lib.rs create mode 100755 meap/actionkv/target/.rustc_info.json create mode 100755 meap/actionkv/target/debug/.cargo-lock (limited to 'meap/actionkv') diff --git a/meap/actionkv/Cargo.lock b/meap/actionkv/Cargo.lock new file mode 100755 index 0000000..6940551 --- /dev/null +++ b/meap/actionkv/Cargo.lock @@ -0,0 +1,32 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "actionkv" +version = "0.1.0" +dependencies = [ + "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", + "crc 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "build_const" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "byteorder" +version = "1.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "crc" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "build_const 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[metadata] +"checksum build_const 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "39092a32794787acd8525ee150305ff051b0aa6cc2abaf193924f5ab05425f39" +"checksum byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "94f88df23a25417badc922ab0f5716cc1330e87f71ddd9203b3a3ccd9cedf75d" +"checksum crc 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bd5d02c0aac6bd68393ed69e00bbc2457f3e89075c6349db7189618dc4ddc1d7" diff --git a/meap/actionkv/Cargo.toml b/meap/actionkv/Cargo.toml new file mode 100755 index 0000000..84ed719 --- /dev/null +++ b/meap/actionkv/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "actionkv" +version = "0.1.0" +authors = ["Adam Carpenter <53hornet@gmail.com>"] +edition = "2018" + +[dependencies] +byteorder = "~1.2" +crc = "~1.7" + +[lib] +name = "libactionkv" +path = "src/lib.rs" + +[[bin]] +name = "akv_mem" +path = "src/akv_mem.rs" + diff --git a/meap/actionkv/src/akv_mem.rs b/meap/actionkv/src/akv_mem.rs new file mode 100755 index 0000000..cbcf88c --- /dev/null +++ b/meap/actionkv/src/akv_mem.rs @@ -0,0 +1,52 @@ +extern crate libactionkv; + +use libactionkv::ActionKv; + +#[cfg(target_os = "windows")] +const USAGE: &'static str = " +Usage: + akv_mem.exe FILE get KEY + akv_mem.exe FILE delete KEY + akv_mem.exe FILE insert KEY VALUE + akv_mem.exe FILE update KEY VALUE +"; + +#[cfg(not(target_os = "windows"))] +const USAGE: &'static str = " +Usage: + akv_mem FILE get KEY + akv_mem FILE delete KEY + akv_mem FILE insert KEY VALUE + akv_mem FILE update KEY VALUE +"; + +fn main() { + let args: Vec = std::env::args().collect(); + let fname = args.get(1).expect(&USAGE); + let action = args.get(2).expect(&USAGE).as_ref(); + let key = args.get(3).expect(&USAGE).as_ref(); + let maybe_value = args.get(4); + + let path = std::path::Path::new(&fname); + let mut store = ActionKV::open(path).expect("unable to open file"); + store.load().expect("unable to load data"); + + match action { + "get" => { + match store.get(key).unwrap() { + None => eprintln!("{:?} not found", key), + Some(value) => println!("{:?}", value), + } + }, + "delete" => store.delete(key).unwrap(), + "insert" => { + let value = maybe_value.expect(&USAGE).as_ref(); + store.insert(key, value).unwrap() + }, + "update" => { + let value = maybe_value.expect(&USAGE).as_ref(); + store.update(key, value).unwrap() + }, + _ => eprintln!("{}", &USAGE), + } +} diff --git a/meap/actionkv/src/lib.rs b/meap/actionkv/src/lib.rs new file mode 100755 index 0000000..31e1bb2 --- /dev/null +++ b/meap/actionkv/src/lib.rs @@ -0,0 +1,7 @@ +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + assert_eq!(2 + 2, 4); + } +} diff --git a/meap/actionkv/target/.rustc_info.json b/meap/actionkv/target/.rustc_info.json new file mode 100755 index 0000000..6645707 --- /dev/null +++ b/meap/actionkv/target/.rustc_info.json @@ -0,0 +1 @@ +{"rustc_fingerprint":5361904215157244162,"outputs":{"1164083562126845933":["rustc 1.34.0\nbinary: rustc\ncommit-hash: unknown\ncommit-date: unknown\nhost: x86_64-unknown-linux-gnu\nrelease: 1.34.0\nLLVM version: 8.0\n",""],"15337506775154344876":["___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/usr\ndebug_assertions\nproc_macro\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"unknown\"\nunix\n",""],"1617349019360157463":["___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/usr\ndebug_assertions\nproc_macro\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"unknown\"\nunix\n",""]},"successes":{}} \ No newline at end of file diff --git a/meap/actionkv/target/debug/.cargo-lock b/meap/actionkv/target/debug/.cargo-lock new file mode 100755 index 0000000..e69de29 -- cgit v1.2.3