# Type System

This page describes the range of possible values that can be represented by a GVariant instance.

GVariant has a strong dynamic type system. Every GVariant instance has a type.

The possible types follow. This list is an exhaustive recursive definition of valid types (ie: no junk, no confusion).

- boolean
- byte
- signed and unsigned 16, 32 and 64 bit integer
- double (and maybe single) precision floating point
- arbitrary precision integer
- string
- type string
- object path string
- variant
array (or "list") of

*x*(where*x*is any valid type)*n*-tuple (or*structure*) composed of any*n*types- dictionary entry (essentially a key-value pair)
maybe

*x*(where*x*is any valid type)a tagged union over any

*n*types

## Type Strings

Each type has an associated type string that describes it.

A property of type strings is that, given a pointer to the start of a type string embedded in a larger string, the length of the type string can be determined. This allows for construction of structure and tagged union types without requiring a separator between the individual subtypes. It also allows unambiguous construction of maybe and array type strings with a simple prefix.

The following is a list of all of the valid type strings.

### Base Types

`b`- boolean`y`- byte`n`- signed 16 bit integer`q`- unsigned 16 bit integer`i`- signed 32 bit integer`u`- unsigned 32 bit integer`x`- signed 64 bit integer`t`- unsigned 64 bit integer`f`- single precision floating point (maybe)`d`- double precision floating point`s`- string`o`- object path`g`- type string`v`- variant

### Type Constructors

In the following list, a single underscore `_` represents any valid type string. A dash `-` represents any valid one-character type string except for `v`. An underscore followed by a plus `_+` indicates the concatenation of one or more valid type strings.

`a_`- array (or list)`m_`- maybe`(_+)`- n-tuple (or structure)`[_+]`- tagged union`{-_}`- dictionary entry

## Valid Values

### Boolean

A boolean value may be either false or true.

### Byte

A byte may be any value between 0 and 255 inclusive.

### (Un)signed 16/32/64bit Integers

A 16bit signed integer ranges from -32768 to 32767 inclusive. A 16bit unsigned integer ranges from 0 to 65535 inclusive.

A 32bit signed integer ranges from -2147483648 to 2147483647 inclusive. A 32bit unsigned integer ranges from 0 to 4294967296 inclusive.

A 64bit signed integer ranges from -9223372036854775808 to 9223372036854775807 inclusive. A 64bit unsigned integer ranges from 0 to 18446744073709551615 inclusive.

### Floating Point Types

Floating point types range over the values specified in IEEE754, including infinities, positive and negative zeros and multiple different representations of NaN.

### String

The string type ranges over valid utf-8 encodings of any length. Strings may not contain zero bytes.

### Type String

The type string type ranges over all valid type strings (as described in the "Type Strings" section of this document).

### Object Path

The object path type ranges over all valid DBus object paths. It consists of a number of segments, separated by '/' delimiters. Each segment may only contain the ASCII characters A-Z, a-z, 0-9 and _. The first segment must be empty and no other segment may be empty.

### Variant

The value of a variant type is a pair of (type string, value). The type string may be any valid type string and the value may be any valid value of the type corresponding to that type string.

### Array

The type "Array of `_``" ranges over `*range*(`_``)``*`` (where ``*`` is the Kleene closure operator). `

### Maybe

The type "Maybe `_``" ranges over the following possible values: `

- Nothing
Just

*x*(where*x*is a member of the range of`_``)`

### Structure

The type "Structure of *t*`0``, `*t*`1``, `*t*`2``... `*t*`n``" ranges over the cross product of the ranges of the types `*t*`0``, `*t*`1``, `*t*`2``... `*t*`n``. `

### Tagged Union

The type "Tagged union of *t*`0``, `*t*`1``, `*t*`2``... `*t*`n``" ranges over the disjoint union of the ranges of the types `*t*`0``, `*t*`1``, `*t*`2``... `*t*`n``. `

### Dictionary Entry

The type "Dictionary Entry from *k* to *v*" ranges over the cross product of *k* × *v*.

Note that *k* is constrained to be a base type (and not a variant).