/*
 * This file is auto-generated, do not modify!
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

#include "config.h"

#include <glib.h>

#include "fu-steelseries-gamepad-struct.h"
#include "fu-byte-array.h"
#include "fu-bytes.h"
#include "fu-mem-private.h"
#include "fu-string.h"

#ifdef G_LOG_DOMAIN
  #undef G_LOG_DOMAIN
#endif
#define G_LOG_DOMAIN "FuStruct"

/**
 * fu_steelseries_gamepad_cmd_to_string:
 * @val: value, e.g. %FU_STEELSERIES_GAMEPAD_CMD_GET_VERSIONS
 *
 * Converts an enumerated value to a string.
 *
 * Returns: identifier string
 **/
static const gchar *
fu_steelseries_gamepad_cmd_to_string(FuSteelseriesGamepadCmd val)
{
    if (val == FU_STEELSERIES_GAMEPAD_CMD_ERASE)
        return "erase";
    if (val == FU_STEELSERIES_GAMEPAD_CMD_GET_VERSIONS)
        return "get-versions";
    if (val == FU_STEELSERIES_GAMEPAD_CMD_RESET)
        return "reset";
    if (val == FU_STEELSERIES_GAMEPAD_CMD_WORK_MODE)
        return "work-mode";
    if (val == FU_STEELSERIES_GAMEPAD_CMD_WRITE_CHUNK)
        return "write-chunk";
    if (val == FU_STEELSERIES_GAMEPAD_CMD_WRITE_CHECKSUM)
        return "write-checksum";
    return NULL;
}


/**
 * fu_steelseries_gamepad_checksum_status_to_string:
 * @val: value, e.g. %FU_STEELSERIES_GAMEPAD_CHECKSUM_STATUS_CORRECT
 *
 * Converts an enumerated value to a string.
 *
 * Returns: identifier string
 **/
static const gchar *
fu_steelseries_gamepad_checksum_status_to_string(FuSteelseriesGamepadChecksumStatus val)
{
    if (val == FU_STEELSERIES_GAMEPAD_CHECKSUM_STATUS_INCORRECT)
        return "incorrect";
    if (val == FU_STEELSERIES_GAMEPAD_CHECKSUM_STATUS_CORRECT)
        return "correct";
    return NULL;
}
/**
 * fu_struct_steelseries_gamepad_erase_req_ref: (skip):
 **/
