diff --git a/src/fot/decoder.rs b/src/fot/decoder.rs index 8eb9b59..5ec8a33 100644 --- a/src/fot/decoder.rs +++ b/src/fot/decoder.rs @@ -3,6 +3,12 @@ use anyhow::Result; use std::str; pub trait Decoder: Sized { + fn decode(raw: &Raw, offset: usize, size: usize) -> Result; + fn encode(&self) -> Result; + fn get_enc_size(&self) -> usize; +} + +pub trait DecoderOpt: Sized { type Opt<'o>; fn decode(raw: &Raw, offset: usize, size: usize, opt: Option>) -> Result; fn encode(&self) -> Result; @@ -10,8 +16,7 @@ pub trait Decoder: Sized { } impl Decoder for String { - type Opt<'o> = (); - fn decode(raw: &Raw, offset: usize, size: usize, _: Option<()>) -> Result { + fn decode(raw: &Raw, offset: usize, size: usize) -> Result { let str = &raw.mem[offset..]; match str.iter().position(|&c| c == 0) { Some(pos) => Ok(str::from_utf8(&str[..pos])?.to_string()), diff --git a/src/fot/esh.rs b/src/fot/esh.rs index a3b60a4..e5c1cee 100644 --- a/src/fot/esh.rs +++ b/src/fot/esh.rs @@ -76,8 +76,7 @@ impl ESHValue { } impl Decoder for ESHValue { - type Opt<'o> = (); - fn decode(raw: &Raw, offset: usize, _: usize, _: Option<()>) -> Result { + fn decode(raw: &Raw, offset: usize, _: usize) -> Result { let mut rd = ReadStream::new(raw, offset); let data_type = rd.read_u32()?; let data_size = rd.read_u32()?; @@ -249,8 +248,7 @@ pub struct ESH { } impl Decoder for ESH { - type Opt<'o> = (); - fn decode(raw: &Raw, offset: usize, _: usize, _: Option<()>) -> Result { + fn decode(raw: &Raw, offset: usize, _: usize) -> Result { let mut rd = ReadStream::new(raw, offset); let tag: Tag = rd.read(0)?; diff --git a/src/fot/fstring.rs b/src/fot/fstring.rs index 93b147a..439ba15 100644 --- a/src/fot/fstring.rs +++ b/src/fot/fstring.rs @@ -24,8 +24,7 @@ pub struct FString { } impl Decoder for FString { - type Opt<'o> = (); - fn decode(raw: &Raw, offset: usize, _: usize, _: Option<()>) -> Result { + fn decode(raw: &Raw, offset: usize, _: usize) -> Result { let mut rdr = Cursor::new(&raw.mem[offset..]); let flen = rdr.read_u32::()? as usize; let len = flen & !(1 << 31); diff --git a/src/fot/sgd.rs b/src/fot/sgd.rs index dd0ae95..7f5526e 100644 --- a/src/fot/sgd.rs +++ b/src/fot/sgd.rs @@ -15,8 +15,7 @@ pub struct SGD { } impl Decoder for SGD { - type Opt<'o> = (); - fn decode(raw: &Raw, offset: usize, _: usize, _: Option<()>) -> Result { + fn decode(raw: &Raw, offset: usize, _: usize) -> Result { let mut rd = ReadStream::new(raw, offset); let tag: Tag = rd.read(0)?; let unk1 = rd.read_bytes(0x48)?; diff --git a/src/fot/ssg.rs b/src/fot/ssg.rs index 5634e37..86186fe 100644 --- a/src/fot/ssg.rs +++ b/src/fot/ssg.rs @@ -11,8 +11,7 @@ pub struct SSG { } impl Decoder for SSG { - type Opt<'o> = (); - fn decode(raw: &Raw, offset: usize, _: usize, _: Option<()>) -> Result { + fn decode(raw: &Raw, offset: usize, _: usize) -> Result { let mut rd = ReadStream::new(raw, offset); let tag: Tag = rd.read(0)?; let unk1 = rd.read_bytes(0x14)?; diff --git a/src/fot/stream.rs b/src/fot/stream.rs index 365a9e7..b7e166d 100644 --- a/src/fot/stream.rs +++ b/src/fot/stream.rs @@ -1,4 +1,4 @@ -use super::decoder::Decoder; +use super::decoder::{Decoder, DecoderOpt}; use super::raw::Raw; use anyhow::anyhow; use anyhow::Result; @@ -46,14 +46,14 @@ 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: Decoder>(&mut self, size: usize, opt: T::Opt<'o>) -> Result { + 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))?; self.skip(val.get_enc_size()); Ok(val) } pub fn read(&mut self, size: usize) -> Result { - let val = T::decode(&self.raw, self.offset(), size, None)?; + let val = T::decode(&self.raw, self.offset(), size)?; self.skip(val.get_enc_size()); Ok(val) } diff --git a/src/fot/tag.rs b/src/fot/tag.rs index d964491..b21e66f 100644 --- a/src/fot/tag.rs +++ b/src/fot/tag.rs @@ -10,8 +10,7 @@ pub struct Tag { } impl Decoder for Tag { - type Opt<'o> = (); - fn decode(raw: &Raw, offset: usize, size: usize, _: Option<()>) -> Result { + fn decode(raw: &Raw, offset: usize, size: usize) -> Result { let mut rd = ReadStream::new(raw, offset); let name: String = rd.read(0)?; let version: String = rd.read(0)?; diff --git a/src/fot/world.rs b/src/fot/world.rs index 9f74d8a..a5bff36 100644 --- a/src/fot/world.rs +++ b/src/fot/world.rs @@ -67,8 +67,7 @@ impl World { } impl Decoder for World { - type Opt<'o> = (); - fn decode(raw: &Raw, offset: usize, size: usize, _: Option<()>) -> Result { + fn decode(raw: &Raw, offset: usize, size: usize) -> Result { let mut enc = ReadStream::new(raw, offset); let tag: Tag = enc.read(Self::WORLD_TAG_LEN)?;