Atomically sets the value to the given updated value only if the current value == the expected value.

        :param expected: (object), the expected value.
        :param updated: (object), the new value.
        :return: (bool), ``true`` if successful; or ``false`` if the actual value was not equal to the expected value.

def compare_and_set(self, expected, updated):
        """
        Atomically sets the value to the given updated value only if the current value == the expected value.

        :param expected: (object), the expected value.
        :param updated: (object), the new value.
        :return: (bool), ``true`` if successful; or ``false`` if the actual value was not equal to the expected value.
        """
        return self._encode_invoke(atomic_reference_compare_and_set_codec,
                                   expected=self._to_data(expected), updated=self._to_data(updated))