/*
 * 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_lenovo_accessory_pair_list_op_code_to_string:
 * @val: value, e.g. %FU_LENOVO_ACCESSORY_PAIR_LIST_OP_CODE_GET_SLOT_INFO
 *
 * Converts an enumerated value to a string.
 *
 * Returns: identifier string
 **/
static const gchar *
fu_lenovo_accessory_pair_list_op_code_to_string(FuLenovoAccessoryPairListOpCode val)
{
    if (val == FU_LENOVO_ACCESSORY_PAIR_LIST_OP_CODE_GET_SUPPORT_INFO)
        return "get-support-info";
    if (val == FU_LENOVO_ACCESSORY_PAIR_LIST_OP_CODE_GET_SLOT_INFO)
        return "get-slot-info";
    if (val == FU_LENOVO_ACCESSORY_PAIR_LIST_OP_CODE_DELETE_SLOT)
        return "delete-slot";
    if (val == FU_LENOVO_ACCESSORY_PAIR_LIST_OP_CODE_GET_SLOT_INFO_V2)
        return "get-slot-info-v2";
    return NULL;
}


/**
 * fu_lenovo_accessory_device_mode_to_string:
 * @val: value, e.g. %FU_LENOVO_ACCESSORY_DEVICE_MODE_DRIVER_MODE
 *
 * Converts an enumerated value to a string.
 *
 * Returns: identifier string
 **/
static const gchar *
fu_lenovo_accessory_device_mode_to_string(FuLenovoAccessoryDeviceMode val)
{
    if (val == FU_LENOVO_ACCESSORY_DEVICE_MODE_NORMAL_MODE)
        return "normal-mode";
    if (val == FU_LENOVO_ACCESSORY_DEVICE_MODE_DRIVER_MODE)
        return "driver-mode";
    if (val == FU_LENOVO_ACCESSORY_DEVICE_MODE_DFU_MODE)
        return "dfu-mode";
    return NULL;
}



/**
 * fu_lenovo_accessory_notify_event_to_string:
 * @val: value, e.g. %FU_LENOVO_ACCESSORY_NOTIFY_EVENT_BT_HOST_MSG
 *
 * Converts an enumerated value to a string.
 *
 * Returns: identifier string
 **/
static const gchar *
fu_lenovo_accessory_notify_event_to_string(FuLenovoAccessoryNotifyEvent val)
{
    if (val == FU_LENOVO_ACCESSORY_NOTIFY_EVENT_WIRELESS_CONNECT_STATUS_CHANGE)
        return "wireless-connect-status-change";
    if (val == FU_LENOVO_ACCESSORY_NOTIFY_EVENT_BT_HOST_MSG)
        return "bt-host-msg";
    return NULL;
}

/**
 * fu_lenovo_accessory_notify_connect_status_to_string:
 * @val: value, e.g. %FU_LENOVO_ACCESSORY_NOTIFY_CONNECT_STATUS_CONNECTED
 *
 * Converts an enumerated value to a string.
 *
 * Returns: identifier string
 **/
static const gchar *
fu_lenovo_accessory_notify_connect_status_to_string(FuLenovoAccessoryNotifyConnectStatus val)
{
    if (val == FU_LENOVO_ACCESSORY_NOTIFY_CONNECT_STATUS_DISCONNECTED)
        return "disconnected";
    if (val == FU_LENOVO_ACCESSORY_NOTIFY_CONNECT_STATUS_CONNECTED)
        return "connected";
    return NULL;
}
/**
 * fu_struct_lenovo_accessory_notify_ref: (skip):
 **/
