[−][src]Struct gdb_protocol::packet::CheckedPacket
Methods
impl CheckedPacket
[src]
pub fn assume_checked(unchecked: UncheckedPacket) -> Self
[src]
If you know the packet isn't corrupted, this function bypasses the checksum verification.
pub fn invalidate_check(self) -> UncheckedPacket
[src]
If you intend to mutate the packet's internals, you must first convert it to an unchecked packet so it isn't marked as checked.
pub fn empty() -> Self
[src]
The empty packet is used when you get a packet which you just don't understand. Replying an empty packet means "I don't support this feature".
let mut encoded = Vec::new(); CheckedPacket::empty().encode(&mut encoded); assert_eq!(encoded, b"$#00")
pub fn from_data(kind: Kind, data: Vec<u8>) -> Self
[src]
Creates a packet from the inputted binary data, and generates the checksum from it.
assert_eq!( CheckedPacket::from_data(Kind::Packet, b"Hello, World!".to_vec()).invalidate_check(), UncheckedPacket { kind: Kind::Packet, data: b"Hello, World!".to_vec(), checksum: *b"69" }, )
Methods from Deref<Target = UncheckedPacket>
pub fn expected_checksum(&self) -> Result<u8, Error>
[src]
Return the integer parsed from the hexadecimal expected checksum.
let packet = UncheckedPacket { kind: Kind::Packet, data: b"Hello, World!".to_vec(), checksum: *b"BA", }; assert_eq!(packet.expected_checksum().unwrap(), 186);
pub fn actual_checksum(&self) -> u8
[src]
Return the actual checksum, derived from the data.
let packet = UncheckedPacket { kind: Kind::Packet, data: b"Hello, World!".to_vec(), checksum: *b"BA", }; assert_eq!(packet.actual_checksum(), 105);
As per the GDB specification, this is currently a sum of all characters, modulo 256. The same result can be compared with
(input.bytes().map(|x| usize::from(x)).sum::<usize>() % 256) as u8
however, this function is more efficient and won't go out of bounds.
pub fn is_valid(&self) -> bool
[src]
Returns true if the checksums match.
assert_eq!(UncheckedPacket { kind: Kind::Packet, data: b"Rust is an amazing programming language".to_vec(), checksum: *b"00", }.is_valid(), false); assert_eq!(UncheckedPacket { kind: Kind::Packet, data: b"Rust is an amazing programming language".to_vec(), checksum: *b"ZZ", }.is_valid(), false); assert_eq!(UncheckedPacket { kind: Kind::Packet, data: b"Rust is an amazing programming language".to_vec(), checksum: *b"C7", }.is_valid(), true);
pub fn encode<W>(&self, w: &mut W) -> Result<()> where
W: Write,
[src]
W: Write,
Encode the packet into a long binary string, written to a
writer of choice. You can receive a Vec
let mut encoded = Vec::new(); UncheckedPacket { kind: Kind::Packet, data: b"these must be escaped: # $ } *".to_vec(), checksum: *b"00", }.encode(&mut encoded); assert_eq!( encoded, b"$these must be escaped: }\x03 }\x04 }] }\x0a#00".to_vec() );
Currently multiple series repeated characters aren't shortened, however, this may change at any time and you should not rely on the output of this function being exactly one of multiple representations.
Trait Implementations
impl Clone for CheckedPacket
[src]
fn clone(&self) -> CheckedPacket
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl PartialEq<CheckedPacket> for CheckedPacket
[src]
fn eq(&self, other: &CheckedPacket) -> bool
[src]
fn ne(&self, other: &CheckedPacket) -> bool
[src]
impl Eq for CheckedPacket
[src]
impl Deref for CheckedPacket
[src]
type Target = UncheckedPacket
The resulting type after dereferencing.
fn deref(&self) -> &Self::Target
[src]
impl Debug for CheckedPacket
[src]
Auto Trait Implementations
impl Unpin for CheckedPacket
impl Send for CheckedPacket
impl Sync for CheckedPacket
impl RefUnwindSafe for CheckedPacket
impl UnwindSafe for CheckedPacket
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,