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

#include "config.h"

#include <glib.h>

#include "fu-wacom-usb-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_wacom_usb_report_id_to_string:
 * @val: value, e.g. %FU_WACOM_USB_REPORT_ID_SWITCH_TO_FLASH_LOADER
 *
 * Converts an enumerated value to a string.
 *
 * Returns: identifier string
 **/
const gchar *
fu_wacom_usb_report_id_to_string(FuWacomUsbReportId val)
{
    if (val == FU_WACOM_USB_REPORT_ID_FW_DESCRIPTOR)
        return "fw-descriptor";
    if (val == FU_WACOM_USB_REPORT_ID_SWITCH_TO_FLASH_LOADER)
        return "switch-to-flash-loader";
    if (val == FU_WACOM_USB_REPORT_ID_QUIT_AND_RESET)
        return "quit-and-reset";
    if (val == FU_WACOM_USB_REPORT_ID_READ_BLOCK_DATA)
        return "read-block-data";
    if (val == FU_WACOM_USB_REPORT_ID_WRITE_BLOCK)
        return "write-block";
    if (val == FU_WACOM_USB_REPORT_ID_ERASE_BLOCK)
        return "erase-block";
    if (val == FU_WACOM_USB_REPORT_ID_SET_READ_ADDRESS)
        return "set-read-address";
    if (val == FU_WACOM_USB_REPORT_ID_GET_STATUS)
        return "get-status";
    if (val == FU_WACOM_USB_REPORT_ID_UPDATE_RESET)
        return "update-reset";
    if (val == FU_WACOM_USB_REPORT_ID_WRITE_WORD)
        return "write-word";
    if (val == FU_WACOM_USB_REPORT_ID_GET_PARAMETERS)
        return "get-parameters";
    if (val == FU_WACOM_USB_REPORT_ID_GET_FLASH_DESCRIPTOR)
        return "get-flash-descriptor";
    if (val == FU_WACOM_USB_REPORT_ID_GET_CHECKSUMS)
        return "get-checksums";
    if (val == FU_WACOM_USB_REPORT_ID_SET_CHECKSUM_FOR_BLOCK)
        return "set-checksum-for-block";
    if (val == FU_WACOM_USB_REPORT_ID_CALCULATE_CHECKSUM_FOR_BLOCK)
        return "calculate-checksum-for-block";
    if (val == FU_WACOM_USB_REPORT_ID_WRITE_CHECKSUM_TABLE)
        return "write-checksum-table";
    if (val == FU_WACOM_USB_REPORT_ID_GET_CURRENT_FIRMWARE_IDX)
        return "get-current-firmware-idx";
    if (val == FU_WACOM_USB_REPORT_ID_MODULE)
        return "module";
    return NULL;
}

/**
 * fu_wacom_usb_module_fw_type_to_string:
 * @val: value, e.g. %FU_WACOM_USB_MODULE_FW_TYPE_BLUETOOTH
 *
 * Converts an enumerated value to a string.
 *
 * Returns: identifier string
 **/
const gchar *
fu_wacom_usb_module_fw_type_to_string(FuWacomUsbModuleFwType val)
{
    if (val == FU_WACOM_USB_MODULE_FW_TYPE_TOUCH)
        return "touch";
    if (val == FU_WACOM_USB_MODULE_FW_TYPE_BLUETOOTH)
        return "bluetooth";
    if (val == FU_WACOM_USB_MODULE_FW_TYPE_EMR_CORRECTION)
        return "emr-correction";
    if (val == FU_WACOM_USB_MODULE_FW_TYPE_BLUETOOTH_HID)
        return "bluetooth-hid";
    if (val == FU_WACOM_USB_MODULE_FW_TYPE_SCALER)
        return "scaler";
    if (val == FU_WACOM_USB_MODULE_FW_TYPE_BLUETOOTH_ID6)
        return "bluetooth-id6";
    if (val == FU_WACOM_USB_MODULE_FW_TYPE_TOUCH_ID7)
        return "touch-id7";
    if (val == FU_WACOM_USB_MODULE_FW_TYPE_BLUETOOTH_ID9)
        return "bluetooth-id9";
    if (val == FU_WACOM_USB_MODULE_FW_TYPE_SUB_CPU)
        return "sub-cpu";
    if (val == FU_WACOM_USB_MODULE_FW_TYPE_MAIN)
        return "main";
    return NULL;
}

/**
 * fu_wacom_usb_module_command_to_string:
 * @val: value, e.g. %FU_WACOM_USB_MODULE_COMMAND_DATA
 *
 * Converts an enumerated value to a string.
 *
 * Returns: identifier string
 **/