FuStructSteelseriesGamepadEraseReq *
fu_struct_steelseries_gamepad_erase_req_ref(FuStructSteelseriesGamepadEraseReq *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_steelseries_gamepad_erase_req_unref: (skip):
 **/
void
fu_struct_steelseries_gamepad_erase_req_unref(FuStructSteelseriesGamepadEraseReq *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructSteelseriesGamepadEraseReq refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_steelseries_gamepad_erase_req_new_internal: (skip):
 **/
static FuStructSteelseriesGamepadEraseReq *
fu_struct_steelseries_gamepad_erase_req_new_internal(void)
{
    FuStructSteelseriesGamepadEraseReq *st = g_new0(FuStructSteelseriesGamepadEraseReq, 1);
    st->refcount = 1;
    return st;
}

/* getters */

/* setters */
/**
 * fu_struct_steelseries_gamepad_erase_req_set_cmd: (skip):
 **/
static void
fu_struct_steelseries_gamepad_erase_req_set_cmd(FuStructSteelseriesGamepadEraseReq *st, FuSteelseriesGamepadCmd value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[0] = value;
}
/**
 * fu_struct_steelseries_gamepad_erase_req_set_magic1: (skip):
 **/
static void
fu_struct_steelseries_gamepad_erase_req_set_magic1(FuStructSteelseriesGamepadEraseReq *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[1] = value;
}
/**
 * fu_struct_steelseries_gamepad_erase_req_set_magic2: (skip):
 **/
static void
fu_struct_steelseries_gamepad_erase_req_set_magic2(FuStructSteelseriesGamepadEraseReq *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[2] = value;
}
/**
 * fu_struct_steelseries_gamepad_erase_req_set_length: (skip):
 **/
void
fu_struct_steelseries_gamepad_erase_req_set_length(FuStructSteelseriesGamepadEraseReq *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 8, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_steelseries_gamepad_erase_req_set_magic3: (skip):
 **/
void
fu_struct_steelseries_gamepad_erase_req_set_magic3(FuStructSteelseriesGamepadEraseReq *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[13] = value;
}
/**
 * fu_struct_steelseries_gamepad_erase_req_new: (skip):
 **/
FuStructSteelseriesGamepadEraseReq *
fu_struct_steelseries_gamepad_erase_req_new(void)
{
    FuStructSteelseriesGamepadEraseReq *st = fu_struct_steelseries_gamepad_erase_req_new_internal();
    st->buf = g_byte_array_sized_new(14);
    fu_byte_array_set_size(st->buf, 14, 0x0);
    fu_struct_steelseries_gamepad_erase_req_set_cmd(st, FU_STEELSERIES_GAMEPAD_CMD_ERASE);
    fu_struct_steelseries_gamepad_erase_req_set_magic1(st, 0xAA);
    fu_struct_steelseries_gamepad_erase_req_set_magic2(st, 0x55);
    return st;
}
/**
 * fu_struct_steelseries_gamepad_get_versions_req_ref: (skip):
 **/
FuStructSteelseriesGamepadGetVersionsReq *
fu_struct_steelseries_gamepad_get_versions_req_ref(FuStructSteelseriesGamepadGetVersionsReq *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_steelseries_gamepad_get_versions_req_unref: (skip):
 **/
void
fu_struct_steelseries_gamepad_get_versions_req_unref(FuStructSteelseriesGamepadGetVersionsReq *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructSteelseriesGamepadGetVersionsReq refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_steelseries_gamepad_get_versions_req_new_internal: (skip):
 **/
static FuStructSteelseriesGamepadGetVersionsReq *
fu_struct_steelseries_gamepad_get_versions_req_new_internal(void)
{
    FuStructSteelseriesGamepadGetVersionsReq *st = g_new0(FuStructSteelseriesGamepadGetVersionsReq, 1);
    st->refcount = 1;
    return st;
}

/* getters */

/* setters */
/**
 * fu_struct_steelseries_gamepad_get_versions_req_set_cmd: (skip):
 **/
static void
fu_struct_steelseries_gamepad_get_versions_req_set_cmd(FuStructSteelseriesGamepadGetVersionsReq *st, FuSteelseriesGamepadCmd value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[0] = value;
}
/**
 * fu_struct_steelseries_gamepad_get_versions_req_new: (skip):
 **/
FuStructSteelseriesGamepadGetVersionsReq *
fu_struct_steelseries_gamepad_get_versions_req_new(void)
{
    FuStructSteelseriesGamepadGetVersionsReq *st = fu_struct_steelseries_gamepad_get_versions_req_new_internal();
    st->buf = g_byte_array_sized_new(1);
    fu_byte_array_set_size(st->buf, 1, 0x0);
    fu_struct_steelseries_gamepad_get_versions_req_set_cmd(st, FU_STEELSERIES_GAMEPAD_CMD_GET_VERSIONS);
    return st;
}
/**
 * fu_struct_steelseries_gamepad_get_versions_res_ref: (skip):
 **/
FuStructSteelseriesGamepadGetVersionsRes *
fu_struct_steelseries_gamepad_get_versions_res_ref(FuStructSteelseriesGamepadGetVersionsRes *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_steelseries_gamepad_get_versions_res_unref: (skip):
 **/
void
fu_struct_steelseries_gamepad_get_versions_res_unref(FuStructSteelseriesGamepadGetVersionsRes *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructSteelseriesGamepadGetVersionsRes refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_steelseries_gamepad_get_versions_res_new_internal: (skip):
 **/
static FuStructSteelseriesGamepadGetVersionsRes *
fu_struct_steelseries_gamepad_get_versions_res_new_internal(void)
{
    FuStructSteelseriesGamepadGetVersionsRes *st = g_new0(FuStructSteelseriesGamepadGetVersionsRes, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_steelseries_gamepad_get_versions_res_get_cmd: (skip):
 **/
static FuSteelseriesGamepadCmd
fu_struct_steelseries_gamepad_get_versions_res_get_cmd(const FuStructSteelseriesGamepadGetVersionsRes *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[0];
}
/**
 * fu_struct_steelseries_gamepad_get_versions_res_get_runtime_version: (skip):
 **/
guint16
fu_struct_steelseries_gamepad_get_versions_res_get_runtime_version(const FuStructSteelseriesGamepadGetVersionsRes *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 1, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_steelseries_gamepad_get_versions_res_get_bootloader_version: (skip):
 **/
guint16
fu_struct_steelseries_gamepad_get_versions_res_get_bootloader_version(const FuStructSteelseriesGamepadGetVersionsRes *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 3, G_LITTLE_ENDIAN);
}

/* setters */
/**
 * fu_struct_steelseries_gamepad_get_versions_res_to_string: (skip):
 **/
static gchar *
fu_struct_steelseries_gamepad_get_versions_res_to_string(const FuStructSteelseriesGamepadGetVersionsRes *st)
{
    g_autoptr(GString) str = g_string_new("FuStructSteelseriesGamepadGetVersionsRes:\n");
    g_return_val_if_fail(st != NULL, NULL);
    {
        const gchar *tmp = fu_steelseries_gamepad_cmd_to_string(fu_struct_steelseries_gamepad_get_versions_res_get_cmd(st));
        if (tmp != NULL) {
            g_string_append_printf(str, "  cmd: 0x%x [%s]\n", (guint) fu_struct_steelseries_gamepad_get_versions_res_get_cmd(st), tmp);
        } else {
            g_string_append_printf(str, "  cmd: 0x%x\n", (guint) fu_struct_steelseries_gamepad_get_versions_res_get_cmd(st));
        }
    }
    g_string_append_printf(str, "  runtime_version: 0x%x\n",
                           (guint) fu_struct_steelseries_gamepad_get_versions_res_get_runtime_version(st));
    g_string_append_printf(str, "  bootloader_version: 0x%x\n",
                           (guint) fu_struct_steelseries_gamepad_get_versions_res_get_bootloader_version(st));
    if (str->len > 0)
        g_string_set_size(str, str->len - 1);
    return g_string_free(g_steal_pointer(&str), FALSE);
}
static gboolean
fu_struct_steelseries_gamepad_get_versions_res_validate_internal(FuStructSteelseriesGamepadGetVersionsRes *st, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    if (fu_struct_steelseries_gamepad_get_versions_res_get_cmd(st) != FU_STEELSERIES_GAMEPAD_CMD_GET_VERSIONS) {
        g_set_error(error,
                    FWUPD_ERROR,
                    FWUPD_ERROR_INVALID_DATA,
                    "constant FuStructSteelseriesGamepadGetVersionsRes.cmd was not valid, "
                    "expected 'FU_STEELSERIES_GAMEPAD_CMD_GET_VERSIONS' and got 0x%x '%s'",
                    fu_struct_steelseries_gamepad_get_versions_res_get_cmd(st),
                    fu_steelseries_gamepad_cmd_to_string(fu_struct_steelseries_gamepad_get_versions_res_get_cmd(st)));
        return FALSE;
    }
    return TRUE;
}
static gboolean
fu_struct_steelseries_gamepad_get_versions_res_parse_internal(FuStructSteelseriesGamepadGetVersionsRes *st, GError **error)
{
    if (g_log_get_debug_enabled()) {
        g_autofree gchar *str = fu_struct_steelseries_gamepad_get_versions_res_to_string(st);
        g_debug("%s", str);
    }
    if (!fu_struct_steelseries_gamepad_get_versions_res_validate_internal(st, error))
        return FALSE;
    return TRUE;
}

/**
 * fu_struct_steelseries_gamepad_get_versions_res_parse: (skip):
 **/
FuStructSteelseriesGamepadGetVersionsRes *
fu_struct_steelseries_gamepad_get_versions_res_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error)
{
    g_autoptr(FuStructSteelseriesGamepadGetVersionsRes) st = fu_struct_steelseries_gamepad_get_versions_res_new_internal();
    g_return_val_if_fail(buf != NULL, NULL);
    g_return_val_if_fail(error == NULL || *error == NULL, NULL);
    if (!fu_memchk_read(bufsz, offset, 5, error)) {
        g_prefix_error_literal(error, "invalid struct FuStructSteelseriesGamepadGetVersionsRes: ");
        return NULL;
    }
    st->buf = g_byte_array_new();
    g_byte_array_append(st->buf, buf + offset, 5);
    if (!fu_struct_steelseries_gamepad_get_versions_res_parse_internal(st, error))
        return NULL;
    return g_steal_pointer(&st);
}
/**
 * fu_struct_steelseries_gamepad_reset_req_ref: (skip):
 **/
FuStructSteelseriesGamepadResetReq *
fu_struct_steelseries_gamepad_reset_req_ref(FuStructSteelseriesGamepadResetReq *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_steelseries_gamepad_reset_req_unref: (skip):
 **/
void
fu_struct_steelseries_gamepad_reset_req_unref(FuStructSteelseriesGamepadResetReq *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructSteelseriesGamepadResetReq refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_steelseries_gamepad_reset_req_new_internal: (skip):
 **/
static FuStructSteelseriesGamepadResetReq *
fu_struct_steelseries_gamepad_reset_req_new_internal(void)
{
    FuStructSteelseriesGamepadResetReq *st = g_new0(FuStructSteelseriesGamepadResetReq, 1);
    st->refcount = 1;
    return st;
}

/* getters */

/* setters */
/**
 * fu_struct_steelseries_gamepad_reset_req_set_cmd: (skip):
 **/
static void
fu_struct_steelseries_gamepad_reset_req_set_cmd(FuStructSteelseriesGamepadResetReq *st, FuSteelseriesGamepadCmd value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[0] = value;
}
/**
 * fu_struct_steelseries_gamepad_reset_req_set_magic1: (skip):
 **/
static void
fu_struct_steelseries_gamepad_reset_req_set_magic1(FuStructSteelseriesGamepadResetReq *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[1] = value;
}
/**
 * fu_struct_steelseries_gamepad_reset_req_set_magic2: (skip):
 **/
static void
fu_struct_steelseries_gamepad_reset_req_set_magic2(FuStructSteelseriesGamepadResetReq *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[2] = value;
}
/**
 * fu_struct_steelseries_gamepad_reset_req_new: (skip):
 **/
FuStructSteelseriesGamepadResetReq *
fu_struct_steelseries_gamepad_reset_req_new(void)
{
    FuStructSteelseriesGamepadResetReq *st = fu_struct_steelseries_gamepad_reset_req_new_internal();
    st->buf = g_byte_array_sized_new(3);
    fu_byte_array_set_size(st->buf, 3, 0x0);
    fu_struct_steelseries_gamepad_reset_req_set_cmd(st, FU_STEELSERIES_GAMEPAD_CMD_RESET);
    fu_struct_steelseries_gamepad_reset_req_set_magic1(st, 0xAA);
    fu_struct_steelseries_gamepad_reset_req_set_magic2(st, 0x55);
    return st;
}
/**
 * fu_struct_steelseries_gamepad_bootloader_mode_req_ref: (skip):
 **/
FuStructSteelseriesGamepadBootloaderModeReq *
fu_struct_steelseries_gamepad_bootloader_mode_req_ref(FuStructSteelseriesGamepadBootloaderModeReq *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_steelseries_gamepad_bootloader_mode_req_unref: (skip):
 **/
void
fu_struct_steelseries_gamepad_bootloader_mode_req_unref(FuStructSteelseriesGamepadBootloaderModeReq *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructSteelseriesGamepadBootloaderModeReq refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_steelseries_gamepad_bootloader_mode_req_new_internal: (skip):
 **/
static FuStructSteelseriesGamepadBootloaderModeReq *
fu_struct_steelseries_gamepad_bootloader_mode_req_new_internal(void)
{
    FuStructSteelseriesGamepadBootloaderModeReq *st = g_new0(FuStructSteelseriesGamepadBootloaderModeReq, 1);
    st->refcount = 1;
    return st;
}

/* getters */

/* setters */
/**
 * fu_struct_steelseries_gamepad_bootloader_mode_req_set_cmd: (skip):
 **/
static void
fu_struct_steelseries_gamepad_bootloader_mode_req_set_cmd(FuStructSteelseriesGamepadBootloaderModeReq *st, FuSteelseriesGamepadCmd value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[0] = value;
}
/**
 * fu_struct_steelseries_gamepad_bootloader_mode_req_set_mode: (skip):
 **/
static void
fu_struct_steelseries_gamepad_bootloader_mode_req_set_mode(FuStructSteelseriesGamepadBootloaderModeReq *st, FuSteelseriesGamepadMode value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[1] = value;
}
/**
 * fu_struct_steelseries_gamepad_bootloader_mode_req_new: (skip):
 **/
FuStructSteelseriesGamepadBootloaderModeReq *
fu_struct_steelseries_gamepad_bootloader_mode_req_new(void)
{
    FuStructSteelseriesGamepadBootloaderModeReq *st = fu_struct_steelseries_gamepad_bootloader_mode_req_new_internal();
    st->buf = g_byte_array_sized_new(2);
    fu_byte_array_set_size(st->buf, 2, 0x0);
    fu_struct_steelseries_gamepad_bootloader_mode_req_set_cmd(st, FU_STEELSERIES_GAMEPAD_CMD_WORK_MODE);
    fu_struct_steelseries_gamepad_bootloader_mode_req_set_mode(st, FU_STEELSERIES_GAMEPAD_MODE_BOOTLOADER_MODE);
    return st;
}
/**
 * fu_struct_steelseries_gamepad_write_chunk_req_ref: (skip):
 **/
FuStructSteelseriesGamepadWriteChunkReq *
fu_struct_steelseries_gamepad_write_chunk_req_ref(FuStructSteelseriesGamepadWriteChunkReq *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_steelseries_gamepad_write_chunk_req_unref: (skip):
 **/
void
fu_struct_steelseries_gamepad_write_chunk_req_unref(FuStructSteelseriesGamepadWriteChunkReq *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructSteelseriesGamepadWriteChunkReq refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_steelseries_gamepad_write_chunk_req_new_internal: (skip):
 **/
static FuStructSteelseriesGamepadWriteChunkReq *
fu_struct_steelseries_gamepad_write_chunk_req_new_internal(void)
{
    FuStructSteelseriesGamepadWriteChunkReq *st = g_new0(FuStructSteelseriesGamepadWriteChunkReq, 1);
    st->refcount = 1;
    return st;
}

/* getters */

/* setters */
/**
 * fu_struct_steelseries_gamepad_write_chunk_req_set_cmd: (skip):
 **/
static void
fu_struct_steelseries_gamepad_write_chunk_req_set_cmd(FuStructSteelseriesGamepadWriteChunkReq *st, FuSteelseriesGamepadCmd value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[0] = value;
}
/**
 * fu_struct_steelseries_gamepad_write_chunk_req_set_block_id: (skip):
 **/
void
fu_struct_steelseries_gamepad_write_chunk_req_set_block_id(FuStructSteelseriesGamepadWriteChunkReq *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 1, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_steelseries_gamepad_write_chunk_req_set_data: (skip):
 **/
gboolean
fu_struct_steelseries_gamepad_write_chunk_req_set_data(FuStructSteelseriesGamepadWriteChunkReq *st, const guint8 *buf, gsize bufsz, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    g_return_val_if_fail(buf != NULL, FALSE);
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
    return fu_memcpy_safe(st->buf->data, st->buf->len, 3, buf, bufsz, 0x0, bufsz, error);
}
/**
 * fu_struct_steelseries_gamepad_write_chunk_req_set_checksum: (skip):
 **/
void
fu_struct_steelseries_gamepad_write_chunk_req_set_checksum(FuStructSteelseriesGamepadWriteChunkReq *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 35, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_steelseries_gamepad_write_chunk_req_new: (skip):
 **/
FuStructSteelseriesGamepadWriteChunkReq *
fu_struct_steelseries_gamepad_write_chunk_req_new(void)
{
    FuStructSteelseriesGamepadWriteChunkReq *st = fu_struct_steelseries_gamepad_write_chunk_req_new_internal();
    st->buf = g_byte_array_sized_new(37);
    fu_byte_array_set_size(st->buf, 37, 0x0);
    fu_struct_steelseries_gamepad_write_chunk_req_set_cmd(st, FU_STEELSERIES_GAMEPAD_CMD_WRITE_CHUNK);
    return st;
}
/**
 * fu_struct_steelseries_gamepad_write_checksum_req_ref: (skip):
 **/
FuStructSteelseriesGamepadWriteChecksumReq *
fu_struct_steelseries_gamepad_write_checksum_req_ref(FuStructSteelseriesGamepadWriteChecksumReq *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_steelseries_gamepad_write_checksum_req_unref: (skip):
 **/
void
fu_struct_steelseries_gamepad_write_checksum_req_unref(FuStructSteelseriesGamepadWriteChecksumReq *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructSteelseriesGamepadWriteChecksumReq refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_steelseries_gamepad_write_checksum_req_new_internal: (skip):
 **/
static FuStructSteelseriesGamepadWriteChecksumReq *
fu_struct_steelseries_gamepad_write_checksum_req_new_internal(void)
{
    FuStructSteelseriesGamepadWriteChecksumReq *st = g_new0(FuStructSteelseriesGamepadWriteChecksumReq, 1);
    st->refcount = 1;
    return st;
}

/* getters */

/* setters */
/**
 * fu_struct_steelseries_gamepad_write_checksum_req_set_cmd: (skip):
 **/
static void
fu_struct_steelseries_gamepad_write_checksum_req_set_cmd(FuStructSteelseriesGamepadWriteChecksumReq *st, FuSteelseriesGamepadCmd value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[0] = value;
}
/**
 * fu_struct_steelseries_gamepad_write_checksum_req_set_magic1: (skip):
 **/
static void
fu_struct_steelseries_gamepad_write_checksum_req_set_magic1(FuStructSteelseriesGamepadWriteChecksumReq *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[1] = value;
}
/**
 * fu_struct_steelseries_gamepad_write_checksum_req_set_magic2: (skip):
 **/
static void
fu_struct_steelseries_gamepad_write_checksum_req_set_magic2(FuStructSteelseriesGamepadWriteChecksumReq *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[2] = value;
}
/**
 * fu_struct_steelseries_gamepad_write_checksum_req_set_checksum: (skip):
 **/
void
fu_struct_steelseries_gamepad_write_checksum_req_set_checksum(FuStructSteelseriesGamepadWriteChecksumReq *st, guint32 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint32(st->buf->data + 3, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_steelseries_gamepad_write_checksum_req_new: (skip):
 **/
FuStructSteelseriesGamepadWriteChecksumReq *
fu_struct_steelseries_gamepad_write_checksum_req_new(void)
{
    FuStructSteelseriesGamepadWriteChecksumReq *st = fu_struct_steelseries_gamepad_write_checksum_req_new_internal();
    st->buf = g_byte_array_sized_new(7);
    fu_byte_array_set_size(st->buf, 7, 0x0);
    fu_struct_steelseries_gamepad_write_checksum_req_set_cmd(st, FU_STEELSERIES_GAMEPAD_CMD_WRITE_CHECKSUM);
    fu_struct_steelseries_gamepad_write_checksum_req_set_magic1(st, 0xAA);
    fu_struct_steelseries_gamepad_write_checksum_req_set_magic2(st, 0x55);
    return st;
}
/**
 * fu_struct_steelseries_gamepad_write_checksum_res_ref: (skip):
 **/
FuStructSteelseriesGamepadWriteChecksumRes *
fu_struct_steelseries_gamepad_write_checksum_res_ref(FuStructSteelseriesGamepadWriteChecksumRes *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_steelseries_gamepad_write_checksum_res_unref: (skip):
 **/
void
fu_struct_steelseries_gamepad_write_checksum_res_unref(FuStructSteelseriesGamepadWriteChecksumRes *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructSteelseriesGamepadWriteChecksumRes refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_steelseries_gamepad_write_checksum_res_new_internal: (skip):
 **/
static FuStructSteelseriesGamepadWriteChecksumRes *
fu_struct_steelseries_gamepad_write_checksum_res_new_internal(void)
{
    FuStructSteelseriesGamepadWriteChecksumRes *st = g_new0(FuStructSteelseriesGamepadWriteChecksumRes, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_steelseries_gamepad_write_checksum_res_get_cmd: (skip):
 **/
static FuSteelseriesGamepadCmd
fu_struct_steelseries_gamepad_write_checksum_res_get_cmd(const FuStructSteelseriesGamepadWriteChecksumRes *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[0];
}
/**
 * fu_struct_steelseries_gamepad_write_checksum_res_get_magic1: (skip):
 **/
static guint8
fu_struct_steelseries_gamepad_write_checksum_res_get_magic1(const FuStructSteelseriesGamepadWriteChecksumRes *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[1];
}
/**
 * fu_struct_steelseries_gamepad_write_checksum_res_get_magic2: (skip):
 **/
static guint8
fu_struct_steelseries_gamepad_write_checksum_res_get_magic2(const FuStructSteelseriesGamepadWriteChecksumRes *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[2];
}
/**
 * fu_struct_steelseries_gamepad_write_checksum_res_get_status: (skip):
 **/
static FuSteelseriesGamepadChecksumStatus
fu_struct_steelseries_gamepad_write_checksum_res_get_status(const FuStructSteelseriesGamepadWriteChecksumRes *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[3];
}
/**
 * fu_struct_steelseries_gamepad_write_checksum_res_get_checksum: (skip):
 **/
guint32
fu_struct_steelseries_gamepad_write_checksum_res_get_checksum(const FuStructSteelseriesGamepadWriteChecksumRes *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint32(st->buf->data + 4, G_LITTLE_ENDIAN);
}

/* setters */
/**
 * fu_struct_steelseries_gamepad_write_checksum_res_to_string: (skip):
 **/
static gchar *
fu_struct_steelseries_gamepad_write_checksum_res_to_string(const FuStructSteelseriesGamepadWriteChecksumRes *st)
{
    g_autoptr(GString) str = g_string_new("FuStructSteelseriesGamepadWriteChecksumRes:\n");
    g_return_val_if_fail(st != NULL, NULL);
    {
        const gchar *tmp = fu_steelseries_gamepad_cmd_to_string(fu_struct_steelseries_gamepad_write_checksum_res_get_cmd(st));
        if (tmp != NULL) {
            g_string_append_printf(str, "  cmd: 0x%x [%s]\n", (guint) fu_struct_steelseries_gamepad_write_checksum_res_get_cmd(st), tmp);
        } else {
            g_string_append_printf(str, "  cmd: 0x%x\n", (guint) fu_struct_steelseries_gamepad_write_checksum_res_get_cmd(st));
        }
    }
    g_string_append_printf(str, "  magic1: 0x%x\n",
                           (guint) fu_struct_steelseries_gamepad_write_checksum_res_get_magic1(st));
    g_string_append_printf(str, "  magic2: 0x%x\n",
                           (guint) fu_struct_steelseries_gamepad_write_checksum_res_get_magic2(st));
    {
        const gchar *tmp = fu_steelseries_gamepad_checksum_status_to_string(fu_struct_steelseries_gamepad_write_checksum_res_get_status(st));
        if (tmp != NULL) {
            g_string_append_printf(str, "  status: 0x%x [%s]\n", (guint) fu_struct_steelseries_gamepad_write_checksum_res_get_status(st), tmp);
        } else {
            g_string_append_printf(str, "  status: 0x%x\n", (guint) fu_struct_steelseries_gamepad_write_checksum_res_get_status(st));
        }
    }
    g_string_append_printf(str, "  checksum: 0x%x\n",
                           (guint) fu_struct_steelseries_gamepad_write_checksum_res_get_checksum(st));
    if (str->len > 0)
        g_string_set_size(str, str->len - 1);
    return g_string_free(g_steal_pointer(&str), FALSE);
}
static gboolean
fu_struct_steelseries_gamepad_write_checksum_res_validate_internal(FuStructSteelseriesGamepadWriteChecksumRes *st, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    if (fu_struct_steelseries_gamepad_write_checksum_res_get_cmd(st) != FU_STEELSERIES_GAMEPAD_CMD_WRITE_CHECKSUM) {
        g_set_error(error,
                    FWUPD_ERROR,
                    FWUPD_ERROR_INVALID_DATA,
                    "constant FuStructSteelseriesGamepadWriteChecksumRes.cmd was not valid, "
                    "expected 'FU_STEELSERIES_GAMEPAD_CMD_WRITE_CHECKSUM' and got 0x%x '%s'",
                    fu_struct_steelseries_gamepad_write_checksum_res_get_cmd(st),
                    fu_steelseries_gamepad_cmd_to_string(fu_struct_steelseries_gamepad_write_checksum_res_get_cmd(st)));
        return FALSE;
    }
    if (fu_struct_steelseries_gamepad_write_checksum_res_get_magic1(st) != 0xAA) {
        g_set_error_literal(error,
                            FWUPD_ERROR,
                            FWUPD_ERROR_INVALID_DATA,
                            "constant FuStructSteelseriesGamepadWriteChecksumRes.magic1 was not valid");
        return FALSE;
    }
    if (fu_struct_steelseries_gamepad_write_checksum_res_get_magic2(st) != 0x55) {
        g_set_error_literal(error,
                            FWUPD_ERROR,
                            FWUPD_ERROR_INVALID_DATA,
                            "constant FuStructSteelseriesGamepadWriteChecksumRes.magic2 was not valid");
        return FALSE;
    }
    if (fu_struct_steelseries_gamepad_write_checksum_res_get_status(st) != FU_STEELSERIES_GAMEPAD_CHECKSUM_STATUS_CORRECT) {
        g_set_error(error,
                    FWUPD_ERROR,
                    FWUPD_ERROR_INVALID_DATA,
                    "constant FuStructSteelseriesGamepadWriteChecksumRes.status was not valid, "
                    "expected 'FU_STEELSERIES_GAMEPAD_CHECKSUM_STATUS_CORRECT' and got 0x%x '%s'",
                    fu_struct_steelseries_gamepad_write_checksum_res_get_status(st),
                    fu_steelseries_gamepad_checksum_status_to_string(fu_struct_steelseries_gamepad_write_checksum_res_get_status(st)));
        return FALSE;
    }
    return TRUE;
}
static gboolean
fu_struct_steelseries_gamepad_write_checksum_res_parse_internal(FuStructSteelseriesGamepadWriteChecksumRes *st, GError **error)
{
    if (g_log_get_debug_enabled()) {
        g_autofree gchar *str = fu_struct_steelseries_gamepad_write_checksum_res_to_string(st);
        g_debug("%s", str);
    }
    if (!fu_struct_steelseries_gamepad_write_checksum_res_validate_internal(st, error))
        return FALSE;
    return TRUE;
}

/**
 * fu_struct_steelseries_gamepad_write_checksum_res_parse: (skip):
 **/
FuStructSteelseriesGamepadWriteChecksumRes *
fu_struct_steelseries_gamepad_write_checksum_res_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error)
{
    g_autoptr(FuStructSteelseriesGamepadWriteChecksumRes) st = fu_struct_steelseries_gamepad_write_checksum_res_new_internal();
    g_return_val_if_fail(buf != NULL, NULL);
    g_return_val_if_fail(error == NULL || *error == NULL, NULL);
    if (!fu_memchk_read(bufsz, offset, 8, error)) {
        g_prefix_error_literal(error, "invalid struct FuStructSteelseriesGamepadWriteChecksumRes: ");
        return NULL;
    }
    st->buf = g_byte_array_new();
    g_byte_array_append(st->buf, buf + offset, 8);
    if (!fu_struct_steelseries_gamepad_write_checksum_res_parse_internal(st, error))
        return NULL;
    return g_steal_pointer(&st);
}
