Haiku API Bindings
TypeConstants
Not logged in

Documentation | SupportKit | TypeConstants

SYNOPSIS

Perl

use HaikuR1::TypeConstants qw(B_STRING_TYPE B_MESSAGE_TYPE)

Python

from HaikuR1.SupportKit import B_STRING_TYPE, B_MESSAGE_TYPE

Python

Note that TypeConstants does not actually exist as a submodule; instead, the constants are imported from SupportKit.

DESCRIPTION

Contains the type constants and some utility functions

For more information on type constants, see the Be Book descriptions.

FUNCTIONS

These utility functions are not part of the Haiku R1 API; they are for convenience.

guess_type

Given a native value, tries to guess the type.

It uses a relatively simple guessing algorithm:

For integers, it returns the highest range it fits into, in the order B_INT32_TYPE B_UINT32_TYPE B_INT64_TYPE B_UINT64_TYPE.

For floating point numbers, it returns B_DOUBLE_TYPE.

For booleans, it returns B_BOOL_TYPE.

Perl

Since Perl does not have a distinct boolean type, the Perl version will never return B_BOOL_TYPE.

For a string that does not contain embedded bytes, it returns B_STRING_TYPE.

For a 1-dimensional native list, it returns B_STRING_LIST_TYPE; for any other native list, it returns B_PATTERN_TYPE.

For a B_CMAP8 Bitmap object that is 32x32 or 16x16, it returns B_LARGE_ICON_TYPE or B_MINI_ICON_TYPE, respectively.

For several object classes, it returns the appropriate type:

For anything else, it returns B_RAW_TYPE.

Perl

my $type = guess_type($value);

Python

type = guess_type(value)

For anything else, it returns B_RAW_TYPE.

value_to_typed_data

For supported types, it converts the native value into a string of bytes.

Returns two values: the byte string and the type that was used to convert the value.

Perl

my ($data, $type) = value_to_typed_data($value, $type);

Python

retval = value_to_typed_data(value, type);

typed_data_to_value

For supported types, it converts a string of bytes into a native value.

Perl

my $value = value_to_typed_data($data, $type);

Python

value = value_to_typed_data(data, type);

CONSTANTS

Basic types

Perl

use HaikuR1::TypeConstants qw(:types)

Python

Python does not support export tags.

URL types

Automatic conversion is not supported for these types.

Perl

use HaikuR1::TypeConstants qw(:url_types)

Python

Python does not support export tags.