pub struct ByteReader<'a> { /* private fields */ }Implementations§
Source§impl<'a> ByteReader<'a>
impl<'a> ByteReader<'a>
Sourcepub fn new(data: &'a [u8]) -> Self
pub fn new(data: &'a [u8]) -> Self
Examples found in repository?
examples/transcode.rs (line 43)
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
fn main() -> ByteReaderResult<()> {
#[rustfmt::skip]
let bytes: Vec<u8> = vec![
// Game ID (UUIDv4)
26, 159, 68, 107, 159, 116, 65, 60, 136, 44, 246, 216, 52, 76, 64, 30,
// Join Code (String)
4, 84, 111, 100, 100,
// Lobby size (u8)
2,
// Account 1
// (UUIDv4)
26, 159, 68, 107, 159, 116, 65, 60, 136, 44, 246, 216, 52, 76, 64, 30,
// (String)
4, 84, 111, 100, 100,
// Account 2
// (UUIDv4)
26, 159, 68, 107, 159, 116, 65, 60, 136, 44, 246, 216, 52, 76, 64, 30,
// (String)
4, 84, 111, 100, 100,
];
let mut byte_reader: ByteReader = ByteReader::new(&bytes);
let game_id: Uuid = byte_reader.read_uuid()?;
let join_code: String = byte_reader.read_string()?;
let mut lobby: Vec<Account> = Vec::new();
let lobby_len: u8 = byte_reader.read_u8()?;
for _ in 0..lobby_len {
lobby.push(Account {
account_id: byte_reader.read_uuid()?,
username: byte_reader.read_string()?,
});
}
println!(
"{:?}",
Payload {
game_id,
join_code,
lobby,
}
);
Ok(())
}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)
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
fn main() -> ByteReaderResult<()> {
#[rustfmt::skip]
let bytes: Vec<u8> = vec![
// Game ID (UUIDv4)
26, 159, 68, 107, 159, 116, 65, 60, 136, 44, 246, 216, 52, 76, 64, 30,
// Join Code (String)
4, 84, 111, 100, 100,
// Lobby size (u8)
2,
// Account 1
// (UUIDv4)
26, 159, 68, 107, 159, 116, 65, 60, 136, 44, 246, 216, 52, 76, 64, 30,
// (String)
4, 84, 111, 100, 100,
// Account 2
// (UUIDv4)
26, 159, 68, 107, 159, 116, 65, 60, 136, 44, 246, 216, 52, 76, 64, 30,
// (String)
4, 84, 111, 100, 100,
];
let mut byte_reader: ByteReader = ByteReader::new(&bytes);
let game_id: Uuid = byte_reader.read_uuid()?;
let join_code: String = byte_reader.read_string()?;
let mut lobby: Vec<Account> = Vec::new();
let lobby_len: u8 = byte_reader.read_u8()?;
for _ in 0..lobby_len {
lobby.push(Account {
account_id: byte_reader.read_uuid()?,
username: byte_reader.read_string()?,
});
}
println!(
"{:?}",
Payload {
game_id,
join_code,
lobby,
}
);
Ok(())
}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_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_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_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)
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
fn main() -> ByteReaderResult<()> {
#[rustfmt::skip]
let bytes: Vec<u8> = vec![
// Game ID (UUIDv4)
26, 159, 68, 107, 159, 116, 65, 60, 136, 44, 246, 216, 52, 76, 64, 30,
// Join Code (String)
4, 84, 111, 100, 100,
// Lobby size (u8)
2,
// Account 1
// (UUIDv4)
26, 159, 68, 107, 159, 116, 65, 60, 136, 44, 246, 216, 52, 76, 64, 30,
// (String)
4, 84, 111, 100, 100,
// Account 2
// (UUIDv4)
26, 159, 68, 107, 159, 116, 65, 60, 136, 44, 246, 216, 52, 76, 64, 30,
// (String)
4, 84, 111, 100, 100,
];
let mut byte_reader: ByteReader = ByteReader::new(&bytes);
let game_id: Uuid = byte_reader.read_uuid()?;
let join_code: String = byte_reader.read_string()?;
let mut lobby: Vec<Account> = Vec::new();
let lobby_len: u8 = byte_reader.read_u8()?;
for _ in 0..lobby_len {
lobby.push(Account {
account_id: byte_reader.read_uuid()?,
username: byte_reader.read_string()?,
});
}
println!(
"{:?}",
Payload {
game_id,
join_code,
lobby,
}
);
Ok(())
}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)
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
fn main() -> ByteReaderResult<()> {
#[rustfmt::skip]
let bytes: Vec<u8> = vec![
// Game ID (UUIDv4)
26, 159, 68, 107, 159, 116, 65, 60, 136, 44, 246, 216, 52, 76, 64, 30,
// Join Code (String)
4, 84, 111, 100, 100,
// Lobby size (u8)
2,
// Account 1
// (UUIDv4)
26, 159, 68, 107, 159, 116, 65, 60, 136, 44, 246, 216, 52, 76, 64, 30,
// (String)
4, 84, 111, 100, 100,
// Account 2
// (UUIDv4)
26, 159, 68, 107, 159, 116, 65, 60, 136, 44, 246, 216, 52, 76, 64, 30,
// (String)
4, 84, 111, 100, 100,
];
let mut byte_reader: ByteReader = ByteReader::new(&bytes);
let game_id: Uuid = byte_reader.read_uuid()?;
let join_code: String = byte_reader.read_string()?;
let mut lobby: Vec<Account> = Vec::new();
let lobby_len: u8 = byte_reader.read_u8()?;
for _ in 0..lobby_len {
lobby.push(Account {
account_id: byte_reader.read_uuid()?,
username: byte_reader.read_string()?,
});
}
println!(
"{:?}",
Payload {
game_id,
join_code,
lobby,
}
);
Ok(())
}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