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

#include "config.h"

#include <glib.h>

#include "fu-zip-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_zip_compression_to_string:
 * @val: value, e.g. %FU_ZIP_COMPRESSION_SHRUNK
 *
 * Converts an enumerated value to a string.
 *
 * Returns: identifier string
 **/
const gchar *
fu_zip_compression_to_string(FuZipCompression val)
{
    if (val == FU_ZIP_COMPRESSION_NONE)
        return "none";
    if (val == FU_ZIP_COMPRESSION_SHRUNK)
        return "shrunk";
    if (val == FU_ZIP_COMPRESSION_IMPLODE)
        return "implode";
    if (val == FU_ZIP_COMPRESSION_TOKENIZE)
        return "tokenize";
    if (val == FU_ZIP_COMPRESSION_DEFLATE)
        return "deflate";
    if (val == FU_ZIP_COMPRESSION_DEFLATE64)
        return "deflate64";
    if (val == FU_ZIP_COMPRESSION_BZIP2)
        return "bzip2";
    if (val == FU_ZIP_COMPRESSION_LZMA)
        return "lzma";
    if (val == FU_ZIP_COMPRESSION_TERSE)
        return "terse";
    if (val == FU_ZIP_COMPRESSION_ZSTANDARD)
        return "zstandard";
    if (val == FU_ZIP_COMPRESSION_XZ)
        return "xz";
    return NULL;
}
/**
 * fu_zip_compression_from_string:
 * @val: (nullable): a string, e.g. `shrunk`
 *
 * Converts a string to an enumerated value.
 *
 * Returns: enumerated value
 **/
FuZipCompression
fu_zip_compression_from_string(const gchar *val)
{
    if (g_strcmp0(val, "none") == 0)
        return FU_ZIP_COMPRESSION_NONE;
    if (g_strcmp0(val, "shrunk") == 0)
        return FU_ZIP_COMPRESSION_SHRUNK;
    if (g_strcmp0(val, "implode") == 0)
        return FU_ZIP_COMPRESSION_IMPLODE;
    if (g_strcmp0(val, "tokenize") == 0)
        return FU_ZIP_COMPRESSION_TOKENIZE;
    if (g_strcmp0(val, "deflate") == 0)
        return FU_ZIP_COMPRESSION_DEFLATE;
    if (g_strcmp0(val, "deflate64") == 0)
        return FU_ZIP_COMPRESSION_DEFLATE64;
    if (g_strcmp0(val, "bzip2") == 0)
        return FU_ZIP_COMPRESSION_BZIP2;
    if (g_strcmp0(val, "lzma") == 0)
        return FU_ZIP_COMPRESSION_LZMA;
    if (g_strcmp0(val, "terse") == 0)
        return FU_ZIP_COMPRESSION_TERSE;
    if (g_strcmp0(val, "zstandard") == 0)
        return FU_ZIP_COMPRESSION_ZSTANDARD;
    if (g_strcmp0(val, "xz") == 0)
        return FU_ZIP_COMPRESSION_XZ;
    return FU_ZIP_COMPRESSION_NONE;
}

/**
 * fu_zip_flags_to_string:
 * @val: value, e.g. %FU_ZIP_FLAG_ENCRYPTED
 *
 * Converts an enumerated value to a string.
 *
 * Returns: identifier string
 *
 **/
static gchar *
fu_zip_flags_to_string(FuZipFlags val)
{
    const gchar *data[6] = {0};
    guint idx = 0;
    if (val == FU_ZIP_FLAG_NONE)
        return g_strdup("none");
    if (val & FU_ZIP_FLAG_ENCRYPTED)
        data[idx++] = "encrypted";
    if (val & FU_ZIP_FLAG_DEFLATE_HI)
        data[idx++] = "deflate-hi";
    if (val & FU_ZIP_FLAG_DEFLATE_LO)
        data[idx++] = "deflate-lo";
    if (val & FU_ZIP_FLAG_DATA_DESCRIPTOR)
        data[idx++] = "data-descriptor";
    if (val & FU_ZIP_FLAG_COMPRESSED_PATCHED)
        data[idx++] = "compressed-patched";
    return g_strjoinv(",", (gchar **)data);
}

/**
 * fu_zip_extra_header_id_to_string:
 * @val: value, e.g. %FU_ZIP_EXTRA_HEADER_ID_EXTENDED_TIMESTAMP
 *
 * Converts an enumerated value to a string.
 *
 * Returns: identifier string
 **/
static const gchar *
fu_zip_extra_header_id_to_string(FuZipExtraHeaderId val)
{
    if (val == FU_ZIP_EXTRA_HEADER_ID_NONE)
        return "none";
    if (val == FU_ZIP_EXTRA_HEADER_ID_EXTENDED_TIMESTAMP)
        return "extended-timestamp";
    if (val == FU_ZIP_EXTRA_HEADER_ID_INFO_ZIP_UNIX)
        return "info-zip-unix";
    if (val == FU_ZIP_EXTRA_HEADER_ID_INFO_ZIP_UNIX_UID_GID)
        return "info-zip-unix-uid-gid";
    return NULL;
}
/**
 * fu_struct_zip_extra_hdr_ref: (skip):
 **/
