'Convert the rdataset to wire format.
@param name: The owner name of the RRset that will be emitted
@type name: dns.name.Name object
@param file: The file to which the wire format data will be appended
@type file: file
@param compress: The compression table to use; the default is None.
@type compress: dict
@param origin: The origin to be appended to any relative names when
they are emitted.  The default is None.
@returns: the number of records emitted
@rtype: int'

def to_wire(self, name, file, compress=None, origin=None, override_rdclass=None, want_shuffle=True):

    if (override_rdclass is not None):
        rdclass = override_rdclass
        want_shuffle = False
    else:
        rdclass = self.rdclass
    file.seek(0, 2)
    if (len(self) == 0):
        name.to_wire(file, compress, origin)
        stuff = struct.pack('!HHIH', self.rdtype, rdclass, 0, 0)
        file.write(stuff)
        return 1
    else:
        if want_shuffle:
            l = list(self)
            random.shuffle(l)
        else:
            l = self
        for rd in l:
            name.to_wire(file, compress, origin)
            stuff = struct.pack('!HHIH', self.rdtype, rdclass, self.ttl, 0)
            file.write(stuff)
            start = file.tell()
            rd.to_wire(file, compress, origin)
            end = file.tell()
            assert ((end - start) < 65536)
            file.seek((start - 2))
            stuff = struct.pack('!H', (end - start))
            file.write(stuff)
            file.seek(0, 2)
        return len(self)
