/*
 * 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-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_struct_dell_smbios_da_ref: (skip):
 **/
FuStructDellSmbiosDa *
fu_struct_dell_smbios_da_ref(FuStructDellSmbiosDa *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_dell_smbios_da_unref: (skip):
 **/
void
fu_struct_dell_smbios_da_unref(FuStructDellSmbiosDa *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructDellSmbiosDa 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_smbios_da_new_internal: (skip):
 **/
static FuStructDellSmbiosDa *
fu_struct_dell_smbios_da_new_internal(void)
{
    FuStructDellSmbiosDa *st = g_new0(FuStructDellSmbiosDa, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_dell_smbios_da_get_type: (skip):
 **/
guint8
fu_struct_dell_smbios_da_get_type(const FuStructDellSmbiosDa *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[0];
}
/**
 * fu_struct_dell_smbios_da_get_length: (skip):
 **/
guint8
fu_struct_dell_smbios_da_get_length(const FuStructDellSmbiosDa *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[1];
}
/**
 * fu_struct_dell_smbios_da_get_handle: (skip):
 **/
guint16
fu_struct_dell_smbios_da_get_handle(const FuStructDellSmbiosDa *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 2, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_dell_smbios_da_get_cmd_address: (skip):
 **/
guint16
fu_struct_dell_smbios_da_get_cmd_address(const FuStructDellSmbiosDa *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 4, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_dell_smbios_da_get_cmd_code: (skip):
 **/
guint8
fu_struct_dell_smbios_da_get_cmd_code(const FuStructDellSmbiosDa *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[6];
}
/**
 * fu_struct_dell_smbios_da_get_supported_cmds: (skip):
 **/
guint32
fu_struct_dell_smbios_da_get_supported_cmds(const FuStructDellSmbiosDa *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint32(st->buf->data + 7, G_LITTLE_ENDIAN);
}

/* setters */
/**
 * fu_struct_dell_smbios_da_to_string: (skip):
 **/
static gchar *
fu_struct_dell_smbios_da_to_string(const FuStructDellSmbiosDa *st)
{
    g_autoptr(GString) str = g_string_new("FuStructDellSmbiosDa:\n");
    g_return_val_if_fail(st != NULL, NULL);
    g_string_append_printf(str, "  type: 0x%x\n",
                           (guint) fu_struct_dell_smbios_da_get_type(st));
    g_string_append_printf(str, "  length: 0x%x\n",
                           (guint) fu_struct_dell_smbios_da_get_length(st));
    g_string_append_printf(str, "  handle: 0x%x\n",
                           (guint) fu_struct_dell_smbios_da_get_handle(st));
    g_string_append_printf(str, "  cmd_address: 0x%x\n",
                           (guint) fu_struct_dell_smbios_da_get_cmd_address(st));
    g_string_append_printf(str, "  cmd_code: 0x%x\n",
                           (guint) fu_struct_dell_smbios_da_get_cmd_code(st));
    g_string_append_printf(str, "  supported_cmds: 0x%x\n",
                           (guint) fu_struct_dell_smbios_da_get_supported_cmds(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_dell_smbios_da_validate_internal(FuStructDellSmbiosDa *st, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    return TRUE;
}
static gboolean
fu_struct_dell_smbios_da_parse_internal(FuStructDellSmbiosDa *st, GError **error)
{
    if (g_log_get_debug_enabled()) {
        g_autofree gchar *str = fu_struct_dell_smbios_da_to_string(st);
        g_debug("%s", str);
    }
    if (!fu_struct_dell_smbios_da_validate_internal(st, error))
        return FALSE;
    return TRUE;
}

/**
 * fu_struct_dell_smbios_da_parse: (skip):
 **/
static FuStructDellSmbiosDa *
fu_struct_dell_smbios_da_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error)
{
    g_autoptr(FuStructDellSmbiosDa) st = fu_struct_dell_smbios_da_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, 11, error)) {
        g_prefix_error_literal(error, "invalid struct FuStructDellSmbiosDa: ");
        return NULL;
    }
    st->buf = g_byte_array_new();
    g_byte_array_append(st->buf, buf + offset, 11);
    if (!fu_struct_dell_smbios_da_parse_internal(st, error))
        return NULL;
    return g_steal_pointer(&st);
}
/**
 * fu_struct_dell_smbios_da_parse_bytes: (skip):
 **/
FuStructDellSmbiosDa *
fu_struct_dell_smbios_da_parse_bytes(GBytes *blob, gsize offset, GError **error)
{
    gsize bufsz = 0;
    const guint8 *buf = fu_bytes_get_data_safe(blob, &bufsz, error);
    if (buf == NULL)
        return NULL;
    return fu_struct_dell_smbios_da_parse(buf, bufsz, offset, error);
}
