Switch const serialize to use CBOR (#4932)
* implement const cbor encoding + decoding for basic types * implement map encoding and decoding * fix map test * all tests passing * dynamically sized arrays * smaller str encoding * swap array and list and add more documentation * move serialization and deserialization for each struct together * support both legacy and new assets * bump const serialize version * fix asset conversion code * pull out manganis symbol struct from tuble * test reading old asset versions * more list/array cleanup and bump rust version * fix clippy * switch cli opt port * install playwright deps * split cli-optimization package to avoid two dioxus' in the same crate * fix clippy * force the toast.png asset to be included in the linker stage #[used] has platform depedant behavior * bundle both formats in the link section and only use the asset the cli changed * remove sudo which doesn't exist on windows * add binstall to the playwright workflow * separate bin target for the old cli * lockfile * cargo update to get versions shaken out * notes on binstalls, add back `.read()` for compat * use 0.8.0-alpha.0 for const-serialize instead of 0.8 this ensures we can still publish breaking changes on 0.8 without taking over the full version * fix clippy in example * small debug nits * update rust-overlay in nix * fix flake? * migrate to new structure * just comment out binstalls * just remove old test harness --------- Co-authored-by: Jonathan Kelley <jkelleyrtp@gmail.com>
This commit is contained in:
1 parent
c68a47b2d3
commit
c977cc125e
48 files changed
+3386
-2007
No files matched your search
@@ -14,6 +14,7 @@ keywords = ["assets"]
|
||||
|
||||
[dependencies]
|
||||
const-serialize = { workspace = true }
|
||||
const-serialize-07 = { workspace = true }
|
||||
manganis-core = { workspace = true }
|
||||
manganis-macro = { workspace = true }
|
||||
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
pub use const_serialize;
|
||||
use const_serialize::{serialize_const, ConstVec, SerializeConst};
|
||||
pub use const_serialize_07;
|
||||
use const_serialize_07::{
|
||||
serialize_const as serialize_const_07, ConstVec as ConstVec07,
|
||||
SerializeConst as SerializeConst07,
|
||||
};
|
||||
use manganis_core::{AssetOptions, BundledAsset};
|
||||
|
||||
const PLACEHOLDER_HASH: &str = "This should be replaced by dx as part of the build process. If you see this error, make sure you are using a matching version of dx and dioxus and you are not stripping symbols from your binary.";
|
||||
|
||||
/// Create a bundled asset from the input path, the content hash, and the asset options
|
||||
pub const fn create_bundled_asset(input_path: &str, asset_config: AssetOptions) -> BundledAsset {
|
||||
BundledAsset::new(input_path, PLACEHOLDER_HASH, asset_config)
|
||||
BundledAsset::new(input_path, BundledAsset::PLACEHOLDER_HASH, asset_config)
|
||||
}
|
||||
|
||||
/// Create a bundled asset from the input path, the content hash, and the asset options with a relative asset deprecation warning
|
||||
@@ -27,7 +30,18 @@ pub const fn serialize_asset(asset: &BundledAsset) -> ConstVec<u8> {
|
||||
let data = ConstVec::new();
|
||||
let mut data = serialize_const(asset, data);
|
||||
// Reserve the maximum size of the asset
|
||||
while data.len() < BundledAsset::MEMORY_LAYOUT.size() {
|
||||
while data.len() < <BundledAsset as SerializeConst>::MEMORY_LAYOUT.size() {
|
||||
data = data.push(0);
|
||||
}
|
||||
data
|
||||
}
|
||||
|
||||
/// Serialize an asset to a const buffer in the legacy 0.7 format
|
||||
pub const fn serialize_asset_07(asset: &BundledAsset) -> ConstVec07<u8> {
|
||||
let data = ConstVec07::new();
|
||||
let mut data = serialize_const_07(asset, data);
|
||||
// Reserve the maximum size of the asset
|
||||
while data.len() < <BundledAsset as SerializeConst07>::MEMORY_LAYOUT.size() {
|
||||
data = data.push(0);
|
||||
}
|
||||
data
|
||||
@@ -35,8 +49,7 @@ pub const fn serialize_asset(asset: &BundledAsset) -> ConstVec<u8> {
|
||||
|
||||
/// Deserialize a const buffer into a BundledAsset
|
||||
pub const fn deserialize_asset(bytes: &[u8]) -> BundledAsset {
|
||||
let bytes = ConstVec::new().extend(bytes);
|
||||
match const_serialize::deserialize_const!(BundledAsset, bytes.read()) {
|
||||
match const_serialize::deserialize_const!(BundledAsset, bytes) {
|
||||
Some((_, asset)) => asset,
|
||||
None => panic!("Failed to deserialize asset. This may be caused by a mismatch between your dioxus and dioxus-cli versions"),
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user