mirror of
https://github.com/loro-dev/loro.git
synced 2025-01-22 21:07:43 +00:00
refactor: fix name err & add counter state fast snapshot
This commit is contained in:
parent
d6c8a632ad
commit
9c050b8b0b
8 changed files with 46 additions and 12 deletions
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
|
@ -44,7 +44,8 @@
|
|||
"DEBUG": "*"
|
||||
},
|
||||
"rust-analyzer.cargo.features": [
|
||||
"test_utils"
|
||||
"test_utils",
|
||||
"counter"
|
||||
],
|
||||
"editor.defaultFormatter": "rust-lang.rust-analyzer",
|
||||
"rust-analyzer.server.extraEnv": {
|
||||
|
|
|
@ -90,7 +90,7 @@ pub(crate) struct ContainerCreationContext<'a> {
|
|||
peer: PeerID,
|
||||
}
|
||||
|
||||
pub(crate) trait FastStateSnashot {
|
||||
pub(crate) trait FastStateSnapshot {
|
||||
fn encode_snapshot_fast<W: Write>(&mut self, w: W);
|
||||
fn decode_value(bytes: &[u8]) -> LoroResult<(LoroValue, &[u8])>;
|
||||
fn decode_snapshot_fast(
|
||||
|
|
|
@ -125,3 +125,36 @@ impl ContainerState for CounterState {
|
|||
false
|
||||
}
|
||||
}
|
||||
|
||||
mod snapshot {
|
||||
use crate::state::FastStateSnapshot;
|
||||
|
||||
use super::*;
|
||||
|
||||
impl FastStateSnapshot for CounterState {
|
||||
fn encode_snapshot_fast<W: std::io::Write>(&mut self, mut w: W) {
|
||||
let bytes = self.value.to_le_bytes();
|
||||
w.write_all(&bytes).unwrap();
|
||||
}
|
||||
|
||||
fn decode_value(bytes: &[u8]) -> LoroResult<(LoroValue, &[u8])> {
|
||||
Ok((
|
||||
LoroValue::Double(f64::from_le_bytes(bytes.try_into().unwrap())),
|
||||
&[],
|
||||
))
|
||||
}
|
||||
|
||||
fn decode_snapshot_fast(
|
||||
idx: ContainerIdx,
|
||||
v: (LoroValue, &[u8]),
|
||||
ctx: crate::state::ContainerCreationContext,
|
||||
) -> LoroResult<Self>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
let mut counter = CounterState::new(idx);
|
||||
counter.value = *v.0.as_double().unwrap();
|
||||
Ok(counter)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ use std::{
|
|||
sync::{Arc, Mutex, Weak},
|
||||
};
|
||||
|
||||
use super::{ContainerState, FastStateSnashot};
|
||||
use super::{ContainerState, FastStateSnapshot};
|
||||
use crate::{
|
||||
arena::SharedArena,
|
||||
container::{idx::ContainerIdx, list::list_op::ListOp, ContainerID},
|
||||
|
@ -552,7 +552,7 @@ mod snapshot {
|
|||
|
||||
use super::*;
|
||||
|
||||
impl FastStateSnashot for ListState {
|
||||
impl FastStateSnapshot for ListState {
|
||||
fn encode_snapshot_fast<W: Write>(&mut self, mut w: W) {
|
||||
let value = self.get_value();
|
||||
postcard::to_io(&value, &mut w).unwrap();
|
||||
|
|
|
@ -245,12 +245,12 @@ mod snapshot {
|
|||
|
||||
use crate::{
|
||||
delta::MapValue,
|
||||
state::{ContainerCreationContext, ContainerState, FastStateSnashot},
|
||||
state::{ContainerCreationContext, ContainerState, FastStateSnapshot},
|
||||
};
|
||||
|
||||
use super::MapState;
|
||||
|
||||
impl FastStateSnashot for MapState {
|
||||
impl FastStateSnapshot for MapState {
|
||||
fn encode_snapshot_fast<W: std::io::prelude::Write>(&mut self, mut w: W) {
|
||||
let value = self.get_value();
|
||||
postcard::to_io(&value, &mut w).unwrap();
|
||||
|
|
|
@ -1524,7 +1524,7 @@ mod snapshot {
|
|||
|
||||
use crate::{
|
||||
encoding::value_register::ValueRegister,
|
||||
state::{ContainerCreationContext, ContainerState, FastStateSnashot},
|
||||
state::{ContainerCreationContext, ContainerState, FastStateSnapshot},
|
||||
};
|
||||
|
||||
use super::{
|
||||
|
@ -1532,7 +1532,7 @@ mod snapshot {
|
|||
EncodedItemForFastSnapshot, MovableListState,
|
||||
};
|
||||
|
||||
impl FastStateSnashot for MovableListState {
|
||||
impl FastStateSnapshot for MovableListState {
|
||||
fn encode_snapshot_fast<W: std::io::prelude::Write>(&mut self, mut w: W) {
|
||||
let value = self.get_value();
|
||||
postcard::to_io(&value, &mut w).unwrap();
|
||||
|
|
|
@ -877,7 +877,7 @@ mod snapshot {
|
|||
TextStyleInfoFlag,
|
||||
},
|
||||
encoding::value_register::ValueRegister,
|
||||
state::{ContainerCreationContext, ContainerState, FastStateSnashot},
|
||||
state::{ContainerCreationContext, ContainerState, FastStateSnapshot},
|
||||
utils::lazy::LazyLoad,
|
||||
};
|
||||
|
||||
|
@ -915,7 +915,7 @@ mod snapshot {
|
|||
marks: Vec<EncodedMark>,
|
||||
}
|
||||
|
||||
impl FastStateSnashot for RichtextState {
|
||||
impl FastStateSnapshot for RichtextState {
|
||||
fn encode_snapshot_fast<W: std::io::prelude::Write>(&mut self, mut w: W) {
|
||||
let value = self.get_value();
|
||||
postcard::to_io(&value, &mut w).unwrap();
|
||||
|
|
|
@ -1234,7 +1234,7 @@ mod snapshot {
|
|||
use loro_common::{IdFull, PeerID, TreeID};
|
||||
use serde_columnar::columnar;
|
||||
|
||||
use crate::{encoding::value_register::ValueRegister, state::FastStateSnashot};
|
||||
use crate::{encoding::value_register::ValueRegister, state::FastStateSnapshot};
|
||||
|
||||
use super::{TreeNode, TreeParentId, TreeState};
|
||||
|
||||
|
@ -1302,7 +1302,7 @@ mod snapshot {
|
|||
)
|
||||
}
|
||||
|
||||
impl FastStateSnashot for TreeState {
|
||||
impl FastStateSnapshot for TreeState {
|
||||
fn encode_snapshot_fast<W: std::io::prelude::Write>(&mut self, mut w: W) {
|
||||
let alive_tree_nodes = self.tree_nodes();
|
||||
let deleted_tree_nodes = self.deleted_tree_nodes();
|
||||
|
|
Loading…
Reference in a new issue