
    g                     $    d dl mZ  G d d      Zy)    )unpackc                   ~    e Zd ZdZd Zd Zd Zd ZeZd Z	d Z
d Zdd	Zd
 Zd Zd Zd Zd ZeZeZd Zd Zd Zy)BinaryDecoderzDecoder for the avro binary format.

    NOTE: All attributes and methods on this class should be considered
    private.

    Parameters
    ----------
    fo: file-like
        Input stream

    c                     || _         y N)fo)selfr   s     O/var/www/openai/venv/lib/python3.12/site-packages/fastavro/io/binary_decoder.py__init__zBinaryDecoder.__init__   s	        c                      y)znull is written as zero bytes.N r	   s    r
   	read_nullzBinaryDecoder.read_null   s    r   c                 X    t        d| j                  j                  d            d   dk7  S )zcA boolean is written as a single byte whose value is either 0
        (false) or 1 (true).
        B   r   r   r   readr   s    r
   read_booleanzBinaryDecoder.read_boolean   s'     c477<<?+A.!33r   c                    | j                   j                  d      }|st        t        |      }|dz  }d}|dz  dk7  r=t        | j                   j                  d            }||dz  |z  z  }|dz  }|dz  dk7  r=|dz	  |dz   z  S )zNint and long values are written using variable-length, zig-zag
        coding.r            r   )r   r   EOFErrorord)r	   cbnshifts        r
   	read_longzBinaryDecoder.read_long!   s     GGLLO NFH4xAoDGGLLO$A!d(u$$AQJE 4xAo
 QAE(""r   c                 R    t        d| j                  j                  d            d   S )zA float is written as 4 bytes.

        The float is converted into a 32-bit integer using a method equivalent
        to Java's floatToIntBits and then encoded in little-endian format.
        z<f   r   r   r   s    r
   
read_floatzBinaryDecoder.read_float7   "     dDGGLLO,Q//r   c                 R    t        d| j                  j                  d            d   S )zA double is written as 8 bytes.

        The double is converted into a 64-bit integer using a method equivalent
        to Java's doubleToLongBits and then encoded in little-endian format.
        z<d   r   r   r   s    r
   read_doublezBinaryDecoder.read_double?   r%   r   c                     | j                         }| j                  j                  |      }t        |      |k7  rt	        d| dt        |             |S )z@Bytes are encoded as a long followed by that many bytes of data.	Expected  bytes, read )r!   r   r   lenr   r	   sizeouts      r
   
read_byteszBinaryDecoder.read_bytesG   sM    ~~ggll4 s8tYtfM#c(DEE
r   c                 B    | j                         j                  |      S )zkA string is encoded as a long followed by that many bytes of UTF-8
        encoded character data.
        )errors)r0   decode)r	   handle_unicode_errorss     r
   	read_utf8zBinaryDecoder.read_utf8O   s       ''/D'EEr   c                     | j                   j                  |      }t        |      |k  rt        d| dt        |             |S )zUFixed instances are encoded using the number of bytes declared in the
        schema.r*   r+   )r   r   r,   r   r-   s      r
   
read_fixedzBinaryDecoder.read_fixedU   sB     ggll4 s8d?YtfM#c(DEE
r   c                 "    | j                         S )zoAn enum is encoded by a int, representing the zero-based position of the
        symbol in the schema.
        r!   r   s    r
   	read_enumzBinaryDecoder.read_enum]   s     ~~r   c                 .    | j                         | _        y)z)Arrays are encoded as a series of blocks.Nr!   _block_countr   s    r
   read_array_startzBinaryDecoder.read_array_startc        NN,r   c                      y r   r   r   s    r
   read_array_endzBinaryDecoder.read_array_endg       r   c              #     K   | j                   dk7  ru| j                   dk  r"| j                    | _         | j                          t        | j                         D ]  }d  | j                         | _         | j                   dk7  rtyyw)a  Each block consists of a long count value, followed by that many
        array items. A block with count zero indicates the end of the array.
        Each item is encoded per the array's item schema.

        If a block's count is negative, then the count is followed immediately
        by a long block size, indicating the number of bytes in the block.
        The actual count in this case is the absolute value of the count
        written.
        r   N)r=   r!   range)r	   is     r
   _iter_array_or_mapz BinaryDecoder._iter_array_or_mapj   sv      1$  1$%)%6%6$6! 4,,- . $ 0D 1$s   BBBc                 .    | j                         | _        y)z'Maps are encoded as a series of blocks.Nr<   r   s    r
   read_map_startzBinaryDecoder.read_map_start   r?   r   c                      y r   r   r   s    r
   read_map_endzBinaryDecoder.read_map_end   rB   r   c                 "    | j                         S )zA union is encoded by first writing a long value indicating the
        zero-based position within the union of the schema of its value.

        The value is then encoded per the indicated schema within the union.
        r9   r   s    r
   
read_indexzBinaryDecoder.read_index   s     ~~r   N)strict)__name__
__module____qualname____doc__r   r   r   r!   read_intr$   r(   r0   r5   r7   r:   r>   rA   rF   
iter_arrayiter_maprH   rJ   rL   r   r   r
   r   r      sk    
4#( H00F -1( $J!H- r   r   N)structr   r   r   r   r
   <module>rV      s    J  J r   