
    9h                     $   S SK r S SKrS SKrS SKrS SKrS SKJr  S SKJrJ	r	J
r
  S SKJrJrJrJrJrJr  S SKJrJrJrJrJrJrJrJrJrJrJr  S SKJr  S SKJ r   S SK!J"r"J#r#J$r$J%r%J&r&J'r'J(r(J)r)J*r*J+r+J,r,J-r-J.r.  S SK/J0s  J1s  J2r2  S S	K3J4r4J5r5J6r6  S S
K7J8r8J9r9  S SK:J;r;  SSK<J=r=J>r>J?r?J@r@  SSKAJBrB  SSKCJDrD  SSKEJFrFJGrGJHrHJIrI  S SKJJKrKJLrL  SSKMJNrNJOrOJPrPJQrQJRrRJSrSJTrT  \R                  S:  a
  S\VS\W4S jrXO	S\VS\Y4S jrX " S S\ R                  5      r[S\4S\\V   4S jr\S\6S\Y4S jr]S\R                  S\Y4S jr_S \YS!\YS\R                  4S" jr` SAS#\FS$\@S%\ S&\\\Y      4S' jjraS%\ 4S( jrb " S) S*\N5      rc " S+ S,\O5      rdS-\PS.\4S/\S0\QS\4
S1 jreS-\PS2\5S3\4S/\9S0\Q4
S4 jrfS2\5S/\9S5\4S6 jrgS2\5S\R4S7 jrhS2\54S8 jriS2\5S\\Y   4S9 jrjS:\\Y   S;\\Y   S\k4S< jrlS \YS\k4S= jrmS5\	S>\VS\BR                  4S? jrn\" 5       roS5\BR                  S\	4S@ jrpg)B    N)deque)ContextDecimalMAX_PREC)SetListUnionOptionalAnyTuple)descriptor_pb2any_pb2api_pb2	empty_pb2duration_pb2field_mask_pb2source_context_pb2
struct_pb2timestamp_pb2type_pb2wrappers_pb2)json_format)DescriptorPool)calendar_period_pb2	color_pb2date_pb2datetime_pb2dayofweek_pb2expr_pb2fraction_pb2
latlng_pb2	money_pb2	month_pb2postal_address_pb2timeofday_pb2quaternion_pb2)
DescriptorFieldDescriptorFileDescriptor)DecodeErrorMessage)GetMessageClass   )_MAGIC_BYTEreference_subject_name_strategytopic_subject_name_strategySchemaRegistryClient)decimal_pb2)RuleRegistry)SchemaSchemaReferenceRuleKindRuleMode)SerializationErrorSerializationContext)BaseSerializerBaseDeserializerRuleContextFieldTransform	FieldTypeRuleConditionErrorParsedSchemaCache3vreturnc                     [        U 45      $ zG
Convert int to bytes

Args:
    v (int): The int to convert to bytes.
)bytesrB   s    mC:\Suresh\moveshuttle\MDcreated\moveengine\venv\Lib\site-packages\confluent_kafka/schema_registry/protobuf.py_bytesrI   =   s     aT{    c                     [        U 5      $ rE   )chrrG   s    rH   rI   rI   F   s     1vrJ   c                   $    \ rS rSrSrS rS rSrg)_ContextStringIOP   z9
Wrapper to allow use of StringIO via 'with' constructs.
c                     U $ N )selfs    rH   	__enter___ContextStringIO.__enter__U   s    rJ   c                 $    U R                  5         gNF)close)rS   argss     rH   __exit___ContextStringIO.__exit__X   s    

rJ   rR   N)__name__
__module____qualname____firstlineno____doc__rT   rZ   __static_attributes__rR   rJ   rH   rN   rN   P   s    rJ   rN   msg_descc                    [        5       nU nSnUR                  bg  UnUR                  n[        UR                  5       H  u  pVXd:X  d  M  UR	                  U5        Sn  O   U(       d  [        S5      eUR                  b  Mg  Sn[        U R                  R                  5       H)  u  pWXrR                  :X  d  M  UR	                  U5        Sn  O   U(       d  [        S5      e[        U5      $ )a&  
Creates an index array specifying the location of msg_desc in
the referenced FileDescriptor.

Args:
    msg_desc (MessageDescriptor): Protobuf MessageDescriptor

Returns:
    list of int: Protobuf MessageDescriptor index array.

Raises:
    ValueError: If the message descriptor is malformed.
FTz"Nested MessageDescriptor not foundz#MessageDescriptor not found in file)
r   containing_type	enumeratenested_types
appendleft
ValueErrorfilemessage_types_by_namenamelist)rb   msg_idxcurrentfoundpreviousidxnodemsg_type_names           rH   _create_index_arrayrt   ]   s     gG GE

!
!
-**"7#7#78IC""3'	 9
 ABB 
!
!
- E'(K(KLLL(s#E	 M
 >??=rJ   file_descriptorc                 `    [         R                  " U R                  5      R                  S5      $ )z
Base64 encode a FileDescriptor

Args:
    file_descriptor (FileDescriptor): FileDescriptor to encode.

Returns:
    str: Base64 encoded FileDescriptor
ascii)base64standard_b64encodeserialized_pbdecode)ru   s    rH   _schema_to_strr|      s&     $$_%B%BCJJ7SSrJ   file_descriptor_protoc                 h    [         R                  " U R                  5       5      R                  S5      $ )z
Base64 encode a FileDescriptorProto

Args:
    file_descriptor_proto (FileDescriptorProto): FileDescriptorProto to encode.

Returns:
    str: Base64 encoded FileDescriptorProto
rw   )rx   ry   SerializeToStringr{   )r}   s    rH   _proto_to_strr      s+     $$%:%L%L%NOVVW^__rJ   rk   
schema_strc                     [         R                  " UR                  S5      5      n[        R                  " 5       n UR                  U5        Xl        U$ ! [         a  n[        [        U5      5      eSnAff = f)z
Base64 decode a FileDescriptor

Args:
    schema_str (str): Base64 encoded FileDescriptorProto

Returns:
    FileDescriptorProto: schema.
rw   N)
rx   standard_b64decodeencoder   FileDescriptorProtoParseFromStringrk   r*   r8   str)rk   r   rz   r}   es        rH   _str_to_protor      sp     --j.?.?.HIM*>>@)--m<%)" !   ) Q(()s   A 
A8A33A8schemaschema_registry_clientpoolvisitedc                    Uc
  [        5       nU R                  b  U R                   H  n[        UR                  5      (       d  UR                  U;   a  M/  UR	                  UR                  5        UR                  UR                  UR                  SS5      n[        UR                  XU5        [        UR                  UR                  R                  5      nUR                  U5        M     gg)a  
Resolves named schemas referenced by the provided schema recursively.
:param schema: Schema to resolve named schemas for.
:param schema_registry_client: SchemaRegistryClient to use for retrieval.
:param pool: DescriptorPool to add resolved schemas to.
:return: DescriptorPool
NT
serialized)set
references_is_builtinrk   addget_versionsubjectversion_resolve_named_schemar   r   r   Add)r   r   r   r   refreferenced_schemar}   s          rH   r   r      s     %$$$C388$$G(;KK! 6 B B3;;PSP[P[]aco p!"3":":<RZab$1#((<M<T<T<_<_$`!HH*+ % %rJ   c                 X   U R                  [        R                  R                  5        U R                  [        R                  R                  5        U R                  [
        R                  R                  5        U R                  [        R                  R                  5        U R                  [        R                  R                  5        U R                  [        R                  R                  5        U R                  [        R                  R                  5        U R                  [        R                  R                  5        U R                  [        R                  R                  5        U R                  [        R                  R                  5        U R                  [        R                  R                  5        U R                  [        R                  R                  5        U R                  [        R                  R                  5        U R                  [         R                  R                  5        U R                  ["        R                  R                  5        U R                  [$        R                  R                  5        U R                  [&        R                  R                  5        U R                  [(        R                  R                  5        U R                  [*        R                  R                  5        U R                  [,        R                  R                  5        U R                  [.        R                  R                  5        U R                  [0        R                  R                  5        U R                  [2        R                  R                  5        U R                  [4        R                  R                  5        U R                  [6        R                  R                  5        U R                  [8        R                  R                  5        g rQ   )AddSerializedFiler   
DESCRIPTORrz   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r&   r%   meta_pb2r2   )r   s    rH   
_init_poolr      s   7--;;<-88FFG8..<<=7--;;<>44BBC<22@@A9//==>>44BBC:00>>?=33AAB<22@@A.99GGH9//==>8..<<=<22@@A=33AAB8..<<=<22@@A:00>>?9//==>9//==>-88FFG>44BBC=33AAB8..<<=;11??@rJ   c                   h  ^  \ rS rSrSr/ SQrSSSSSS\\SS.	r   SS\	S	\
S
\\   S\\   S\\   4
U 4S jjjr\SS\R"                  S\S\4S jj5       r\SS\R"                  S\\   S\4S jj5       rS\S\S\\   4S jrSS\	S\\   S\\   4S jjrS\S\\R@                  \!4   4S jr"Sr#U =r$$ ) ProtobufSerializer   a$  
Serializer for Protobuf Message derived classes. Serialization format is Protobuf,
with Confluent Schema Registry framing.

Configuration properties:

+-------------------------------------+----------+------------------------------------------------------+
| Property Name                       | Type     | Description                                          |
+=====================================+==========+======================================================+
|                                     |          | If True, automatically register the configured       |
| ``auto.register.schemas``           | bool     | schema with Confluent Schema Registry if it has      |
|                                     |          | not previously been associated with the relevant     |
|                                     |          | subject (determined via subject.name.strategy).      |
|                                     |          |                                                      |
|                                     |          | Defaults to True.                                    |
|                                     |          |                                                      |
|                                     |          | Raises SchemaRegistryError if the schema was not     |
|                                     |          | registered against the subject, or could not be      |
|                                     |          | successfully registered.                             |
+-------------------------------------+----------+------------------------------------------------------+
|                                     |          | Whether to normalize schemas, which will             |
| ``normalize.schemas``               | bool     | transform schemas to have a consistent format,       |
|                                     |          | including ordering properties and references.        |
+-------------------------------------+----------+------------------------------------------------------+
|                                     |          | Whether to use the given schema ID for               |
| ``use.schema.id``                   | int      | serialization.                                       |
|                                     |          |                                                      |
+-----------------------------------------+----------+--------------------------------------------------+
|                                     |          | Whether to use the latest subject version for        |
| ``use.latest.version``              | bool     | serialization.                                       |
|                                     |          |                                                      |
|                                     |          | WARNING: There is no check that the latest           |
|                                     |          | schema is backwards compatible with the object       |
|                                     |          | being serialized.                                    |
|                                     |          |                                                      |
|                                     |          | Defaults to False.                                   |
+-------------------------------------+----------+------------------------------------------------------+
|                                     |          | Whether to use the latest subject version with       |
| ``use.latest.with.metadata``        | dict     | the given metadata.                                  |
|                                     |          |                                                      |
|                                     |          | WARNING: There is no check that the latest           |
|                                     |          | schema is backwards compatible with the object       |
|                                     |          | being serialized.                                    |
|                                     |          |                                                      |
|                                     |          | Defaults to None.                                    |
+-------------------------------------+----------+------------------------------------------------------+
|                                     |          | Whether or not to skip known types when resolving    |
| ``skip.known.types``                | bool     | schema dependencies.                                 |
|                                     |          |                                                      |
|                                     |          | Defaults to True.                                    |
+-------------------------------------+----------+------------------------------------------------------+
|                                     |          | Callable(SerializationContext, str) -> str           |
|                                     |          |                                                      |
| ``subject.name.strategy``           | callable | Defines how Schema Registry subject names are        |
|                                     |          | constructed. Standard naming strategies are          |
|                                     |          | defined in the confluent_kafka.schema_registry       |
|                                     |          | namespace.                                           |
|                                     |          |                                                      |
|                                     |          | Defaults to topic_subject_name_strategy.             |
+-------------------------------------+----------+------------------------------------------------------+
|                                     |          | Callable(SerializationContext, str) -> str           |
|                                     |          |                                                      |
| ``reference.subject.name.strategy`` | callable | Defines how Schema Registry subject names for schema |
|                                     |          | references are constructed.                          |
|                                     |          |                                                      |
|                                     |          | Defaults to reference_subject_name_strategy          |
+-------------------------------------+----------+------------------------------------------------------+
| ``use.deprecated.format``           | bool     | Specifies whether the Protobuf serializer should     |
|                                     |          | serialize message indexes without zig-zag encoding.  |
|                                     |          | This option must be explicitly configured as older   |
|                                     |          | and newer Protobuf producers are incompatible.       |
|                                     |          | If the consumers of the topic being produced to are  |
|                                     |          | using confluent-kafka-python <1.8 then this property |
|                                     |          | must be set to True until all old consumers have     |
|                                     |          | have been upgraded.                                  |
|                                     |          |                                                      |
|                                     |          | Warning: This configuration property will be removed |
|                                     |          | in a future version of the client.                   |
+-------------------------------------+----------+------------------------------------------------------+

Schemas are registered against subject names in Confluent Schema Registry that
define a scope in which the schemas can be evolved. By default, the subject name
is formed by concatenating the topic name with the message field (key or value)
separated by a hyphen.

i.e. {topic name}-{message field}

Alternative naming strategies may be configured with the property
``subject.name.strategy``.

Supported subject name strategies

+--------------------------------------+------------------------------+
| Subject Name Strategy                | Output Format                |
+======================================+==============================+
| topic_subject_name_strategy(default) | {topic name}-{message field} |
+--------------------------------------+------------------------------+
| topic_record_subject_name_strategy   | {topic name}-{record name}   |
+--------------------------------------+------------------------------+
| record_subject_name_strategy         | {record name}                |
+--------------------------------------+------------------------------+

See `Subject name strategy <https://docs.confluent.io/current/schema-registry/serializer-formatter.html#subject-name-strategy>`_ for additional details.

Args:
    msg_type (Message): Protobuf Message type.

    schema_registry_client (SchemaRegistryClient): Schema Registry
        client instance.

    conf (dict): ProtobufSerializer configuration.

See Also:
    `Protobuf API reference <https://googleapis.dev/python/protobuf/latest/google/protobuf.html>`_
)	_skip_known_types_known_subjects
_msg_class_index_array_schema
_schema_id_ref_reference_subject_func_use_deprecated_format_parsed_schemasTFN)	auto.register.schemasnormalize.schemasuse.schema.iduse.latest.versionuse.latest.with.metadataskip.known.typessubject.name.strategyreference.subject.name.strategyuse.deprecated.formatmsg_typer   conf	rule_confrule_registryc                 l  > [         T	U ]  5         Ub  SU;  a  [        S5      eU R                  R	                  5       nUb  UR                  U5        UR                  S5      U l        [        U R                  [        5      (       d  [        S5      eUR                  S5      U l        [        U R                  [        5      (       d  [        S5      eUR                  S5      U l        U R                  b*  [        U R                  [        5      (       d  [        S5      eUR                  S	5      U l        [        U R                  [        5      (       d  [        S
5      eU R                  (       a  U R                  (       a  [        S5      eUR                  S5      U l        U R                  b*  [        U R                  [         5      (       d  [        S5      eUR                  S5      U l        [        U R"                  [        5      (       d  [        S5      eUR                  S5      U l        [        U R$                  [        5      (       d  [        S5      eU R$                  (       a  [&        R(                  " S5        UR                  S5      U l        [-        U R*                  5      (       d  [        S5      eUR                  S5      U l        [-        U R.                  5      (       d  [        S5      e[1        U5      S:  a7  [        SR3                  SR5                  UR7                  5       5      5      5      eX l        U(       a  UO[:        R<                  " 5       U l        S U l         [C        5       U l"        Xl#        [I        5       U l%        URL                  n[O        U5      U l(        [S        [U        URV                  5      SS9U l,        U R>                  R[                  5        HI  nUR]                  U R8                  (       a  U R8                  R_                  5       O0 U(       a  UO0 5        MK     g )Nr   zProtobufSerializer: the 'use.deprecated.format' configuration property must be explicitly set due to backward incompatibility with older confluent-kafka-python Protobuf producers and consumers. See the release notes for more detailsr   z-auto.register.schemas must be a boolean valuer   z)normalize.schemas must be a boolean valuer   z"use.schema.id must be an int valuer   *use.latest.version must be a boolean valuez?cannot enable both use.latest.version and auto.register.schemasr   -use.latest.with.metadata must be a dict valuer   z(skip.known.types must be a boolean value-use.deprecated.format must be a boolean valuead  ProtobufSerializer: the 'use.deprecated.format' configuration property, and the ability to use the old incorrect Protobuf serializer heading format introduced in confluent-kafka-python v1.4.0, will be removed in an upcoming release in 2021 Q2. Please migrate your Python Protobuf producers and consumers to 'use.deprecated.format':False as soon as possibler   &subject.name.strategy must be callabler   r   zUnrecognized properties: {}z, PROTOBUF)schema_type)0super__init__RuntimeError_default_confcopyupdatepop_auto_register
isinstanceboolrh   _normalize_schemas_use_schema_idint_use_latest_version_use_latest_with_metadatadictr   r   warningswarn_subject_name_funccallabler   lenformatjoinkeys	_registryr3   get_global_instance_rule_registryr   r   r   r   r@   r   r   rt   r   r4   r|   ri   r   get_executors	configureconfig)
rS   r   r   r   r   r   	conf_copy
descriptorrule	__class__s
            rH   r   ProtobufSerializer.__init__z  sL    	<2$>9: : &&++-	T"'mm,CD$--t44LMM"+--0C"D$11488HII'mmO<+t22C88ABB#,==1E#F $22D99IJJ##(;(;^__)27Q)R&**6t==tDDLMM!*/A!B$00$77GHH&/mm4K&L#$55t<<LMM&&MM - . #,--0G"H//00EFF+4==-,/(8899EFFy>A:$fTYYy~~/?%@AC C 0/<m,BbBbBd"u"02((
/
;nZ__=*46 ''557DNNdnn4>>002"(19r; 8rJ   bufvalzigzagc                     U(       a  US-  US-	  -  nUS-  S:w  a0  U R                  [        US-  S-  5      5        US-  nUS-  S:w  a  M0  U R                  [        U5      5        g)	z
Writes val to buf, either using zigzag or uvarint encoding.

Args:
    buf (BytesIO): buffer to write to.
    val (int): integer to be encoded.
    zigzag (bool): whether to encode in zigzag or uvarint encoding
r-   ?   ir            N)writerI   )r   r   r   s      rH   _write_varint ProtobufSerializer._write_varint  sh     !8r	*CU{q IIfcDjD012AIC U{q  			&+rJ   intsc                     [        U5      S:  d   eUS/:X  a  U R                  [        S5      5        g[        R	                  U [        U5      US9  U H  n[        R	                  XUS9  M     g)z
Encodes each int as a uvarint onto buf

Args:
    buf (BytesIO): buffer to write to.
    ints ([int]): ints to be encoded.
    zigzag (bool): whether to encode in zigzag or uvarint encoding
r   Nr   )r   r   rI   r   r   )r   r   r   values       rH   _encode_varints"ProtobufSerializer._encode_varints  sf     4y1}}A3;IIfTl#((c$i(GE,,S,G rJ   ctx	file_descrC   c                    / nUR                    H  nU R                  (       a  [        UR                  5      (       a  M0  U R	                  X5      nU R                  X5      n[        [        U5      USS9nU R                  (       a  U R                  R                  Xg5        U R                  R                  Xg5      nUR                  [        UR                  UUR                  5      5        M     U$ )z
Resolves and optionally registers schema references recursively.

Args:
    ctx (SerializationContext): Serialization context.

    file_desc (FileDescriptor): file descriptor to traverse.
r   )r   r   )dependenciesr   r   rk   _resolve_dependenciesr   r4   r|   r   r   register_schemalookup_schemaappendr5   r   )	rS   r   r   schema_refsdepdep_refsr   r   	references	            rH   r   (ProtobufSerializer._resolve_dependencies  s     ))C%%+chh*?*?11#;H66s@GN3/'/(24F ""..w?44WEIsxx/6/8/@/@ B C *  rJ   messagec           
        ^ Uc  g[        XR                  5      (       d.  [        SR                  U R                  [	        U5      5      5      eU R                  UUR                  R                  5      nU R                  USS9nUb  UR                  U l
        GOX0R                  ;  Ga  U R                  X!R                  R                  5      n[        U R                  R                   U R                  R"                  U5      U l        U R$                  (       a7  U R&                  R)                  UU R                  U R*                  5      U l
        O?U R&                  R-                  X0R                  U R*                  5      R                  U l
        U R                  R/                  U5        Ub  U R1                  UR2                  5      u  pgUR5                  UR6                  5      nUR8                  UR                  R6                     mU4S jn	U R;                  X#[<        R>                  SUR2                  USU	5      n[A        5        n
U
RC                  [D        RF                  " S[H        U R                  5      5        U RK                  XRL                  U RN                  (       + S9  U
RC                  URQ                  5       5        U
RS                  5       sSSS5        $ ! , (       d  f       g= f)a  
Serializes an instance of a class derived from Protobuf Message, and prepends
it with Confluent Schema Registry framing.

Args:
    message (Message): An instance of a class derived from Protobuf Message.

    ctx (SerializationContext): Metadata relevant to the serialization.
        operation.

Raises:
    SerializerError if any error occurs during serialization.

Returns:
    None if messages is None, else a byte array containing the Protobuf
    serialized message with Confluent Schema Registry framing.
Nz!message must be of type {} not {}r   fmtc                    > [        U TX!5      $ rQ   	transform)rule_ctxfield_transformmsgdescs      rH   <lambda>-ProtobufSerializer.__call__.<locals>.<lambda>T  s    (D#?rJ   >bIr   )*r   r   rh   r   typer   r   	full_name_get_reader_schema	schema_idr   r   r   ri   r4   r   r   r   r   r   r   r   r   r   _get_parsed_schemar   FindFileByNamerk   rj   _execute_rulesr7   WRITErN   r   structpackr.   r   r   r   r   getvalue)rS   r  r   r   latest_schemar   fd_protor   fdfield_transformerfor  s              @rH   __call__ProtobufSerializer.__call__  s\   & ?'??33@$fT__d7mDF F ))#*1*<*<*F*FH//\/J$+55DO00033'',,.J!''((DL """&.."@"@AEAEAXAX#Z #'..">">\\4+B+B#DDMI    $$W-$!44]5I5IJNH$$X]]3B++G,>,>,C,CDD!A))#*7*>*>*;=G 2 HHV[[T__EF   %6%6,0,G,G(G ! I HHW..01;;=  s   BK
K-r   c                 &   U R                   R                  U5      nUb  U$ [        5       n[        U5        [	        XR
                  U5        [        SUR                  5      nUR                  U5        U R                   R                  XU45        XC4$ Ndefault
r   get_parsed_schemar   r   r   r   r   r   r   r   rS   r   resultr   r  s        rH   r  %ProtobufSerializer._get_parsed_schemaf      %%77?M4fnnd; F,=,=>  D)9:~rJ   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )NNNTrQ   )%r\   r]   r^   r_   r`   	__slots__r0   r/   r   r+   r1   r
   r   r3   r   staticmethodioBytesIOr   r   r   r   r   r9   r)   r5   r   rF   r  r4   r   r   r   r   r  ra   __classcell__r   s   @rH   r   r      sl   rf>I
 "&"#$( !<+J!&
M   $$(04Y;Y; !5Y; tn	Y;
 D>Y;  -Y; Y;v 2:: C   $ HRZZ HtCy H$ H H*'! 
o	@F! F!h7K.L F!X`afXg F!P E.:\:\^l:l4m  rJ   r   c                   
  ^  \ rS rSrSr/ SQrSS\SS.r    S S\S\	\
   S	\	\   S
\	\
   S\	\   4
U 4S jjjr\S!S\R                   S\S\4S jj5       r\S\R                   S\4S j5       r\S!S\R                   S\S\\   4S jj5       rS"S\S\	\   S\	\   4S jjrS\S\\R:                  \4   4S jrS\S\ S\\   S\!4S jr"S\#S\$\R:                  \RJ                  4   S\\   S\\#\RJ                  4   4S jr&Sr'U =r($ )#ProtobufDeserializerit  a  
Deserializer for Protobuf serialized data with Confluent Schema Registry framing.

Args:
    message_type (Message derived type): Protobuf Message type.
    conf (dict): Configuration dictionary.

ProtobufDeserializer configuration properties:

+-------------------------------------+----------+------------------------------------------------------+
| Property Name                       | Type     | Description                                          |
+-------------------------------------+----------+------------------------------------------------------+
|                                     |          | Whether to use the latest subject version for        |
| ``use.latest.version``              | bool     | deserialization.                                     |
|                                     |          |                                                      |
|                                     |          | Defaults to False.                                   |
+-------------------------------------+----------+------------------------------------------------------+
|                                     |          | Whether to use the latest subject version with       |
| ``use.latest.with.metadata``        | dict     | the given metadata.                                  |
|                                     |          |                                                      |
|                                     |          | Defaults to None.                                    |
+-------------------------------------+----------+------------------------------------------------------+
|                                     |          | Callable(SerializationContext, str) -> str           |
|                                     |          |                                                      |
| ``subject.name.strategy``           | callable | Defines how Schema Registry subject names are        |
|                                     |          | constructed. Standard naming strategies     are      |
|                                     |          | defined in the confluent_kafka.    schema_registry   |
|                                     |          | namespace    .                                       |
|                                     |          |                                                      |
|                                     |          | Defaults to topic_subject_name_strategy.             |
+-------------------------------------+----------+------------------------------------------------------+
| ``use.deprecated.format``           | bool     | Specifies whether the Protobuf deserializer should   |
|                                     |          | deserialize message indexes without zig-zag encoding.|
|                                     |          | This option must be explicitly configured as older   |
|                                     |          | and newer Protobuf producers are incompatible.       |
|                                     |          | If Protobuf messages in the topic to consume were    |
|                                     |          | produced with confluent-kafka-python <1.8 then this  |
|                                     |          | property must be set to True until all old messages  |
|                                     |          | have been processed and producers have been upgraded.|
|                                     |          | Warning: This configuration property will be removed |
|                                     |          | in a future version of the client.                   |
+-------------------------------------+----------+------------------------------------------------------+


See Also:
`Protobuf API reference <https://googleapis.dev/python/protobuf/latest/google/protobuf.html>`_
)r   r   r   FN)r   r   r   r   message_typer   r   r   r   c                   > [         T	U ]  5         X0l        U(       a  UO[        R                  " 5       U l        [        5       U l        S U l        Ub  SU;  a  [        S5      eU R                  R                  5       nUb  UR                  U5        UR                  S5      U l        [        U R                  [         5      (       d  [#        S5      eUR                  S5      U l        U R$                  b*  [        U R$                  [&        5      (       d  [#        S5      eUR                  S5      U l        [+        U R(                  5      (       d  [#        S5      eUR                  S5      U l        [        U R,                  [         5      (       d  [#        S	5      eU R,                  (       a  [.        R0                  " S
5        UR2                  n[5        U5      U l        U R
                  R9                  5        HI  nUR;                  U R                  (       a  U R                  R=                  5       O0 U(       a  UO0 5        MK     g )Nr   zProtobufDeserializer: the 'use.deprecated.format' configuration property must be explicitly set due to backward incompatibility with older confluent-kafka-python Protobuf producers and consumers. See the release notes for more detailsr   r   r   r   r   r   r   af  ProtobufDeserializer: the 'use.deprecated.format' configuration property, and the ability to use the old incorrect Protobuf serializer heading format introduced in confluent-kafka-python v1.4.0, will be removed in an upcoming release in 2022 Q2. Please migrate your Python Protobuf producers and consumers to 'use.deprecated.format':False as soon as possible)r   r   r   r3   r   r   r@   r   r   r   r   r   r   r   r   r   r   rh   r   r   r   r   r   r   r   r   r,   r   r   r   r   )
rS   r3  r   r   r   r   r   r   r   r   s
            rH   r   ProtobufDeserializer.__init__  s    	//<m,BbBbBd02"
 <2$>9: : &&++-	T"#,==1E#F $22D99IJJ)27Q)R&**6t==tDDLMM"+--0G"H//00EFF&/mm4K&L#$55t<<LMM&&MM - . ",,
)*5''557DNNdnn4>>002"(19r; 8rJ   r   r   rC   c                     SnSn  [         R                  U 5      nX$S-  U-  -  nUS-  nUS-  (       d  OM1  U(       a  US-	  US-  * -  nU$ ! [         a    [        S5      ef = f)z
Decodes a single varint from a buffer.

Args:
    buf (BytesIO): buffer to read from
    zigzag (bool): decode as zigzag or uvarint

Returns:
    int: decoded varint

Raises:
    EOFError: if buffer is empty
r   r   r   r   r-   z"Unexpected EOF while reading index)r2  
_read_byteEOFError)r   r   r   shiftis        rH   _decode_varint#ProtobufDeserializer._decode_varint  s      	A(33C8d(u,,
D  !|3L 	A?@@	As   AA A#c                 \    U R                  S5      nUS:X  a  [        S5      e[        U5      $ )z
Read one byte from buf as an int.

Args:
    buf (BytesIO): The buffer to read from.

.. _ord:
    https://docs.python.org/2/library/functions.html#ord
r-   rJ   zUnexpected EOF encountered)readr8  ord)r   r:  s     rH   r7  ProtobufDeserializer._read_byte  s-     HHQK87881vrJ   c                     [         R                  XS9nUS:  d  US:  a  [        S5      eUS:X  a  S/$ / n[        U5       H&  nUR	                  [         R                  U US95        M(     U$ )z
Read an index array from buf that specifies the message
descriptor of interest in the file descriptor.

Args:
    buf (BytesIO): The buffer to read from.

Returns:
    list of int: The index array.
r   r   i z$Invalid Protobuf msgidx array length)r2  r;  r*   ranger   )r   r   size	msg_index_s        rH   _read_index_array&ProtobufDeserializer._read_index_array   s     $2232F!8tf}DEE193J	tA1@@HN A P Q  rJ   datar   c                   ^ Uc  g[        U5      S:  a#  [        SR                  [        U5      5      5      eU R                  US5      nSnUb  U R                  b  U R                  USS9n[        U5       n[        R                  " SUR                  S5      5      u  pgU[        :w  a  [        S5      eU R                  XPR                  (       + S	9nU R                  b  U R                  R                  USS9n	U R                  U	5      u  pUR                  U
R                   5      nU R#                  XU5      nUc.  U R                  X-R$                  5      nUb  U R                  USS9nOSn	SnUbX  U R'                  X9US5      nUR(                  nU R                  UR(                  5      u  pUR                  U
R                   5      nOSnU	nUnUb:  U R#                  WUS
/5      mUR*                  R-                  WR                   T5      mU(       a  [/        W5      " 5       n UR1                  UR                  5       5        [6        R8                  " US5      nU R;                  X#UU5      n[/        T5      " 5       n[6        R<                  " UU5      nO0U R?                  5       n UR1                  UR                  5       5        U4S jnU RA                  X#[B        RD                  SUUSU5      nUsSSS5        $ ! [2         a  n[        [5        U5      5      eSnAff = f! [2         a  n[        [5        U5      5      eSnAff = f! , (       d  f       g= f)a  
Deserialize a serialized protobuf message with Confluent Schema Registry
framing.

Args:
    data (bytes): Serialized protobuf message with Confluent Schema
                   Registry framing.

    ctx (SerializationContext): Metadata relevant to the serialization
        operation.

Returns:
    Message: Protobuf Message instance.

Raises:
    SerializerError: If there was an error reading the Confluent framing
        data, or parsing the protobuf serialized message.
N   zExpecting data framing of length 6 bytes or more but total data size is {} bytes. This message was not produced with a Confluent Schema Registry serializerr   r  r     z]Unknown magic byte. This message was not produced with a Confluent Schema Registry serializerr   r   Tc                    > [        U TX!5      $ rQ   r  )r  r	  r  reader_descs      rH   r  /ProtobufDeserializer.__call__.<locals>.<lambda>  s    (KJrJ   )#r   r8   r   r   r   r  rN   r  unpackr>  r.   rF  r   
get_schemar  r  rk   _get_message_descr  _get_migrationsr   rj   getr,   r   r*   r   r   MessageToDict_execute_migrations	ParseDictr   r  r7   READ)rS   rH  r   r   r  payloadmagicr  rD  writer_schema_rawr  r   writer_schemawriter_desc
migrationsreader_schema_rawreader_schemar
  r   obj_dictr  rM  s                        @rH   r  ProtobufDeserializer.__call__;  s9   ( < t9q=$ &B CI&TBSU U
 ))#t44>>#= 33G3NMd#w%}}UGLLODE#( *F G G ..wC^C^?^._I~~)$(NN$=$=i\$=$Z!!%!8!89J!K $ 3 3HMM B"44T)T?"55c;P;PQG*(,(?(?\(?(Z$(! $(!11'm]ab
$1$8$8!!%!8!89M9M!N $ 3 3HMM B!
$5! -("44T=1#N+AAEEkFVFVXcd%k245''7 '44S$?33C*hW%k24!++Hc: oo'5''7!L%%cHMM4&7d&79C  $#T # 5,SV445 # 5,SV445m $#sV   7F.M	&K=A"M	(L#,M	=
L LL  M	#
M-MMM		
Mr   c                 &   U R                   R                  U5      nUb  U$ [        5       n[        U5        [	        XR
                  U5        [        SUR                  5      nUR                  U5        U R                   R                  XU45        XC4$ r"  r$  r&  s        rH   r  'ProtobufDeserializer._get_parsed_schema  r)  rJ   r   r  rD  c                     [         R                  " 5       nUR                  U5        U R                  SXC5      u  pVUR                  nU(       a  US-   U-   OUnUR                  U5      $ )N .)r   r   CopyToProto_get_message_desc_protopackageFindMessageTypeByName)	rS   r   r  rD  file_desc_protor  
desc_protori  qualified_names	            rH   rQ  &ProtobufDeserializer._get_message_desc  sa     )<<>
'"&">">r?"^!))6=329)).99rJ   pathr  c                    US   n[        U[        R                  5      (       a[  UR                  U   nU(       a  US-   UR                  -   OUR                  n[        U5      S:X  a  X4$ U R                  XUSS  5      $ UR                  U   nU(       a  US-   UR                  -   OUR                  n[        U5      S:X  a  X4$ U R                  XUSS  5      $ )Nr   rf  r-   )r   r   r   r3  rk   r   rh  nested_type)rS   ro  r  rD  indexr
  s         rH   rh  ,ProtobufDeserializer._get_message_desc_proto  s     !dN>>??##E*C,04#:(chhD9~"y //9QR=II""5)C,04#:(chhD9~"y //9QR=IIrJ   )	r   r   r   r   r   r   r   r   r   )NNNNr*  rQ   ))r\   r]   r^   r_   r`   r+  r0   r   r+   r
   r   r1   r3   r   r,  r-  r.  r   r   r;  r7  r   rF  rF   r9   r  r4   r   r   r   r   r  r)   r'   rQ  r   r	   DescriptorProtorh  ra   r/  r0  s   @rH   r2  r2  t  s   .` LI $$(!<!&	M  $AE$(04<;<; tn<; !))= >	<;
 D><;  -<; <;|  ABJJ  A  A  A  AD 

 s    rzz 4 49  4bU b2F)G bS[\cSd bH E.:\:\^l:l4m 	:"	:(6	:9	: 
	:JJ N668V8VVWJ 9	J
 
sN222	3J JrJ   r2  r   r   r  r	  c                 B   Ub  Uc  U$ [        U[        5      (       a  U Vs/ s H  n[        XXC5      PM     sn$ [        U[        5      (       a0  UR	                  5        VVs0 s H  u  pVU[        XXc5      _M     snn$ [        U[
        5      (       a"  UR                   H  n[        XXU5        M     U$ U R                  5       nUbJ  U R                  R                  n	U	(       a$  [        [        U	5      UR                  5      (       d	  U" XU5      $ U$ s  snf s  snnf rQ   )r   rl   r  r   itemsr+   fields_transform_fieldcurrent_fieldr   tags	_disjointr   )
r   r   r  r	  itemkeyr   r  	field_ctx	rule_tagss
             rH   r  r    s
    *,'4  #%#D #4A#% 	%'4  ")--/3"1JC YsGG"13 	3'7####BSj?K $!!#IHHMM		#i.).. I I"37;;N%3s   D#Dr  r  c           	          U R                  UUR                  UR                  [        U5      [	        U5      5        UR
                  b2  UR                  UR                  5      (       d   U R                  5         g [        X1R                  5      n[        U5      (       a  U Vs0 s H  ofXV   _M	     nnO/UR                  [        R                  :X  a  U Vs/ s H  owPM     nn[        XXT5      nU R                  R                  [         R"                  :X  a  USL a  [%        U R                  5      eO['        XU5        U R                  5         g s  snf s  snf ! U R                  5         f = frW   )enter_fieldr  rk   get_typeget_inline_tagscontaining_oneofHasField
exit_fieldgetattris_map_fieldlabelr(   LABEL_REPEATEDr  r   kindr6   	CONDITIONr?   
_set_field)	r   r  r  r  r	  r   r}  r|  	new_values	            rH   rx  rx    s)   LLGGRLB	
 *73C3CBGG3L3L 	 )056%*_E6EXX777&+,edTeE,c@	88==H...E!(22 " rI. 7, 	s1   A(E <)E %E3%E E#AE 
E E-r   c                    [        U[        5      (       aB  UR                  U R                  5        [	        XR                  5      nUR                  U5        g [        U[        5      (       aB  UR                  U R                  5        [	        XR                  5      nUR                  U5        g [        XR                  U5        g rQ   )	r   rl   
ClearFieldrk   r  extendr   r   setattr)r  r  r   	old_values       rH   r  r    s    %277#GWW-		E4	 	 277#GWW-	%(rJ   c                    [        U 5      (       a  [        R                  $ U R                  [        R
                  :X  a  [        R                  $ U R                  [        R                  :X  a  [        R                  $ U R                  [        R                  :X  a  [        R                  $ U R                  [        R                  :X  a  [        R                  $ U R                  [        R                  [        R                  [        R                  [        R                   [        R"                  4;   a  [        R$                  $ U R                  [        R&                  [        R(                  [        R*                  [        R,                  [        R.                  4;   a  [        R0                  $ U R                  [        R2                  :X  a  [        R4                  $ U R                  [        R6                  :X  a  [        R8                  $ U R                  [        R:                  :X  a  [        R<                  $ [        R>                  $ rQ   ) r  r>   MAPr  r(   TYPE_MESSAGERECORD	TYPE_ENUMENUMTYPE_STRINGSTRING
TYPE_BYTESBYTES
TYPE_INT32TYPE_SINT32TYPE_UINT32TYPE_FIXED32TYPE_SFIXED32INT
TYPE_INT64TYPE_SINT64TYPE_UINT64TYPE_FIXED64TYPE_SFIXED64LONG
TYPE_FLOATFLOATTYPE_DOUBLEDOUBLE	TYPE_BOOLBOOLEANNULLr  s    rH   r  r    s{   B}}	ww/...	ww/+++~~	ww/---	ww/,,,	ww?--/J/J"..0L0L"002 2 }}	ww?--/J/J"..0L0L"002 2 ~~	ww/,,,	ww/---	ww/+++   >>rJ   c                     U R                   [        R                  :H  =(       a=    [        U R                  S5      =(       a     U R                  R
                  R                  $ )Noptions)r  r(   r  hasattrr3  r  	map_entryr  s    rH   r  r  *  sD    GG333 232''113rJ   c                     U R                  5       R                  [        R                     nUc
  [	        5       $ [	        UR
                  5      $ rQ   )
GetOptions
Extensionsr   
field_metar   rz  )r  metas     rH   r  r  0  s8    ==?%%h&9&9:D|u499~rJ   tags1tags2c                 $    U  H
  nX!;   d  M
    g   g)NFTrR   )r  r  tags      rH   r{  r{  8  s    <  rJ   c                     U R                  S5      =(       d)    U R                  S5      =(       d    U R                  S5      $ )Nz
confluent/zgoogle/protobuf/zgoogle/type/)
startswith)rk   s    rH   r   r   ?  s6    ??<( +??-.+??>*+rJ   scalec                 >   U R                  5       u  p#nXA-   nUS:  a  [        S5      eSnU H  nUS-  U-   nM     SU-  U-  nUR                  5       S-   S-  nU(       a  U* nUR                  USSS9n	[        R
                  " 5       n
Xl        SU
l        Xl        U
$ )z
Converts a Decimal to a Protobuf value.

Args:
    value (Decimal): The Decimal value to convert.

Returns:
    The Protobuf value.
r   z)Scale provided does not match the decimal
      bigT	byteordersigned)	as_tuplerh   
bit_lengthto_bytesr2   r   r   	precisionr  )r   r  signdigitsexpdeltaunscaled_datumdigit	bytes_reqrF   r'  s              rH   decimalToProtobufr  E  s     (D#KEqy79 	9 N(2-6  Y/N**,q0Q6I(##It#LE  "FLFLMrJ   c                    [         R                  U R                  SSS9nU R                  S:  a  U R                  [        l        O[        [        l        [        R                  U5      R                  U R                  * [        5      $ )z
Converts a Protobuf value to Decimal.

Args:
    value (decimal_pb2.Decimal): The Protobuf value to convert.

Returns:
    The Decimal value.
r  Tr  r   )
r   
from_bytesr   r  decimal_contextprecr   create_decimalscalebr  )r   r  s     rH   protobufToDecimalr  n  se     ^^EKK5^NN$')).9@@	o rJ   rQ   )qr-  sysrx   r  r   collectionsr   decimalr   r   r   typingr   r   r	   r
   r   r   google.protobufr   r   r   r   r   r   r   r   r   r   r   r   google.protobuf.descriptor_poolr   google.typer   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   2confluent_kafka.schema_registry.confluent.meta_pb2schema_registry	confluentr   google.protobuf.descriptorr'   r(   r)   google.protobuf.messager*   r+   google.protobuf.message_factoryr,   re  r.   r/   r0   r1   confluent.typesr2   r   r3   r   r4   r5   r6   r7   confluent_kafka.serializationr8   r9   serder:   r;   r<   r=   r>   r?   r@   r   r   rF   rI   r   r.  rN   rt   r|   r   r   r   r   r   r   r2  r  rx  r  r  r  r  r   r{  r   r  r  r  rR   rJ   rH   <module>r     s  $ 
 
     . . 9 9    ( :6 6 6 6 F E  8 ;B B ) '/ /E E E ;;# % # # 
rzz 
** *c *ZTN Ts T`)K)K `PS `! ! !1S1S !2 #'	,,0, , c#h	,4A^ AB{ {|UJ+ UJp
	",7:# 	0	)1;'5:
)? 
)W 
)S 
) Y 83_ 3 CH SX c#h 4 +c +d +#W #S #[5H5H #L )[00 W rJ   