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

#include "fu-acpi-phat-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"
/* getters */
/**
 * fu_struct_acpi_phat_health_record_get_signature: (skip):
 **/
guint16
fu_struct_acpi_phat_health_record_get_signature(const GByteArray *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->data + 0, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_acpi_phat_health_record_get_rcdlen: (skip):
 **/
guint16
fu_struct_acpi_phat_health_record_get_rcdlen(const GByteArray *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->data + 2, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_acpi_phat_health_record_get_version: (skip):
 **/
guint8
fu_struct_acpi_phat_health_record_get_version(const GByteArray *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->data[4];
}
/**
 * fu_struct_acpi_phat_health_record_get_flags: (skip):
 **/
guint8
fu_struct_acpi_phat_health_record_get_flags(const GByteArray *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->data[7];
}
/**
 * fu_struct_acpi_phat_health_record_get_device_signature: (skip):
 **/
const fwupd_guid_t *
fu_struct_acpi_phat_health_record_get_device_signature(const GByteArray *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    return (const fwupd_guid_t *) (st->data + 8);
}
/**
 * fu_struct_acpi_phat_health_record_get_device_specific_data: (skip):
 **/
guint32
fu_struct_acpi_phat_health_record_get_device_specific_data(const GByteArray *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint32(st->data + 24, G_LITTLE_ENDIAN);
}

/* setters */
/**
 * fu_struct_acpi_phat_health_record_set_signature: (skip):
 **/
void
fu_struct_acpi_phat_health_record_set_signature(GByteArray *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->data + 0, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_acpi_phat_health_record_set_rcdlen: (skip):
 **/
void
fu_struct_acpi_phat_health_record_set_rcdlen(GByteArray *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->data + 2, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_acpi_phat_health_record_set_version: (skip):
 **/
void
fu_struct_acpi_phat_health_record_set_version(GByteArray *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->data[4] = value;
}
/**
 * fu_struct_acpi_phat_health_record_set_flags: (skip):
 **/
void
fu_struct_acpi_phat_health_record_set_flags(GByteArray *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->data[7] = value;
}
/**
 * fu_struct_acpi_phat_health_record_set_device_signature: (skip):
 **/
void
fu_struct_acpi_phat_health_record_set_device_signature(GByteArray *st, const fwupd_guid_t *value)
{
    g_return_if_fail(st != NULL);
    g_return_if_fail(value != NULL);
    memcpy(st->data + 8, value, sizeof(*value));
}
/**
 * fu_struct_acpi_phat_health_record_set_device_specific_data: (skip):
 **/
void
fu_struct_acpi_phat_health_record_set_device_specific_data(GByteArray *st, guint32 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint32(st->data + 24, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_acpi_phat_health_record_new: (skip):
 **/
GByteArray *
fu_struct_acpi_phat_health_record_new(void)
{
    GByteArray *st = g_byte_array_sized_new(28);
    fu_byte_array_set_size(st, 28, 0x0);
    fu_struct_acpi_phat_health_record_set_signature(st, 0x1);
    return st;
}
/**
 * fu_struct_acpi_phat_health_record_to_string: (skip):
 **/
static gchar *
fu_struct_acpi_phat_health_record_to_string(const GByteArray *st)
{
    g_autoptr(GString) str = g_string_new("AcpiPhatHealthRecord:\n");
    g_return_val_if_fail(st != NULL, NULL);
    g_string_append_printf(str, "  signature: 0x%x\n",
                           (guint) fu_struct_acpi_phat_health_record_get_signature(st));
    g_string_append_printf(str, "  rcdlen: 0x%x\n",
                           (guint) fu_struct_acpi_phat_health_record_get_rcdlen(st));
    g_string_append_printf(str, "  version: 0x%x\n",
                           (guint) fu_struct_acpi_phat_health_record_get_version(st));
    g_string_append_printf(str, "  flags: 0x%x\n",
                           (guint) fu_struct_acpi_phat_health_record_get_flags(st));
    {
        g_autofree gchar *tmp = fwupd_guid_to_string(fu_struct_acpi_phat_health_record_get_device_signature(st), FWUPD_GUID_FLAG_MIXED_ENDIAN);
        g_string_append_printf(str, "  device_signature: %s\n", tmp);
    }
    g_string_append_printf(str, "  device_specific_data: 0x%x\n",
                           (guint) fu_struct_acpi_phat_health_record_get_device_specific_data(st));
    if (str->len > 0)
        g_string_set_size(str, str->len - 1);
    return g_string_free(g_steal_pointer(&str), FALSE);
}
/**
 * fu_struct_acpi_phat_health_record_parse: (skip):
 **/
static GByteArray *
fu_struct_acpi_phat_health_record_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, 28, error)) {
        g_prefix_error(error, "invalid struct AcpiPhatHealthRecord: ");
        return NULL;
    }
    g_byte_array_append(st, buf + offset, 28);
    str = fu_struct_acpi_phat_health_record_to_string(st);
    g_debug("%s", str);
    return g_steal_pointer(&st);
}
/**
 * fu_struct_acpi_phat_health_record_parse_bytes: (skip):
 **/
GByteArray *
fu_struct_acpi_phat_health_record_parse_bytes(GBytes *blob, gsize offset, GError **error)
{
    gsize bufsz = 0;
    const guint8 *buf = g_bytes_get_data(blob, &bufsz);
    return fu_struct_acpi_phat_health_record_parse(buf, bufsz, offset, error);
}
/* getters */
/**
 * fu_struct_acpi_phat_version_element_get_component_id: (skip):
 **/
const fwupd_guid_t *
fu_struct_acpi_phat_version_element_get_component_id(const GByteArray *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    return (const fwupd_guid_t *) (st->data + 0);
}
/**
 * fu_struct_acpi_phat_version_element_get_version_value: (skip):
 **/
guint64
fu_struct_acpi_phat_version_element_get_version_value(const GByteArray *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint64(st->data + 16, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_acpi_phat_version_element_get_producer_id: (skip):
 **/
gchar *
fu_struct_acpi_phat_version_element_get_producer_id(const GByteArray *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    return fu_memstrsafe(st->data, st->len, 24, 4, NULL);
}

/* setters */
/**
 * fu_struct_acpi_phat_version_element_set_component_id: (skip):
 **/
void
fu_struct_acpi_phat_version_element_set_component_id(GByteArray *st, const fwupd_guid_t *value)
{
    g_return_if_fail(st != NULL);
    g_return_if_fail(value != NULL);
    memcpy(st->data + 0, value, sizeof(*value));
}
/**
 * fu_struct_acpi_phat_version_element_set_version_value: (skip):
 **/
void
fu_struct_acpi_phat_version_element_set_version_value(GByteArray *st, guint64 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint64(st->data + 16, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_acpi_phat_version_element_set_producer_id: (skip):
 **/
gboolean
fu_struct_acpi_phat_version_element_set_producer_id(GByteArray *st, const gchar *value, GError **error)
{
    gsize len;
    g_return_val_if_fail(st != NULL, FALSE);
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
    if (value == NULL) {
        memset(st->data + 24, 0x0, 4);
        return TRUE;
    }
    len = strlen(value);
    if (len > 4) {
        g_set_error(error,
                    G_IO_ERROR,
                    G_IO_ERROR_INVALID_DATA,
                    "string '%s' (0x%x bytes) does not fit in AcpiPhatVersionElement.producer_id (0x%x bytes)",
                    value, (guint) len, (guint) 4);
        return FALSE;
    }
    return fu_memcpy_safe(st->data, st->len, 24, (const guint8 *)value, len, 0x0, len, error);
}
/**
 * fu_struct_acpi_phat_version_element_new: (skip):
 **/
GByteArray *
fu_struct_acpi_phat_version_element_new(void)
{
    GByteArray *st = g_byte_array_sized_new(28);
    fu_byte_array_set_size(st, 28, 0x0);
    return st;
}
/**
 * fu_struct_acpi_phat_version_element_to_string: (skip):
 **/
static gchar *
fu_struct_acpi_phat_version_element_to_string(const GByteArray *st)
{
    g_autoptr(GString) str = g_string_new("AcpiPhatVersionElement:\n");
    g_return_val_if_fail(st != NULL, NULL);
    {
        g_autofree gchar *tmp = fwupd_guid_to_string(fu_struct_acpi_phat_version_element_get_component_id(st), FWUPD_GUID_FLAG_MIXED_ENDIAN);
        g_string_append_printf(str, "  component_id: %s\n", tmp);
    }
    g_string_append_printf(str, "  version_value: 0x%x\n",
                           (guint) fu_struct_acpi_phat_version_element_get_version_value(st));
    {
        g_autofree gchar *tmp = fu_struct_acpi_phat_version_element_get_producer_id(st);
        if (tmp != NULL)
            g_string_append_printf(str, "  producer_id: %s\n", tmp);
    }
    if (str->len > 0)
        g_string_set_size(str, str->len - 1);
    return g_string_free(g_steal_pointer(&str), FALSE);
}
/**
 * fu_struct_acpi_phat_version_element_parse: (skip):
 **/
static GByteArray *
fu_struct_acpi_phat_version_element_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, 28, error)) {
        g_prefix_error(error, "invalid struct AcpiPhatVersionElement: ");
        return NULL;
    }
    g_byte_array_append(st, buf + offset, 28);
    str = fu_struct_acpi_phat_version_element_to_string(st);
    g_debug("%s", str);
    return g_steal_pointer(&st);
}
/**
 * fu_struct_acpi_phat_version_element_parse_bytes: (skip):
 **/
GByteArray *
fu_struct_acpi_phat_version_element_parse_bytes(GBytes *blob, gsize offset, GError **error)
{
    gsize bufsz = 0;
    const guint8 *buf = g_bytes_get_data(blob, &bufsz);
    return fu_struct_acpi_phat_version_element_parse(buf, bufsz, offset, error);
}
/* getters */
/**
 * fu_struct_acpi_phat_version_record_get_signature: (skip):
 **/
guint16
fu_struct_acpi_phat_version_record_get_signature(const GByteArray *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->data + 0, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_acpi_phat_version_record_get_rcdlen: (skip):
 **/
guint16
fu_struct_acpi_phat_version_record_get_rcdlen(const GByteArray *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->data + 2, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_acpi_phat_version_record_get_version: (skip):
 **/
guint8
fu_struct_acpi_phat_version_record_get_version(const GByteArray *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->data[4];
}
/**
 * fu_struct_acpi_phat_version_record_get_record_count: (skip):
 **/
guint32
fu_struct_acpi_phat_version_record_get_record_count(const GByteArray *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint32(st->data + 8, G_LITTLE_ENDIAN);
}

/* setters */
/**
 * fu_struct_acpi_phat_version_record_set_signature: (skip):
 **/
void
fu_struct_acpi_phat_version_record_set_signature(GByteArray *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->data + 0, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_acpi_phat_version_record_set_rcdlen: (skip):
 **/
void
fu_struct_acpi_phat_version_record_set_rcdlen(GByteArray *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->data + 2, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_acpi_phat_version_record_set_version: (skip):
 **/
void
fu_struct_acpi_phat_version_record_set_version(GByteArray *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->data[4] = value;
}
/**
 * fu_struct_acpi_phat_version_record_set_record_count: (skip):
 **/
void
fu_struct_acpi_phat_version_record_set_record_count(GByteArray *st, guint32 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint32(st->data + 8, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_acpi_phat_version_record_new: (skip):
 **/
GByteArray *
fu_struct_acpi_phat_version_record_new(void)
{
    GByteArray *st = g_byte_array_sized_new(12);
    fu_byte_array_set_size(st, 12, 0x0);
    fu_struct_acpi_phat_version_record_set_signature(st, 0x0);
    return st;
}
/**
 * fu_struct_acpi_phat_version_record_to_string: (skip):
 **/
static gchar *
fu_struct_acpi_phat_version_record_to_string(const GByteArray *st)
{
    g_autoptr(GString) str = g_string_new("AcpiPhatVersionRecord:\n");
    g_return_val_if_fail(st != NULL, NULL);
    g_string_append_printf(str, "  signature: 0x%x\n",
                           (guint) fu_struct_acpi_phat_version_record_get_signature(st));
    g_string_append_printf(str, "  rcdlen: 0x%x\n",
                           (guint) fu_struct_acpi_phat_version_record_get_rcdlen(st));
    g_string_append_printf(str, "  version: 0x%x\n",
                           (guint) fu_struct_acpi_phat_version_record_get_version(st));
    g_string_append_printf(str, "  record_count: 0x%x\n",
                           (guint) fu_struct_acpi_phat_version_record_get_record_count(st));
    if (str->len > 0)
        g_string_set_size(str, str->len - 1);
    return g_string_free(g_steal_pointer(&str), FALSE);
}
/**
 * fu_struct_acpi_phat_version_record_parse: (skip):
 **/
static GByteArray *
fu_struct_acpi_phat_version_record_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, 12, error)) {
        g_prefix_error(error, "invalid struct AcpiPhatVersionRecord: ");
        return NULL;
    }
    g_byte_array_append(st, buf + offset, 12);
    str = fu_struct_acpi_phat_version_record_to_string(st);
    g_debug("%s", str);
    return g_steal_pointer(&st);
}
/**
 * fu_struct_acpi_phat_version_record_parse_bytes: (skip):
 **/
GByteArray *
fu_struct_acpi_phat_version_record_parse_bytes(GBytes *blob, gsize offset, GError **error)
{
    gsize bufsz = 0;
    const guint8 *buf = g_bytes_get_data(blob, &bufsz);
    return fu_struct_acpi_phat_version_record_parse(buf, bufsz, offset, error);
}
