
    ^iO	                    (    S r SSKJr   " S S5      rg)z
An implementation of a bitwise prefix tree specially built for decoding
Huffman-coded content where we already know the Huffman table.
    )annotationsc                  ,    \ rS rSrSrSS jrSS jrSrg)	HuffmanEncoder   z^
Encodes a string according to the Huffman encoding table defined in the
HPACK specification.
c                    Xl         X l        g )Nhuffman_code_listhuffman_code_list_lengths)selfr	   r
   s      G/home/james-whalen/.local/lib/python3.13/site-packages/hpack/huffman.py__init__HuffmanEncoder.__init__   s    !2)B&    c                   U(       d  gSnSnU H9  nU R                   U   nU R                  U   SUS-   -  S-
  -  nX%-  nX&-  nX5-  nM;     SUS-  -
  S-  nX'-  nUSU-  S-
  -  n[        U5      SS R                  S5      n[	        U5      S-  S:w  a  SU-   OUnX7-   S-  n	U	S-  n
[	        U5      U
:w  a  U
[	        U5      -
  nSU-  U-   n[
        R                  U5      $ )	zU
Given a string of bytes, encodes them according to the HPACK Huffman
specification.
r   r         r   NL0)r
   r	   hexrstriplenbytesfromhex)r   bytes_to_encode	final_numfinal_int_lenbytebin_int_lenbin_intbits_to_be_paddedstotal_bytesexpected_digitsmissing_digitss               r   encodeHuffmanEncoder.encode   s,    	
 $D88>K,,T2kAo&*G %I I(M $ -!"349'	a,,11	 	N12%%c* 1vzQC!GA
 %8Q>%/q6_$,s1v5N~%*A}}Qr   r   N)r	   	list[int]r
   r'   returnNone)r   zbytes | Noner(   r   )__name__
__module____qualname____firstlineno____doc__r   r%   __static_attributes__ r   r   r   r      s    
C. r   r   N)r.   
__future__r   r   r0   r   r   <module>r2      s    #8  8 r   