dnsbase
Copyright(c) Viktor Dukhovni 2026
LicenseBSD-3-Clause
Maintainerietf-dane@dukhovni.org
Stabilityunstable
Safe HaskellNone
LanguageGHC2024

Net.DNSBase.Decode.State

Description

The SGet decoder monad for parsing DNS wire-form data, plus the primitive readers (get8, get16, get32, ...), DNS-style helpers (getDnsTime, getIPv4, getIPv6), length-prefixed byte-string readers, and the sequence and sandboxing combinators (getVarWidthSequence, fitSGet, seekSGet). Used by authors of KnownRData and KnownEdnsOption instances to implement the value-side decoding; most applications will not use this module directly.

Synopsis

DNS message element parser

data SGet a Source #

Minimal Reader + State + Except Monad.

Instances

Instances details
Applicative SGet Source # 
Instance details

Defined in Net.DNSBase.Decode.Internal.State

Methods

pure :: a -> SGet a #

(<*>) :: SGet (a -> b) -> SGet a -> SGet b #

liftA2 :: (a -> b -> c) -> SGet a -> SGet b -> SGet c #

(*>) :: SGet a -> SGet b -> SGet b #

(<*) :: SGet a -> SGet b -> SGet a #

Functor SGet Source # 
Instance details

Defined in Net.DNSBase.Decode.Internal.State

Methods

fmap :: (a -> b) -> SGet a -> SGet b #

(<$) :: a -> SGet b -> SGet a #

Monad SGet Source # 
Instance details

Defined in Net.DNSBase.Decode.Internal.State

Methods

(>>=) :: SGet a -> (a -> SGet b) -> SGet b #

(>>) :: SGet a -> SGet b -> SGet b #

return :: a -> SGet a #

Internal state accessors

getPosition :: SGet Int Source #

Returns the current position relative to the start of the internal buffer

getChrono :: SGet Int64 Source #

Returns the epoch-relative time passed to decodeAtWith

Generic low-level decoders

get8 :: SGet Word8 Source #

Consumes one octet and returns it as a Word8

get16 :: SGet Word16 Source #

Load a 16-bit big-endian word.

get32 :: SGet Word32 Source #

Load a 32-bit big-endian word.

get64 :: SGet Word64 Source #

Load a 64-bit big-endian word.

getInt8 :: SGet Int Source #

Consumes one octet and returns it as an Int

getInt16 :: SGet Int Source #

Consumes two octets and returns them as an Int computed using network byte order

DNS-specific low-level decoders

getIPv4 :: SGet IPv4 Source #

Reads 4 octets and returns them as an IPv4 address

getIPv4Net :: Int -> SGet IPv4 Source #

Reads up to four octets and returns them as an IPv4 address padded as needed with trailing 0x0 bytes.

getIPv6 :: SGet IPv6 Source #

Reads 16 octets and returns them as an IPv6 address

getIPv6Net :: Int -> SGet IPv6 Source #

Reads up to 16 octets and returns them as an IPv6 address padded as needed with trailing 0x0 bytes.

getDnsTime :: SGet Int64 Source #

Converts a 32-bit circle-arithmetic DNS time to an absolute 64-bit DNS timestamp that lies within a 31-bit band of the parser state's reference timestamp.

Octet-string decoders

skipNBytes :: Int -> SGet () Source #

Consumes and discards n bytes of input from the buffer

getNBytes :: Int -> SGet [Word8] Source #

Consumes and returns n bytes of input from the buffer.

getShortByteString :: SGet ShortByteString Source #

Consumes the rest of the buffer as ShortByteString.

getShortNByteString :: Int -> SGet ShortByteString Source #

Consumes and returns a ShortByteString of length n from the buffer.

getShortByteStringLen8 :: SGet ShortByteString Source #

Read a ShortByteString whose length is determined by an 8-bit prefix.

getShortByteStringLen16 :: SGet ShortByteString Source #

Read a ShortByteString whose length is determined by a 16-bit prefix.

getUtf8Text :: Int -> SGet Text Source #

Read a UTF8-encoded text string of the given length.

getUtf8TextLen8 :: SGet Text Source #

Read a UTF8-encoded text string preceded by an explicit 8-bit length.

getUtf8TextLen16 :: SGet Text Source #

Read a UTF8-encoded text string preceded by an explicit 16-bit length.

Sequence decoders

getVarWidthSequence Source #

Arguments

:: SGet a

Decoder for a single value

-> Int

Total number of octets in the sequence

-> SGet [a] 

Decodes a sequence of values with a variable wire-form byte-width.

getFixedWidthSequence Source #

Arguments

:: Int

Number of octets to encode one value

-> SGet a

Decoder for a single value

-> Int

Total number of octets in the sequence

-> SGet [a] 

Decodes a sequence of values with a fixed wire-form byte-width.

Decoder sandboxing

seekSGet :: Word16 -> SGet a -> SGet a Source #

Seek to a given offset and run a parser that can consume at most the given number of bytes. The caller's state remains unchanged. Used exclusively for decoding DNS message name compression.

fitSGet :: Int -> SGet a -> SGet a Source #

Runs a parser on an initial segment of the unread input. Consumes exactly the specified number of bytes or fails.

Decoder failure

failSGet :: String -> SGet a Source #

Abort the decoder with a DecodeError carrying the given diagnostic message and the current DecodeContext (message section, RR triple, and source address) drawn from the reader environment. Used by RR-data parsers when the wire bytes don't conform to the expected shape.

Decoder driver

decodeAtWith Source #

Arguments

:: Int64

Current absolute offset from epoch

-> Bool

Support name compression?

-> SGet a

Decoder to run

-> ByteString

Buffer to run decoder over

-> Either DNSError a 

Run a decoder with a given epoch offset over specified input