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); } }
/* ------------------------------------------------------------ */ public void putTo(Buffer buffer) throws IOException { int o = (_name instanceof CachedBuffer) ? ((CachedBuffer) _name).getOrdinal() : -1; if (o >= 0) buffer.put(_name); else { int s = _name.getIndex(); int e = _name.putIndex(); while (s < e) { byte b = _name.peek(s++); switch (b) { case '\r': case '\n': case ':': continue; default: buffer.put(b); } } } buffer.put((byte) ':'); buffer.put((byte) ' '); o = (_value instanceof CachedBuffer) ? ((CachedBuffer) _value).getOrdinal() : -1; if (o >= 0) buffer.put(_value); else { int s = _value.getIndex(); int e = _value.putIndex(); while (s < e) { byte b = _value.peek(s++); switch (b) { case '\r': case '\n': continue; default: buffer.put(b); } } } BufferUtil.putCRLF(buffer); }