Fixed some compile errors.
This commit is contained in:
parent
059f2a2630
commit
d155ae2a68
@ -14,3 +14,6 @@ git = "ssh://git@gitlab.com/CyberMages/Core/scribe.git"
|
||||
|
||||
[dependencies.alchemy]
|
||||
git = "ssh://git@gitlab.com/CyberMages/Core/alchemy.git"
|
||||
|
||||
[dependencies.spellbook]
|
||||
git = "ssh://git@gitlab.com/CyberMages/Core/spellbook.git"
|
||||
|
@ -2,6 +2,7 @@
|
||||
extern crate scribe;
|
||||
|
||||
extern crate alchemy;
|
||||
extern crate spellbook;
|
||||
|
||||
|
||||
|
||||
|
@ -3,6 +3,8 @@ use std::io::{Error, ErrorKind, BufReader, BufWriter, Read, Write};
|
||||
|
||||
use alchemy::*;
|
||||
|
||||
use spellbook::components::Array;
|
||||
|
||||
|
||||
|
||||
///
|
||||
@ -36,7 +38,7 @@ pub struct Entry
|
||||
pub struct Loader
|
||||
{
|
||||
///
|
||||
entries: Vec<Entry>
|
||||
entries: Array<Entry>
|
||||
}
|
||||
|
||||
|
||||
@ -76,7 +78,8 @@ impl Entry
|
||||
|
||||
impl Transmutable for Entry
|
||||
{
|
||||
fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Self
|
||||
fn from_endian_bytes(buffer: &[u8], endianess: Endianess)
|
||||
-> Result<Self, ConversionError>
|
||||
{
|
||||
let buffer_size: usize;
|
||||
let name: String;
|
||||
@ -87,26 +90,27 @@ impl Transmutable for Entry
|
||||
buffer_size = buffer.len() - 1;
|
||||
|
||||
skip_size = 0;
|
||||
name = String::from_endian_bytes(&buffer[skip_size..buffer_size],
|
||||
endianess);
|
||||
name = try!(String::from_endian_bytes(&buffer[skip_size..buffer_size],
|
||||
endianess));
|
||||
|
||||
skip_size = skip_size + get_byte_size_of_string(&name);
|
||||
type_hint = String::from_endian_bytes(&buffer[skip_size..buffer_size],
|
||||
endianess);
|
||||
type_hint =
|
||||
try!(String::from_endian_bytes(&buffer[skip_size..buffer_size],
|
||||
endianess));
|
||||
|
||||
skip_size = skip_size + get_byte_size_of_string(&type_hint);
|
||||
path = String::from_endian_bytes(&buffer[skip_size..buffer_size],
|
||||
endianess);
|
||||
path = try!(String::from_endian_bytes(&buffer[skip_size..buffer_size],
|
||||
endianess));
|
||||
|
||||
Entry::new(name, type_hint, path)
|
||||
Ok(Entry::new(name, type_hint, path))
|
||||
}
|
||||
|
||||
fn as_endian_bytes(&self, endianess: Endianess) -> Vec<u8>
|
||||
fn as_endian_bytes(&self, endianess: Endianess) -> Array<u8>
|
||||
{
|
||||
let mut buffer: Vec<u8>;
|
||||
let mut buffer: Array<u8>;
|
||||
|
||||
// Create the new buffer to hold the data from this type.
|
||||
buffer = Vec::new();
|
||||
buffer = Array::new();
|
||||
|
||||
// Add the buffer data of the three paths to the data buffer.
|
||||
buffer.append(&mut self.name.as_endian_bytes(endianess));
|
||||
@ -133,7 +137,7 @@ impl Loader
|
||||
{
|
||||
Loader
|
||||
{
|
||||
entries: Vec::new()
|
||||
entries: Array::new()
|
||||
}
|
||||
}
|
||||
|
||||
@ -145,7 +149,7 @@ impl Loader
|
||||
// Create a new loader.
|
||||
loader = Loader
|
||||
{
|
||||
entries: Vec::new()
|
||||
entries: Array::new()
|
||||
};
|
||||
|
||||
// Read the given file.
|
||||
@ -176,7 +180,7 @@ impl Loader
|
||||
}
|
||||
|
||||
///
|
||||
pub fn get_resource_entries(&self) -> &Vec<Entry>
|
||||
pub fn get_resource_entries(&self) -> &Array<Entry>
|
||||
{
|
||||
&self.entries
|
||||
}
|
||||
@ -184,14 +188,14 @@ impl Loader
|
||||
/// Write the resource entries out to a file.
|
||||
pub fn write_to_file(&self, file: File) -> ::std::io::Result<()>
|
||||
{
|
||||
let mut data: Vec<u8>;
|
||||
let mut data: Array<u8>;
|
||||
let mut writer: BufWriter<File>;
|
||||
|
||||
// Create the writer for the file.
|
||||
writer = BufWriter::new(file);
|
||||
|
||||
// Create a Vector for the data of this loader data.
|
||||
data = Vec::new();
|
||||
// Create a Arraytor for the data of this loader data.
|
||||
data = Array::new();
|
||||
|
||||
// Write the header of the file.
|
||||
data.extend_from_slice(MAGIC_NUMBER.as_bytes());
|
||||
@ -214,7 +218,7 @@ impl Loader
|
||||
fn read_from_file(&mut self, file: File) -> ::std::io::Result<()>
|
||||
{
|
||||
let mut pos: usize;
|
||||
let mut data: Vec<u8>;
|
||||
let mut data: Array<u8>;
|
||||
let mut reader: BufReader<File>;
|
||||
let data_size: usize;
|
||||
let data_slice: &[u8];
|
||||
@ -225,7 +229,7 @@ impl Loader
|
||||
reader = BufReader::new(file);
|
||||
|
||||
// Try to read in all of the file.
|
||||
data = Vec::new();
|
||||
data = Array::new();
|
||||
try!(reader.read_to_end(&mut data));
|
||||
data_slice = data.as_slice();
|
||||
data_size = data_slice.len() - 1;
|
||||
@ -239,11 +243,20 @@ impl Loader
|
||||
while pos <= data_size
|
||||
{
|
||||
debug!("\tParsing entry.");
|
||||
entry = Entry::from_endian_bytes(&data_slice[pos..data_size],
|
||||
Endianess::Little);
|
||||
pos = pos + entry.determine_byte_size();
|
||||
match Entry::from_endian_bytes(&data_slice[pos..data_size],
|
||||
Endianess::Little)
|
||||
{
|
||||
Ok(entry) =>
|
||||
{
|
||||
pos = pos + entry.determine_byte_size();
|
||||
self.entries.push(entry);
|
||||
}
|
||||
|
||||
self.entries.push(entry);
|
||||
Err(error) =>
|
||||
{
|
||||
error!("{}", error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
debug!("Loader manifest parsed successfully.");
|
||||
|
Loading…
x
Reference in New Issue
Block a user