U
    L?h2                     @   s,   d dl mZ d dl mZ G dd deZdS )   )encode)number_typesc                   @   st   e Zd ZdZdZdd Zdd Zdd Zd	d
 Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd ZdS )TablezTable wraps a byte slice and provides read access to its data.

    The variable `Pos` indicates the root of the FlatBuffers object therein.)BytesPosc                 C   s   t |t j || _|| _d S )N)Nenforce_numberUOffsetTFlagsr   r   )selfbufpos r   C/var/www/html/venv/lib/python3.8/site-packages/flatbuffers/table.py__init__   s    zTable.__init__c                 C   sB   | j | tj| j  }| tj|}||k r>| tj|| S dS )zwOffset provides access into the Table's vtable.

        Deprecated fields are ignored by checking the vtable's length.    )r   Getr   ZSOffsetTFlagsVOffsetTFlags)r
   ZvtableOffsetZvtableZ	vtableEndr   r   r   Offset    s
    zTable.Offsetc                 C   s&   t |t j |tt jj| j| S )z:Indirect retrieves the relative offset stored at `offset`.)r   r   r	   r   r   packer_typer   )r
   offr   r   r   Indirect+   s    zTable.Indirectc                 C   s\   t |t j |tt jj| j|7 }|t jj }tt jj| j|}t| j|||  S )z<String gets a string from data stored inside the flatbuffer.)	r   r   r	   r   r   r   r   	bytewidthbytes)r
   r   startlengthr   r   r   String0   s
    zTable.Stringc                 C   sH   t |t j || j7 }|tt jj| j|7 }tt jj| j|}|S )zgVectorLen retrieves the length of the vector whose offset is stored
           at "off" in this object.)r   r   r	   r   r   r   r   r   )r
   r   retr   r   r   	VectorLen8   s
    
zTable.VectorLenc                 C   s:   t |t j || j7 }|| t j| }|t jj7 }|S )zkVector retrieves the start of data of the vector whose offset is
           stored at "off" in this object.)r   r   r	   r   r   r   )r
   r   xr   r   r   VectorB   s
    
zTable.Vectorc                 C   sH   t |tkstt|tj || j7 }|| tj| |_| j|_dS )z^Union initializes any Table-derived type to point to the union at
           the given offset.N)	typer   AssertionErrorr   r   r	   r   r   r   )r
   t2r   r   r   r   UnionM   s
    
zTable.Unionc                 C   s&   t |t j |t|j| j|S )zf
        Get retrieves a value of the type specified by `flags`  at the
        given offset.
        )r   r   r	   Zpy_typer   r   r   r   )r
   flagsr   r   r   r   r   W   s    z	Table.Getc                 C   sJ   t |t j |d k	r"t || | |}|dkr8|S | || j| S )Nr   )r   r   r   r   r   r   )r
   slotdZvalidator_flagsr   r   r   r   GetSlot_   s    
zTable.GetSlotc                 C   s0   |  |}| |}t|}t|| j||S )z
        GetVectorAsNumpy returns the vector that starts at `Vector(off)`
        as a numpy array with the type specified by `flags`. The array is
        a `view` into Bytes, so modifying the returned array will
        modify Bytes in place.
        )r   r   r   to_numpy_typer   GetVectorAsNumpyr   )r
   r$   r   offsetr   numpy_dtyper   r   r   r)   h   s    


zTable.GetVectorAsNumpyc                 C   s   t |}t|| j||S )a  
        GetArrayAsNumpy returns the array with fixed width that starts at `Vector(offset)`
        with length `length` as a numpy array with the type specified by `flags`. The
        array is a `view` into Bytes so modifying the returned will modify Bytes in place.
        )r   r(   r   r)   r   )r
   r$   r   r   r+   r   r   r   GetArrayAsNumpyt   s    
zTable.GetArrayAsNumpyc                 C   s6   t |t j t |t j | |}|dkr2|S |S )z
        GetVOffsetTSlot retrieves the VOffsetT that the given vtable location
        points to. If the vtable value is zero, the default value `d`
        will be returned.
        r   )r   r   r   r   )r
   r%   r&   r   r   r   r   GetVOffsetTSlot}   s    
zTable.GetVOffsetTSlotN)__name__
__module____qualname____doc__	__slots__r   r   r   r   r   r   r#   r   r'   r)   r,   r-   r   r   r   r   r      s   

		r   N) r   r   r   objectr   r   r   r   r   <module>   s   