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: Vec<Player>,
    pub commands: HashMap<u8, Vec<Command>>,
    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

If parsing failed, this will contain an error string

Game engine version

Game type (i.e. Automatch/Annihilate)

Timestamp encoded in replay file

Map this game was played on

Players involved in the game

Commands issued per player

Game length in seconds

Internal RNG seed used by game engine

Type of opponent (1 = human, 2 = cpu)

List of chat messages sent during replay

Methods

impl Replay
[src]

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

Examples

extern crate vault;

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

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

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),
}

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 vault::Config;
use std::ops::Deref;
use std::path::Path;
use zip::read::{ZipArchive, ZipFile};

let path = Path::new("/path/to/archive.zip");
let config = Config::default();
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, config).unwrap();
replay.parse();

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;
use vault::Config;
use std::path::Path;

let path = Path::new("/path/to/replay.rec");
let config = Config::default();
let replay = Replay::new(&path, config).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);

Trait Implementations

impl Debug for Replay
[src]

Formats the value using the given formatter.

impl Encodable for Replay
[src]

Serialize a value using an Encoder.