const gchar *
fu_wacom_usb_module_command_to_string(FuWacomUsbModuleCommand val)
{
    if (val == FU_WACOM_USB_MODULE_COMMAND_START)
        return "start";
    if (val == FU_WACOM_USB_MODULE_COMMAND_DATA)
        return "data";
    if (val == FU_WACOM_USB_MODULE_COMMAND_END)
        return "end";
    return NULL;
}

/**
 * fu_wacom_usb_module_status_to_string:
 * @val: value, e.g. %FU_WACOM_USB_MODULE_STATUS_BUSY
 *
 * Converts an enumerated value to a string.
 *
 * Returns: identifier string
 **/
const gchar *
fu_wacom_usb_module_status_to_string(FuWacomUsbModuleStatus val)
{
    if (val == FU_WACOM_USB_MODULE_STATUS_OK)
        return "ok";
    if (val == FU_WACOM_USB_MODULE_STATUS_BUSY)
        return "busy";
    if (val == FU_WACOM_USB_MODULE_STATUS_ERR_CRC)
        return "err-crc";
    if (val == FU_WACOM_USB_MODULE_STATUS_ERR_CMD)
        return "err-cmd";
    if (val == FU_WACOM_USB_MODULE_STATUS_ERR_HW_ACCESS_FAIL)
        return "err-hw-access-fail";
    if (val == FU_WACOM_USB_MODULE_STATUS_ERR_FLASH_NO_SUPPORT)
        return "err-flash-no-support";
    if (val == FU_WACOM_USB_MODULE_STATUS_ERR_MODE_WRONG)
        return "err-mode-wrong";
    if (val == FU_WACOM_USB_MODULE_STATUS_ERR_MPU_NO_SUPPORT)
        return "err-mpu-no-support";
    if (val == FU_WACOM_USB_MODULE_STATUS_ERR_VERSION_NO_SUPPORT)
        return "err-version-no-support";
    if (val == FU_WACOM_USB_MODULE_STATUS_ERR_ERASE)
        return "err-erase";
    if (val == FU_WACOM_USB_MODULE_STATUS_ERR_WRITE)
        return "err-write";
    if (val == FU_WACOM_USB_MODULE_STATUS_ERR_EXIT)
        return "err-exit";
    if (val == FU_WACOM_USB_MODULE_STATUS_ERR)
        return "err";
    if (val == FU_WACOM_USB_MODULE_STATUS_ERR_INVALID_OP)
        return "err-invalid-op";
    if (val == FU_WACOM_USB_MODULE_STATUS_ERR_WRONG_IMAGE)
        return "err-wrong-image";
    return NULL;
}

/**
 * fu_wacom_usb_device_status_to_string:
 * @val: value, e.g. %FU_WACOM_USB_DEVICE_STATUS_WRITING
 *
 * Converts an enumerated value to a string.
 *
 * Returns: identifier string
 *
 **/
gchar *
fu_wacom_usb_device_status_to_string(FuWacomUsbDeviceStatus val)
{
    const gchar *data[6] = {0};
    guint idx = 0;
    if (val == FU_WACOM_USB_DEVICE_STATUS_UNKNOWN)
        return g_strdup("unknown");
    if (val & FU_WACOM_USB_DEVICE_STATUS_WRITING)
        data[idx++] = "writing";
    if (val & FU_WACOM_USB_DEVICE_STATUS_ERASING)
        data[idx++] = "erasing";
    if (val & FU_WACOM_USB_DEVICE_STATUS_ERROR_WRITE)
        data[idx++] = "error-write";
    if (val & FU_WACOM_USB_DEVICE_STATUS_ERROR_ERASE)
        data[idx++] = "error-erase";
    if (val & FU_WACOM_USB_DEVICE_STATUS_WRITE_PROTECTED)
        data[idx++] = "write-protected";
    return g_strjoinv(",", (gchar **)data);
}
/**
 * fu_struct_wacom_usb_firmware_hdr_ref: (skip):
 **/
