private static Record newRecord(
      Name name, int type, int dclass, long ttl, int length, DNSInput in) throws IOException {
    Record rec;
    int recstart;
    rec = getEmptyRecord(name, type, dclass, ttl, in != null);
    if (in != null) {
      if (in.remaining() < length) throw new WireParseException("truncated record");
      in.setActive(length);

      rec.rrFromWire(in);

      if (in.remaining() > 0) throw new WireParseException("invalid record length");
      in.clearActive();
    }
    return rec;
  }
  static Record fromWire(DNSInput in, int section, boolean isUpdate) throws IOException {
    int type, dclass;
    long ttl;
    int length;
    Name name;
    Record rec;

    name = new Name(in);
    type = in.readU16();
    dclass = in.readU16();

    if (section == Section.QUESTION) return newRecord(name, type, dclass);

    ttl = in.readU32();
    length = in.readU16();
    if (length == 0 && isUpdate) return newRecord(name, type, dclass, ttl);
    rec = newRecord(name, type, dclass, ttl, length, in);
    return rec;
  }