1use byte_transcoder::{reader::ByteReader, reader_error::ByteReaderResult};
2use uuid::Uuid;
3
4#[allow(dead_code)]
5#[derive(Debug)]
6pub struct Payload {
7 game_id: Uuid,
8 join_code: String,
9 lobby: Vec<Account>,
10}
11
12#[derive(Debug)]
13pub struct Account {
14 pub account_id: Uuid,
15 pub username: String,
16}
17
18fn main() -> ByteReaderResult<()> {
19 #[rustfmt::skip]
20 let bytes: Vec<u8> = vec![
21 26, 159, 68, 107, 159, 116, 65, 60, 136, 44, 246, 216, 52, 76, 64, 30,
23
24 4, 84, 111, 100, 100,
26
27 2,
29
30 26, 159, 68, 107, 159, 116, 65, 60, 136, 44, 246, 216, 52, 76, 64, 30,
33 4, 84, 111, 100, 100,
35
36 26, 159, 68, 107, 159, 116, 65, 60, 136, 44, 246, 216, 52, 76, 64, 30,
39 4, 84, 111, 100, 100,
41 ];
42
43 let mut byte_reader: ByteReader = ByteReader::new(&bytes);
44
45 let game_id: Uuid = byte_reader.read_uuid()?;
46 let join_code: String = byte_reader.read_string()?;
47
48 let mut lobby: Vec<Account> = Vec::new();
49 let lobby_len: u8 = byte_reader.read_u8()?;
50 for _ in 0..lobby_len {
51 lobby.push(Account {
52 account_id: byte_reader.read_uuid()?,
53 username: byte_reader.read_string()?,
54 });
55 }
56
57 println!(
58 "{:?}",
59 Payload {
60 game_id,
61 join_code,
62 lobby,
63 }
64 );
65 Ok(())
66}