| Copyright | (c) Viktor Dukhovni 2026 |
|---|---|
| License | BSD-3-Clause |
| Maintainer | ietf-dane@dukhovni.org |
| Stability | unstable |
| Safe Haskell | None |
| Language | GHC2024 |
Net.DNSBase.Present
Description
The Presentable typeclass renders DNS data into the conventional zone-file
textual form
(RFC 1035 section 5,
with later refinements). Instances produce Builder
fragments, which are stitched together by the small combinator set
(presentSp, presentCharSep, presentLn, and friends) for separators and
line breaks. presentString and presentStrict run the builder to a String
or strict ByteString for final output; putBuilder writes a
builder to stdout.
The Epoch64 newtype renders a 64-bit absolute time as the
RFC 4034 14-digit YYYYMMDDHHmmSS string used in RRSIG
timestamps.
Synopsis
- class Presentable a where
- present :: a -> Builder -> Builder
- presentLazy :: a -> ByteString -> ByteString
- presentByte :: Word8 -> Builder -> Builder
- presentCharSep :: Presentable a => Char -> a -> Builder -> Builder
- presentCharSepLn :: Presentable a => Char -> a -> Builder -> Builder
- presentLn :: Presentable a => a -> Builder -> Builder
- presentSep :: Presentable a => Word8 -> a -> Builder -> Builder
- presentSepLn :: Presentable a => Word8 -> a -> Builder -> Builder
- presentSp :: Presentable a => a -> Builder -> Builder
- presentSpLn :: Presentable a => a -> Builder -> Builder
- newtype Epoch64 = Epoch64 Int64
- presentString :: Presentable a => a -> String -> String
- presentStrict :: Presentable a => a -> ByteString -> ByteString
- data Builder
- hPutBuilder :: Handle -> Builder -> IO ()
- putBuilder :: Builder -> IO ()
Documentation
class Presentable a where Source #
Return DNS presentation form, as a lazy ByteString builder, taking a continuation. Since DNS record presentation form is ASCII, we don't need Unicode strings, and lazy ByteString builders perform one to two orders of magnitude faster.
Complex builders with nested sub-components are much more efficient when constructed in continuation passing style.
Minimal complete definition
Methods
Serialise the input value with the given continuation.
Arguments
| :: a | Value to serialise |
| -> ByteString | Lazy bytestring suffix |
| -> ByteString | Final output |
Run the builder immediately, producing a lazy ByteString with the
given tail.
Instances
Builder combinators
presentByte :: Word8 -> Builder -> Builder Source #
Prepend a single literal byte to a continuation builder. The
workhorse separator primitive that the other combinators
(presentSep, presentSp, presentLn, ...) are built on.
presentCharSep :: Presentable a => Char -> a -> Builder -> Builder Source #
Append with a leading Char octet separator
presentCharSepLn :: Presentable a => Char -> a -> Builder -> Builder Source #
Append with a leading separator and a trailing newline
presentLn :: Presentable a => a -> Builder -> Builder Source #
Append the presentation of a followed by a newline (\n,
0x0a). Use this to terminate each record when emitting a
zone-file-style stream, as in
foldr presentLn mempty records.
presentSep :: Presentable a => Word8 -> a -> Builder -> Builder Source #
Append with a leading separator
presentSepLn :: Presentable a => Word8 -> a -> Builder -> Builder Source #
Append with a leading separator and a trailing newline
presentSpLn :: Presentable a => a -> Builder -> Builder Source #
Append with a leading space and a trailing newline
Newtype to present 64-bit epoch times.
64-bit extended representation of 32-bit DNS clock-arithmetic types. The presentation form is as a YYYYMMDDHHMMSS string.
Instances
| Presentable Epoch64 Source # | |
Defined in Net.DNSBase.Internal.Present Methods present :: Epoch64 -> Builder -> Builder Source # presentLazy :: Epoch64 -> ByteString -> ByteString Source # | |
| IsString Epoch64 Source # | Parse DNSSEC YYYYmmddHHMMSS time format to |
Defined in Net.DNSBase.Internal.Present Methods fromString :: String -> Epoch64 # | |
| Bounded Epoch64 Source # | |
| Enum Epoch64 Source # | |
| Num Epoch64 Source # | |
| Integral Epoch64 Source # | |
Defined in Net.DNSBase.Internal.Present | |
| Real Epoch64 Source # | |
Defined in Net.DNSBase.Internal.Present Methods toRational :: Epoch64 -> Rational # | |
| Show Epoch64 Source # | |
| Eq Epoch64 Source # | |
| Ord Epoch64 Source # | |
Defined in Net.DNSBase.Internal.Present | |
Build directly to a String or ByteString
presentString :: Presentable a => a -> String -> String Source #
Immediately construct a String from the input followed by the given
tail.
presentStrict :: Presentable a => a -> ByteString -> ByteString Source #
Immediately construct a strict ByteString from the input followed by
the given lazy ByteString tail.
Re-exported from Data.ByteString.Builder
Builders denote sequences of bytes.
They are Monoids where
mempty is the zero-length sequence and
mappend is concatenation, which runs in O(1).
Instances
| Presentable Builder Source # | |
Defined in Net.DNSBase.Internal.Present Methods present :: Builder -> Builder -> Builder Source # presentLazy :: Builder -> ByteString -> ByteString Source # | |
| Monoid Builder # | |
| Semigroup Builder # | |
| IsString Builder # | |
Defined in Data.ByteString.Builder Methods fromString :: String -> Builder # | |
| IsList Builder # | For long or infinite lists use |
| Show Builder # | Since: bytestring-0.11.1.0 |
| type Item Builder # | |
Defined in Data.ByteString.Builder.Internal | |
hPutBuilder :: Handle -> Builder -> IO () #
Output a Builder to a Handle.
The Builder is executed directly on the buffer of the Handle. If the
buffer is too small (or not present), then it is replaced with a large
enough buffer.
It is recommended that the Handle is set to binary and
BlockBuffering mode. See hSetBinaryMode and
hSetBuffering.
This function is more efficient than hPut . because in
many cases no buffer allocation has to be done. Moreover, the results of
several executions of short toLazyByteStringBuilders are concatenated in the Handles
buffer, therefore avoiding unnecessary buffer flushes.
hPutBuilder specialised to stdout
putBuilder :: Builder -> IO () Source #
Execute the Builder writing output to IO.stdout.
Typically, stdout should be set in BinaryMode with
BlockBuffering. See hSetBinaryMode and
hSetBuffering for details.