/* auto-generated, do not modify */
#include "config.h"

#include "fu-usi-dock-struct.h"
#include "fu-byte-array.h"
#include "fu-mem-private.h"
#include "fu-string.h"

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

const gchar *
fu_usi_dock_spi_state_to_string(FuUsiDockSpiState val)
{
    if (val == FU_USI_DOCK_SPI_STATE_NONE)
        return "none";
    if (val == FU_USI_DOCK_SPI_STATE_SWITCH_SUCCESS)
        return "switch-success";
    if (val == FU_USI_DOCK_SPI_STATE_SWITCH_FAIL)
        return "switch-fail";
    if (val == FU_USI_DOCK_SPI_STATE_CMD_SUCCESS)
        return "cmd-success";
    if (val == FU_USI_DOCK_SPI_STATE_CMD_FAIL)
        return "cmd-fail";
    if (val == FU_USI_DOCK_SPI_STATE_RW_SUCCESS)
        return "rw-success";
    if (val == FU_USI_DOCK_SPI_STATE_RW_FAIL)
        return "rw-fail";
    if (val == FU_USI_DOCK_SPI_STATE_READY)
        return "ready";
    if (val == FU_USI_DOCK_SPI_STATE_BUSY)
        return "busy";
    if (val == FU_USI_DOCK_SPI_STATE_TIMEOUT)
        return "timeout";
    if (val == FU_USI_DOCK_SPI_STATE_FLASH_FOUND)
        return "flash-found";
    if (val == FU_USI_DOCK_SPI_STATE_FLASH_NOT_FOUND)
        return "flash-not-found";
    return NULL;
}


static const gchar *
fu_usi_dock_tag2_to_string(FuUsiDockTag2 val)
{
    if (val == FU_USI_DOCK_TAG2_ISP_BOOT)
        return "isp-boot";
    if (val == FU_USI_DOCK_TAG2_ISP)
        return "isp";
    if (val == FU_USI_DOCK_TAG2_CMD_MCU)
        return "cmd-mcu";
    if (val == FU_USI_DOCK_TAG2_CMD_SPI)
        return "cmd-spi";
    if (val == FU_USI_DOCK_TAG2_CMD_I2C)
        return "cmd-i2c";
    if (val == FU_USI_DOCK_TAG2_MASS_DATA_MCU)
        return "mass-data-mcu";
    if (val == FU_USI_DOCK_TAG2_MASS_DATA_SPI)
        return "mass-data-spi";
    if (val == FU_USI_DOCK_TAG2_MASS_DATA_I2C)
        return "mass-data-i2c";
    return NULL;
}

static const gchar *
fu_usi_dock_mcu_cmd_to_string(FuUsiDockMcuCmd val)
{
    if (val == FU_USI_DOCK_MCU_CMD_MCU_NONE)
        return "mcu-none";
    if (val == FU_USI_DOCK_MCU_CMD_MCU_STATUS)
        return "mcu-status";
    if (val == FU_USI_DOCK_MCU_CMD_MCU_JUMP2BOOT)
        return "mcu-jump2boot";
    if (val == FU_USI_DOCK_MCU_CMD_READ_MCU_VERSIONPAGE)
        return "read-mcu-versionpage";
    if (val == FU_USI_DOCK_MCU_CMD_SET_I225_PWR)
        return "set-i225-pwr";
    if (val == FU_USI_DOCK_MCU_CMD_DOCK_RESET)
        return "dock-reset";
    if (val == FU_USI_DOCK_MCU_CMD_VERSION_WRITEBACK)
        return "version-writeback";
    if (val == FU_USI_DOCK_MCU_CMD_SET_CHIP_TYPE)
        return "set-chip-type";
    if (val == FU_USI_DOCK_MCU_CMD_FW_INITIAL)
        return "fw-initial";
    if (val == FU_USI_DOCK_MCU_CMD_FW_UPDATE)
        return "fw-update";
    if (val == FU_USI_DOCK_MCU_CMD_FW_TARGET_CHECKSUM)
        return "fw-target-checksum";
    if (val == FU_USI_DOCK_MCU_CMD_FW_ISP_END)
        return "fw-isp-end";
    if (val == FU_USI_DOCK_MCU_CMD_ALL)
        return "all";
    return NULL;
}

/* getters */

/* setters */
/**
 * fu_struct_usi_dock_hid_req_set_id: (skip):
 **/
static void
fu_struct_usi_dock_hid_req_set_id(GByteArray *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->data[0] = value;
}
/**
 * fu_struct_usi_dock_hid_req_set_length: (skip):
 **/
void
fu_struct_usi_dock_hid_req_set_length(GByteArray *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->data[1] = value;
}
/**
 * fu_struct_usi_dock_hid_req_set_buf: (skip):
 **/
