o
    2h                     @   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   L/var/www/html/chatgem/venv/lib/python3.10/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 )zxOffset provides access into the Table's vtable.

    Deprecated fields are ignored by checking the vtable's length.
        )r   Getr   SOffsetTFlagsVOffsetTFlags)r
   vtableOffsetvtable	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   String2   s
   zTable.Stringc                 C   sH   t |t j || j7 }|tt jj| j|7 }tt jj| j|}|S )zfVectorLen 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   	VectorLen:   s
   
zTable.VectorLenc                 C   s:   t |t j || j7 }|| t j| }|t jj7 }|S )zjVector 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   VectorF   s
   
zTable.Vectorc                 C   sH   t |tu sJ 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   r   r   r	   r   r   r   )r
   t2r   r   r   r   UnionS   s
   
zTable.Unionc                 C   s&   t |t j |t|j| j|S )zVGet retrieves a value of the type specified by `flags`  at the

    given offset.
    )r   r   r	   py_typer   r   r   r   )r
   flagsr   r   r   r   r   _   s   z	Table.Getc                 C   sJ   t |t j |d urt || | |}|dkr|S | || j| S )Nr   )r   r   r   r   r   r   )r
   slotdvalidator_flagsr   r   r   r   GetSlotg   s   
zTable.GetSlotc                 C   s0   |  |}| |}t|}t|| j||S )zGetVectorAsNumpy 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.   p   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   r0   r   r   r   GetArrayAsNumpy|   s   
zTable.GetArrayAsNumpyc                 C   s6   t |t j t |t j | |}|dkr|S |S )zGetVOffsetTSlot 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.   r1   r2   r   r   r   r   r      s    	r   N) r   r   r   objectr   r   r   r   r   <module>   s   