Base datatype

class pygarmin.datatype.DataType

Bases: object

Base datatype.

Datatypes must derive from the DataType base class. It uses the rawutil module to pack and unpack binary data. Each subclass must define a _fields attribute. _fields must be a list of 2-tuples, containing a field name and a field type. The field type must be a rawutil format character.

data = b''

binary data

epoch = datetime.datetime(1989, 12, 31, 0, 0, tzinfo=datetime.timezone.utc)

datetime of 12:00 AM December 31, 1989 UTC

re_upcase_digit = '[A-Z0-9]'

regex matching upper-case letters and numbers

re_upcase_digit_space = '[A-Z0-9 ]'

regex matching upper-case letters, numbers and space

re_upcase_digit_space_hyphen = '[A-Z0-9 _]'

regex matching upper-case letters, numbers, space and hyphen

re_ascii = '[\\x20-\\x7E]'

regex matching any ASCII character

classmethod get_keys()

Return the list of keys of the structure fields.

Returns

list of _field keys

Return type

list[str]

classmethod get_format()

Return the format string of the structure fields.

Returns

rawutil format string

Return type

str

classmethod get_struct()

Return a rawutil.Struct object with the structure fields.

Returns

struct object

Return type

rawutil.Struct

get_dict()

Return a dictionary with the datatype properties.

Returns

dictionary with datatype properties

Return type

dict

get_values()

Return the list of values of the datatype properties.

Returns

list of values

Return type

list

get_data()

Return the packed data.

Returns

packed data

Return type

bytes

unpack(data)

Unpack binary data according to the structure.

Parameters

data (bytes) – binary data

Returns

None

pack()

Pack the datatype properties in the format defined by the structure.

is_valid_charset(pattern, bytes)

Return whether the bytes string matches the regex pattern.

Parameters
  • pattern (str) – regular expression

  • bytes (bytes) – bytestring

Returns

True if bytes matches pattern, otherwise False

Return type

bool