Turn cache entry into writable bytes.
This commit is contained in:
parent
eb97e3399a
commit
8db7a6d9bf
@ -19,9 +19,18 @@ enum CacheEntry {
|
|||||||
impl CacheEntry {
|
impl CacheEntry {
|
||||||
fn entry_type(&self) -> String {
|
fn entry_type(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
CacheEntry::Raw(_) => "raw".to_string(),
|
CacheEntry::Raw(_) => "Raw".to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn to_bytes(&self) -> Vec<u8> {
|
||||||
|
let mut output = self.entry_type().into_bytes();
|
||||||
|
output.push(0);
|
||||||
|
match self {
|
||||||
|
CacheEntry::Raw(s) => output.append(&mut s.as_bytes().to_vec()),
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for CacheEntry {
|
impl fmt::Display for CacheEntry {
|
||||||
@ -214,8 +223,19 @@ mod cache_entry {
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn raw_type() {
|
fn raw_get_type() {
|
||||||
let holder = CacheEntry::Raw("nothing important".to_string());
|
let holder = CacheEntry::Raw("nothing important".to_string());
|
||||||
assert_eq!(holder.entry_type(), "raw");
|
assert_eq!(holder.entry_type(), "Raw");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn raw_get_bytes() {
|
||||||
|
let data = "addams";
|
||||||
|
let holder = CacheEntry::Raw(data.to_string());
|
||||||
|
let mut expected = holder.entry_type().into_bytes();
|
||||||
|
expected.push(0);
|
||||||
|
expected.append(&mut data.as_bytes().to_vec());
|
||||||
|
let output = holder.to_bytes();
|
||||||
|
assert_eq!(output, expected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user