o
    i+                     @   s~   d Z ddlmZ ddlmZ ddlmZ ddlm  m	  m
  mZ ddlmZmZmZmZ ddlmZ G dd	 d	eZdS )
z+Frame serialization interfaces for Pipecat.    )abstractmethod)Optional)	BaseModelN)FrameOutputTransportMessageFrame!OutputTransportMessageUrgentFrame
StartFrame)
BaseObjectc                       s   e Zd ZdZG dd deZddee f fddZded	e	fd
dZ
defddZeded	eeB dB fddZedeeB d	edB fddZ  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                   @   s   e Zd ZU dZdZeed< dS )z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__ r   r   W/home/ubuntu/.local/lib/python3.10/site-packages/pipecat/serializers/base_serializer.pyInputParams    s   
 r   Nparamsc                    s$   t  jdi | |pt | _dS )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__r   r   r   *   s   zFrameSerializer.__init__framereturnc                 C   s0   | j jrt|ttfr|jdtjkrdS dS )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   r   r   r   should_ignore_frame4   s   z#FrameSerializer.should_ignore_framec                       dS )zInitialize the serializer with startup configuration.

        Args:
            frame: StartFrame containing initialization parameters.
        Nr   r%   r   r   r   setupH   s   zFrameSerializer.setupc                    r'   )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%   r   r   r   	serializeP      
zFrameSerializer.serializedatac                    r'   )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   r+   r   r   r   deserialize\   r*   zFrameSerializer.deserialize)N)r   r   r   r   r   r   r   r   r   r   r&   r   r(   r   strbytesr)   r,   __classcell__r   r   r   r   r
      s    

$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   r   <module>   s   