Skip to content

Basic

packtype.utils.basic

clog2(x)

Calculate the ceiling of the base-2 logarithm of x.

Parameters:

Name Type Description Default
x int

The integer to calculate the logarithm of

required

Returns:

Type Description
int

The ceiling of the base-2 logarithm of x

get_doc(ptype)

Get the docstring of a Packtype definition

Parameters:

Name Type Description Default
ptype type[Base] | Base

The Packtype definition to inspect

required

Returns:

Type Description
str

The docstring of the Packtype definition

get_name(ptype)

Get the name of a Packtype definition

Parameters:

Name Type Description Default
ptype type[Base] | Base

The Packtype definition to inspect

required

Returns:

Type Description
str

The name of the Packtype definition

get_package(ptype)

Get the package a Packtype definition is attached to, if the type is not associated to a package then None will be returned

Parameters:

Name Type Description Default
ptype type[Base] | Base

The Packtype definition to inspect

required

Returns:

Type Description
type[Base] | None

The Package to which this type is attached

get_source(ptype)

Get the name of a Packtype definition

Parameters:

Name Type Description Default
ptype type[Base] | Base

The Packtype definition to inspect

required

Returns:

Type Description
tuple[str, int]

The source file and line number of the Packtype definition

get_width(ptype)

Get the width of a Packtype definition

Parameters:

Name Type Description Default
ptype type[PackedAssembly | Enum | NumericType | Union] | PackedAssembly | NumericType | Union

The Packtype definition to inspect

required

Returns:

Type Description
int

The width in bits of the Packtype definition

is_scalar(ptype)

Check if a Packtype definition is a scalar type

Parameters:

Name Type Description Default
ptype type[Base] | Base

The Packtype definition to check

required

Returns:

Type Description
bool

True if the definition is a scalar type, False otherwise

is_signed(ptype)

Check if a Packtype definition is signed

Parameters:

Name Type Description Default
ptype type[NumericType] | NumericType

The Packtype definition to check

required

Returns:

Type Description
bool

True if the definition is signed, False otherwise

pack(pinst)

Pack an instance of a Packtype definition into an integer

Parameters:

Name Type Description Default
pinst Base

The instance of the Packtype definition to pack

required

Returns:

Type Description
int

The packed value as an integer

unpack(ptype, value)

Unpack a value into a Packtype definition

Parameters:

Name Type Description Default
ptype type[Base]

The Packtype definition to unpack into

required
value int

The value to unpack

required

Returns:

Type Description
Base

An instance of the Packtype definition with the unpacked value