B s `—ã@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. csnd}d}x`t ||¡}||d@|>O}|d7}|d@sN|ˆM}ˆ|ƒ}||fS|d7}|dkr tdƒ‚q WdS)Nrééé€éé@z$Too many bytes when decoding varint.)ÚsixÚ indexbytesÚ _DecodeError)ÚbufferÚposÚresultÚshiftÚb)ÚmaskÚ result_type©úD/tmp/pip-unpacked-wheel-u0__x60w/google/protobuf/internal/decoder.pyÚ DecodeVarintzs z$_VarintDecoder..DecodeVarintr)rrrr)rrrÚ_VarintDecoderps rcs,d|d>‰d|>d‰‡‡‡fdd„}|S)z0Like _VarintDecoder() but decodes signed values.rcszd}d}xlt ||¡}||d@|>O}|d7}|d@sZ|ˆM}|ˆAˆ}ˆ|ƒ}||fS|d7}|dkr tdƒ‚q WdS)Nrrrrr r z$Too many bytes when decoding varint.)r r r )rrrrr)rrÚsignbitrrr‘s  z*_SignedVarintDecoder..DecodeVarintr)Úbitsrrr)rrrrÚ_SignedVarintDecoder‹s  rlÿÿÿÿr lÿÿé cCsB|}xt ||¡d@r |d7}qW|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. rr)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ƒ‚x$||krlˆ||ƒ\}}| |¡qJW||kr„|d=tdƒ‚|S)NzTruncated message.éÿÿÿÿzPacked 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..DecodePackedFieldcsx| ˆ¡}|dkr"| ˆˆ|ƒ¡}xPˆ||ƒ\}}| |¡|ˆ}|||…ˆks\||kr$||krltdƒ‚|Sq$WdS)NzTruncated message.)r"r#r$r )rrr%rr&r'r)Únew_pos)r*r+r-rÚtag_lenrrÚDecodeRepeatedFieldës  zD_SimpleDecoder..SpecificDecoder..DecodeRepeatedFieldcs@ˆ||ƒ\}}||krtdƒ‚ˆr4|s4| ˆd¡n||ˆ<|S)NzTruncated message.)r Úpop)rrr%rr&Ú new_value)Úclear_if_defaultr*r+rrÚ DecodeFieldüsz<_SimpleDecoder..SpecificDecoder..DecodeField)Ú _DecodeVarintrÚTagBytesÚlen) Ú field_numberÚ is_repeatedÚ is_packedr+r-r4r.r1r5)r*Ú wire_type)r4r+r,r-rr0rÚSpecificDecoderÔs  z'_SimpleDecoder..SpecificDecoder)Fr)r<r*r=r)r*r<rÚ_SimpleDecoderËs 2r>cs‡‡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)rrrr/)r*Ú modify_valuerrÚ InnerDecodesz%_ModifiedDecoder..InnerDecode)r>)r<r*r?r@r)r*r?rÚ_ModifiedDecoder srAcs*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)rrr/r)ÚformatÚ local_unpackÚ value_sizerrr@*sz'_StructPackDecoder..InnerDecode)ÚstructÚcalcsizeÚunpackr>)r<rBr@r)rBrCrDrÚ_StructPackDecoders  rHcstj‰‡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. éésÿéó€rs€óÿz.InnerDecode)rErGr>rÚWIRETYPE_FIXED32)r@r)rCrÚ _FloatDecoder1s !rRcstj‰‡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 sÿéóðrsðz.InnerDecode)rErGr>rÚWIRETYPE_FIXED64)r@r)rCrÚ_DoubleDecoder^s rWFc 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ƒ‚x�||krØ|}t||ƒ\}}|ˆjkrz| |¡qJ|js†g|_t ˆt j ¡} |j | |||…  ¡f¡|j dkrÄt  ¡|_ |j  ˆt j |¡qJW||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. NzTruncated message.r!zPacked element was truncated.)r"r#r Ú_DecodeSignedVarint32Úvalues_by_numberr$Ú_unknown_fieldsrr7rÚWIRETYPE_VARINTrÚ_unknown_field_setrÚUnknownFieldSetÚ_addZ_values) rrr%rr&r'r(Úvalue_start_posr)r)Ú enum_typer9r+r,r-rrr.Œs:         z&EnumDecoder..DecodePackedFieldcsÒ| ˆ¡}|dkr"| ˆˆ|ƒ¡}xªt||ƒ\}}|ˆjkrH| |¡nN|jsTg|_|j ˆ|||… ¡f¡|jdkr„t  ¡|_|j  ˆt j |¡|ˆ}|||…ˆks¶||kr$||krÆt dƒ‚|Sq$WdS)a³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. NzTruncated message.)r"r#rXrYr$rZrr\rr]r^rr[r )rrr%rr&r'r)r/)r`r9r+r-rr0rrr1Ás(      z(EnumDecoder..DecodeRepeatedFieldcs®|}t||ƒ\}}||kr"tdƒ‚ˆr:|s:| ˆd¡|S|ˆjkrN||ˆ<n\|jsZg|_t ˆtj¡}|j  ||||…  ¡f¡|j dkr˜t   ¡|_ |j  ˆtj|¡|S)a³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. zTruncated message.N)rXr r2rYrZrr7rr[r$rr\rr]r^)rrr%rr&r_Z enum_valuer)r4r`r9r+rrr5ês(       z EnumDecoder..DecodeFieldN)r`r6rr7rr[r8) r9r:r;r+r-r4r.r1r5r)r4r`r9r+r,r-rr0rÚ EnumDecoder†s1'$raz._ConvertToUnicodecsŒ| ˆ¡}|dkr"| ˆˆ|ƒ¡}xdˆ||ƒ\}}||}||krJtdƒ‚| ˆ|||…ƒ¡|ˆ}|||…ˆks€||kr$|Sq$WdS)NzTruncated string.)r"r#r r$)rrr%rr&r'Úsizer/)ror+r,r-rr0rrr1Rs z*StringDecoder..DecodeRepeatedFieldcsTˆ||ƒ\}}||}||kr&tdƒ‚ˆr<|s<| ˆd¡nˆ|||…ƒ|ˆ<|S)NzTruncated string.)r r2)rrr%rr&rpr/)ror4r+r,rrr5csz"StringDecoder..DecodeFieldN) r6r Ú text_typeÚAssertionErrorrr7rÚWIRETYPE_LENGTH_DELIMITEDr8) r9r:r;r+r-rmr4r1r5r) ror4rmr+r,rnr-rr0rÚ StringDecoder1s rtcsVt‰|r t‚|r>t |tj¡‰tˆƒ‰‡‡‡‡‡fdd„}|S‡‡‡fdd„}|SdS)z$Returns a decoder for a bytes field.csŒ| ˆ¡}|dkr"| ˆˆ|ƒ¡}xdˆ||ƒ\}}||}||krJtdƒ‚| |||… ¡¡|ˆ}|||…ˆks€||kr$|Sq$WdS)NzTruncated string.)r"r#r r$r)rrr%rr&r'rpr/)r+r,r-rr0rrr1{s z)BytesDecoder..DecodeRepeatedFieldcsTˆ||ƒ\}}||}||kr&tdƒ‚ˆr<|s<| ˆd¡n|||… ¡|ˆ<|S)NzTruncated string.)r r2r)rrr%rr&rpr/)r4r+r,rrr5Œsz!BytesDecoder..DecodeFieldN)r6rrrr7rrsr8)r9r:r;r+r-r4r1r5r)r4r+r,r-rr0rÚ BytesDecoderps rucslt |tj¡‰tˆƒ‰|rt‚|rRt |tj¡‰tˆƒ‰‡‡‡‡‡‡fdd„}|S‡‡‡‡fdd„}|SdS)z$Returns a decoder for a group field.cs¬| ˆ¡}|dkr"| ˆˆ|ƒ¡}x„| ˆ¡}|dkrF| ˆˆ|ƒ¡}| ¡ |||¡}|ˆ}|||…ˆksx||kr€tdƒ‚|ˆ}|||…ˆks ||kr$|Sq$WdS)NzMissing group end tag.)r"r#ÚaddÚ_InternalParser )rrr%rr&r'r/)Ú end_tag_bytesÚ end_tag_lenr+r-rr0rrr1¥s  z)GroupDecoder..DecodeRepeatedFieldcs\| ˆ¡}|dkr"| ˆˆ|ƒ¡}| |||¡}|ˆ}|||…ˆksP||krXtdƒ‚|S)NzMissing group end tag.)r"r#rwr )rrr%rr&r'r/)rxryr+r-rrr5ºs z!GroupDecoder..DecodeFieldN)rr7rÚWIRETYPE_END_GROUPr8rrÚWIRETYPE_START_GROUP)r9r:r;r+r-r1r5r)rxryr+r-rr0rÚ GroupDecoder™s r|csVt‰|r t‚|r>t |tj¡‰tˆƒ‰‡‡‡‡‡fdd„}|S‡‡‡fdd„}|SdS)z&Returns a decoder for a message field.cs”| ˆ¡}|dkr"| ˆˆ|ƒ¡}xlˆ||ƒ\}}||}||krJtdƒ‚| ¡ |||¡|krhtdƒ‚|ˆ}|||…ˆksˆ||kr$|Sq$WdS)NzTruncated message.zUnexpected end-group tag.)r"r#r rvrw)rrr%rr&r'rpr/)r+r,r-rr0rrr1Òs z+MessageDecoder..DecodeRepeatedFieldcsf| ˆ¡}|dkr"| ˆˆ|ƒ¡}ˆ||ƒ\}}||}||krHtdƒ‚| |||¡|krbtdƒ‚|S)NzTruncated message.zUnexpected end-group tag.)r"r#r rw)rrr%rr&r'rpr/)r+r,r-rrr5ès z#MessageDecoder..DecodeFieldN)r6rrrr7rrsr8)r9r:r;r+r-r1r5r)r+r,r-rr0rÚMessageDecoderÈsr}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; } } rKrJrcs’|}d}d}d}xxˆ||ƒ\} }| ˆkr8ˆ||ƒ\}}q| ˆkr\ˆ||ƒ\} }|| }}q| ˆkrhPqt|||| ƒ}|dkrtdƒ‚qW||krštdƒ‚|dkrªtdƒ‚|dkrºtdƒ‚|j |¡} | dk �r0| | ¡} | dk�r| j} t| dƒ�s|j | ¡|  | |   ¡¡} |   |||¡|k�rŽtdƒ‚n^|j �s>g|_ |j   t|||… ¡f¡|jdk�rpt ¡|_|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!zMissing group end tag.zTruncated message.z MessageSet item missing type_id.z MessageSet item missing message.NÚ_concrete_classzUnexpected end-group tag.)Ú SkipFieldr Z ExtensionsZ_FindExtensionByNumberr"Ú message_typeÚhasattrZ_FACTORYZ GetPrototyper#r~rwrZr$ÚMESSAGE_SET_ITEM_TAGrr\rr]r^rrs)rrr%rr&Zmessage_set_item_startZtype_idÚ message_startZ message_endrrpÚ extensionr'r€)Úitem_end_tag_bytesr,Ú local_ReadTagÚmessage_tag_bytesÚtype_id_tag_bytesrrÚ DecodeItemsX            z)MessageSetItemDecoder..DecodeItem) rr7rr[rsrzr r6r)Z descriptorZlocal_SkipFieldr‰r)r…r,r†r‡rˆrÚMessageSetItemDecoderþsHrŠcsB|‰t |jtj¡‰tˆƒ‰t‰|j‰‡‡‡‡‡‡‡fdd„}|S)z"Returns a decoder for a map field.c sĈ ¡}| ˆ¡}|dkr*| ˆˆ|ƒ¡}x”ˆ||ƒ\}}||}||krRtdƒ‚| ¡| |||¡|krttdƒ‚ˆrŒ||j |j¡n |j||j<|ˆ}|||…ˆks¸||kr,|Sq,WdS)NzTruncated message.zUnexpected end-group tag.) r~r"r#r ZClearrwr+ZCopyFromr') rrr%rr&Zsubmsgr'rpr/)Úis_message_mapr+r,r€r-rr0rrÚ DecodeMapks$  zMapDecoder..DecodeMap)rr7Únumberrrsr8r6r€)Zfield_descriptorr-r‹rŒr)r‹r+r,r€r-rr0rÚ MapDecoder`srŽcCsFx(t|||d… ¡ƒd@r(|d7}qW|d7}||krBtdƒ‚|S)z/Skip a varint value. Returns the new position.rrzTruncated message.)Úordrr )rrr%rrrÚ _SkipVarintŽs  r�cCs|d7}||krtdƒ‚|S)z0Skip a fixed64 value. Returns the new position.rSzTruncated message.)r )rrr%rrrÚ _SkipFixed64šsr‘cCs$|d}t d|||…¡d|fS)zDecode a fixed64.rSz.SkipField) r�r‘r“r”r›rœr�rZ TAG_TYPE_MASK)rr)ržrŸrÚ _FieldSkippersr )F)FF)F)N)MÚ__doc__Ú __author__rErer rgÚPY3ÚintÚlongÚreÚcompileÚurhZgoogle.protobuf.internalrrrZgoogle.protobufrrPrOrNrjr rrr6Z_DecodeSignedVarintZ_DecodeVarint32rXr r>rArHrRrWrar[Z Int32DecoderZ Int64DecoderZ UInt32DecoderZ UInt64DecoderZ ZigZagDecodeZ SInt32DecoderZ SInt64DecoderrQZFixed32DecoderrVZFixed64DecoderZSFixed32DecoderZSFixed64DecoderZ FloatDecoderZ DoubleDecoderÚboolZ BoolDecoderrtrur|r}r7r{r‚rŠrŽr�r‘r’r“r”r™r•r›rœršr�r rrrrrÚOsŠ        ?-)           ? (/4b.