관리-도구
편집 파일: encoder.cpython-311.pyc
� P�Dg�o � � � d Z dZddlZddlmZ dZe Zd� Zd� Zd� Z d � Z d � Zd� Z e e� � xZ xZZ e e� � xZZ eeej � � xZZ ed� � xZxZZ ed � � xZxZZ ed� � Zd� Zd� Zd� Zd� Zd� Z d� Z!d� Z"d� Z# e"� � Z$ e#� � Z%d� Z&d� Z'd� Z(d� Z)d� Z*d� Z+ e(ej, e%e� � xZ-xZ.Z/ e(ej, e$e� � xZ0Z1 e)ej, e$eej � � xZ2Z3 e*ej4 d� � Z5 e*ej6 d� � Z7 e*ej4 d� � Z8 e*ej6 d � � Z9 e+ej4 d!� � Z: e+ej6 d"� � Z;d#� Z<d$� Z=d%� Z>d&� Z?d'� Z@d(� ZAd)� ZBdS )*a� Code for encoding protocol message primitives. Contains the logic for encoding every logical protocol field type into one of the 5 physical wire types. This code is designed to push the Python interpreter's performance to the limits. The basic idea is that at startup time, for every field (i.e. every FieldDescriptor) we construct two functions: a "sizer" and an "encoder". The sizer takes a value of this field's type and computes its byte size. The encoder takes a writer function and a value. It encodes the value into byte strings and invokes the writer function to write those strings. Typically the writer function is the write() method of a BytesIO. We try to do as much work as possible when constructing the writer and the sizer rather than when calling them. In particular: * We copy any needed global functions to local variables, so that we do not need to do costly global table lookups at runtime. * Similarly, we try to do any attribute lookups at startup time if possible. * Every field's tag is encoded to bytes at startup, since it can't change at runtime. * Whatever component of the field size we can compute at startup, we do. * We *avoid* sharing code if doing so would make the code slower and not sharing does not burden us too much. For example, encoders for repeated fields do not just call the encoders for singular fields in a loop because this would add an extra function call overhead for every loop iteration; instead, we manually inline the single-value encoder into the loop. * If a Python function lacks a return statement, Python actually generates instructions to pop the result of the last statement off the stack, push None onto the stack, and then return that. If we really don't care what value is returned, then we can save two instructions by returning the result of the last statement. It looks funny but it helps. * We assume that type and bounds checking has happened at a higher level. z kenton@google.com (Kenton Varda)� N)�wire_formatg �c � � | dk rdS | dk rdS | dk rdS | dk rdS | d k rd S | dk rdS | d k rdS | dk rdS | dk rdS dS )z#Compute the size of a varint value.� � �? � � � ��� � �� � � ���� � ��� � � ����� � ���� � � � ��values ��/builddir/build/BUILD/imunify360-venv-2.4.0/opt/imunify360/venv/lib64/python3.11/site-packages/google/protobuf/internal/encoder.py�_VarintSizer P s� � � �d�]�]�1�1� �f�_�_�Q�Q� �h���q�q� �i����� �k���!�!� �m���A�A� �o���a�a� ����q�q� � � � ��� �� c � � | dk rdS | dk rdS | dk rdS | dk rdS | d k rd S | dk rdS | d k rdS | dk rdS | dk rdS | dk rdS dS )z*Compute the size of a signed varint value.r r r r r r r r r r r r r r r r r r r r r r s r �_SignedVarintSizer ^ s� � � �Q�Y�Y�r�r� �d�]�]�1�1� �f�_�_�Q�Q� �h���q�q� �i����� �k���!�!� �m���A�A� �o���a�a� ����q�q� � � � ��� �r c �F � t t j | d� � � � S )zQReturns the number of bytes required to serialize a tag with this field number.r )r r �PackTag)�field_numbers r �_TagSizer# m s � � �[�(��q�9�9� :� :�:r c � � � � fd�}|S )z�A sizer which uses the function compute_value_size to compute the size of each value. Typically compute_value_size is _VarintSize.c �n ���� t | � � �|rt ����fd�}|S |r��fd�}|S ��fd�}|S )Nc �P �� d}| D ]}| �|� � z }�| �|� � z �z S �Nr r )r �result�element�compute_value_size�local_VarintSize�tag_sizes ���r �PackedFieldSizez<_SimpleSizer.<locals>.SpecificSizer.<locals>.PackedFieldSize� sK �� ���� 0� 0�G� �&�&�w�/�/� /�&�&��(�(��0�0�0�8�;�;r c �R �� �t | � � z }| D ]}| �|� � z }�|S �N��len)r r( r) r* r, s ��r �RepeatedFieldSizez>_SimpleSizer.<locals>.SpecificSizer.<locals>.RepeatedFieldSize� s? �� ��C��J�J�&��� 0� 0�G� �&�&�w�/�/� /�&�&�� r c � �� � �| � � z S r/ r )r r* r, s ��r � FieldSizez6_SimpleSizer.<locals>.SpecificSizer.<locals>.FieldSize� s �� ��,�,�U�3�3�3�3r �r# r ) r"