from __future__ import annotations
from typing import Any, ClassVar, overload, Iterable, Iterator, SupportsIndex, Union

_TibsLike = Union["Tibs", "Mutibs", str, bytes, bytearray, memoryview, Iterable[Any]]
_DtypeLike = Union["Dtype", str]


class Endianness:
    Unspecified: ClassVar[Endianness]
    Big: ClassVar[Endianness]
    Little: ClassVar[Endianness]


class BitOrder:
    Msb0: ClassVar[BitOrder]
    Lsb0: ClassVar[BitOrder]


class Codec:
    Auto: ClassVar[Codec]
    Raw: ClassVar[Codec]
    Rice: ClassVar[Codec]
    Zstd: ClassVar[Codec]


class DtypeKind:
    Uint: ClassVar[DtypeKind]
    Int: ClassVar[DtypeKind]
    Float: ClassVar[DtypeKind]
    Bytes: ClassVar[DtypeKind]
    Bin: ClassVar[DtypeKind]
    Oct: ClassVar[DtypeKind]
    Hex: ClassVar[DtypeKind]


class Dtype:
    def __init__(self, spec: str, /) -> None: ...

    @classmethod
    def from_params(
            cls,
            kind: DtypeKind,
            length: int,
            byte_order: Endianness = Endianness.Unspecified
    ) -> Dtype: ...

    @property
    def kind(self) -> DtypeKind: ...

    @property
    def length(self) -> int: ...

    @property
    def byte_order(self) -> Endianness: ...


class View:
    def __init__(
            self,
            source: Tibs | Mutibs,
            byte_order: Endianness = Endianness.Unspecified,
            bit_order: BitOrder = BitOrder.Msb0
    ) -> None: ...

    @classmethod
    def from_indices(
            cls,
            source: Tibs | Mutibs,
            indices: Iterable[int],
            byte_order: Endianness = Endianness.Unspecified,
            bit_order: BitOrder = BitOrder.Msb0
    ) -> View: ...

    def view(
            self,
            byte_order: Endianness | None = None,
            bit_order: BitOrder | None = None
    ) -> View: ...

    @property
    def le(self) -> View: ...

    @property
    def be(self) -> View: ...

    @property
    def lsb0(self) -> View: ...

    @property
    def msb0(self) -> View: ...

    @property
    def byte_order(self) -> Endianness: ...

    @property
    def bit_order(self) -> BitOrder: ...

    def to_u(self) -> int: ...

    def to_i(self) -> int: ...

    def to_f(self) -> float: ...

    def to_bin(self) -> str: ...

    def to_oct(self) -> str: ...

    def to_hex(self) -> str: ...

    def to_bytes(self) -> bytes: ...

    def __bytes__(self) -> bytes: ...

    def to_tibs(self) -> Tibs: ...

    def to_mutibs(self) -> Mutibs: ...

    @property
    def u(self) -> int: ...

    @property
    def i(self) -> int: ...

    @property
    def f(self) -> float: ...

    @property
    def bin(self) -> str: ...

    @property
    def oct(self) -> str: ...

    @property
    def hex(self) -> str: ...

    @property
    def bytes(self) -> bytes: ...

    def field(self, a: int, b: int) -> View: ...

    def __len__(self) -> int: ...

    def __eq__(self, other: Any) -> bool: ...

    def __repr__(self) -> str: ...


