Skip to content

Commit

Permalink
Switch to cbor serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
hendrikvanantwerpen committed Jul 27, 2023
1 parent f6ba30c commit 87e8c76
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
4 changes: 2 additions & 2 deletions stack-graphs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ edition = "2018"
[features]
copious-debugging = []
serde = ["dep:serde", "lsp-positions/serde"]
storage = ["rusqlite", "serde", "rmp-serde"]
storage = ["rusqlite", "serde", "serde_cbor"]
visualization = ["serde", "serde_json"]

[lib]
Expand All @@ -31,9 +31,9 @@ fxhash = "0.2"
itertools = "0.10"
libc = "0.2"
lsp-positions = { version = "0.3", path = "../lsp-positions" }
rmp-serde = { version = "1.1", optional = true }
rusqlite = { version = "0.28", optional = true, features = ["bundled", "functions"] }
serde = { version = "1.0", optional = true, features = ["derive"] }
serde_cbor = { version = "0.11", optional = true }
serde_json = { version = "1.0", optional = true }
smallvec = { version = "1.6", features = ["union"] }
thiserror = { version = "1.0" }
Expand Down
20 changes: 9 additions & 11 deletions stack-graphs/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use crate::stitching::ForwardPartialPathStitcher;
use crate::CancellationError;
use crate::CancellationFlag;

const VERSION: usize = 3;
const VERSION: usize = 4;

const SCHEMA: &str = r#"
CREATE TABLE metadata (
Expand Down Expand Up @@ -75,9 +75,7 @@ pub enum StorageError {
#[error(transparent)]
Serde(#[from] serde::Error),
#[error(transparent)]
RmpSerdeDecode(#[from] rmp_serde::decode::Error),
#[error(transparent)]
RmpSerdeEncode(#[from] rmp_serde::encode::Error),
SerdeCbor(#[from] serde_cbor::Error),
}

pub type Result<T> = std::result::Result<T, StorageError>;
Expand Down Expand Up @@ -283,7 +281,7 @@ impl SQLiteWriter {
&file.to_string_lossy(),
tag,
error,
&rmp_serde::to_vec_named(&graph)?,
&serde_cbor::to_vec(&graph)?,
))?;
Ok(())
}
Expand Down Expand Up @@ -323,7 +321,7 @@ impl SQLiteWriter {
let mut stmt =
conn.prepare_cached("INSERT INTO graphs (file, tag, value) VALUES (?, ?, ?)")?;
let graph = serde::StackGraph::from_graph_filter(graph, &FileFilter(file));
stmt.execute((file_str, tag, &rmp_serde::to_vec_named(&graph)?))?;
stmt.execute((file_str, tag, &serde_cbor::to_vec(&graph)?))?;
Ok(())
}

Expand Down Expand Up @@ -364,7 +362,7 @@ impl SQLiteWriter {
);
let symbol_stack = path.symbol_stack_precondition.storage_key(graph, partials);
let path = serde::PartialPath::from_partial_path(graph, partials, path);
root_stmt.execute((file_str, symbol_stack, &rmp_serde::to_vec_named(&path)?))?;
root_stmt.execute((file_str, symbol_stack, &serde_cbor::to_vec(&path)?))?;
root_path_count += 1;
} else if start_node.is_in_file(file) {
copious_debugging!(
Expand All @@ -375,7 +373,7 @@ impl SQLiteWriter {
node_stmt.execute((
file_str,
path.start_node.local_id,
&rmp_serde::to_vec_named(&path)?,
&serde_cbor::to_vec(&path)?,
))?;
node_path_count += 1;
} else {
Expand Down Expand Up @@ -525,7 +523,7 @@ impl SQLiteReader {
copious_debugging!(" * Load from database");
let mut stmt = conn.prepare_cached("SELECT value FROM graphs WHERE file = ?")?;
let value = stmt.query_row([file], |row| row.get::<_, Vec<u8>>(0))?;
let file_graph = rmp_serde::from_slice::<serde::StackGraph>(&value)?;
let file_graph = serde_cbor::from_slice::<serde::StackGraph>(&value)?;
file_graph.load_into(graph)?;
Ok(graph.get_file(file).expect("loaded file to exist"))
}
Expand Down Expand Up @@ -581,7 +579,7 @@ impl SQLiteReader {
&mut self.loaded_graphs,
&self.conn,
)?;
let path = rmp_serde::from_slice::<serde::PartialPath>(&value)?;
let path = serde_cbor::from_slice::<serde::PartialPath>(&value)?;
let path = path.to_partial_path(&mut self.graph, &mut self.partials)?;
copious_debugging!(
" > Loaded {}",
Expand Down Expand Up @@ -635,7 +633,7 @@ impl SQLiteReader {
&mut self.loaded_graphs,
&self.conn,
)?;
let path = rmp_serde::from_slice::<serde::PartialPath>(&value)?;
let path = serde_cbor::from_slice::<serde::PartialPath>(&value)?;
let path = path.to_partial_path(&mut self.graph, &mut self.partials)?;
copious_debugging!(
" > Loaded {}",
Expand Down

0 comments on commit 87e8c76

Please sign in to comment.