o
    i                     @   s   d dl mZ G dd dZdS )    )unpackc                   @   s   e Zd ZdZdd Zdd Zdd Zdd	 ZeZd
d Z	dd Z
dd Zd$ddZdd Zdd Zdd Zdd Zdd ZeZeZdd Zdd  Zd!d" Zd#S )%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                 C   s
   || _ d S N)fo)selfr    r   `/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/fastavro/io/binary_decoder.py__init__   s   
zBinaryDecoder.__init__c                 C   s   dS )znull is written as zero bytes.Nr   r   r   r   r   	read_null   s   zBinaryDecoder.read_nullc                 C   s   t d| jdd dkS )zcA boolean is written as a single byte whose value is either 0
        (false) or 1 (true).
        B   r   r   r   readr
   r   r   r   read_boolean   s   zBinaryDecoder.read_booleanc                 C   sz   | j d}|s
tt|}|d@ }d}|d@ dkr4t| j d}||d@ |> O }|d7 }|d@ dks|d? |d@  A S )zNint and long values are written using variable-length, zig-zag
        coding.r            r   )r   r   EOFErrorord)r   cbnshiftr   r   r   	read_long!   s   zBinaryDecoder.read_longc                 C      t d| 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
   r   r   r   
read_float7      zBinaryDecoder.read_floatc                 C   r   )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
   r   r   r   read_double?   r   zBinaryDecoder.read_doublec                 C   s<   |   }| j|}t||k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outr   r   r   
read_bytesG   s
   zBinaryDecoder.read_bytesstrictc                 C   s   |   j|dS )zkA string is encoded as a long followed by that many bytes of UTF-8
        encoded character data.
        )errors)r'   decode)r   handle_unicode_errorsr   r   r   	read_utf8O   s   zBinaryDecoder.read_utf8c                 C   s4   | 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$   r   r   r   
read_fixedU   s   zBinaryDecoder.read_fixedc                 C      |   S )zoAn enum is encoded by a int, representing the zero-based position of the
        symbol in the schema.
        r   r
   r   r   r   	read_enum]   s   zBinaryDecoder.read_enumc                 C      |   | _dS )z)Arrays are encoded as a series of blocks.Nr   _block_countr
   r   r   r   read_array_startc      zBinaryDecoder.read_array_startc                 C      d S r   r   r
   r   r   r   read_array_endg      zBinaryDecoder.read_array_endc                 c   sZ    | j dkr+| j dk r| j  | _ |   t| j D ]}dV  q|  | _ | j dksdS dS )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)r3   r   range)r   ir   r   r   _iter_array_or_mapj   s   




z BinaryDecoder._iter_array_or_mapc                 C   r1   )z'Maps are encoded as a series of blocks.Nr2   r
   r   r   r   read_map_start   r5   zBinaryDecoder.read_map_startc                 C   r6   r   r   r
   r   r   r   read_map_end   r8   zBinaryDecoder.read_map_endc                 C   r.   )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.
        r/   r
   r   r   r   
read_index   s   zBinaryDecoder.read_indexN)r(   )__name__
__module____qualname____doc__r	   r   r   r   read_intr   r    r'   r,   r-   r0   r4   r7   r;   
iter_arrayiter_mapr<   r=   r>   r   r   r   r   r      s*    	
r   N)structr   r   r   r   r   r   <module>   s    