Compare commits
3 Commits
d641610fbf
...
d592c74654
| Author | SHA1 | Date | |
|---|---|---|---|
| d592c74654 | |||
| d5bc1bed11 | |||
| cef372377b |
53
Cargo.lock
generated
53
Cargo.lock
generated
@ -136,6 +136,12 @@ version = "1.5.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
|
checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "base64"
|
||||||
|
version = "0.22.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bincode"
|
name = "bincode"
|
||||||
version = "1.3.3"
|
version = "1.3.3"
|
||||||
@ -1214,9 +1220,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "js-sys"
|
name = "js-sys"
|
||||||
version = "0.3.83"
|
version = "0.3.81"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "464a3709c7f55f1f721e5389aa6ea4e3bc6aba669353300af094b29ffbdde1d8"
|
checksum = "ec48937a97411dcb524a265206ccd4c90bb711fca92b2792c407f268825b9305"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
@ -2910,9 +2916,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasm-bindgen"
|
name = "wasm-bindgen"
|
||||||
version = "0.2.106"
|
version = "0.2.104"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0d759f433fa64a2d763d1340820e46e111a7a5ab75f993d1852d70b03dbb80fd"
|
checksum = "c1da10c01ae9f1ae40cbfac0bac3b1e724b320abfcf52229f80b547c0d250e2d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
@ -2922,10 +2928,24 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasm-bindgen-futures"
|
name = "wasm-bindgen-backend"
|
||||||
version = "0.4.56"
|
version = "0.2.104"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "836d9622d604feee9e5de25ac10e3ea5f2d65b41eac0d9ce72eb5deae707ce7c"
|
checksum = "671c9a5a66f49d8a47345ab942e2cb93c7d1d0339065d4f8139c486121b43b19"
|
||||||
|
dependencies = [
|
||||||
|
"bumpalo",
|
||||||
|
"log",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
"wasm-bindgen-shared",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasm-bindgen-futures"
|
||||||
|
version = "0.4.54"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7e038d41e478cc73bae0ff9b36c60cff1c98b8f38f8d7e8061e79ee63608ac5c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"js-sys",
|
"js-sys",
|
||||||
@ -2936,9 +2956,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasm-bindgen-macro"
|
name = "wasm-bindgen-macro"
|
||||||
version = "0.2.106"
|
version = "0.2.104"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "48cb0d2638f8baedbc542ed444afc0644a29166f1595371af4fecf8ce1e7eeb3"
|
checksum = "7ca60477e4c59f5f2986c50191cd972e3a50d8a95603bc9434501cf156a9a119"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"quote",
|
"quote",
|
||||||
"wasm-bindgen-macro-support",
|
"wasm-bindgen-macro-support",
|
||||||
@ -2946,22 +2966,22 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasm-bindgen-macro-support"
|
name = "wasm-bindgen-macro-support"
|
||||||
version = "0.2.106"
|
version = "0.2.104"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "cefb59d5cd5f92d9dcf80e4683949f15ca4b511f4ac0a6e14d4e1ac60c6ecd40"
|
checksum = "9f07d2f20d4da7b26400c9f4a0511e6e0345b040694e8a75bd41d578fa4421d7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bumpalo",
|
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn",
|
||||||
|
"wasm-bindgen-backend",
|
||||||
"wasm-bindgen-shared",
|
"wasm-bindgen-shared",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasm-bindgen-shared"
|
name = "wasm-bindgen-shared"
|
||||||
version = "0.2.106"
|
version = "0.2.104"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "cbc538057e648b67f72a982e708d485b2efa771e1ac05fec311f9f63e5800db4"
|
checksum = "bad67dc8b2a1a6e5448428adec4c3e84c43e561d8c9ee8a9e5aabeb193ec41d1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
@ -3090,9 +3110,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "web-sys"
|
name = "web-sys"
|
||||||
version = "0.3.83"
|
version = "0.3.81"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9b32828d774c412041098d182a8b38b16ea816958e07cf40eec2bc080ae137ac"
|
checksum = "9367c417a924a74cae129e6a2ae3b47fabb1f8995595ab474029da749a8be120"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"js-sys",
|
"js-sys",
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
@ -3680,6 +3700,7 @@ dependencies = [
|
|||||||
name = "ytbn_graphing_software"
|
name = "ytbn_graphing_software"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"base64",
|
||||||
"bincode",
|
"bincode",
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"const_format",
|
"const_format",
|
||||||
|
|||||||
@ -57,6 +57,7 @@ static_assertions = "1.1"
|
|||||||
bincode = "1.3"
|
bincode = "1.3"
|
||||||
serde = "1"
|
serde = "1"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
|
base64 = "0.22"
|
||||||
|
|
||||||
# Note: benchmarks are in a separate crate - run with:
|
# Note: benchmarks are in a separate crate - run with:
|
||||||
# cd benchmarks && cargo bench
|
# cd benchmarks && cargo bench
|
||||||
@ -89,7 +90,8 @@ wasm-bindgen = { version = "0.2", default-features = false, features = ["std"] }
|
|||||||
web-sys = "0.3"
|
web-sys = "0.3"
|
||||||
tracing-wasm = "0.2"
|
tracing-wasm = "0.2"
|
||||||
getrandom = { version = "0.3", features = ["wasm_js"] }
|
getrandom = { version = "0.3", features = ["wasm_js"] }
|
||||||
wasm-bindgen-futures = "0.4"
|
# pinned to 0.4.54 because nix provides up to 0.2.104 wasm-bindgen-cli
|
||||||
|
wasm-bindgen-futures = "=0.4.54"
|
||||||
|
|
||||||
[package.metadata.cargo-all-features]
|
[package.metadata.cargo-all-features]
|
||||||
skip_optional_dependencies = true #don't test optional dependencies, only features
|
skip_optional_dependencies = true #don't test optional dependencies, only features
|
||||||
|
|||||||
8
flake.lock
generated
8
flake.lock
generated
@ -65,17 +65,17 @@
|
|||||||
"simon-egui": {
|
"simon-egui": {
|
||||||
"flake": false,
|
"flake": false,
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1764730109,
|
"lastModified": 1764740756,
|
||||||
"narHash": "sha256-vNETC0oq6tKJKF8KOGQKKIWRom38m0RwGgi3MPBrRx8=",
|
"narHash": "sha256-CX0v82hDmLSEx5uFViWvfJaeADFJKR0G+MJYFFQcxng=",
|
||||||
"owner": "Titaniumtown",
|
"owner": "Titaniumtown",
|
||||||
"repo": "egui",
|
"repo": "egui",
|
||||||
"rev": "b63c21d70150f1b414370f0f9a8af56e886662f4",
|
"rev": "217d3f250c499ae88c02930b26cacb945c4a2369",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"owner": "Titaniumtown",
|
"owner": "Titaniumtown",
|
||||||
"repo": "egui",
|
"repo": "egui",
|
||||||
"rev": "b63c21d70150f1b414370f0f9a8af56e886662f4",
|
"rev": "217d3f250c499ae88c02930b26cacb945c4a2369",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
61
flake.nix
61
flake.nix
@ -9,13 +9,21 @@
|
|||||||
inputs.nixpkgs.follows = "nixpkgs";
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
};
|
};
|
||||||
simon-egui = {
|
simon-egui = {
|
||||||
url = "github:Titaniumtown/egui/b63c21d70150f1b414370f0f9a8af56e886662f4";
|
url = "github:Titaniumtown/egui/217d3f250c499ae88c02930b26cacb945c4a2369";
|
||||||
flake = false;
|
flake = false;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = { self, nixpkgs, flake-utils, rust-overlay, simon-egui }:
|
outputs =
|
||||||
flake-utils.lib.eachDefaultSystem (system:
|
{
|
||||||
|
self,
|
||||||
|
nixpkgs,
|
||||||
|
flake-utils,
|
||||||
|
rust-overlay,
|
||||||
|
simon-egui,
|
||||||
|
}:
|
||||||
|
flake-utils.lib.eachDefaultSystem (
|
||||||
|
system:
|
||||||
let
|
let
|
||||||
overlays = [ (import rust-overlay) ];
|
overlays = [ (import rust-overlay) ];
|
||||||
pkgs = import nixpkgs {
|
pkgs = import nixpkgs {
|
||||||
@ -23,7 +31,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
# Use nightly rust with wasm32 target
|
# Use nightly rust with wasm32 target
|
||||||
rustToolchain = pkgs.rust-bin.nightly."2025-05-01".default.override {
|
rustToolchain = pkgs.rust-bin.stable.latest.default.override {
|
||||||
targets = [ "wasm32-unknown-unknown" ];
|
targets = [ "wasm32-unknown-unknown" ];
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -32,28 +40,6 @@
|
|||||||
rustc = rustToolchain;
|
rustc = rustToolchain;
|
||||||
};
|
};
|
||||||
|
|
||||||
# Build wasm-bindgen-cli matching the version in Cargo.lock (0.2.106)
|
|
||||||
wasm-bindgen-cli = rustPlatform.buildRustPackage rec {
|
|
||||||
pname = "wasm-bindgen-cli";
|
|
||||||
version = "0.2.106";
|
|
||||||
|
|
||||||
src = pkgs.fetchCrate {
|
|
||||||
inherit pname version;
|
|
||||||
hash = "sha256-M6WuGl7EruNopHZbqBpucu4RWz44/MSdv6f0zkYw+44=";
|
|
||||||
};
|
|
||||||
|
|
||||||
cargoHash = "sha256-ElDatyOwdKwHg3bNH/1pcxKI7LXkhsotlDPQjiLHBwA=";
|
|
||||||
|
|
||||||
nativeBuildInputs = [ pkgs.pkg-config ];
|
|
||||||
buildInputs = [ pkgs.openssl ] ++ pkgs.lib.optionals pkgs.stdenv.isDarwin [
|
|
||||||
pkgs.curl
|
|
||||||
pkgs.darwin.apple_sdk.frameworks.Security
|
|
||||||
];
|
|
||||||
|
|
||||||
# Tests require network access
|
|
||||||
doCheck = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
# Create a combined source with the main project and dependencies
|
# Create a combined source with the main project and dependencies
|
||||||
combinedSrc = pkgs.stdenv.mkDerivation {
|
combinedSrc = pkgs.stdenv.mkDerivation {
|
||||||
name = "ytbn-combined-src";
|
name = "ytbn-combined-src";
|
||||||
@ -125,9 +111,9 @@
|
|||||||
|
|
||||||
src = ./.;
|
src = ./.;
|
||||||
|
|
||||||
nativeBuildInputs = [
|
nativeBuildInputs = with pkgs; [
|
||||||
wasm-bindgen-cli
|
wasm-bindgen-cli
|
||||||
pkgs.binaryen
|
binaryen
|
||||||
];
|
];
|
||||||
|
|
||||||
buildPhase = ''
|
buildPhase = ''
|
||||||
@ -211,14 +197,17 @@
|
|||||||
zstd
|
zstd
|
||||||
];
|
];
|
||||||
|
|
||||||
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath (with pkgs; [
|
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath (
|
||||||
libxkbcommon
|
with pkgs;
|
||||||
libGL
|
[
|
||||||
wayland
|
libxkbcommon
|
||||||
xorg.libX11
|
libGL
|
||||||
xorg.libXcursor
|
wayland
|
||||||
xorg.libXi
|
xorg.libX11
|
||||||
]);
|
xorg.libXcursor
|
||||||
|
xorg.libXi
|
||||||
|
]
|
||||||
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@ -1,8 +1,5 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
consts::COLORS,
|
consts::COLORS, function_entry::FunctionEntry, misc::random_u64, widgets::widgets_ontop,
|
||||||
function_entry::FunctionEntry,
|
|
||||||
misc::{create_id, get_u64_id, random_u64},
|
|
||||||
widgets::widgets_ontop,
|
|
||||||
};
|
};
|
||||||
use egui::{Button, Id, Key, Modifiers, Popup, TextEdit, WidgetText};
|
use egui::{Button, Id, Key, Modifiers, Popup, TextEdit, WidgetText};
|
||||||
use emath::vec2;
|
use emath::vec2;
|
||||||
@ -22,7 +19,7 @@ impl Default for FunctionManager {
|
|||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
let mut vec: Functions = Vec::with_capacity(COLORS.len());
|
let mut vec: Functions = Vec::with_capacity(COLORS.len());
|
||||||
vec.push((
|
vec.push((
|
||||||
create_id(11414819524356497634), // Random number here to avoid call to crate::misc::random_u64()
|
Id::NULL.with(11414819524356497634_u64), // Random number here to avoid call to crate::misc::random_u64()
|
||||||
FunctionEntry::default(),
|
FunctionEntry::default(),
|
||||||
));
|
));
|
||||||
Self { functions: vec }
|
Self { functions: vec }
|
||||||
@ -40,8 +37,8 @@ impl Serialize for FunctionManager {
|
|||||||
&self
|
&self
|
||||||
.functions
|
.functions
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(id, func)| (get_u64_id(*id), func.clone()))
|
.map(|(id, func)| (*id, func.clone()))
|
||||||
.collect::<Vec<(u64, FunctionEntry)>>(),
|
.collect::<Vec<(Id, FunctionEntry)>>(),
|
||||||
)?;
|
)?;
|
||||||
s.end()
|
s.end()
|
||||||
}
|
}
|
||||||
@ -53,17 +50,12 @@ impl<'de> Deserialize<'de> for FunctionManager {
|
|||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
{
|
{
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct Helper(Vec<(u64, FunctionEntry)>);
|
struct Helper(Vec<(Id, FunctionEntry)>);
|
||||||
|
|
||||||
let helper = Helper::deserialize(deserializer)?;
|
let helper = Helper::deserialize(deserializer)?;
|
||||||
|
|
||||||
Ok(FunctionManager {
|
Ok(FunctionManager {
|
||||||
functions: helper
|
functions: helper.0.to_vec(),
|
||||||
.0
|
|
||||||
.iter()
|
|
||||||
.cloned()
|
|
||||||
.map(|(id, func)| (create_id(id), func))
|
|
||||||
.collect::<Vec<(Id, FunctionEntry)>>(),
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -204,7 +196,7 @@ impl FunctionManager {
|
|||||||
const BUTTONS_Y_OFFSET: f32 = 1.32;
|
const BUTTONS_Y_OFFSET: f32 = 1.32;
|
||||||
const Y_OFFSET: f32 = crate::consts::FONT_SIZE * BUTTONS_Y_OFFSET;
|
const Y_OFFSET: f32 = crate::consts::FONT_SIZE * BUTTONS_Y_OFFSET;
|
||||||
|
|
||||||
widgets_ontop(ui, create_id(i as u64), &re, Y_OFFSET, |ui| {
|
widgets_ontop(ui, Id::NULL.with(i), &re, Y_OFFSET, |ui| {
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
// There's more than 1 function! Functions can now be deleted
|
// There's more than 1 function! Functions can now be deleted
|
||||||
if ui
|
if ui
|
||||||
@ -327,7 +319,7 @@ impl FunctionManager {
|
|||||||
/// Create and push new empty function entry
|
/// Create and push new empty function entry
|
||||||
pub fn push_empty(&mut self) {
|
pub fn push_empty(&mut self) {
|
||||||
self.functions.push((
|
self.functions.push((
|
||||||
create_id(random_u64().expect("unable to generate random id")),
|
Id::NULL.with(random_u64().expect("unable to generate random id")),
|
||||||
FunctionEntry::default(),
|
FunctionEntry::default(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -337,7 +329,7 @@ impl FunctionManager {
|
|||||||
// Reset settings_opened so the cloned function doesn't have settings open
|
// Reset settings_opened so the cloned function doesn't have settings open
|
||||||
entry.settings_opened = false;
|
entry.settings_opened = false;
|
||||||
self.functions.push((
|
self.functions.push((
|
||||||
create_id(random_u64().expect("unable to generate random id")),
|
Id::NULL.with(random_u64().expect("unable to generate random id")),
|
||||||
entry,
|
entry,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -176,6 +176,7 @@ impl MathApp {
|
|||||||
|
|
||||||
// TODO: stabilize FunctionManager serialize so it can persist across builds
|
// TODO: stabilize FunctionManager serialize so it can persist across builds
|
||||||
let (commit, func_data) = crate::misc::hashed_storage_read(&data)?;
|
let (commit, func_data) = crate::misc::hashed_storage_read(&data)?;
|
||||||
|
let func_data: &[u8] = &func_data;
|
||||||
|
|
||||||
|
|
||||||
if commit == unsafe { std::mem::transmute::<&str, &[u8]>(build::SHORT_COMMIT) } {
|
if commit == unsafe { std::mem::transmute::<&str, &[u8]>(build::SHORT_COMMIT) } {
|
||||||
|
|||||||
32
src/misc.rs
32
src/misc.rs
@ -1,4 +1,3 @@
|
|||||||
use egui::Id;
|
|
||||||
use egui_plot::{Line, PlotPoint, PlotPoints, Points};
|
use egui_plot::{Line, PlotPoint, PlotPoints, Points};
|
||||||
use emath::Pos2;
|
use emath::Pos2;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
@ -62,14 +61,6 @@ impl Offset for Pos2 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const fn create_id(x: u64) -> Id {
|
|
||||||
unsafe { std::mem::transmute::<u64, Id>(x) }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub const fn get_u64_id(id: Id) -> u64 {
|
|
||||||
unsafe { std::mem::transmute::<Id, u64>(id) }
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
/// Rounds f64 to `n` decimal places
|
/// Rounds f64 to `n` decimal places
|
||||||
pub fn decimal_round(x: f64, n: usize) -> f64 {
|
pub fn decimal_round(x: f64, n: usize) -> f64 {
|
||||||
@ -179,24 +170,27 @@ pub type HashBytes = [u8; HASH_LENGTH];
|
|||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn hashed_storage_create(hashbytes: HashBytes, data: &[u8]) -> String {
|
pub fn hashed_storage_create(hashbytes: HashBytes, data: &[u8]) -> String {
|
||||||
unsafe { std::mem::transmute::<Vec<u8>, String>([hashbytes.to_vec(), data.to_vec()].concat()) }
|
// Use base64 encoding to safely store binary data in localStorage
|
||||||
|
let combined: Vec<u8> = [hashbytes.to_vec(), data.to_vec()].concat();
|
||||||
|
base64::encode(combined)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn hashed_storage_read(data: &str) -> Option<(HashBytes, &[u8])> {
|
pub fn hashed_storage_read(data: &str) -> Option<(HashBytes, Vec<u8>)> {
|
||||||
|
// Decode base64 data
|
||||||
|
let decoded = base64::decode(data).ok()?;
|
||||||
|
|
||||||
// Make sure data is long enough to decode
|
// Make sure data is long enough to decode
|
||||||
if HASH_LENGTH >= data.len() {
|
if HASH_LENGTH >= decoded.len() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transmute data into slice
|
// Extract hash and data
|
||||||
let decoded_1: &[u8] = unsafe { std::mem::transmute::<&str, &[u8]>(data) };
|
let mut hash: HashBytes = [0u8; HASH_LENGTH];
|
||||||
|
hash.copy_from_slice(&decoded[..HASH_LENGTH]);
|
||||||
|
let data_part = decoded[HASH_LENGTH..].to_vec();
|
||||||
|
|
||||||
// Return hash and decoded data
|
Some((hash, data_part))
|
||||||
Some((
|
|
||||||
unsafe { *(decoded_1[..HASH_LENGTH].as_ptr() as *const HashBytes) },
|
|
||||||
&decoded_1[HASH_LENGTH..],
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates and returns random u64
|
/// Creates and returns random u64
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user