gboolean
fu_struct_usi_dock_hid_req_set_buf(GByteArray *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->data, st->len, 2, buf, bufsz, 0x0, bufsz, error);
}
/**
 * fu_struct_usi_dock_hid_req_set_tag3: (skip):
 **/
void
fu_struct_usi_dock_hid_req_set_tag3(GByteArray *st, FuUsiDockTag2 value)
{
    g_return_if_fail(st != NULL);
    st->data[63] = value;
}
/**
 * fu_struct_usi_dock_hid_req_new: (skip):
 **/
GByteArray *
fu_struct_usi_dock_hid_req_new(void)
{
    GByteArray *st = g_byte_array_sized_new(64);
    fu_byte_array_set_size(st, 64, 0x0);
    fu_struct_usi_dock_hid_req_set_id(st, 2);
    return st;
}
/* getters */

/* setters */
/**
 * fu_struct_usi_dock_mcu_cmd_req_set_id: (skip):
 **/
static void
fu_struct_usi_dock_mcu_cmd_req_set_id(GByteArray *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->data[0] = value;
}
/**
 * fu_struct_usi_dock_mcu_cmd_req_set_length: (skip):
 **/
void
fu_struct_usi_dock_mcu_cmd_req_set_length(GByteArray *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->data[1] = value;
}
/**
 * fu_struct_usi_dock_mcu_cmd_req_set_tag1: (skip):
 **/
static void
fu_struct_usi_dock_mcu_cmd_req_set_tag1(GByteArray *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->data[2] = value;
}
/**
 * fu_struct_usi_dock_mcu_cmd_req_set_tag2: (skip):
 **/
static void
fu_struct_usi_dock_mcu_cmd_req_set_tag2(GByteArray *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->data[3] = value;
}
/**
 * fu_struct_usi_dock_mcu_cmd_req_set_buf: (skip):
 **/
gboolean
fu_struct_usi_dock_mcu_cmd_req_set_buf(GByteArray *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->data, st->len, 4, buf, bufsz, 0x0, bufsz, error);
}
/**
 * fu_struct_usi_dock_mcu_cmd_req_set_tag3: (skip):
 **/
void
fu_struct_usi_dock_mcu_cmd_req_set_tag3(GByteArray *st, FuUsiDockTag2 value)
{
    g_return_if_fail(st != NULL);
    st->data[63] = value;
}
/**
 * fu_struct_usi_dock_mcu_cmd_req_new: (skip):
 **/
GByteArray *
fu_struct_usi_dock_mcu_cmd_req_new(void)
{
    GByteArray *st = g_byte_array_sized_new(64);
    fu_byte_array_set_size(st, 64, 0x0);
    fu_struct_usi_dock_mcu_cmd_req_set_id(st, 2);
    fu_struct_usi_dock_mcu_cmd_req_set_tag1(st, 0xFE);
    fu_struct_usi_dock_mcu_cmd_req_set_tag2(st, 0xFF);
    return st;
}
/* getters */
/**
 * fu_struct_usi_dock_mcu_cmd_res_get_id: (skip):
 **/
static guint8
fu_struct_usi_dock_mcu_cmd_res_get_id(const GByteArray *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->data[0];
}
/**
 * fu_struct_usi_dock_mcu_cmd_res_get_cmd1: (skip):
 **/
FuUsiDockMcuCmd
fu_struct_usi_dock_mcu_cmd_res_get_cmd1(const GByteArray *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->data[1];
}
/**
 * fu_struct_usi_dock_mcu_cmd_res_get_tag1: (skip):
 **/
static guint8
fu_struct_usi_dock_mcu_cmd_res_get_tag1(const GByteArray *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->data[2];
}
/**
 * fu_struct_usi_dock_mcu_cmd_res_get_tag2: (skip):
 **/
static guint8
fu_struct_usi_dock_mcu_cmd_res_get_tag2(const GByteArray *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->data[3];
}
/**
 * fu_struct_usi_dock_mcu_cmd_res_get_cmd2: (skip):
 **/
FuUsiDockMcuCmd
fu_struct_usi_dock_mcu_cmd_res_get_cmd2(const GByteArray *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->data[4];
}
/**
 * fu_struct_usi_dock_mcu_cmd_res_get_buf: (skip):
 **/
const guint8 *
fu_struct_usi_dock_mcu_cmd_res_get_buf(const GByteArray *st, gsize *bufsz)
{
    g_return_val_if_fail(st != NULL, NULL);
    if (bufsz != NULL)
        *bufsz = 58;
    return st->data + 5;
}
/**
 * fu_struct_usi_dock_mcu_cmd_res_get_tag3: (skip):
 **/
