Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ members = [
"packages/signals",
"packages/stores",
"packages/stores-macro",
"packages/dioxus-const-vec",
"packages/const-serialize",
"packages/const-serialize-macro",
"packages/dx-wire-format",
Expand Down Expand Up @@ -181,6 +182,7 @@ manganis-core = { path = "packages/manganis/manganis-core", version = "0.8.0-alp
manganis-macro = { path = "packages/manganis/manganis-macro", version = "0.8.0-alpha.0" }

# const-serialize
dioxus-const-vec = { path = "packages/dioxus-const-vec", version = "0.8.0-alpha.0" }
const-serialize = { path = "packages/const-serialize", version = "0.8.0-alpha.0" }
const-serialize-macro = { path = "packages/const-serialize-macro", version = "0.8.0-alpha.0" }

Expand Down
1 change: 1 addition & 0 deletions packages/const-serialize/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ keywords = ["const", "serialize"]
rust-version = "1.85.0"

[dependencies]
dioxus-const-vec = { workspace = true }
const-serialize-macro = { workspace = true }
serde = { workspace = true, features = ["derive"], optional = true }

Expand Down
19 changes: 11 additions & 8 deletions packages/const-serialize/src/cbor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ pub(crate) const fn write_number<const MAX_SIZE: usize>(
/// contains both the major type and the additional information which contains
/// either the number itself or the number of extra bytes the number occupies.
const fn write_major_type_and_u64<const MAX_SIZE: usize>(
vec: ConstVec<u8, MAX_SIZE>,
mut vec: ConstVec<u8, MAX_SIZE>,
major: MajorType,
number: u64,
) -> ConstVec<u8, MAX_SIZE> {
Expand All @@ -167,18 +167,19 @@ const fn write_major_type_and_u64<const MAX_SIZE: usize>(
0..24 => {
let additional_information = number as u8;
let byte = major | additional_information;
vec.push(byte)
vec.push(byte);
vec
}
// For larger numbers, store the number of extra bytes the number occupies
24.. => {
let log2_additional_bytes = log2_bytes_for_number(number);
let additional_bytes = 1 << log2_additional_bytes;
let additional_information = log2_additional_bytes + 24;
let byte = major | additional_information;
let mut vec = vec.push(byte);
vec.push(byte);
let mut byte = 0;
while byte < additional_bytes {
vec = vec.push((number >> ((additional_bytes - byte - 1) * 8)) as u8);
vec.push((number >> ((additional_bytes - byte - 1) * 8)) as u8);
byte += 1;
}
vec
Expand Down Expand Up @@ -218,8 +219,9 @@ pub(crate) const fn write_bytes<const MAX_SIZE: usize>(
vec: ConstVec<u8, MAX_SIZE>,
bytes: &[u8],
) -> ConstVec<u8, MAX_SIZE> {
let vec = write_major_type_and_u64(vec, MajorType::Bytes, bytes.len() as u64);
vec.extend(bytes)
let mut vec = write_major_type_and_u64(vec, MajorType::Bytes, bytes.len() as u64);
vec.extend(bytes);
vec
}

/// Take a string from a buffer and return the string and the remaining buffer.
Expand Down Expand Up @@ -247,8 +249,9 @@ pub(crate) const fn write_str<const MAX_SIZE: usize>(
vec: ConstVec<u8, MAX_SIZE>,
string: &str,
) -> ConstVec<u8, MAX_SIZE> {
let vec = write_major_type_and_u64(vec, MajorType::Text, string.len() as u64);
vec.extend(string.as_bytes())
let mut vec = write_major_type_and_u64(vec, MajorType::Text, string.len() as u64);
vec.extend(string.as_bytes());
vec
}

/// Take the length and header of an array from a buffer and return the length and the remaining buffer.
Expand Down
38 changes: 0 additions & 38 deletions packages/const-serialize/src/const_buffers.rs

This file was deleted.

Loading
Loading