Skip to content

Instantly share code, notes, and snippets.

@timsneath
Last active January 22, 2021 22:57
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timsneath/983764458690f89a5c8231b4ff2e2e64 to your computer and use it in GitHub Desktop.
Save timsneath/983764458690f89a5c8231b4ff2e2e64 to your computer and use it in GitHub Desktop.
// struct XrApplicationInfo {
// char applicationName[128]; // 128 bytes
// uint32_t applicationVersion; // 4 bytes
// char engineName[128]; // 128 bytes
// uint32_t engineVersion; // 4 bytes
// XrVersion apiVersion; // assume this is a uint64_t, i.e. 8 bytes
// };
class XrApplicationInfo extends Struct {
Pointer<Utf8> get applicationName => addressOf.cast<Utf8>();
int get ApplicationVersion =>
addressOf.cast<Uint8>().elementAt(128).cast<Uint32>().value;
Pointer<Utf8> get engineName => addressOf.cast<Utf8>().elementAt(128 + 4);
int get engineVersion =>
addressOf.cast<Uint8>().elementAt(128 + 4 + 128).cast<Uint32>().value;
int get apiVersion =>
addressOf.cast<Uint8>().elementAt(128 + 4 + 128 + 4).cast<Uint64>().value;
factory XrApplicationInfo.allocate() {
final structSize = 128 + 4 + 128 + 4 + 8;
final ptr = allocate<Uint8>(count: structSize);
for (var idx = 0; idx < structSize; idx++) {
ptr.elementAt(idx).value = 0;
}
return ptr.cast<XrApplicationInfo>().ref;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment