DSL

Use the following imports for the examples:

import com.github.mkroli.dns4s._
import com.github.mkroli.dns4s.dsl._
import com.github.mkroli.dns4s.section._
import com.github.mkroli.dns4s.section.resource._

Header

ID

// Creation
val msg: Message = Query ~ Id(123)
// msg: Message = Message(
//   HeaderSection(123, false, 0, false, false, true, false, 0, 0, 0, 0, 0),
//   List(),
//   List(),
//   List(),
//   List()
// )

// Matching
val id = msg match {
  case Id(id) => id
}
// id: Int = 123

QR

// Creation
val query: Message = Query
// query: Message = Message(
//   HeaderSection(0, false, 0, false, false, true, false, 0, 0, 0, 0, 0),
//   List(),
//   List(),
//   List(),
//   List()
// )
val response1: Message = Response
// response1: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 0, 0, 0, 0),
//   List(),
//   List(),
//   List(),
//   List()
// )
val response2: Message = Response(query)
// response2: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 0, 0, 0, 0),
//   List(),
//   List(),
//   List(),
//   List()
// )

// Matching
val qr = query match {
  case Query(msg)    => "query"
  case Response(msg) => "response"
}
// qr: String = "query"

Opcode

// Creation
val query1: Message = Query ~ StandardQuery
// query1: Message = Message(
//   HeaderSection(0, false, 0, false, false, true, false, 0, 0, 0, 0, 0),
//   List(),
//   List(),
//   List(),
//   List()
// )
val query2: Message = Query ~ InverseQuery
// query2: Message = Message(
//   HeaderSection(0, false, 1, false, false, true, false, 0, 0, 0, 0, 0),
//   List(),
//   List(),
//   List(),
//   List()
// )
val query3: Message = Query ~ ServerStatusRequest
// query3: Message = Message(
//   HeaderSection(0, false, 2, false, false, true, false, 0, 0, 0, 0, 0),
//   List(),
//   List(),
//   List(),
//   List()
// )

// Matching
val op = query1 match {
  case StandardQuery()       => "standard-query"
  case InverseQuery()        => "inverse-query"
  case ServerStatusRequest() => "server-status-request"
}
// op: String = "standard-query"

AA

// Creation
val response: Message = Response ~ AuthoritativeAnswer
// response: Message = Message(
//   HeaderSection(0, true, 0, true, false, true, false, 0, 0, 0, 0, 0),
//   List(),
//   List(),
//   List(),
//   List()
// )

// Matching
val aa = response match {
  case AuthoritativeAnswer() => true
  case _ => false
}
// aa: Boolean = true

TC

// Creation
val response: Message = Response ~ Truncation
// response: Message = Message(
//   HeaderSection(0, true, 0, false, true, true, false, 0, 0, 0, 0, 0),
//   List(),
//   List(),
//   List(),
//   List()
// )

// Matching
val tc = response match {
  case Truncation() => true
  case _ => false
}
// tc: Boolean = true

RD

// Creation
val query: Message = Query ~ RecursionDesired
// query: Message = Message(
//   HeaderSection(0, false, 0, false, false, true, false, 0, 0, 0, 0, 0),
//   List(),
//   List(),
//   List(),
//   List()
// )

// Matching
val rd = query match {
  case RecursionDesired() => true
  case _ => false
}
// rd: Boolean = true

RA

// Creation
val response: Message = Response ~ RecursionAvailable
// response: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, true, 0, 0, 0, 0, 0),
//   List(),
//   List(),
//   List(),
//   List()
// )

// Matching
val ra = response match {
  case RecursionAvailable() => true
  case _ => false
}
// ra: Boolean = true

RCODE

// Creation
val response1: Message = Response ~ NoError
// response1: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 0, 0, 0, 0),
//   List(),
//   List(),
//   List(),
//   List()
// )
val response2: Message = Response ~ FormatError
// response2: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 1, 0, 0, 0, 0),
//   List(),
//   List(),
//   List(),
//   List()
// )
val response3: Message = Response ~ ServerFailure
// response3: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 2, 0, 0, 0, 0),
//   List(),
//   List(),
//   List(),
//   List()
// )
val response4: Message = Response ~ NameError
// response4: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 3, 0, 0, 0, 0),
//   List(),
//   List(),
//   List(),
//   List()
// )
val response5: Message = Response ~ NotImplemented
// response5: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 4, 0, 0, 0, 0),
//   List(),
//   List(),
//   List(),
//   List()
// )
val response6: Message = Response ~ Refused
// response6: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 5, 0, 0, 0, 0),
//   List(),
//   List(),
//   List(),
//   List()
// )

// Matching
val rCode = response1 match {
  case Response(r) ~ NoError()        => "no-error"
  case Response(r) ~ FormatError()    => "format-error"
  case Response(r) ~ ServerFailure()  => "server-failure"
  case Response(r) ~ NameError()      => "name-error"
  case Response(r) ~ NotImplemented() => "not-implemented"
  case Response(r) ~ Refused()        => "refused"
}
// rCode: String = "no-error"

Sections

Question section

// Creation
val query: Message = Query ~ Questions()
// query: Message = Message(
//   HeaderSection(0, false, 0, false, false, true, false, 0, 0, 0, 0, 0),
//   List(),
//   List(),
//   List(),
//   List()
// )

// Matching
val questions = query match {
  case Query(_) ~ Questions(questions) => questions
}
// questions: Seq[QuestionSection] = List()

QNAME

// Creation
val query1: Message = Query ~ Questions(QName("example.com"))
// query1: Message = Message(
//   HeaderSection(0, false, 0, false, false, true, false, 0, 1, 0, 0, 0),
//   List(QuestionSection("example.com", 1, 1)),
//   List(),
//   List(),
//   List()
// )
val query2: Message = Query ~ Questions(QName("example.com"), QName("www.example.com"))
// query2: Message = Message(
//   HeaderSection(0, false, 0, false, false, true, false, 0, 2, 0, 0, 0),
//   List(
//     QuestionSection("example.com", 1, 1),
//     QuestionSection("www.example.com", 1, 1)
//   ),
//   List(),
//   List(),
//   List()
// )

// Matching
val names = query2 match {
  case Query(_) ~ Questions(QName(name1) :: QName(name2) :: Nil) => (name1, name2)
}
// names: (String, String) = ("example.com", "www.example.com")