FuStructZipExtraHdr *
fu_struct_zip_extra_hdr_ref(FuStructZipExtraHdr *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_zip_extra_hdr_unref: (skip):
 **/
void
fu_struct_zip_extra_hdr_unref(FuStructZipExtraHdr *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructZipExtraHdr refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_zip_extra_hdr_new_internal: (skip):
 **/
static FuStructZipExtraHdr *
fu_struct_zip_extra_hdr_new_internal(void)
{
    FuStructZipExtraHdr *st = g_new0(FuStructZipExtraHdr, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_zip_extra_hdr_get_header_id: (skip):
 **/
FuZipExtraHeaderId
fu_struct_zip_extra_hdr_get_header_id(const FuStructZipExtraHdr *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 0, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_extra_hdr_get_datasz: (skip):
 **/
guint16
fu_struct_zip_extra_hdr_get_datasz(const FuStructZipExtraHdr *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 2, G_LITTLE_ENDIAN);
}

/* setters */
/**
 * fu_struct_zip_extra_hdr_set_header_id: (skip):
 **/
void
fu_struct_zip_extra_hdr_set_header_id(FuStructZipExtraHdr *st, FuZipExtraHeaderId value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 0, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_extra_hdr_set_datasz: (skip):
 **/
void
fu_struct_zip_extra_hdr_set_datasz(FuStructZipExtraHdr *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 2, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_extra_hdr_new: (skip):
 **/
FuStructZipExtraHdr *
fu_struct_zip_extra_hdr_new(void)
{
    FuStructZipExtraHdr *st = fu_struct_zip_extra_hdr_new_internal();
    st->buf = g_byte_array_sized_new(4);
    fu_byte_array_set_size(st->buf, 4, 0x0);
    return st;
}
/**
 * fu_struct_zip_extra_hdr_to_string: (skip):
 **/
static gchar *
fu_struct_zip_extra_hdr_to_string(const FuStructZipExtraHdr *st)
{
    g_autoptr(GString) str = g_string_new("FuStructZipExtraHdr:\n");
    g_return_val_if_fail(st != NULL, NULL);
    {
        const gchar *tmp = fu_zip_extra_header_id_to_string(fu_struct_zip_extra_hdr_get_header_id(st));
        if (tmp != NULL) {
            g_string_append_printf(str, "  header_id: 0x%x [%s]\n", (guint) fu_struct_zip_extra_hdr_get_header_id(st), tmp);
        } else {
            g_string_append_printf(str, "  header_id: 0x%x\n", (guint) fu_struct_zip_extra_hdr_get_header_id(st));
        }
    }
    g_string_append_printf(str, "  datasz: 0x%x\n",
                           (guint) fu_struct_zip_extra_hdr_get_datasz(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_zip_extra_hdr_validate_internal(FuStructZipExtraHdr *st, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    return TRUE;
}
static gboolean
fu_struct_zip_extra_hdr_parse_internal(FuStructZipExtraHdr *st, GError **error)
{
    if (g_log_get_debug_enabled()) {
        g_autofree gchar *str = fu_struct_zip_extra_hdr_to_string(st);
        g_debug("%s", str);
    }
    if (!fu_struct_zip_extra_hdr_validate_internal(st, error))
        return FALSE;
    return TRUE;
}
/**
 * fu_struct_zip_extra_hdr_parse_stream: (skip):
 **/
FuStructZipExtraHdr *
fu_struct_zip_extra_hdr_parse_stream(GInputStream *stream, gsize offset, GError **error)
{
    g_autoptr(FuStructZipExtraHdr) st = fu_struct_zip_extra_hdr_new_internal();
    st->buf = fu_input_stream_read_byte_array(stream, offset, 4, NULL, error);
    if (st->buf == NULL) {
        g_prefix_error(error, "FuStructZipExtraHdr failed read of 0x%x: ", (guint) 4);
        return NULL;
    }
    if (st->buf->len != 4) {
        g_set_error(error,
                    FWUPD_ERROR,
                    FWUPD_ERROR_INVALID_DATA,
                    "FuStructZipExtraHdr requested 0x%x and got 0x%x",
                    (guint) 4,
                    (guint) st->buf->len);
        return NULL;
    }
    if (!fu_struct_zip_extra_hdr_parse_internal(st, error))
        return NULL;
    return g_steal_pointer(&st);
}
/**
 * fu_struct_zip_cdfh_ref: (skip):
 **/
FuStructZipCdfh *
fu_struct_zip_cdfh_ref(FuStructZipCdfh *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_zip_cdfh_unref: (skip):
 **/
void
fu_struct_zip_cdfh_unref(FuStructZipCdfh *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructZipCdfh refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_zip_cdfh_new_internal: (skip):
 **/
static FuStructZipCdfh *
fu_struct_zip_cdfh_new_internal(void)
{
    FuStructZipCdfh *st = g_new0(FuStructZipCdfh, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_zip_cdfh_get_magic: (skip):
 **/
static gchar *
fu_struct_zip_cdfh_get_magic(const FuStructZipCdfh *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    return fu_memstrsafe(st->buf->data, st->buf->len, 0, 4, NULL);
}
/**
 * fu_struct_zip_cdfh_get_version_generated: (skip):
 **/
guint16
fu_struct_zip_cdfh_get_version_generated(const FuStructZipCdfh *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 4, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_cdfh_get_version_extract: (skip):
 **/
guint16
fu_struct_zip_cdfh_get_version_extract(const FuStructZipCdfh *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 6, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_cdfh_get_flags: (skip):
 **/
FuZipFlags
fu_struct_zip_cdfh_get_flags(const FuStructZipCdfh *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 8, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_cdfh_get_compression: (skip):
 **/
FuZipCompression
fu_struct_zip_cdfh_get_compression(const FuStructZipCdfh *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 10, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_cdfh_get_file_time: (skip):
 **/
guint16
fu_struct_zip_cdfh_get_file_time(const FuStructZipCdfh *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 12, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_cdfh_get_file_date: (skip):
 **/
guint16
fu_struct_zip_cdfh_get_file_date(const FuStructZipCdfh *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 14, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_cdfh_get_uncompressed_crc: (skip):
 **/
guint32
fu_struct_zip_cdfh_get_uncompressed_crc(const FuStructZipCdfh *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint32(st->buf->data + 16, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_cdfh_get_compressed_size: (skip):
 **/
guint32
fu_struct_zip_cdfh_get_compressed_size(const FuStructZipCdfh *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint32(st->buf->data + 20, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_cdfh_get_uncompressed_size: (skip):
 **/
guint32
fu_struct_zip_cdfh_get_uncompressed_size(const FuStructZipCdfh *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint32(st->buf->data + 24, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_cdfh_get_filename_size: (skip):
 **/
guint16
fu_struct_zip_cdfh_get_filename_size(const FuStructZipCdfh *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 28, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_cdfh_get_extra_size: (skip):
 **/
guint16
fu_struct_zip_cdfh_get_extra_size(const FuStructZipCdfh *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 30, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_cdfh_get_comment_size: (skip):
 **/
guint16
fu_struct_zip_cdfh_get_comment_size(const FuStructZipCdfh *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 32, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_cdfh_get_disk_number: (skip):
 **/
guint16
fu_struct_zip_cdfh_get_disk_number(const FuStructZipCdfh *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 34, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_cdfh_get_internal_attrs: (skip):
 **/
guint16
fu_struct_zip_cdfh_get_internal_attrs(const FuStructZipCdfh *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 36, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_cdfh_get_external_attrs: (skip):
 **/
guint32
fu_struct_zip_cdfh_get_external_attrs(const FuStructZipCdfh *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint32(st->buf->data + 38, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_cdfh_get_offset_lfh: (skip):
 **/
guint32
fu_struct_zip_cdfh_get_offset_lfh(const FuStructZipCdfh *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint32(st->buf->data + 42, G_LITTLE_ENDIAN);
}

/* setters */
/**
 * fu_struct_zip_cdfh_set_magic: (skip):
 **/
static gboolean
fu_struct_zip_cdfh_set_magic(FuStructZipCdfh *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->buf->data + 0, 0x0, 4);
        return TRUE;
    }
    len = strlen(value);
    if (len > 4) {
        g_set_error(error,
                    FWUPD_ERROR,
                    FWUPD_ERROR_INVALID_DATA,
                    "string '%s' (0x%x bytes) does not fit in FuStructZipCdfh.magic (0x%x bytes)",
                    value, (guint) len, (guint) 4);
        return FALSE;
    }
    return fu_memcpy_safe(st->buf->data, st->buf->len, 0, (const guint8 *)value, len, 0x0, len, error);
}
/**
 * fu_struct_zip_cdfh_set_version_generated: (skip):
 **/
void
fu_struct_zip_cdfh_set_version_generated(FuStructZipCdfh *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 4, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_cdfh_set_version_extract: (skip):
 **/
void
fu_struct_zip_cdfh_set_version_extract(FuStructZipCdfh *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 6, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_cdfh_set_flags: (skip):
 **/
void
fu_struct_zip_cdfh_set_flags(FuStructZipCdfh *st, FuZipFlags value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 8, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_cdfh_set_compression: (skip):
 **/
void
fu_struct_zip_cdfh_set_compression(FuStructZipCdfh *st, FuZipCompression value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 10, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_cdfh_set_file_time: (skip):
 **/
void
fu_struct_zip_cdfh_set_file_time(FuStructZipCdfh *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 12, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_cdfh_set_file_date: (skip):
 **/
void
fu_struct_zip_cdfh_set_file_date(FuStructZipCdfh *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 14, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_cdfh_set_uncompressed_crc: (skip):
 **/
void
fu_struct_zip_cdfh_set_uncompressed_crc(FuStructZipCdfh *st, guint32 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint32(st->buf->data + 16, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_cdfh_set_compressed_size: (skip):
 **/
void
fu_struct_zip_cdfh_set_compressed_size(FuStructZipCdfh *st, guint32 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint32(st->buf->data + 20, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_cdfh_set_uncompressed_size: (skip):
 **/
void
fu_struct_zip_cdfh_set_uncompressed_size(FuStructZipCdfh *st, guint32 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint32(st->buf->data + 24, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_cdfh_set_filename_size: (skip):
 **/
void
fu_struct_zip_cdfh_set_filename_size(FuStructZipCdfh *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 28, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_cdfh_set_extra_size: (skip):
 **/
void
fu_struct_zip_cdfh_set_extra_size(FuStructZipCdfh *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 30, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_cdfh_set_comment_size: (skip):
 **/
void
fu_struct_zip_cdfh_set_comment_size(FuStructZipCdfh *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 32, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_cdfh_set_disk_number: (skip):
 **/
void
fu_struct_zip_cdfh_set_disk_number(FuStructZipCdfh *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 34, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_cdfh_set_internal_attrs: (skip):
 **/
void
fu_struct_zip_cdfh_set_internal_attrs(FuStructZipCdfh *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 36, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_cdfh_set_external_attrs: (skip):
 **/
void
fu_struct_zip_cdfh_set_external_attrs(FuStructZipCdfh *st, guint32 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint32(st->buf->data + 38, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_cdfh_set_offset_lfh: (skip):
 **/
void
fu_struct_zip_cdfh_set_offset_lfh(FuStructZipCdfh *st, guint32 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint32(st->buf->data + 42, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_cdfh_new: (skip):
 **/
FuStructZipCdfh *
fu_struct_zip_cdfh_new(void)
{
    FuStructZipCdfh *st = fu_struct_zip_cdfh_new_internal();
    st->buf = g_byte_array_sized_new(46);
    fu_byte_array_set_size(st->buf, 46, 0x0);
    fu_struct_zip_cdfh_set_magic(st, "PK\x01\x02", NULL);
    fu_struct_zip_cdfh_set_version_generated(st, 0xA);
    fu_struct_zip_cdfh_set_version_extract(st, 0xA);
    return st;
}
/**
 * fu_struct_zip_cdfh_to_string: (skip):
 **/
static gchar *
fu_struct_zip_cdfh_to_string(const FuStructZipCdfh *st)
{
    g_autoptr(GString) str = g_string_new("FuStructZipCdfh:\n");
    g_return_val_if_fail(st != NULL, NULL);
    {
        g_autofree gchar *tmp = fu_struct_zip_cdfh_get_magic(st);
        if (tmp != NULL)
            g_string_append_printf(str, "  magic: %s\n", tmp);
    }
    g_string_append_printf(str, "  version_generated: 0x%x\n",
                           (guint) fu_struct_zip_cdfh_get_version_generated(st));
    g_string_append_printf(str, "  version_extract: 0x%x\n",
                           (guint) fu_struct_zip_cdfh_get_version_extract(st));
    {
        g_autofree gchar *tmp = fu_zip_flags_to_string(fu_struct_zip_cdfh_get_flags(st));
        if (tmp != NULL) {
            g_string_append_printf(str, "  flags: 0x%x [%s]\n", (guint) fu_struct_zip_cdfh_get_flags(st), tmp);
        } else {
            g_string_append_printf(str, "  flags: 0x%x\n", (guint) fu_struct_zip_cdfh_get_flags(st));
        }
    }
    {
        const gchar *tmp = fu_zip_compression_to_string(fu_struct_zip_cdfh_get_compression(st));
        if (tmp != NULL) {
            g_string_append_printf(str, "  compression: 0x%x [%s]\n", (guint) fu_struct_zip_cdfh_get_compression(st), tmp);
        } else {
            g_string_append_printf(str, "  compression: 0x%x\n", (guint) fu_struct_zip_cdfh_get_compression(st));
        }
    }
    g_string_append_printf(str, "  file_time: 0x%x\n",
                           (guint) fu_struct_zip_cdfh_get_file_time(st));
    g_string_append_printf(str, "  file_date: 0x%x\n",
                           (guint) fu_struct_zip_cdfh_get_file_date(st));
    g_string_append_printf(str, "  uncompressed_crc: 0x%x\n",
                           (guint) fu_struct_zip_cdfh_get_uncompressed_crc(st));
    g_string_append_printf(str, "  compressed_size: 0x%x\n",
                           (guint) fu_struct_zip_cdfh_get_compressed_size(st));
    g_string_append_printf(str, "  uncompressed_size: 0x%x\n",
                           (guint) fu_struct_zip_cdfh_get_uncompressed_size(st));
    g_string_append_printf(str, "  filename_size: 0x%x\n",
                           (guint) fu_struct_zip_cdfh_get_filename_size(st));
    g_string_append_printf(str, "  extra_size: 0x%x\n",
                           (guint) fu_struct_zip_cdfh_get_extra_size(st));
    g_string_append_printf(str, "  comment_size: 0x%x\n",
                           (guint) fu_struct_zip_cdfh_get_comment_size(st));
    g_string_append_printf(str, "  disk_number: 0x%x\n",
                           (guint) fu_struct_zip_cdfh_get_disk_number(st));
    g_string_append_printf(str, "  internal_attrs: 0x%x\n",
                           (guint) fu_struct_zip_cdfh_get_internal_attrs(st));
    g_string_append_printf(str, "  external_attrs: 0x%x\n",
                           (guint) fu_struct_zip_cdfh_get_external_attrs(st));
    g_string_append_printf(str, "  offset_lfh: 0x%x\n",
                           (guint) fu_struct_zip_cdfh_get_offset_lfh(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_zip_cdfh_validate_internal(FuStructZipCdfh *st, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    if (strncmp((const gchar *) (st->buf->data + 0), "PK\x01\x02", 4) != 0) {
        g_autofree gchar *str = fu_struct_zip_cdfh_get_magic(st);
        g_set_error(error,
                    FWUPD_ERROR,
                    FWUPD_ERROR_INVALID_DATA,
                    "constant FuStructZipCdfh.magic was not valid, "
                    "expected 'PK\x01\x02' and got '%s'",
                    str);
        return FALSE;
    }
    return TRUE;
}
static gboolean
fu_struct_zip_cdfh_parse_internal(FuStructZipCdfh *st, GError **error)
{
    if (g_log_get_debug_enabled()) {
        g_autofree gchar *str = fu_struct_zip_cdfh_to_string(st);
        g_debug("%s", str);
    }
    if (!fu_struct_zip_cdfh_validate_internal(st, error))
        return FALSE;
    return TRUE;
}
/**
 * fu_struct_zip_cdfh_parse_stream: (skip):
 **/
FuStructZipCdfh *
fu_struct_zip_cdfh_parse_stream(GInputStream *stream, gsize offset, GError **error)
{
    g_autoptr(FuStructZipCdfh) st = fu_struct_zip_cdfh_new_internal();
    st->buf = fu_input_stream_read_byte_array(stream, offset, 46, NULL, error);
    if (st->buf == NULL) {
        g_prefix_error(error, "FuStructZipCdfh failed read of 0x%x: ", (guint) 46);
        return NULL;
    }
    if (st->buf->len != 46) {
        g_set_error(error,
                    FWUPD_ERROR,
                    FWUPD_ERROR_INVALID_DATA,
                    "FuStructZipCdfh requested 0x%x and got 0x%x",
                    (guint) 46,
                    (guint) st->buf->len);
        return NULL;
    }
    if (!fu_struct_zip_cdfh_parse_internal(st, error))
        return NULL;
    return g_steal_pointer(&st);
}
/**
 * fu_struct_zip_eocd_ref: (skip):
 **/
FuStructZipEocd *
fu_struct_zip_eocd_ref(FuStructZipEocd *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_zip_eocd_unref: (skip):
 **/
void
fu_struct_zip_eocd_unref(FuStructZipEocd *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructZipEocd refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_zip_eocd_new_internal: (skip):
 **/
static FuStructZipEocd *
fu_struct_zip_eocd_new_internal(void)
{
    FuStructZipEocd *st = g_new0(FuStructZipEocd, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_zip_eocd_get_magic: (skip):
 **/
static gchar *
fu_struct_zip_eocd_get_magic(const FuStructZipEocd *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    return fu_memstrsafe(st->buf->data, st->buf->len, 0, 4, NULL);
}
/**
 * fu_struct_zip_eocd_get_disk_number: (skip):
 **/
guint16
fu_struct_zip_eocd_get_disk_number(const FuStructZipEocd *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 4, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_eocd_get_cd_disk: (skip):
 **/
guint16
fu_struct_zip_eocd_get_cd_disk(const FuStructZipEocd *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 6, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_eocd_get_cd_number_disk: (skip):
 **/
guint16
fu_struct_zip_eocd_get_cd_number_disk(const FuStructZipEocd *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 8, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_eocd_get_cd_number: (skip):
 **/
guint16
fu_struct_zip_eocd_get_cd_number(const FuStructZipEocd *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 10, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_eocd_get_cd_size: (skip):
 **/
guint32
fu_struct_zip_eocd_get_cd_size(const FuStructZipEocd *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint32(st->buf->data + 12, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_eocd_get_cd_offset: (skip):
 **/
guint32
fu_struct_zip_eocd_get_cd_offset(const FuStructZipEocd *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint32(st->buf->data + 16, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_eocd_get_comment_size: (skip):
 **/
guint16
fu_struct_zip_eocd_get_comment_size(const FuStructZipEocd *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 20, G_LITTLE_ENDIAN);
}

/* setters */
/**
 * fu_struct_zip_eocd_set_magic: (skip):
 **/
static gboolean
fu_struct_zip_eocd_set_magic(FuStructZipEocd *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->buf->data + 0, 0x0, 4);
        return TRUE;
    }
    len = strlen(value);
    if (len > 4) {
        g_set_error(error,
                    FWUPD_ERROR,
                    FWUPD_ERROR_INVALID_DATA,
                    "string '%s' (0x%x bytes) does not fit in FuStructZipEocd.magic (0x%x bytes)",
                    value, (guint) len, (guint) 4);
        return FALSE;
    }
    return fu_memcpy_safe(st->buf->data, st->buf->len, 0, (const guint8 *)value, len, 0x0, len, error);
}
/**
 * fu_struct_zip_eocd_set_disk_number: (skip):
 **/
void
fu_struct_zip_eocd_set_disk_number(FuStructZipEocd *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 4, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_eocd_set_cd_disk: (skip):
 **/
void
fu_struct_zip_eocd_set_cd_disk(FuStructZipEocd *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 6, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_eocd_set_cd_number_disk: (skip):
 **/
void
fu_struct_zip_eocd_set_cd_number_disk(FuStructZipEocd *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 8, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_eocd_set_cd_number: (skip):
 **/
void
fu_struct_zip_eocd_set_cd_number(FuStructZipEocd *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 10, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_eocd_set_cd_size: (skip):
 **/
void
fu_struct_zip_eocd_set_cd_size(FuStructZipEocd *st, guint32 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint32(st->buf->data + 12, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_eocd_set_cd_offset: (skip):
 **/
void
fu_struct_zip_eocd_set_cd_offset(FuStructZipEocd *st, guint32 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint32(st->buf->data + 16, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_eocd_set_comment_size: (skip):
 **/
void
fu_struct_zip_eocd_set_comment_size(FuStructZipEocd *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 20, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_eocd_new: (skip):
 **/
FuStructZipEocd *
fu_struct_zip_eocd_new(void)
{
    FuStructZipEocd *st = fu_struct_zip_eocd_new_internal();
    st->buf = g_byte_array_sized_new(22);
    fu_byte_array_set_size(st->buf, 22, 0x0);
    fu_struct_zip_eocd_set_magic(st, "PK\x05\x06", NULL);
    return st;
}
/**
 * fu_struct_zip_eocd_to_string: (skip):
 **/
static gchar *
fu_struct_zip_eocd_to_string(const FuStructZipEocd *st)
{
    g_autoptr(GString) str = g_string_new("FuStructZipEocd:\n");
    g_return_val_if_fail(st != NULL, NULL);
    {
        g_autofree gchar *tmp = fu_struct_zip_eocd_get_magic(st);
        if (tmp != NULL)
            g_string_append_printf(str, "  magic: %s\n", tmp);
    }
    g_string_append_printf(str, "  disk_number: 0x%x\n",
                           (guint) fu_struct_zip_eocd_get_disk_number(st));
    g_string_append_printf(str, "  cd_disk: 0x%x\n",
                           (guint) fu_struct_zip_eocd_get_cd_disk(st));
    g_string_append_printf(str, "  cd_number_disk: 0x%x\n",
                           (guint) fu_struct_zip_eocd_get_cd_number_disk(st));
    g_string_append_printf(str, "  cd_number: 0x%x\n",
                           (guint) fu_struct_zip_eocd_get_cd_number(st));
    g_string_append_printf(str, "  cd_size: 0x%x\n",
                           (guint) fu_struct_zip_eocd_get_cd_size(st));
    g_string_append_printf(str, "  cd_offset: 0x%x\n",
                           (guint) fu_struct_zip_eocd_get_cd_offset(st));
    g_string_append_printf(str, "  comment_size: 0x%x\n",
                           (guint) fu_struct_zip_eocd_get_comment_size(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_zip_eocd_validate_internal(FuStructZipEocd *st, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    if (strncmp((const gchar *) (st->buf->data + 0), "PK\x05\x06", 4) != 0) {
        g_autofree gchar *str = fu_struct_zip_eocd_get_magic(st);
        g_set_error(error,
                    FWUPD_ERROR,
                    FWUPD_ERROR_INVALID_DATA,
                    "constant FuStructZipEocd.magic was not valid, "
                    "expected 'PK\x05\x06' and got '%s'",
                    str);
        return FALSE;
    }
    return TRUE;
}
static gboolean
fu_struct_zip_eocd_parse_internal(FuStructZipEocd *st, GError **error)
{
    if (g_log_get_debug_enabled()) {
        g_autofree gchar *str = fu_struct_zip_eocd_to_string(st);
        g_debug("%s", str);
    }
    if (!fu_struct_zip_eocd_validate_internal(st, error))
        return FALSE;
    return TRUE;
}
/**
 * fu_struct_zip_eocd_parse_stream: (skip):
 **/
FuStructZipEocd *
fu_struct_zip_eocd_parse_stream(GInputStream *stream, gsize offset, GError **error)
{
    g_autoptr(FuStructZipEocd) st = fu_struct_zip_eocd_new_internal();
    st->buf = fu_input_stream_read_byte_array(stream, offset, 22, NULL, error);
    if (st->buf == NULL) {
        g_prefix_error(error, "FuStructZipEocd failed read of 0x%x: ", (guint) 22);
        return NULL;
    }
    if (st->buf->len != 22) {
        g_set_error(error,
                    FWUPD_ERROR,
                    FWUPD_ERROR_INVALID_DATA,
                    "FuStructZipEocd requested 0x%x and got 0x%x",
                    (guint) 22,
                    (guint) st->buf->len);
        return NULL;
    }
    if (!fu_struct_zip_eocd_parse_internal(st, error))
        return NULL;
    return g_steal_pointer(&st);
}
/**
 * fu_struct_zip_lfh_ref: (skip):
 **/
FuStructZipLfh *
fu_struct_zip_lfh_ref(FuStructZipLfh *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_zip_lfh_unref: (skip):
 **/
void
fu_struct_zip_lfh_unref(FuStructZipLfh *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructZipLfh refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_zip_lfh_new_internal: (skip):
 **/
static FuStructZipLfh *
fu_struct_zip_lfh_new_internal(void)
{
    FuStructZipLfh *st = g_new0(FuStructZipLfh, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_zip_lfh_get_magic: (skip):
 **/
static gchar *
fu_struct_zip_lfh_get_magic(const FuStructZipLfh *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    return fu_memstrsafe(st->buf->data, st->buf->len, 0, 4, NULL);
}
/**
 * fu_struct_zip_lfh_get_version_extract: (skip):
 **/
guint16
fu_struct_zip_lfh_get_version_extract(const FuStructZipLfh *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 4, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_lfh_get_flags: (skip):
 **/
FuZipFlags
fu_struct_zip_lfh_get_flags(const FuStructZipLfh *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 6, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_lfh_get_compression: (skip):
 **/
FuZipCompression
fu_struct_zip_lfh_get_compression(const FuStructZipLfh *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 8, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_lfh_get_file_time: (skip):
 **/
guint16
fu_struct_zip_lfh_get_file_time(const FuStructZipLfh *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 10, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_lfh_get_file_date: (skip):
 **/
guint16
fu_struct_zip_lfh_get_file_date(const FuStructZipLfh *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 12, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_lfh_get_uncompressed_crc: (skip):
 **/
guint32
fu_struct_zip_lfh_get_uncompressed_crc(const FuStructZipLfh *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint32(st->buf->data + 14, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_lfh_get_compressed_size: (skip):
 **/
guint32
fu_struct_zip_lfh_get_compressed_size(const FuStructZipLfh *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint32(st->buf->data + 18, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_lfh_get_uncompressed_size: (skip):
 **/
guint32
fu_struct_zip_lfh_get_uncompressed_size(const FuStructZipLfh *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint32(st->buf->data + 22, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_lfh_get_filename_size: (skip):
 **/
guint16
fu_struct_zip_lfh_get_filename_size(const FuStructZipLfh *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 26, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_lfh_get_extra_size: (skip):
 **/
guint16
fu_struct_zip_lfh_get_extra_size(const FuStructZipLfh *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 28, G_LITTLE_ENDIAN);
}

/* setters */
/**
 * fu_struct_zip_lfh_set_magic: (skip):
 **/
static gboolean
fu_struct_zip_lfh_set_magic(FuStructZipLfh *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->buf->data + 0, 0x0, 4);
        return TRUE;
    }
    len = strlen(value);
    if (len > 4) {
        g_set_error(error,
                    FWUPD_ERROR,
                    FWUPD_ERROR_INVALID_DATA,
                    "string '%s' (0x%x bytes) does not fit in FuStructZipLfh.magic (0x%x bytes)",
                    value, (guint) len, (guint) 4);
        return FALSE;
    }
    return fu_memcpy_safe(st->buf->data, st->buf->len, 0, (const guint8 *)value, len, 0x0, len, error);
}
/**
 * fu_struct_zip_lfh_set_version_extract: (skip):
 **/
void
fu_struct_zip_lfh_set_version_extract(FuStructZipLfh *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 4, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_lfh_set_flags: (skip):
 **/
void
fu_struct_zip_lfh_set_flags(FuStructZipLfh *st, FuZipFlags value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 6, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_lfh_set_compression: (skip):
 **/
void
fu_struct_zip_lfh_set_compression(FuStructZipLfh *st, FuZipCompression value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 8, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_lfh_set_file_time: (skip):
 **/
void
fu_struct_zip_lfh_set_file_time(FuStructZipLfh *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 10, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_lfh_set_file_date: (skip):
 **/
void
fu_struct_zip_lfh_set_file_date(FuStructZipLfh *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 12, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_lfh_set_uncompressed_crc: (skip):
 **/
void
fu_struct_zip_lfh_set_uncompressed_crc(FuStructZipLfh *st, guint32 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint32(st->buf->data + 14, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_lfh_set_compressed_size: (skip):
 **/
void
fu_struct_zip_lfh_set_compressed_size(FuStructZipLfh *st, guint32 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint32(st->buf->data + 18, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_lfh_set_uncompressed_size: (skip):
 **/
void
fu_struct_zip_lfh_set_uncompressed_size(FuStructZipLfh *st, guint32 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint32(st->buf->data + 22, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_lfh_set_filename_size: (skip):
 **/
void
fu_struct_zip_lfh_set_filename_size(FuStructZipLfh *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 26, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_lfh_set_extra_size: (skip):
 **/
void
fu_struct_zip_lfh_set_extra_size(FuStructZipLfh *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 28, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_zip_lfh_new: (skip):
 **/
FuStructZipLfh *
fu_struct_zip_lfh_new(void)
{
    FuStructZipLfh *st = fu_struct_zip_lfh_new_internal();
    st->buf = g_byte_array_sized_new(30);
    fu_byte_array_set_size(st->buf, 30, 0x0);
    fu_struct_zip_lfh_set_magic(st, "PK\x03\x04", NULL);
    fu_struct_zip_lfh_set_version_extract(st, 0xA);
    return st;
}
/**
 * fu_struct_zip_lfh_to_string: (skip):
 **/
static gchar *
fu_struct_zip_lfh_to_string(const FuStructZipLfh *st)
{
    g_autoptr(GString) str = g_string_new("FuStructZipLfh:\n");
    g_return_val_if_fail(st != NULL, NULL);
    {
        g_autofree gchar *tmp = fu_struct_zip_lfh_get_magic(st);
        if (tmp != NULL)
            g_string_append_printf(str, "  magic: %s\n", tmp);
    }
    g_string_append_printf(str, "  version_extract: 0x%x\n",
                           (guint) fu_struct_zip_lfh_get_version_extract(st));
    {
        g_autofree gchar *tmp = fu_zip_flags_to_string(fu_struct_zip_lfh_get_flags(st));
        if (tmp != NULL) {
            g_string_append_printf(str, "  flags: 0x%x [%s]\n", (guint) fu_struct_zip_lfh_get_flags(st), tmp);
        } else {
            g_string_append_printf(str, "  flags: 0x%x\n", (guint) fu_struct_zip_lfh_get_flags(st));
        }
    }
    {
        const gchar *tmp = fu_zip_compression_to_string(fu_struct_zip_lfh_get_compression(st));
        if (tmp != NULL) {
            g_string_append_printf(str, "  compression: 0x%x [%s]\n", (guint) fu_struct_zip_lfh_get_compression(st), tmp);
        } else {
            g_string_append_printf(str, "  compression: 0x%x\n", (guint) fu_struct_zip_lfh_get_compression(st));
        }
    }
    g_string_append_printf(str, "  file_time: 0x%x\n",
                           (guint) fu_struct_zip_lfh_get_file_time(st));
    g_string_append_printf(str, "  file_date: 0x%x\n",
                           (guint) fu_struct_zip_lfh_get_file_date(st));
    g_string_append_printf(str, "  uncompressed_crc: 0x%x\n",
                           (guint) fu_struct_zip_lfh_get_uncompressed_crc(st));
    g_string_append_printf(str, "  compressed_size: 0x%x\n",
                           (guint) fu_struct_zip_lfh_get_compressed_size(st));
    g_string_append_printf(str, "  uncompressed_size: 0x%x\n",
                           (guint) fu_struct_zip_lfh_get_uncompressed_size(st));
    g_string_append_printf(str, "  filename_size: 0x%x\n",
                           (guint) fu_struct_zip_lfh_get_filename_size(st));
    g_string_append_printf(str, "  extra_size: 0x%x\n",
                           (guint) fu_struct_zip_lfh_get_extra_size(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_zip_lfh_validate_internal(FuStructZipLfh *st, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    if (strncmp((const gchar *) (st->buf->data + 0), "PK\x03\x04", 4) != 0) {
        g_autofree gchar *str = fu_struct_zip_lfh_get_magic(st);
        g_set_error(error,
                    FWUPD_ERROR,
                    FWUPD_ERROR_INVALID_DATA,
                    "constant FuStructZipLfh.magic was not valid, "
                    "expected 'PK\x03\x04' and got '%s'",
                    str);
        return FALSE;
    }
    return TRUE;
}
static gboolean
fu_struct_zip_lfh_parse_internal(FuStructZipLfh *st, GError **error)
{
    if (g_log_get_debug_enabled()) {
        g_autofree gchar *str = fu_struct_zip_lfh_to_string(st);
        g_debug("%s", str);
    }
    if (!fu_struct_zip_lfh_validate_internal(st, error))
        return FALSE;
    return TRUE;
}
/**
 * fu_struct_zip_lfh_parse_stream: (skip):
 **/
FuStructZipLfh *
fu_struct_zip_lfh_parse_stream(GInputStream *stream, gsize offset, GError **error)
{
    g_autoptr(FuStructZipLfh) st = fu_struct_zip_lfh_new_internal();
    st->buf = fu_input_stream_read_byte_array(stream, offset, 30, NULL, error);
    if (st->buf == NULL) {
        g_prefix_error(error, "FuStructZipLfh failed read of 0x%x: ", (guint) 30);
        return NULL;
    }
    if (st->buf->len != 30) {
        g_set_error(error,
                    FWUPD_ERROR,
                    FWUPD_ERROR_INVALID_DATA,
                    "FuStructZipLfh requested 0x%x and got 0x%x",
                    (guint) 30,
                    (guint) st->buf->len);
        return NULL;
    }
    if (!fu_struct_zip_lfh_parse_internal(st, error))
        return NULL;
    return g_steal_pointer(&st);
}
