Skip to content

Commit

Permalink
make record data structured in the JSON output
Browse files Browse the repository at this point in the history
  • Loading branch information
tertsdiepraam committed Jun 21, 2024
1 parent d1eaea7 commit 54442bb
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/output/json.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::client::{Answer, Stats};
use bytes::Bytes;
use domain::base::iana::{Class, Opcode};
use domain::base::{Rtype, Ttl};
use domain::base::{ParsedName, Rtype, Ttl};
use domain::rdata::AllRecordData;
use serde::Serialize;
use std::io;
Expand Down Expand Up @@ -41,7 +42,7 @@ struct RecordOutput {
class: Class,
r#type: Rtype,
ttl: Ttl,
data: String,
data: AllRecordData<Bytes, ParsedName<Bytes>>,
}

pub fn write(
Expand Down Expand Up @@ -76,7 +77,7 @@ pub fn write(
class: rec.class(),
r#type: rec.rtype(),
ttl: rec.ttl(),
data: rec.data().to_string(),
data: rec.data().clone(),
});
}

Expand All @@ -85,10 +86,7 @@ pub fn write(
};

for v in [&mut answer, &mut authority, &mut additional] {
let iter =
section.limit_to::<AllRecordData<_, _>>().filter(|i| {
i.as_ref().map_or(true, |i| i.rtype() != Rtype::OPT)
});
let iter = section.limit_to::<AllRecordData<_, _>>();

for rec in iter {
let Ok(rec) = rec else {
Expand All @@ -100,7 +98,7 @@ pub fn write(
class: rec.class(),
r#type: rec.rtype(),
ttl: rec.ttl(),
data: rec.data().to_string(),
data: rec.data().clone(),
});
}

Expand Down

0 comments on commit 54442bb

Please sign in to comment.