Encode or decode the RDATA field in multicast DNS TXT records. For use with DNS-\/\+Based Service Discovery. For details see \href{https://tools.ietf.org/html/rfc6763}{\texttt{ RFC 6763}}.

\href{https://travis-ci.org/watson/dns-txt}{\texttt{ }} \href{https://github.com/feross/standard}{\texttt{ }} \href{https://github.com/mafintosh/abstract-encoding}{\texttt{ }}\hypertarget{md_sfcode_node_modules_dns_txt_README_autotoc_md8242}{}\doxysection{Installation}\label{md_sfcode_node_modules_dns_txt_README_autotoc_md8242}

\begin{DoxyCode}{0}
\DoxyCodeLine{npm install dns-\/txt }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_dns_txt_README_autotoc_md8243}{}\doxysection{Usage}\label{md_sfcode_node_modules_dns_txt_README_autotoc_md8243}

\begin{DoxyCode}{0}
\DoxyCodeLine{var txt = require('dns-\/txt')()}
\DoxyCodeLine{}
\DoxyCodeLine{var obj = \{}
\DoxyCodeLine{  foo: 1,}
\DoxyCodeLine{  bar: 2}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{var enc = txt.encode(obj) // <Buffer 05 66 6f 6f 3d 31 05 62 61 72 3d 32>}
\DoxyCodeLine{}
\DoxyCodeLine{txt.decode(enc) // \{ foo: '1', bar: '2' \} }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_dns_txt_README_autotoc_md8244}{}\doxysection{API}\label{md_sfcode_node_modules_dns_txt_README_autotoc_md8244}
The encoder and decoder conforms to \href{https://tools.ietf.org/html/rfc6763}{\texttt{ RFC 6763}}.\hypertarget{md_sfcode_node_modules_dns_txt_README_autotoc_md8245}{}\doxysubsection{Initialize}\label{md_sfcode_node_modules_dns_txt_README_autotoc_md8245}
The module exposes a constructor function which can be called with an optional options object\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{var txt = require('dns-\/txt')(\{ binary: true \}) }

\end{DoxyCode}


The options are\+:


\begin{DoxyItemize}
\item {\ttfamily binary} -\/ If set to {\ttfamily true} all values will be returned as {\ttfamily Buffer} objects. The default behavior is to turn all values into strings. But according to the RFC the values can be any binary data. If you expect binary data, use this option.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_dns_txt_README_autotoc_md8246}{}\doxysubsubsection{$<$tt$>$txt.\+encode(obj, \mbox{[}buffer\mbox{]}, \mbox{[}offset\mbox{]})$<$/tt$>$}\label{md_sfcode_node_modules_dns_txt_README_autotoc_md8246}
Takes a key/value object and returns a buffer with the encoded TXT record. If a buffer is passed as the second argument the object should be encoded into that buffer. Otherwise a new buffer should be allocated If an offset is passed as the third argument the object should be encoded at that byte offset. The byte offset defaults to {\ttfamily 0}.

This module does not actively validate the key/value pairs, but keep the following in rules in mind\+:


\begin{DoxyItemize}
\item To be RFC compliant, each key should conform with the rules as specified in \href{https://tools.ietf.org/html/rfc6763\#section-6.4}{\texttt{ section 6.\+4}}.
\item To be RFC compliant, each value should conform with the rules as specified in \href{https://tools.ietf.org/html/rfc6763\#section-6.5}{\texttt{ section 6.\+5}}.
\end{DoxyItemize}

After encoding {\ttfamily txt.\+encode.\+bytes} is set to the amount of bytes used to encode the object.\hypertarget{md_sfcode_node_modules_dns_txt_README_autotoc_md8247}{}\doxysubsubsection{$<$tt$>$txt.\+decode(buffer, \mbox{[}offset\mbox{]}, \mbox{[}length\mbox{]})$<$/tt$>$}\label{md_sfcode_node_modules_dns_txt_README_autotoc_md8247}
Takes a buffer and returns a decoded key/value object. If an offset is passed as the second argument the object should be decoded from that byte offset. The byte offset defaults to {\ttfamily 0}. Note that all keys will be lowercased and all values will be Buffer objects.

After decoding {\ttfamily txt.\+decode.\+bytes} is set to the amount of bytes used to decode the object.\hypertarget{md_sfcode_node_modules_dns_txt_README_autotoc_md8248}{}\doxysubsubsection{$<$tt$>$txt.\+encoding\+Length(obj)$<$/tt$>$}\label{md_sfcode_node_modules_dns_txt_README_autotoc_md8248}
Takes a single key/value object and returns the number of bytes that the given object would require if encoded.\hypertarget{md_sfcode_node_modules_dns_txt_README_autotoc_md8249}{}\doxysection{License}\label{md_sfcode_node_modules_dns_txt_README_autotoc_md8249}
MIT 