FuStructWacomUsbFirmwareHdr *
fu_struct_wacom_usb_firmware_hdr_ref(FuStructWacomUsbFirmwareHdr *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_wacom_usb_firmware_hdr_unref: (skip):
 **/
void
fu_struct_wacom_usb_firmware_hdr_unref(FuStructWacomUsbFirmwareHdr *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructWacomUsbFirmwareHdr refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_wacom_usb_firmware_hdr_new_internal: (skip):
 **/
static FuStructWacomUsbFirmwareHdr *
fu_struct_wacom_usb_firmware_hdr_new_internal(void)
{
    FuStructWacomUsbFirmwareHdr *st = g_new0(FuStructWacomUsbFirmwareHdr, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_wacom_usb_firmware_hdr_get_magic: (skip):
 **/
static gchar *
fu_struct_wacom_usb_firmware_hdr_get_magic(const FuStructWacomUsbFirmwareHdr *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    return fu_memstrsafe(st->buf->data, st->buf->len, 0, 5, NULL);
}

/* setters */
static gboolean
fu_struct_wacom_usb_firmware_hdr_validate_internal(FuStructWacomUsbFirmwareHdr *st, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    if (strncmp((const gchar *) (st->buf->data + 0), "WACOM", 5) != 0) {
        g_autofree gchar *str = fu_struct_wacom_usb_firmware_hdr_get_magic(st);
        g_set_error(error,
                    FWUPD_ERROR,
                    FWUPD_ERROR_INVALID_DATA,
                    "constant FuStructWacomUsbFirmwareHdr.magic was not valid, "
                    "expected 'WACOM' and got '%s'",
                    str);
        return FALSE;
    }
    return TRUE;
}
/**
 * fu_struct_wacom_usb_firmware_hdr_validate_stream: (skip):
 **/
gboolean
fu_struct_wacom_usb_firmware_hdr_validate_stream(GInputStream *stream, gsize offset, GError **error)
{
    g_autoptr(FuStructWacomUsbFirmwareHdr) st = fu_struct_wacom_usb_firmware_hdr_new_internal();
    g_return_val_if_fail(G_IS_INPUT_STREAM(stream), FALSE);
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
    st->buf = fu_input_stream_read_byte_array(stream, offset, 5, NULL, error);
    if (st->buf == NULL) {
        g_prefix_error(error, "FuStructWacomUsbFirmwareHdr failed read of 0x%x: ", (guint) 5);
        return FALSE;
    }
    if (st->buf->len != 5) {
        g_set_error(error,
                    FWUPD_ERROR,
                    FWUPD_ERROR_INVALID_DATA,
                    "FuStructWacomUsbFirmwareHdr requested 0x%x and got 0x%x",
                    (guint) 5,
                    (guint) st->buf->len);
        return FALSE;
    }
    return fu_struct_wacom_usb_firmware_hdr_validate_internal(st, error);
}
/**
 * fu_struct_wta_block_header_ref: (skip):
 **/
FuStructWtaBlockHeader *
fu_struct_wta_block_header_ref(FuStructWtaBlockHeader *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_wta_block_header_unref: (skip):
 **/
void
fu_struct_wta_block_header_unref(FuStructWtaBlockHeader *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructWtaBlockHeader refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_wta_block_header_new_internal: (skip):
 **/
static FuStructWtaBlockHeader *
fu_struct_wta_block_header_new_internal(void)
{
    FuStructWtaBlockHeader *st = g_new0(FuStructWtaBlockHeader, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_wta_block_header_get_block_start: (skip):
 **/
guint32
fu_struct_wta_block_header_get_block_start(const FuStructWtaBlockHeader *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint32(st->buf->data + 0, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_wta_block_header_get_block_size: (skip):
 **/
guint32
fu_struct_wta_block_header_get_block_size(const FuStructWtaBlockHeader *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint32(st->buf->data + 4, G_LITTLE_ENDIAN);
}

/* setters */
/**
 * fu_struct_wta_block_header_to_string: (skip):
 **/
static gchar *
fu_struct_wta_block_header_to_string(const FuStructWtaBlockHeader *st)
{
    g_autoptr(GString) str = g_string_new("FuStructWtaBlockHeader:\n");
    g_return_val_if_fail(st != NULL, NULL);
    g_string_append_printf(str, "  block_start: 0x%x\n",
                           (guint) fu_struct_wta_block_header_get_block_start(st));
    g_string_append_printf(str, "  block_size: 0x%x\n",
                           (guint) fu_struct_wta_block_header_get_block_size(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_wta_block_header_validate_internal(FuStructWtaBlockHeader *st, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    return TRUE;
}
static gboolean
fu_struct_wta_block_header_parse_internal(FuStructWtaBlockHeader *st, GError **error)
{
    if (g_log_get_debug_enabled()) {
        g_autofree gchar *str = fu_struct_wta_block_header_to_string(st);
        g_debug("%s", str);
    }
    if (!fu_struct_wta_block_header_validate_internal(st, error))
        return FALSE;
    return TRUE;
}

/**
 * fu_struct_wta_block_header_parse: (skip):
 **/
FuStructWtaBlockHeader *
fu_struct_wta_block_header_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error)
{
    g_autoptr(FuStructWtaBlockHeader) st = fu_struct_wta_block_header_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 FuStructWtaBlockHeader: ");
        return NULL;
    }
    st->buf = g_byte_array_new();
    g_byte_array_append(st->buf, buf + offset, 8);
    if (!fu_struct_wta_block_header_parse_internal(st, error))
        return NULL;
    return g_steal_pointer(&st);
}
/**
 * fu_struct_wacom_usb_id9_unknown_cmd_ref: (skip):
 **/
FuStructWacomUsbId9UnknownCmd *
fu_struct_wacom_usb_id9_unknown_cmd_ref(FuStructWacomUsbId9UnknownCmd *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_wacom_usb_id9_unknown_cmd_unref: (skip):
 **/
void
fu_struct_wacom_usb_id9_unknown_cmd_unref(FuStructWacomUsbId9UnknownCmd *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructWacomUsbId9UnknownCmd refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_wacom_usb_id9_unknown_cmd_new_internal: (skip):
 **/
static FuStructWacomUsbId9UnknownCmd *
fu_struct_wacom_usb_id9_unknown_cmd_new_internal(void)
{
    FuStructWacomUsbId9UnknownCmd *st = g_new0(FuStructWacomUsbId9UnknownCmd, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_wacom_usb_id9_unknown_cmd_get_unknown1: (skip):
 **/
static guint16
fu_struct_wacom_usb_id9_unknown_cmd_get_unknown1(const FuStructWacomUsbId9UnknownCmd *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 0, G_BIG_ENDIAN);
}
/**
 * fu_struct_wacom_usb_id9_unknown_cmd_get_unknown2: (skip):
 **/
static guint32
fu_struct_wacom_usb_id9_unknown_cmd_get_unknown2(const FuStructWacomUsbId9UnknownCmd *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint32(st->buf->data + 2, G_BIG_ENDIAN);
}

/* setters */
/**
 * fu_struct_wacom_usb_id9_unknown_cmd_set_unknown1: (skip):
 **/
static void
fu_struct_wacom_usb_id9_unknown_cmd_set_unknown1(FuStructWacomUsbId9UnknownCmd *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 0, value, G_BIG_ENDIAN);
}
/**
 * fu_struct_wacom_usb_id9_unknown_cmd_set_unknown2: (skip):
 **/
static void
fu_struct_wacom_usb_id9_unknown_cmd_set_unknown2(FuStructWacomUsbId9UnknownCmd *st, guint32 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint32(st->buf->data + 2, value, G_BIG_ENDIAN);
}
/**
 * fu_struct_wacom_usb_id9_unknown_cmd_set_size: (skip):
 **/
void
fu_struct_wacom_usb_id9_unknown_cmd_set_size(FuStructWacomUsbId9UnknownCmd *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 6, value, G_BIG_ENDIAN);
}
/**
 * fu_struct_wacom_usb_id9_unknown_cmd_new: (skip):
 **/
FuStructWacomUsbId9UnknownCmd *
fu_struct_wacom_usb_id9_unknown_cmd_new(void)
{
    FuStructWacomUsbId9UnknownCmd *st = fu_struct_wacom_usb_id9_unknown_cmd_new_internal();
    st->buf = g_byte_array_sized_new(8);
    fu_byte_array_set_size(st->buf, 8, 0x0);
    fu_struct_wacom_usb_id9_unknown_cmd_set_unknown1(st, 0x7050);
    fu_struct_wacom_usb_id9_unknown_cmd_set_unknown2(st, 0);
    return st;
}
static gboolean
fu_struct_wacom_usb_id9_unknown_cmd_validate_internal(FuStructWacomUsbId9UnknownCmd *st, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    if (fu_struct_wacom_usb_id9_unknown_cmd_get_unknown1(st) != 0x7050) {
        g_set_error(error,
                    FWUPD_ERROR,
                    FWUPD_ERROR_INVALID_DATA,
                    "constant FuStructWacomUsbId9UnknownCmd.unknown1 was not valid, "
                    "expected 0x%x and got 0x%x",
                    (guint) 0x7050,
                    (guint) fu_struct_wacom_usb_id9_unknown_cmd_get_unknown1(st));
        return FALSE;
    }
    if (fu_struct_wacom_usb_id9_unknown_cmd_get_unknown2(st) != 0) {
        g_set_error(error,
                    FWUPD_ERROR,
                    FWUPD_ERROR_INVALID_DATA,
                    "constant FuStructWacomUsbId9UnknownCmd.unknown2 was not valid, "
                    "expected 0x%x and got 0x%x",
                    (guint) 0,
                    (guint) fu_struct_wacom_usb_id9_unknown_cmd_get_unknown2(st));
        return FALSE;
    }
    return TRUE;
}
/**
 * fu_struct_wacom_usb_id9_spi_cmd_ref: (skip):
 **/
FuStructWacomUsbId9SpiCmd *
fu_struct_wacom_usb_id9_spi_cmd_ref(FuStructWacomUsbId9SpiCmd *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_wacom_usb_id9_spi_cmd_unref: (skip):
 **/
void
fu_struct_wacom_usb_id9_spi_cmd_unref(FuStructWacomUsbId9SpiCmd *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructWacomUsbId9SpiCmd refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_wacom_usb_id9_spi_cmd_new_internal: (skip):
 **/
static FuStructWacomUsbId9SpiCmd *
fu_struct_wacom_usb_id9_spi_cmd_new_internal(void)
{
    FuStructWacomUsbId9SpiCmd *st = g_new0(FuStructWacomUsbId9SpiCmd, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_wacom_usb_id9_spi_cmd_get_command: (skip):
 **/
static guint8
fu_struct_wacom_usb_id9_spi_cmd_get_command(const FuStructWacomUsbId9SpiCmd *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[0];
}
/**
 * fu_struct_wacom_usb_id9_spi_cmd_get_start_addr: (skip):
 **/
static guint32
fu_struct_wacom_usb_id9_spi_cmd_get_start_addr(const FuStructWacomUsbId9SpiCmd *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint32(st->buf->data + 1, G_BIG_ENDIAN);
}

/* setters */
/**
 * fu_struct_wacom_usb_id9_spi_cmd_set_command: (skip):
 **/
static void
fu_struct_wacom_usb_id9_spi_cmd_set_command(FuStructWacomUsbId9SpiCmd *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[0] = value;
}
/**
 * fu_struct_wacom_usb_id9_spi_cmd_set_start_addr: (skip):
 **/
static void
fu_struct_wacom_usb_id9_spi_cmd_set_start_addr(FuStructWacomUsbId9SpiCmd *st, guint32 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint32(st->buf->data + 1, value, G_BIG_ENDIAN);
}
/**
 * fu_struct_wacom_usb_id9_spi_cmd_set_size: (skip):
 **/
void
fu_struct_wacom_usb_id9_spi_cmd_set_size(FuStructWacomUsbId9SpiCmd *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 5, value, G_BIG_ENDIAN);
}
/**
 * fu_struct_wacom_usb_id9_spi_cmd_set_data: (skip):
 **/
gboolean
fu_struct_wacom_usb_id9_spi_cmd_set_data(FuStructWacomUsbId9SpiCmd *st, const FuStructWacomUsbId9UnknownCmd *st_donor, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    g_return_val_if_fail(st_donor != NULL, FALSE);
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);

    if (st_donor->buf->len > FU_STRUCT_WACOM_USB_ID9_UNKNOWN_CMD_SIZE) {
        g_set_error(error,
                    FWUPD_ERROR,
                    FWUPD_ERROR_INVALID_DATA,
                    "donor 'FuStructWacomUsbId9UnknownCmd' (0x%x bytes) does not fit in "
                    "FuStructWacomUsbId9SpiCmd.data (0x%x bytes)",
                    (guint) st_donor->buf->len,
                    (guint) FU_STRUCT_WACOM_USB_ID9_UNKNOWN_CMD_SIZE);
        return FALSE;
    }
    memcpy(st->buf->data + FU_STRUCT_WACOM_USB_ID9_SPI_CMD_OFFSET_DATA, st_donor->buf->data, st_donor->buf->len);
    return TRUE;
}
/**
 * fu_struct_wacom_usb_id9_spi_cmd_new: (skip):
 **/
FuStructWacomUsbId9SpiCmd *
fu_struct_wacom_usb_id9_spi_cmd_new(void)
{
    FuStructWacomUsbId9SpiCmd *st = fu_struct_wacom_usb_id9_spi_cmd_new_internal();
    st->buf = g_byte_array_sized_new(15);
    fu_byte_array_set_size(st->buf, 15, 0x0);
    {
        g_autoptr(FuStructWacomUsbId9UnknownCmd) st_donor = fu_struct_wacom_usb_id9_unknown_cmd_new();
        memcpy(st->buf->data + 0x7, st_donor->buf->data, st_donor->buf->len); /* nocheck:blocked */
    }
    fu_struct_wacom_usb_id9_spi_cmd_set_command(st, 0x91);
    fu_struct_wacom_usb_id9_spi_cmd_set_start_addr(st, 0);
    return st;
}
static gboolean
fu_struct_wacom_usb_id9_spi_cmd_validate_internal(FuStructWacomUsbId9SpiCmd *st, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    if (fu_struct_wacom_usb_id9_spi_cmd_get_command(st) != 0x91) {
        g_set_error_literal(error,
                            FWUPD_ERROR,
                            FWUPD_ERROR_INVALID_DATA,
                            "constant FuStructWacomUsbId9SpiCmd.command was not valid");
        return FALSE;
    }
    if (fu_struct_wacom_usb_id9_spi_cmd_get_start_addr(st) != 0) {
        g_set_error(error,
                    FWUPD_ERROR,
                    FWUPD_ERROR_INVALID_DATA,
                    "constant FuStructWacomUsbId9SpiCmd.start_addr was not valid, "
                    "expected 0x%x and got 0x%x",
                    (guint) 0,
                    (guint) fu_struct_wacom_usb_id9_spi_cmd_get_start_addr(st));
        return FALSE;
    }
    {
        GByteArray buf_tmp = {
            .data = (guint8*) st->buf->data + 0x7,
            .len = 8,
        };
        FuStructWacomUsbId9UnknownCmd st_tmp = { .buf = &buf_tmp };
        if (!fu_struct_wacom_usb_id9_unknown_cmd_validate_internal(&st_tmp, error))
            return FALSE;
    }
    return TRUE;
}
/**
 * fu_struct_wacom_usb_id9_loader_cmd_ref: (skip):
 **/
FuStructWacomUsbId9LoaderCmd *
fu_struct_wacom_usb_id9_loader_cmd_ref(FuStructWacomUsbId9LoaderCmd *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_wacom_usb_id9_loader_cmd_unref: (skip):
 **/
void
fu_struct_wacom_usb_id9_loader_cmd_unref(FuStructWacomUsbId9LoaderCmd *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructWacomUsbId9LoaderCmd refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_wacom_usb_id9_loader_cmd_new_internal: (skip):
 **/
static FuStructWacomUsbId9LoaderCmd *
fu_struct_wacom_usb_id9_loader_cmd_new_internal(void)
{
    FuStructWacomUsbId9LoaderCmd *st = g_new0(FuStructWacomUsbId9LoaderCmd, 1);
    st->refcount = 1;
    return st;
}

/* getters */

/* setters */
/**
 * fu_struct_wacom_usb_id9_loader_cmd_set_command: (skip):
 **/
void
fu_struct_wacom_usb_id9_loader_cmd_set_command(FuStructWacomUsbId9LoaderCmd *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[0] = value;
}
/**
 * fu_struct_wacom_usb_id9_loader_cmd_set_size: (skip):
 **/
void
fu_struct_wacom_usb_id9_loader_cmd_set_size(FuStructWacomUsbId9LoaderCmd *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 1, value, G_BIG_ENDIAN);
}
/**
 * fu_struct_wacom_usb_id9_loader_cmd_set_crc: (skip):
 **/
void
fu_struct_wacom_usb_id9_loader_cmd_set_crc(FuStructWacomUsbId9LoaderCmd *st, guint32 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint32(st->buf->data + 3, value, G_BIG_ENDIAN);
}
/**
 * fu_struct_wacom_usb_id9_loader_cmd_set_data: (skip):
 **/
gboolean
fu_struct_wacom_usb_id9_loader_cmd_set_data(FuStructWacomUsbId9LoaderCmd *st, const FuStructWacomUsbId9SpiCmd *st_donor, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    g_return_val_if_fail(st_donor != NULL, FALSE);
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);

    if (st_donor->buf->len > FU_STRUCT_WACOM_USB_ID9_SPI_CMD_SIZE) {
        g_set_error(error,
                    FWUPD_ERROR,
                    FWUPD_ERROR_INVALID_DATA,
                    "donor 'FuStructWacomUsbId9SpiCmd' (0x%x bytes) does not fit in "
                    "FuStructWacomUsbId9LoaderCmd.data (0x%x bytes)",
                    (guint) st_donor->buf->len,
                    (guint) FU_STRUCT_WACOM_USB_ID9_SPI_CMD_SIZE);
        return FALSE;
    }
    memcpy(st->buf->data + FU_STRUCT_WACOM_USB_ID9_LOADER_CMD_OFFSET_DATA, st_donor->buf->data, st_donor->buf->len);
    return TRUE;
}
/**
 * fu_struct_wacom_usb_id9_loader_cmd_new: (skip):
 **/
FuStructWacomUsbId9LoaderCmd *
fu_struct_wacom_usb_id9_loader_cmd_new(void)
{
    FuStructWacomUsbId9LoaderCmd *st = fu_struct_wacom_usb_id9_loader_cmd_new_internal();
    st->buf = g_byte_array_sized_new(22);
    fu_byte_array_set_size(st->buf, 22, 0x0);
    {
        g_autoptr(FuStructWacomUsbId9SpiCmd) st_donor = fu_struct_wacom_usb_id9_spi_cmd_new();
        memcpy(st->buf->data + 0x7, st_donor->buf->data, st_donor->buf->len); /* nocheck:blocked */
    }
    return st;
}
/**
 * fu_struct_wacom_usb_id9_loader_cmd_to_bytes: (skip):
 **/
GBytes *
fu_struct_wacom_usb_id9_loader_cmd_to_bytes(const FuStructWacomUsbId9LoaderCmd *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    return g_bytes_new(st->buf->data, st->buf->len);
}
static gboolean
fu_struct_wacom_usb_id9_loader_cmd_validate_internal(FuStructWacomUsbId9LoaderCmd *st, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    {
        GByteArray buf_tmp = {
            .data = (guint8*) st->buf->data + 0x7,
            .len = 15,
        };
        FuStructWacomUsbId9SpiCmd st_tmp = { .buf = &buf_tmp };
        if (!fu_struct_wacom_usb_id9_spi_cmd_validate_internal(&st_tmp, error))
            return FALSE;
    }
    return TRUE;
}
/**
 * fu_struct_wacom_usb_id9_loader_cmd_validate: (skip):
 **/
gboolean
fu_struct_wacom_usb_id9_loader_cmd_validate(const guint8 *buf, gsize bufsz, gsize offset, GError **error)
{
    GByteArray st_buf = {.data = (guint8 *) buf + offset, .len = bufsz - offset, };
    FuStructWacomUsbId9LoaderCmd st_tmp = {.buf = &st_buf };
    g_return_val_if_fail(buf != NULL, FALSE);
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
    if (!fu_memchk_read(bufsz, offset, 22, error)) {
        g_prefix_error_literal(error, "invalid struct FuStructWacomUsbId9LoaderCmd: ");
        return FALSE;
    }
    if (!fu_struct_wacom_usb_id9_loader_cmd_validate_internal(&st_tmp, error))
        return FALSE;
    return TRUE;
}
/**
 * fu_struct_wacom_usb_module_desc_ref: (skip):
 **/
FuStructWacomUsbModuleDesc *
fu_struct_wacom_usb_module_desc_ref(FuStructWacomUsbModuleDesc *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_wacom_usb_module_desc_unref: (skip):
 **/
void
fu_struct_wacom_usb_module_desc_unref(FuStructWacomUsbModuleDesc *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructWacomUsbModuleDesc refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_wacom_usb_module_desc_new_internal: (skip):
 **/
static FuStructWacomUsbModuleDesc *
fu_struct_wacom_usb_module_desc_new_internal(void)
{
    FuStructWacomUsbModuleDesc *st = g_new0(FuStructWacomUsbModuleDesc, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_wacom_usb_module_desc_get_bootloader_version: (skip):
 **/
guint16
fu_struct_wacom_usb_module_desc_get_bootloader_version(const FuStructWacomUsbModuleDesc *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 1, G_BIG_ENDIAN);
}
/**
 * fu_struct_wacom_usb_module_desc_get_number_modules: (skip):
 **/
guint8
fu_struct_wacom_usb_module_desc_get_number_modules(const FuStructWacomUsbModuleDesc *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[3];
}

/* setters */
/**
 * fu_struct_wacom_usb_module_desc_to_string: (skip):
 **/
static gchar *
fu_struct_wacom_usb_module_desc_to_string(const FuStructWacomUsbModuleDesc *st)
{
    g_autoptr(GString) str = g_string_new("FuStructWacomUsbModuleDesc:\n");
    g_return_val_if_fail(st != NULL, NULL);
    g_string_append_printf(str, "  bootloader_version: 0x%x\n",
                           (guint) fu_struct_wacom_usb_module_desc_get_bootloader_version(st));
    g_string_append_printf(str, "  number_modules: 0x%x\n",
                           (guint) fu_struct_wacom_usb_module_desc_get_number_modules(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_wacom_usb_module_desc_validate_internal(FuStructWacomUsbModuleDesc *st, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    return TRUE;
}
static gboolean
fu_struct_wacom_usb_module_desc_parse_internal(FuStructWacomUsbModuleDesc *st, GError **error)
{
    if (g_log_get_debug_enabled()) {
        g_autofree gchar *str = fu_struct_wacom_usb_module_desc_to_string(st);
        g_debug("%s", str);
    }
    if (!fu_struct_wacom_usb_module_desc_validate_internal(st, error))
        return FALSE;
    return TRUE;
}

/**
 * fu_struct_wacom_usb_module_desc_parse: (skip):
 **/
FuStructWacomUsbModuleDesc *
fu_struct_wacom_usb_module_desc_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error)
{
    g_autoptr(FuStructWacomUsbModuleDesc) st = fu_struct_wacom_usb_module_desc_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, 4, error)) {
        g_prefix_error_literal(error, "invalid struct FuStructWacomUsbModuleDesc: ");
        return NULL;
    }
    st->buf = g_byte_array_new();
    g_byte_array_append(st->buf, buf + offset, 4);
    if (!fu_struct_wacom_usb_module_desc_parse_internal(st, error))
        return NULL;
    return g_steal_pointer(&st);
}
/**
 * fu_struct_wacom_usb_module_item_ref: (skip):
 **/
FuStructWacomUsbModuleItem *
fu_struct_wacom_usb_module_item_ref(FuStructWacomUsbModuleItem *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_wacom_usb_module_item_unref: (skip):
 **/
void
fu_struct_wacom_usb_module_item_unref(FuStructWacomUsbModuleItem *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructWacomUsbModuleItem refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_wacom_usb_module_item_new_internal: (skip):
 **/
static FuStructWacomUsbModuleItem *
fu_struct_wacom_usb_module_item_new_internal(void)
{
    FuStructWacomUsbModuleItem *st = g_new0(FuStructWacomUsbModuleItem, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_wacom_usb_module_item_get_kind: (skip):
 **/
FuWacomUsbModuleFwType
fu_struct_wacom_usb_module_item_get_kind(const FuStructWacomUsbModuleItem *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[0];
}
/**
 * fu_struct_wacom_usb_module_item_get_version: (skip):
 **/
guint16
fu_struct_wacom_usb_module_item_get_version(const FuStructWacomUsbModuleItem *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 1, G_BIG_ENDIAN);
}
/**
 * fu_struct_wacom_usb_module_item_get_version2: (skip):
 **/
guint8
fu_struct_wacom_usb_module_item_get_version2(const FuStructWacomUsbModuleItem *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[3];
}

/* setters */
/**
 * fu_struct_wacom_usb_module_item_to_string: (skip):
 **/
static gchar *
fu_struct_wacom_usb_module_item_to_string(const FuStructWacomUsbModuleItem *st)
{
    g_autoptr(GString) str = g_string_new("FuStructWacomUsbModuleItem:\n");
    g_return_val_if_fail(st != NULL, NULL);
    {
        const gchar *tmp = fu_wacom_usb_module_fw_type_to_string(fu_struct_wacom_usb_module_item_get_kind(st));
        if (tmp != NULL) {
            g_string_append_printf(str, "  kind: 0x%x [%s]\n", (guint) fu_struct_wacom_usb_module_item_get_kind(st), tmp);
        } else {
            g_string_append_printf(str, "  kind: 0x%x\n", (guint) fu_struct_wacom_usb_module_item_get_kind(st));
        }
    }
    g_string_append_printf(str, "  version: 0x%x\n",
                           (guint) fu_struct_wacom_usb_module_item_get_version(st));
    g_string_append_printf(str, "  version2: 0x%x\n",
                           (guint) fu_struct_wacom_usb_module_item_get_version2(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_wacom_usb_module_item_validate_internal(FuStructWacomUsbModuleItem *st, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    return TRUE;
}
static gboolean
fu_struct_wacom_usb_module_item_parse_internal(FuStructWacomUsbModuleItem *st, GError **error)
{
    if (g_log_get_debug_enabled()) {
        g_autofree gchar *str = fu_struct_wacom_usb_module_item_to_string(st);
        g_debug("%s", str);
    }
    if (!fu_struct_wacom_usb_module_item_validate_internal(st, error))
        return FALSE;
    return TRUE;
}

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