class MutableView:
    def __init__(
            self,
            source: Mutibs,
            byte_order: Endianness = Endianness.Unspecified,
            bit_order: BitOrder = BitOrder.Msb0
    ) -> None: ...

    @classmethod
    def from_indices(
            cls,
            source: Mutibs,
            indices: Iterable[int],
            byte_order: Endianness = Endianness.Unspecified,
            bit_order: BitOrder = BitOrder.Msb0
    ) -> MutableView: ...

    def view(
            self,
            byte_order: Endianness | None = None,
            bit_order: BitOrder | None = None
    ) -> MutableView: ...

    @property
    def le(self) -> MutableView: ...

    @property
    def be(self) -> MutableView: ...

    @property
    def lsb0(self) -> MutableView: ...

    @property
    def msb0(self) -> MutableView: ...

    @property
    def byte_order(self) -> Endianness: ...

    @property
    def bit_order(self) -> BitOrder: ...

    def to_u(self) -> int: ...

    def write_u(self, u: int, /) -> None: ...

    def to_i(self) -> int: ...

    def write_i(self, i: int, /) -> None: ...

    def to_f(self) -> float: ...

    def write_f(self, f: float, /) -> None: ...

    def to_bin(self) -> str: ...

    def write_bin(self, s: str, /) -> None: ...

    def to_oct(self) -> str: ...

    def write_oct(self, s: str, /) -> None: ...

    def to_hex(self) -> str: ...

    def write_hex(self, s: str, /) -> None: ...

    def to_bytes(self) -> bytes: ...

    def __bytes__(self) -> bytes: ...

    def write_bytes(self, data: bytes | bytearray | memoryview, /) -> None: ...

    def to_tibs(self) -> Tibs: ...

    def to_mutibs(self) -> Mutibs: ...

    @property
    def u(self) -> int: ...

    @u.setter
    def u(self, value: int) -> None: ...

    @property
    def i(self) -> int: ...

    @i.setter
    def i(self, value: int) -> None: ...

    @property
    def f(self) -> float: ...

    @f.setter
    def f(self, value: float) -> None: ...

    @property
    def bin(self) -> str: ...

    @bin.setter
    def bin(self, value: str) -> None: ...

    @property
    def oct(self) -> str: ...

    @oct.setter
    def oct(self, value: str) -> None: ...

    @property
    def hex(self) -> str: ...

    @hex.setter
    def hex(self, value: str) -> None: ...

    @property
    def bytes(self) -> bytes: ...

    @bytes.setter
    def bytes(self, value: bytes | bytearray | memoryview) -> None: ...

    def field(self, a: int, b: int) -> MutableView: ...

    def __len__(self) -> int: ...

    def __eq__(self, other: Any) -> bool: ...

    def __repr__(self) -> str: ...


