'Encode this SMB message into a series of bytes suitable to be embedded with a NetBIOS session message.
AssertionError will be raised if this SMB message has not been initialized with a Payload instance
@return: a string containing the encoded SMB message'

def encode(self):

    assert self.payload
    self.pid = os.getpid()
    self.payload.prepare(self)
    parameters_len = len(self.parameters_data)
    assert ((parameters_len % 2) == 0)
    headers_data = struct.pack(self.HEADER_STRUCT_FORMAT, '\xffSMB', self.command, self.status.internal_value, self.flags, self.flags2, ((self.pid >> 16) & 65535), self.security, self.tid, (self.pid & 65535), self.uid, self.mid, int((parameters_len / 2)))
    return (((headers_data + self.parameters_data) + struct.pack('<H', len(self.data))) + self.data)
