Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add protobuf module as wasm module #2054

Draft
wants to merge 21 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion .github/workflows/lint_master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,4 @@ jobs:
- name: install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- name: Execute tests
run: cargo chipmunk test core wrapper wasm -u print
run: cargo chipmunk test core wrapper wasm -u print
2 changes: 1 addition & 1 deletion .github/workflows/pullrequest_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,4 @@ jobs:
- name: install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- name: Execute tests
run: cargo chipmunk test core wrapper wasm -u print
run: cargo chipmunk test core wrapper wasm -u print
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ jobs:
uses: actions/setup-node@master
with:
node-version: "current"
- name: Install Protoc
uses: arduino/setup-protoc@v3
- name: install rust
uses: hecrj/setup-rust-action@v1
with:
Expand Down
4 changes: 3 additions & 1 deletion application/apps/indexer/sources/src/factory.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use indexer_base::config::MulticastInfo;
pub use indexer_base::config::MulticastInfo;
use parsers::dlt;
use serde::{Deserialize, Serialize};
use std::{collections::HashMap, path::PathBuf};
use uuid::Uuid;

pub use dlt::DltFilterConfig;

#[allow(clippy::large_enum_variant)]
#[derive(Debug, Serialize, Deserialize, Clone)]
pub enum ParserType {
Expand Down
47 changes: 47 additions & 0 deletions application/apps/protocol/binding/extend/Cargo.lock

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

12 changes: 12 additions & 0 deletions application/apps/protocol/binding/extend/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "extend"
version = "0.1.0"
edition = "2018"

[lib]
proc-macro = true

[dependencies]
proc-macro2 = "1.0.78"
quote = "1.0"
syn = { version="2.0.37", features=["full","fold"] }
40 changes: 40 additions & 0 deletions application/apps/protocol/binding/extend/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
mod opt;
use opt::Opt;
use proc_macro::TokenStream;
use quote::quote;
use syn::{parse_macro_input, ItemStruct, Path};

#[proc_macro_attribute]
pub fn extend(args: TokenStream, input: TokenStream) -> TokenStream {
let opt: Opt = parse_macro_input!(args as Opt);
let item_struct = parse_macro_input!(input as ItemStruct);
let proto_path: Path = if opt.path.is_empty() {
syn::parse_str(&format!("{}", item_struct.ident))
} else {
syn::parse_str(&format!("{}::{}", opt.path, item_struct.ident))
}
.expect("Path to proto type parsed");
let struct_name = item_struct.ident.clone();
TokenStream::from(quote! {

#[wasm_bindgen]
#item_struct

#[wasm_bindgen]
impl #struct_name {

#[wasm_bindgen]
pub fn decode(buf: &[u8]) -> Result<JsValue, E> {
Ok(to_value(&#proto_path::decode(buf)?)?)
}

#[wasm_bindgen]
pub fn encode(val: JsValue) -> Result<Vec<u8>, E> {
let val: #proto_path = from_value(val)?;
let mut buf = Vec::new();
val.encode(&mut buf)?;
Ok(buf)
}
}
})
}
36 changes: 36 additions & 0 deletions application/apps/protocol/binding/extend/src/opt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use syn::{
parse::{self, Parse, ParseStream},
punctuated::Punctuated,
Expr, Token,
};

#[derive(Clone, Debug, Default)]
pub struct Opt {
pub path: String,
}

impl Opt {
pub(self) fn new(path: String) -> Self {
Self { path }
}
}

impl Parse for Opt {
fn parse(input: ParseStream) -> parse::Result<Self> {
let input = Punctuated::<Expr, Token![,]>::parse_terminated(input)?;
let Some(expr) = input.first() else {
return Ok(Opt::new(String::new()));
};

let Expr::Path(p) = expr else {
return Err(syn::Error::new_spanned(
expr,
"Expecting expr like [key = \"value as String\"] or [key]",
));
};
let Some(ident) = p.path.get_ident() else {
return Err(syn::Error::new_spanned(p, "Cannot extract identification"));
};
Ok(Opt::new(ident.to_string()))
}
}
1 change: 1 addition & 0 deletions application/apps/protocol/binding/proto/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
Loading