Skip to content

arg ๐Ÿ”—

Interface to the struct vaccel_arg C object.

Arg ๐Ÿ”—

Arg(data: Any, type_: ArgType = RAW, custom_type_id: int = 0)

Bases: CType

Wrapper for the vaccel_arg C struct.

Manages the creation and initialization of a C struct vaccel_arg object and provides access to it through Python properties.

Inherits

CType: Abstract base class for defining C data types.

Parameters:

Name Type Description Default

data ๐Ÿ”—

Any

The input data to be passed to the C struct.

required

type_ ๐Ÿ”—

ArgType

The type of the arg.

RAW

custom_type_id ๐Ÿ”—

int

The user-specified type ID of the arg if the type is ArgType.CUSTOM.

0
Source code in vaccel/arg.py
def __init__(
    self, data: Any, type_: ArgType = ArgType.RAW, custom_type_id: int = 0
):
    """Initializes a new `Arg` object.

    Args:
        data: The input data to be passed to the C struct.
        type_: The type of the arg.
        custom_type_id: The user-specified type ID of the arg if the type is
            `ArgType.CUSTOM`.
    """
    if ArgType != ArgType.RAW and ArgTypeMapper.is_numeric(type_):
        precision = ArgTypeMapper.type_to_c_type(type_)
        self._c_data = CAny(data, precision=precision)
    else:
        self._c_data = CAny(data)
    self._c_obj_ptr = ffi.NULL
    self._type = type_
    self._custom_type_id = custom_type_id
    super().__init__()

buf property ๐Ÿ”—

buf: Any

Returns the buffer value from the underlying C struct.

Retrieves the buffer (buf) stored in the struct vaccel_arg C object. If the original data type is a Python built-in type, the buffer is converted back to that type.

Returns:

Type Description
Any

The buffer value from the C struct vaccel_arg.

c_size property ๐Ÿ”—

c_size: int

Returns the size of the object in bytes.

type property ๐Ÿ”—

type: ArgType

The arg type.

Returns:

Type Description
ArgType

The type of the arg.

value property ๐Ÿ”—

value: CData

Returns the value of the underlying C struct.

Returns:

Type Description
CData

The dereferenced 'struct vaccel_arg`

ArgTypeMapper ๐Ÿ”—

Utility for mapping between ArgType and other common types.

is_numeric classmethod ๐Ÿ”—

is_numeric(arg_type: ArgType) -> bool

Checks if the arg type represents a numeric type.

Parameters:

Name Type Description Default

arg_type ๐Ÿ”—

ArgType

The arg type value.

required

Returns:

Type Description
bool

True if the arg type represents a numeric type.

Source code in vaccel/arg.py
@classmethod
def is_numeric(cls, arg_type: ArgType) -> bool:
    """Checks if the arg type represents a numeric type.

    Args:
        arg_type: The arg type value.

    Returns:
        True if the arg type represents a numeric type.
    """
    return arg_type in cls._NUMERIC_TYPES

type_to_c_type classmethod ๐Ÿ”—

type_to_c_type(arg_type: ArgType) -> str

Converts an ArgType to a C type string.

Parameters:

Name Type Description Default

arg_type ๐Ÿ”—

ArgType

The arg type value.

required

Returns:

Type Description
str

A corresponding C type as a string (e.g., "float", "int64_t").

Raises:

Type Description
ValueError

If the arg_type value is not supported.

Source code in vaccel/arg.py
@classmethod
def type_to_c_type(cls, arg_type: ArgType) -> str:
    """Converts an `ArgType` to a C type string.

    Args:
        arg_type: The arg type value.

    Returns:
        A corresponding C type as a string (e.g., "float", "int64_t").

    Raises:
        ValueError: If the `arg_type` value is not supported.
    """
    if arg_type not in cls._ARG_TYPE_TO_C:
        supported = ", ".join(str(d) for d in cls._ARG_TYPE_TO_C)
        msg = f"Unsupported ArgType: {arg_type}. Supported: {supported}"
        raise ValueError(msg)
    return cls._ARG_TYPE_TO_C[arg_type]