rpfm_lib/files/bmd/deployment_list/deployment_area/deployment_zone/
mod.rs

1//---------------------------------------------------------------------------//
2// Copyright (c) 2017-2024 Ismael Gutiérrez González. All rights reserved.
3//
4// This file is part of the Rusted PackFile Manager (RPFM) project,
5// which can be found here: https://github.com/Frodo45127/rpfm.
6//
7// This file is licensed under the MIT license, which can be found here:
8// https://github.com/Frodo45127/rpfm/blob/master/LICENSE.
9//---------------------------------------------------------------------------//
10
11use getset::*;
12use serde_derive::{Serialize, Deserialize};
13
14use crate::binary::{ReadBytes, WriteBytes};
15use crate::error::{Result, RLibError};
16use crate::files::{Decodeable, EncodeableExtraData, Encodeable};
17
18use self::deployment_region::DeploymentRegion;
19
20use super::*;
21
22mod deployment_region;
23mod v1;
24
25//---------------------------------------------------------------------------//
26//                              Enum & Structs
27//---------------------------------------------------------------------------//
28
29#[derive(Default, PartialEq, Clone, Debug, Getters, MutGetters, Setters, Serialize, Deserialize)]
30#[getset(get = "pub", get_mut = "pub", set = "pub")]
31pub struct DeploymentZone {
32    serialise_version: u16,
33    deployment_regions: Vec<DeploymentRegion>,
34}
35
36//---------------------------------------------------------------------------//
37//                   Implementation of DeploymentZone
38//---------------------------------------------------------------------------//
39
40impl Decodeable for DeploymentZone {
41
42    fn decode<R: ReadBytes>(data: &mut R, extra_data: &Option<DecodeableExtraData>) -> Result<Self> {
43        let mut decoded = Self::default();
44        decoded.serialise_version = data.read_u16()?;
45
46        match decoded.serialise_version {
47            1 => decoded.read_v1(data, extra_data)?,
48            _ => return Err(RLibError::DecodingFastBinUnsupportedVersion(String::from("DeploymentZone"), decoded.serialise_version)),
49        }
50
51        Ok(decoded)
52    }
53}
54
55impl Encodeable for DeploymentZone {
56
57    fn encode<W: WriteBytes>(&mut self, buffer: &mut W, extra_data: &Option<EncodeableExtraData>) -> Result<()> {
58        buffer.write_u16(self.serialise_version)?;
59
60        match self.serialise_version {
61            1 => self.write_v1(buffer, extra_data)?,
62            _ => return Err(RLibError::EncodingFastBinUnsupportedVersion(String::from("DeploymentZone"), self.serialise_version)),
63        }
64
65        Ok(())
66    }
67}