class Tibs:
    def __init__(self, auto: _TibsLike | None = None) -> None: ...

    def to_raw_data(self) -> tuple[bytes, int, int]: ...

    def __str__(self) -> str: ...

    def __repr__(self) -> str: ...

    def view(
            self,
            byte_order: Endianness = Endianness.Unspecified,
            bit_order: BitOrder = BitOrder.Msb0
    ) -> View: ...

    @property
    def le(self) -> View: ...

    @property
    def be(self) -> View: ...

    @property
    def lsb0(self) -> View: ...

    @property
    def msb0(self) -> View: ...

    def field(self, a: int, b: int) -> View: ...

    def __iter__(self) -> Iterator[bool]: ...

    def chunks(self, chunk_size: int, count: int | None = None) -> list[Tibs]: ...

    def chunks_iter(self, chunk_size: int, count: int | None = None) -> Iterator[Tibs]: ...

    def rchunks_iter(self, chunk_size: int, count: int | None = None) -> Iterator[Tibs]: ...

    def __eq__(self, other: Any) -> bool: ...

    def __hash__(self) -> int: ...

    def find_all(self, b: _TibsLike, start: int | None = None, end: int | None = None, byte_aligned: bool = False) -> \
            list[int]: ...

    def find_all_iter(self, b: _TibsLike, start: int | None = None, end: int | None = None,
                      byte_aligned: bool = False) -> Iterator[int]: ...

    def rfind_all_iter(self, b: _TibsLike, start: int | None = None, end: int | None = None,
                  byte_aligned: bool = False) -> Iterator[int]: ...

    def __len__(self) -> int: ...

    @classmethod
    def from_zeros(cls, length: int, /) -> Tibs: ...

    @classmethod
    def from_ones(cls, length: int, /) -> Tibs: ...

    @classmethod
    def from_string(cls, s: str, /) -> Tibs: ...

    @classmethod
    def from_value(cls, dtype: _DtypeLike, value: Any, /) -> Tibs: ...

    @classmethod
    def from_values(cls, dtype: _DtypeLike, iterable: Iterable[Any], /) -> Tibs: ...

    def to_value(self, dtype: _DtypeLike, start: int | None = None, end: int | None = None) -> int | float | str | bytes: ...

    def to_values_iter(self, dtype: _DtypeLike, start: int | None = None, end: int | None = None) -> Iterator[int | float | str | bytes]: ...

    def to_values(self, dtype: _DtypeLike, start: int | None = None, end: int | None = None) -> list[int | float | str | bytes]: ...

    @classmethod
    def from_u(cls, u: int, /, length: int, byte_order: Endianness = Endianness.Unspecified) -> Tibs: ...

    def to_u(self, start: int | None = None, end: int | None = None) -> int: ...

    @property
    def u(self) -> int: ...

    @classmethod
    def from_i(cls, i: int, /, length: int, byte_order: Endianness = Endianness.Unspecified) -> Tibs: ...

    def to_i(self, start: int | None = None, end: int | None = None) -> int: ...

    @property
    def i(self) -> int: ...

    @classmethod
    def from_f(cls, f: float, /, length: int, byte_order: Endianness = Endianness.Unspecified) -> Tibs: ...

    def to_f(self, start: int | None = None, end: int | None = None) -> float: ...

    @property
    def f(self) -> float: ...

    @classmethod
    def from_bin(cls, s: str, /) -> Tibs: ...

    def to_bin(self, start: int | None = None, end: int | None = None) -> str: ...

    @property
    def bin(self) -> str: ...

    @classmethod
    def from_oct(cls, s: str, /) -> Tibs: ...

    def to_oct(self, start: int | None = None, end: int | None = None) -> str: ...

    @property
    def oct(self) -> str: ...

    @classmethod
    def from_hex(cls, s: str, /) -> Tibs: ...

    def to_hex(self, start: int | None = None, end: int | None = None) -> str: ...

    @property
    def hex(self) -> str: ...

    @classmethod
    def from_bytes(cls, data: bytes | bytearray | memoryview, /, offset: int | None = None,
                   length: int | None = None) -> Tibs: ...

    @classmethod
    def from_bools(cls, iterable: Iterable[Any], /) -> Tibs: ...

    @classmethod
    def from_random(cls, length: int, /, secure: bool = False, seed: bytes | bytearray | None = None) -> Tibs: ...

    @classmethod
    def from_joined(cls, iterable: Iterable[_TibsLike], /) -> Tibs: ...

    @classmethod
    def decode(cls, b: bytes, /) -> Tibs: ...

    def to_bytes(self, start: int | None = None, end: int | None = None) -> bytes: ...

    @property
    def bytes(self) -> bytes: ...

    def find(self, b: _TibsLike, start: int | None = None, end: int | None = None,
             byte_aligned: bool = False) -> int | None: ...

    def __contains__(self, b: _TibsLike) -> bool: ...

    def __copy__(self) -> Tibs: ...

    def rfind(self, b: _TibsLike, start: int | None = None, end: int | None = None,
              byte_aligned: bool = False) -> int | None: ...

    def starts_with(self, prefix: _TibsLike) -> bool: ...

    def ends_with(self, suffix: _TibsLike) -> bool: ...

    def count(self, value: Any, start: int | None = None, end: int | None = None) -> int: ...

    def all(self) -> bool: ...

    def any(self) -> bool: ...

    def set_at(self, pos: SupportsIndex | Iterable[SupportsIndex] | range) -> Tibs: ...

    def unset_at(self, pos: SupportsIndex | Iterable[SupportsIndex] | range) -> Tibs: ...

    def inverted(self, pos: SupportsIndex | Iterable[SupportsIndex] | None = None) -> Tibs: ...

    def inserted(self, pos: int, bs: _TibsLike, /) -> Tibs: ...

    def replaced(self, old: _TibsLike, new: _TibsLike, start: int | None = None, end: int | None = None,
                 count: int | None = None, byte_aligned: bool = False) -> Tibs: ...

    def rotated_left(self, n: int, start: int | None = None, end: int | None = None) -> Tibs: ...

    def rotated_right(self, n: int, start: int | None = None, end: int | None = None) -> Tibs: ...

    def reversed(self) -> Tibs: ...

    def byte_swapped(self, byte_length: int | None = None, start: int | None = None,
                     end: int | None = None) -> Tibs: ...

    def to_mutibs(self) -> Mutibs: ...

    def encode(self, codec: Codec = Codec.Auto) -> bytes: ...

    @overload
    def __getitem__(self, key: SupportsIndex) -> bool: ...

    @overload
    def __getitem__(self, key: slice) -> Tibs: ...

    def __getitem__(self, key: SupportsIndex | slice) -> bool | Tibs: ...

    def __lshift__(self, n: int) -> Tibs: ...

    def __rshift__(self, n: int) -> Tibs: ...

    def __add__(self, bs: _TibsLike) -> Tibs: ...

    def __radd__(self, bs: _TibsLike) -> Tibs: ...

    def __and__(self, bs: _TibsLike) -> Tibs: ...

    def __or__(self, bs: _TibsLike) -> Tibs: ...

    def __xor__(self, bs: _TibsLike) -> Tibs: ...

    def __rand__(self, bs: _TibsLike) -> Tibs: ...

    def __ror__(self, bs: _TibsLike) -> Tibs: ...

    def __rxor__(self, bs: _TibsLike) -> Tibs: ...

    def __invert__(self) -> Tibs: ...

    def __bytes__(self) -> bytes: ...

    def __mul__(self, n: int) -> Tibs: ...

    def __rmul__(self, n: int) -> Tibs: ...