QTYPE

// Creation
val query: Message = Query ~ Questions(QName("example.com") ~ QType(ResourceRecord.typeTXT))
// query: Message = Message(
//   HeaderSection(0, false, 0, false, false, true, false, 0, 1, 0, 0, 0),
//   List(QuestionSection("example.com", 16, 1)),
//   List(),
//   List(),
//   List()
// )

val queryA:        Message = Query ~ Questions(QName("example.com") ~ TypeA)
// queryA: Message = Message(
//   HeaderSection(0, false, 0, false, false, true, false, 0, 1, 0, 0, 0),
//   List(QuestionSection("example.com", 1, 1)),
//   List(),
//   List(),
//   List()
// )
val queryNS:       Message = Query ~ Questions(QName("example.com") ~ TypeNS)
// queryNS: Message = Message(
//   HeaderSection(0, false, 0, false, false, true, false, 0, 1, 0, 0, 0),
//   List(QuestionSection("example.com", 2, 1)),
//   List(),
//   List(),
//   List()
// )
val queryMD:       Message = Query ~ Questions(QName("example.com") ~ TypeMD)
// queryMD: Message = Message(
//   HeaderSection(0, false, 0, false, false, true, false, 0, 1, 0, 0, 0),
//   List(QuestionSection("example.com", 3, 1)),
//   List(),
//   List(),
//   List()
// )
val queryMF:       Message = Query ~ Questions(QName("example.com") ~ TypeMF)
// queryMF: Message = Message(
//   HeaderSection(0, false, 0, false, false, true, false, 0, 1, 0, 0, 0),
//   List(QuestionSection("example.com", 4, 1)),
//   List(),
//   List(),
//   List()
// )
val queryCNAME:    Message = Query ~ Questions(QName("example.com") ~ TypeCNAME)
// queryCNAME: Message = Message(
//   HeaderSection(0, false, 0, false, false, true, false, 0, 1, 0, 0, 0),
//   List(QuestionSection("example.com", 5, 1)),
//   List(),
//   List(),
//   List()
// )
val querySOA:      Message = Query ~ Questions(QName("example.com") ~ TypeSOA)
// querySOA: Message = Message(
//   HeaderSection(0, false, 0, false, false, true, false, 0, 1, 0, 0, 0),
//   List(QuestionSection("example.com", 6, 1)),
//   List(),
//   List(),
//   List()
// )
val queryMB:       Message = Query ~ Questions(QName("example.com") ~ TypeMB)
// queryMB: Message = Message(
//   HeaderSection(0, false, 0, false, false, true, false, 0, 1, 0, 0, 0),
//   List(QuestionSection("example.com", 7, 1)),
//   List(),
//   List(),
//   List()
// )
val queryMG:       Message = Query ~ Questions(QName("example.com") ~ TypeMG)
// queryMG: Message = Message(
//   HeaderSection(0, false, 0, false, false, true, false, 0, 1, 0, 0, 0),
//   List(QuestionSection("example.com", 8, 1)),
//   List(),
//   List(),
//   List()
// )
val queryMR:       Message = Query ~ Questions(QName("example.com") ~ TypeMR)
// queryMR: Message = Message(
//   HeaderSection(0, false, 0, false, false, true, false, 0, 1, 0, 0, 0),
//   List(QuestionSection("example.com", 9, 1)),
//   List(),
//   List(),
//   List()
// )
val queryNULL:     Message = Query ~ Questions(QName("example.com") ~ TypeNULL)
// queryNULL: Message = Message(
//   HeaderSection(0, false, 0, false, false, true, false, 0, 1, 0, 0, 0),
//   List(QuestionSection("example.com", 10, 1)),
//   List(),
//   List(),
//   List()
// )
val queryWKS:      Message = Query ~ Questions(QName("example.com") ~ TypeWKS)
// queryWKS: Message = Message(
//   HeaderSection(0, false, 0, false, false, true, false, 0, 1, 0, 0, 0),
//   List(QuestionSection("example.com", 11, 1)),
//   List(),
//   List(),
//   List()
// )
val queryPTR:      Message = Query ~ Questions(QName("example.com") ~ TypePTR)
// queryPTR: Message = Message(
//   HeaderSection(0, false, 0, false, false, true, false, 0, 1, 0, 0, 0),
//   List(QuestionSection("example.com", 12, 1)),
//   List(),
//   List(),
//   List()
// )
val queryHINFO:    Message = Query ~ Questions(QName("example.com") ~ TypeHINFO)
// queryHINFO: Message = Message(
//   HeaderSection(0, false, 0, false, false, true, false, 0, 1, 0, 0, 0),
//   List(QuestionSection("example.com", 13, 1)),
//   List(),
//   List(),
//   List()
// )
val queryMINFO:    Message = Query ~ Questions(QName("example.com") ~ TypeMINFO)
// queryMINFO: Message = Message(
//   HeaderSection(0, false, 0, false, false, true, false, 0, 1, 0, 0, 0),
//   List(QuestionSection("example.com", 14, 1)),
//   List(),
//   List(),
//   List()
// )
val queryMX:       Message = Query ~ Questions(QName("example.com") ~ TypeMX)
// queryMX: Message = Message(
//   HeaderSection(0, false, 0, false, false, true, false, 0, 1, 0, 0, 0),
//   List(QuestionSection("example.com", 15, 1)),
//   List(),
//   List(),
//   List()
// )
val queryTXT:      Message = Query ~ Questions(QName("example.com") ~ TypeTXT)
// queryTXT: Message = Message(
//   HeaderSection(0, false, 0, false, false, true, false, 0, 1, 0, 0, 0),
//   List(QuestionSection("example.com", 16, 1)),
//   List(),
//   List(),
//   List()
// )
val queryAAAA:     Message = Query ~ Questions(QName("example.com") ~ TypeAAAA)
// queryAAAA: Message = Message(
//   HeaderSection(0, false, 0, false, false, true, false, 0, 1, 0, 0, 0),
//   List(QuestionSection("example.com", 28, 1)),
//   List(),
//   List(),
//   List()
// )
val querySRV:      Message = Query ~ Questions(QName("example.com") ~ TypeSRV)
// querySRV: Message = Message(
//   HeaderSection(0, false, 0, false, false, true, false, 0, 1, 0, 0, 0),
//   List(QuestionSection("example.com", 33, 1)),
//   List(),
//   List(),
//   List()
// )
val queryNAPTR:    Message = Query ~ Questions(QName("example.com") ~ TypeNAPTR)
// queryNAPTR: Message = Message(
//   HeaderSection(0, false, 0, false, false, true, false, 0, 1, 0, 0, 0),
//   List(QuestionSection("example.com", 35, 1)),
//   List(),
//   List(),
//   List()
// )
val queryOPT:      Message = Query ~ Questions(QName("example.com") ~ TypeOPT)
// queryOPT: Message = Message(
//   HeaderSection(0, false, 0, false, false, true, false, 0, 1, 0, 0, 0),
//   List(QuestionSection("example.com", 41, 1)),
//   List(),
//   List(),
//   List()
// )
val queryAXFR:     Message = Query ~ Questions(QName("example.com") ~ TypeAXFR)
// queryAXFR: Message = Message(
//   HeaderSection(0, false, 0, false, false, true, false, 0, 1, 0, 0, 0),
//   List(QuestionSection("example.com", 252, 1)),
//   List(),
//   List(),
//   List()
// )
val queryMAILB:    Message = Query ~ Questions(QName("example.com") ~ TypeMAILB)
// queryMAILB: Message = Message(
//   HeaderSection(0, false, 0, false, false, true, false, 0, 1, 0, 0, 0),
//   List(QuestionSection("example.com", 253, 1)),
//   List(),
//   List(),
//   List()
// )
val queryMAILA:    Message = Query ~ Questions(QName("example.com") ~ TypeMAILA)
// queryMAILA: Message = Message(
//   HeaderSection(0, false, 0, false, false, true, false, 0, 1, 0, 0, 0),
//   List(QuestionSection("example.com", 254, 1)),
//   List(),
//   List(),
//   List()
// )
val queryAsterisk: Message = Query ~ Questions(QName("example.com") ~ TypeAsterisk)
// queryAsterisk: Message = Message(
//   HeaderSection(0, false, 0, false, false, true, false, 0, 1, 0, 0, 0),
//   List(QuestionSection("example.com", 255, 1)),
//   List(),
//   List(),
//   List()
// )

