diff --git a/src/fot.rs b/src/fot.rs index caf4488..e5829f2 100644 --- a/src/fot.rs +++ b/src/fot.rs @@ -1,5 +1,6 @@ mod decoder; mod entity; +mod entitylist; mod esh; mod fstring; mod raw; diff --git a/src/fot/decoder.rs b/src/fot/decoder.rs index 5ec8a33..7800edf 100644 --- a/src/fot/decoder.rs +++ b/src/fot/decoder.rs @@ -8,9 +8,8 @@ pub trait Decoder: Sized { fn get_enc_size(&self) -> usize; } -pub trait DecoderOpt: Sized { - type Opt<'o>; - fn decode(raw: &Raw, offset: usize, size: usize, opt: Option>) -> Result; +pub trait DecoderOpt: Sized { + fn decode(raw: &Raw, offset: usize, size: usize, opt: Opt) -> Result; fn encode(&self) -> Result; fn get_enc_size(&self) -> usize; } diff --git a/src/fot/entity.rs b/src/fot/entity.rs index c386a5e..3c0562f 100644 --- a/src/fot/entity.rs +++ b/src/fot/entity.rs @@ -1,57 +1,24 @@ -use super::raw::Raw; -use super::tag::Tag; -use super::esh::ESH; use super::decoder::DecoderOpt; +use super::entitylist::{EntityEncoding, EntityList}; +use super::esh::ESH; use super::fstring::FString; +use super::raw::Raw; use super::stream::{ReadStream, WriteStream}; +use super::tag::Tag; use anyhow::anyhow; use anyhow::Result; -pub enum EntityEncoding { - File, - World -} - -pub struct EntityList {} - -impl EntityList { - fn get_entity_encoding(&self) -> EntityEncoding { - todo!(); - } - - fn get_entity_tag(&self) -> &Tag { - todo!(); - } - - fn add_new_type(&mut self, name: FString) -> usize { - todo!(); - } - - fn add_or_get_type(&mut self, name: FString) -> usize { - todo!(); - } - - fn get_type_name(&self, type_idx: usize) -> &FString { - todo!(); - } -} - pub struct Entity { pub flags: u32, pub type_idx: usize, pub esh: ESH, - enc_size: usize + enc_size: usize, } -impl DecoderOpt for Entity { - type Opt<'o> = &'o EntityList; - fn decode<'o>(raw: &Raw, offset: usize, _: usize, opt: Option>) -> Result { - let rd = ReadStream::new(raw, offset); - let opt = match opt { - Some(opt) => opt, - None => return Err(anyhow!("no EntityOpt was provided!")) - }; - +impl DecoderOpt<&EntityList> for Entity { + fn decode(raw: &Raw, offset: usize, _: usize, opt: &EntityList) -> Result { + let mut rd = ReadStream::new(raw, offset); + todo!(); } diff --git a/src/fot/entitylist.rs b/src/fot/entitylist.rs new file mode 100644 index 0000000..85bed0a --- /dev/null +++ b/src/fot/entitylist.rs @@ -0,0 +1,38 @@ +use super::decoder::DecoderOpt; +use super::entity::Entity; +use super::esh::ESH; +use super::fstring::FString; +use super::raw::Raw; +use super::stream::{ReadStream, WriteStream}; +use super::tag::Tag; +use anyhow::anyhow; +use anyhow::Result; + +pub enum EntityEncoding { + File, + World, +} + +pub struct EntityList {} + +impl EntityList { + fn get_entity_encoding(&self) -> EntityEncoding { + todo!(); + } + + fn get_entity_tag(&self) -> &Tag { + todo!(); + } + + fn add_new_type(&mut self, name: FString) -> usize { + todo!(); + } + + fn add_or_get_type(&mut self, name: FString) -> usize { + todo!(); + } + + fn get_type_name(&self, type_idx: usize) -> &FString { + todo!(); + } +} diff --git a/src/fot/stream.rs b/src/fot/stream.rs index b7e166d..50dac4b 100644 --- a/src/fot/stream.rs +++ b/src/fot/stream.rs @@ -46,8 +46,8 @@ impl<'a> ReadStream<'a> { // read_opt - decode with optional paramters. required for complex structure // with different origins (save / entfile) like entities - pub fn read_opt<'o, T: DecoderOpt>(&mut self, size: usize, opt: T::Opt<'o>) -> Result { - let val = T::decode(&self.raw, self.offset(), size, Some(opt))?; + pub fn read_opt, Opt>(&mut self, size: usize, opt: Opt) -> Result { + let val = T::decode(&self.raw, self.offset(), size, opt)?; self.skip(val.get_enc_size()); Ok(val) }