U
    Sd                      @   s  d Z dZddlZddlmZ ddlmZ dZde> d ZdZdZ	dZ
dZd	Zd
Zd
ZedZedZdZdZdZdZdZdZdZdZeed	kredeedkreddd Zdd Zdd Zdd Zd d! Z d"d# Z!d$d% Z"d&d' Z#d(d) Z$d*d+ Z%d,d- Z&d.d/ Z'd0d1 Z(d2d3 Z)d4d5 Z*d6d7 Z+d8d9 Z,d:d; Z-d<d= Z.d>d? Z/d@dA Z0dBdC Z1dDdE Z2dFdG Z3dHdI Z4dJdK Z5ej6j7ej6j8ej6j9ej6j:fZ;dLdM Z<dS )NzFConstants and static functions to support protocol buffer wire format.z#robinson@google.com (Will Robinson)    N)
descriptor)message               ii   l        l             z<Iz<Qz<fz<dz"Format "I" is not a 32-bit number.   z"Format "Q" is not a 64-bit number.c                 C   s0   d|  krt ks$n td| | t> |B S )a  Returns an unsigned 32-bit integer that encodes the field number and
  wire type information in standard protocol message wire format.

  Args:
    field_number: Expected to be an integer in the range [1, 1 << 29)
    wire_type: One of the WIRETYPE_* constants.
  r   zUnknown wire type: %d)_WIRETYPE_MAXr   EncodeErrorTAG_TYPE_BITS)field_numberZ	wire_type r   H/tmp/pip-unpacked-wheel-1ori_g8k/google/protobuf/internal/wire_format.pyPackTagP   s    r   c                 C   s   | t ? | t@ fS )zkThe inverse of PackTag().  Given an unsigned 32-bit number,
  returns a (field_number, wire_type) tuple.
  )r   TAG_TYPE_MASK)tagr   r   r   	UnpackTag]   s    r   c                 C   s   | dkr| d> S | d> dA S )zZigZag Transform:  Encodes signed integers so that they can be
  effectively used with varint encoding.  See wire_format.h for
  more details.
  r   r   r   valuer   r   r   ZigZagEncoded   s    r   c                 C   s   | d@ s| d? S | d? dA S )zInverse of ZigZagEncode().r   r   r   r   r   r   r   ZigZagDecoden   s    r   c                 C   s
   t | |S N)Int64ByteSizer   int32r   r   r   Int32ByteSizez   s    r   c                 C   s   t d| @ S Nr
   )_VarUInt64ByteSizeNoTag)r   r   r   r   Int32ByteSizeNoTag~   s    r"   c                 C   s   t | d|@ S r    UInt64ByteSizer   Zint64r   r   r   r      s    r   c                 C   s
   t | |S r   r#   )r   Zuint32r   r   r   UInt32ByteSize   s    r&   c                 C   s   t | t| S r   )TagByteSizer!   )r   uint64r   r   r   r$      s    r$   c                 C   s   t | t|S r   )r&   r   r   r   r   r   SInt32ByteSize   s    r)   c                 C   s   t | t|S r   )r$   r   r%   r   r   r   SInt64ByteSize   s    r*   c                 C   s   t | d S Nr   r'   )r   Zfixed32r   r   r   Fixed32ByteSize   s    r-   c                 C   s   t | d S Nr   r,   )r   Zfixed64r   r   r   Fixed64ByteSize   s    r/   c                 C   s   t | d S r+   r,   )r   Zsfixed32r   r   r   SFixed32ByteSize   s    r0   c                 C   s   t | d S r.   r,   )r   Zsfixed64r   r   r   SFixed64ByteSize   s    r1   c                 C   s   t | d S r+   r,   )r   Zfltr   r   r   FloatByteSize   s    r2   c                 C   s   t | d S r.   r,   )r   doubler   r   r   DoubleByteSize   s    r4   c                 C   s   t | d S )Nr   r,   r   br   r   r   BoolByteSize   s    r7   c                 C   s
   t | |S r   )r&   )r   enumr   r   r   EnumByteSize   s    r9   c                 C   s   t | |dS )Nzutf-8)BytesByteSizeencode)r   stringr   r   r   StringByteSize   s    r=   c                 C   s   t | tt| t| S r   )r'   r!   lenr5   r   r   r   r:      s
    
r:   c                 C   s   dt |  |  S )Nr   )r'   ByteSizer   r   r   r   r   GroupByteSize   s    
rA   c                 C   s   t | t|  |  S r   r'   r!   r?   r@   r   r   r   MessageByteSize   s
    
rC   c                 C   sH   dt d t d t d }|t| 7 }| }|t|7 }||7 }|S )Nr   r   r   rB   )r   msgZ
total_sizeZmessage_sizer   r   r   MessageSetItemByteSize   s    rE   c                 C   s   t t| dS )zEReturns the bytes required to serialize a tag with this field number.r   )r!   r   )r   r   r   r   r'      s    r'   c                 C   s   | dkrdS | dkrdS | dkr$dS | dkr0dS | d	kr<d
S | dkrHdS | dkrTdS | dkr`dS | dkrldS | t krtd|  dS )zReturns the number of bytes required to serialize a single varint
  using boundary value comparisons. (unrolled loop optimization -WPierce)
  uint64 must be unsigned.
     r   i?  r   i r   ir   l    r   l      l       l   r   r	   	   zValue out of range: %d
   )
UINT64_MAXr   r   )r(   r   r   r   r!      s*             r!   c                 C   s   | t kS )zReturn true iff packable = true is valid for fields of this type.

  Args:
    field_type: a FieldDescriptor::Type value.

  Returns:
    True iff fields of this type are packable.
  )NON_PACKABLE_TYPES)Z
field_typer   r   r   IsTypePackable  s    	rM   )=__doc__
__author__structZgoogle.protobufr   r   r   r   ZWIRETYPE_VARINTZWIRETYPE_FIXED64ZWIRETYPE_LENGTH_DELIMITEDZWIRETYPE_START_GROUPZWIRETYPE_END_GROUPZWIRETYPE_FIXED32r   intZ	INT32_MAXZ	INT32_MINZ
UINT32_MAXZ	INT64_MAXZ	INT64_MINrK   ZFORMAT_UINT32_LITTLE_ENDIANZFORMAT_UINT64_LITTLE_ENDIANZFORMAT_FLOAT_LITTLE_ENDIANZFORMAT_DOUBLE_LITTLE_ENDIANcalcsizeAssertionErrorr   r   r   r   r   r"   r   r&   r$   r)   r*   r-   r/   r0   r1   r2   r4   r7   r9   r=   r:   rA   rC   rE   r'   r!   ZFieldDescriptorZTYPE_STRINGZ
TYPE_GROUPZTYPE_MESSAGEZ
TYPE_BYTESrL   rM   r   r   r   r   <module>   sv   
