[][src]Struct rscache::cache::Cache

pub struct Cache<S: Store> { /* fields omitted */ }

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

impl<S: Store> CacheCore for Cache<S>[src]

impl<S: Store> CacheRead for Cache<S>[src]

Auto Trait Implementations

impl<S> RefUnwindSafe for Cache<S> where
    S: RefUnwindSafe

impl<S> Send for Cache<S> where
    S: Send

impl<S> Sync for Cache<S> where
    S: Sync

impl<S> Unpin for Cache<S> where
    S: Unpin

impl<S> UnwindSafe for Cache<S> where
    S: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.