// Matching
val `type` = query match {
  case Query(q) ~ Questions(QName(name) ~ TypeA()        :: Nil) => "A"
  case Query(q) ~ Questions(QName(name) ~ TypeNS()       :: Nil) => "NS"
  case Query(q) ~ Questions(QName(name) ~ TypeMD()       :: Nil) => "MD"
  case Query(q) ~ Questions(QName(name) ~ TypeMF()       :: Nil) => "MF"
  case Query(q) ~ Questions(QName(name) ~ TypeCNAME()    :: Nil) => "CNAME"
  case Query(q) ~ Questions(QName(name) ~ TypeSOA()      :: Nil) => "SOA"
  case Query(q) ~ Questions(QName(name) ~ TypeMB()       :: Nil) => "MB"
  case Query(q) ~ Questions(QName(name) ~ TypeMG()       :: Nil) => "MG"
  case Query(q) ~ Questions(QName(name) ~ TypeMR()       :: Nil) => "MR"
  case Query(q) ~ Questions(QName(name) ~ TypeNULL()     :: Nil) => "NULL"
  case Query(q) ~ Questions(QName(name) ~ TypeWKS()      :: Nil) => "WKS"
  case Query(q) ~ Questions(QName(name) ~ TypePTR()      :: Nil) => "PTR"
  case Query(q) ~ Questions(QName(name) ~ TypeHINFO()    :: Nil) => "HINFO"
  case Query(q) ~ Questions(QName(name) ~ TypeMINFO()    :: Nil) => "MINFO"
  case Query(q) ~ Questions(QName(name) ~ TypeMX()       :: Nil) => "MX"
  case Query(q) ~ Questions(QName(name) ~ TypeTXT()      :: Nil) => "TXT"
  case Query(q) ~ Questions(QName(name) ~ TypeAAAA()     :: Nil) => "AAAA"
  case Query(q) ~ Questions(QName(name) ~ TypeSRV()      :: Nil) => "SRV"
  case Query(q) ~ Questions(QName(name) ~ TypeNAPTR()    :: Nil) => "NAPTR"
  case Query(q) ~ Questions(QName(name) ~ TypeOPT()      :: Nil) => "OPT"
  case Query(q) ~ Questions(QName(name) ~ TypeAXFR()     :: Nil) => "AXFR"
  case Query(q) ~ Questions(QName(name) ~ TypeMAILB()    :: Nil) => "MAILB"
  case Query(q) ~ Questions(QName(name) ~ TypeMAILA()    :: Nil) => "MAILA"
  case Query(q) ~ Questions(QName(name) ~ TypeAsterisk() :: Nil) => "Asterisk"

  case Query(q) ~ Questions(QName(name) ~ QType(t) :: Nil) => t.toString
}
// `type`: String = "TXT"

QCLASS

// Creation
val query: Message = Query ~ Questions(QName("example.com") ~ QType(ResourceRecord.typeA) ~ QClass(ResourceRecord.classIN))
// query: Message = Message(
//   HeaderSection(0, false, 0, false, false, true, false, 0, 1, 0, 0, 0),
//   List(QuestionSection("example.com", 1, 1)),
//   List(),
//   List(),
//   List()
// )

val queryIN:       Message = Query ~ Questions(QName("example.com") ~ TypeA ~ ClassIN)
// queryIN: Message = Message(
//   HeaderSection(0, false, 0, false, false, true, false, 0, 1, 0, 0, 0),
//   List(QuestionSection("example.com", 1, 1)),
//   List(),
//   List(),
//   List()
// )
val queryCS:       Message = Query ~ Questions(QName("example.com") ~ TypeA ~ ClassCS)
// queryCS: Message = Message(
//   HeaderSection(0, false, 0, false, false, true, false, 0, 1, 0, 0, 0),
//   List(QuestionSection("example.com", 1, 2)),
//   List(),
//   List(),
//   List()
// )
val queryCH:       Message = Query ~ Questions(QName("example.com") ~ TypeA ~ ClassCH)
// queryCH: Message = Message(
//   HeaderSection(0, false, 0, false, false, true, false, 0, 1, 0, 0, 0),
//   List(QuestionSection("example.com", 1, 3)),
//   List(),
//   List(),
//   List()
// )
val queryHS:       Message = Query ~ Questions(QName("example.com") ~ TypeA ~ ClassHS)
// queryHS: Message = Message(
//   HeaderSection(0, false, 0, false, false, true, false, 0, 1, 0, 0, 0),
//   List(QuestionSection("example.com", 1, 4)),
//   List(),
//   List(),
//   List()
// )
val queryAsterisk: Message = Query ~ Questions(QName("example.com") ~ TypeA ~ ClassAsterisk)
// queryAsterisk: Message = Message(
//   HeaderSection(0, false, 0, false, false, true, false, 0, 1, 0, 0, 0),
//   List(QuestionSection("example.com", 1, 255)),
//   List(),
//   List(),
//   List()
// )

