From 8e231845ef38e04a8bd8b229ae67cd94aab48c86 Mon Sep 17 00:00:00 2001 From: Pragyansh Chaturvedi Date: Sun, 21 Sep 2025 03:01:13 +0530 Subject: [PATCH] Add struct example and decorator --- examples/execve5.py | 9 ++++++++- pythonbpf/decorators.py | 8 ++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/examples/execve5.py b/examples/execve5.py index 45d51b0..0aff573 100644 --- a/examples/execve5.py +++ b/examples/execve5.py @@ -1,9 +1,16 @@ -from pythonbpf import bpf, map, section, bpfglobal, compile +from pythonbpf import bpf, map, struct, section, bpfglobal, compile from pythonbpf.helpers import ktime, pid from pythonbpf.maps import PerfEventArray from ctypes import c_void_p, c_int64, c_int32, c_uint64 + +@bpf +@struct +class data_t: + pid: c_uint64 + ts: c_uint64 + @bpf @map def events() -> PerfEventArray: diff --git a/pythonbpf/decorators.py b/pythonbpf/decorators.py index 6bf3b24..7afa8c6 100644 --- a/pythonbpf/decorators.py +++ b/pythonbpf/decorators.py @@ -9,11 +9,19 @@ def bpfglobal(func): func._is_bpfglobal = True return func + def map(func): """Decorator to mark a function as a BPF map.""" func._is_map = True return func + +def struct(cls): + """Decorator to mark a class as a BPF struct.""" + cls._is_struct = True + return cls + + def section(name: str): def wrapper(fn): fn._section = name