From 87e8c7688e38ed2e18de7c603f231870f45e4d56 Mon Sep 17 00:00:00 2001 From: Hendrik van Antwerpen Date: Thu, 27 Jul 2023 17:25:13 +0200 Subject: [PATCH] Switch to cbor serialization --- stack-graphs/Cargo.toml | 4 ++-- stack-graphs/src/storage.rs | 20 +++++++++----------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/stack-graphs/Cargo.toml b/stack-graphs/Cargo.toml index 21c17fe33..9bbabae9e 100644 --- a/stack-graphs/Cargo.toml +++ b/stack-graphs/Cargo.toml @@ -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] @@ -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" } diff --git a/stack-graphs/src/storage.rs b/stack-graphs/src/storage.rs index ac28bb048..0613f0825 100644 --- a/stack-graphs/src/storage.rs +++ b/stack-graphs/src/storage.rs @@ -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 ( @@ -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 = std::result::Result; @@ -283,7 +281,7 @@ impl SQLiteWriter { &file.to_string_lossy(), tag, error, - &rmp_serde::to_vec_named(&graph)?, + &serde_cbor::to_vec(&graph)?, ))?; Ok(()) } @@ -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(()) } @@ -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!( @@ -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 { @@ -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>(0))?; - let file_graph = rmp_serde::from_slice::(&value)?; + let file_graph = serde_cbor::from_slice::(&value)?; file_graph.load_into(graph)?; Ok(graph.get_file(file).expect("loaded file to exist")) } @@ -581,7 +579,7 @@ impl SQLiteReader { &mut self.loaded_graphs, &self.conn, )?; - let path = rmp_serde::from_slice::(&value)?; + let path = serde_cbor::from_slice::(&value)?; let path = path.to_partial_path(&mut self.graph, &mut self.partials)?; copious_debugging!( " > Loaded {}", @@ -635,7 +633,7 @@ impl SQLiteReader { &mut self.loaded_graphs, &self.conn, )?; - let path = rmp_serde::from_slice::(&value)?; + let path = serde_cbor::from_slice::(&value)?; let path = path.to_partial_path(&mut self.graph, &mut self.partials)?; copious_debugging!( " > Loaded {}",