use crate::query::QueryBuf;
pub(crate) fn read_u8(inp: &mut &[u8]) -> Result<u8, ()> {
- let res = *inp.get(0).ok_or(())?;
+ let res = *inp.first().ok_or(())?;
*inp = &inp[1..];
Ok(res)
}
}
pub(crate) fn read_u8_len_prefixed_bytes(inp: &mut &[u8]) -> Result<Vec<u8>, ()> {
- let len = *inp.get(0).ok_or(())?;
+ let len = *inp.first().ok_or(())?;
*inp = &inp[1..];
if inp.len() < len.into() { return Err(()); }
let mut res = Vec::with_capacity(len.into());
pub(crate) fn write_nsec_types_bitmap<W: Writer>(out: &mut W, types: &[u8; 8192]) {
for (idx, flags) in types.chunks(32).enumerate() {
debug_assert_eq!(flags.len(), 32);
- if flags != &[0; 32] {
+ if flags != [0; 32] {
let last_nonzero_idx = flags.iter().rposition(|flag| *flag != 0)
.unwrap_or_else(|| { debug_assert!(false); 0 });
out.write(&(idx as u8).to_be_bytes());
let mut total_len = 0;
for flags in types.chunks(32) {
debug_assert_eq!(flags.len(), 32);
- if flags != &[0; 32] {
+ if flags != [0; 32] {
total_len += 3 + flags.iter().rposition(|flag| *flag != 0)
.unwrap_or_else(|| { debug_assert!(false); 0 }) as u16;
}
pub(crate) fn read_wire_packet_name(inp: &mut &[u8], wire_packet: &[u8]) -> Result<Name, ()> {
let mut name = String::with_capacity(1024);
read_wire_packet_labels(inp, wire_packet, &mut name)?;
- Ok(name.try_into()?)
+ name.try_into()
}
pub(crate) trait Writer { fn write(&mut self, buf: &[u8]); }
if canonical_name == "." {
out.write(&[0]);
} else {
- for label in canonical_name.split(".") {
+ for label in canonical_name.split('.') {
out.write(&(label.len() as u8).to_be_bytes());
out.write(label.as_bytes());
}
1
} else {
let mut res = 0;
- for label in name.split(".") {
+ for label in name.split('.') {
res += 1 + label.len();
}
res as u16