* @return The {@link DnsMessage}.
* @throws IOException
*/
public DnsMessage decode( IoBuffer in ) throws IOException
{
DnsMessageModifier modifier = new DnsMessageModifier();
modifier.setTransactionId( in.getUnsignedShort() );
byte header = in.get();
modifier.setMessageType( decodeMessageType( header ) );
modifier.setOpCode( decodeOpCode( header ) );
modifier.setAuthoritativeAnswer( decodeAuthoritativeAnswer( header ) );
modifier.setTruncated( decodeTruncated( header ) );
modifier.setRecursionDesired( decodeRecursionDesired( header ) );
header = in.get();
modifier.setRecursionAvailable( decodeRecursionAvailable( header ) );
modifier.setResponseCode( decodeResponseCode( header ) );
short questionCount = in.getShort();
short answerCount = in.getShort();
short authorityCount = in.getShort();
short additionalCount = in.getShort();
logger.debug( "decoding {} question records", questionCount );
modifier.setQuestionRecords( getQuestions( in, questionCount ) );
logger.debug( "decoding {} answer records", answerCount );
modifier.setAnswerRecords( getRecords( in, answerCount ) );
logger.debug( "decoding {} authority records", authorityCount );
modifier.setAuthorityRecords( getRecords( in, authorityCount ) );
logger.debug( "decoding {} additional records", additionalCount );
modifier.setAdditionalRecords( getRecords( in, additionalCount ) );
return modifier.getDnsMessage();
}