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

#include "config.h"

#include <glib.h>

#include "fu-corsair-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_corsair_destination_to_string:
 * @val: value, e.g. %FU_CORSAIR_DESTINATION_INTERNAL
 *
 * Converts an enumerated value to a string.
 *
 * Returns: identifier string
 **/
static const gchar *
fu_corsair_destination_to_string(FuCorsairDestination val)
{
    if (val == FU_CORSAIR_DESTINATION_PC)
        return "pc";
    if (val == FU_CORSAIR_DESTINATION_INTERNAL)
        return "internal";
    if (val == FU_CORSAIR_DESTINATION_SELF)
        return "self";
    if (val == FU_CORSAIR_DESTINATION_SUBDEVICE)
        return "subdevice";
    return NULL;
}

/**
 * fu_corsair_cmd_to_string:
 * @val: value, e.g. %FU_CORSAIR_CMD_SET_MODE
 *
 * Converts an enumerated value to a string.
 *
 * Returns: identifier string
 **/
static const gchar *
fu_corsair_cmd_to_string(FuCorsairCmd val)
{
    if (val == FU_CORSAIR_CMD_SET_MODE)
        return "set-mode";
    if (val == FU_CORSAIR_CMD_GET_PROPERTY)
        return "get-property";
    if (val == FU_CORSAIR_CMD_COMMIT)
        return "commit";
    if (val == FU_CORSAIR_CMD_WRITE_FIRST)
        return "write-first";
    if (val == FU_CORSAIR_CMD_WRITE_NEXT)
        return "write-next";
    if (val == FU_CORSAIR_CMD_INIT)
        return "init";
    if (val == FU_CORSAIR_CMD_ATTACH)
        return "attach";
    if (val == FU_CORSAIR_CMD_ACTIVATE)
        return "activate";
    return NULL;
}

/**
 * fu_corsair_status_to_string:
 * @val: value, e.g. %FU_CORSAIR_STATUS_UNKNOWN3
 *
 * Converts an enumerated value to a string.
 *
 * Returns: identifier string
 **/
static const gchar *
fu_corsair_status_to_string(FuCorsairStatus val)
{
    if (val == FU_CORSAIR_STATUS_SUCCESS)
        return "success";
    if (val == FU_CORSAIR_STATUS_UNKNOWN3)
        return "unknown3";
    if (val == FU_CORSAIR_STATUS_NOT_SUPPORTED)
        return "not-supported";
    return NULL;
}
/**
 * fu_struct_corsair_generic_res_ref: (skip):
 **/
