o
    7D©i‚
  ã                   @   s8   d Z ddlZG dd„ dƒZG dd„ dƒZeƒ Zeƒ ZdS )a)  
https://en.wikipedia.org/wiki/LEB128

LEB128 or Little Endian Base 128 is a form of variable-length code
compression used to store an arbitrarily large integer in a small number of
bytes. LEB128 is used in the DWARF debug file format and the WebAssembly
binary encoding for all integer literals.
é    Nc                   @   óZ   e Zd Zededefdd„ƒZededefdd„ƒZedej	dej
eef fd	d
„ƒZdS )Ú_UÚiÚreturnc                 C   sL   | dksJ ‚g }	 | d@ }| d? } | dkr|  |¡ t|ƒS |  d|B ¡ q	)zHEncode the int i using unsigned leb128 and return the encoded bytearray.r   Té   é   é€   ©ÚappendÚ	bytearray©r   ÚrÚbyte© r   úH/var/www/Datamplify/venv/lib/python3.10/site-packages/leb128/__init__.pyÚencode   s   
úz	_U.encodeÚbc                 C   s.   d}t | ƒD ]\}}||d@ |d >  }q|S )z,Decode the unsigned leb128 encoded bytearrayr   r   r   ©Ú	enumerate©r   r   r   Úer   r   r   Údecode   s   z	_U.decoder   c                 C   óV   t ƒ }	 |  d¡}t|ƒdkrt‚t|ƒ}| |¡ |d@ dkr!nqt |¡t|ƒfS )z–
        Decode the unsigned leb128 encoded from a reader, it will return two values, the actual number and the number
        of bytes read.
        Té   r   r   )r   ÚreadÚlenÚEOFErrorÚordr
   r   r   ©r   Úar   r   r   r   Údecode_reader#   ó   

ùz_U.decode_readerN©Ú__name__Ú
__module__Ú__qualname__ÚstaticmethodÚintr   r   r   ÚtypingÚBinaryIOÚTupler    r   r   r   r   r      s    $r   c                   @   r   )Ú_Ir   r   c                 C   s`   g }	 | d@ }| d? } | dkr|d@ dks| dkr(|d@ dkr(|  |¡ t|ƒS |  d|B ¡ q)zFEncode the int i using signed leb128 and return the encoded bytearray.Tr   r   r   é@   éÿÿÿÿr   r	   r   r   r   r   r   6   s   (
úz	_I.encoder   c                 C   sP   d}t | ƒD ]\}}||d@ |d >  }q|d@ dkr&|d|d d >  O }|S )z*Decode the signed leb128 encoded bytearrayr   r   r   r,   r   r   r   r   r   r   r   B   s   z	_I.decoder   c                 C   r   )z”
        Decode the signed leb128 encoded from a reader, it will return two values, the actual number and the number
        of bytes read.
        Tr   r   r   )r   r   r   r   r   r
   r+   r   r   r   r   r   r    L   r!   z_I.decode_readerNr"   r   r   r   r   r+   5   s    	$r+   )Ú__doc__r(   r   r+   Úur   r   r   r   r   Ú<module>   s    	()
