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

#include "config.h"

#include <glib.h>

#include "fu-cfu-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_cfu_offer_info_code_to_string:
 * @val: value, e.g. %FU_CFU_OFFER_INFO_CODE_START_OFFER_LIST
 *
 * Converts an enumerated value to a string.
 *
 * Returns: identifier string
 **/
const gchar *
fu_cfu_offer_info_code_to_string(FuCfuOfferInfoCode val)
{
    if (val == FU_CFU_OFFER_INFO_CODE_START_ENTIRE_TRANSACTION)
        return "start-entire-transaction";
    if (val == FU_CFU_OFFER_INFO_CODE_START_OFFER_LIST)
        return "start-offer-list";
    if (val == FU_CFU_OFFER_INFO_CODE_END_OFFER_LIST)
        return "end-offer-list";
    return NULL;
}

/**
 * fu_cfu_rr_code_to_string:
 * @val: value, e.g. %FU_CFU_RR_CODE_OFFER_REJECT_INV_COMPONENT
 *
 * Converts an enumerated value to a string.
 *
 * Returns: identifier string
 **/
const gchar *
fu_cfu_rr_code_to_string(FuCfuRrCode val)
{
    if (val == FU_CFU_RR_CODE_OFFER_REJECT_OLD_FIRMWARE)
        return "offer-reject-old-firmware";
    if (val == FU_CFU_RR_CODE_OFFER_REJECT_INV_COMPONENT)
        return "offer-reject-inv-component";
    if (val == FU_CFU_RR_CODE_UPDATE_OFFER_SWAP_PENDING)
        return "update-offer-swap-pending";
    if (val == FU_CFU_RR_CODE_WRONG_BANK)
        return "wrong-bank";
    if (val == FU_CFU_RR_CODE_SIGN_RULE)
        return "sign-rule";
    if (val == FU_CFU_RR_CODE_VER_RELEASE_DEBUG)
        return "ver-release-debug";
    if (val == FU_CFU_RR_CODE_DEBUG_SAME_VERSION)
        return "debug-same-version";
    if (val == FU_CFU_RR_CODE_NONE)
        return "none";
    return NULL;
}

/**
 * fu_cfu_offer_status_to_string:
 * @val: value, e.g. %FU_CFU_OFFER_STATUS_ACCEPT
 *
 * Converts an enumerated value to a string.
 *
 * Returns: identifier string
 **/
const gchar *
fu_cfu_offer_status_to_string(FuCfuOfferStatus val)
{
    if (val == FU_CFU_OFFER_STATUS_SKIP)
        return "skip";
    if (val == FU_CFU_OFFER_STATUS_ACCEPT)
        return "accept";
    if (val == FU_CFU_OFFER_STATUS_REJECT)
        return "reject";
    if (val == FU_CFU_OFFER_STATUS_BUSY)
        return "busy";
    if (val == FU_CFU_OFFER_STATUS_COMMAND)
        return "command";
    if (val == FU_CFU_OFFER_STATUS_CMD_NOT_SUPPORTED)
        return "cmd-not-supported";
    return NULL;
}


/**
 * fu_cfu_content_status_to_string:
 * @val: value, e.g. %FU_CFU_CONTENT_STATUS_ERROR_PREPARE
 *
 * Converts an enumerated value to a string.
 *
 * Returns: identifier string
 **/
const gchar *
fu_cfu_content_status_to_string(FuCfuContentStatus val)
{
    if (val == FU_CFU_CONTENT_STATUS_SUCCESS)
        return "success";
    if (val == FU_CFU_CONTENT_STATUS_ERROR_PREPARE)
        return "error-prepare";
    if (val == FU_CFU_CONTENT_STATUS_ERROR_WRITE)
        return "error-write";
    if (val == FU_CFU_CONTENT_STATUS_ERROR_COMPLETE)
        return "error-complete";
    if (val == FU_CFU_CONTENT_STATUS_ERROR_VERIFY)
        return "error-verify";
    if (val == FU_CFU_CONTENT_STATUS_ERROR_CRC)
        return "error-crc";
    if (val == FU_CFU_CONTENT_STATUS_ERROR_SIGNATURE)
        return "error-signature";
    if (val == FU_CFU_CONTENT_STATUS_ERROR_VERSION)
        return "error-version";
    if (val == FU_CFU_CONTENT_STATUS_SWAP_PENDING)
        return "swap-pending";
    if (val == FU_CFU_CONTENT_STATUS_ERROR_INVALID_ADDR)
        return "error-invalid-addr";
    if (val == FU_CFU_CONTENT_STATUS_ERROR_NO_OFFER)
        return "error-no-offer";
    if (val == FU_CFU_CONTENT_STATUS_ERROR_INVALID)
        return "error-invalid";
    return NULL;
}
/**
 * fu_struct_cfu_get_version_rsp_ref: (skip):
 **/
