o
    Ín~bë  ã                   @   sr   d dl Z d dlmZ d dlmZ e jree	efZ
neeeeefZ
dZdd„ Zdd„ Zd	d
„ Zdd„ Zddd„ZdS )é    N)ÚGeneratorType)ÚMessagel        c                 C   s   t | ƒt@ dkS )zb
    :param emsg: emsg number
    :type emsg: int
    :return: True or False
    :rtype: bool
    r   ©ÚintÚprotobuf_mask©Zemsg© r   ú</usr/local/lib/python3.10/dist-packages/steam/utils/proto.pyÚis_proto   s   r
   c                 C   s   t | ƒtB S )zk
    :param emsg: emsg number
    :type emsg: int
    :return: emsg with proto bit set
    :rtype: int
    r   r   r   r   r	   Úset_proto_bit   s   r   c                 C   s   t | ƒt @ S )zo
    :param emsg: emsg number
    :type emsg: int
    :return: emsg with proto bit removed
    :rtype: int
    r   r   r   r   r	   Úclear_proto_bit!   s   r   c                 C   sˆ   t | tƒs	tdƒ‚i }|  ¡ D ]2\}}|j|jkr2|j|jkr*tt	t
|ƒƒ||j< qt
|ƒ||j< q|j|jkr<t|ƒn|||j< q|S )zßConverts protobuf message instance to dict

    :param message: protobuf message instance
    :return: parameters and their values
    :rtype: dict
    :raises: :class:`.TypeError` if ``message`` is not a proto message
    ú7Expected `message` to be a instance of protobuf message)Ú
isinstanceÚ_ProtoMessageTypeÚ	TypeErrorZ
ListFieldsÚtypeÚTYPE_MESSAGEÚlabelÚLABEL_REPEATEDÚlistÚmapÚproto_to_dictÚname)ÚmessageÚdataÚdescÚfieldr   r   r	   r   *   s   
 r   Tc           
      C   s:  t | tƒs	tdƒ‚t |tƒstdƒ‚|r|  ¡  | jj}| ¡ D ]z\}}|| }|j|j	kr}|j
|jkrct |tƒsEtdt|ƒt|ƒf ƒ‚t| |ƒ}|sQ|dd…= |D ]}t| |ƒ ¡ }	t|	|ƒ qSq t |tƒsttdt|ƒttƒf ƒ‚tt| |ƒ|ƒ q t |tƒr”t| |ƒ}|sŽ|dd…= | |¡ q t| ||ƒ q | S )aO  Fills protobuf message parameters inplace from a :class:`dict`

    :param message: protobuf message instance
    :param data: parameters and values
    :type data: dict
    :param clear: whether clear exisiting values
    :type clear: bool
    :return: value of message paramater
    :raises: incorrect types or values will raise
    r   z$Expected `data` to be of type `dict`z&Expected %s to be of type list, got %sNz&Expected %s to be of type dict, got %s)r   r   r   ÚdictZClearZ
DESCRIPTORZfields_by_nameÚitemsr   r   r   r   Ú_list_typesÚreprÚgetattrÚaddÚproto_fill_from_dictÚextendÚsetattr)
r   r   ÚclearZfield_descsÚkeyÚvalr   Zlist_refÚitemZitem_messager   r   r	   r#   B   s6   



þ


r#   )T)ÚsixÚtypesr   Z_GeneratorTypeZgoogle.protobuf.messager   r   ÚPY2r   Úxranger   Úranger   Úfilterr   r
   r   r   r   r#   r   r   r   r	   Ú<module>   s   			