Expose classes and perform struct conversion in __init__

This commit is contained in:
Pragyansh Chaturvedi
2025-10-20 02:58:22 +05:30
parent 30021e8520
commit 23cafa4d7b

41
__init__.py Normal file
View File

@ -0,0 +1,41 @@
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",
]