-
Notifications
You must be signed in to change notification settings - Fork 1
Bindings
Xinxin Mei edited this page Sep 5, 2024
·
10 revisions
The Python bindings for E2SAR are implemented with pybind11. You can find the source code in the 'src/pybind' directory.
The pybind11 module, named e2sar_py, is built alongside the C++ library and is named e2sar_py.cpython-<platform>.so based on the platform. To use the module, add its path to the Python environment:
# Add the path of the pybind module
import sys
sys.path.append('/path/to/e2sar_py.cpython-<platform>.so')
# Import the module
import e2sar_py
# Your Python code hereWe provide Jupyter notebooks in the 'scripts/notebooks/pybind11_examples' directory to demonstrate Python usage.
-
example_DataPlane.ipynb: Shows how to use the Python
SegmenterandReassemblerclasses to send and receive messages without a real FPGA control plane. -
example_EjfatURI.ipynb: Demonstrates how to create Python
EjfatURIclasses and handle cases where C++ functions returnresult<T>types.
We list the C++ e2sar classes that are bound to Python and explain how their input, output, and return types are mapped to Python equivalents.
The C++ e2sar::EjfatURI class is mapped to the Python class e2sar_py.EjfatURI with its public methods listed in the table below.
Click to expand
| Members | C++ `e2sar::EjfatURI` class | Python `e2sar_py.EjfatURI` class |
Notes |
|---|---|---|---|
| Enum class | EjfatURI::TokenType::admin EjfatURI::TokenType::instance EjfatURI::TokenType::session |
e2sar_py.EjfatURI.TokenType.admin e2sar_py.EjfatURI.TokenType.instance e2sar_py.EjfatURI.TokenType.session |
|
| Constructor | EjfatURI(const std::string &, TokenType, bool)` | e2sar_py.EjfatURI(uri:str, tt:e2sar_py.EjfatURI.TokenType) | The same default parameters. |
| Get/Set LB name | const std::string get_lbName() void set_lbName(const std::string &)const std::string get_lbName() |
e2sar_py.EjfatURI.lb_name | The C++ get and set methods are mapped to the `lb_name` attribute of type string in the Python `EjfatURI` class. |
| Get/Set LB ID | const std::string get_lbId() void set_lbId(const std::string &) |
e2sar_py.EjfatURI.lb_id | |
| Get/Set session ID | const std::string get_sessionId() void set_sessionId(const std::string &) |
e2sar_py.EjfatURI.session_id |