FuStructLenovoAccessoryNotify *
fu_struct_lenovo_accessory_notify_ref(FuStructLenovoAccessoryNotify *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_lenovo_accessory_notify_unref: (skip):
 **/
void
fu_struct_lenovo_accessory_notify_unref(FuStructLenovoAccessoryNotify *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructLenovoAccessoryNotify 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_notify_new_internal: (skip):
 **/
static FuStructLenovoAccessoryNotify *
fu_struct_lenovo_accessory_notify_new_internal(void)
{
    FuStructLenovoAccessoryNotify *st = g_new0(FuStructLenovoAccessoryNotify, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_lenovo_accessory_notify_get_report_id: (skip):
 **/
static guint8
fu_struct_lenovo_accessory_notify_get_report_id(const FuStructLenovoAccessoryNotify *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[0];
}
/**
 * fu_struct_lenovo_accessory_notify_get_ntf_type: (skip):
 **/
static guint8
fu_struct_lenovo_accessory_notify_get_ntf_type(const FuStructLenovoAccessoryNotify *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[1];
}
/**
 * fu_struct_lenovo_accessory_notify_get_event: (skip):
 **/
FuLenovoAccessoryNotifyEvent
fu_struct_lenovo_accessory_notify_get_event(const FuStructLenovoAccessoryNotify *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[2];
}
/**
 * fu_struct_lenovo_accessory_notify_get_connect_status: (skip):
 **/
FuLenovoAccessoryNotifyConnectStatus
fu_struct_lenovo_accessory_notify_get_connect_status(const FuStructLenovoAccessoryNotify *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[3];
}
/**
 * fu_struct_lenovo_accessory_notify_get_slot: (skip):
 **/
guint8
fu_struct_lenovo_accessory_notify_get_slot(const FuStructLenovoAccessoryNotify *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[4];
}

/* setters */
/**
 * fu_struct_lenovo_accessory_notify_to_string: (skip):
 **/
static gchar *
fu_struct_lenovo_accessory_notify_to_string(const FuStructLenovoAccessoryNotify *st)
{
    g_autoptr(GString) str = g_string_new("FuStructLenovoAccessoryNotify:\n");
    g_return_val_if_fail(st != NULL, NULL);
    g_string_append_printf(str, "  report_id: 0x%x\n",
                           (guint) fu_struct_lenovo_accessory_notify_get_report_id(st));
    g_string_append_printf(str, "  ntf_type: 0x%x\n",
                           (guint) fu_struct_lenovo_accessory_notify_get_ntf_type(st));
    {
        const gchar *tmp = fu_lenovo_accessory_notify_event_to_string(fu_struct_lenovo_accessory_notify_get_event(st));
        if (tmp != NULL) {
            g_string_append_printf(str, "  event: 0x%x [%s]\n", (guint) fu_struct_lenovo_accessory_notify_get_event(st), tmp);
        } else {
            g_string_append_printf(str, "  event: 0x%x\n", (guint) fu_struct_lenovo_accessory_notify_get_event(st));
        }
    }
    {
        const gchar *tmp = fu_lenovo_accessory_notify_connect_status_to_string(fu_struct_lenovo_accessory_notify_get_connect_status(st));
        if (tmp != NULL) {
            g_string_append_printf(str, "  connect_status: 0x%x [%s]\n", (guint) fu_struct_lenovo_accessory_notify_get_connect_status(st), tmp);
        } else {
            g_string_append_printf(str, "  connect_status: 0x%x\n", (guint) fu_struct_lenovo_accessory_notify_get_connect_status(st));
        }
    }
    g_string_append_printf(str, "  slot: 0x%x\n",
                           (guint) fu_struct_lenovo_accessory_notify_get_slot(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_notify_validate_internal(FuStructLenovoAccessoryNotify *st, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    if (fu_struct_lenovo_accessory_notify_get_report_id(st) != 0x04) {
        g_set_error_literal(error,
                            FWUPD_ERROR,
                            FWUPD_ERROR_INVALID_DATA,
                            "constant FuStructLenovoAccessoryNotify.report_id was not valid");
        return FALSE;
    }
    if (fu_struct_lenovo_accessory_notify_get_ntf_type(st) != 0x02) {
        g_set_error_literal(error,
                            FWUPD_ERROR,
                            FWUPD_ERROR_INVALID_DATA,
                            "constant FuStructLenovoAccessoryNotify.ntf_type was not valid");
        return FALSE;
    }
    return TRUE;
}
static gboolean
fu_struct_lenovo_accessory_notify_parse_internal(FuStructLenovoAccessoryNotify *st, GError **error)
{
    if (g_log_get_debug_enabled()) {
        g_autofree gchar *str = fu_struct_lenovo_accessory_notify_to_string(st);
        g_debug("%s", str);
    }
    if (!fu_struct_lenovo_accessory_notify_validate_internal(st, error))
        return FALSE;
    return TRUE;
}

/**
 * fu_struct_lenovo_accessory_notify_parse: (skip):
 **/
FuStructLenovoAccessoryNotify *
fu_struct_lenovo_accessory_notify_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error)
{
    g_autoptr(FuStructLenovoAccessoryNotify) st = fu_struct_lenovo_accessory_notify_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, 5, error)) {
        g_prefix_error_literal(error, "invalid struct FuStructLenovoAccessoryNotify: ");
        return NULL;
    }
    st->buf = g_byte_array_new();
    g_byte_array_append(st->buf, buf + offset, 5);
    if (!fu_struct_lenovo_accessory_notify_parse_internal(st, error))
        return NULL;
    return g_steal_pointer(&st);
}
/**
 * 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_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);
    }
    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, FuLenovoAccessoryDfuFileType 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, FuLenovoAccessoryDfuExitCode 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_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);
    }
    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_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);
    }
    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, FuLenovoAccessoryDfuFileType 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, FuLenovoAccessoryDeviceMode 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);
}
/**
 * fu_struct_lenovo_devicemode_rsp_new_internal: (skip):
 **/
static FuStructLenovoDevicemodeRsp *
fu_struct_lenovo_devicemode_rsp_new_internal(void)
{
    FuStructLenovoDevicemodeRsp *st = g_new0(FuStructLenovoDevicemodeRsp, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_lenovo_devicemode_rsp_get_mode: (skip):
 **/
FuLenovoAccessoryDeviceMode
fu_struct_lenovo_devicemode_rsp_get_mode(const FuStructLenovoDevicemodeRsp *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[0];
}

/* setters */
/**
 * fu_struct_lenovo_devicemode_rsp_to_string: (skip):
 **/
static gchar *
fu_struct_lenovo_devicemode_rsp_to_string(const FuStructLenovoDevicemodeRsp *st)
{
    g_autoptr(GString) str = g_string_new("FuStructLenovoDevicemodeRsp:\n");
    g_return_val_if_fail(st != NULL, NULL);
    {
        const gchar *tmp = fu_lenovo_accessory_device_mode_to_string(fu_struct_lenovo_devicemode_rsp_get_mode(st));
        if (tmp != NULL) {
            g_string_append_printf(str, "  mode: 0x%x [%s]\n", (guint) fu_struct_lenovo_devicemode_rsp_get_mode(st), tmp);
        } else {
            g_string_append_printf(str, "  mode: 0x%x\n", (guint) fu_struct_lenovo_devicemode_rsp_get_mode(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_devicemode_rsp_parse_internal(FuStructLenovoDevicemodeRsp *st, GError **error)
{
    if (g_log_get_debug_enabled()) {
        g_autofree gchar *str = fu_struct_lenovo_devicemode_rsp_to_string(st);
        g_debug("%s", str);
    }
    return TRUE;
}

/**
 * fu_struct_lenovo_devicemode_rsp_parse: (skip):
 **/
FuStructLenovoDevicemodeRsp *
fu_struct_lenovo_devicemode_rsp_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error)
{
    g_autoptr(FuStructLenovoDevicemodeRsp) st = fu_struct_lenovo_devicemode_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, 1, error)) {
        g_prefix_error_literal(error, "invalid struct FuStructLenovoDevicemodeRsp: ");
        return NULL;
    }
    st->buf = g_byte_array_new();
    g_byte_array_append(st->buf, buf + offset, 1);
    if (!fu_struct_lenovo_devicemode_rsp_parse_internal(st, error))
        return NULL;
    return g_steal_pointer(&st);
}
/**
 * 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_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);
    }
    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);
}
/**
 * fu_struct_lenovo_accessory_pair_list_req_ref: (skip):
 **/
FuStructLenovoAccessoryPairListReq *
fu_struct_lenovo_accessory_pair_list_req_ref(FuStructLenovoAccessoryPairListReq *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_lenovo_accessory_pair_list_req_unref: (skip):
 **/
void
fu_struct_lenovo_accessory_pair_list_req_unref(FuStructLenovoAccessoryPairListReq *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructLenovoAccessoryPairListReq 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_pair_list_req_new_internal: (skip):
 **/
static FuStructLenovoAccessoryPairListReq *
fu_struct_lenovo_accessory_pair_list_req_new_internal(void)
{
    FuStructLenovoAccessoryPairListReq *st = g_new0(FuStructLenovoAccessoryPairListReq, 1);
    st->refcount = 1;
    return st;
}

/* getters */

/* setters */
/**
 * fu_struct_lenovo_accessory_pair_list_req_set_cmd: (skip):
 **/
gboolean
fu_struct_lenovo_accessory_pair_list_req_set_cmd(FuStructLenovoAccessoryPairListReq *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 "
                    "FuStructLenovoAccessoryPairListReq.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_ACCESSORY_PAIR_LIST_REQ_OFFSET_CMD, st_donor->buf->data, st_donor->buf->len);
    return TRUE;
}
/**
 * fu_struct_lenovo_accessory_pair_list_req_set_op_code: (skip):
 **/
void
fu_struct_lenovo_accessory_pair_list_req_set_op_code(FuStructLenovoAccessoryPairListReq *st, FuLenovoAccessoryPairListOpCode value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[6] = value;
}
/**
 * fu_struct_lenovo_accessory_pair_list_req_set_target_slot: (skip):
 **/
void
fu_struct_lenovo_accessory_pair_list_req_set_target_slot(FuStructLenovoAccessoryPairListReq *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[7] = value;
}
/**
 * fu_struct_lenovo_accessory_pair_list_req_new: (skip):
 **/
FuStructLenovoAccessoryPairListReq *
fu_struct_lenovo_accessory_pair_list_req_new(void)
{
    FuStructLenovoAccessoryPairListReq *st = fu_struct_lenovo_accessory_pair_list_req_new_internal();
    st->buf = g_byte_array_sized_new(8);
    fu_byte_array_set_size(st->buf, 8, 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_accessory_pair_support_info_rsp_ref: (skip):
 **/
FuStructLenovoAccessoryPairSupportInfoRsp *
fu_struct_lenovo_accessory_pair_support_info_rsp_ref(FuStructLenovoAccessoryPairSupportInfoRsp *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_lenovo_accessory_pair_support_info_rsp_unref: (skip):
 **/
void
fu_struct_lenovo_accessory_pair_support_info_rsp_unref(FuStructLenovoAccessoryPairSupportInfoRsp *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructLenovoAccessoryPairSupportInfoRsp 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_pair_support_info_rsp_new_internal: (skip):
 **/
static FuStructLenovoAccessoryPairSupportInfoRsp *
fu_struct_lenovo_accessory_pair_support_info_rsp_new_internal(void)
{
    FuStructLenovoAccessoryPairSupportInfoRsp *st = g_new0(FuStructLenovoAccessoryPairSupportInfoRsp, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_lenovo_accessory_pair_support_info_rsp_get_op_code: (skip):
 **/
FuLenovoAccessoryPairListOpCode
fu_struct_lenovo_accessory_pair_support_info_rsp_get_op_code(const FuStructLenovoAccessoryPairSupportInfoRsp *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[0];
}
/**
 * fu_struct_lenovo_accessory_pair_support_info_rsp_get_max_slot_num: (skip):
 **/
guint8
fu_struct_lenovo_accessory_pair_support_info_rsp_get_max_slot_num(const FuStructLenovoAccessoryPairSupportInfoRsp *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[1];
}
/**
 * fu_struct_lenovo_accessory_pair_support_info_rsp_get_slot_status: (skip):
 **/
const guint8 *
fu_struct_lenovo_accessory_pair_support_info_rsp_get_slot_status(const FuStructLenovoAccessoryPairSupportInfoRsp *st, gsize *bufsz)
{
    g_return_val_if_fail(st != NULL, NULL);
    if (bufsz != NULL)
        *bufsz = 8;
    return st->buf->data + 2;
}

/* setters */
/**
 * fu_struct_lenovo_accessory_pair_support_info_rsp_to_string: (skip):
 **/
static gchar *
fu_struct_lenovo_accessory_pair_support_info_rsp_to_string(const FuStructLenovoAccessoryPairSupportInfoRsp *st)
{
    g_autoptr(GString) str = g_string_new("FuStructLenovoAccessoryPairSupportInfoRsp:\n");
    g_return_val_if_fail(st != NULL, NULL);
    {
        const gchar *tmp = fu_lenovo_accessory_pair_list_op_code_to_string(fu_struct_lenovo_accessory_pair_support_info_rsp_get_op_code(st));
        if (tmp != NULL) {
            g_string_append_printf(str, "  op_code: 0x%x [%s]\n", (guint) fu_struct_lenovo_accessory_pair_support_info_rsp_get_op_code(st), tmp);
        } else {
            g_string_append_printf(str, "  op_code: 0x%x\n", (guint) fu_struct_lenovo_accessory_pair_support_info_rsp_get_op_code(st));
        }
    }
    g_string_append_printf(str, "  max_slot_num: 0x%x\n",
                           (guint) fu_struct_lenovo_accessory_pair_support_info_rsp_get_max_slot_num(st));
    {
        gsize bufsz = 0;
        const guint8 *buf = fu_struct_lenovo_accessory_pair_support_info_rsp_get_slot_status(st, &bufsz);
        g_autoptr(GString) tmp = g_string_new(NULL);
        for (gsize i = 0; i < bufsz; i++)
            g_string_append_printf(tmp, "%02X", buf[i]);
        g_string_append_printf(str, "  slot_status: 0x%s\n", tmp->str);
    }
    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_pair_support_info_rsp_parse_internal(FuStructLenovoAccessoryPairSupportInfoRsp *st, GError **error)
{
    if (g_log_get_debug_enabled()) {
        g_autofree gchar *str = fu_struct_lenovo_accessory_pair_support_info_rsp_to_string(st);
        g_debug("%s", str);
    }
    return TRUE;
}

/**
 * fu_struct_lenovo_accessory_pair_support_info_rsp_parse: (skip):
 **/
FuStructLenovoAccessoryPairSupportInfoRsp *
fu_struct_lenovo_accessory_pair_support_info_rsp_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error)
{
    g_autoptr(FuStructLenovoAccessoryPairSupportInfoRsp) st = fu_struct_lenovo_accessory_pair_support_info_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, 10, error)) {
        g_prefix_error_literal(error, "invalid struct FuStructLenovoAccessoryPairSupportInfoRsp: ");
        return NULL;
    }
    st->buf = g_byte_array_new();
    g_byte_array_append(st->buf, buf + offset, 10);
    if (!fu_struct_lenovo_accessory_pair_support_info_rsp_parse_internal(st, error))
        return NULL;
    return g_steal_pointer(&st);
}
/**
 * fu_struct_lenovo_accessory_pair_slot_info_v2_rsp_ref: (skip):
 **/
FuStructLenovoAccessoryPairSlotInfoV2Rsp *
fu_struct_lenovo_accessory_pair_slot_info_v2_rsp_ref(FuStructLenovoAccessoryPairSlotInfoV2Rsp *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_lenovo_accessory_pair_slot_info_v2_rsp_unref: (skip):
 **/
void
fu_struct_lenovo_accessory_pair_slot_info_v2_rsp_unref(FuStructLenovoAccessoryPairSlotInfoV2Rsp *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructLenovoAccessoryPairSlotInfoV2Rsp 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_pair_slot_info_v2_rsp_new_internal: (skip):
 **/
static FuStructLenovoAccessoryPairSlotInfoV2Rsp *
fu_struct_lenovo_accessory_pair_slot_info_v2_rsp_new_internal(void)
{
    FuStructLenovoAccessoryPairSlotInfoV2Rsp *st = g_new0(FuStructLenovoAccessoryPairSlotInfoV2Rsp, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_lenovo_accessory_pair_slot_info_v2_rsp_get_op_code: (skip):
 **/
FuLenovoAccessoryPairListOpCode
fu_struct_lenovo_accessory_pair_slot_info_v2_rsp_get_op_code(const FuStructLenovoAccessoryPairSlotInfoV2Rsp *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[0];
}
/**
 * fu_struct_lenovo_accessory_pair_slot_info_v2_rsp_get_target_slot: (skip):
 **/
guint8
fu_struct_lenovo_accessory_pair_slot_info_v2_rsp_get_target_slot(const FuStructLenovoAccessoryPairSlotInfoV2Rsp *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[1];
}
/**
 * fu_struct_lenovo_accessory_pair_slot_info_v2_rsp_get_pid: (skip):
 **/
guint16
fu_struct_lenovo_accessory_pair_slot_info_v2_rsp_get_pid(const FuStructLenovoAccessoryPairSlotInfoV2Rsp *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 2, G_BIG_ENDIAN);
}
/**
 * fu_struct_lenovo_accessory_pair_slot_info_v2_rsp_get_mac_addr: (skip):
 **/
const guint8 *
fu_struct_lenovo_accessory_pair_slot_info_v2_rsp_get_mac_addr(const FuStructLenovoAccessoryPairSlotInfoV2Rsp *st, gsize *bufsz)
{
    g_return_val_if_fail(st != NULL, NULL);
    if (bufsz != NULL)
        *bufsz = 6;
    return st->buf->data + 4;
}
/**
 * fu_struct_lenovo_accessory_pair_slot_info_v2_rsp_get_bt_name: (skip):
 **/
gchar *
fu_struct_lenovo_accessory_pair_slot_info_v2_rsp_get_bt_name(const FuStructLenovoAccessoryPairSlotInfoV2Rsp *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    return fu_memstrsafe(st->buf->data, st->buf->len, 10, 48, NULL);
}

/* setters */
/**
 * fu_struct_lenovo_accessory_pair_slot_info_v2_rsp_to_string: (skip):
 **/
static gchar *
fu_struct_lenovo_accessory_pair_slot_info_v2_rsp_to_string(const FuStructLenovoAccessoryPairSlotInfoV2Rsp *st)
{
    g_autoptr(GString) str = g_string_new("FuStructLenovoAccessoryPairSlotInfoV2Rsp:\n");
    g_return_val_if_fail(st != NULL, NULL);
    {
        const gchar *tmp = fu_lenovo_accessory_pair_list_op_code_to_string(fu_struct_lenovo_accessory_pair_slot_info_v2_rsp_get_op_code(st));
        if (tmp != NULL) {
            g_string_append_printf(str, "  op_code: 0x%x [%s]\n", (guint) fu_struct_lenovo_accessory_pair_slot_info_v2_rsp_get_op_code(st), tmp);
        } else {
            g_string_append_printf(str, "  op_code: 0x%x\n", (guint) fu_struct_lenovo_accessory_pair_slot_info_v2_rsp_get_op_code(st));
        }
    }
    g_string_append_printf(str, "  target_slot: 0x%x\n",
                           (guint) fu_struct_lenovo_accessory_pair_slot_info_v2_rsp_get_target_slot(st));
    g_string_append_printf(str, "  pid: 0x%x\n",
                           (guint) fu_struct_lenovo_accessory_pair_slot_info_v2_rsp_get_pid(st));
    {
        gsize bufsz = 0;
        const guint8 *buf = fu_struct_lenovo_accessory_pair_slot_info_v2_rsp_get_mac_addr(st, &bufsz);
        g_autoptr(GString) tmp = g_string_new(NULL);
        for (gsize i = 0; i < bufsz; i++)
            g_string_append_printf(tmp, "%02X", buf[i]);
        g_string_append_printf(str, "  mac_addr: 0x%s\n", tmp->str);
    }
    {
        g_autofree gchar *tmp = fu_struct_lenovo_accessory_pair_slot_info_v2_rsp_get_bt_name(st);
        if (tmp != NULL)
            g_string_append_printf(str, "  bt_name: %s\n", tmp);
    }
    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_pair_slot_info_v2_rsp_parse_internal(FuStructLenovoAccessoryPairSlotInfoV2Rsp *st, GError **error)
{
    if (g_log_get_debug_enabled()) {
        g_autofree gchar *str = fu_struct_lenovo_accessory_pair_slot_info_v2_rsp_to_string(st);
        g_debug("%s", str);
    }
    return TRUE;
}

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