[][src]Struct gdb_protocol::packet::UncheckedPacket

pub struct UncheckedPacket {
    pub kind: Kind,
    pub data: Vec<u8>,
    pub checksum: [u8; 2],
}

Fields

kind: Kinddata: Vec<u8>checksum: [u8; 2]

Methods

impl UncheckedPacket[src]

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 check(self) -> Option<CheckedPacket>[src]

Will return a checked packet if, and only if, the checksums match. If you know the packet wasn't corrupted and want to bypass the check, use CheckedPacket::assume_checked.

pub fn encode<W>(&self, w: &mut W) -> Result<()> where
    W: Write
[src]

Encode the packet into a long binary string, written to a writer of choice. You can receive a Vec by taking advantage of the fact that they implement io::Write:

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 UncheckedPacket[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl PartialEq<UncheckedPacket> for UncheckedPacket[src]

impl Eq for UncheckedPacket[src]

impl Debug for UncheckedPacket[src]

Auto Trait Implementations

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]