From 14e59dfb8ff5ceab946fb9ea531d21f895b7f80e Mon Sep 17 00:00:00 2001 From: we sell insurance Date: Sat, 31 Aug 2024 17:24:43 -0500 Subject: [PATCH 1/3] Create Identifer to help keep track of plugin resources. --- Cargo.lock | 9 +++++---- pumpkin-plugin/Cargo.toml | 3 ++- pumpkin-plugin/src/api/identifer.rs | 15 +++++++++++++++ pumpkin-plugin/src/api/mod.rs | 1 + pumpkin-plugin/src/lib.rs | 2 ++ 5 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 pumpkin-plugin/src/api/identifer.rs create mode 100644 pumpkin-plugin/src/api/mod.rs diff --git a/Cargo.lock b/Cargo.lock index 990b46cf0..daf2d714a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1972,6 +1972,7 @@ version = "0.1.0" dependencies = [ "extism", "log", + "serde", ] [[package]] @@ -2404,9 +2405,9 @@ checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "serde" -version = "1.0.205" +version = "1.0.209" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e33aedb1a7135da52b7c21791455563facbbcc43d0f0f66165b42c21b3dfb150" +checksum = "99fce0ffe7310761ca6bf9faf5115afbc19688edd00171d81b1bb1b116c63e09" dependencies = [ "serde_derive", ] @@ -2422,9 +2423,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.205" +version = "1.0.209" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "692d6f5ac90220161d6774db30c662202721e64aed9058d2c394f451261420c1" +checksum = "a5831b979fd7b5439637af1752d535ff49f4860c0f341d1baeb6faf0f4242170" dependencies = [ "proc-macro2", "quote", diff --git a/pumpkin-plugin/Cargo.toml b/pumpkin-plugin/Cargo.toml index a3d6bea27..e757c6539 100644 --- a/pumpkin-plugin/Cargo.toml +++ b/pumpkin-plugin/Cargo.toml @@ -5,4 +5,5 @@ edition.workspace = true [dependencies] extism = "1.5.0" -log.workspace = true \ No newline at end of file +log.workspace = true +serde ={ version = "1.0.209", features = ["derive"] } \ No newline at end of file diff --git a/pumpkin-plugin/src/api/identifer.rs b/pumpkin-plugin/src/api/identifer.rs new file mode 100644 index 000000000..cdfce0e47 --- /dev/null +++ b/pumpkin-plugin/src/api/identifer.rs @@ -0,0 +1,15 @@ +use extism::{convert::Msgpack, host_fn, FromBytes, ToBytes}; +use serde::{Deserialize, Serialize}; + +/// Used to keep track of things created by plugins. +/// This can include things like events, commands, etc. +#[derive(Hash, PartialEq, Eq, ToBytes, FromBytes, Serialize, Deserialize)] +#[encoding(Msgpack)] +struct Identifier { + namespace: String, + path: String, +} + +host_fn!(new(namespace: String, path: String) -> Result { + Ok(Identifier { namespace, path }) +}); diff --git a/pumpkin-plugin/src/api/mod.rs b/pumpkin-plugin/src/api/mod.rs new file mode 100644 index 000000000..e9cb03788 --- /dev/null +++ b/pumpkin-plugin/src/api/mod.rs @@ -0,0 +1 @@ +mod identifer; diff --git a/pumpkin-plugin/src/lib.rs b/pumpkin-plugin/src/lib.rs index 3ac56bf6f..66865e2c0 100644 --- a/pumpkin-plugin/src/lib.rs +++ b/pumpkin-plugin/src/lib.rs @@ -1,3 +1,5 @@ +mod api; + use std::path::Path; use extism::{Manifest, Plugin, Wasm}; From 5ab877a40a0003cead2753ea3c9354e09dc675c7 Mon Sep 17 00:00:00 2001 From: we sell insurance Date: Sun, 1 Sep 2024 08:16:43 -0500 Subject: [PATCH 2/3] Add TODO comment for encoding --- pumpkin-plugin/src/api/identifer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pumpkin-plugin/src/api/identifer.rs b/pumpkin-plugin/src/api/identifer.rs index cdfce0e47..886282bad 100644 --- a/pumpkin-plugin/src/api/identifer.rs +++ b/pumpkin-plugin/src/api/identifer.rs @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize}; /// Used to keep track of things created by plugins. /// This can include things like events, commands, etc. #[derive(Hash, PartialEq, Eq, ToBytes, FromBytes, Serialize, Deserialize)] -#[encoding(Msgpack)] +#[encoding(Msgpack)] // TODO: Switch to protocal buffers for smaller size struct Identifier { namespace: String, path: String, From 0a02c28b26d7de11b125c4d1af24c7d290f903ef Mon Sep 17 00:00:00 2001 From: we sell insurance Date: Sun, 1 Sep 2024 12:26:48 -0500 Subject: [PATCH 3/3] Move serde into workspace --- Cargo.toml | 1 + pumpkin-core/Cargo.toml | 2 +- pumpkin-plugin/Cargo.toml | 2 +- pumpkin-protocol/Cargo.toml | 2 +- pumpkin-registry/Cargo.toml | 2 +- pumpkin-world/Cargo.toml | 2 +- pumpkin/Cargo.toml | 2 +- 7 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3fbea597f..e52fe3294 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,3 +17,4 @@ tokio = { version = "1.39.2", features = ["net", "macros", "rt-multi-thread", "f rayon = "1.10.0" uuid = { version = "1.10.0", features = ["serde", "v3"] } derive_more = { version = "1.0.0", features = ["full"] } +serde = { version = "1.0", features = ["derive"] } diff --git a/pumpkin-core/Cargo.toml b/pumpkin-core/Cargo.toml index 6bd39248b..f2a86dcd1 100644 --- a/pumpkin-core/Cargo.toml +++ b/pumpkin-core/Cargo.toml @@ -4,7 +4,7 @@ version.workspace = true edition.workspace = true [dependencies] -serde = { version = "1.0", features = ["derive"] } +serde.workspace = true fastnbt = { git = "https://github.com/owengage/fastnbt.git" } uuid.workspace = true colored = "2" diff --git a/pumpkin-plugin/Cargo.toml b/pumpkin-plugin/Cargo.toml index e757c6539..558ce3b4c 100644 --- a/pumpkin-plugin/Cargo.toml +++ b/pumpkin-plugin/Cargo.toml @@ -6,4 +6,4 @@ edition.workspace = true [dependencies] extism = "1.5.0" log.workspace = true -serde ={ version = "1.0.209", features = ["derive"] } \ No newline at end of file +serde.workspace = true diff --git a/pumpkin-protocol/Cargo.toml b/pumpkin-protocol/Cargo.toml index e87e51557..b9d59e16f 100644 --- a/pumpkin-protocol/Cargo.toml +++ b/pumpkin-protocol/Cargo.toml @@ -12,7 +12,7 @@ bytes = "1.7" uuid.workspace = true -serde = { version = "1.0", features = ["derive"] } +serde.workspace = true # to parse strings to json responses serde_json = "1.0" diff --git a/pumpkin-registry/Cargo.toml b/pumpkin-registry/Cargo.toml index f1e53cba3..8ba0b9457 100644 --- a/pumpkin-registry/Cargo.toml +++ b/pumpkin-registry/Cargo.toml @@ -11,4 +11,4 @@ pumpkin-core = { path = "../pumpkin-core"} fastnbt = { git = "https://github.com/owengage/fastnbt.git" } fastsnbt = "0.2" -serde = { version = "1.0", features = ["derive"] } +serde.workspace = true diff --git a/pumpkin-world/Cargo.toml b/pumpkin-world/Cargo.toml index 4008eaa84..687c60b58 100644 --- a/pumpkin-world/Cargo.toml +++ b/pumpkin-world/Cargo.toml @@ -14,7 +14,7 @@ itertools = "0.13.0" thiserror = "1.0.63" futures = "0.3.30" flate2 = "1.0.33" -serde = { version = "1.0", features = ["derive"] } +serde.workspace = true lazy_static = "1.5.0" serde_json = "1.0" static_assertions = "1.1.0" diff --git a/pumpkin/Cargo.toml b/pumpkin/Cargo.toml index 0494fc462..ef2d4371f 100644 --- a/pumpkin/Cargo.toml +++ b/pumpkin/Cargo.toml @@ -18,7 +18,7 @@ pumpkin-protocol = { path = "../pumpkin-protocol"} pumpkin-registry = { path = "../pumpkin-registry"} # config -serde = { version = "1.0", features = ["derive"] } +serde.workspace = true serde_json = "1.0" toml = "0.8.19"