class_docstr: Initialize the serialization library.
  
  This defines a custom serializer for object refs and also tells ray to
  serialize several exception classes that we define for error handling.
code: def _serialize_to_msgpack(self, value):
      # Only RayTaskError is possible to be serialized here. We don't
      # need to deal with other exception types here.
      contained_object_refs = []
  
      if isinstance(value, RayTaskError):
          if issubclass(value.cause.__class__, TaskCancelledError):
              # Handle task cancellation errors separately because we never
              # want to warn about tasks that were intentionally cancelled by
              # the user.
              metadata = str(ErrorType.Value("TASK_CANCELLED")).encode(
                  "ascii"
              )
              value = value.to_bytes()
          else:
              metadata = str(
                  ErrorType.Value("TASK_EXECUTION_EXCEPTION")
              ).encode("ascii")
              value = value.to_bytes()
      elif isinstance(value, ray.actor.ActorHandle):
          # TODO(fyresone): ActorHandle should be serialized via the
          # custom type feature of cross-language.
          serialized, actor_handle_id = value._serialization_helper()
          contained_object_refs.append(actor_handle_id)
          # Update ref counting for the actor handle
          metadata = ray_constants.OBJECT_METADATA_TYPE_ACTOR_HANDLE
          value = serialized
      else:
          metadata = ray_constants.OBJECT_METADATA_TYPE_CROSS_LANGUAGE
  
      python_objects = []
  
      def _python_serializer(o):
          index = len(python_objects)
          python_objects.append(o)
          return index
  
      msgpack_data = MessagePackSerializer.dumps(
          value, _python_serializer
      )
  
      if python_objects:
          metadata = ray_constants.OBJECT_METADATA_TYPE_PYTHON
          pickle5_serialized_object = self._serialize_to_pickle5(
              metadata, python_objects
          )
      else:
          pickle5_serialized_object = None
  
      return MessagePackSerializedObject(
          metadata,
          msgpack_data,
          contained_object_refs,
          pickle5_serialized_object,
      )
  
imports: import io
  import logging
  import threading
  import traceback
  from typing import Any
  import google.protobuf.message
  import ray._private.utils
  import ray.cloudpickle
  from ray._private import ray_constants
  from ray._raylet import MessagePackSerializedObject, MessagePackSerializer, DynamicObjectRefGenerator, Pickle5SerializedObject, Pickle5Writer, RawSerializedObject, split_buffer, unpack_pickle5_buffers
  from ray.core.generated.common_pb2 import ErrorType, RayErrorInfo
  from ray.exceptions import ActorPlacementGroupRemoved, ActorUnschedulableError, LocalRayletDiedError, NodeDiedError, ObjectFetchTimedOutError, ObjectLostError, ObjectReconstructionFailedError, ObjectReconstructionFailedLineageEvictedError, ObjectReconstructionFailedMaxAttemptsExceededError, OutOfDiskError, OwnerDiedError, PlasmaObjectNotAvailable, RayActorError, RayError, RaySystemError, RayTaskError, ReferenceCountingAssertionError, ObjectFreedError, RuntimeEnvSetupError, TaskCancelledError, TaskPlacementGroupRemoved, TaskUnschedulableError, WorkerCrashedError, OutOfMemoryError, ObjectRefStreamEndOfStreamError
  from ray.util import serialization_addons
  from ray.util import inspect_serializability
label_desc: Use image node_id 18 for calling the SerializationContext obj's underlying member method code with example usage: obj._serialize_to_msgpack(value) and returns: MessagePackSerializedObject, index