Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 44 additions & 3 deletions Cargo.lock

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

File renamed without changes.
8 changes: 7 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub use http_client::send_request;
pub use crate::exports::gcore::fastedge::http_handler;
use crate::gcore::fastedge::http::{Error as HttpError, Method, Request, Response};

mod utils;
mod helper;

/// Implementation of Outbound HTTP component
mod http_client;
Expand Down Expand Up @@ -81,6 +81,12 @@ pub mod key_value {
pub use crate::gcore::fastedge::key_value::Error;
}

/// FastEdge-specific utility functions for diagnostics and statistics.
pub mod utils {
#[doc(inline)]
pub use crate::gcore::fastedge::utils::set_user_diag;
}

/// Error type returned by [`send_request`]
#[derive(thiserror::Error, Debug)]
pub enum Error {
Expand Down
20 changes: 16 additions & 4 deletions src/proxywasm/key_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@
//! }
//! ```
//!
use crate::utils;

use std::fmt::Display;
use crate::helper;
use std::ptr::null_mut;

/// The set of errors which may be raised by functions in this interface
Expand All @@ -67,6 +69,16 @@ pub struct Store {
handle: u32,
}

impl Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Error::NoSuchStore => write!(f, "no such store"),
Error::AccessDenied => write!(f, "access denied"),
Error::Other(msg) => write!(f, "other error: {}", msg),
}
}
}

impl Store {
/// Open the default store.
pub fn new() -> Result<Self, Error> {
Expand Down Expand Up @@ -144,7 +156,7 @@ impl Store {
if !return_data.is_null() {
let data = Vec::from_raw_parts(return_data, return_size, return_size);

let data: Vec<(Vec<u8>, f64)> = utils::deserialize_list(&data)
let data: Vec<(Vec<u8>, f64)> = helper::deserialize_list(&data)
.into_iter()
.map(|v| {
let mut value = v.to_vec();
Expand Down Expand Up @@ -193,7 +205,7 @@ impl Store {
if !return_data.is_null() {
let data = Vec::from_raw_parts(return_data, return_size, return_size);

let data: Vec<String> = utils::deserialize_list(&data)
let data: Vec<String> = helper::deserialize_list(&data)
.into_iter()
.map(|v| String::from_utf8_lossy(v).to_string())
.collect();
Expand Down Expand Up @@ -228,7 +240,7 @@ impl Store {
if !return_data.is_null() {
let data = Vec::from_raw_parts(return_data, return_size, return_size);

let data: Vec<(Vec<u8>, f64)> = utils::deserialize_list(&data)
let data: Vec<(Vec<u8>, f64)> = helper::deserialize_list(&data)
.into_iter()
.map(|v| {
let mut value = v.to_vec();
Expand Down
6 changes: 6 additions & 0 deletions src/proxywasm/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub mod key_value;
pub mod secret;
pub mod dictionary;
pub mod utils;

extern "C" {
fn proxy_secret_get(
Expand Down Expand Up @@ -71,4 +72,9 @@ extern "C" {
item_size: usize,
return_handle: *mut u32,
) -> u32;

fn stats_set_user_diag(
value_data: *const u8,
value_size: usize,
) -> u32;
}
12 changes: 12 additions & 0 deletions src/proxywasm/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//! This module provides an interface for FastEdge specific handlers, such as setting user diagnostics.
//!

/// Save statistics user diagnostic message.
pub fn set_user_diag(value: &str) {
unsafe {
let status = super::stats_set_user_diag(value.as_ptr(), value.len());
if status != 0 {
panic!("unexpected status: {}", status)
}
}
}
2 changes: 1 addition & 1 deletion wit
Submodule wit updated 2 files
+4 −0 utils.wit
+1 −1 world.wit