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

#include "fu-intel-usb4-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"

static const gchar *
fu_intel_usb4_opcode_to_string(FuIntelUsb4Opcode val)
{
    if (val == FU_INTEL_USB4_OPCODE_NVM_WRITE)
        return "nvm-write";
    if (val == FU_INTEL_USB4_OPCODE_NVM_AUTH_WRITE)
        return "nvm-auth-write";
    if (val == FU_INTEL_USB4_OPCODE_NVM_READ)
        return "nvm-read";
    if (val == FU_INTEL_USB4_OPCODE_NVM_SET_OFFSET)
        return "nvm-set-offset";
    if (val == FU_INTEL_USB4_OPCODE_DROM_READ)
        return "drom-read";
    return NULL;
}
/* getters */
/**
 * fu_struct_intel_usb4_mbox_get_opcode: (skip):
 **/
FuIntelUsb4Opcode
fu_struct_intel_usb4_mbox_get_opcode(const GByteArray *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->data + 0, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_intel_usb4_mbox_get_status: (skip):
 **/
guint8
fu_struct_intel_usb4_mbox_get_status(const GByteArray *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->data[3];
}

/* setters */
/**
 * fu_struct_intel_usb4_mbox_set_opcode: (skip):
 **/
void
fu_struct_intel_usb4_mbox_set_opcode(GByteArray *st, FuIntelUsb4Opcode value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->data + 0, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_intel_usb4_mbox_set_status: (skip):
 **/
void
fu_struct_intel_usb4_mbox_set_status(GByteArray *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->data[3] = value;
}
/**
 * fu_struct_intel_usb4_mbox_new: (skip):
 **/
GByteArray *
fu_struct_intel_usb4_mbox_new(void)
{
    GByteArray *st = g_byte_array_sized_new(4);
    fu_byte_array_set_size(st, 4, 0x0);
    return st;
}
/**
 * fu_struct_intel_usb4_mbox_to_string: (skip):
 **/
static gchar *
fu_struct_intel_usb4_mbox_to_string(const GByteArray *st)
{
    g_autoptr(GString) str = g_string_new("IntelUsb4Mbox:\n");
    g_return_val_if_fail(st != NULL, NULL);
    {
        const gchar *tmp = fu_intel_usb4_opcode_to_string(fu_struct_intel_usb4_mbox_get_opcode(st));
        if (tmp != NULL) {
            g_string_append_printf(str, "  opcode: 0x%x [%s]\n", (guint) fu_struct_intel_usb4_mbox_get_opcode(st), tmp);
        } else {
            g_string_append_printf(str, "  opcode: 0x%x\n", (guint) fu_struct_intel_usb4_mbox_get_opcode(st));
        }
    }
    g_string_append_printf(str, "  status: 0x%x\n",
                           (guint) fu_struct_intel_usb4_mbox_get_status(st));
    if (str->len > 0)
        g_string_set_size(str, str->len - 1);
    return g_string_free(g_steal_pointer(&str), FALSE);
}
/**
 * fu_struct_intel_usb4_mbox_parse: (skip):
 **/
GByteArray *
fu_struct_intel_usb4_mbox_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, 4, error)) {
        g_prefix_error(error, "invalid struct IntelUsb4Mbox: ");
        return NULL;
    }
    g_byte_array_append(st, buf + offset, 4);
    str = fu_struct_intel_usb4_mbox_to_string(st);
    g_debug("%s", str);
    return g_steal_pointer(&st);
}
