DNS.Message.Record.Data (DNS v0.5.0)
View SourceGeneric DNS resource record data module.
This module provides a fallback implementation for DNS resource record data when specific record type modules are not available. It serves as a generic container for raw record data and delegates to specialized modules when possible.
Registry Integration
The module integrates with DNS.Message.Record.Data.Registry to find appropriate
record type implementations. When a specific type is found, it delegates to that
module. When no specific implementation exists, it stores the raw data.
Fields
type- Resource record type informationrdlength- Length of the RDATA field (0-65535)raw- Raw binary data for the record
Examples
# When specific type is available
iex> rtype = DNS.ResourceRecordType.new(1) # A record
iex> data = DNS.Message.Record.Data.new(rtype, {192, 168, 1, 1})
iex> %DNS.Message.Record.Data.A{} = data
# When type is unknown, falls back to generic storage
iex> rtype = DNS.ResourceRecordType.new(9999) # Unknown type
iex> data = DNS.Message.Record.Data.new(rtype, "custom_data")
iex> %DNS.Message.Record.Data{raw: "custom_data"} = data
Summary
Types
@type t() :: %DNS.Message.Record.Data{ raw: bitstring(), rdlength: 0..65535, type: DNS.ResourceRecordType.t() }
Functions
@spec from_iodata(non_neg_integer(), iodata(), binary()) :: term()
Parse record data from binary iodata.
Attempts to find a specific implementation for the record type in the registry.
If found, delegates to that module's from_iodata/2 function. Otherwise,
creates a generic data container with the raw bytes.
Parameters
type- DNS record type number (integer)raw- Binary data for the recordmessage- Full DNS message (used by some record types for context)
Returns
- Record data struct (specific type if available, generic otherwise)
Examples
iex> data = DNS.Message.Record.Data.from_iodata(1, <<192, 168, 1, 1>>)
iex> %DNS.Message.Record.Data.A{} = data
@spec new(DNS.ResourceRecordType.t(), term()) :: term()
Create a new record data instance.
Attempts to find a specific implementation for the record type in the registry. If found, delegates to that module. Otherwise, creates a generic data container.
Parameters
rtype- Resource record type struct containing type informationrdata- Raw record data (format depends on record type)
Returns
- Record data struct (specific type if available, generic otherwise)
Examples
iex> rtype = DNS.ResourceRecordType.new(1) # A record
iex> data = DNS.Message.Record.Data.new(rtype, {192, 168, 1, 1})
iex> %DNS.Message.Record.Data.A{} = data