U Xzf_—ã@sJdZdZddlZddlZddlZdZejr0eZnddl Z e   e  d¡¡Z ddl mZddl mZddl mZdd lmZd Ze ZedZejZd d „Zd d„ZedeƒZedeƒZedeƒZedeƒZdd„Zdd„Zdd„Z dd„Z!dd„Z"dd„Z#dKd d!„Z$eej%eƒZ&eej%eƒZ'eej%eƒZ(eej%eƒZ)e ej%eej*ƒZ+e ej%eej*ƒZ,e!ej-d"ƒZ.e!ej/d#ƒZ0e!ej-d$ƒZ1e!ej/d%ƒZ2e"ƒZ3e#ƒZ4e ej%ee5ƒZ6dLd&d'„Z7dMd(d)„Z8d*d+„Z9d,d-„Z:e ;d.ej<¡Z=d/d0„Z>d1d2„Z?d3d4„Z@d5d6„ZAd7d8„ZBd9d:„ZCd;d<„ZDdNd=d>„ZEd?d@„ZFdAdB„ZGdCdD„ZHdEdF„ZIdGdH„ZJdIdJ„ZKeKƒZLdS)OaÏ Code for decoding protocol buffer primitives. This code is very similar to encoder.py -- read the docs for that module first. A "decoder" is a function with the signature: Decode(buffer, pos, end, message, field_dict) The arguments are: buffer: The string containing the encoded message. pos: The current position in the string. end: The position in the string where the current message ends. May be less than len(buffer) if we're reading a sub-message. message: The message object into which we're parsing. field_dict: message._fields (avoids a hashtable lookup). The decoder reads the field and stores it into field_dict, returning the new buffer position. A decoder for a repeated field may proactively decode all of the elements of that field, if they appear consecutively. Note that decoders may throw any of the following: IndexError: Indicates a truncated message. struct.error: Unpacking of a fixed-width field failed. message.DecodeError: Other errors. Decoders are expected to raise an exception if they are called with pos > end. This allows callers to be lax about bounds checking: it's fineto read past "end" as long as you are sure that someone else will notice and throw an exception later on. Something up the call stack is expected to catch IndexError and struct.error and convert them to message.DecodeError. Decoders are constructed using decoder constructors with the signature: MakeDecoder(field_number, is_repeated, is_packed, key, new_default) The arguments are: field_number: The field number of the field we want to decode. is_repeated: Is the field a repeated field? (bool) is_packed: Is the field a packed field? (bool) key: The key to use when looking up the field within field_dict. (This is actually the FieldDescriptor but nothing in this file should depend on that.) new_default: A function which takes a message object as a parameter and returns a new instance of the default value for this field. (This is called for repeated fields and sub-messages, when an instance does not already exist.) As with encoders, we define a decoder constructor for every type of field. Then, for every field of every message class we construct an actual decoder. That decoder goes into a dict indexed by tag, so when we decode a message we repeatedly read a tag, look up the corresponding decoder, and invoke it. z kenton@google.com (Kenton Varda)éNiÿÿz[\ud800-\udfff])Ú containers)Úencoder)Ú wire_format)Úmessagegðcs‡‡fdd„}|S)a¢Return an encoder for a basic varint value (does not include tag). Decoded values will be bitwise-anded with the given mask before being returned, e.g. to limit them to 32 bits. The returned decoder does not take the usual "end" parameter -- the caller is expected to do bounds checking after the fact (often the caller can defer such checking until later). The decoder returns a (value, new_pos) pair. csjd}d}t ||¡}||d@|>O}|d7}|d@sL|ˆM}ˆ|ƒ}||fS|d7}|dkrtdƒ‚qdS©Nrééé€éé@z$Too many bytes when decoding varint.©ÚsixÚ indexbytesÚ _DecodeError©ÚbufferÚposÚresultÚshiftÚb©ÚmaskÚ result_type©úx/private/var/folders/n9/53xbvtmd7sjg1q1l55xmpg58n4mgng/T/pip-unpacked-wheel-3cr5c46n/google/protobuf/internal/decoder.pyÚ DecodeVarintzs z$_VarintDecoder..DecodeVarintr)rrrrrrÚ_VarintDecoderps rcs,d|d>‰d|>d‰‡‡‡fdd„}|S)z0Like _VarintDecoder() but decodes signed values.rcsvd}d}t ||¡}||d@|>O}|d7}|d@sX|ˆM}|ˆAˆ}ˆ|ƒ}||fS|d7}|dkrtdƒ‚qdSrr r©rrZsignbitrrr‘s  z*_SignedVarintDecoder..DecodeVarintr)ÚbitsrrrrrÚ_SignedVarintDecoder‹s  rlÿÿÿÿr lÿÿé cCs>|}t ||¡d@r|d7}q|d7}|||… ¡}||fS)ažRead a tag from the memoryview, and return a (tag_bytes, new_pos) tuple. We return the raw bytes of the tag rather than decoding them. The raw bytes can then be used to look up the proper decoder. This effectively allows us to trade some work that would be done in pure-python (decoding a varint) for work that is done in C (searching for a byte string in a hash table). In a low-level language it would be much cheaper to decode the varint and use that, but not in Python. Args: buffer: memoryview object of the encoded bytes pos: int of the current position to start from Returns: Tuple[bytes, int] of the tag data and new position. r r)r rÚtobytes)rrÚstartÚ tag_bytesrrrÚReadTag®s  r$csd‡‡fdd„ }|S)zØReturn a constructor for a decoder for fields of a particular type. Args: wire_type: The field's wire type. decode_value: A function which decodes an individual value, e.g. _DecodeVarint() Fc sf|rt‰‡‡‡‡fdd„}|S|rNt |ˆ¡‰tˆƒ‰‡‡‡‡‡fdd„}|S‡‡‡fdd„}|SdS)Ncs„| ˆ¡}|dkr"| ˆˆ|ƒ¡}ˆ||ƒ\}}||7}||krHtdƒ‚||krjˆ||ƒ\}}| |¡qH||kr€|d=tdƒ‚|S)NúTruncated message.éÿÿÿÿúPacked element was truncated.©ÚgetÚ setdefaultrÚappend)rrÚendrÚ field_dictÚvalueÚendpointÚelement)Ú decode_valueÚkeyÚlocal_DecodeVarintÚ new_defaultrrÚDecodePackedFieldØs  zB_SimpleDecoder..SpecificDecoder..DecodePackedFieldcst| ˆ¡}|dkr"| ˆˆ|ƒ¡}ˆ||ƒ\}}| |¡|ˆ}|||…ˆksZ||kr"||krjtdƒ‚|Sq"dS©Nr%)r)r*r+r©rrr,rr-r.r0Únew_pos)r1r2r4r#Útag_lenrrÚDecodeRepeatedFieldës  zD_SimpleDecoder..SpecificDecoder..DecodeRepeatedFieldcs@ˆ||ƒ\}}||krtdƒ‚ˆr4|s4| ˆd¡n||ˆ<|Sr6©rÚpop)rrr,rr-Ú new_value)Úclear_if_defaultr1r2rrÚ DecodeFieldüsz<_SimpleDecoder..SpecificDecoder..DecodeField)Ú _DecodeVarintrÚTagBytesÚlen© Ú field_numberÚ is_repeatedÚ is_packedr2r4r>r5r:r?©r1Ú wire_type©r>r2r3r4r#r9rÚSpecificDecoderÔs  z'_SimpleDecoder..SpecificDecoder)Fr)rHr1rJrrGrÚ_SimpleDecoderËs ÿ3rKcs‡‡fdd„}t||ƒS)z†Like SimpleDecoder but additionally invokes modify_value on every value before storing it. Usually modify_value is ZigZagDecode. csˆ||ƒ\}}ˆ|ƒ|fS)Nr)rrrr8©r1Ú modify_valuerrÚ InnerDecodesz%_ModifiedDecoder..InnerDecode)rK)rHr1rMrNrrLrÚ_ModifiedDecoder srOcs*t ˆ¡‰tj‰‡‡‡fdd„}t||ƒS)z­Return a constructor for a decoder for a fixed-width field. Args: wire_type: The field's wire type. format: The format string to pass to struct.unpack(). cs&|ˆ}ˆˆ|||…ƒd}||fS)Nrr)rrr8r©ÚformatÚ local_unpackZ value_sizerrrN*sz'_StructPackDecoder..InnerDecode)ÚstructÚcalcsizeÚunpackrK)rHrQrNrrPrÚ_StructPackDecoders  rVcstj‰‡fdd„}ttj|ƒS)z‡Returns a decoder for a float field. This code works around a bug in struct.unpack for non-finite 32-bit floating-point values. cs†|d}|||… ¡}|dd…dkrp|dd…dkrp|dd…dkrPt|fS|dd…dkrht|fSt|fSˆd |ƒd}||fS) a#Decode serialized float to a float and new position. Args: buffer: memoryview of the serialized bytes pos: int, position in the memory view to start at. Returns: Tuple[float, int] of the deserialized float value and new position in the serialized data. ééóÿéó€rs€óÿz.InnerDecode)rSrUrKrÚWIRETYPE_FIXED32©rNrr`rÚ _FloatDecoder1s !rccstj‰‡fdd„}ttj|ƒS)zkReturns a decoder for a double field. This code works around a bug in struct.unpack for not-a-number. csf|d}|||… ¡}|dd…dkrP|dd…dkrP|dd…dkrPt|fSˆd|ƒd}||fS) a"Decode serialized double to a double and new position. Args: buffer: memoryview of the serialized bytes. pos: int, position in the memory view to start at. Returns: Tuple[float, int] of the decoded double value and new position in the serialized data. ér rYéóðrsðz.InnerDecode)rSrUrKrÚWIRETYPE_FIXED64rbrr`rÚ_DoubleDecoder^s rhFc stˆj‰|r&t‰‡‡‡‡‡fdd„}|S|rZt ˆtj¡‰tˆƒ‰‡‡‡‡‡‡fdd„}|S‡‡‡‡fdd„}|SdS)z!Returns a decoder for enum field.c s| ˆ¡}|dkr"| ˆˆ|ƒ¡}ˆ||ƒ\}}||7}||krHtdƒ‚||krÖ|}t||ƒ\}}|ˆjkrx| |¡qH|js„g|_t ˆt j ¡} |j | |||…  ¡f¡|j dkrÂt  ¡|_ |j  ˆt j |¡qH||k�r |ˆjkrò|d=n|jd=|j jd=tdƒ‚|S)a±Decode serialized packed enum to its value and a new position. Args: buffer: memoryview of the serialized bytes. pos: int, position in the memory view to start at. end: int, end position of serialized data message: Message object to store unknown fields in field_dict: Map[Descriptor, Any] to store decoded values in. Returns: int, new position in serialized data. Nr%r&r')r)r*rÚ_DecodeSignedVarint32Úvalues_by_numberr+Ú_unknown_fieldsrrArÚWIRETYPE_VARINTr!Ú_unknown_field_setrÚUnknownFieldSetÚ_addZ_values) rrr,rr-r.r/Úvalue_start_posr0r#)Ú enum_typerDr2r3r4rrr5ŒsD   ÿÿ  ÿ   z&EnumDecoder..DecodePackedFieldcsÎ| ˆ¡}|dkr"| ˆˆ|ƒ¡}t||ƒ\}}|ˆjkrF| |¡nN|jsRg|_|j ˆ|||… ¡f¡|jdkr‚t  ¡|_|j  ˆt j |¡|ˆ}|||…ˆks´||kr"||krÄt dƒ‚|Sq"dS)á³Decode serialized repeated enum to its value and a new position. Args: buffer: memoryview of the serialized bytes. pos: int, position in the memory view to start at. end: int, end position of serialized data message: Message object to store unknown fields in field_dict: Map[Descriptor, Any] to store decoded values in. Returns: int, new position in serialized data. Nr%)r)r*rirjr+rkr!rmrrnrorrlrr7)rqrDr2r4r#r9rrr:Ás.   ÿ  ÿz(EnumDecoder..DecodeRepeatedFieldcs®|}t||ƒ\}}||kr"tdƒ‚ˆr:|s:| ˆd¡|S|ˆjkrN||ˆ<n\|jsZg|_t ˆtj¡}|j  ||||…  ¡f¡|j dkr˜t   ¡|_ |j  ˆtj|¡|S)rrr%N)rirr<rjrkrrArrlr+r!rmrrnro)rrr,rr-rpZ enum_valuer#)r>rqrDr2rrr?ês2    ÿÿ  ÿz EnumDecoder..DecodeFieldN)rqr@rrArrlrBrCr)r>rqrDr2r3r4r#r9rÚ EnumDecoder†s1'$rsú._ConvertToUnicodecsˆ| ˆ¡}|dkr"| ˆˆ|ƒ¡}ˆ||ƒ\}}||}||krHtdƒ‚| ˆ|||…ƒ¡|ˆ}|||…ˆks~||kr"|Sq"dS©NzTruncated string.r(©rrr,rr-r.Úsizer8)rƒr2r3r4r#r9rrr:Rs z*StringDecoder..DecodeRepeatedFieldcsTˆ||ƒ\}}||}||kr&tdƒ‚ˆr<|s<| ˆd¡nˆ|||…ƒ|ˆ<|Sr„r;©rrr,rr-r†r8)rƒr>r2r3rrr?csz"StringDecoder..DecodeFieldN) r@r Ú text_typeÚAssertionErrorrrArÚWIRETYPE_LENGTH_DELIMITEDrB) rDrErFr2r4r�r>r:r?r) rƒr>r�r2r3r‚r4r#r9rÚ StringDecoder1sÿ r‹csVt‰|r t‚|r>t |tj¡‰tˆƒ‰‡‡‡‡‡fdd„}|S‡‡‡fdd„}|SdS)z$Returns a decoder for a bytes field.csˆ| ˆ¡}|dkr"| ˆˆ|ƒ¡}ˆ||ƒ\}}||}||krHtdƒ‚| |||… ¡¡|ˆ}|||…ˆks~||kr"|Sq"dSr„)r)r*rr+r!r…©r2r3r4r#r9rrr:{s z)BytesDecoder..DecodeRepeatedFieldcsTˆ||ƒ\}}||}||kr&tdƒ‚ˆr<|s<| ˆd¡n|||… ¡|ˆ<|Sr„)rr<r!r‡)r>r2r3rrr?Œsz!BytesDecoder..DecodeFieldN©r@r‰rrArrŠrB)rDrErFr2r4r>r:r?rrIrÚ BytesDecoderpsÿ rŽcslt |tj¡‰tˆƒ‰|rt‚|rRt |tj¡‰tˆƒ‰‡‡‡‡‡‡fdd„}|S‡‡‡‡fdd„}|SdS)z$Returns a decoder for a group field.cs¨| ˆ¡}|dkr"| ˆˆ|ƒ¡}| ˆ¡}|dkrD| ˆˆ|ƒ¡}| ¡ |||¡}|ˆ}|||…ˆksv||kr~tdƒ‚|ˆ}|||…ˆksž||kr"|Sq"dS©NúMissing group end tag.)r)r*ÚaddÚ_InternalParser©rrr,rr-r.r8©Ú end_tag_bytesÚ end_tag_lenr2r4r#r9rrr:¥s  z)GroupDecoder..DecodeRepeatedFieldcs\| ˆ¡}|dkr"| ˆˆ|ƒ¡}| |||¡}|ˆ}|||…ˆksP||krXtdƒ‚|Sr�)r)r*r’rr“)r•r–r2r4rrr?ºs z!GroupDecoder..DecodeFieldN)rrArÚWIRETYPE_END_GROUPrBr‰ÚWIRETYPE_START_GROUP©rDrErFr2r4r:r?rr”rÚ GroupDecoder™sÿÿ ršcsVt‰|r t‚|r>t |tj¡‰tˆƒ‰‡‡‡‡‡fdd„}|S‡‡‡fdd„}|SdS)z&Returns a decoder for a message field.cs�| ˆ¡}|dkr"| ˆˆ|ƒ¡}ˆ||ƒ\}}||}||krHtdƒ‚| ¡ |||¡|krftdƒ‚|ˆ}|||…ˆks†||kr"|Sq"dS©Nr%úUnexpected end-group tag.)r)r*rr‘r’r…rŒrrr:Òs z+MessageDecoder..DecodeRepeatedFieldcsf| ˆ¡}|dkr"| ˆˆ|ƒ¡}ˆ||ƒ\}}||}||krHtdƒ‚| |||¡|krbtdƒ‚|Sr›)r)r*rr’r…)r2r3r4rrr?ès z#MessageDecoder..DecodeFieldNr�r™rrŒrÚMessageDecoderÈsÿr�rcsNt dtj¡‰t dtj¡‰t dtj¡‰t‰t‰t}‡‡‡‡‡fdd„}|S)aReturns a decoder for a MessageSet item. The parameter is the message Descriptor. The message set message looks like this: message MessageSet { repeated group Item = 1 { required int32 type_id = 2; required string message = 3; } } rZrXrcsŒ|}d}d}d}ˆ||ƒ\} }| ˆkr6ˆ||ƒ\}}q| ˆkrZˆ||ƒ\} }|| }}q| ˆkrfq†qt|||| ƒ}|dkrtdƒ‚q||kr–tdƒ‚|dkr¦tdƒ‚|dkr¶tdƒ‚|j |¡} | dk �r*| | ¡} | dk�r | j} t| dƒsü|j | ¡|  | |   ¡¡} |   |||¡|k�rˆtdƒ‚n^|j �s8g|_ |j   t|||… ¡f¡|jdk�rjt ¡|_|j |tj|||… ¡¡|S) a�Decode serialized message set to its value and new position. Args: buffer: memoryview of the serialized bytes. pos: int, position in the memory view to start at. end: int, end position of serialized data message: Message object to store unknown fields in field_dict: Map[Descriptor, Any] to store decoded values in. Returns: int, new position in serialized data. r&r�r%z MessageSet item missing type_id.z MessageSet item missing message.NÚ_concrete_classrœ)Ú SkipFieldrZ ExtensionsZ_FindExtensionByNumberr)Ú message_typeÚhasattrZ_FACTORYZ GetPrototyper*ržr’rkr+ÚMESSAGE_SET_ITEM_TAGr!rmrrnrorrŠ)rrr,rr-Zmessage_set_item_startZtype_idÚ message_startZ message_endr#r†Ú extensionr.r ©Zitem_end_tag_bytesr3Z local_ReadTagZmessage_tag_bytesZtype_id_tag_bytesrrÚ DecodeItems^        ÿ ÿ  ýz)MessageSetItemDecoder..DecodeItem) rrArrlrŠr—r$r@rŸ)Z descriptorZlocal_SkipFieldr¦rr¥rÚMessageSetItemDecoderþsHr§csB|‰t |jtj¡‰tˆƒ‰t‰|j‰‡‡‡‡‡‡‡fdd„}|S)z"Returns a decoder for a map field.c sÀˆ ¡}| ˆ¡}|dkr*| ˆˆ|ƒ¡}ˆ||ƒ\}}||}||krPtdƒ‚| ¡| |||¡|krrtdƒ‚ˆrŠ||j |j¡n |j||j<|ˆ}|||…ˆks¶||kr*|Sq*dSr›) ržr)r*rZClearr’r2ZCopyFromr.) rrr,rr-Zsubmsgr.r†r8©Úis_message_mapr2r3r r4r#r9rrÚ DecodeMapks"  zMapDecoder..DecodeMap)rrAÚnumberrrŠrBr@r )Zfield_descriptorr4r©rªrr¨rÚ MapDecoder`sÿr¬cCsBt|||d… ¡ƒd@r&|d7}q|d7}||kr>tdƒ‚|S)z/Skip a varint value. Returns the new position.rr r%)Úordr!r©rrr,rrrÚ _SkipVarintŽs  r¯cCs|d7}||krtdƒ‚|S)z0Skip a fixed64 value. Returns the new position.rdr%©rr®rrrÚ _SkipFixed64šsr±cCs$|d}t d|||…¡d|fS)zDecode a fixed64.rdrur©rSrU©rrr8rrrÚ_DecodeFixed64£sr´cCs*t||ƒ\}}||7}||kr&tdƒ‚|S)z9Skip a length-delimited value. Returns the new position.r%)r@r)rrr,r†rrrÚ_SkipLengthDelimited©s rµcCs2t||ƒ\}}t||||ƒ}|dkr(|S|}qdS)z*Skip sub-group. Returns the new position.r&N)r$rŸ)rrr,r#r8rrrÚ _SkipGroup³s r¶c Csvt ¡}|dks||krnt||ƒ\}}t|dƒ\}}t |¡\}}|tjkrNqnt|||ƒ\} }| ||| ¡q||fS)zFDecode UnknownFieldSet. Returns the UnknownFieldSet and new position.Nr) rrnr$r@rZ UnpackTagr—Ú_DecodeUnknownFieldro) rrZend_posZunknown_field_setr#ÚtagÚ_rDrHÚdatarrrÚ_DecodeUnknownFieldSet¾s r»cCs¼|tjkrt||ƒ\}}nš|tjkr4t||ƒ\}}n€|tjkrNt||ƒ\}}nf|tjkr„t||ƒ\}}||||… ¡}||7}n0|tj kržt ||ƒ\}}n|tj kr¬dSt dƒ‚||fS)zCDecode a unknown field. Returns the UnknownField and new position.)rr&zWrong wire type in tag.) rrlr@rgr´raÚ_DecodeFixed32rŠr!r˜r»r—r)rrrHrºr†rrrr·Ïs        r·cCsdS)zFSkipping an END_GROUP tag returns -1 to tell the parent loop to break.r&rr®rrrÚ _EndGroupæsr½cCs|d7}||krtdƒ‚|S)z0Skip a fixed32 value. Returns the new position.rWr%r°r®rrrÚ _SkipFixed32ìsr¾cCs$|d}t d|||…¡d|fS)zDecode a fixed32.rWrtrr²r³rrrr¼õsr¼cCs tdƒ‚dS)z;Skip function for unknown wire types. Raises an exception.zTag had invalid wire type.Nr°r®rrrÚ_RaiseInvalidWireTypeüsr¿cs,ttttttttg‰tj‰‡‡fdd„}|S)z"Constructs the SkipField function.cs$t|dd…ƒˆ@}ˆ||||ƒS)aSkips a field with the specified tag. |pos| should point to the byte immediately after the tag. Returns: The new position (after the tag value), or -1 if the tag is an end-group tag (in which case the calling loop should break). rr)r­)rrr,r#rH©ZWIRETYPE_TO_SKIPPERZ wiretype_maskrrrŸs z _FieldSkipper..SkipField) r¯r±rµr¶r½r¾r¿rZ TAG_TYPE_MASK)rŸrrÀrÚ _FieldSkippersø rÁ)F)FF)F)N)MÚ__doc__Ú __author__rSryr r{ÚPY3ÚintÚlongÚreÚcompileÚur|Zgoogle.protobuf.internalrrrZgoogle.protobufrr_r^r]r~rrrr@Z_DecodeSignedVarintZ_DecodeVarint32rir$rKrOrVrcrhrsrlZ Int32DecoderZ Int64DecoderZ UInt32DecoderZ UInt64DecoderZ ZigZagDecodeZ SInt32DecoderZ SInt64DecoderraZFixed32DecoderrgZFixed64DecoderZSFixed32DecoderZSFixed64DecoderZ FloatDecoderZ DoubleDecoderÚboolZ BoolDecoderr‹rŽršr�rAr˜r¢r§r¬r¯r±r´rµr¶r»r·r½r¾r¼r¿rÁrŸrrrrÚs¬2        ?-)ÿ ÿÿ  ÿÿ    ÿÿ @ÿ )/4b.