[−][src]Struct rscache::Cache
Main cache struct providing basic utilities.
Implementations
impl<S: Store> Cache<S>
[src]
pub fn new<P: AsRef<Path>>(path: P) -> Result<Self>
[src]
Constructs a new Cache<S>
with the given store.
Errors
If this function encounters any form of I/O or other error, a CacheError
is returned which wrapps the underlying error.
Examples
use rscache::{ Cache, store::MemoryStore }; let cache: Cache<MemoryStore> = Cache::new("./data/cache")?;
pub fn read(&self, index_id: u8, archive_id: u32) -> Result<Vec<u8>>
[src]
Reads from the internal store.
A lookup is performed on the specified index to find the sector id and the total length
of the buffer that needs to be read from the main_file_cache.dat2
.
If the lookup is successfull the data is gathered into a Vec<u8>
.
Errors
Returns an IndexNotFound
error if the specified index_id
is not a valid Index
.
Returns an ArchiveNotFound
error if the specified archive_id
is not a valid Archive
.
Examples
let cache: Cache<MemoryStore> = Cache::new(path)?; let index_id = 2; // Config index let archive_id = 10; // Random archive. let buffer = cache.read(index_id, archive_id)?;
pub fn create_checksum(&self) -> Result<Checksum>
[src]
Creates a Checksum
which can be used to validate the cache data
that the client received during the update protocol.
NOTE: The RuneScape client doesn't have a valid crc for index 16. This checksum sets the crc and revision for index 16 both to 0. The crc for index 16 should be skipped.
Errors
Returns an error when a buffer read from the reference table could not be decoded / decompressed.
Examples
let checksum = cache.create_checksum()?;
pub fn huffman_table(&self) -> Result<Vec<u8>>
[src]
Constructs a buffer which contains the huffman table.
Errors
Returns an error if the huffman archive could not be found or if the decode / decompression of the huffman table failed.
Examples
let huffman_table = cache.huffman_table()?; let huffman = Huffman::new(huffman_table);
pub fn archive_by_name(&self, index_id: u8, name: &str) -> Result<Archive>
[src]
Searches for the archive which contains the given name hash in the given index_id.
Errors
Panics if the string couldn't be hashed by the djd2 hasher.
Returns an IndexNotFound
error if the specified index_id
is not a valid Index
.
Returns an ArchiveNotFound
error if the specified archive_id
is not a valid Archive
.
Returns an NameNotInArchive
error if the name
hash is not present in this archive.
Examples
let index_id = 10; let archive = cache.archive_by_name(index_id, "huffman")?;
pub fn index_count(&self) -> usize
[src]
Simply returns the index count, by getting the len()
of
the underlying indices
vector.
Examples
for index in 0..cache.index_count() { // ... } assert_eq!(22, cache.index_count());
Trait Implementations
Auto Trait Implementations
impl<S> RefUnwindSafe for Cache<S> where
S: RefUnwindSafe,
S: RefUnwindSafe,
impl<S> Send for Cache<S> where
S: Send,
S: Send,
impl<S> Sync for Cache<S> where
S: Sync,
S: Sync,
impl<S> Unpin for Cache<S> where
S: Unpin,
S: Unpin,
impl<S> UnwindSafe for Cache<S> where
S: UnwindSafe,
S: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,