public void decode(Buffer buffer, int nbRecords) throws IOException { for (int i = 0; i < nbRecords; i++) { Name name = getMessage().getCompression().decodeName(buffer); Type type = Type.getType(BufferUtil.get16(buffer)); DnsClass clazz = DnsClass.getClass(BufferUtil.get16(buffer)); Record record = type.newRecord(); record.setName(name); record.setDnsClass(clazz); record.setTtl(BufferUtil.getInt(buffer)); int dataLength = BufferUtil.get16(buffer); record.doDecode(buffer, getMessage().getCompression(), dataLength); _records.add(record); } }
public void encode(Buffer buffer) throws IOException { for (Record record : _records) { getMessage().getCompression().encodeName(record.getName(), buffer); record.getType().encode(buffer); record.getDnsClass().encode(buffer); BufferUtil.putInt(buffer, record.getTtl()); int index = buffer.putIndex(); buffer.setPutIndex(index + 2); record.doEncode(buffer, getMessage().getCompression()); BufferUtil.poke16(buffer, index, buffer.putIndex() - index - 2); } }