// Matching
val qclass = query match {
  case Query(q) ~ Questions(QName(name) ~ QType(t) ~ QClass(c) :: Nil) => c

  case Query(q) ~ Questions(QName(name) ~ TypeA() ~ ClassIN() :: Nil) => ???
  case Query(q) ~ Questions(QName(name) ~ TypeA() ~ ClassCS() :: Nil) => ???
  case Query(q) ~ Questions(QName(name) ~ TypeA() ~ ClassCH() :: Nil) => ???
  case Query(q) ~ Questions(QName(name) ~ TypeA() ~ ClassHS() :: Nil) => ???
  case Query(q) ~ Questions(QName(name) ~ TypeA() ~ ClassAsterisk() :: Nil) => ???
}
// qclass: Int = 1

Answer section

// Creation
val response: Message = Response ~ Questions(QName("example.com") ~ TypeA) ~ Answers()
// response: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 1, 0, 0, 0),
//   List(QuestionSection("example.com", 1, 1)),
//   List(),
//   List(),
//   List()
// )

// Matching
val answers = response match {
  case Response(r) ~ Answers(answers) => answers
}
// answers: Seq[ResourceRecord] = List()

Authority records section

// Creation
val response: Message = Response ~ Questions(QName("example.com") ~ TypeA) ~ Authority()
// response: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 1, 0, 0, 0),
//   List(QuestionSection("example.com", 1, 1)),
//   List(),
//   List(),
//   List()
// )

// Matching
val authority = response match {
  case Response(r) ~ Authority(authority) => authority
}
// authority: Seq[ResourceRecord] = List()

Additional records section

// Creation
val response: Message = Response ~ Questions(QName("example.com") ~ TypeA) ~ Additional()
// response: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 1, 0, 0, 0),
//   List(QuestionSection("example.com", 1, 1)),
//   List(),
//   List(),
//   List()
// )

// Matching
val additional = response match {
  case Response(r) ~ Additional(additional) => additional
}
// additional: Seq[ResourceRecord] = List()

Resource record

NAME

// Creation
val response: Message = Response ~ Questions(QName("example.com") ~ TypeA) ~ Answers(RRName("example.com"))
// response: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 1, 1, 0, 0),
//   List(QuestionSection("example.com", 1, 1)),
//   List(ResourceRecord("example.com", 10, 1, 3600L, UnknownResource(List(), 10))),
//   List(),
//   List()
// )

// Matching
val name = response match {
  case Response(r) ~ Answers(RRName(name) :: Nil) => name
}
// name: String = "example.com"

TYPE

// Creation
val response:         Message = Response ~ Answers(RRName("example.com") ~ RRType(ResourceRecord.typeTXT))
// response: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 0, 1, 0, 0),
//   List(),
//   List(ResourceRecord("example.com", 16, 1, 3600L, UnknownResource(List(), 10))),
//   List(),
//   List()
// )

