'Return a string containing the message in DNS compressed wire
format.
Additional keyword arguments are passed to the rrset to_wire()
method.
@param origin: The origin to be appended to any relative names.
@type origin: dns.name.Name object
@param max_size: The maximum size of the wire format output; default
is 0, which means \'the message\'s request payload, if nonzero, or
65536\'.
@type max_size: int
@raises dns.exception.TooBig: max_size was exceeded
@rtype: string'

def to_wire(self, origin=None, max_size=0, **kw):

    if (max_size == 0):
        if (self.request_payload != 0):
            max_size = self.request_payload
        else:
            max_size = 65535
    if (max_size < 512):
        max_size = 512
    elif (max_size > 65535):
        max_size = 65535
    r = dns.renderer.Renderer(self.id, self.flags, max_size, origin)
    for rrset in self.question:
        r.add_question(rrset.name, rrset.rdtype, rrset.rdclass)
    for rrset in self.answer:
        r.add_rrset(dns.renderer.ANSWER, rrset, **kw)
    for rrset in self.authority:
        r.add_rrset(dns.renderer.AUTHORITY, rrset, **kw)
    if (self.edns >= 0):
        r.add_edns(self.edns, self.ednsflags, self.payload, self.options)
    for rrset in self.additional:
        r.add_rrset(dns.renderer.ADDITIONAL, rrset, **kw)
    r.write_header()
    if (not (self.keyname is None)):
        r.add_tsig(self.keyname, self.keyring[self.keyname], self.fudge, self.original_id, self.tsig_error, self.other_data, self.request_mac, self.keyalgorithm)
        self.mac = r.mac
    return r.get_wire()
