
    qi+                         d Z ddlmZ ddlmZ ddlmZ ddlmc m	c m
c mZ ddlmZmZmZmZ ddlmZ  G d d	e      Zy)
z+Frame serialization interfaces for Pipecat.    )abstractmethod)Optional)	BaseModelN)FrameOutputTransportMessageFrame!OutputTransportMessageUrgentFrame
StartFrame)
BaseObjectc                        e Zd ZdZ G d de      Zddee   f fdZdede	fd	Z
defd
Zededeez  dz  fd       Zedeez  dedz  fd       Z xZS )FrameSerializerzAbstract base class for frame serialization implementations.

    Defines the interface for converting frames to/from serialized formats
    for transmission or storage. Subclasses must implement the core
    serialize/deserialize methods.
    c                        e Zd ZU dZdZeed<   y)FrameSerializer.InputParamsa  Base configuration parameters for FrameSerializer.

        Parameters:
            ignore_rtvi_messages: Whether to ignore RTVI protocol messages during serialization.
                Defaults to True to prevent RTVI messages from being sent to external transports.
        Tignore_rtvi_messagesN)__name__
__module____qualname____doc__r   bool__annotations__     U/opt/pipecat/venv/lib/python3.12/site-packages/pipecat/serializers/base_serializer.pyInputParamsr       s    	 &*d)r   r   Nparamsc                 ^    t        |   di | |xs t        j                         | _        y)zInitialize the FrameSerializer.

        Args:
            params: Configuration parameters.
            **kwargs: Additional arguments passed to BaseObject (e.g., name).
        Nr   )super__init__r   r   _params)selfr   kwargs	__class__s      r   r   zFrameSerializer.__init__*   s*     	"6">!<!<!>r   framereturnc                     | j                   j                  rCt        |t        t        f      r-|j
                  j                  d      t        j                  k(  ryy)aq  Check if a frame should be ignored during serialization.

        This method filters out RTVI protocol messages when ignore_rtvi_messages is enabled.
        Subclasses can override this to add additional filtering logic.

        Args:
            frame: The frame to check.

        Returns:
            True if the frame should be ignored, False otherwise.
        labelTF)	r   r   
isinstancer   r   messagegetRTVIMESSAGE_LABELr   r"   s     r   should_ignore_framez#FrameSerializer.should_ignore_frame4   sE     LL--5#>@a"bc!!'*d.@.@@r   c                    K   yw)zInitialize the serializer with startup configuration.

        Args:
            frame: StartFrame containing initialization parameters.
        Nr   r+   s     r   setupzFrameSerializer.setupH   s      	   c                    K   yw)zConvert a frame to its serialized representation.

        Args:
            frame: The frame to serialize.

        Returns:
            Serialized frame data as string, bytes, or None if serialization fails.
        Nr   r+   s     r   	serializezFrameSerializer.serializeP         	r/   datac                    K   yw)zConvert serialized data back to a frame object.

        Args:
            data: Serialized frame data as string or bytes.

        Returns:
            Reconstructed Frame object, or None if deserialization fails.
        Nr   )r   r3   s     r   deserializezFrameSerializer.deserialize\   r2   r/   )N)r   r   r   r   r   r   r   r   r   r   r,   r	   r.   r   strbytesr1   r5   __classcell__)r!   s   @r   r   r      s    *i *?x4 ? 4 (  	U 	sU{T/A 	 	 	cEk 	edl 	 	r   r   )r   abcr   typingr   pydanticr   )pipecat.processors.frameworks.rtvi.models
processors
frameworksrtvimodelsr)   pipecat.frames.framesr   r   r   r	   pipecat.utils.base_objectr
   r   r   r   r   <module>rC      s6    2    8 8  1Nj Nr   