Skip to content

Commit

Permalink
feat(kv,wasm): kv persist and http arg
Browse files Browse the repository at this point in the history
1.  Persist kv on master
2. Support multi fn http handler(second level path)
3. Suited panote app
  • Loading branch information
ActivePeter committed Feb 21, 2024
1 parent 7c495c7 commit fa8491b
Show file tree
Hide file tree
Showing 60 changed files with 3,487 additions and 292 deletions.
77 changes: 77 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ moka = { version = "0.12.1", features = ["sync"] }
rand = "0.8.5"
slotmap = { version = "1.0" }
prometheus-client = "0.22.1"
tower-http = {version="0.4.0", features=["cors"]}
tower= "0.4.0"
sled = "0.34.7"

# slog-envlogger = { version = "2.1.0", optional = true }

Expand Down
1 change: 1 addition & 0 deletions apps/_wasm_serverless_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ edition = "2021"
crate-type = ["lib"]

[dependencies]
wasmedge-bindgen = "0.4.1"
23 changes: 22 additions & 1 deletion apps/_wasm_serverless_lib/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::mem::ManuallyDrop;
use std::vec::Vec;

pub use wasmedge_bindgen::*;
// use externref::externref;
// #[allow(unused_imports)]
// use wasmedge_bindgen::*;
Expand All @@ -14,6 +14,26 @@ extern "C" {
fn kv_batch_res(ope_id: i32, args_ptr: *const i32, args_len: i32);
fn open_file(fname: *const u8, fnamelen: i32, fd: &mut i32);
fn read_file_at(fd: i32, buf: *const u8, buflen: i32, offset: i32, readlen: &mut i32);
pub fn write_result(res_ptr: *const u8, res_len: i32);
}

pub trait KvResTrans {
fn res_str(&self) -> Option<&str>;
}

impl KvResTrans for Vec<KvResult> {
fn res_str(&self) -> Option<&str> {
if let KvResult::Get(Some(s)) = &self[0] {
return std::str::from_utf8(s).map_or_else(
|err| {
println!("err when get kv res str:{}", err);
None
},
|v| Some(v),
);
}
None
}
}

// pub enum KvOpe {
Expand Down Expand Up @@ -191,6 +211,7 @@ impl HostFile {
Self { fd }
}

// data will be append to `buf` until the file is read to the end or `buf` is full to capacity
pub fn read_at(&self, offset: usize, buf: &mut Vec<u8>) -> usize {
let mut readlen = 0;
let buf_old_len = buf.len();
Expand Down
3 changes: 3 additions & 0 deletions apps/fn2/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions apps/longchain/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit fa8491b

Please sign in to comment.