Files
pylibbpf/__init__.py
2025-10-20 02:58:22 +05:30

42 lines
1.0 KiB
Python

import logging
from .pylibbpf import (
BpfObject as _BpfObject, # C++ object (internal)
BpfProgram,
BpfMap,
PerfEventArray,
StructParser,
BpfException,
)
from .wrappers import BpfObjectWrapper
from .ir_to_ctypes import convert_structs_to_ctypes, is_pythonbpf_structs
logger = logging.getLogger(__name__)
class BpfObject(BpfObjectWrapper):
"""BpfObject with automatic struct conversion"""
def __init__(self, object_path: str, structs=None):
"""Create a BPF object"""
if structs is None:
structs = {}
elif is_pythonbpf_structs(structs):
logger.info(f"Auto-converting {len(structs)} PythonBPF structs to ctypes")
structs = convert_structs_to_ctypes(structs)
# Create C++ BpfObject with converted structs
cpp_obj = _BpfObject(object_path, structs)
# Initialize wrapper
super().__init__(cpp_obj)
__all__ = [
"BpfObject",
"BpfProgram",
"BpfMap",
"PerfEventArray",
"StructParser",
"BpfException",
]