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

#include "config.h"

#include <glib.h>

#include "fu-dell-kestrel-hid-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_dell_kestrel_hid_ec_chunk_response_to_string:
 * @val: value, e.g. %FU_DELL_KESTREL_HID_EC_CHUNK_RESPONSE_UPDATE_COMPLETE
 *
 * Converts an enumerated value to a string.
 *
 * Returns: identifier string
 **/
const gchar *
fu_dell_kestrel_hid_ec_chunk_response_to_string(FuDellKestrelHidEcChunkResponse val)
{
    if (val == FU_DELL_KESTREL_HID_EC_CHUNK_RESPONSE_UPDATE_COMPLETE)
        return "update-complete";
    if (val == FU_DELL_KESTREL_HID_EC_CHUNK_RESPONSE_SEND_NEXT_CHUNK)
        return "send-next-chunk";
    if (val == FU_DELL_KESTREL_HID_EC_CHUNK_RESPONSE_UPDATE_FAILED)
        return "update-failed";
    return NULL;
}
/**
 * fu_struct_dell_kestrel_hid_cmd_buffer_ref: (skip):
 **/
FuStructDellKestrelHidCmdBuffer *
fu_struct_dell_kestrel_hid_cmd_buffer_ref(FuStructDellKestrelHidCmdBuffer *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_dell_kestrel_hid_cmd_buffer_unref: (skip):
 **/
void
fu_struct_dell_kestrel_hid_cmd_buffer_unref(FuStructDellKestrelHidCmdBuffer *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructDellKestrelHidCmdBuffer refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_dell_kestrel_hid_cmd_buffer_new_internal: (skip):
 **/
static FuStructDellKestrelHidCmdBuffer *
fu_struct_dell_kestrel_hid_cmd_buffer_new_internal(void)
{
    FuStructDellKestrelHidCmdBuffer *st = g_new0(FuStructDellKestrelHidCmdBuffer, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_dell_kestrel_hid_cmd_buffer_get_cmd: (skip):
 **/
guint8
fu_struct_dell_kestrel_hid_cmd_buffer_get_cmd(const FuStructDellKestrelHidCmdBuffer *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[0];
}
/**
 * fu_struct_dell_kestrel_hid_cmd_buffer_get_ext: (skip):
 **/
guint8
fu_struct_dell_kestrel_hid_cmd_buffer_get_ext(const FuStructDellKestrelHidCmdBuffer *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[1];
}
/**
 * fu_struct_dell_kestrel_hid_cmd_buffer_get_dwregaddr: (skip):
 **/
guint32
fu_struct_dell_kestrel_hid_cmd_buffer_get_dwregaddr(const FuStructDellKestrelHidCmdBuffer *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint32(st->buf->data + 2, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_dell_kestrel_hid_cmd_buffer_get_bufferlen: (skip):
 **/
guint16
fu_struct_dell_kestrel_hid_cmd_buffer_get_bufferlen(const FuStructDellKestrelHidCmdBuffer *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 6, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_dell_kestrel_hid_cmd_buffer_get_parameters: (skip):
 **/
const guint8 *
fu_struct_dell_kestrel_hid_cmd_buffer_get_parameters(const FuStructDellKestrelHidCmdBuffer *st, gsize *bufsz)
{
    g_return_val_if_fail(st != NULL, NULL);
    if (bufsz != NULL)
        *bufsz = 3;
    return st->buf->data + 8;
}
/**
 * fu_struct_dell_kestrel_hid_cmd_buffer_get_extended_cmdarea: (skip):
 **/
const guint8 *
fu_struct_dell_kestrel_hid_cmd_buffer_get_extended_cmdarea(const FuStructDellKestrelHidCmdBuffer *st, gsize *bufsz)
{
    g_return_val_if_fail(st != NULL, NULL);
    if (bufsz != NULL)
        *bufsz = 53;
    return st->buf->data + 11;
}
/**
 * fu_struct_dell_kestrel_hid_cmd_buffer_get_databytes: (skip):
 **/
const guint8 *
fu_struct_dell_kestrel_hid_cmd_buffer_get_databytes(const FuStructDellKestrelHidCmdBuffer *st, gsize *bufsz)
{
    g_return_val_if_fail(st != NULL, NULL);
    if (bufsz != NULL)
        *bufsz = 128;
    return st->buf->data + 64;
}

/* setters */
/**
 * fu_struct_dell_kestrel_hid_cmd_buffer_set_cmd: (skip):
 **/
void
fu_struct_dell_kestrel_hid_cmd_buffer_set_cmd(FuStructDellKestrelHidCmdBuffer *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[0] = value;
}
/**
 * fu_struct_dell_kestrel_hid_cmd_buffer_set_ext: (skip):
 **/
void
fu_struct_dell_kestrel_hid_cmd_buffer_set_ext(FuStructDellKestrelHidCmdBuffer *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[1] = value;
}
/**
 * fu_struct_dell_kestrel_hid_cmd_buffer_set_dwregaddr: (skip):
 **/
void
fu_struct_dell_kestrel_hid_cmd_buffer_set_dwregaddr(FuStructDellKestrelHidCmdBuffer *st, guint32 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint32(st->buf->data + 2, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_dell_kestrel_hid_cmd_buffer_set_bufferlen: (skip):
 **/
void
fu_struct_dell_kestrel_hid_cmd_buffer_set_bufferlen(FuStructDellKestrelHidCmdBuffer *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 6, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_dell_kestrel_hid_cmd_buffer_set_parameters: (skip):
 **/
gboolean
fu_struct_dell_kestrel_hid_cmd_buffer_set_parameters(FuStructDellKestrelHidCmdBuffer *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, 8, buf, bufsz, 0x0, bufsz, error);
}
/**
 * fu_struct_dell_kestrel_hid_cmd_buffer_set_extended_cmdarea: (skip):
 **/
gboolean
fu_struct_dell_kestrel_hid_cmd_buffer_set_extended_cmdarea(FuStructDellKestrelHidCmdBuffer *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, 11, buf, bufsz, 0x0, bufsz, error);
}
/**
 * fu_struct_dell_kestrel_hid_cmd_buffer_set_databytes: (skip):
 **/
gboolean
fu_struct_dell_kestrel_hid_cmd_buffer_set_databytes(FuStructDellKestrelHidCmdBuffer *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, 64, buf, bufsz, 0x0, bufsz, error);
}
/**
 * fu_struct_dell_kestrel_hid_cmd_buffer_new: (skip):
 **/
FuStructDellKestrelHidCmdBuffer *
fu_struct_dell_kestrel_hid_cmd_buffer_new(void)
{
    FuStructDellKestrelHidCmdBuffer *st = fu_struct_dell_kestrel_hid_cmd_buffer_new_internal();
    st->buf = g_byte_array_sized_new(192);
    fu_byte_array_set_size(st->buf, 192, 0x0);
    memcpy(st->buf->data + 0x8, "\xEC\x01\x80", 3); /* nocheck:blocked */
    return st;
}
/**
 * fu_struct_dell_kestrel_hid_fw_update_pkg_ref: (skip):
 **/
FuStructDellKestrelHidFwUpdatePkg *
fu_struct_dell_kestrel_hid_fw_update_pkg_ref(FuStructDellKestrelHidFwUpdatePkg *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_dell_kestrel_hid_fw_update_pkg_unref: (skip):
 **/
void
fu_struct_dell_kestrel_hid_fw_update_pkg_unref(FuStructDellKestrelHidFwUpdatePkg *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructDellKestrelHidFwUpdatePkg refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_dell_kestrel_hid_fw_update_pkg_new_internal: (skip):
 **/
static FuStructDellKestrelHidFwUpdatePkg *
fu_struct_dell_kestrel_hid_fw_update_pkg_new_internal(void)
{
    FuStructDellKestrelHidFwUpdatePkg *st = g_new0(FuStructDellKestrelHidFwUpdatePkg, 1);
    st->refcount = 1;
    return st;
}

/* getters */

/* setters */
/**
 * fu_struct_dell_kestrel_hid_fw_update_pkg_set_cmd: (skip):
 **/
void
fu_struct_dell_kestrel_hid_fw_update_pkg_set_cmd(FuStructDellKestrelHidFwUpdatePkg *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[0] = value;
}
/**
 * fu_struct_dell_kestrel_hid_fw_update_pkg_set_ext: (skip):
 **/
void
fu_struct_dell_kestrel_hid_fw_update_pkg_set_ext(FuStructDellKestrelHidFwUpdatePkg *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[1] = value;
}
/**
 * fu_struct_dell_kestrel_hid_fw_update_pkg_set_chunk_sz: (skip):
 **/
void
fu_struct_dell_kestrel_hid_fw_update_pkg_set_chunk_sz(FuStructDellKestrelHidFwUpdatePkg *st, guint32 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint32(st->buf->data + 2, value, G_BIG_ENDIAN);
}
/**
 * fu_struct_dell_kestrel_hid_fw_update_pkg_set_sub_cmd: (skip):
 **/
void
fu_struct_dell_kestrel_hid_fw_update_pkg_set_sub_cmd(FuStructDellKestrelHidFwUpdatePkg *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[6] = value;
}
/**
 * fu_struct_dell_kestrel_hid_fw_update_pkg_set_dev_type: (skip):
 **/
void
fu_struct_dell_kestrel_hid_fw_update_pkg_set_dev_type(FuStructDellKestrelHidFwUpdatePkg *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[7] = value;
}
/**
 * fu_struct_dell_kestrel_hid_fw_update_pkg_set_dev_identifier: (skip):
 **/
void
fu_struct_dell_kestrel_hid_fw_update_pkg_set_dev_identifier(FuStructDellKestrelHidFwUpdatePkg *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[8] = value;
}
/**
 * fu_struct_dell_kestrel_hid_fw_update_pkg_set_fw_sz: (skip):
 **/
void
fu_struct_dell_kestrel_hid_fw_update_pkg_set_fw_sz(FuStructDellKestrelHidFwUpdatePkg *st, guint32 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint32(st->buf->data + 9, value, G_BIG_ENDIAN);
}
/**
 * fu_struct_dell_kestrel_hid_fw_update_pkg_new: (skip):
 **/
FuStructDellKestrelHidFwUpdatePkg *
fu_struct_dell_kestrel_hid_fw_update_pkg_new(void)
{
    FuStructDellKestrelHidFwUpdatePkg *st = fu_struct_dell_kestrel_hid_fw_update_pkg_new_internal();
    st->buf = g_byte_array_sized_new(13);
    fu_byte_array_set_size(st->buf, 13, 0x0);
    return st;
}
/**
 * fu_struct_dell_kestrel_hid_fw_update_pkg_to_bytes: (skip):
 **/
GBytes *
fu_struct_dell_kestrel_hid_fw_update_pkg_to_bytes(const FuStructDellKestrelHidFwUpdatePkg *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    return g_bytes_new(st->buf->data, st->buf->len);
}
