mirror of
https://github.com/loro-dev/loro.git
synced 2024-12-12 16:55:12 +00:00
fix: snapshot encoding err
This commit is contained in:
parent
c56653c3c8
commit
2a436e07ad
3 changed files with 25 additions and 4 deletions
|
@ -517,9 +517,17 @@ impl Container for ListContainer {
|
|||
.as_mut()
|
||||
.unwrap()
|
||||
.convert_ops_slice(slice.0.clone(), old_pool);
|
||||
let mut offset = 0;
|
||||
new_slice
|
||||
.into_iter()
|
||||
.map(|slice| InnerContent::List(InnerListOp::Insert { slice, pos: *pos }))
|
||||
.map(|slice| {
|
||||
let ans = InnerContent::List(InnerListOp::Insert {
|
||||
slice,
|
||||
pos: *pos + offset,
|
||||
});
|
||||
offset += ans.atom_len();
|
||||
ans
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
InnerListOp::Delete(span) => {
|
||||
|
|
|
@ -435,9 +435,17 @@ impl Container for TextContainer {
|
|||
.as_mut()
|
||||
.unwrap()
|
||||
.convert_ops_slice(slice.0.clone(), old_pool);
|
||||
let mut offset = 0;
|
||||
new_slice
|
||||
.into_iter()
|
||||
.map(|slice| InnerContent::List(InnerListOp::Insert { slice, pos: *pos }))
|
||||
.map(|slice| {
|
||||
let ans = InnerContent::List(InnerListOp::Insert {
|
||||
slice,
|
||||
pos: *pos + offset,
|
||||
});
|
||||
offset += ans.atom_len();
|
||||
ans
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
InnerListOp::Delete(span) => {
|
||||
|
|
|
@ -187,6 +187,8 @@ fn convert_inner_content(
|
|||
}
|
||||
|
||||
pub(super) fn encode_snapshot(store: &LogStore, gc: bool) -> Result<Vec<u8>, LoroError> {
|
||||
debug_log::debug_dbg!(&store.vv);
|
||||
debug_log::debug_dbg!(&store.changes);
|
||||
let mut client_id_to_idx: FxHashMap<ClientID, ClientIdx> = FxHashMap::default();
|
||||
let mut clients = Vec::with_capacity(store.changes.len());
|
||||
let mut change_num = 0;
|
||||
|
@ -214,13 +216,13 @@ pub(super) fn encode_snapshot(store: &LogStore, gc: bool) -> Result<Vec<u8>, Lor
|
|||
let mut deps = Vec::with_capacity(change_num);
|
||||
for (client_idx, (_, change_vec)) in store.changes.iter().enumerate() {
|
||||
for change in change_vec.iter() {
|
||||
let mut op_len = 0;
|
||||
for dep in change.deps.iter() {
|
||||
deps.push(DepsEncoding::new(
|
||||
*client_id_to_idx.get(&dep.client_id).unwrap(),
|
||||
dep.counter,
|
||||
));
|
||||
}
|
||||
let op_len = change.ops.len() as u32;
|
||||
for op in change.ops.iter() {
|
||||
let container_idx = op.container;
|
||||
let container_id = store.reg.get_id(container_idx).unwrap();
|
||||
|
@ -231,6 +233,7 @@ pub(super) fn encode_snapshot(store: &LogStore, gc: bool) -> Result<Vec<u8>, Lor
|
|||
.try_lock()
|
||||
.unwrap()
|
||||
.to_export_snapshot(&op.content, gc);
|
||||
op_len += new_ops.len();
|
||||
for op_content in new_ops {
|
||||
let (prop, value, value2) =
|
||||
convert_inner_content(&op_content, &mut key_to_idx, &mut keys);
|
||||
|
@ -249,7 +252,7 @@ pub(super) fn encode_snapshot(store: &LogStore, gc: bool) -> Result<Vec<u8>, Lor
|
|||
lamport: change.lamport,
|
||||
timestamp: change.timestamp,
|
||||
deps_len: change.deps.len() as u32,
|
||||
op_len,
|
||||
op_len: op_len as u32,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -407,6 +410,8 @@ pub(super) fn decode_snapshot(
|
|||
.map(|changes| changes.last().unwrap().id_last())
|
||||
.collect();
|
||||
|
||||
debug_log::debug_dbg!(&vv, &changes);
|
||||
|
||||
let can_load = match vv.partial_cmp(&store.vv) {
|
||||
Some(ord) => match ord {
|
||||
std::cmp::Ordering::Less => false,
|
||||
|
|
Loading…
Reference in a new issue