Libre Gaming Infrastructure

Preface

This document specifies the data types and syntax for representing them.

Comments

Comments begin with /* and end with */.

Scalar values

byte

Specifies a single byte that is 8 bit wide with no particular interpretation of the contents. This is an opaque data type.

uint8_t
uint16_t
uint32_t
uint64_t

Specifies an unsigned big endian integer that is respectevily 8, 16, 32 or 64 bit wide.

int8_t
int16_t
int32_t
int64_t

Specifies a singed big endian two’s complement integer that is respectevily 8, 16, 32 or 64 bit wide.

float32
float64

Specifies, respectively, binary32 or binary64 floating point number as described in IEEE 754.

enum Foo : T
{
	First = 0,
	Second = 1
};

Specifies an enumeration type which is implemented using type T and can only hold the provided values. The values are prepended with the enumeration name and double colon. For example:

enum Color : uint8_t
{
	Red = 0,
	Green = 1,
	Blue = 2
};

Color c1 = Color::Red;

Arrays

T foo[N]

Specifies an array foo of N elements of type T which occur consecutively in a stream. The total size of the array in bytes is (size of T) * N. For example:

uint16_t foo[4]

Specifies an array foo of 4 elements of type uint16_t. The total size of the array in bytes is 8.

T foo[floor ... ceiling]

Specifies an array foo with dynamic size which must be between the floor and ceiling. The size of the array precedes the contents in a stream and the type of the size if the smallest unsigned type that can represent ceiling. For example, if the ceiling is 100, the type of the size is uint8_t, if the ceiling is 1000, the type of the size is uint16_t.

T foo[implicit]

Specifies an array foo with dynamic size that occupies the rest of the stream. The size is not prepended and the program should continue reading data until end of stream is reached.

Structs

struct Foo
{
	T1 member1;
	T2 member2;
};

Specifies a structure where element of type T1 is followed by element of type T2 without any padding between them. The total size of the structure is a sum of the sizes of its elements.

Variants

Sometimes the layout of the stream is determined by previous data occuring at runtime.

enum Color : uint8_t
{
	Red = 0,
	Green = 1,
	Blue = 2
};

struct ColorWithStuff
{
	Color color;
	switch (color)
	{
		case Color::Red:
		{
			uint8_t stuff;
		}
		case Color::Green:
		{
			uint16_t stuff;
		}
		case Color::Blue:
		{
			byte stuff[32];
		}
	}
};

In this example Color field goes first and then, depending on its value, different fields follow.