Skip to content

Commit

Permalink
support gzip coding in the controlplane meta
Browse files Browse the repository at this point in the history
  • Loading branch information
sehz committed Oct 1, 2022
1 parent cb847c3 commit 8e9680c
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 15 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/fluvio-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ fluvio-smartmodule-package = { path = "../fluvio-smartmodule-package" }
fluvio-smartengine = { path = "../fluvio-smartengine", optional = true }
fluvio-protocol = { path = "../fluvio-protocol", features=["record","api"] }
fluvio-smartmodule = { path = "../fluvio-smartmodule", default-features = false }
fluvio-controlplane-metadata = { path = "../fluvio-controlplane-metadata", features = ["smartmodule"] }

# Optional Fluvio dependencies
fluvio-types = { path = "../fluvio-types", optional = true }
Expand Down
12 changes: 4 additions & 8 deletions crates/fluvio-cli/src/client/smartmodule/create.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::collections::BTreeMap;
use std::path::PathBuf;
use std::io::Read;
use std::fmt::Debug;
use std::sync::Arc;

Expand All @@ -11,8 +10,7 @@ use tracing::debug;
use clap::Parser;

use fluvio::Fluvio;
use fluvio::metadata::smartmodule::{SmartModuleWasm, SmartModuleSpec};
use flate2::{Compression, bufread::GzEncoder};
use fluvio_controlplane_metadata::smartmodule::{SmartModuleWasm, SmartModuleSpec};
use fluvio_smartmodule_package::package::{SmartModuleMetadata, InitType};

use crate::Result;
Expand Down Expand Up @@ -41,10 +39,6 @@ impl ClientCmd for CreateSmartModuleOpt {
_out: Arc<O>,
fluvio: &Fluvio,
) -> Result<()> {
let raw = std::fs::read(self.wasm_file)?;
let mut encoder = GzEncoder::new(raw.as_slice(), Compression::default());
let mut buffer = Vec::with_capacity(raw.len());
encoder.read_to_end(&mut buffer)?;
/*
* TODO: Fix the CRD to work with this
let buffer = vec!['a' as u8; self.size];
Expand Down Expand Up @@ -78,8 +72,10 @@ impl ClientCmd for CreateSmartModuleOpt {
(None, BTreeMap::new())
};

let raw = std::fs::read(self.wasm_file)?;

let spec: SmartModuleSpec = SmartModuleSpec {
wasm: SmartModuleWasm::from_compressed_gzip(buffer),
wasm: SmartModuleWasm::from_raw_wasm_bytes(&raw)?,
package: package_opt.0,
init_params: package_opt.1,
..Default::default()
Expand Down
5 changes: 1 addition & 4 deletions crates/fluvio-controlplane-metadata/src/smartmodule/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ impl std::fmt::Debug for SmartModuleWasm {
}

impl SmartModuleWasm {

/// Create SmartModule from compressed Gzip format
pub fn from_compressed_gzip(payload: Vec<u8>) -> Self {
SmartModuleWasm {
Expand All @@ -143,10 +142,9 @@ impl SmartModuleWasm {
}
}

#[cfg(feature="smartmodule")]
#[cfg(feature = "smartmodule")]
/// Create SmartModule from uncompressed Wasm format
pub fn from_raw_wasm_bytes(raw_payload: &[u8]) -> std::io::Result<Self> {

use std::io::Read;
use flate2::{Compression, bufread::GzEncoder};

Expand All @@ -158,7 +156,6 @@ impl SmartModuleWasm {
}
}


#[cfg(feature = "use_serde")]
mod base64 {
use serde::{Serialize, Deserialize};
Expand Down
5 changes: 2 additions & 3 deletions crates/smdk/src/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ pub struct LoadOpt {
}
impl LoadOpt {
pub(crate) fn process(&self) -> Result<()> {

/*
/*
let mut encoder = GzEncoder::new(raw.as_slice(), Compression::default());
let mut buffer = Vec::with_capacity(raw.len());
encoder.read_to_end(&mut buffer)?;
Expand All @@ -30,7 +29,7 @@ impl LoadOpt {
};
let wasm = SmartModuleWasm::new(self.wasm.wasm_file.clone())?;
*/

Ok(())
}
}

0 comments on commit 8e9680c

Please sign in to comment.