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

#include "fu-sbatlevel-section-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_sbat_level_section_header_get_version: (skip):
 **/
static guint32
fu_struct_sbat_level_section_header_get_version(const GByteArray *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint32(st->data + 0, G_BYTE_ORDER);
}
/**
 * fu_struct_sbat_level_section_header_get_previous: (skip):
 **/
guint32
fu_struct_sbat_level_section_header_get_previous(const GByteArray *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint32(st->data + 4, G_BYTE_ORDER);
}
/**
 * fu_struct_sbat_level_section_header_get_latest: (skip):
 **/
guint32
fu_struct_sbat_level_section_header_get_latest(const GByteArray *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint32(st->data + 8, G_BYTE_ORDER);
}

/* setters */
/**
 * fu_struct_sbat_level_section_header_to_string: (skip):
 **/
static gchar *
fu_struct_sbat_level_section_header_to_string(const GByteArray *st)
{
    g_autoptr(GString) str = g_string_new("SbatLevelSectionHeader:\n");
    g_return_val_if_fail(st != NULL, NULL);
    g_string_append_printf(str, "  previous: 0x%x\n",
                           (guint) fu_struct_sbat_level_section_header_get_previous(st));
    g_string_append_printf(str, "  latest: 0x%x\n",
                           (guint) fu_struct_sbat_level_section_header_get_latest(st));
    if (str->len > 0)
        g_string_set_size(str, str->len - 1);
    return g_string_free(g_steal_pointer(&str), FALSE);
}
/**
 * fu_struct_sbat_level_section_header_parse: (skip):
 **/
static GByteArray *
fu_struct_sbat_level_section_header_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 SbatLevelSectionHeader: ");
        return NULL;
    }
    g_byte_array_append(st, buf + offset, 12);
    if (fu_struct_sbat_level_section_header_get_version(st) != 0x0) {
        g_set_error_literal(error,
                            G_IO_ERROR,
                            G_IO_ERROR_INVALID_DATA,
                            "constant SbatLevelSectionHeader.version was not valid, expected 0x0");
        return NULL;
    }
    str = fu_struct_sbat_level_section_header_to_string(st);
    g_debug("%s", str);
    return g_steal_pointer(&st);
}
/**
 * fu_struct_sbat_level_section_header_parse_bytes: (skip):
 **/
GByteArray *
fu_struct_sbat_level_section_header_parse_bytes(GBytes *blob, gsize offset, GError **error)
{
    gsize bufsz = 0;
    const guint8 *buf = g_bytes_get_data(blob, &bufsz);
    return fu_struct_sbat_level_section_header_parse(buf, bufsz, offset, error);
}
