update on EntityList decoding
This commit is contained in:
parent
ff900bf123
commit
6d7b9f735b
1 changed files with 49 additions and 0 deletions
|
|
@ -18,6 +18,7 @@ pub struct EntityList {
|
|||
encoding: EntityEncoding,
|
||||
entity_file_tag: Option<Tag>,
|
||||
entity_tag: Option<Tag>,
|
||||
enc_size: usize,
|
||||
|
||||
types: Vec<FString>,
|
||||
entities: Vec<Entity>
|
||||
|
|
@ -48,3 +49,51 @@ impl EntityList {
|
|||
&self.types[type_idx]
|
||||
}
|
||||
}
|
||||
|
||||
impl DecoderCtx<EntityEncoding> for EntityList {
|
||||
fn decode(raw: &Raw, offset: usize, size: usize, ctx: EntityEncoding) -> Result<Self> {
|
||||
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<Raw> {
|
||||
todo!();
|
||||
}
|
||||
|
||||
fn get_enc_size(&self) -> usize {
|
||||
todo!();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue