| Copyright | (c) Viktor Dukhovni 2026 |
|---|---|
| License | BSD-3-Clause |
| Maintainer | ietf-dane@dukhovni.org |
| Stability | unstable |
| Safe Haskell | None |
| Language | GHC2024 |
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
- data SGet a
- getPosition :: SGet Int
- getChrono :: SGet Int64
- get8 :: SGet Word8
- get16 :: SGet Word16
- get32 :: SGet Word32
- get64 :: SGet Word64
- getInt8 :: SGet Int
- getInt16 :: SGet Int
- getIPv4 :: SGet IPv4
- getIPv4Net :: Int -> SGet IPv4
- getIPv6 :: SGet IPv6
- getIPv6Net :: Int -> SGet IPv6
- getDnsTime :: SGet Int64
- skipNBytes :: Int -> SGet ()
- getNBytes :: Int -> SGet [Word8]
- getShortByteString :: SGet ShortByteString
- getShortNByteString :: Int -> SGet ShortByteString
- getShortByteStringLen8 :: SGet ShortByteString
- getShortByteStringLen16 :: SGet ShortByteString
- getUtf8Text :: Int -> SGet Text
- getUtf8TextLen8 :: SGet Text
- getUtf8TextLen16 :: SGet Text
- getVarWidthSequence :: SGet a -> Int -> SGet [a]
- getFixedWidthSequence :: Int -> SGet a -> Int -> SGet [a]
- seekSGet :: Word16 -> SGet a -> SGet a
- fitSGet :: Int -> SGet a -> SGet a
- failSGet :: String -> SGet a
- decodeAtWith :: Int64 -> Bool -> SGet a -> ByteString -> Either DNSError a
DNS message element parser
Minimal Reader + State + Except Monad.
Internal state accessors
getPosition :: SGet Int Source #
Returns the current position relative to the start of the internal buffer
Generic low-level decoders
Consumes two octets and returns them as an Int
computed using network byte order
DNS-specific low-level decoders
getIPv4Net :: Int -> SGet IPv4 Source #
Reads up to four octets and returns them as an IPv4
address padded as needed with trailing 0x0 bytes.
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
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.
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
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.