Crate elvwasm

Source
Expand description

elvwasm contains and collects the bitcode extension API for the Eluvio content fabric.
The library is intended to be built as wasm and the resultant part uploaded to the content fabric. The main entry point for each client module is implemented by jpc which automatically creates and dispatches requests to the BitcodeContext
Example

  extern crate elvwasm;
  extern crate serde_json;
  use serde_json::json;

  use elvwasm::{implement_bitcode_module, jpc, register_handler, BitcodeContext, ErrorKinds};

  implement_bitcode_module!("proxy", do_proxy);

  fn do_proxy(bcc: &mut elvwasm::BitcodeContext) -> CallResult {
      let http_p = &bcc.request.params.http;
      let qp = &http_p.query;
      bcc.log_debug(&format!("In DoProxy hash={} headers={:#?} query params={qp:#?}",&bcc.request.q_info.hash, &http_p.headers))?;
      let res = bcc.sqmd_get_json("/request_parameters")?;
      let mut meta_str: String = match String::from_utf8(res){
        Ok(m) => m,
        Err(e) => {return bcc.make_error_with_kind(ErrorKinds::Invalid(format!("failed to parse request params err = {e}")))}
      };
      meta_str = meta_str.replace("${API_KEY}", &qp["API_KEY"][0].to_string()).
        replace("${QUERY}", &qp["QUERY"][0].to_string()).
        replace("${CONTEXT}", &qp["CONTEXT"][0].to_string());
      bcc.log_debug(&format!("MetaData = {}", &meta_str))?;
      let req:serde_json::Map<String,serde_json::Value> = match serde_json::from_str::<serde_json::Map<String,serde_json::Value>>(&meta_str){
        Ok(m) => m,
        Err(e) => return bcc.make_error_with_kind(ErrorKinds::Invalid(format!("serde_json::from_str failed error = {e}"))),
      };
      let proxy_resp =  bcc.proxy_http(Some(json!({"request": req})))?;
      let proxy_resp_json:serde_json::Value = serde_json::from_str(std::str::from_utf8(&proxy_resp).unwrap_or("{}"))?;
      let client_response = serde_json::to_vec(&proxy_resp_json["result"])?;
      let id = &bcc.request.id;
      bcc.callback(200, "application/json", client_response.len())?;
      bcc.write_stream("fos", &client_response)?;
      bcc.make_success_json(&json!(
        {
            "headers" : "application/json",
            "body" : "SUCCESS",
            "result" : 0,
        }))
  }

To Build binaries
cargo build –all –features “host-wasm”
To Build samples
cd samples
cargo build –target wasm32-unknown-unknown

test
target/debug/mock ./samples/target/wasm32-unknown-unknown/debug/deps/rproxy.wasm ./samples/fabric.json

Re-exports§

pub use self::bccontext::*;
pub use self::bccontext_core::*;
pub use self::bccontext_error::*;
pub use self::bccontext_ext::*;
pub use self::bccontext_search::*;
pub use self::bccontext_struct::*;

Modules§

bccontext
bccontext_core
Context core is a logical separation of portions of the BitcodeContext that result in calls to qfab’s core interfaces
Most documentation will appear in the BitcodeModule and there is nothing else of interest here This module is to organize the fabric APIs via a grouping of their corresoding function on the server
bccontext_error
bccontext_ext
bccontext_search
bccontext_struct

Macros§

implement_bitcode_module
This macro delivers the required initializtion of the eluvio wasm module In addition the macro also registers a handler of the form
implement_ext_func
register_handlers

Functions§

jpc
jpc is the main entry point into a wasm bitcode for the web assembly procedure calls this function will
register_handler
register_handler adjusts the global static call map to associate a bitcode module with a path this map is used by jpc to implement bitcode calls