cube_engine/protocol/pk/spawn.rs
1/*
2 * cube-engine
3 *
4 * Copyright (C) 2019 SOFe
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published
8 * by the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20use std::io::{Read, Write};
21
22use crate::io::flex::FlexPos;
23use crate::io::reader::CubeReader;
24use crate::io::writer::CubeWriter;
25use crate::util::{IoResult, VioResult};
26
27pub const PK_SPAWN_SPAWN: u16 = 0x0201;
28
29pub struct Spawn {
30 pos: FlexPos,
31}
32
33impl Spawn {
34 pub fn write<W: Write>(&self, writer: &mut CubeWriter<W>) -> VioResult {
35 writer.write_uint16(PK_SPAWN_SPAWN)?;
36 writer.write_flex_pos(&self.pos)?;
37 Result::Ok(())
38 }
39
40 pub fn read<R: Read>(reader: &mut CubeReader<R>) -> IoResult<Spawn> {
41 Result::Ok(Spawn {
42 pos: reader.read_flex_pos()?,
43 })
44 }
45}