python: capi: add nla_put() function to python capi
Adding nla_put() to the capi using a typemap on the input parameter which needs to be either a str or bytearray. Otherwise a SWIG exception with be thrown. Signed-off-by: Arend van Spriel <aspriel@gmail.com>
This commit is contained in:
parent
ff6467135e
commit
36f4adfa81
1 changed files with 14 additions and 0 deletions
|
@ -17,6 +17,7 @@
|
|||
%include <stdint.i>
|
||||
%include <cstring.i>
|
||||
%include <cpointer.i>
|
||||
%include <exception.i>
|
||||
|
||||
%inline %{
|
||||
struct nl_dump_params *alloc_dump_params(void)
|
||||
|
@ -812,6 +813,19 @@ extern void *nla_data(struct nlattr *);
|
|||
%typemap(out) void *;
|
||||
extern int nla_type(const struct nlattr *);
|
||||
|
||||
%typemap(in) (int, const void *) {
|
||||
$1 = Py_SIZE($input);
|
||||
if (PyByteArray_Check($input)) {
|
||||
$2 = ($2_ltype)PyByteArray_AsString($input);
|
||||
} else if (PyString_Check($input)) {
|
||||
$2 = ($2_ltype)PyString_AsString($input);
|
||||
} else
|
||||
SWIG_exception(SWIG_TypeError,
|
||||
"pointer must be bytearray or string.");
|
||||
}
|
||||
extern int nla_put(struct nl_msg *, int, int, const void *);
|
||||
%typemap(in) const void *;
|
||||
|
||||
/* Integer attribute */
|
||||
extern uint8_t nla_get_u8(struct nlattr *);
|
||||
extern int nla_put_u8(struct nl_msg *, int, uint8_t);
|
||||
|
|
Loading…
Add table
Reference in a new issue