Trait jvs_packets::WritePacket
source · pub trait WritePacket: Write {
// Provided methods
fn write_packet<P: Packet>(&mut self, packet: &P) -> Result<usize> { ... }
fn write_packet_with_checksum<P: Packet>(
&mut self,
packet: &P
) -> Result<usize> { ... }
}Expand description
A helper trait which implemented for std::io::Write. Contains methods for writing Packets to the Writer.
It is better to use std::io::BufWriter to avoid unnecessary syscalls, since we have to read one byte at a time to check for escaped by MARK_BYTE bytes.
Provided Methods§
sourcefn write_packet<P: Packet>(&mut self, packet: &P) -> Result<usize>
fn write_packet<P: Packet>(&mut self, packet: &P) -> Result<usize>
Writes a packet to the Writer.
The function doesn’t calculate checksum and instead writes whatever is present in the packet itself. So you have to use Packet::calculate_checksum before writing.
Use Self::write_packet_with_checksum to calculate checksum while writing bytes.
§Errors
Will return Err if Packet::len_of_packet less than Packet::DATA_BEGIN_INDEX + 1 which is nonsense.
sourcefn write_packet_with_checksum<P: Packet>(&mut self, packet: &P) -> Result<usize>
fn write_packet_with_checksum<P: Packet>(&mut self, packet: &P) -> Result<usize>
Similar to WritePacket::write_packet, but it will calculate checksum while writing bytes to the writer.
§Errors
Will return Err if Packet::len_of_packet less than Packet::DATA_BEGIN_INDEX + 1 which is nonsense.