
    eCi	                     n    d Z ddlZ G d d          Z G 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                   |    e Zd Zededefd            Zededefd            Zedej	        deeffd            Z
dS )	_Uireturnc                     | dk    sJ g }	 | dz  }| dz	  } | dk    r$|                     |           t          |          S |                     d|z             M)zHEncode the int i using unsigned leb128 and return the encoded bytearray.r   T         append	bytearrayr   rbytes      ?/b/s/w/ir/x/w/install/emscripten/third_party/leb128/__init__.pyencodez	_U.encode   sl     Avvvv	"t8DQAAvv ||#HHTD[!!!	"    bc                 P    d}t          |           D ]\  }}||dz  |dz  z  z   }|S )z,Decode the unsigned leb128 encoded bytearrayr   r   r	   	enumerater   r   r   es       r   decodez	_U.decode   s@     aLL 	, 	,DAqa$hAE*+AAr   r   c                     t                      }	 t          |                     d                    }|                    |           |dz  dk    rnBt                              |          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   ordreadr   r   r   lenr   ar   s      r   decode_readerz_U.decode_reader#   h     KK	AFF1IIAHHQKKKDQ		
 yy||SVV##r   N__name__
__module____qualname__staticmethodintr   r   r   typingBinaryIOr"    r   r   r   r      s        
"# 
") 
" 
" 
" \
" )     \ $ $c3Z $ $ $ \$ $ $r   r   c                   |    e Zd Zededefd            Zededefd            Zedej	        deeffd            Z
dS )	_Ir   r   c                     g }	 | dz  }| dz	  } | dk    r	|dz  dk    s| dk    r-|dz  dk    r$|                     |           t          |          S |                     d|z             e)zFEncode the int i using signed leb128 and return the encoded bytearray.Tr   r	   r   @   r
   r   r   s      r   r   z	_I.encode3   s     	"t8DQAQ4$;!++bTD[A=M=M ||#HHTD[!!!	"r   r   c                     d}t          |           D ]\  }}||dz  |dz  z  z   }|dz  dk    r|d|dz  dz   z   z  }|S )z*Decode the signed leb128 encoded bytearrayr   r   r	   r0   r   r   r   s       r   r   z	_I.decode?   sg     aLL 	, 	,DAqa$hAE*+AAt8q==A!a%1$%%Ar   r   c                     t                      }	 t          |                     d                    }|                    |           |dz  dk    rnBt                              |          t          |          fS )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    s      r   r"   z_I.decode_readerI   r#   r   Nr$   r,   r   r   r.   r.   2   s        	"# 	") 	" 	" 	" \	" )     \ $ $c3Z $ $ $ \$ $ $r   r.   )__doc__r*   r   r.   ur   r,   r   r   <module>r6      s     "$ "$ "$ "$ "$ "$ "$ "$J#$ #$ #$ #$ #$ #$ #$ #$L BDDBDDr   