o
    «¸¢i×  ã                   @   sR   d dl mZ d dlmZ d dlmZmZ d dlmZ d dl	m
Z
 G dd„ dƒZdS )	é    )ÚAny)ÚUUID)ÚSTRUCT_DOUBLEÚSTRUCT_FLOAT)ÚOutputStream)ÚUTF8c                   @   sÎ   e Zd ZU dZeed< deddfdd„Zdeddfd	d
„Zde	ddfdd„Z
deddfdd„Zdeddfdd„Zdeddfdd„Zdeddfdd„Zdeddfdd„Zdeddfdd„Zdeddfdd „ZdS )!ÚBinaryEncoderz)Encodes Python physical types into bytes.Ú_output_streamÚoutput_streamÚreturnNc                 C   s
   || _ d S ©N)r	   )Úselfr
   © r   úT/home/ubuntu/transcripts/venv/lib/python3.10/site-packages/pyiceberg/avro/encoder.pyÚ__init__   s   
zBinaryEncoder.__init__Úbc                 C   s   | j  |¡ d S r   )r	   Úwrite©r   r   r   r   r   r   !   s   zBinaryEncoder.writeÚbooleanc                 C   s   |   tt|ƒgƒ¡ dS )zWrite a boolean as a single byte whose value is either 0 (false) or 1 (true).

        Args:
            boolean: The boolean to write.
        N)r   ÚbytesÚbool)r   r   r   r   r   Úwrite_boolean$   s   zBinaryEncoder.write_booleanÚintegerc                 C   s\   |d> |d? A }|d@ dkr$|   t|d@ dB gƒ¡ |dL }|d@ dks|   t|gƒ¡ dS )	zIInteger and long values are written using variable-length zig-zag coding.é   é?   i€ÿÿÿr   é   é€   é   N)r   r   )r   r   Údatumr   r   r   Ú	write_int,   s   þzBinaryEncoder.write_intÚfc                 C   ó   |   t |¡¡ dS )zWrite a float as 4 bytes.N)r   r   Úpack©r   r    r   r   r   Úwrite_float4   ó   zBinaryEncoder.write_floatc                 C   r!   )zWrite a double as 8 bytes.N)r   r   r"   r#   r   r   r   Úwrite_double8   r%   zBinaryEncoder.write_doublec                 C   s   |   t|ƒ¡ |  |¡ dS )z@Bytes are encoded as a long followed by that many bytes of data.N)r   Úlenr   r   r   r   r   Úwrite_bytes<   s   zBinaryEncoder.write_bytesÚsc                 C   s   |   | t¡¡ dS )zVEncode a string as a long followed by that many bytes of UTF-8 encoded character data.N)r(   Úencoder   )r   r)   r   r   r   Ú
write_utf8A   r%   zBinaryEncoder.write_utf8Úuuidc                 C   s,   t |jƒdkrtd|j›dƒ‚|  |j¡S )zæWrite UUID as a fixed[16].

        The uuid logical type represents a random generated universally unique identifier (UUID).
        An uuid logical type annotates an Avro string. The string has to conform with RFC-4122.
        é   z)Expected UUID to have 16 bytes, got: len(ú))r'   r   Ú
ValueErrorr   )r   r,   r   r   r   Ú
write_uuidE   s   zBinaryEncoder.write_uuidÚ_c                 C   s   dS )z7Nulls are written as 0 bytes in avro, so we do nothing.Nr   )r   r1   r   r   r   Úwrite_unknownO   s    zBinaryEncoder.write_unknown)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú__annotations__r   r   r   r   r   Úintr   Úfloatr$   r&   r(   Ústrr+   r   r0   r   r2   r   r   r   r   r      s   
 
r   N)Útypingr   r,   r   Úpyiceberg.avror   r   Úpyiceberg.ior   Úpyiceberg.typedefr   r   r   r   r   r   Ú<module>   s   