FuUsiDockTag2
fu_struct_usi_dock_mcu_cmd_res_get_tag3(const GByteArray *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->data[63];
}

/* setters */
/**
 * fu_struct_usi_dock_mcu_cmd_res_to_string: (skip):
 **/
static gchar *
fu_struct_usi_dock_mcu_cmd_res_to_string(const GByteArray *st)
{
    g_autoptr(GString) str = g_string_new("UsiDockMcuCmdRes:\n");
    g_return_val_if_fail(st != NULL, NULL);
    {
        const gchar *tmp = fu_usi_dock_mcu_cmd_to_string(fu_struct_usi_dock_mcu_cmd_res_get_cmd1(st));
        if (tmp != NULL) {
            g_string_append_printf(str, "  cmd1: 0x%x [%s]\n", (guint) fu_struct_usi_dock_mcu_cmd_res_get_cmd1(st), tmp);
        } else {
            g_string_append_printf(str, "  cmd1: 0x%x\n", (guint) fu_struct_usi_dock_mcu_cmd_res_get_cmd1(st));
        }
    }
    {
        const gchar *tmp = fu_usi_dock_mcu_cmd_to_string(fu_struct_usi_dock_mcu_cmd_res_get_cmd2(st));
        if (tmp != NULL) {
            g_string_append_printf(str, "  cmd2: 0x%x [%s]\n", (guint) fu_struct_usi_dock_mcu_cmd_res_get_cmd2(st), tmp);
        } else {
            g_string_append_printf(str, "  cmd2: 0x%x\n", (guint) fu_struct_usi_dock_mcu_cmd_res_get_cmd2(st));
        }
    }
    {
        gsize bufsz = 0;
        const guint8 *buf = fu_struct_usi_dock_mcu_cmd_res_get_buf(st, &bufsz);
        g_autoptr(GString) tmp = g_string_new(NULL);
        for (gsize i = 0; i < bufsz; i++)
            g_string_append_printf(tmp, "%02X", buf[i]);
        g_string_append_printf(str, "  buf: 0x%s\n", tmp->str);
    }
    {
        const gchar *tmp = fu_usi_dock_tag2_to_string(fu_struct_usi_dock_mcu_cmd_res_get_tag3(st));
        if (tmp != NULL) {
            g_string_append_printf(str, "  tag3: 0x%x [%s]\n", (guint) fu_struct_usi_dock_mcu_cmd_res_get_tag3(st), tmp);
        } else {
            g_string_append_printf(str, "  tag3: 0x%x\n", (guint) fu_struct_usi_dock_mcu_cmd_res_get_tag3(st));
        }
    }
    if (str->len > 0)
        g_string_set_size(str, str->len - 1);
    return g_string_free(g_steal_pointer(&str), FALSE);
}
/**
 * fu_struct_usi_dock_mcu_cmd_res_parse: (skip):
 **/
GByteArray *
fu_struct_usi_dock_mcu_cmd_res_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error)
{
    g_autoptr(GByteArray) st = g_byte_array_new();
    g_autofree gchar *str = NULL;
    g_return_val_if_fail(buf != NULL, NULL);
    g_return_val_if_fail(error == NULL || *error == NULL, NULL);
    if (!fu_memchk_read(bufsz, offset, 64, error)) {
        g_prefix_error(error, "invalid struct UsiDockMcuCmdRes: ");
        return NULL;
    }
    g_byte_array_append(st, buf + offset, 64);
    if (fu_struct_usi_dock_mcu_cmd_res_get_id(st) != 2) {
        g_set_error_literal(error,
                            G_IO_ERROR,
                            G_IO_ERROR_INVALID_DATA,
                            "constant UsiDockMcuCmdRes.id was not valid, expected 2");
        return NULL;
    }
    if (fu_struct_usi_dock_mcu_cmd_res_get_tag1(st) != 0xFE) {
        g_set_error_literal(error,
                            G_IO_ERROR,
                            G_IO_ERROR_INVALID_DATA,
                            "constant UsiDockMcuCmdRes.tag1 was not valid, expected 0xFE");
        return NULL;
    }
    if (fu_struct_usi_dock_mcu_cmd_res_get_tag2(st) != 0xFF) {
        g_set_error_literal(error,
                            G_IO_ERROR,
                            G_IO_ERROR_INVALID_DATA,
                            "constant UsiDockMcuCmdRes.tag2 was not valid, expected 0xFF");
        return NULL;
    }
    str = fu_struct_usi_dock_mcu_cmd_res_to_string(st);
    g_debug("%s", str);
    return g_steal_pointer(&st);
}
/* getters */

/* setters */
