From 91e185df0b0a3204c9414bcf7ece14b977a220f3 Mon Sep 17 00:00:00 2001 From: Artemy Egorov Date: Mon, 5 Aug 2024 19:16:27 +0300 Subject: [PATCH] fix: update daletpack spec impl --- src/daletpack/encode.rs | 13 ++----------- src/daletpack/types.rs | 9 ++++----- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/daletpack/encode.rs b/src/daletpack/encode.rs index 4051214..44c52a6 100644 --- a/src/daletpack/encode.rs +++ b/src/daletpack/encode.rs @@ -33,18 +33,9 @@ fn write_str(bv: &mut Vec, string: &String) -> Result<(), DaletPackError> { return Err(DaletPackError::StrMaxSizeExceeded); } - if size <= 256 { - bv.push(TypeId::Str8 as u8); - bv.push((size - 1) as u8); - } else if size <= 65536 { - bv.push(TypeId::Str16 as u8); - bv.extend(((size - 1) as u16).to_be_bytes()); - } else { - bv.push(TypeId::Str32 as u8); - bv.extend(((size - 1) as u32).to_be_bytes()); - } - + bv.push(TypeId::Str as u8); bv.extend_from_slice(string.as_bytes()); + bv.push(TypeId::StrEnd as u8); Ok(()) } diff --git a/src/daletpack/types.rs b/src/daletpack/types.rs index c6fc344..e87ea4d 100644 --- a/src/daletpack/types.rs +++ b/src/daletpack/types.rs @@ -14,13 +14,12 @@ pub enum DaletPackError { #[derive(Debug, Clone, PartialEq, Eq, TryFromPrimitive, Copy)] #[repr(u8)] pub enum TypeId { - Int8 = 1, - Str8 = 4, - Str16, - Str32, + StrEnd = 0, + Str, + Int8, TagArray, TagArrayEnd, - TagId = 12, + TagId, TagIdBody, TagIdArgument, TagIdBodyArgument,