o
    Mf9  ã                   @   s   d dl Z G dd„ dƒZdS )é    Nc                   @   s,   e Zd ZdZddœdefdd„Zdd„ ZdS )	Ú	BytesRulea‡  A marshal between Python strings and protobuf bytes.

    Note: this conversion is asymmetric because Python does have a bytes type.
    It is sometimes necessary to convert proto bytes fields to strings, e.g. for
    JSON encoding, marshalling a message to a dict. Because bytes fields can
    represent arbitrary data, bytes fields are base64 encoded when they need to
    be represented as strings.

    It is necessary to have the conversion be bidirectional, i.e.
    my_message == MyMessage(MyMessage.to_dict(my_message))

    To accomplish this, we need to intercept assignments from strings and
    base64 decode them back into bytes.
    N)Úabsentr   c                C   s   |S )N© )ÚselfÚvaluer   r   r   ú[/var/www/html/analyze/labelStudio/lib/python3.10/site-packages/proto/marshal/rules/bytes.pyÚ	to_python#   s   zBytesRule.to_pythonc                 C   s:   t |tƒr| d¡}|ddt|ƒd   7 }t |¡}|S )Nzutf-8ó   =é   )Ú
isinstanceÚstrÚencodeÚlenÚbase64Úurlsafe_b64decode)r   r   r   r   r   Úto_proto&   s
   


zBytesRule.to_proto)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úboolr   r   r   r   r   r   r      s    r   )r   r   r   r   r   r   Ú<module>   s   