
XXc           @   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 d3  Z e d5  Z d7 Z d9 Z d; Z d= Z d Z d Z d Z d Z e j e  d
 k r e d   n  e j e  d k re d   n  d   Z d   Z d   Z d   Z d   Z  d   Z! d   Z" d   Z# d   Z$ d    Z% d!   Z& d"   Z' d#   Z( d$   Z) d%   Z* d&   Z+ d'   Z, d(   Z- d)   Z. d*   Z/ d+   Z0 d,   Z1 d-   Z2 d.   Z3 d/   Z4 d0   Z5 e j6 j7 e j6 j8 e j6 j9 e j6 j: f Z; d1   Z< d S(>   sF   Constants and static functions to support protocol buffer wire format.s#   robinson@google.com (Will Robinson)iN(   t
   descriptor(   t   messagei   i   i    i   i   i   i   i    i?   i@   s   <Is   <Qs   <fs   <ds"   Format "I" is not a 32-bit number.i   s"   Format "Q" is not a 64-bit number.c         C   s>   d | k o t  k n s2 t j d |   n  |  t >| BS(   s  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.
  i    s   Unknown wire type: %d(   t   _WIRETYPE_MAXR   t   EncodeErrort   TAG_TYPE_BITS(   t   field_numbert	   wire_type(    (    sF   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/wire_format.pyt   PackTagP   s    c         C   s   |  t  ?|  t @f S(   sk   The inverse of PackTag().  Given an unsigned 32-bit number,
  returns a (field_number, wire_type) tuple.
  (   R   t   TAG_TYPE_MASK(   t   tag(    (    sF   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/wire_format.pyt	   UnpackTag]   s    c         C   s    |  d k r |  d >S|  d >d AS(   s   ZigZag Transform:  Encodes signed integers so that they can be
  effectively used with varint encoding.  See wire_format.h for
  more details.
  i    i   i(    (   t   value(    (    sF   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/wire_format.pyt   ZigZagEncoded   s    c         C   s   |  d @s |  d ?S|  d ?d AS(   s   Inverse of ZigZagEncode().i   i    i(    (   R   (    (    sF   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/wire_format.pyt   ZigZagDecoden   s    
c         C   s   t  |  |  S(   N(   t   Int64ByteSize(   R   t   int32(    (    sF   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/wire_format.pyt   Int32ByteSizez   s    c         C   s   t  d |  @ S(   Nl    (   t   _VarUInt64ByteSizeNoTag(   R   (    (    sF   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/wire_format.pyt   Int32ByteSizeNoTag~   s    c         C   s   t  |  d | @ S(   Nl    (   t   UInt64ByteSize(   R   t   int64(    (    sF   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/wire_format.pyR      s    c         C   s   t  |  |  S(   N(   R   (   R   t   uint32(    (    sF   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/wire_format.pyt   UInt32ByteSize   s    c         C   s   t  |   t |  S(   N(   t   TagByteSizeR   (   R   t   uint64(    (    sF   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/wire_format.pyR      s    c         C   s   t  |  t |   S(   N(   R   R   (   R   R   (    (    sF   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/wire_format.pyt   SInt32ByteSize   s    c         C   s   t  |  t |   S(   N(   R   R   (   R   R   (    (    sF   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/wire_format.pyt   SInt64ByteSize   s    c         C   s   t  |   d S(   Ni   (   R   (   R   t   fixed32(    (    sF   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/wire_format.pyt   Fixed32ByteSize   s    c         C   s   t  |   d S(   Ni   (   R   (   R   t   fixed64(    (    sF   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/wire_format.pyt   Fixed64ByteSize   s    c         C   s   t  |   d S(   Ni   (   R   (   R   t   sfixed32(    (    sF   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/wire_format.pyt   SFixed32ByteSize   s    c         C   s   t  |   d S(   Ni   (   R   (   R   t   sfixed64(    (    sF   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/wire_format.pyt   SFixed64ByteSize   s    c         C   s   t  |   d S(   Ni   (   R   (   R   t   flt(    (    sF   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/wire_format.pyt   FloatByteSize   s    c         C   s   t  |   d S(   Ni   (   R   (   R   t   double(    (    sF   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/wire_format.pyt   DoubleByteSize   s    c         C   s   t  |   d S(   Ni   (   R   (   R   t   b(    (    sF   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/wire_format.pyt   BoolByteSize   s    c         C   s   t  |  |  S(   N(   R   (   R   t   enum(    (    sF   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/wire_format.pyt   EnumByteSize   s    c         C   s   t  |  | j d   S(   Ns   utf-8(   t   BytesByteSizet   encode(   R   t   string(    (    sF   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/wire_format.pyt   StringByteSize   s    c         C   s$   t  |   t t |   t |  S(   N(   R   R   t   len(   R   R'   (    (    sF   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/wire_format.pyR+      s    c         C   s   d t  |   | j   S(   Ni   (   R   t   ByteSize(   R   R   (    (    sF   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/wire_format.pyt   GroupByteSize   s    c         C   s$   t  |   t | j    | j   S(   N(   R   R   R0   (   R   R   (    (    sF   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/wire_format.pyt   MessageByteSize   s    c         C   s^   d t  d  t  d  t  d  } | t |   7} | j   } | t |  7} | | 7} | S(   Ni   i   i   (   R   R   R0   (   R   t   msgt
   total_sizet   message_size(    (    sF   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/wire_format.pyt   MessageSetItemByteSize   s    $
c         C   s   t  t |  d   S(   sE   Returns the bytes required to serialize a tag with this field number.i    (   R   R   (   R   (    (    sF   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/wire_format.pyR      s    c         C   s   |  d k r d S|  d k r  d S|  d k r0 d S|  d k r@ d S|  d	 k rP d
 S|  d k r` d S|  d k rp d S|  d k r d S|  d k r d S|  t  k r t j d |    n  d S(   s   Returns the number of bytes required to serialize a single varint
  using boundary value comparisons. (unrolled loop optimization -WPierce)
  uint64 must be unsigned.
  i   i   i?  i   i i   ii   I   i   I  i   I i   I i   Ii	   s   Value out of range: %di
   (   t
   UINT64_MAXR   R   (   R   (    (    sF   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/wire_format.pyR      s*             c         C   s
   |  t  k S(   s   Return 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.
  (   t   NON_PACKABLE_TYPES(   t
   field_type(    (    sF   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/wire_format.pyt   IsTypePackable  s    	I       iI       i   I       I    l            l    l            l         l            l    (=   t   __doc__t
   __author__t   structt   google.protobufR    R   R   R   t   WIRETYPE_VARINTt   WIRETYPE_FIXED64t   WIRETYPE_LENGTH_DELIMITEDt   WIRETYPE_START_GROUPt   WIRETYPE_END_GROUPt   WIRETYPE_FIXED32R   t   intt	   INT32_MAXt	   INT32_MINt
   UINT32_MAXt	   INT64_MAXt	   INT64_MINR7   t   FORMAT_UINT32_LITTLE_ENDIANt   FORMAT_UINT64_LITTLE_ENDIANt   FORMAT_FLOAT_LITTLE_ENDIANt   FORMAT_DOUBLE_LITTLE_ENDIANt   calcsizet   AssertionErrorR   R
   R   R   R   R   R   R   R   R   R   R   R   R    R"   R$   R&   R(   R*   R.   R+   R1   R2   R6   R   R   t   FieldDescriptort   TYPE_STRINGt
   TYPE_GROUPt   TYPE_MESSAGEt
   TYPE_BYTESR8   R:   (    (    (    sF   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/wire_format.pyt   <module>   st   			
																										