Skip to main content

steel_protocol/packets/common/
c_transfer.rs

1use std::io::{Result, Write};
2
3use steel_macros::ClientPacket;
4use steel_registry::packets::{config, play};
5use steel_utils::{
6    codec::VarInt,
7    serial::{PrefixedWrite, WriteTo},
8};
9
10#[derive(ClientPacket, Clone, Debug)]
11#[packet_id(Config = config::C_TRANSFER, Play = play::C_TRANSFER)]
12pub struct CTransfer<'a> {
13    pub host: &'a str,
14    pub port: i32,
15}
16
17impl<'a> CTransfer<'a> {
18    #[must_use]
19    pub const fn new(host: &'a str, port: i32) -> Self {
20        Self { host, port }
21    }
22}
23
24impl WriteTo for CTransfer<'_> {
25    fn write(&self, writer: &mut impl Write) -> Result<()> {
26        self.host.write_prefixed::<VarInt>(writer)?;
27        VarInt(self.port).write(writer)
28    }
29}