'Encode this SMB2 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 SMB2 message'

def encode(self):

    assert self.payload
    self.pid = os.getpid()
    self.payload.prepare(self)
    headers_data = (struct.pack(self.HEADER_STRUCT_FORMAT, '\xfeSMB', self.HEADER_SIZE, 0, self.status, self.command, 0, self.flags) + struct.pack(self.SYNC_HEADER_STRUCT_FORMAT, self.next_command_offset, self.mid, self.pid, self.tid, self.session_id, self.signature))
    return (headers_data + self.data)