val responseA:        Message = Response ~ Answers(RRName("example.com") ~ TypeA)
// responseA: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 0, 1, 0, 0),
//   List(),
//   List(ResourceRecord("example.com", 1, 1, 3600L, UnknownResource(List(), 10))),
//   List(),
//   List()
// )
val responseNS:       Message = Response ~ Answers(RRName("example.com") ~ TypeNS)
// responseNS: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 0, 1, 0, 0),
//   List(),
//   List(ResourceRecord("example.com", 2, 1, 3600L, UnknownResource(List(), 10))),
//   List(),
//   List()
// )
val responseMD:       Message = Response ~ Answers(RRName("example.com") ~ TypeMD)
// responseMD: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 0, 1, 0, 0),
//   List(),
//   List(ResourceRecord("example.com", 3, 1, 3600L, UnknownResource(List(), 10))),
//   List(),
//   List()
// )
val responseMF:       Message = Response ~ Answers(RRName("example.com") ~ TypeMF)
// responseMF: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 0, 1, 0, 0),
//   List(),
//   List(ResourceRecord("example.com", 4, 1, 3600L, UnknownResource(List(), 10))),
//   List(),
//   List()
// )
val responseCNAME:    Message = Response ~ Answers(RRName("example.com") ~ TypeCNAME)
// responseCNAME: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 0, 1, 0, 0),
//   List(),
//   List(ResourceRecord("example.com", 5, 1, 3600L, UnknownResource(List(), 10))),
//   List(),
//   List()
// )
val responseSOA:      Message = Response ~ Answers(RRName("example.com") ~ TypeSOA)
// responseSOA: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 0, 1, 0, 0),
//   List(),
//   List(ResourceRecord("example.com", 6, 1, 3600L, UnknownResource(List(), 10))),
//   List(),
//   List()
// )
val responseMB:       Message = Response ~ Answers(RRName("example.com") ~ TypeMB)
// responseMB: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 0, 1, 0, 0),
//   List(),
//   List(ResourceRecord("example.com", 7, 1, 3600L, UnknownResource(List(), 10))),
//   List(),
//   List()
// )
val responseMG:       Message = Response ~ Answers(RRName("example.com") ~ TypeMG)
// responseMG: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 0, 1, 0, 0),
//   List(),
//   List(ResourceRecord("example.com", 8, 1, 3600L, UnknownResource(List(), 10))),
//   List(),
//   List()
// )
val responseMR:       Message = Response ~ Answers(RRName("example.com") ~ TypeMR)
// responseMR: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 0, 1, 0, 0),
//   List(),
//   List(ResourceRecord("example.com", 9, 1, 3600L, UnknownResource(List(), 10))),
//   List(),
//   List()
// )
val responseNULL:     Message = Response ~ Answers(RRName("example.com") ~ TypeNULL)
// responseNULL: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 0, 1, 0, 0),
//   List(),
//   List(ResourceRecord("example.com", 10, 1, 3600L, UnknownResource(List(), 10))),
//   List(),
//   List()
// )
val responseWKS:      Message = Response ~ Answers(RRName("example.com") ~ TypeWKS)
// responseWKS: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 0, 1, 0, 0),
//   List(),
//   List(ResourceRecord("example.com", 11, 1, 3600L, UnknownResource(List(), 10))),
//   List(),
//   List()
// )
val responsePTR:      Message = Response ~ Answers(RRName("example.com") ~ TypePTR)
// responsePTR: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 0, 1, 0, 0),
//   List(),
//   List(ResourceRecord("example.com", 12, 1, 3600L, UnknownResource(List(), 10))),
//   List(),
//   List()
// )
val responseHINFO:    Message = Response ~ Answers(RRName("example.com") ~ TypeHINFO)
// responseHINFO: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 0, 1, 0, 0),
//   List(),
//   List(ResourceRecord("example.com", 13, 1, 3600L, UnknownResource(List(), 10))),
//   List(),
//   List()
// )
val responseMINFO:    Message = Response ~ Answers(RRName("example.com") ~ TypeMINFO)
// responseMINFO: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 0, 1, 0, 0),
//   List(),
//   List(ResourceRecord("example.com", 14, 1, 3600L, UnknownResource(List(), 10))),
//   List(),
//   List()
// )
val responseMX:       Message = Response ~ Answers(RRName("example.com") ~ TypeMX)
// responseMX: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 0, 1, 0, 0),
//   List(),
//   List(ResourceRecord("example.com", 15, 1, 3600L, UnknownResource(List(), 10))),
//   List(),
//   List()
// )
val responseTXT:      Message = Response ~ Answers(RRName("example.com") ~ TypeTXT)
// responseTXT: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 0, 1, 0, 0),
//   List(),
//   List(ResourceRecord("example.com", 16, 1, 3600L, UnknownResource(List(), 10))),
//   List(),
//   List()
// )
val responseAAAA:     Message = Response ~ Answers(RRName("example.com") ~ TypeAAAA)
// responseAAAA: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 0, 1, 0, 0),
//   List(),
//   List(ResourceRecord("example.com", 28, 1, 3600L, UnknownResource(List(), 10))),
//   List(),
//   List()
// )
val responseSRV:      Message = Response ~ Answers(RRName("example.com") ~ TypeSRV)
// responseSRV: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 0, 1, 0, 0),
//   List(),
//   List(ResourceRecord("example.com", 33, 1, 3600L, UnknownResource(List(), 10))),
//   List(),
//   List()
// )
val responseNAPTR:    Message = Response ~ Answers(RRName("example.com") ~ TypeNAPTR)
// responseNAPTR: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 0, 1, 0, 0),
//   List(),
//   List(ResourceRecord("example.com", 35, 1, 3600L, UnknownResource(List(), 10))),
//   List(),
//   List()
// )
val responseOPT:      Message = Response ~ Answers(RRName("example.com") ~ TypeOPT)
// responseOPT: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 0, 1, 0, 0),
//   List(),
//   List(ResourceRecord("example.com", 41, 1, 3600L, UnknownResource(List(), 10))),
//   List(),
//   List()
// )
val responseAXFR:     Message = Response ~ Answers(RRName("example.com") ~ TypeAXFR)
// responseAXFR: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 0, 1, 0, 0),
//   List(),
//   List(
//     ResourceRecord("example.com", 252, 1, 3600L, UnknownResource(List(), 10))
//   ),
//   List(),
//   List()
// )
val responseMAILB:    Message = Response ~ Answers(RRName("example.com") ~ TypeMAILB)
// responseMAILB: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 0, 1, 0, 0),
//   List(),
//   List(
//     ResourceRecord("example.com", 253, 1, 3600L, UnknownResource(List(), 10))
//   ),
//   List(),
//   List()
// )
val responseMAILA:    Message = Response ~ Answers(RRName("example.com") ~ TypeMAILA)
// responseMAILA: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 0, 1, 0, 0),
//   List(),
//   List(
//     ResourceRecord("example.com", 254, 1, 3600L, UnknownResource(List(), 10))
//   ),
//   List(),
//   List()
// )
val responseCAA:      Message = Response ~ Answers(RRName("example.com") ~ TypeCAA)
// responseCAA: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 0, 1, 0, 0),
//   List(),
//   List(
//     ResourceRecord("example.com", 257, 1, 3600L, UnknownResource(List(), 10))
//   ),
//   List(),
//   List()
// )
val responseAsterisk: Message = Response ~ Answers(RRName("example.com") ~ TypeAsterisk)
// responseAsterisk: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 0, 1, 0, 0),
//   List(),
//   List(
//     ResourceRecord("example.com", 255, 1, 3600L, UnknownResource(List(), 10))
//   ),
//   List(),
//   List()
// )