class Mutibs:
    def __init__(self, auto: _TibsLike | None = None) -> None: ...

    def __eq__(self, other: Any) -> bool: ...

    def __str__(self) -> str: ...

    def __repr__(self) -> str: ...

    def view(
            self,
            byte_order: Endianness = Endianness.Unspecified,
            bit_order: BitOrder = BitOrder.Msb0
    ) -> MutableView: ...

    @property
    def le(self) -> MutableView: ...

    @property
    def be(self) -> MutableView: ...

    @property
    def lsb0(self) -> MutableView: ...

    @property
    def msb0(self) -> MutableView: ...

    def field(self, a: int, b: int) -> MutableView: ...

    @classmethod
    def from_string(cls, s: str, /) -> Mutibs: ...

    @classmethod
    def from_bin(cls, s: str, /) -> Mutibs: ...

    def to_bin(self, start: int | None = None, end: int | None = None) -> str: ...

    def write_bin(self, s: str, /) -> None: ...

    @property
    def bin(self) -> str: ...

    @bin.setter
    def bin(self, value: str) -> None: ...

    @classmethod
    def from_oct(cls, s: str, /) -> Mutibs: ...

    def to_oct(self, start: int | None = None, end: int | None = None) -> str: ...

    def write_oct(self, s: str, /) -> None: ...

    @property
    def oct(self) -> str: ...

    @oct.setter
    def oct(self, value: str) -> None: ...

    @classmethod
    def from_hex(cls, s: str, /) -> Mutibs: ...

    def to_hex(self, start: int | None = None, end: int | None = None) -> str: ...

    def write_hex(self, s: str, /) -> None: ...

    @property
    def hex(self) -> str: ...

    @hex.setter
    def hex(self, value: str) -> None: ...

    def to_bytes(self, start: int | None = None, end: int | None = None) -> bytes: ...

    def write_bytes(self, data: bytes | bytearray | memoryview, /) -> None: ...

    @property
    def bytes(self) -> bytes: ...

    @bytes.setter
    def bytes(self, value: bytes | bytearray | memoryview) -> None: ...

    def to_raw_data(self) -> tuple[bytes, int, int]: ...

    def as_raw_data(self) -> tuple[bytes, int, int]: ...

    @classmethod
    def from_u(cls, u: int, /, length: int, byte_order: Endianness = Endianness.Unspecified) -> Mutibs: ...

    def to_u(self, start: int | None = None, end: int | None = None) -> int: ...

    def write_u(self, u: int, /) -> None: ...

    @property
    def u(self) -> int: ...

    @u.setter
    def u(self, value: int) -> None: ...

    @classmethod
    def from_i(cls, i: int, /, length: int, byte_order: Endianness = Endianness.Unspecified) -> Mutibs: ...

    def to_i(self, start: int | None = None, end: int | None = None) -> int: ...

    def write_i(self, i: int, /) -> None: ...

    @property
    def i(self) -> int: ...

    @i.setter
    def i(self, value: int) -> None: ...

    @classmethod
    def from_f(cls, f: float, /, length: int, byte_order: Endianness = Endianness.Unspecified) -> Mutibs: ...

    def to_f(self, start: int | None = None, end: int | None = None) -> float: ...

    def write_f(self, f: float, /) -> None: ...

    @property
    def f(self) -> float: ...

    @f.setter
    def f(self, value: float) -> None: ...

    @classmethod
    def from_zeros(cls, length: int, /) -> Mutibs: ...

    @classmethod
    def from_ones(cls, length: int, /) -> Mutibs: ...

    @classmethod
    def from_bools(cls, iterable: Iterable[Any], /) -> Mutibs: ...

    @classmethod
    def from_random(cls, length: int, /, secure: bool = False, seed: bytes | bytearray | None = None) -> Mutibs: ...

    @classmethod
    def from_bytes(cls, data: bytes | bytearray | memoryview, /, offset: int | None = None,
                   length: int | None = None) -> Mutibs: ...

    @classmethod
    def from_joined(cls, iterable: Iterable[_TibsLike], /) -> Mutibs: ...

    def __len__(self) -> int: ...

    @overload
    def __getitem__(self, key: SupportsIndex) -> bool: ...

    @overload
    def __getitem__(self, key: slice) -> Mutibs: ...

    def __getitem__(self, key: SupportsIndex | slice) -> bool | Mutibs: ...

    @overload
    def __setitem__(self, key: SupportsIndex, value: Any) -> None: ...

    @overload
    def __setitem__(self, key: slice, value: _TibsLike) -> None: ...

    def __setitem__(self, key: SupportsIndex | slice, value: Any | _TibsLike) -> None: ...

    def __delitem__(self, key: SupportsIndex | slice) -> None: ...

    def chunks(self, chunk_size: int, count: int | None = None) -> list[Mutibs]: ...

    @classmethod
    def from_value(cls, dtype: _DtypeLike, value: Any, /) -> Mutibs: ...

    @classmethod
    def from_values(cls, dtype: _DtypeLike, iterable: Iterable[Any], /) -> Mutibs: ...

    def to_value(self, dtype: _DtypeLike, start: int | None = None, end: int | None = None) -> int | float | str | bytes: ...

    def to_values(self, dtype: _DtypeLike, start: int | None = None, end: int | None = None) -> list[int | float | str | bytes]: ...

    def starts_with(self, prefix: _TibsLike) -> bool: ...

    def __contains__(self, b: _TibsLike) -> bool: ...

    def ends_with(self, suffix: _TibsLike) -> bool: ...

    def find(self, b: _TibsLike, start: int | None = None, end: int | None = None,
             byte_aligned: bool = False) -> int | None: ...

    def find_all(self, b: _TibsLike, start: int | None = None, end: int | None = None,
                 byte_aligned: bool = False) -> list[int]: ...

    def __and__(self, bs: _TibsLike) -> Mutibs: ...

    def __or__(self, bs: _TibsLike) -> Mutibs: ...

    def __xor__(self, bs: _TibsLike) -> Mutibs: ...

    def __rand__(self, bs: _TibsLike) -> Mutibs: ...

    def __ror__(self, bs: _TibsLike) -> Mutibs: ...

    def __rxor__(self, bs: _TibsLike) -> Mutibs: ...

    def rotate_left(self, n: int, start: int | None = None, end: int | None = None) -> None: ...

    def rotate_right(self, n: int, start: int | None = None, end: int | None = None) -> None: ...

    def rotated_left(self, n: int, start: int | None = None, end: int | None = None) -> Mutibs: ...

    def rotated_right(self, n: int, start: int | None = None, end: int | None = None) -> Mutibs: ...

    @classmethod
    def decode(cls, b: bytes, /) -> Mutibs: ...

    def encode(self, codec: Codec = Codec.Auto) -> bytes: ...

    def set(self, pos: SupportsIndex | Iterable[SupportsIndex] | range) -> None: ...

    def unset(self, pos: SupportsIndex | Iterable[SupportsIndex] | range) -> None: ...

    def set_at(self, pos: SupportsIndex | Iterable[SupportsIndex] | range) -> Mutibs: ...

    def unset_at(self, pos: SupportsIndex | Iterable[SupportsIndex] | range) -> Mutibs: ...

    def count(self, value: Any, start: int | None = None, end: int | None = None) -> int: ...

    def all(self) -> bool: ...

    def any(self) -> bool: ...

    def rfind(self, b: _TibsLike, start: int | None = None, end: int | None = None,
              byte_aligned: bool = False) -> int | None: ...

    def invert(self, pos: SupportsIndex | Iterable[SupportsIndex] | None = None) -> None: ...

    def inverted(self, pos: SupportsIndex | Iterable[SupportsIndex] | None = None) -> Mutibs: ...

    def reverse(self) -> None: ...

    def reversed(self) -> Mutibs: ...

    def byte_swap(self, byte_length: int | None = None, start: int | None = None,
                  end: int | None = None) -> None: ...

    def byte_swapped(self, byte_length: int | None = None, start: int | None = None,
                     end: int | None = None) -> Mutibs: ...

    def __invert__(self) -> Mutibs: ...

    def __lshift__(self, n: int) -> Mutibs: ...

    def __rshift__(self, n: int) -> Mutibs: ...

    def __copy__(self) -> Mutibs: ...

    def to_tibs(self) -> Tibs: ...

    def as_tibs(self) -> Tibs: ...

    def clear(self) -> None: ...

    def capacity(self) -> int: ...

    def reserve(self, additional: int) -> None: ...

    def __add__(self, bs: _TibsLike) -> Mutibs: ...

    def __radd__(self, bs: _TibsLike) -> Mutibs: ...

    def __iadd__(self, bs: _TibsLike) -> Mutibs: ...

    def append(self, bit: bool | int) -> None: ...

    def pop(self) -> bool: ...

    def extend(self, bs: _TibsLike, /) -> None: ...

    def extend_left(self, bs: _TibsLike, /) -> None: ...

    def replace(self, old: _TibsLike, new: _TibsLike, start: int | None = None, end: int | None = None,
                count: int | None = None, byte_aligned: bool = False) -> int: ...

    def replaced(self, old: _TibsLike, new: _TibsLike, start: int | None = None, end: int | None = None,
                 count: int | None = None, byte_aligned: bool = False) -> Mutibs: ...

    def insert(self, pos: int, bs: _TibsLike, /) -> None: ...

    def inserted(self, pos: int, bs: _TibsLike, /) -> Mutibs: ...

    def __ilshift__(self, n: int) -> Mutibs: ...

    def __irshift__(self, n: int) -> Mutibs: ...

    def __bytes__(self) -> bytes: ...

    def __mul__(self, n: int) -> Mutibs: ...

    def __rmul__(self, n: int) -> Mutibs: ...

    def __iter__(self) -> None: ...

    def __iand__(self, bs: _TibsLike) -> Mutibs: ...

    def __ior__(self, bs: _TibsLike) -> Mutibs: ...

    def __ixor__(self, bs: _TibsLike) -> Mutibs: ...

    def __imul__(self, n: int) -> Mutibs: ...
