Source code for bluebase.pf.type

from typing import Self

from pathlib import Path
from dataclasses import dataclass


__all__ = (
    'PfPageId',
    'PfPageData',
    'PfFileId',
    'PfEntryId',
)


[docs] class PfPageId(int): """ An ID for a page. """
[docs] @classmethod def first(cls) -> Self: """ Return the first page ID. """ return cls(0)
[docs] def succ(self) -> Self: """ Return the next page ID. """ return type(self)(int(self) + 1)
[docs] class PfPageData(bytearray): """ A data buffer for a page. """
[docs] @classmethod def new(cls, size: int) -> Self: """ Create a new data buffer for a page. """ return cls(size)
[docs] class PfFileId(Path): """ An ID for a file. """
[docs] @classmethod def new(cls, path: Path | str) -> Self: """ Create a new file ID. """ return cls(Path(path).resolve())
[docs] @dataclass(frozen=True, slots=True) class PfEntryId: """ An ID for an entry in the page cache. Attributes: fid: ID of the file. pid: ID of the page. """ fid: PfFileId pid: PfPageId