// Matching
val rtype = response match {
  case Response(r) ~ Answers(RRName(name) ~ TypeA()        :: Nil) => "A"
  case Response(r) ~ Answers(RRName(name) ~ TypeNS()       :: Nil) => "NS"
  case Response(r) ~ Answers(RRName(name) ~ TypeMD()       :: Nil) => "MD"
  case Response(r) ~ Answers(RRName(name) ~ TypeMF()       :: Nil) => "MF"
  case Response(r) ~ Answers(RRName(name) ~ TypeCNAME()    :: Nil) => "CNAME"
  case Response(r) ~ Answers(RRName(name) ~ TypeSOA()      :: Nil) => "SOA"
  case Response(r) ~ Answers(RRName(name) ~ TypeMB()       :: Nil) => "MB"
  case Response(r) ~ Answers(RRName(name) ~ TypeMG()       :: Nil) => "MG"
  case Response(r) ~ Answers(RRName(name) ~ TypeMR()       :: Nil) => "MR"
  case Response(r) ~ Answers(RRName(name) ~ TypeNULL()     :: Nil) => "NULL"
  case Response(r) ~ Answers(RRName(name) ~ TypeWKS()      :: Nil) => "WKS"
  case Response(r) ~ Answers(RRName(name) ~ TypePTR()      :: Nil) => "PTR"
  case Response(r) ~ Answers(RRName(name) ~ TypeHINFO()    :: Nil) => "HINFO"
  case Response(r) ~ Answers(RRName(name) ~ TypeMINFO()    :: Nil) => "MINFO"
  case Response(r) ~ Answers(RRName(name) ~ TypeMX()       :: Nil) => "MX"
  case Response(r) ~ Answers(RRName(name) ~ TypeTXT()      :: Nil) => "TXT"
  case Response(r) ~ Answers(RRName(name) ~ TypeAAAA()     :: Nil) => "AAAA"
  case Response(r) ~ Answers(RRName(name) ~ TypeSRV()      :: Nil) => "SRV"
  case Response(r) ~ Answers(RRName(name) ~ TypeNAPTR()    :: Nil) => "NAPTR"
  case Response(r) ~ Answers(RRName(name) ~ TypeOPT()      :: Nil) => "OPT"
  case Response(r) ~ Answers(RRName(name) ~ TypeAXFR()     :: Nil) => "AXFR"
  case Response(r) ~ Answers(RRName(name) ~ TypeMAILB()    :: Nil) => "MAILB"
  case Response(r) ~ Answers(RRName(name) ~ TypeMAILA()    :: Nil) => "MAILA"
  case Response(r) ~ Answers(RRName(name) ~ TypeCAA()      :: Nil) => "CAA"
  case Response(r) ~ Answers(RRName(name) ~ TypeAsterisk() :: Nil) => "Asterisk"

  case Response(r) ~ Answers(RRName(name) ~ RRType(t)      :: Nil) => t.toString
}
// rtype: String = "TXT"

CLASS

// Creation
val response:         Message = Response ~ Answers(RRName("example.com") ~ RRClass(ResourceRecord.classIN))
// response: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 0, 1, 0, 0),
//   List(),
//   List(ResourceRecord("example.com", 10, 1, 3600L, UnknownResource(List(), 10))),
//   List(),
//   List()
// )

val responseIN:       Message = Response ~ Answers(RRName("example.com") ~ ClassIN)
// responseIN: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 0, 1, 0, 0),
//   List(),
//   List(ResourceRecord("example.com", 10, 1, 3600L, UnknownResource(List(), 10))),
//   List(),
//   List()
// )
val responseCS:       Message = Response ~ Answers(RRName("example.com") ~ ClassCS)
// responseCS: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 0, 1, 0, 0),
//   List(),
//   List(ResourceRecord("example.com", 10, 2, 3600L, UnknownResource(List(), 10))),
//   List(),
//   List()
// )
val responseCH:       Message = Response ~ Answers(RRName("example.com") ~ ClassCH)
// responseCH: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 0, 1, 0, 0),
//   List(),
//   List(ResourceRecord("example.com", 10, 3, 3600L, UnknownResource(List(), 10))),
//   List(),
//   List()
// )
val responseHS:       Message = Response ~ Answers(RRName("example.com") ~ ClassHS)
// responseHS: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 0, 1, 0, 0),
//   List(),
//   List(ResourceRecord("example.com", 10, 4, 3600L, UnknownResource(List(), 10))),
//   List(),
//   List()
// )
val responseAsterisk: Message = Response ~ Answers(RRName("example.com") ~ ClassAsterisk)
// responseAsterisk: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 0, 1, 0, 0),
//   List(),
//   List(
//     ResourceRecord("example.com", 10, 255, 3600L, UnknownResource(List(), 10))
//   ),
//   List(),
//   List()
// )

// Matching
val `class` = response match {
  case Response(q) ~ Answers(ClassIN()       :: Nil) => "IN"
  case Response(q) ~ Answers(ClassCS()       :: Nil) => "CS"
  case Response(q) ~ Answers(ClassCH()       :: Nil) => "CH"
  case Response(q) ~ Answers(ClassHS()       :: Nil) => "HS"
  case Response(q) ~ Answers(ClassAsterisk() :: Nil) => "Asterisk"

  case Response(q) ~ Answers(RRClass(c)       :: Nil) => c.toString
}
// `class`: String = "IN"

TTL

// Creation
val response: Message = Response ~ Questions(QName("example.com") ~ TypeA) ~ Answers(RRName("example.com") ~ RRType(ResourceRecord.typeTXT) ~ RRClass(ResourceRecord.classIN) ~ RRTtl(123))
// response: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 1, 1, 0, 0),
//   List(QuestionSection("example.com", 1, 1)),
//   List(ResourceRecord("example.com", 16, 1, 123L, UnknownResource(List(), 10))),
//   List(),
//   List()
// )

// Matching
val ttl = response match {
  case Response(r) ~ Answers(RRName(name) ~ RRType(t) ~ RRClass(c) ~ RRTtl(ttl) :: Nil) => ttl
}
// ttl: Long = 123L

Resource records

ARecord

// Creation
val addr: java.net.Inet4Address = java.net.InetAddress.getByAddress(Array.fill[Byte](4)(0)).asInstanceOf[java.net.Inet4Address]
// addr: java.net.Inet4Address = /0.0.0.0
val response1: Message = Response ~ Questions(QName("example.com") ~ TypeA) ~ Answers(ARecord(addr))
// response1: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 1, 1, 0, 0),
//   List(QuestionSection("example.com", 1, 1)),
//   List(ResourceRecord("", 1, 1, 3600L, AResource(/0.0.0.0))),
//   List(),
//   List()
// )
val response2: Message = Response ~ Questions(QName("example.com") ~ TypeA) ~ Answers(ARecord(Array[Byte](1, 2, 3, 4)))
// response2: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 1, 1, 0, 0),
//   List(QuestionSection("example.com", 1, 1)),
//   List(ResourceRecord("", 1, 1, 3600L, AResource(/1.2.3.4))),
//   List(),
//   List()
// )
val response3: Message = Response ~ Questions(QName("example.com") ~ TypeA) ~ Answers(ARecord("1.2.3.4"))
// response3: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 1, 1, 0, 0),
//   List(QuestionSection("example.com", 1, 1)),
//   List(ResourceRecord("", 1, 1, 3600L, AResource(/1.2.3.4))),
//   List(),
//   List()
// )

// Matching
val address = response1 match {
  case Response(_) ~ Answers(ARecord(r) :: Nil) => r.address
}
// address: java.net.Inet4Address = /0.0.0.0

AAAARecord

