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

#include "config.h"

#include <glib.h>

#include "fu-lenovo-accessory-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_lenovo_accessory_cmd_ref: (skip):
 **/
FuStructLenovoAccessoryCmd *
fu_struct_lenovo_accessory_cmd_ref(FuStructLenovoAccessoryCmd *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_lenovo_accessory_cmd_unref: (skip):
 **/
void
fu_struct_lenovo_accessory_cmd_unref(FuStructLenovoAccessoryCmd *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructLenovoAccessoryCmd refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_lenovo_accessory_cmd_new_internal: (skip):
 **/
static FuStructLenovoAccessoryCmd *
fu_struct_lenovo_accessory_cmd_new_internal(void)
{
    FuStructLenovoAccessoryCmd *st = g_new0(FuStructLenovoAccessoryCmd, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_lenovo_accessory_cmd_get_target_status: (skip):
 **/
guint8
fu_struct_lenovo_accessory_cmd_get_target_status(const FuStructLenovoAccessoryCmd *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[0];
}
/**
 * fu_struct_lenovo_accessory_cmd_get_data_size: (skip):
 **/
guint8
fu_struct_lenovo_accessory_cmd_get_data_size(const FuStructLenovoAccessoryCmd *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[1];
}
/**
 * fu_struct_lenovo_accessory_cmd_get_command_class: (skip):
 **/
guint8
fu_struct_lenovo_accessory_cmd_get_command_class(const FuStructLenovoAccessoryCmd *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[2];
}
/**
 * fu_struct_lenovo_accessory_cmd_get_command_id: (skip):
 **/
guint8
fu_struct_lenovo_accessory_cmd_get_command_id(const FuStructLenovoAccessoryCmd *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[3];
}
/**
 * fu_struct_lenovo_accessory_cmd_get_flag_profile: (skip):
 **/
guint8
fu_struct_lenovo_accessory_cmd_get_flag_profile(const FuStructLenovoAccessoryCmd *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[4];
}
/**
 * fu_struct_lenovo_accessory_cmd_get_reserve: (skip):
 **/
guint8
fu_struct_lenovo_accessory_cmd_get_reserve(const FuStructLenovoAccessoryCmd *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[5];
}

/* setters */
/**
 * fu_struct_lenovo_accessory_cmd_set_target_status: (skip):
 **/
void
fu_struct_lenovo_accessory_cmd_set_target_status(FuStructLenovoAccessoryCmd *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[0] = value;
}
/**
 * fu_struct_lenovo_accessory_cmd_set_data_size: (skip):
 **/
void
fu_struct_lenovo_accessory_cmd_set_data_size(FuStructLenovoAccessoryCmd *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[1] = value;
}
/**
 * fu_struct_lenovo_accessory_cmd_set_command_class: (skip):
 **/
void
fu_struct_lenovo_accessory_cmd_set_command_class(FuStructLenovoAccessoryCmd *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[2] = value;
}
/**
 * fu_struct_lenovo_accessory_cmd_set_command_id: (skip):
 **/
void
fu_struct_lenovo_accessory_cmd_set_command_id(FuStructLenovoAccessoryCmd *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[3] = value;
}
/**
 * fu_struct_lenovo_accessory_cmd_set_flag_profile: (skip):
 **/
void
fu_struct_lenovo_accessory_cmd_set_flag_profile(FuStructLenovoAccessoryCmd *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[4] = value;
}
/**
 * fu_struct_lenovo_accessory_cmd_set_reserve: (skip):
 **/
void
fu_struct_lenovo_accessory_cmd_set_reserve(FuStructLenovoAccessoryCmd *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[5] = value;
}
/**
 * fu_struct_lenovo_accessory_cmd_new: (skip):
 **/
FuStructLenovoAccessoryCmd *
fu_struct_lenovo_accessory_cmd_new(void)
{
    FuStructLenovoAccessoryCmd *st = fu_struct_lenovo_accessory_cmd_new_internal();
    st->buf = g_byte_array_sized_new(6);
    fu_byte_array_set_size(st->buf, 6, 0x0);
    return st;
}
/**
 * fu_struct_lenovo_accessory_cmd_to_string: (skip):
 **/
static gchar *
fu_struct_lenovo_accessory_cmd_to_string(const FuStructLenovoAccessoryCmd *st)
{
    g_autoptr(GString) str = g_string_new("FuStructLenovoAccessoryCmd:\n");
    g_return_val_if_fail(st != NULL, NULL);
    g_string_append_printf(str, "  target_status: 0x%x\n",
                           (guint) fu_struct_lenovo_accessory_cmd_get_target_status(st));
    g_string_append_printf(str, "  data_size: 0x%x\n",
                           (guint) fu_struct_lenovo_accessory_cmd_get_data_size(st));
    g_string_append_printf(str, "  command_class: 0x%x\n",
                           (guint) fu_struct_lenovo_accessory_cmd_get_command_class(st));
    g_string_append_printf(str, "  command_id: 0x%x\n",
                           (guint) fu_struct_lenovo_accessory_cmd_get_command_id(st));
    g_string_append_printf(str, "  flag_profile: 0x%x\n",
                           (guint) fu_struct_lenovo_accessory_cmd_get_flag_profile(st));
    g_string_append_printf(str, "  reserve: 0x%x\n",
                           (guint) fu_struct_lenovo_accessory_cmd_get_reserve(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_lenovo_accessory_cmd_validate_internal(FuStructLenovoAccessoryCmd *st, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    return TRUE;
}
static gboolean
fu_struct_lenovo_accessory_cmd_parse_internal(FuStructLenovoAccessoryCmd *st, GError **error)
{
    if (g_log_get_debug_enabled()) {
        g_autofree gchar *str = fu_struct_lenovo_accessory_cmd_to_string(st);
        g_debug("%s", str);
    }
    if (!fu_struct_lenovo_accessory_cmd_validate_internal(st, error))
        return FALSE;
    return TRUE;
}

/**
 * fu_struct_lenovo_accessory_cmd_parse: (skip):
 **/
FuStructLenovoAccessoryCmd *
fu_struct_lenovo_accessory_cmd_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error)
{
    g_autoptr(FuStructLenovoAccessoryCmd) st = fu_struct_lenovo_accessory_cmd_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, 6, error)) {
        g_prefix_error_literal(error, "invalid struct FuStructLenovoAccessoryCmd: ");
        return NULL;
    }
    st->buf = g_byte_array_new();
    g_byte_array_append(st->buf, buf + offset, 6);
    if (!fu_struct_lenovo_accessory_cmd_parse_internal(st, error))
        return NULL;
    return g_steal_pointer(&st);
}
/**
 * fu_struct_lenovo_dfu_fw_req_ref: (skip):
 **/
FuStructLenovoDfuFwReq *
fu_struct_lenovo_dfu_fw_req_ref(FuStructLenovoDfuFwReq *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_lenovo_dfu_fw_req_unref: (skip):
 **/
void
fu_struct_lenovo_dfu_fw_req_unref(FuStructLenovoDfuFwReq *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructLenovoDfuFwReq refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_lenovo_dfu_fw_req_new_internal: (skip):
 **/
static FuStructLenovoDfuFwReq *
fu_struct_lenovo_dfu_fw_req_new_internal(void)
{
    FuStructLenovoDfuFwReq *st = g_new0(FuStructLenovoDfuFwReq, 1);
    st->refcount = 1;
    return st;
}

/* getters */

/* setters */
/**
 * fu_struct_lenovo_dfu_fw_req_set_cmd: (skip):
 **/
gboolean
fu_struct_lenovo_dfu_fw_req_set_cmd(FuStructLenovoDfuFwReq *st, const FuStructLenovoAccessoryCmd *st_donor, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    g_return_val_if_fail(st_donor != NULL, FALSE);
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);

    if (st_donor->buf->len > FU_STRUCT_LENOVO_ACCESSORY_CMD_SIZE) {
        g_set_error(error,
                    FWUPD_ERROR,
                    FWUPD_ERROR_INVALID_DATA,
                    "donor 'FuStructLenovoAccessoryCmd' (0x%x bytes) does not fit in "
                    "FuStructLenovoDfuFwReq.cmd (0x%x bytes)",
                    (guint) st_donor->buf->len,
                    (guint) FU_STRUCT_LENOVO_ACCESSORY_CMD_SIZE);
        return FALSE;
    }
    memcpy(st->buf->data + FU_STRUCT_LENOVO_DFU_FW_REQ_OFFSET_CMD, st_donor->buf->data, st_donor->buf->len);
    return TRUE;
}
/**
 * fu_struct_lenovo_dfu_fw_req_set_file_type: (skip):
 **/
void
fu_struct_lenovo_dfu_fw_req_set_file_type(FuStructLenovoDfuFwReq *st, FuLenovoDfuFileType value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[6] = value;
}
/**
 * fu_struct_lenovo_dfu_fw_req_set_offset_address: (skip):
 **/
void
fu_struct_lenovo_dfu_fw_req_set_offset_address(FuStructLenovoDfuFwReq *st, guint32 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint32(st->buf->data + 7, value, G_BIG_ENDIAN);
}
/**
 * fu_struct_lenovo_dfu_fw_req_set_data: (skip):
 **/
gboolean
fu_struct_lenovo_dfu_fw_req_set_data(FuStructLenovoDfuFwReq *st, const guint8 *buf, gsize bufsz, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    g_return_val_if_fail(buf != NULL, FALSE);
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
    return fu_memcpy_safe(st->buf->data, st->buf->len, 11, buf, bufsz, 0x0, bufsz, error);
}
/**
 * fu_struct_lenovo_dfu_fw_req_new: (skip):
 **/
FuStructLenovoDfuFwReq *
fu_struct_lenovo_dfu_fw_req_new(void)
{
    FuStructLenovoDfuFwReq *st = fu_struct_lenovo_dfu_fw_req_new_internal();
    st->buf = g_byte_array_sized_new(43);
    fu_byte_array_set_size(st->buf, 43, 0x0);
    {
        g_autoptr(FuStructLenovoAccessoryCmd) st_donor = fu_struct_lenovo_accessory_cmd_new();
        memcpy(st->buf->data + 0x0, st_donor->buf->data, st_donor->buf->len); /* nocheck:blocked */
    }
    return st;
}
/**
 * fu_struct_lenovo_dfu_exit_req_ref: (skip):
 **/
FuStructLenovoDfuExitReq *
fu_struct_lenovo_dfu_exit_req_ref(FuStructLenovoDfuExitReq *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_lenovo_dfu_exit_req_unref: (skip):
 **/
void
fu_struct_lenovo_dfu_exit_req_unref(FuStructLenovoDfuExitReq *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructLenovoDfuExitReq refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_lenovo_dfu_exit_req_new_internal: (skip):
 **/
static FuStructLenovoDfuExitReq *
fu_struct_lenovo_dfu_exit_req_new_internal(void)
{
    FuStructLenovoDfuExitReq *st = g_new0(FuStructLenovoDfuExitReq, 1);
    st->refcount = 1;
    return st;
}

/* getters */

/* setters */
/**
 * fu_struct_lenovo_dfu_exit_req_set_cmd: (skip):
 **/
gboolean
fu_struct_lenovo_dfu_exit_req_set_cmd(FuStructLenovoDfuExitReq *st, const FuStructLenovoAccessoryCmd *st_donor, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    g_return_val_if_fail(st_donor != NULL, FALSE);
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);

    if (st_donor->buf->len > FU_STRUCT_LENOVO_ACCESSORY_CMD_SIZE) {
        g_set_error(error,
                    FWUPD_ERROR,
                    FWUPD_ERROR_INVALID_DATA,
                    "donor 'FuStructLenovoAccessoryCmd' (0x%x bytes) does not fit in "
                    "FuStructLenovoDfuExitReq.cmd (0x%x bytes)",
                    (guint) st_donor->buf->len,
                    (guint) FU_STRUCT_LENOVO_ACCESSORY_CMD_SIZE);
        return FALSE;
    }
    memcpy(st->buf->data + FU_STRUCT_LENOVO_DFU_EXIT_REQ_OFFSET_CMD, st_donor->buf->data, st_donor->buf->len);
    return TRUE;
}
/**
 * fu_struct_lenovo_dfu_exit_req_set_exit_code: (skip):
 **/
void
fu_struct_lenovo_dfu_exit_req_set_exit_code(FuStructLenovoDfuExitReq *st, FuLenovoDfuExitCode value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[6] = value;
}
/**
 * fu_struct_lenovo_dfu_exit_req_new: (skip):
 **/
FuStructLenovoDfuExitReq *
fu_struct_lenovo_dfu_exit_req_new(void)
{
    FuStructLenovoDfuExitReq *st = fu_struct_lenovo_dfu_exit_req_new_internal();
    st->buf = g_byte_array_sized_new(7);
    fu_byte_array_set_size(st->buf, 7, 0x0);
    {
        g_autoptr(FuStructLenovoAccessoryCmd) st_donor = fu_struct_lenovo_accessory_cmd_new();
        memcpy(st->buf->data + 0x0, st_donor->buf->data, st_donor->buf->len); /* nocheck:blocked */
    }
    return st;
}
/**
 * fu_struct_lenovo_dfu_attribute_rsp_ref: (skip):
 **/
FuStructLenovoDfuAttributeRsp *
fu_struct_lenovo_dfu_attribute_rsp_ref(FuStructLenovoDfuAttributeRsp *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_lenovo_dfu_attribute_rsp_unref: (skip):
 **/
void
fu_struct_lenovo_dfu_attribute_rsp_unref(FuStructLenovoDfuAttributeRsp *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructLenovoDfuAttributeRsp refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_lenovo_dfu_attribute_rsp_new_internal: (skip):
 **/
static FuStructLenovoDfuAttributeRsp *
fu_struct_lenovo_dfu_attribute_rsp_new_internal(void)
{
    FuStructLenovoDfuAttributeRsp *st = g_new0(FuStructLenovoDfuAttributeRsp, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_lenovo_dfu_attribute_rsp_get_major_ver: (skip):
 **/
guint8
fu_struct_lenovo_dfu_attribute_rsp_get_major_ver(const FuStructLenovoDfuAttributeRsp *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[0];
}
/**
 * fu_struct_lenovo_dfu_attribute_rsp_get_minor_ver: (skip):
 **/
guint8
fu_struct_lenovo_dfu_attribute_rsp_get_minor_ver(const FuStructLenovoDfuAttributeRsp *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[1];
}
/**
 * fu_struct_lenovo_dfu_attribute_rsp_get_product_pid: (skip):
 **/
guint16
fu_struct_lenovo_dfu_attribute_rsp_get_product_pid(const FuStructLenovoDfuAttributeRsp *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 2, G_BIG_ENDIAN);
}
/**
 * fu_struct_lenovo_dfu_attribute_rsp_get_processor_id: (skip):
 **/
guint8
fu_struct_lenovo_dfu_attribute_rsp_get_processor_id(const FuStructLenovoDfuAttributeRsp *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[4];
}
/**
 * fu_struct_lenovo_dfu_attribute_rsp_get_app_max_size: (skip):
 **/
guint32
fu_struct_lenovo_dfu_attribute_rsp_get_app_max_size(const FuStructLenovoDfuAttributeRsp *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint32(st->buf->data + 5, G_BIG_ENDIAN);
}
/**
 * fu_struct_lenovo_dfu_attribute_rsp_get_page_size: (skip):
 **/
guint32
fu_struct_lenovo_dfu_attribute_rsp_get_page_size(const FuStructLenovoDfuAttributeRsp *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint32(st->buf->data + 9, G_BIG_ENDIAN);
}

/* setters */
/**
 * fu_struct_lenovo_dfu_attribute_rsp_to_string: (skip):
 **/
static gchar *
fu_struct_lenovo_dfu_attribute_rsp_to_string(const FuStructLenovoDfuAttributeRsp *st)
{
    g_autoptr(GString) str = g_string_new("FuStructLenovoDfuAttributeRsp:\n");
    g_return_val_if_fail(st != NULL, NULL);
    g_string_append_printf(str, "  major_ver: 0x%x\n",
                           (guint) fu_struct_lenovo_dfu_attribute_rsp_get_major_ver(st));
    g_string_append_printf(str, "  minor_ver: 0x%x\n",
                           (guint) fu_struct_lenovo_dfu_attribute_rsp_get_minor_ver(st));
    g_string_append_printf(str, "  product_pid: 0x%x\n",
                           (guint) fu_struct_lenovo_dfu_attribute_rsp_get_product_pid(st));
    g_string_append_printf(str, "  processor_id: 0x%x\n",
                           (guint) fu_struct_lenovo_dfu_attribute_rsp_get_processor_id(st));
    g_string_append_printf(str, "  app_max_size: 0x%x\n",
                           (guint) fu_struct_lenovo_dfu_attribute_rsp_get_app_max_size(st));
    g_string_append_printf(str, "  page_size: 0x%x\n",
                           (guint) fu_struct_lenovo_dfu_attribute_rsp_get_page_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_lenovo_dfu_attribute_rsp_validate_internal(FuStructLenovoDfuAttributeRsp *st, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    return TRUE;
}
static gboolean
fu_struct_lenovo_dfu_attribute_rsp_parse_internal(FuStructLenovoDfuAttributeRsp *st, GError **error)
{
    if (g_log_get_debug_enabled()) {
        g_autofree gchar *str = fu_struct_lenovo_dfu_attribute_rsp_to_string(st);
        g_debug("%s", str);
    }
    if (!fu_struct_lenovo_dfu_attribute_rsp_validate_internal(st, error))
        return FALSE;
    return TRUE;
}

/**
 * fu_struct_lenovo_dfu_attribute_rsp_parse: (skip):
 **/
FuStructLenovoDfuAttributeRsp *
fu_struct_lenovo_dfu_attribute_rsp_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error)
{
    g_autoptr(FuStructLenovoDfuAttributeRsp) st = fu_struct_lenovo_dfu_attribute_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, 13, error)) {
        g_prefix_error_literal(error, "invalid struct FuStructLenovoDfuAttributeRsp: ");
        return NULL;
    }
    st->buf = g_byte_array_new();
    g_byte_array_append(st->buf, buf + offset, 13);
    if (!fu_struct_lenovo_dfu_attribute_rsp_parse_internal(st, error))
        return NULL;
    return g_steal_pointer(&st);
}
/**
 * fu_struct_lenovo_dfu_crc_rsp_ref: (skip):
 **/
FuStructLenovoDfuCrcRsp *
fu_struct_lenovo_dfu_crc_rsp_ref(FuStructLenovoDfuCrcRsp *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_lenovo_dfu_crc_rsp_unref: (skip):
 **/
void
fu_struct_lenovo_dfu_crc_rsp_unref(FuStructLenovoDfuCrcRsp *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructLenovoDfuCrcRsp refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_lenovo_dfu_crc_rsp_new_internal: (skip):
 **/
static FuStructLenovoDfuCrcRsp *
fu_struct_lenovo_dfu_crc_rsp_new_internal(void)
{
    FuStructLenovoDfuCrcRsp *st = g_new0(FuStructLenovoDfuCrcRsp, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_lenovo_dfu_crc_rsp_get_crc32: (skip):
 **/
guint32
fu_struct_lenovo_dfu_crc_rsp_get_crc32(const FuStructLenovoDfuCrcRsp *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint32(st->buf->data + 0, G_BIG_ENDIAN);
}

/* setters */
/**
 * fu_struct_lenovo_dfu_crc_rsp_to_string: (skip):
 **/
static gchar *
fu_struct_lenovo_dfu_crc_rsp_to_string(const FuStructLenovoDfuCrcRsp *st)
{
    g_autoptr(GString) str = g_string_new("FuStructLenovoDfuCrcRsp:\n");
    g_return_val_if_fail(st != NULL, NULL);
    g_string_append_printf(str, "  crc32: 0x%x\n",
                           (guint) fu_struct_lenovo_dfu_crc_rsp_get_crc32(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_lenovo_dfu_crc_rsp_validate_internal(FuStructLenovoDfuCrcRsp *st, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    return TRUE;
}
static gboolean
fu_struct_lenovo_dfu_crc_rsp_parse_internal(FuStructLenovoDfuCrcRsp *st, GError **error)
{
    if (g_log_get_debug_enabled()) {
        g_autofree gchar *str = fu_struct_lenovo_dfu_crc_rsp_to_string(st);
        g_debug("%s", str);
    }
    if (!fu_struct_lenovo_dfu_crc_rsp_validate_internal(st, error))
        return FALSE;
    return TRUE;
}

/**
 * fu_struct_lenovo_dfu_crc_rsp_parse: (skip):
 **/
FuStructLenovoDfuCrcRsp *
fu_struct_lenovo_dfu_crc_rsp_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error)
{
    g_autoptr(FuStructLenovoDfuCrcRsp) st = fu_struct_lenovo_dfu_crc_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 FuStructLenovoDfuCrcRsp: ");
        return NULL;
    }
    st->buf = g_byte_array_new();
    g_byte_array_append(st->buf, buf + offset, 4);
    if (!fu_struct_lenovo_dfu_crc_rsp_parse_internal(st, error))
        return NULL;
    return g_steal_pointer(&st);
}
/**
 * fu_struct_lenovo_dfu_prepare_req_ref: (skip):
 **/
FuStructLenovoDfuPrepareReq *
fu_struct_lenovo_dfu_prepare_req_ref(FuStructLenovoDfuPrepareReq *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_lenovo_dfu_prepare_req_unref: (skip):
 **/
void
fu_struct_lenovo_dfu_prepare_req_unref(FuStructLenovoDfuPrepareReq *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructLenovoDfuPrepareReq refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_lenovo_dfu_prepare_req_new_internal: (skip):
 **/
static FuStructLenovoDfuPrepareReq *
fu_struct_lenovo_dfu_prepare_req_new_internal(void)
{
    FuStructLenovoDfuPrepareReq *st = g_new0(FuStructLenovoDfuPrepareReq, 1);
    st->refcount = 1;
    return st;
}

/* getters */

/* setters */
/**
 * fu_struct_lenovo_dfu_prepare_req_set_cmd: (skip):
 **/
gboolean
fu_struct_lenovo_dfu_prepare_req_set_cmd(FuStructLenovoDfuPrepareReq *st, const FuStructLenovoAccessoryCmd *st_donor, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    g_return_val_if_fail(st_donor != NULL, FALSE);
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);

    if (st_donor->buf->len > FU_STRUCT_LENOVO_ACCESSORY_CMD_SIZE) {
        g_set_error(error,
                    FWUPD_ERROR,
                    FWUPD_ERROR_INVALID_DATA,
                    "donor 'FuStructLenovoAccessoryCmd' (0x%x bytes) does not fit in "
                    "FuStructLenovoDfuPrepareReq.cmd (0x%x bytes)",
                    (guint) st_donor->buf->len,
                    (guint) FU_STRUCT_LENOVO_ACCESSORY_CMD_SIZE);
        return FALSE;
    }
    memcpy(st->buf->data + FU_STRUCT_LENOVO_DFU_PREPARE_REQ_OFFSET_CMD, st_donor->buf->data, st_donor->buf->len);
    return TRUE;
}
/**
 * fu_struct_lenovo_dfu_prepare_req_set_file_type: (skip):
 **/
void
fu_struct_lenovo_dfu_prepare_req_set_file_type(FuStructLenovoDfuPrepareReq *st, FuLenovoDfuFileType value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[6] = value;
}
/**
 * fu_struct_lenovo_dfu_prepare_req_set_start_address: (skip):
 **/
void
fu_struct_lenovo_dfu_prepare_req_set_start_address(FuStructLenovoDfuPrepareReq *st, guint32 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint32(st->buf->data + 7, value, G_BIG_ENDIAN);
}
/**
 * fu_struct_lenovo_dfu_prepare_req_set_end_address: (skip):
 **/
void
fu_struct_lenovo_dfu_prepare_req_set_end_address(FuStructLenovoDfuPrepareReq *st, guint32 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint32(st->buf->data + 11, value, G_BIG_ENDIAN);
}
/**
 * fu_struct_lenovo_dfu_prepare_req_set_crc32: (skip):
 **/
void
fu_struct_lenovo_dfu_prepare_req_set_crc32(FuStructLenovoDfuPrepareReq *st, guint32 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint32(st->buf->data + 15, value, G_BIG_ENDIAN);
}
/**
 * fu_struct_lenovo_dfu_prepare_req_new: (skip):
 **/
FuStructLenovoDfuPrepareReq *
fu_struct_lenovo_dfu_prepare_req_new(void)
{
    FuStructLenovoDfuPrepareReq *st = fu_struct_lenovo_dfu_prepare_req_new_internal();
    st->buf = g_byte_array_sized_new(19);
    fu_byte_array_set_size(st->buf, 19, 0x0);
    {
        g_autoptr(FuStructLenovoAccessoryCmd) st_donor = fu_struct_lenovo_accessory_cmd_new();
        memcpy(st->buf->data + 0x0, st_donor->buf->data, st_donor->buf->len); /* nocheck:blocked */
    }
    return st;
}
/**
 * fu_struct_lenovo_devicemode_req_ref: (skip):
 **/
FuStructLenovoDevicemodeReq *
fu_struct_lenovo_devicemode_req_ref(FuStructLenovoDevicemodeReq *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_lenovo_devicemode_req_unref: (skip):
 **/
void
fu_struct_lenovo_devicemode_req_unref(FuStructLenovoDevicemodeReq *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructLenovoDevicemodeReq refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_lenovo_devicemode_req_new_internal: (skip):
 **/
static FuStructLenovoDevicemodeReq *
fu_struct_lenovo_devicemode_req_new_internal(void)
{
    FuStructLenovoDevicemodeReq *st = g_new0(FuStructLenovoDevicemodeReq, 1);
    st->refcount = 1;
    return st;
}

/* getters */

/* setters */
/**
 * fu_struct_lenovo_devicemode_req_set_cmd: (skip):
 **/
gboolean
fu_struct_lenovo_devicemode_req_set_cmd(FuStructLenovoDevicemodeReq *st, const FuStructLenovoAccessoryCmd *st_donor, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    g_return_val_if_fail(st_donor != NULL, FALSE);
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);

    if (st_donor->buf->len > FU_STRUCT_LENOVO_ACCESSORY_CMD_SIZE) {
        g_set_error(error,
                    FWUPD_ERROR,
                    FWUPD_ERROR_INVALID_DATA,
                    "donor 'FuStructLenovoAccessoryCmd' (0x%x bytes) does not fit in "
                    "FuStructLenovoDevicemodeReq.cmd (0x%x bytes)",
                    (guint) st_donor->buf->len,
                    (guint) FU_STRUCT_LENOVO_ACCESSORY_CMD_SIZE);
        return FALSE;
    }
    memcpy(st->buf->data + FU_STRUCT_LENOVO_DEVICEMODE_REQ_OFFSET_CMD, st_donor->buf->data, st_donor->buf->len);
    return TRUE;
}
/**
 * fu_struct_lenovo_devicemode_req_set_mode: (skip):
 **/
void
fu_struct_lenovo_devicemode_req_set_mode(FuStructLenovoDevicemodeReq *st, FuLenovoDeviceMode value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[6] = value;
}
/**
 * fu_struct_lenovo_devicemode_req_new: (skip):
 **/
FuStructLenovoDevicemodeReq *
fu_struct_lenovo_devicemode_req_new(void)
{
    FuStructLenovoDevicemodeReq *st = fu_struct_lenovo_devicemode_req_new_internal();
    st->buf = g_byte_array_sized_new(7);
    fu_byte_array_set_size(st->buf, 7, 0x0);
    {
        g_autoptr(FuStructLenovoAccessoryCmd) st_donor = fu_struct_lenovo_accessory_cmd_new();
        memcpy(st->buf->data + 0x0, st_donor->buf->data, st_donor->buf->len); /* nocheck:blocked */
    }
    return st;
}
/**
 * fu_struct_lenovo_devicemode_rsp_ref: (skip):
 **/
FuStructLenovoDevicemodeRsp *
fu_struct_lenovo_devicemode_rsp_ref(FuStructLenovoDevicemodeRsp *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_lenovo_devicemode_rsp_unref: (skip):
 **/
void
fu_struct_lenovo_devicemode_rsp_unref(FuStructLenovoDevicemodeRsp *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructLenovoDevicemodeRsp refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}

/* getters */

/* setters */
/**
 * fu_struct_lenovo_fw_version_rsp_ref: (skip):
 **/
FuStructLenovoFwVersionRsp *
fu_struct_lenovo_fw_version_rsp_ref(FuStructLenovoFwVersionRsp *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_lenovo_fw_version_rsp_unref: (skip):
 **/
void
fu_struct_lenovo_fw_version_rsp_unref(FuStructLenovoFwVersionRsp *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructLenovoFwVersionRsp refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_lenovo_fw_version_rsp_new_internal: (skip):
 **/
static FuStructLenovoFwVersionRsp *
fu_struct_lenovo_fw_version_rsp_new_internal(void)
{
    FuStructLenovoFwVersionRsp *st = g_new0(FuStructLenovoFwVersionRsp, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_lenovo_fw_version_rsp_get_major: (skip):
 **/
guint8
fu_struct_lenovo_fw_version_rsp_get_major(const FuStructLenovoFwVersionRsp *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[0];
}
/**
 * fu_struct_lenovo_fw_version_rsp_get_minor: (skip):
 **/
guint8
fu_struct_lenovo_fw_version_rsp_get_minor(const FuStructLenovoFwVersionRsp *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[1];
}
/**
 * fu_struct_lenovo_fw_version_rsp_get_internal: (skip):
 **/
guint8
fu_struct_lenovo_fw_version_rsp_get_internal(const FuStructLenovoFwVersionRsp *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[2];
}

/* setters */
/**
 * fu_struct_lenovo_fw_version_rsp_to_string: (skip):
 **/
static gchar *
fu_struct_lenovo_fw_version_rsp_to_string(const FuStructLenovoFwVersionRsp *st)
{
    g_autoptr(GString) str = g_string_new("FuStructLenovoFwVersionRsp:\n");
    g_return_val_if_fail(st != NULL, NULL);
    g_string_append_printf(str, "  major: 0x%x\n",
                           (guint) fu_struct_lenovo_fw_version_rsp_get_major(st));
    g_string_append_printf(str, "  minor: 0x%x\n",
                           (guint) fu_struct_lenovo_fw_version_rsp_get_minor(st));
    g_string_append_printf(str, "  internal: 0x%x\n",
                           (guint) fu_struct_lenovo_fw_version_rsp_get_internal(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_lenovo_fw_version_rsp_validate_internal(FuStructLenovoFwVersionRsp *st, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    return TRUE;
}
static gboolean
fu_struct_lenovo_fw_version_rsp_parse_internal(FuStructLenovoFwVersionRsp *st, GError **error)
{
    if (g_log_get_debug_enabled()) {
        g_autofree gchar *str = fu_struct_lenovo_fw_version_rsp_to_string(st);
        g_debug("%s", str);
    }
    if (!fu_struct_lenovo_fw_version_rsp_validate_internal(st, error))
        return FALSE;
    return TRUE;
}

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