Struct vault::Replay [] [src]

pub struct Replay {
    pub error: Option<String>,
    pub version: u16,
    pub game_type: String,
    pub date_time: String,
    pub map: Map,
    pub players: HashMap<u8Player>,
    pub duration: u32,
    pub rng_seed: u32,
    pub opponent_type: u32,
    pub chat: Vec<ChatLine>,
    // some fields omitted
}

The main Replay type, contains all currently parsed replay data. Can be serialized to JSON for output using rustc_serialize.

Fields

error: Option<String> version: u16 game_type: String date_time: String map: Map players: HashMap<u8Player> duration: u32 rng_seed: u32 opponent_type: u32 chat: Vec<ChatLine>

Methods

impl Replay
[src]

fn new(path: &Path) -> Result<Replay>

Constructs a new Replay and loads the file specified by path into memory.

Examples

extern crate vault;

use vault::Replay;
use std::path::Path;

let path = Path::new("/path/to/replay.rec");
let replay = Replay::new(&path).unwrap();

fn new_with_error(name: &str, err: Error) -> Replay

Constructs a junk Replay type with empty data and an error value set. Used to return a Replay and its error information out of a thread without panicking if an error was encountered during creation.

Examples

extern crate vault;

use vault::Replay;

match Replay::new("/path/to/replay.rec") {
    Ok(replay) => replay,
    Err(err) => Replay::with_new_error(err),
}

fn from_bytes(name: &str, bytes: Vec<u8>) -> Result<Replay>

Constructs a new Replay and loads the byte vector given as the file data.

Examples

extern crate vault;
extern crate zip;

use vault::Replay;
use std::ops::Deref;
use std::path::Path;
use zip::read::{ZipArchive, ZipFile};

let path = Path::new("/path/to/archive.zip");
let name = path.to_string_lossy();
let name = name.deref();
let file = File::open(&path).unwrap();
let archive = ZipArchive::new(file).unwrap();
let mut buff: Vec<u8> = Vec::with_capacity(replay_file.size() as usize);
let mut replay_file = archive.by_index(0).unwrap();

replay_file.read_to_end(&mut buff).unwrap();
let mut replay = Replay::from_bytes(&name, buff).unwrap();
replay.parse();

fn parse(&mut self)

Parses the loaded replay and populates the Replay type with the return data.

When the replay has finished being parsed, the vector of byte data loaded into memory from file is dropped. This is done to clean up the resulting type in order to make working with the output easier. The file cursor property remains, however, and is an accurate representation of the size of the replay file in bytes.

Examples

extern crate vault;

use vault::replay::Replay;
use std::path::Path;

let path = Path::new("/path/to/replay.rec");
let replay = Replay::new(&path).unwrap();

replay.parse();
 
// You can serialize the Replay type to JSON after parsing if you would like to print
// replay data to stdout or write it to a file.
//
let encoded = replay.to_json().unwrap();
println!("{}", encoded);

fn to_json(&self) -> Result<String>

Serializes Replay as JSON String.

fn display(&self)

Writes the contents of the Replay to stdout.

Trait Implementations

impl Encodable for Replay
[src]

fn encode<__S: Encoder>(&self, __arg_0: &mut __S) -> Result<(), __S::Error>

impl Debug for Replay
[src]

fn fmt(&self, __arg_0: &mut Formatter) -> Result

Formats the value using the given formatter.