From 6d7b9f735bed3ebe84bd23d59434c4722e123297 Mon Sep 17 00:00:00 2001 From: mykola2312 <49044616+mykola2312@users.noreply.github.com> Date: Mon, 4 Sep 2023 03:03:51 +0300 Subject: [PATCH] update on EntityList decoding --- src/fot/entitylist.rs | 49 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/fot/entitylist.rs b/src/fot/entitylist.rs index 5c58641..498ab96 100644 --- a/src/fot/entitylist.rs +++ b/src/fot/entitylist.rs @@ -18,6 +18,7 @@ pub struct EntityList { encoding: EntityEncoding, entity_file_tag: Option, entity_tag: Option, + enc_size: usize, types: Vec, entities: Vec @@ -48,3 +49,51 @@ impl EntityList { &self.types[type_idx] } } + +impl DecoderCtx for EntityList { + fn decode(raw: &Raw, offset: usize, size: usize, ctx: EntityEncoding) -> Result { + let mut rd = ReadStream::new(raw, offset); + let mut ent_list = EntityList { + encoding: ctx, + entity_file_tag: None, + entity_tag: None, + enc_size: 0, + types: Vec::new(), + entities: Vec::new() + }; + + Ok(match ctx { + EntityEncoding::File => { + let mut first = true; + while rd.offset() < size { + let tag: Tag = rd.read(0)?; + if (first) { + ent_list.entity_tag = Some(tag); + first = false; + } + + let ent: Entity = rd.read_opt(0, &mut ent_list)?; + ent_list.entities.push(ent); + } + + ent_list.enc_size = rd.offset() - offset; + ent_list + }, + + EntityEncoding::World => { + + + ent_list.enc_size = rd.offset() - offset; + ent_list + } + }) + } + + fn encode(&self, ctx: EntityEncoding) -> Result { + todo!(); + } + + fn get_enc_size(&self) -> usize { + todo!(); + } +}