Skip to content
Merged
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
4 changes: 2 additions & 2 deletions src/headlenpow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fn decimal(s: &str) -> Option<u64> {
fn slack_count(s: &str, body: &[u8]) -> Option<u64> {
match s {
"char/utf8" => Some(std::str::from_utf8(body).ok()?.chars().count() as u64),
"byte" => Some(body.len() as u64),
"uint8" => Some(body.len() as u64),
"char/ascii" if body.is_ascii() => Some(body.len() as u64),
"char/utf32" if body.len() % 4 == 0 => {
for chunk in body.chunks_exact(4) {
Expand Down Expand Up @@ -241,7 +241,7 @@ pub fn reserve(flags: u8, langtype: &str, content: usize, cap: usize) -> Option<
|| decimal(&langtype[1..end]).is_none()
|| !matches!(
&langtype[end + 1..],
"char/utf8" | "byte" | "char/utf32" | "char/ascii"
"char/utf8" | "uint8" | "char/utf32" | "char/ascii"
)
{
return None;
Expand Down
4 changes: 2 additions & 2 deletions src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub fn encode(ro: bool, vid: u32) -> Option<Vec<u8>> {
let mut body = [0u8; 5];
body[0] = u8::from(ro);
body[1..].copy_from_slice(&vid.to_le_bytes());
headlenpow::encode(6, 1, 5, 5, "[5]byte", &body, 5)
headlenpow::encode(6, 1, 5, 5, "[5]uint8", &body, 5)
}

pub fn decode(data: &[u8]) -> Option<(bool, u32)> {
Expand All @@ -49,7 +49,7 @@ pub fn decode(data: &[u8]) -> Option<(bool, u32)> {
|| h.flags != 1
|| h.a != 5
|| h.b != 5
|| h.langtype != "[5]byte"
|| h.langtype != "[5]uint8"
|| h.body[0] > 1
{
return None;
Expand Down
3 changes: 1 addition & 2 deletions src/xvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ pub fn encode_head(kind: &str, r#ref: i32, dims: &[i32], raw: &[u8]) -> Vec<u8>
return Vec::new();
} else if kind.is_empty() || kind == "None" {
(5, 0, 0, 0, String::new())
} else if matches!(kind, "char/utf8" | "char/ascii" | "char/utf32" | "byte") {
} else if matches!(kind, "char/utf8" | "char/ascii" | "char/utf32") {
let count = match kind {
"char/utf8" => std::str::from_utf8(raw).ok().map(|s| s.chars().count()),
"char/ascii" if raw.is_ascii() => Some(raw.len()),
Expand All @@ -434,7 +434,6 @@ pub fn encode_head(kind: &str, r#ref: i32, dims: &[i32], raw: &[u8]) -> Vec<u8>
{
Some(raw.len() / 4)
}
"byte" => Some(raw.len()),
_ => None,
};
let Some(count) = count else {
Expand Down
Loading