def encode(self):
        """Encode the DAT packet based on instance variables, populating
        self.buffer, returning self."""
        fmt = b"!HH%dsx" % len(self.errmsgs[self.errorcode])
        log.debug("encoding ERR packet with fmt %s", fmt)
        self.buffer = struct.pack(fmt,
                                  self.opcode,
                                  self.errorcode,
                                  self.errmsgs[self.errorcode])
        return self
Encode the DAT packet based on instance variables, populating
        self.buffer, returning self.