// Creation
val addr: java.net.Inet6Address = java.net.InetAddress.getByAddress(Array.fill[Byte](16)(0)).asInstanceOf[java.net.Inet6Address]
// addr: java.net.Inet6Address = /0:0:0:0:0:0:0:0
val response1: Message = Response ~ Questions(QName("example.com") ~ TypeAAAA) ~ Answers(AAAARecord(addr))
// response1: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 1, 1, 0, 0),
//   List(QuestionSection("example.com", 28, 1)),
//   List(ResourceRecord("", 28, 1, 3600L, AAAAResource(/0:0:0:0:0:0:0:0))),
//   List(),
//   List()
// )
val response2: Message = Response ~ Questions(QName("example.com") ~ TypeAAAA) ~ Answers(AAAARecord(Array[Byte](1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)))
// response2: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 1, 1, 0, 0),
//   List(QuestionSection("example.com", 28, 1)),
//   List(
//     ResourceRecord(
//       "",
//       28,
//       1,
//       3600L,
//       AAAAResource(/102:304:506:708:90a:b0c:d0e:f10)
//     )
//   ),
//   List(),
//   List()
// )
val response3: Message = Response ~ Questions(QName("example.com") ~ TypeAAAA) ~ Answers(AAAARecord("0123:4567:89ab:cdef:0123:4567:89ab:cdef"))
// response3: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 1, 1, 0, 0),
//   List(QuestionSection("example.com", 28, 1)),
//   List(
//     ResourceRecord(
//       "",
//       28,
//       1,
//       3600L,
//       AAAAResource(/123:4567:89ab:cdef:123:4567:89ab:cdef)
//     )
//   ),
//   List(),
//   List()
// )

// Matching
val address = response1 match {
  case Response(_) ~ Answers(AAAARecord(r) :: Nil) => r.address
}
// address: java.net.Inet6Address = /0:0:0:0:0:0:0:0

CNameRecord

// Creation
val response: Message = Response ~ Questions(QName("www.example.com") ~ TypeCNAME) ~ Answers(CNameRecord("example.com"))
// response: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 1, 1, 0, 0),
//   List(QuestionSection("www.example.com", 5, 1)),
//   List(ResourceRecord("", 5, 1, 3600L, CNameResource("example.com"))),
//   List(),
//   List()
// )

// Matching
val cname = response match {
  case Response(_) ~ Answers(CNameRecord(r) :: Nil) => r.cname
}
// cname: String = "example.com"

MXRecord

// Creation
val response: Message = Response ~ Questions(QName("example.com") ~ TypeMX) ~ Answers(MXRecord(1, "example.com"))
// response: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 1, 1, 0, 0),
//   List(QuestionSection("example.com", 15, 1)),
//   List(ResourceRecord("", 15, 1, 3600L, MXResource(1, "example.com"))),
//   List(),
//   List()
// )

// Matching
val (preference, exchange) = response match {
  case Response(_) ~ Answers(MXRecord(r) :: Nil) => (r.preference, r.exchange)
}
// preference: Int = 1
// exchange: String = "example.com"

NAPTRRecord

// Creation
val response: Message = Response ~ Questions(QName("example.com") ~ TypeNAPTR) ~ Answers(NAPTRRecord(1, 1, "A", "", "!^.*$!example.com!", ""))
// response: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 1, 1, 0, 0),
//   List(QuestionSection("example.com", 35, 1)),
//   List(
//     ResourceRecord(
//       "",
//       35,
//       1,
//       3600L,
//       NAPTRResource(1, 1, "A", "", "!^.*$!example.com!", "")
//     )
//   ),
//   List(),
//   List()
// )

// Matching
val (order, preference, flags, services, regexp, replacement) = response match {
  case Response(_) ~ Answers(NAPTRRecord(r) :: Nil) => (r.order, r.preference, r.flags, r.services, r.regexp, r.replacement)
}
// order: Int = 1
// preference: Int = 1
// flags: String = "A"
// services: String = ""
// regexp: String = "!^.*$!example.com!"
// replacement: String = ""

OPTRecord

// Creation
val response: Message = Response ~ Questions(QName("example.com") ~ TypeOPT) ~ Additional(OPTRecord(Nil))
// response: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 1, 0, 0, 1),
//   List(QuestionSection("example.com", 41, 1)),
//   List(),
//   List(),
//   List(ResourceRecord("", 41, 1, 3600L, OPTResource(List())))
// )

// Matching
val optRecord = response match {
  case Response(_) ~ Additional(OPTRecord(r) :: Nil) => r
}
// optRecord: OPTResource = OPTResource(List())
ClientSubnetOption
// Creation
val response: Message = Response ~ Additional(OPTRecord(ClientSubnetOption(OPTResource.ClientSubnetOPTOptionData.familyIPv4, 24, 0, java.net.InetAddress.getByName("1.2.3.0")) :: Nil))
// response: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 0, 0, 0, 1),
//   List(),
//   List(),
//   List(),
//   List(
//     ResourceRecord(
//       "",
//       41,
//       1,
//       3600L,
//       OPTResource(
//         List(OPTOption(8, ClientSubnetOPTOptionData(1, 24, 0, /1.2.3.0)))
//       )
//     )
//   )
// )

// Matching
val (family, sourcePrefixLength, scopePrefixLength, address) = response match {
  case Response(_) ~ Additional(OPTRecord(OPTResource(ClientSubnetOption(OPTResource.ClientSubnetOPTOptionData(family, sourcePrefixLength, scopePrefixLength, address)) :: Nil)) :: Nil) => (family, sourcePrefixLength, scopePrefixLength, address)
}
// family: Int = 1
// sourcePrefixLength: Int = 24
// scopePrefixLength: Int = 0
// address: java.net.InetAddress = /1.2.3.0

NSRecord

// Creation
val response: Message = Response ~ Questions(QName("example.com") ~ TypeNS) ~ Answers(NSRecord("example.com"))
// response: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 1, 1, 0, 0),
//   List(QuestionSection("example.com", 2, 1)),
//   List(ResourceRecord("", 2, 1, 3600L, NSResource("example.com"))),
//   List(),
//   List()
// )

// Matching
val nsdname = response match {
  case Response(_) ~ Answers(NSRecord(r) :: Nil) => r.nsdname
}
// nsdname: String = "example.com"

PTRRecord

