o
    Á¿iŽ  ã                   @   s\   d dl mZ d dlmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZ G dd„ de
ƒZd	S )
é    )ÚFieldDescriptor©Úschema)Údata_streams_processor)ÚSchemaBuilder)ÚSchemaIterator)ÚSpanc                   @   s¬   e Zd ZdZdZdZdd„ Zedede	de	d	e
d
edefdd„ƒZed	e
d
edefdd„ƒZedefdd„ƒZd	e
fdd„Zedede	fdd„ƒZededefdd„ƒZdS )ÚSchemaExtractorÚserializationÚdeserializationÚprotobufc                 C   s
   || _ d S ©Nr   )Úselfr   © r   úe/home/ubuntu/.local/lib/python3.10/site-packages/ddtrace/contrib/internal/protobuf/schema_iterator.pyÚ__init__   s   
zSchemaExtractor.__init__ÚfieldÚschema_nameÚ
field_nameÚbuilderÚdepthÚreturnc              
   C   sœ   d}d }d }d }d }	d }
t  | j¡}|d }|d }|d u r5|dkr5d }d| jj }	t  | j||¡s4dS n|dkrBdd„ | jjD ƒ}
| ||||||	||
¡S )	NFr   é   úMessage typez#/components/schemas/Úenumc                 S   s   g | ]}|j ‘qS r   )Úname)Ú.0Úvaluer   r   r   Ú
<listcomp>)   s    z4SchemaExtractor.extract_property.<locals>.<listcomp>)	r	   Úget_type_and_formatÚtypeÚmessage_typer   Úextract_schemaÚ	enum_typeÚvaluesÚadd_property)r   r   r   r   r   ÚarrayÚtype_Úformat_ÚdescriptionÚrefÚenum_valuesÚtype_formatr   r   r   Úextract_property   s$   ÿz SchemaExtractor.extract_propertyc                 C   sh   |d7 }| j }| ||¡sdS z| j ¡ D ]\}}t |||||¡s& W dS qW dS  ty3   Y dS w )Nr   FT)r   Úshould_extract_schemaÚfields_by_nameÚitemsr	   r-   Ú	Exception)r   r   r   r   r   Ú
field_descr   r   r   r"   ,   s   ÿÿþÿzSchemaExtractor.extract_schemac                 C   s   t ƒ  | jt| ƒ¡S r   )r   Ú
get_schemar   r	   )Ú
descriptorr   r   r   Úextract_schemas:   s   zSchemaExtractor.extract_schemasc                 C   s   |   | j|d¡ d S ©Nr   )r"   r   )r   r   r   r   r   Úiterate_over_schema>   s   z#SchemaExtractor.iterate_over_schemaÚspanÚ	operationc                 C   sÂ   | d u s|d u r
d S |  tjtj¡ |  tj| j¡ |  tj|¡ tƒ  	|¡s)d S |j
j}|d u s5|dkr7d S tƒ  |¡}|dkrCd S t | ¡}|  tj|j¡ | tj|¡ |  tj|j¡ d S r6   )Úset_tagÚSCHEMA_TAGSÚSCHEMA_TYPEr	   ÚPROTOBUFÚSCHEMA_NAMEr   ÚSCHEMA_OPERATIONr   Úcan_sample_schemaÚcontextÚsampling_priorityÚtry_sample_schemar5   ÚSCHEMA_DEFINITIONÚ
definitionÚ
set_metricÚSCHEMA_WEIGHTÚ	SCHEMA_IDÚid)r4   r8   r9   ÚprioÚweightÚschema_datar   r   r   Úattach_schema_on_spanA   s"   
z%SchemaExtractor.attach_schema_on_spanr'   c                 C   s~   i dd“dd“dd“dd“d	d
“dd“dd“dd“dd“dd“dd“dd“dd“dd“dd“dd “d!d
“d"di¥}|  | d¡S )#Nr   )ÚnumberÚdoubleé   )rN   Úfloaté   )ÚintegerÚint64é   )rS   Úuint64é   )rS   Úint32é   )rS   Úfixed64é   )rS   Úfixed32é   )ÚbooleanNé	   )ÚstringNé
   )Úobjectz
Group typeé   )Nr   é   )r`   Úbyteé   )rS   Úuint32é   )r`   r   é   )rS   Úsfixed32é   )rS   Úsfixed64é   é   )Úget)r'   Útype_format_mappingr   r   r   r   [   sL   ÿþýüûúùø	÷
öõôóòñðïîz#SchemaExtractor.get_type_and_formatN)Ú__name__Ú
__module__Ú__qualname__ÚSERIALIZATIONÚDESERIALIZATIONr=   r   Ústaticmethodr   Ústrr   Úintr-   Úboolr"   r5   r7   r   rM   Útupler   r   r   r   r   r	      s8    ÿÿÿÿÿþr	   N)Úgoogle.protobuf.descriptorr   Úddtrace.extr   r;   Úddtrace.internal.datastreamsr   Ú3ddtrace.internal.datastreams.schemas.schema_builderr   Ú4ddtrace.internal.datastreams.schemas.schema_iteratorr   Úddtrace.tracer   r	   r   r   r   r   Ú<module>   s    