FuStructCfuGetVersionRsp *
fu_struct_cfu_get_version_rsp_ref(FuStructCfuGetVersionRsp *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_cfu_get_version_rsp_unref: (skip):
 **/
void
fu_struct_cfu_get_version_rsp_unref(FuStructCfuGetVersionRsp *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructCfuGetVersionRsp refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_cfu_get_version_rsp_new_internal: (skip):
 **/
static FuStructCfuGetVersionRsp *
fu_struct_cfu_get_version_rsp_new_internal(void)
{
    FuStructCfuGetVersionRsp *st = g_new0(FuStructCfuGetVersionRsp, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_cfu_get_version_rsp_get_component_cnt: (skip):
 **/
guint8
fu_struct_cfu_get_version_rsp_get_component_cnt(const FuStructCfuGetVersionRsp *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[0];
}
/**
 * fu_struct_cfu_get_version_rsp_get_flags: (skip):
 **/
guint8
fu_struct_cfu_get_version_rsp_get_flags(const FuStructCfuGetVersionRsp *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[3];
}

/* setters */
/**
 * fu_struct_cfu_get_version_rsp_set_component_cnt: (skip):
 **/
void
fu_struct_cfu_get_version_rsp_set_component_cnt(FuStructCfuGetVersionRsp *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[0] = value;
}
/**
 * fu_struct_cfu_get_version_rsp_set_flags: (skip):
 **/
void
fu_struct_cfu_get_version_rsp_set_flags(FuStructCfuGetVersionRsp *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[3] = value;
}
/**
 * fu_struct_cfu_get_version_rsp_new: (skip):
 **/
FuStructCfuGetVersionRsp *
fu_struct_cfu_get_version_rsp_new(void)
{
    FuStructCfuGetVersionRsp *st = fu_struct_cfu_get_version_rsp_new_internal();
    st->buf = g_byte_array_sized_new(4);
    fu_byte_array_set_size(st->buf, 4, 0x0);
    return st;
}
/**
 * fu_struct_cfu_get_version_rsp_to_string: (skip):
 **/
static gchar *
fu_struct_cfu_get_version_rsp_to_string(const FuStructCfuGetVersionRsp *st)
{
    g_autoptr(GString) str = g_string_new("FuStructCfuGetVersionRsp:\n");
    g_return_val_if_fail(st != NULL, NULL);
    g_string_append_printf(str, "  component_cnt: 0x%x\n",
                           (guint) fu_struct_cfu_get_version_rsp_get_component_cnt(st));
    g_string_append_printf(str, "  flags: 0x%x\n",
                           (guint) fu_struct_cfu_get_version_rsp_get_flags(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_cfu_get_version_rsp_validate_internal(FuStructCfuGetVersionRsp *st, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    return TRUE;
}
static gboolean
fu_struct_cfu_get_version_rsp_parse_internal(FuStructCfuGetVersionRsp *st, GError **error)
{
    if (g_log_get_debug_enabled()) {
        g_autofree gchar *str = fu_struct_cfu_get_version_rsp_to_string(st);
        g_debug("%s", str);
    }
    if (!fu_struct_cfu_get_version_rsp_validate_internal(st, error))
        return FALSE;
    return TRUE;
}

/**
 * fu_struct_cfu_get_version_rsp_parse: (skip):
 **/
FuStructCfuGetVersionRsp *
fu_struct_cfu_get_version_rsp_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error)
{
    g_autoptr(FuStructCfuGetVersionRsp) st = fu_struct_cfu_get_version_rsp_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, 4, error)) {
        g_prefix_error_literal(error, "invalid struct FuStructCfuGetVersionRsp: ");
        return NULL;
    }
    st->buf = g_byte_array_new();
    g_byte_array_append(st->buf, buf + offset, 4);
    if (!fu_struct_cfu_get_version_rsp_parse_internal(st, error))
        return NULL;
    return g_steal_pointer(&st);
}
/**
 * fu_struct_cfu_get_version_rsp_component_ref: (skip):
 **/
FuStructCfuGetVersionRspComponent *
fu_struct_cfu_get_version_rsp_component_ref(FuStructCfuGetVersionRspComponent *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_cfu_get_version_rsp_component_unref: (skip):
 **/
void
fu_struct_cfu_get_version_rsp_component_unref(FuStructCfuGetVersionRspComponent *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructCfuGetVersionRspComponent refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_cfu_get_version_rsp_component_new_internal: (skip):
 **/
static FuStructCfuGetVersionRspComponent *
fu_struct_cfu_get_version_rsp_component_new_internal(void)
{
    FuStructCfuGetVersionRspComponent *st = g_new0(FuStructCfuGetVersionRspComponent, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_cfu_get_version_rsp_component_get_fw_version: (skip):
 **/
guint32
fu_struct_cfu_get_version_rsp_component_get_fw_version(const FuStructCfuGetVersionRspComponent *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint32(st->buf->data + 0, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_cfu_get_version_rsp_component_get_flags: (skip):
 **/
guint8
fu_struct_cfu_get_version_rsp_component_get_flags(const FuStructCfuGetVersionRspComponent *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[4];
}
/**
 * fu_struct_cfu_get_version_rsp_component_get_component_id: (skip):
 **/
guint8
fu_struct_cfu_get_version_rsp_component_get_component_id(const FuStructCfuGetVersionRspComponent *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[5];
}

/* setters */
/**
 * fu_struct_cfu_get_version_rsp_component_set_fw_version: (skip):
 **/
void
fu_struct_cfu_get_version_rsp_component_set_fw_version(FuStructCfuGetVersionRspComponent *st, guint32 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint32(st->buf->data + 0, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_cfu_get_version_rsp_component_set_flags: (skip):
 **/
void
fu_struct_cfu_get_version_rsp_component_set_flags(FuStructCfuGetVersionRspComponent *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[4] = value;
}
/**
 * fu_struct_cfu_get_version_rsp_component_set_component_id: (skip):
 **/
void
fu_struct_cfu_get_version_rsp_component_set_component_id(FuStructCfuGetVersionRspComponent *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[5] = value;
}
/**
 * fu_struct_cfu_get_version_rsp_component_new: (skip):
 **/
FuStructCfuGetVersionRspComponent *
fu_struct_cfu_get_version_rsp_component_new(void)
{
    FuStructCfuGetVersionRspComponent *st = fu_struct_cfu_get_version_rsp_component_new_internal();
    st->buf = g_byte_array_sized_new(8);
    fu_byte_array_set_size(st->buf, 8, 0x0);
    return st;
}
/**
 * fu_struct_cfu_get_version_rsp_component_to_string: (skip):
 **/
static gchar *
fu_struct_cfu_get_version_rsp_component_to_string(const FuStructCfuGetVersionRspComponent *st)
{
    g_autoptr(GString) str = g_string_new("FuStructCfuGetVersionRspComponent:\n");
    g_return_val_if_fail(st != NULL, NULL);
    g_string_append_printf(str, "  fw_version: 0x%x\n",
                           (guint) fu_struct_cfu_get_version_rsp_component_get_fw_version(st));
    g_string_append_printf(str, "  flags: 0x%x\n",
                           (guint) fu_struct_cfu_get_version_rsp_component_get_flags(st));
    g_string_append_printf(str, "  component_id: 0x%x\n",
                           (guint) fu_struct_cfu_get_version_rsp_component_get_component_id(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_cfu_get_version_rsp_component_validate_internal(FuStructCfuGetVersionRspComponent *st, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    return TRUE;
}
static gboolean
fu_struct_cfu_get_version_rsp_component_parse_internal(FuStructCfuGetVersionRspComponent *st, GError **error)
{
    if (g_log_get_debug_enabled()) {
        g_autofree gchar *str = fu_struct_cfu_get_version_rsp_component_to_string(st);
        g_debug("%s", str);
    }
    if (!fu_struct_cfu_get_version_rsp_component_validate_internal(st, error))
        return FALSE;
    return TRUE;
}

/**
 * fu_struct_cfu_get_version_rsp_component_parse: (skip):
 **/
FuStructCfuGetVersionRspComponent *
fu_struct_cfu_get_version_rsp_component_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error)
{
    g_autoptr(FuStructCfuGetVersionRspComponent) st = fu_struct_cfu_get_version_rsp_component_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, 8, error)) {
        g_prefix_error_literal(error, "invalid struct FuStructCfuGetVersionRspComponent: ");
        return NULL;
    }
    st->buf = g_byte_array_new();
    g_byte_array_append(st->buf, buf + offset, 8);
    if (!fu_struct_cfu_get_version_rsp_component_parse_internal(st, error))
        return NULL;
    return g_steal_pointer(&st);
}
/**
 * fu_struct_cfu_offer_info_req_ref: (skip):
 **/
FuStructCfuOfferInfoReq *
fu_struct_cfu_offer_info_req_ref(FuStructCfuOfferInfoReq *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_cfu_offer_info_req_unref: (skip):
 **/
void
fu_struct_cfu_offer_info_req_unref(FuStructCfuOfferInfoReq *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructCfuOfferInfoReq refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_cfu_offer_info_req_new_internal: (skip):
 **/
static FuStructCfuOfferInfoReq *
fu_struct_cfu_offer_info_req_new_internal(void)
{
    FuStructCfuOfferInfoReq *st = g_new0(FuStructCfuOfferInfoReq, 1);
    st->refcount = 1;
    return st;
}

/* getters */

/* setters */
/**
 * fu_struct_cfu_offer_info_req_set_code: (skip):
 **/
void
fu_struct_cfu_offer_info_req_set_code(FuStructCfuOfferInfoReq *st, FuCfuOfferInfoCode value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[0] = value;
}
/**
 * fu_struct_cfu_offer_info_req_set_component_id: (skip):
 **/
static void
fu_struct_cfu_offer_info_req_set_component_id(FuStructCfuOfferInfoReq *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[2] = value;
}
/**
 * fu_struct_cfu_offer_info_req_set_token: (skip):
 **/
static void
fu_struct_cfu_offer_info_req_set_token(FuStructCfuOfferInfoReq *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[3] = value;
}
/**
 * fu_struct_cfu_offer_info_req_new: (skip):
 **/
FuStructCfuOfferInfoReq *
fu_struct_cfu_offer_info_req_new(void)
{
    FuStructCfuOfferInfoReq *st = fu_struct_cfu_offer_info_req_new_internal();
    st->buf = g_byte_array_sized_new(16);
    fu_byte_array_set_size(st->buf, 16, 0x0);
    fu_struct_cfu_offer_info_req_set_component_id(st, 0xFF);
    fu_struct_cfu_offer_info_req_set_token(st, 0xDE);
    return st;
}
/**
 * fu_struct_cfu_offer_rsp_ref: (skip):
 **/
FuStructCfuOfferRsp *
fu_struct_cfu_offer_rsp_ref(FuStructCfuOfferRsp *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_cfu_offer_rsp_unref: (skip):
 **/
void
fu_struct_cfu_offer_rsp_unref(FuStructCfuOfferRsp *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructCfuOfferRsp refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_cfu_offer_rsp_new_internal: (skip):
 **/
static FuStructCfuOfferRsp *
fu_struct_cfu_offer_rsp_new_internal(void)
{
    FuStructCfuOfferRsp *st = g_new0(FuStructCfuOfferRsp, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_cfu_offer_rsp_get_token: (skip):
 **/
guint8
fu_struct_cfu_offer_rsp_get_token(const FuStructCfuOfferRsp *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[3];
}
/**
 * fu_struct_cfu_offer_rsp_get_rr_code: (skip):
 **/
FuCfuRrCode
fu_struct_cfu_offer_rsp_get_rr_code(const FuStructCfuOfferRsp *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[8];
}
/**
 * fu_struct_cfu_offer_rsp_get_status: (skip):
 **/
FuCfuOfferStatus
fu_struct_cfu_offer_rsp_get_status(const FuStructCfuOfferRsp *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[12];
}

/* setters */
/**
 * fu_struct_cfu_offer_rsp_to_string: (skip):
 **/
static gchar *
fu_struct_cfu_offer_rsp_to_string(const FuStructCfuOfferRsp *st)
{
    g_autoptr(GString) str = g_string_new("FuStructCfuOfferRsp:\n");
    g_return_val_if_fail(st != NULL, NULL);
    g_string_append_printf(str, "  token: 0x%x\n",
                           (guint) fu_struct_cfu_offer_rsp_get_token(st));
    {
        const gchar *tmp = fu_cfu_rr_code_to_string(fu_struct_cfu_offer_rsp_get_rr_code(st));
        if (tmp != NULL) {
            g_string_append_printf(str, "  rr_code: 0x%x [%s]\n", (guint) fu_struct_cfu_offer_rsp_get_rr_code(st), tmp);
        } else {
            g_string_append_printf(str, "  rr_code: 0x%x\n", (guint) fu_struct_cfu_offer_rsp_get_rr_code(st));
        }
    }
    {
        const gchar *tmp = fu_cfu_offer_status_to_string(fu_struct_cfu_offer_rsp_get_status(st));
        if (tmp != NULL) {
            g_string_append_printf(str, "  status: 0x%x [%s]\n", (guint) fu_struct_cfu_offer_rsp_get_status(st), tmp);
        } else {
            g_string_append_printf(str, "  status: 0x%x\n", (guint) fu_struct_cfu_offer_rsp_get_status(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_cfu_offer_rsp_validate_internal(FuStructCfuOfferRsp *st, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    return TRUE;
}
static gboolean
fu_struct_cfu_offer_rsp_parse_internal(FuStructCfuOfferRsp *st, GError **error)
{
    if (g_log_get_debug_enabled()) {
        g_autofree gchar *str = fu_struct_cfu_offer_rsp_to_string(st);
        g_debug("%s", str);
    }
    if (!fu_struct_cfu_offer_rsp_validate_internal(st, error))
        return FALSE;
    return TRUE;
}

/**
 * fu_struct_cfu_offer_rsp_parse: (skip):
 **/
FuStructCfuOfferRsp *
fu_struct_cfu_offer_rsp_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error)
{
    g_autoptr(FuStructCfuOfferRsp) st = fu_struct_cfu_offer_rsp_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, 16, error)) {
        g_prefix_error_literal(error, "invalid struct FuStructCfuOfferRsp: ");
        return NULL;
    }
    st->buf = g_byte_array_new();
    g_byte_array_append(st->buf, buf + offset, 16);
    if (!fu_struct_cfu_offer_rsp_parse_internal(st, error))
        return NULL;
    return g_steal_pointer(&st);
}
/**
 * fu_struct_cfu_content_req_ref: (skip):
 **/
FuStructCfuContentReq *
fu_struct_cfu_content_req_ref(FuStructCfuContentReq *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_cfu_content_req_unref: (skip):
 **/
void
fu_struct_cfu_content_req_unref(FuStructCfuContentReq *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructCfuContentReq refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_cfu_content_req_new_internal: (skip):
 **/
static FuStructCfuContentReq *
fu_struct_cfu_content_req_new_internal(void)
{
    FuStructCfuContentReq *st = g_new0(FuStructCfuContentReq, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_cfu_content_req_get_flags: (skip):
 **/
FuCfuContentFlags
fu_struct_cfu_content_req_get_flags(const FuStructCfuContentReq *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[0];
}
/**
 * fu_struct_cfu_content_req_get_data_length: (skip):
 **/
guint8
fu_struct_cfu_content_req_get_data_length(const FuStructCfuContentReq *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[1];
}
/**
 * fu_struct_cfu_content_req_get_seq_number: (skip):
 **/
guint16
fu_struct_cfu_content_req_get_seq_number(const FuStructCfuContentReq *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 2, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_cfu_content_req_get_address: (skip):
 **/
guint32
fu_struct_cfu_content_req_get_address(const FuStructCfuContentReq *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint32(st->buf->data + 4, G_LITTLE_ENDIAN);
}

/* setters */
/**
 * fu_struct_cfu_content_req_set_flags: (skip):
 **/
void
fu_struct_cfu_content_req_set_flags(FuStructCfuContentReq *st, FuCfuContentFlags value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[0] = value;
}
/**
 * fu_struct_cfu_content_req_set_data_length: (skip):
 **/
void
fu_struct_cfu_content_req_set_data_length(FuStructCfuContentReq *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[1] = value;
}
/**
 * fu_struct_cfu_content_req_set_seq_number: (skip):
 **/
void
fu_struct_cfu_content_req_set_seq_number(FuStructCfuContentReq *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 2, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_cfu_content_req_set_address: (skip):
 **/
void
fu_struct_cfu_content_req_set_address(FuStructCfuContentReq *st, guint32 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint32(st->buf->data + 4, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_cfu_content_req_new: (skip):
 **/
FuStructCfuContentReq *
fu_struct_cfu_content_req_new(void)
{
    FuStructCfuContentReq *st = fu_struct_cfu_content_req_new_internal();
    st->buf = g_byte_array_sized_new(8);
    fu_byte_array_set_size(st->buf, 8, 0x0);
    return st;
}
/**
 * fu_struct_cfu_content_rsp_ref: (skip):
 **/
FuStructCfuContentRsp *
fu_struct_cfu_content_rsp_ref(FuStructCfuContentRsp *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_cfu_content_rsp_unref: (skip):
 **/
void
fu_struct_cfu_content_rsp_unref(FuStructCfuContentRsp *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructCfuContentRsp refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_cfu_content_rsp_new_internal: (skip):
 **/
static FuStructCfuContentRsp *
fu_struct_cfu_content_rsp_new_internal(void)
{
    FuStructCfuContentRsp *st = g_new0(FuStructCfuContentRsp, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_cfu_content_rsp_get_seq_number: (skip):
 **/
guint16
fu_struct_cfu_content_rsp_get_seq_number(const FuStructCfuContentRsp *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 0, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_cfu_content_rsp_get_status: (skip):
 **/
FuCfuContentStatus
fu_struct_cfu_content_rsp_get_status(const FuStructCfuContentRsp *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[4];
}

/* setters */
/**
 * fu_struct_cfu_content_rsp_to_string: (skip):
 **/
static gchar *
fu_struct_cfu_content_rsp_to_string(const FuStructCfuContentRsp *st)
{
    g_autoptr(GString) str = g_string_new("FuStructCfuContentRsp:\n");
    g_return_val_if_fail(st != NULL, NULL);
    g_string_append_printf(str, "  seq_number: 0x%x\n",
                           (guint) fu_struct_cfu_content_rsp_get_seq_number(st));
    {
        const gchar *tmp = fu_cfu_content_status_to_string(fu_struct_cfu_content_rsp_get_status(st));
        if (tmp != NULL) {
            g_string_append_printf(str, "  status: 0x%x [%s]\n", (guint) fu_struct_cfu_content_rsp_get_status(st), tmp);
        } else {
            g_string_append_printf(str, "  status: 0x%x\n", (guint) fu_struct_cfu_content_rsp_get_status(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_cfu_content_rsp_validate_internal(FuStructCfuContentRsp *st, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    return TRUE;
}
static gboolean
fu_struct_cfu_content_rsp_parse_internal(FuStructCfuContentRsp *st, GError **error)
{
    if (g_log_get_debug_enabled()) {
        g_autofree gchar *str = fu_struct_cfu_content_rsp_to_string(st);
        g_debug("%s", str);
    }
    if (!fu_struct_cfu_content_rsp_validate_internal(st, error))
        return FALSE;
    return TRUE;
}

/**
 * fu_struct_cfu_content_rsp_parse: (skip):
 **/
FuStructCfuContentRsp *
fu_struct_cfu_content_rsp_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error)
{
    g_autoptr(FuStructCfuContentRsp) st = fu_struct_cfu_content_rsp_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, 16, error)) {
        g_prefix_error_literal(error, "invalid struct FuStructCfuContentRsp: ");
        return NULL;
    }
    st->buf = g_byte_array_new();
    g_byte_array_append(st->buf, buf + offset, 16);
    if (!fu_struct_cfu_content_rsp_parse_internal(st, error))
        return NULL;
    return g_steal_pointer(&st);
}
