Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic HashMap for memory store and enable store_one_item_existence test
- Loading branch information
Showing
10 changed files
with
125 additions
and
26 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,48 @@ | ||
// Copyright 2020 Nathan (Blaise) Bruer. All rights reserved. | ||
|
||
use async_trait::async_trait; | ||
use std::collections::HashMap; | ||
|
||
use tokio::io::{AsyncRead, Error}; | ||
use async_trait::async_trait; | ||
use hex::FromHex; | ||
use tokio::io::{AsyncRead, AsyncReadExt, Error}; | ||
|
||
use traits::StoreTrait; | ||
|
||
#[derive(Debug)] | ||
pub struct MemoryStore {} | ||
pub struct MemoryStore { | ||
map: HashMap<[u8; 32], Vec<u8>>, | ||
} | ||
|
||
impl MemoryStore { | ||
pub fn new() -> Self { | ||
MemoryStore {} | ||
MemoryStore { | ||
map: HashMap::new(), | ||
} | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl StoreTrait for MemoryStore { | ||
fn has(&self, _hash: &str) -> bool { | ||
false | ||
async fn has(&self, hash: &str) -> Result<bool, Error> { | ||
let raw_key = <[u8; 32]>::from_hex(&hash).expect("Hex length is not 64 hex characters"); | ||
Ok(self.map.contains_key(&raw_key)) | ||
} | ||
|
||
async fn update<'a>( | ||
&'a self, | ||
_hash: &'a str, | ||
_size: i64, | ||
_reader: Box<dyn AsyncRead + Send>, | ||
&'a mut self, | ||
hash: &'a str, | ||
expected_size: usize, | ||
mut reader: Box<dyn AsyncRead + Send + Unpin>, | ||
) -> Result<(), Error> { | ||
let raw_key = <[u8; 32]>::from_hex(&hash).expect("Hex length is not 64 hex characters"); | ||
let mut buffer = Vec::new(); | ||
let read_size = reader.read_to_end(&mut buffer).await?; | ||
assert_eq!( | ||
read_size, expected_size, | ||
"Expected size {} but got size {} for hash {} CAS insert", | ||
expected_size, read_size, hash | ||
); | ||
self.map.insert(raw_key, buffer); | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
""" | ||
@generated | ||
cargo-raze crate build file. | ||
|
||
DO NOT EDIT! Replaced on runs of cargo-raze | ||
""" | ||
|
||
# buildifier: disable=load | ||
load( | ||
"@io_bazel_rules_rust//rust:rust.bzl", | ||
"rust_binary", | ||
"rust_library", | ||
"rust_test", | ||
) | ||
|
||
# buildifier: disable=load | ||
load("@bazel_skylib//lib:selects.bzl", "selects") | ||
|
||
package(default_visibility = [ | ||
# Public for visibility by "@raze__crate__version//" targets. | ||
# | ||
# Prefer access through "//third_party", which limits external | ||
# visibility to explicit Cargo.toml dependencies. | ||
"//visibility:public", | ||
]) | ||
|
||
licenses([ | ||
"notice", # MIT from expression "MIT OR Apache-2.0" | ||
]) | ||
|
||
# Generated Targets | ||
|
||
# Unsupported target "hex" with type "bench" omitted | ||
|
||
rust_library( | ||
name = "hex", | ||
srcs = glob(["**/*.rs"]), | ||
crate_features = [ | ||
"default", | ||
"std", | ||
], | ||
crate_root = "src/lib.rs", | ||
crate_type = "lib", | ||
data = [], | ||
edition = "2018", | ||
rustc_flags = [ | ||
"--cap-lints=allow", | ||
], | ||
tags = [ | ||
"cargo-raze", | ||
"manual", | ||
], | ||
version = "0.4.2", | ||
# buildifier: leave-alone | ||
deps = [ | ||
], | ||
) | ||
|
||
# Unsupported target "serde" with type "test" omitted | ||
|
||
# Unsupported target "version-number" with type "test" omitted |