// Creation
val response: Message = Response ~ Questions(QName("example.com") ~ TypePTR) ~ Answers(PTRRecord("example.com"))
// response: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 1, 1, 0, 0),
//   List(QuestionSection("example.com", 12, 1)),
//   List(ResourceRecord("", 12, 1, 3600L, PTRResource("example.com"))),
//   List(),
//   List()
// )

// Matching
val ptrdname = response match {
  case Response(_) ~ Answers(PTRRecord(r) :: Nil) => r.ptrdname
}
// ptrdname: String = "example.com"

HInfoRecord

// Creation
val response: Message = Response ~ Questions(QName("example.com") ~ TypeHINFO) ~ Answers(HInfoRecord("CPU", "Linux"))
// response: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 1, 1, 0, 0),
//   List(QuestionSection("example.com", 13, 1)),
//   List(ResourceRecord("", 13, 1, 3600L, HInfoResource("CPU", "Linux"))),
//   List(),
//   List()
// )

// Matching
val (cpu, os) = response match {
  case Response(_) ~ Answers(HInfoRecord(r) :: Nil) => (r.cpu, r.os)
}
// cpu: String = "CPU"
// os: String = "Linux"

TXTRecord

// Creation
val response: Message = Response ~ Questions(QName("example.com") ~ TypeTXT) ~ Answers(TXTRecord("Test", "test", "tesT"))
// response: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 1, 1, 0, 0),
//   List(QuestionSection("example.com", 16, 1)),
//   List(
//     ResourceRecord(
//       "",
//       16,
//       1,
//       3600L,
//       TXTResource(ArraySeq("Test", "test", "tesT"))
//     )
//   ),
//   List(),
//   List()
// )

// Matching
val txt = response match {
  case Response(_) ~ Answers(TXTRecord(r) :: Nil) => r.txt
}
// txt: Seq[String] = ArraySeq("Test", "test", "tesT")

SOARecord

// Creation
val response: Message = Response ~ Questions(QName("example.com") ~ TypeSOA) ~ Answers(SOARecord("example.com", "admin.example.com", 2015122401L, 3600L, 1800L, 604800L, 600L))
// response: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 1, 1, 0, 0),
//   List(QuestionSection("example.com", 6, 1)),
//   List(
//     ResourceRecord(
//       "",
//       6,
//       1,
//       3600L,
//       SOAResource(
//         "example.com",
//         "admin.example.com",
//         2015122401L,
//         3600L,
//         1800L,
//         604800L,
//         600L
//       )
//     )
//   ),
//   List(),
//   List()
// )

// Matching
val (mname, rname, serial, refresh, retry, expire, minimum) = response match {
  case Response(_) ~ Answers(SOARecord(r) :: Nil) => (r.mname, r.rname, r.serial, r.refresh, r.retry, r.expire, r.minimum)
}
// mname: String = "example.com"
// rname: String = "admin.example.com"
// serial: Long = 2015122401L
// refresh: Long = 3600L
// retry: Long = 1800L
// expire: Long = 604800L
// minimum: Long = 600L

CAARecord

// Creation
val response: Message = Response ~ Questions(QName("example.com") ~ TypeCAA) ~ Answers(RRName("example.com") ~ CAARecord.Issue("cert-authority.org"))
// response: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 1, 1, 0, 0),
//   List(QuestionSection("example.com", 257, 1)),
//   List(
//     ResourceRecord(
//       "example.com",
//       257,
//       1,
//       3600L,
//       IssueResource("cert-authority.org", false)
//     )
//   ),
//   List(),
//   List()
// )

// Matching
val value = response match {
  case Response(_) ~ Answers(CAARecord.Issue(r) :: Nil) => r.value
}
// value: String = "cert-authority.org"

Misc

DnsClassName

// Matching
val msg: Message = Response ~ Questions(QName("example.com") ~ TypeTXT) ~ Answers(TXTRecord("Test", "test", "tesT"))
// msg: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 1, 1, 0, 0),
//   List(QuestionSection("example.com", 16, 1)),
//   List(
//     ResourceRecord(
//       "",
//       16,
//       1,
//       3600L,
//       TXTResource(ArraySeq("Test", "test", "tesT"))
//     )
//   ),
//   List(),
//   List()
// )
val (qclass, aclass) = msg match {
  case Response(_) ~ Questions(DnsClassName(qclass) :: Nil) ~ Answers(DnsClassName(aclass) :: Nil) => (qclass, aclass)
}
// qclass: String = "IN"
// aclass: String = "IN"

DnsTypeName

The DnsTypeName object can be used to extract a String representation of a Question or a ResourceRecord.

// Matching
val msg: Message = Response ~ Questions(QName("example.com") ~ TypeTXT) ~ Answers(TXTRecord("Test", "test", "tesT"))
// msg: Message = Message(
//   HeaderSection(0, true, 0, false, false, true, false, 0, 1, 1, 0, 0),
//   List(QuestionSection("example.com", 16, 1)),
//   List(
//     ResourceRecord(
//       "",
//       16,
//       1,
//       3600L,
//       TXTResource(ArraySeq("Test", "test", "tesT"))
//     )
//   ),
//   List(),
//   List()
// )
val (qtype, atype) = msg match {
  case Response(_) ~ Questions(DnsTypeName(qtype) :: Nil) ~ Answers(DnsTypeName(atype) :: Nil) => (qtype, atype)
}
// qtype: String = "TXT"
// atype: String = "TXT"

EDNS

// Creation
val query1: Message = Query ~ Questions(QName("example.com") ~ TypeA) ~ EDNS()
// query1: Message = Message(
//   HeaderSection(0, false, 0, false, false, true, false, 0, 1, 0, 0, 1),
//   List(QuestionSection("example.com", 1, 1)),
//   List(),
//   List(),
//   List(ResourceRecord("", 41, 4096, 0L, OPTResource(List())))
// )
val query2: Message = Query ~ Questions(QName("example.com") ~ TypeA) ~ EDNS(4096)
// query2: Message = Message(
//   HeaderSection(0, false, 0, false, false, true, false, 0, 1, 0, 0, 1),
//   List(QuestionSection("example.com", 1, 1)),
//   List(),
//   List(),
//   List(ResourceRecord("", 41, 4096, 0L, OPTResource(List())))
// )

// Matching
val size = query1 match {
  case Query(_) ~ Questions(q) ~ EDNS(size) => size
}
// size: Int = 4096