pub struct ByteReader<'a> { /* private fields */ }
Implementations§
Source§impl<'a> ByteReader<'a>
impl<'a> ByteReader<'a>
Sourcepub fn new(data: &'a [u8], endian: Endian) -> Self
pub fn new(data: &'a [u8], endian: Endian) -> Self
Examples found in repository?
examples/transcode.rs (line 43)
18fn main() -> ByteReaderResult<()> {
19 #[rustfmt::skip]
20 let bytes: Vec<u8> = vec![
21 // Game ID (UUIDv4)
22 26, 159, 68, 107, 159, 116, 65, 60, 136, 44, 246, 216, 52, 76, 64, 30,
23
24 // Join Code (String)
25 4, 84, 111, 100, 100,
26
27 // Lobby size (u8)
28 2,
29
30 // Account 1
31 // (UUIDv4)
32 26, 159, 68, 107, 159, 116, 65, 60, 136, 44, 246, 216, 52, 76, 64, 30,
33 // (String)
34 4, 84, 111, 100, 100,
35
36 // Account 2
37 // (UUIDv4)
38 26, 159, 68, 107, 159, 116, 65, 60, 136, 44, 246, 216, 52, 76, 64, 30,
39 // (String)
40 4, 84, 111, 100, 100,
41 ];
42
43 let mut byte_reader: ByteReader = ByteReader::new(&bytes, Endian::Little);
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}
Sourcepub fn read_u8(&mut self) -> ByteReaderResult<u8>
pub fn read_u8(&mut self) -> ByteReaderResult<u8>
§Errors
Will return an error if there are not enough bytes to read.
Examples found in repository?
examples/transcode.rs (line 49)
18fn main() -> ByteReaderResult<()> {
19 #[rustfmt::skip]
20 let bytes: Vec<u8> = vec![
21 // Game ID (UUIDv4)
22 26, 159, 68, 107, 159, 116, 65, 60, 136, 44, 246, 216, 52, 76, 64, 30,
23
24 // Join Code (String)
25 4, 84, 111, 100, 100,
26
27 // Lobby size (u8)
28 2,
29
30 // Account 1
31 // (UUIDv4)
32 26, 159, 68, 107, 159, 116, 65, 60, 136, 44, 246, 216, 52, 76, 64, 30,
33 // (String)
34 4, 84, 111, 100, 100,
35
36 // Account 2
37 // (UUIDv4)
38 26, 159, 68, 107, 159, 116, 65, 60, 136, 44, 246, 216, 52, 76, 64, 30,
39 // (String)
40 4, 84, 111, 100, 100,
41 ];
42
43 let mut byte_reader: ByteReader = ByteReader::new(&bytes, Endian::Little);
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}
Sourcepub fn read_i8(&mut self) -> ByteReaderResult<i8>
pub fn read_i8(&mut self) -> ByteReaderResult<i8>
§Errors
Will return an error if there are not enough bytes to read.
Sourcepub fn read_u16(&mut self) -> ByteReaderResult<u16>
pub fn read_u16(&mut self) -> ByteReaderResult<u16>
§Errors
Will return an error if there are not enough bytes to read.
Sourcepub fn read_i16(&mut self) -> ByteReaderResult<i16>
pub fn read_i16(&mut self) -> ByteReaderResult<i16>
§Errors
Will return an error if there are not enough bytes to read.
Sourcepub fn read_u32(&mut self) -> ByteReaderResult<u32>
pub fn read_u32(&mut self) -> ByteReaderResult<u32>
§Errors
Will return an error if there are not enough bytes to read.
Sourcepub fn read_i32(&mut self) -> ByteReaderResult<i32>
pub fn read_i32(&mut self) -> ByteReaderResult<i32>
§Errors
Will return an error if there are not enough bytes to read.
Sourcepub fn read_u64(&mut self) -> ByteReaderResult<u64>
pub fn read_u64(&mut self) -> ByteReaderResult<u64>
§Errors
Will return an error if there are not enough bytes to read.
Sourcepub fn read_i64(&mut self) -> ByteReaderResult<i64>
pub fn read_i64(&mut self) -> ByteReaderResult<i64>
§Errors
Will return an error if there are not enough bytes to read.
Sourcepub fn read_string(&mut self) -> ByteReaderResult<String>
pub fn read_string(&mut self) -> ByteReaderResult<String>
§Errors
Will return an error if there are not enough bytes to read or if the UTF-8 bytes are invalid.
Examples found in repository?
examples/transcode.rs (line 46)
18fn main() -> ByteReaderResult<()> {
19 #[rustfmt::skip]
20 let bytes: Vec<u8> = vec![
21 // Game ID (UUIDv4)
22 26, 159, 68, 107, 159, 116, 65, 60, 136, 44, 246, 216, 52, 76, 64, 30,
23
24 // Join Code (String)
25 4, 84, 111, 100, 100,
26
27 // Lobby size (u8)
28 2,
29
30 // Account 1
31 // (UUIDv4)
32 26, 159, 68, 107, 159, 116, 65, 60, 136, 44, 246, 216, 52, 76, 64, 30,
33 // (String)
34 4, 84, 111, 100, 100,
35
36 // Account 2
37 // (UUIDv4)
38 26, 159, 68, 107, 159, 116, 65, 60, 136, 44, 246, 216, 52, 76, 64, 30,
39 // (String)
40 4, 84, 111, 100, 100,
41 ];
42
43 let mut byte_reader: ByteReader = ByteReader::new(&bytes, Endian::Little);
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}
Sourcepub fn read_uuid(&mut self) -> ByteReaderResult<Uuid>
pub fn read_uuid(&mut self) -> ByteReaderResult<Uuid>
§Errors
Will return an error if there are not enough bytes to read or if the UUID bytes are invalid.
Examples found in repository?
examples/transcode.rs (line 45)
18fn main() -> ByteReaderResult<()> {
19 #[rustfmt::skip]
20 let bytes: Vec<u8> = vec![
21 // Game ID (UUIDv4)
22 26, 159, 68, 107, 159, 116, 65, 60, 136, 44, 246, 216, 52, 76, 64, 30,
23
24 // Join Code (String)
25 4, 84, 111, 100, 100,
26
27 // Lobby size (u8)
28 2,
29
30 // Account 1
31 // (UUIDv4)
32 26, 159, 68, 107, 159, 116, 65, 60, 136, 44, 246, 216, 52, 76, 64, 30,
33 // (String)
34 4, 84, 111, 100, 100,
35
36 // Account 2
37 // (UUIDv4)
38 26, 159, 68, 107, 159, 116, 65, 60, 136, 44, 246, 216, 52, 76, 64, 30,
39 // (String)
40 4, 84, 111, 100, 100,
41 ];
42
43 let mut byte_reader: ByteReader = ByteReader::new(&bytes, Endian::Little);
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}
pub fn read_remaining_bytes(&mut self) -> Vec<u8> ⓘ
pub fn is_empty(&self) -> bool
pub fn remaining(&self) -> usize
Auto Trait Implementations§
impl<'a> Freeze for ByteReader<'a>
impl<'a> RefUnwindSafe for ByteReader<'a>
impl<'a> Send for ByteReader<'a>
impl<'a> Sync for ByteReader<'a>
impl<'a> Unpin for ByteReader<'a>
impl<'a> UnwindSafe for ByteReader<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more