FuStructCorsairGenericRes *
fu_struct_corsair_generic_res_ref(FuStructCorsairGenericRes *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_corsair_generic_res_unref: (skip):
 **/
void
fu_struct_corsair_generic_res_unref(FuStructCorsairGenericRes *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructCorsairGenericRes refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_corsair_generic_res_new_internal: (skip):
 **/
static FuStructCorsairGenericRes *
fu_struct_corsair_generic_res_new_internal(void)
{
    FuStructCorsairGenericRes *st = g_new0(FuStructCorsairGenericRes, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_corsair_generic_res_get_destination: (skip):
 **/
FuCorsairDestination
fu_struct_corsair_generic_res_get_destination(const FuStructCorsairGenericRes *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[0];
}
/**
 * fu_struct_corsair_generic_res_get_cmd: (skip):
 **/
FuCorsairCmd
fu_struct_corsair_generic_res_get_cmd(const FuStructCorsairGenericRes *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[1];
}
/**
 * fu_struct_corsair_generic_res_get_status: (skip):
 **/
FuCorsairStatus
fu_struct_corsair_generic_res_get_status(const FuStructCorsairGenericRes *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[2];
}

/* setters */
/**
 * fu_struct_corsair_generic_res_to_string: (skip):
 **/
static gchar *
fu_struct_corsair_generic_res_to_string(const FuStructCorsairGenericRes *st)
{
    g_autoptr(GString) str = g_string_new("FuStructCorsairGenericRes:\n");
    g_return_val_if_fail(st != NULL, NULL);
    {
        const gchar *tmp = fu_corsair_destination_to_string(fu_struct_corsair_generic_res_get_destination(st));
        if (tmp != NULL) {
            g_string_append_printf(str, "  destination: 0x%x [%s]\n", (guint) fu_struct_corsair_generic_res_get_destination(st), tmp);
        } else {
            g_string_append_printf(str, "  destination: 0x%x\n", (guint) fu_struct_corsair_generic_res_get_destination(st));
        }
    }
    {
        const gchar *tmp = fu_corsair_cmd_to_string(fu_struct_corsair_generic_res_get_cmd(st));
        if (tmp != NULL) {
            g_string_append_printf(str, "  cmd: 0x%x [%s]\n", (guint) fu_struct_corsair_generic_res_get_cmd(st), tmp);
        } else {
            g_string_append_printf(str, "  cmd: 0x%x\n", (guint) fu_struct_corsair_generic_res_get_cmd(st));
        }
    }
    {
        const gchar *tmp = fu_corsair_status_to_string(fu_struct_corsair_generic_res_get_status(st));
        if (tmp != NULL) {
            g_string_append_printf(str, "  status: 0x%x [%s]\n", (guint) fu_struct_corsair_generic_res_get_status(st), tmp);
        } else {
            g_string_append_printf(str, "  status: 0x%x\n", (guint) fu_struct_corsair_generic_res_get_status(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_corsair_generic_res_validate_internal(FuStructCorsairGenericRes *st, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    return TRUE;
}
static gboolean
fu_struct_corsair_generic_res_parse_internal(FuStructCorsairGenericRes *st, GError **error)
{
    if (g_log_get_debug_enabled()) {
        g_autofree gchar *str = fu_struct_corsair_generic_res_to_string(st);
        g_debug("%s", str);
    }
    if (!fu_struct_corsair_generic_res_validate_internal(st, error))
        return FALSE;
    return TRUE;
}

/**
 * fu_struct_corsair_generic_res_parse: (skip):
 **/
FuStructCorsairGenericRes *
fu_struct_corsair_generic_res_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error)
{
    g_autoptr(FuStructCorsairGenericRes) st = fu_struct_corsair_generic_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, 3, error)) {
        g_prefix_error_literal(error, "invalid struct FuStructCorsairGenericRes: ");
        return NULL;
    }
    st->buf = g_byte_array_new();
    g_byte_array_append(st->buf, buf + offset, 3);
    if (!fu_struct_corsair_generic_res_parse_internal(st, error))
        return NULL;
    return g_steal_pointer(&st);
}
/**
 * fu_struct_corsair_init_req_ref: (skip):
 **/
FuStructCorsairInitReq *
fu_struct_corsair_init_req_ref(FuStructCorsairInitReq *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_corsair_init_req_unref: (skip):
 **/
void
fu_struct_corsair_init_req_unref(FuStructCorsairInitReq *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructCorsairInitReq refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_corsair_init_req_new_internal: (skip):
 **/
static FuStructCorsairInitReq *
fu_struct_corsair_init_req_new_internal(void)
{
    FuStructCorsairInitReq *st = g_new0(FuStructCorsairInitReq, 1);
    st->refcount = 1;
    return st;
}

/* getters */

/* setters */
/**
 * fu_struct_corsair_init_req_set_destination: (skip):
 **/
void
fu_struct_corsair_init_req_set_destination(FuStructCorsairInitReq *st, FuCorsairDestination value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[0] = value;
}
/**
 * fu_struct_corsair_init_req_set_cmd: (skip):
 **/
static void
fu_struct_corsair_init_req_set_cmd(FuStructCorsairInitReq *st, FuCorsairCmd value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[1] = value;
}
/**
 * fu_struct_corsair_init_req_set_data1: (skip):
 **/
static void
fu_struct_corsair_init_req_set_data1(FuStructCorsairInitReq *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[2] = value;
}
/**
 * fu_struct_corsair_init_req_set_data2: (skip):
 **/
static void
fu_struct_corsair_init_req_set_data2(FuStructCorsairInitReq *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[3] = value;
}
/**
 * fu_struct_corsair_init_req_new: (skip):
 **/
FuStructCorsairInitReq *
fu_struct_corsair_init_req_new(void)
{
    FuStructCorsairInitReq *st = fu_struct_corsair_init_req_new_internal();
    st->buf = g_byte_array_sized_new(4);
    fu_byte_array_set_size(st->buf, 4, 0x0);
    fu_struct_corsair_init_req_set_destination(st, FU_CORSAIR_DESTINATION_SELF);
    fu_struct_corsair_init_req_set_cmd(st, FU_CORSAIR_CMD_INIT);
    fu_struct_corsair_init_req_set_data1(st, 0x00);
    fu_struct_corsair_init_req_set_data2(st, 0x03);
    return st;
}
/**
 * fu_struct_corsair_write_first_req_ref: (skip):
 **/
FuStructCorsairWriteFirstReq *
fu_struct_corsair_write_first_req_ref(FuStructCorsairWriteFirstReq *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_corsair_write_first_req_unref: (skip):
 **/
void
fu_struct_corsair_write_first_req_unref(FuStructCorsairWriteFirstReq *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructCorsairWriteFirstReq refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_corsair_write_first_req_new_internal: (skip):
 **/
static FuStructCorsairWriteFirstReq *
fu_struct_corsair_write_first_req_new_internal(void)
{
    FuStructCorsairWriteFirstReq *st = g_new0(FuStructCorsairWriteFirstReq, 1);
    st->refcount = 1;
    return st;
}

/* getters */

/* setters */
/**
 * fu_struct_corsair_write_first_req_set_destination: (skip):
 **/
void
fu_struct_corsair_write_first_req_set_destination(FuStructCorsairWriteFirstReq *st, FuCorsairDestination value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[0] = value;
}
/**
 * fu_struct_corsair_write_first_req_set_cmd: (skip):
 **/
static void
fu_struct_corsair_write_first_req_set_cmd(FuStructCorsairWriteFirstReq *st, FuCorsairCmd value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[1] = value;
}
/**
 * fu_struct_corsair_write_first_req_set_data1: (skip):
 **/
static void
fu_struct_corsair_write_first_req_set_data1(FuStructCorsairWriteFirstReq *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[2] = value;
}
/**
 * fu_struct_corsair_write_first_req_set_size: (skip):
 **/
void
fu_struct_corsair_write_first_req_set_size(FuStructCorsairWriteFirstReq *st, guint32 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint32(st->buf->data + 3, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_corsair_write_first_req_new: (skip):
 **/
FuStructCorsairWriteFirstReq *
fu_struct_corsair_write_first_req_new(void)
{
    FuStructCorsairWriteFirstReq *st = fu_struct_corsair_write_first_req_new_internal();
    st->buf = g_byte_array_sized_new(7);
    fu_byte_array_set_size(st->buf, 7, 0x0);
    fu_struct_corsair_write_first_req_set_destination(st, FU_CORSAIR_DESTINATION_SELF);
    fu_struct_corsair_write_first_req_set_cmd(st, FU_CORSAIR_CMD_WRITE_FIRST);
    fu_struct_corsair_write_first_req_set_data1(st, 0x00);
    return st;
}
/**
 * fu_struct_corsair_write_next_req_ref: (skip):
 **/
FuStructCorsairWriteNextReq *
fu_struct_corsair_write_next_req_ref(FuStructCorsairWriteNextReq *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_corsair_write_next_req_unref: (skip):
 **/
void
fu_struct_corsair_write_next_req_unref(FuStructCorsairWriteNextReq *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructCorsairWriteNextReq refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_corsair_write_next_req_new_internal: (skip):
 **/
static FuStructCorsairWriteNextReq *
fu_struct_corsair_write_next_req_new_internal(void)
{
    FuStructCorsairWriteNextReq *st = g_new0(FuStructCorsairWriteNextReq, 1);
    st->refcount = 1;
    return st;
}

/* getters */

/* setters */
/**
 * fu_struct_corsair_write_next_req_set_destination: (skip):
 **/
void
fu_struct_corsair_write_next_req_set_destination(FuStructCorsairWriteNextReq *st, FuCorsairDestination value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[0] = value;
}
/**
 * fu_struct_corsair_write_next_req_set_cmd: (skip):
 **/
static void
fu_struct_corsair_write_next_req_set_cmd(FuStructCorsairWriteNextReq *st, FuCorsairCmd value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[1] = value;
}
/**
 * fu_struct_corsair_write_next_req_set_data1: (skip):
 **/
static void
fu_struct_corsair_write_next_req_set_data1(FuStructCorsairWriteNextReq *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[2] = value;
}
/**
 * fu_struct_corsair_write_next_req_new: (skip):
 **/
FuStructCorsairWriteNextReq *
fu_struct_corsair_write_next_req_new(void)
{
    FuStructCorsairWriteNextReq *st = fu_struct_corsair_write_next_req_new_internal();
    st->buf = g_byte_array_sized_new(3);
    fu_byte_array_set_size(st->buf, 3, 0x0);
    fu_struct_corsair_write_next_req_set_destination(st, FU_CORSAIR_DESTINATION_SELF);
    fu_struct_corsair_write_next_req_set_cmd(st, FU_CORSAIR_CMD_WRITE_NEXT);
    fu_struct_corsair_write_next_req_set_data1(st, 0x00);
    return st;
}
/**
 * fu_struct_corsair_set_mode_req_ref: (skip):
 **/
FuStructCorsairSetModeReq *
fu_struct_corsair_set_mode_req_ref(FuStructCorsairSetModeReq *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_corsair_set_mode_req_unref: (skip):
 **/
void
fu_struct_corsair_set_mode_req_unref(FuStructCorsairSetModeReq *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructCorsairSetModeReq refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_corsair_set_mode_req_new_internal: (skip):
 **/
static FuStructCorsairSetModeReq *
fu_struct_corsair_set_mode_req_new_internal(void)
{
    FuStructCorsairSetModeReq *st = g_new0(FuStructCorsairSetModeReq, 1);
    st->refcount = 1;
    return st;
}

/* getters */

/* setters */
/**
 * fu_struct_corsair_set_mode_req_set_destination: (skip):
 **/
void
fu_struct_corsair_set_mode_req_set_destination(FuStructCorsairSetModeReq *st, FuCorsairDestination value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[0] = value;
}
/**
 * fu_struct_corsair_set_mode_req_set_cmd: (skip):
 **/
static void
fu_struct_corsair_set_mode_req_set_cmd(FuStructCorsairSetModeReq *st, FuCorsairCmd value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[1] = value;
}
/**
 * fu_struct_corsair_set_mode_req_set_data1: (skip):
 **/
static void
fu_struct_corsair_set_mode_req_set_data1(FuStructCorsairSetModeReq *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[2] = value;
}
/**
 * fu_struct_corsair_set_mode_req_set_data2: (skip):
 **/
static void
fu_struct_corsair_set_mode_req_set_data2(FuStructCorsairSetModeReq *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[3] = value;
}
/**
 * fu_struct_corsair_set_mode_req_set_mode: (skip):
 **/
void
fu_struct_corsair_set_mode_req_set_mode(FuStructCorsairSetModeReq *st, FuCorsairDeviceMode value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[4] = value;
}
/**
 * fu_struct_corsair_set_mode_req_new: (skip):
 **/
FuStructCorsairSetModeReq *
fu_struct_corsair_set_mode_req_new(void)
{
    FuStructCorsairSetModeReq *st = fu_struct_corsair_set_mode_req_new_internal();
    st->buf = g_byte_array_sized_new(5);
    fu_byte_array_set_size(st->buf, 5, 0x0);
    fu_struct_corsair_set_mode_req_set_destination(st, FU_CORSAIR_DESTINATION_SELF);
    fu_struct_corsair_set_mode_req_set_cmd(st, FU_CORSAIR_CMD_SET_MODE);
    fu_struct_corsair_set_mode_req_set_data1(st, 0x03);
    fu_struct_corsair_set_mode_req_set_data2(st, 0x00);
    return st;
}
/**
 * fu_struct_corsair_commit_req_ref: (skip):
 **/
FuStructCorsairCommitReq *
fu_struct_corsair_commit_req_ref(FuStructCorsairCommitReq *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_corsair_commit_req_unref: (skip):
 **/
void
fu_struct_corsair_commit_req_unref(FuStructCorsairCommitReq *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructCorsairCommitReq refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_corsair_commit_req_new_internal: (skip):
 **/
static FuStructCorsairCommitReq *
fu_struct_corsair_commit_req_new_internal(void)
{
    FuStructCorsairCommitReq *st = g_new0(FuStructCorsairCommitReq, 1);
    st->refcount = 1;
    return st;
}

/* getters */

/* setters */
/**
 * fu_struct_corsair_commit_req_set_destination: (skip):
 **/
void
fu_struct_corsair_commit_req_set_destination(FuStructCorsairCommitReq *st, FuCorsairDestination value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[0] = value;
}
/**
 * fu_struct_corsair_commit_req_set_cmd: (skip):
 **/
static void
fu_struct_corsair_commit_req_set_cmd(FuStructCorsairCommitReq *st, FuCorsairCmd value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[1] = value;
}
/**
 * fu_struct_corsair_commit_req_set_data1: (skip):
 **/
static void
fu_struct_corsair_commit_req_set_data1(FuStructCorsairCommitReq *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[2] = value;
}
/**
 * fu_struct_corsair_commit_req_set_data2: (skip):
 **/
static void
fu_struct_corsair_commit_req_set_data2(FuStructCorsairCommitReq *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[3] = value;
}
/**
 * fu_struct_corsair_commit_req_new: (skip):
 **/
FuStructCorsairCommitReq *
fu_struct_corsair_commit_req_new(void)
{
    FuStructCorsairCommitReq *st = fu_struct_corsair_commit_req_new_internal();
    st->buf = g_byte_array_sized_new(4);
    fu_byte_array_set_size(st->buf, 4, 0x0);
    fu_struct_corsair_commit_req_set_destination(st, FU_CORSAIR_DESTINATION_SELF);
    fu_struct_corsair_commit_req_set_cmd(st, FU_CORSAIR_CMD_COMMIT);
    fu_struct_corsair_commit_req_set_data1(st, 0x01);
    fu_struct_corsair_commit_req_set_data2(st, 0x00);
    return st;
}
/**
 * fu_struct_corsair_activate_req_ref: (skip):
 **/
FuStructCorsairActivateReq *
fu_struct_corsair_activate_req_ref(FuStructCorsairActivateReq *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_corsair_activate_req_unref: (skip):
 **/
void
fu_struct_corsair_activate_req_unref(FuStructCorsairActivateReq *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructCorsairActivateReq refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_corsair_activate_req_new_internal: (skip):
 **/
static FuStructCorsairActivateReq *
fu_struct_corsair_activate_req_new_internal(void)
{
    FuStructCorsairActivateReq *st = g_new0(FuStructCorsairActivateReq, 1);
    st->refcount = 1;
    return st;
}

/* getters */

/* setters */
/**
 * fu_struct_corsair_activate_req_set_destination: (skip):
 **/
void
fu_struct_corsair_activate_req_set_destination(FuStructCorsairActivateReq *st, FuCorsairDestination value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[0] = value;
}
/**
 * fu_struct_corsair_activate_req_set_cmd: (skip):
 **/
static void
fu_struct_corsair_activate_req_set_cmd(FuStructCorsairActivateReq *st, FuCorsairCmd value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[1] = value;
}
/**
 * fu_struct_corsair_activate_req_set_data1: (skip):
 **/
static void
fu_struct_corsair_activate_req_set_data1(FuStructCorsairActivateReq *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[2] = value;
}
/**
 * fu_struct_corsair_activate_req_set_data2: (skip):
 **/
static void
fu_struct_corsair_activate_req_set_data2(FuStructCorsairActivateReq *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[3] = value;
}
/**
 * fu_struct_corsair_activate_req_set_data3: (skip):
 **/
static void
fu_struct_corsair_activate_req_set_data3(FuStructCorsairActivateReq *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[4] = value;
}
/**
 * fu_struct_corsair_activate_req_set_data4: (skip):
 **/
static void
fu_struct_corsair_activate_req_set_data4(FuStructCorsairActivateReq *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[5] = value;
}
/**
 * fu_struct_corsair_activate_req_set_data5: (skip):
 **/
static void
fu_struct_corsair_activate_req_set_data5(FuStructCorsairActivateReq *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[6] = value;
}
/**
 * fu_struct_corsair_activate_req_set_data6: (skip):
 **/
static void
fu_struct_corsair_activate_req_set_data6(FuStructCorsairActivateReq *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[7] = value;
}
/**
 * fu_struct_corsair_activate_req_set_crc: (skip):
 **/
void
fu_struct_corsair_activate_req_set_crc(FuStructCorsairActivateReq *st, guint32 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint32(st->buf->data + 8, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_corsair_activate_req_new: (skip):
 **/
FuStructCorsairActivateReq *
fu_struct_corsair_activate_req_new(void)
{
    FuStructCorsairActivateReq *st = fu_struct_corsair_activate_req_new_internal();
    st->buf = g_byte_array_sized_new(12);
    fu_byte_array_set_size(st->buf, 12, 0x0);
    fu_struct_corsair_activate_req_set_destination(st, FU_CORSAIR_DESTINATION_SELF);
    fu_struct_corsair_activate_req_set_cmd(st, FU_CORSAIR_CMD_ACTIVATE);
    fu_struct_corsair_activate_req_set_data1(st, 0x00);
    fu_struct_corsair_activate_req_set_data2(st, 0x01);
    fu_struct_corsair_activate_req_set_data3(st, 0x03);
    fu_struct_corsair_activate_req_set_data4(st, 0x00);
    fu_struct_corsair_activate_req_set_data5(st, 0x01);
    fu_struct_corsair_activate_req_set_data6(st, 0x01);
    return st;
}
/**
 * fu_struct_corsair_attach_req_ref: (skip):
 **/
FuStructCorsairAttachReq *
fu_struct_corsair_attach_req_ref(FuStructCorsairAttachReq *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_corsair_attach_req_unref: (skip):
 **/
void
fu_struct_corsair_attach_req_unref(FuStructCorsairAttachReq *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructCorsairAttachReq refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_corsair_attach_req_new_internal: (skip):
 **/
static FuStructCorsairAttachReq *
fu_struct_corsair_attach_req_new_internal(void)
{
    FuStructCorsairAttachReq *st = g_new0(FuStructCorsairAttachReq, 1);
    st->refcount = 1;
    return st;
}

/* getters */

/* setters */
/**
 * fu_struct_corsair_attach_req_set_destination: (skip):
 **/
void
fu_struct_corsair_attach_req_set_destination(FuStructCorsairAttachReq *st, FuCorsairDestination value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[0] = value;
}
/**
 * fu_struct_corsair_attach_req_set_cmd: (skip):
 **/
static void
fu_struct_corsair_attach_req_set_cmd(FuStructCorsairAttachReq *st, FuCorsairCmd value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[1] = value;
}
/**
 * fu_struct_corsair_attach_req_set_data1: (skip):
 **/
static void
fu_struct_corsair_attach_req_set_data1(FuStructCorsairAttachReq *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[2] = value;
}
/**
 * fu_struct_corsair_attach_req_set_data2: (skip):
 **/
static void
fu_struct_corsair_attach_req_set_data2(FuStructCorsairAttachReq *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[3] = value;
}
/**
 * fu_struct_corsair_attach_req_set_data3: (skip):
 **/
static void
fu_struct_corsair_attach_req_set_data3(FuStructCorsairAttachReq *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[4] = value;
}
/**
 * fu_struct_corsair_attach_req_set_data4: (skip):
 **/
static void
fu_struct_corsair_attach_req_set_data4(FuStructCorsairAttachReq *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[5] = value;
}
/**
 * fu_struct_corsair_attach_req_set_data5: (skip):
 **/
static void
fu_struct_corsair_attach_req_set_data5(FuStructCorsairAttachReq *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[6] = value;
}
/**
 * fu_struct_corsair_attach_req_new: (skip):
 **/
FuStructCorsairAttachReq *
fu_struct_corsair_attach_req_new(void)
{
    FuStructCorsairAttachReq *st = fu_struct_corsair_attach_req_new_internal();
    st->buf = g_byte_array_sized_new(7);
    fu_byte_array_set_size(st->buf, 7, 0x0);
    fu_struct_corsair_attach_req_set_destination(st, FU_CORSAIR_DESTINATION_SELF);
    fu_struct_corsair_attach_req_set_cmd(st, FU_CORSAIR_CMD_ATTACH);
    fu_struct_corsair_attach_req_set_data1(st, 0x01);
    fu_struct_corsair_attach_req_set_data2(st, 0x00);
    fu_struct_corsair_attach_req_set_data3(st, 0x03);
    fu_struct_corsair_attach_req_set_data4(st, 0x00);
    fu_struct_corsair_attach_req_set_data5(st, 0x01);
    return st;
}
/**
 * fu_struct_corsair_get_property_req_ref: (skip):
 **/
FuStructCorsairGetPropertyReq *
fu_struct_corsair_get_property_req_ref(FuStructCorsairGetPropertyReq *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_corsair_get_property_req_unref: (skip):
 **/
void
fu_struct_corsair_get_property_req_unref(FuStructCorsairGetPropertyReq *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructCorsairGetPropertyReq refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_corsair_get_property_req_new_internal: (skip):
 **/
static FuStructCorsairGetPropertyReq *
fu_struct_corsair_get_property_req_new_internal(void)
{
    FuStructCorsairGetPropertyReq *st = g_new0(FuStructCorsairGetPropertyReq, 1);
    st->refcount = 1;
    return st;
}

/* getters */

/* setters */
/**
 * fu_struct_corsair_get_property_req_set_destination: (skip):
 **/
void
fu_struct_corsair_get_property_req_set_destination(FuStructCorsairGetPropertyReq *st, FuCorsairDestination value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[0] = value;
}
/**
 * fu_struct_corsair_get_property_req_set_cmd: (skip):
 **/
static void
fu_struct_corsair_get_property_req_set_cmd(FuStructCorsairGetPropertyReq *st, FuCorsairCmd value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[1] = value;
}
/**
 * fu_struct_corsair_get_property_req_set_property: (skip):
 **/
void
fu_struct_corsair_get_property_req_set_property(FuStructCorsairGetPropertyReq *st, FuCorsairDeviceProperty value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 2, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_corsair_get_property_req_new: (skip):
 **/
FuStructCorsairGetPropertyReq *
fu_struct_corsair_get_property_req_new(void)
{
    FuStructCorsairGetPropertyReq *st = fu_struct_corsair_get_property_req_new_internal();
    st->buf = g_byte_array_sized_new(4);
    fu_byte_array_set_size(st->buf, 4, 0x0);
    fu_struct_corsair_get_property_req_set_destination(st, FU_CORSAIR_DESTINATION_SELF);
    fu_struct_corsair_get_property_req_set_cmd(st, FU_CORSAIR_CMD_GET_PROPERTY);
    return st;
}
/**
 * fu_struct_corsair_get_property_res_ref: (skip):
 **/
FuStructCorsairGetPropertyRes *
fu_struct_corsair_get_property_res_ref(FuStructCorsairGetPropertyRes *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_corsair_get_property_res_unref: (skip):
 **/
void
fu_struct_corsair_get_property_res_unref(FuStructCorsairGetPropertyRes *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructCorsairGetPropertyRes refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_corsair_get_property_res_new_internal: (skip):
 **/
static FuStructCorsairGetPropertyRes *
fu_struct_corsair_get_property_res_new_internal(void)
{
    FuStructCorsairGetPropertyRes *st = g_new0(FuStructCorsairGetPropertyRes, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_corsair_get_property_res_get_destination: (skip):
 **/
FuCorsairDestination
fu_struct_corsair_get_property_res_get_destination(const FuStructCorsairGetPropertyRes *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[0];
}
/**
 * fu_struct_corsair_get_property_res_get_cmd: (skip):
 **/
FuCorsairCmd
fu_struct_corsair_get_property_res_get_cmd(const FuStructCorsairGetPropertyRes *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[1];
}
/**
 * fu_struct_corsair_get_property_res_get_status: (skip):
 **/
static FuCorsairStatus
fu_struct_corsair_get_property_res_get_status(const FuStructCorsairGetPropertyRes *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[2];
}
/**
 * fu_struct_corsair_get_property_res_get_value: (skip):
 **/
guint32
fu_struct_corsair_get_property_res_get_value(const FuStructCorsairGetPropertyRes *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint32(st->buf->data + 3, G_LITTLE_ENDIAN);
}

/* setters */
/**
 * fu_struct_corsair_get_property_res_to_string: (skip):
 **/
static gchar *
fu_struct_corsair_get_property_res_to_string(const FuStructCorsairGetPropertyRes *st)
{
    g_autoptr(GString) str = g_string_new("FuStructCorsairGetPropertyRes:\n");
    g_return_val_if_fail(st != NULL, NULL);
    {
        const gchar *tmp = fu_corsair_destination_to_string(fu_struct_corsair_get_property_res_get_destination(st));
        if (tmp != NULL) {
            g_string_append_printf(str, "  destination: 0x%x [%s]\n", (guint) fu_struct_corsair_get_property_res_get_destination(st), tmp);
        } else {
            g_string_append_printf(str, "  destination: 0x%x\n", (guint) fu_struct_corsair_get_property_res_get_destination(st));
        }
    }
    {
        const gchar *tmp = fu_corsair_cmd_to_string(fu_struct_corsair_get_property_res_get_cmd(st));
        if (tmp != NULL) {
            g_string_append_printf(str, "  cmd: 0x%x [%s]\n", (guint) fu_struct_corsair_get_property_res_get_cmd(st), tmp);
        } else {
            g_string_append_printf(str, "  cmd: 0x%x\n", (guint) fu_struct_corsair_get_property_res_get_cmd(st));
        }
    }
    {
        const gchar *tmp = fu_corsair_status_to_string(fu_struct_corsair_get_property_res_get_status(st));
        if (tmp != NULL) {
            g_string_append_printf(str, "  status: 0x%x [%s]\n", (guint) fu_struct_corsair_get_property_res_get_status(st), tmp);
        } else {
            g_string_append_printf(str, "  status: 0x%x\n", (guint) fu_struct_corsair_get_property_res_get_status(st));
        }
    }
    g_string_append_printf(str, "  value: 0x%x\n",
                           (guint) fu_struct_corsair_get_property_res_get_value(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_corsair_get_property_res_validate_internal(FuStructCorsairGetPropertyRes *st, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    if (fu_struct_corsair_get_property_res_get_status(st) != FU_CORSAIR_STATUS_SUCCESS) {
        g_set_error(error,
                    FWUPD_ERROR,
                    FWUPD_ERROR_INVALID_DATA,
                    "constant FuStructCorsairGetPropertyRes.status was not valid, "
                    "expected 'FU_CORSAIR_STATUS_SUCCESS' and got 0x%x '%s'",
                    fu_struct_corsair_get_property_res_get_status(st),
                    fu_corsair_status_to_string(fu_struct_corsair_get_property_res_get_status(st)));
        return FALSE;
    }
    return TRUE;
}
static gboolean
fu_struct_corsair_get_property_res_parse_internal(FuStructCorsairGetPropertyRes *st, GError **error)
{
    if (g_log_get_debug_enabled()) {
        g_autofree gchar *str = fu_struct_corsair_get_property_res_to_string(st);
        g_debug("%s", str);
    }
    if (!fu_struct_corsair_get_property_res_validate_internal(st, error))
        return FALSE;
    return TRUE;
}

/**
 * fu_struct_corsair_get_property_res_parse: (skip):
 **/
FuStructCorsairGetPropertyRes *
fu_struct_corsair_get_property_res_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error)
{
    g_autoptr(FuStructCorsairGetPropertyRes) st = fu_struct_corsair_get_property_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, 7, error)) {
        g_prefix_error_literal(error, "invalid struct FuStructCorsairGetPropertyRes: ");
        return NULL;
    }
    st->buf = g_byte_array_new();
    g_byte_array_append(st->buf, buf + offset, 7);
    if (!fu_struct_corsair_get_property_res_parse_internal(st, error))
        return NULL;
    return g_steal_pointer(&st);
}
