diff options
| author | Aram Drevekenin <aram@poor.dev> | 2023-08-09 22:26:00 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-08-09 22:26:00 +0200 |
| commit | 1bedfc90021558cb201695444107afe5bddd2c17 (patch) | |
| tree | 38dd31b5ab112aa9b1c3a54edb07331013bf7d87 /zellij-server/src/plugins/plugin_worker.rs | |
| parent | docs(changelog): plug memory leak (diff) | |
| download | sl0ppij-1bedfc90021558cb201695444107afe5bddd2c17.tar.gz sl0ppij-1bedfc90021558cb201695444107afe5bddd2c17.tar.xz sl0ppij-1bedfc90021558cb201695444107afe5bddd2c17.zip | |
feat(plugins): use protocol buffers for serializing across the wasm boundary (#2686)
* work
* almost done with command protobuffers
* done translating command data structures
* mid transferring of every command to protobuff command
* transferred plugin_command.rs, now moving on to shim.rs
* plugin command working with protobufs
* protobuffers in update
* protobuf event tests
* various TODOs and comments
* fix zellij-tile
* clean up prost deps
* remove version mismatch error
* fix panic
* some cleanups
* clean up event protobuffers
* clean up command protobuffers
* clean up various protobufs
* refactor protobufs
* update comments
* some transformation fixes
* use protobufs for workers
* style(fmt): rustfmt
* style(fmt): rustfmt
* chore(build): add protoc
* chore(build): authenticate protoc
Diffstat (limited to 'zellij-server/src/plugins/plugin_worker.rs')
| -rw-r--r-- | zellij-server/src/plugins/plugin_worker.rs | 31 |
1 files changed, 11 insertions, 20 deletions
diff --git a/zellij-server/src/plugins/plugin_worker.rs b/zellij-server/src/plugins/plugin_worker.rs index bc7303c7..9aae0bab 100644 --- a/zellij-server/src/plugins/plugin_worker.rs +++ b/zellij-server/src/plugins/plugin_worker.rs @@ -1,4 +1,3 @@ -use crate::plugins::plugin_loader::VersionMismatchError; use crate::plugins::plugin_map::PluginEnv; use crate::plugins::zellij_exports::wasi_write_object; use wasmer::Instance; @@ -6,7 +5,9 @@ use wasmer::Instance; use zellij_utils::async_channel::{unbounded, Receiver, Sender}; use zellij_utils::async_std::task; use zellij_utils::errors::prelude::*; -use zellij_utils::{consts::VERSION, input::plugins::PluginConfig}; +use zellij_utils::input::plugins::PluginConfig; +use zellij_utils::plugin_api::message::ProtobufMessage; +use zellij_utils::prost::Message; pub struct RunningWorker { pub instance: Instance, @@ -31,29 +32,19 @@ impl RunningWorker { } pub fn send_message(&self, message: String, payload: String) -> Result<()> { let err_context = || format!("Failed to send message to worker"); - + let protobuf_message = ProtobufMessage { + name: message, + payload, + ..Default::default() + }; + let protobuf_bytes = protobuf_message.encode_to_vec(); let work_function = self .instance .exports .get_function(&self.name) .with_context(err_context)?; - wasi_write_object(&self.plugin_env.wasi_env, &(message, payload)) - .with_context(err_context)?; - work_function.call(&[]).or_else::<anyError, _>(|e| { - match e.downcast::<serde_json::Error>() { - Ok(_) => panic!( - "{}", - anyError::new(VersionMismatchError::new( - VERSION, - "Unavailable", - &self.plugin_config.path, - self.plugin_config.is_builtin(), - )) - ), - Err(e) => Err(e).with_context(err_context), - } - })?; - + wasi_write_object(&self.plugin_env.wasi_env, &protobuf_bytes).with_context(err_context)?; + work_function.call(&[]).with_context(err_context)?; Ok(()) } } |
