From 5a03e7fa3a562fbc4274719bc65868c128916a86 Mon Sep 17 00:00:00 2001 From: Zixuan Chen Date: Wed, 21 Aug 2024 12:02:35 +0800 Subject: [PATCH] fix: issue when getting container value --- crates/loro-internal/src/state/container_store.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/crates/loro-internal/src/state/container_store.rs b/crates/loro-internal/src/state/container_store.rs index 0a5b1312..2e848921 100644 --- a/crates/loro-internal/src/state/container_store.rs +++ b/crates/loro-internal/src/state/container_store.rs @@ -469,6 +469,17 @@ impl ContainerWrapper { return Ok(()); }; + if self.bytes_offset_for_value.is_none() { + let src: &[u8] = b; + let mut bytes: &[u8] = b; + bytes = &bytes[1..]; + let _depth = leb128::read::unsigned(&mut bytes).unwrap(); + let (_parent, bytes) = postcard::take_from_bytes::>(bytes).unwrap(); + // SAFETY: bytes is a slice of b + let size = unsafe { bytes.as_ptr().offset_from(src.as_ptr()) }; + self.bytes_offset_for_value = Some(size as usize); + } + let value_offset = self.bytes_offset_for_value.unwrap(); let b = &b[value_offset..];