~kf5jwc/dns-server-rs

48db22e4e8b928803616d0e6e126bd8cf64ca934 — Kyle Jones 6 months ago db92469
Preparation for setting bits in byte buffers
1 files changed, 17 insertions(+), 0 deletions(-)

M src/dns_packet/byte_packet_buffer.rs
M src/dns_packet/byte_packet_buffer.rs => src/dns_packet/byte_packet_buffer.rs +17 -0
@@ 164,4 164,21 @@ impl BytePacketBuffer {
        Ok(())
    }

    fn set(&mut self, pos: usize, val: u8) -> Result<()> {
        self.buf[pos] = val;
        Ok(())
    }

    pub fn set_u8(&mut self, pos: usize, val: u8) -> Result<()> {
        self.set(pos, val)
    }

    pub fn set_u16(&mut self, pos: usize, val: u16) -> Result<()> {
        let shifts: &[u8] = &[8, 0];
        for (pos_modifier, shift) in shifts.iter().enumerate() {
            self.set(pos+pos_modifier, ((val >> shift) & 0xFF) as u8)?
        }
        Ok(())
    }

}