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

#include "config.h"

#include <glib.h>

#include "fu-logitech-hidpp-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_logitech_hidpp_feature_to_string:
 * @val: value, e.g. %FU_LOGITECH_HIDPP_FEATURE_I_FEATURE_SET
 *
 * Converts an enumerated value to a string.
 *
 * Returns: identifier string
 **/
const gchar *
fu_logitech_hidpp_feature_to_string(FuLogitechHidppFeature val)
{
    if (val == FU_LOGITECH_HIDPP_FEATURE_ROOT)
        return "root";
    if (val == FU_LOGITECH_HIDPP_FEATURE_I_FEATURE_SET)
        return "i-feature-set";
    if (val == FU_LOGITECH_HIDPP_FEATURE_I_FIRMWARE_INFO)
        return "i-firmware-info";
    if (val == FU_LOGITECH_HIDPP_FEATURE_GET_DEVICE_NAME_TYPE)
        return "get-device-name-type";
    if (val == FU_LOGITECH_HIDPP_FEATURE_DFU_CONTROL)
        return "dfu-control";
    if (val == FU_LOGITECH_HIDPP_FEATURE_DFU_CONTROL_SIGNED)
        return "dfu-control-signed";
    if (val == FU_LOGITECH_HIDPP_FEATURE_DFU_CONTROL_BOLT)
        return "dfu-control-bolt";
    if (val == FU_LOGITECH_HIDPP_FEATURE_DFU)
        return "dfu";
    if (val == FU_LOGITECH_HIDPP_FEATURE_RDFU)
        return "rdfu";
    if (val == FU_LOGITECH_HIDPP_FEATURE_BATTERY_LEVEL_STATUS)
        return "battery-level-status";
    if (val == FU_LOGITECH_HIDPP_FEATURE_UNIFIED_BATTERY)
        return "unified-battery";
    if (val == FU_LOGITECH_HIDPP_FEATURE_KBD_REPROGRAMMABLE_KEYS)
        return "kbd-reprogrammable-keys";
    if (val == FU_LOGITECH_HIDPP_FEATURE_SPECIAL_KEYS_BUTTONS)
        return "special-keys-buttons";
    if (val == FU_LOGITECH_HIDPP_FEATURE_MOUSE_POINTER_BASIC)
        return "mouse-pointer-basic";
    if (val == FU_LOGITECH_HIDPP_FEATURE_ADJUSTABLE_DPI)
        return "adjustable-dpi";
    if (val == FU_LOGITECH_HIDPP_FEATURE_ADJUSTABLE_REPORT_RATE)
        return "adjustable-report-rate";
    if (val == FU_LOGITECH_HIDPP_FEATURE_COLOR_LED_EFFECTS)
        return "color-led-effects";
    if (val == FU_LOGITECH_HIDPP_FEATURE_ONBOARD_PROFILES)
        return "onboard-profiles";
    if (val == FU_LOGITECH_HIDPP_FEATURE_MOUSE_BUTTON_SPY)
        return "mouse-button-spy";
    return NULL;
}

/**
 * fu_logitech_hidpp_device_idx_to_string:
 * @val: value, e.g. %FU_LOGITECH_HIDPP_DEVICE_IDX_RECEIVER
 *
 * Converts an enumerated value to a string.
 *
 * Returns: identifier string
 **/
const gchar *
fu_logitech_hidpp_device_idx_to_string(FuLogitechHidppDeviceIdx val)
{
    if (val == FU_LOGITECH_HIDPP_DEVICE_IDX_WIRED)
        return "wired";
    if (val == FU_LOGITECH_HIDPP_DEVICE_IDX_RECEIVER)
        return "receiver";
    return NULL;
}

/**
 * fu_logitech_hidpp_report_id_to_string:
 * @val: value, e.g. %FU_LOGITECH_HIDPP_REPORT_ID_LONG
 *
 * Converts an enumerated value to a string.
 *
 * Returns: identifier string
 **/
static const gchar *
fu_logitech_hidpp_report_id_to_string(FuLogitechHidppReportId val)
{
    if (val == FU_LOGITECH_HIDPP_REPORT_ID_SHORT)
        return "short";
    if (val == FU_LOGITECH_HIDPP_REPORT_ID_LONG)
        return "long";
    if (val == FU_LOGITECH_HIDPP_REPORT_ID_VERY_LONG)
        return "very-long";
    return NULL;
}


/**
 * fu_logitech_hidpp_subid_to_string:
 * @val: value, e.g. %FU_LOGITECH_HIDPP_SUBID_POWER_KEYS
 *
 * Converts an enumerated value to a string.
 *
 * Returns: identifier string
 **/
const gchar *
fu_logitech_hidpp_subid_to_string(FuLogitechHidppSubid val)
{
    if (val == FU_LOGITECH_HIDPP_SUBID_VENDOR_SPECIFIC_KEYS)
        return "vendor-specific-keys";
    if (val == FU_LOGITECH_HIDPP_SUBID_POWER_KEYS)
        return "power-keys";
    if (val == FU_LOGITECH_HIDPP_SUBID_ROLLER)
        return "roller";
    if (val == FU_LOGITECH_HIDPP_SUBID_MOUSE_EXTRA_BUTTONS)
        return "mouse-extra-buttons";
    if (val == FU_LOGITECH_HIDPP_SUBID_BATTERY_CHARGING_LEVEL)
        return "battery-charging-level";
    if (val == FU_LOGITECH_HIDPP_SUBID_USER_INTERFACE_EVENT)
        return "user-interface-event";
    if (val == FU_LOGITECH_HIDPP_SUBID_F_LOCK_STATUS)
        return "f-lock-status";
    if (val == FU_LOGITECH_HIDPP_SUBID_CALCULATOR_RESULT)
        return "calculator-result";
    if (val == FU_LOGITECH_HIDPP_SUBID_MENU_NAVIGATE)
        return "menu-navigate";
    if (val == FU_LOGITECH_HIDPP_SUBID_FN_KEY)
        return "fn-key";
    if (val == FU_LOGITECH_HIDPP_SUBID_BATTERY_MILEAGE)
        return "battery-mileage";
    if (val == FU_LOGITECH_HIDPP_SUBID_UART_RX)
        return "uart-rx";
    if (val == FU_LOGITECH_HIDPP_SUBID_BACKLIGHT_DURATION_UPDATE)
        return "backlight-duration-update";
    if (val == FU_LOGITECH_HIDPP_SUBID_DEVICE_DISCONNECTION)
        return "device-disconnection";
    if (val == FU_LOGITECH_HIDPP_SUBID_DEVICE_CONNECTION)
        return "device-connection";
    if (val == FU_LOGITECH_HIDPP_SUBID_DEVICE_DISCOVERY)
        return "device-discovery";
    if (val == FU_LOGITECH_HIDPP_SUBID_PIN_CODE_REQUEST)
        return "pin-code-request";
    if (val == FU_LOGITECH_HIDPP_SUBID_RECEIVER_WORKING_MODE)
        return "receiver-working-mode";
    if (val == FU_LOGITECH_HIDPP_SUBID_ERROR_MESSAGE)
        return "error-message";
    if (val == FU_LOGITECH_HIDPP_SUBID_RF_LINK_CHANGE)
        return "rf-link-change";
    if (val == FU_LOGITECH_HIDPP_SUBID_HCI)
        return "hci";
    if (val == FU_LOGITECH_HIDPP_SUBID_LINK_QUALITY)
        return "link-quality";
    if (val == FU_LOGITECH_HIDPP_SUBID_DEVICE_LOCKING_CHANGED)
        return "device-locking-changed";
    if (val == FU_LOGITECH_HIDPP_SUBID_WIRELESS_DEVICE_CHANGE)
        return "wireless-device-change";
    if (val == FU_LOGITECH_HIDPP_SUBID_ACL)
        return "acl";
    if (val == FU_LOGITECH_HIDPP_SUBID_VOIP_TELEPHONY_EVENT)
        return "voip-telephony-event";
    if (val == FU_LOGITECH_HIDPP_SUBID_LED)
        return "led";
    if (val == FU_LOGITECH_HIDPP_SUBID_GESTURE_AND_AIR)
        return "gesture-and-air";
    if (val == FU_LOGITECH_HIDPP_SUBID_TOUCHPAD_MULTI_TOUCH)
        return "touchpad-multi-touch";
    if (val == FU_LOGITECH_HIDPP_SUBID_TRACEABILITY)
        return "traceability";
    if (val == FU_LOGITECH_HIDPP_SUBID_SET_REGISTER)
        return "set-register";
    if (val == FU_LOGITECH_HIDPP_SUBID_GET_REGISTER)
        return "get-register";
    if (val == FU_LOGITECH_HIDPP_SUBID_SET_LONG_REGISTER)
        return "set-long-register";
    if (val == FU_LOGITECH_HIDPP_SUBID_GET_LONG_REGISTER)
        return "get-long-register";
    if (val == FU_LOGITECH_HIDPP_SUBID_SET_VERY_LONG_REGISTER)
        return "set-very-long-register";
    if (val == FU_LOGITECH_HIDPP_SUBID_GET_VERY_LONG_REGISTER)
        return "get-very-long-register";
    if (val == FU_LOGITECH_HIDPP_SUBID_ERROR_MSG)
        return "error-msg";
    if (val == FU_LOGITECH_HIDPP_SUBID_ERROR_MSG_20)
        return "error-msg-20";
    return NULL;
}

/**
 * fu_logitech_hidpp_bootloader_cmd_to_string:
 * @val: value, e.g. %FU_LOGITECH_HIDPP_BOOTLOADER_CMD_READ
 *
 * Converts an enumerated value to a string.
 *
 * Returns: identifier string
 **/
static const gchar *
fu_logitech_hidpp_bootloader_cmd_to_string(FuLogitechHidppBootloaderCmd val)
{
    if (val == FU_LOGITECH_HIDPP_BOOTLOADER_CMD_GENERAL_ERROR)
        return "general-error";
    if (val == FU_LOGITECH_HIDPP_BOOTLOADER_CMD_READ)
        return "read";
    if (val == FU_LOGITECH_HIDPP_BOOTLOADER_CMD_WRITE)
        return "write";
    if (val == FU_LOGITECH_HIDPP_BOOTLOADER_CMD_WRITE_INVALID_ADDR)
        return "write-invalid-addr";
    if (val == FU_LOGITECH_HIDPP_BOOTLOADER_CMD_WRITE_VERIFY_FAIL)
        return "write-verify-fail";
    if (val == FU_LOGITECH_HIDPP_BOOTLOADER_CMD_WRITE_NONZERO_START)
        return "write-nonzero-start";
    if (val == FU_LOGITECH_HIDPP_BOOTLOADER_CMD_WRITE_INVALID_CRC)
        return "write-invalid-crc";
    if (val == FU_LOGITECH_HIDPP_BOOTLOADER_CMD_ERASE_PAGE)
        return "erase-page";
    if (val == FU_LOGITECH_HIDPP_BOOTLOADER_CMD_ERASE_PAGE_INVALID_ADDR)
        return "erase-page-invalid-addr";
    if (val == FU_LOGITECH_HIDPP_BOOTLOADER_CMD_ERASE_PAGE_NONZERO_START)
        return "erase-page-nonzero-start";
    if (val == FU_LOGITECH_HIDPP_BOOTLOADER_CMD_GET_HW_PLATFORM_ID)
        return "get-hw-platform-id";
    if (val == FU_LOGITECH_HIDPP_BOOTLOADER_CMD_GET_FW_VERSION)
        return "get-fw-version";
    if (val == FU_LOGITECH_HIDPP_BOOTLOADER_CMD_GET_CHECKSUM)
        return "get-checksum";
    if (val == FU_LOGITECH_HIDPP_BOOTLOADER_CMD_REBOOT)
        return "reboot";
    if (val == FU_LOGITECH_HIDPP_BOOTLOADER_CMD_GET_MEMINFO)
        return "get-meminfo";
    if (val == FU_LOGITECH_HIDPP_BOOTLOADER_CMD_GET_BL_VERSION)
        return "get-bl-version";
    if (val == FU_LOGITECH_HIDPP_BOOTLOADER_CMD_GET_INIT_FW_VERSION)
        return "get-init-fw-version";
    if (val == FU_LOGITECH_HIDPP_BOOTLOADER_CMD_READ_SIGNATURE)
        return "read-signature";
    if (val == FU_LOGITECH_HIDPP_BOOTLOADER_CMD_WRITE_RAM_BUFFER)
        return "write-ram-buffer";
    if (val == FU_LOGITECH_HIDPP_BOOTLOADER_CMD_WRITE_RAM_BUFFER_INVALID_ADDR)
        return "write-ram-buffer-invalid-addr";
    if (val == FU_LOGITECH_HIDPP_BOOTLOADER_CMD_WRITE_RAM_BUFFER_OVERFLOW)
        return "write-ram-buffer-overflow";
    if (val == FU_LOGITECH_HIDPP_BOOTLOADER_CMD_FLASH_RAM)
        return "flash-ram";
    if (val == FU_LOGITECH_HIDPP_BOOTLOADER_CMD_FLASH_RAM_INVALID_ADDR)
        return "flash-ram-invalid-addr";
    if (val == FU_LOGITECH_HIDPP_BOOTLOADER_CMD_FLASH_RAM_WRONG_CRC)
        return "flash-ram-wrong-crc";
    if (val == FU_LOGITECH_HIDPP_BOOTLOADER_CMD_FLASH_RAM_PAGE0_INVALID)
        return "flash-ram-page0-invalid";
    if (val == FU_LOGITECH_HIDPP_BOOTLOADER_CMD_FLASH_RAM_INVALID_ORDER)
        return "flash-ram-invalid-order";
    if (val == FU_LOGITECH_HIDPP_BOOTLOADER_CMD_WRITE_SIGNATURE)
        return "write-signature";
    return NULL;
}

/**
 * fu_logitech_hidpp_err_to_string:
 * @val: value, e.g. %FU_LOGITECH_HIDPP_ERR_INVALID_SUBID
 *
 * Converts an enumerated value to a string.
 *
 * Returns: identifier string
 **/
const gchar *
fu_logitech_hidpp_err_to_string(FuLogitechHidppErr val)
{
    if (val == FU_LOGITECH_HIDPP_ERR_SUCCESS)
        return "success";
    if (val == FU_LOGITECH_HIDPP_ERR_INVALID_SUBID)
        return "invalid-subid";
    if (val == FU_LOGITECH_HIDPP_ERR_INVALID_ADDRESS)
        return "invalid-address";
    if (val == FU_LOGITECH_HIDPP_ERR_INVALID_VALUE)
        return "invalid-value";
    if (val == FU_LOGITECH_HIDPP_ERR_CONNECT_FAIL)
        return "connect-fail";
    if (val == FU_LOGITECH_HIDPP_ERR_TOO_MANY_DEVICES)
        return "too-many-devices";
    if (val == FU_LOGITECH_HIDPP_ERR_ALREADY_EXISTS)
        return "already-exists";
    if (val == FU_LOGITECH_HIDPP_ERR_BUSY)
        return "busy";
    if (val == FU_LOGITECH_HIDPP_ERR_UNKNOWN_DEVICE)
        return "unknown-device";
    if (val == FU_LOGITECH_HIDPP_ERR_RESOURCE_ERROR)
        return "resource-error";
    if (val == FU_LOGITECH_HIDPP_ERR_REQUEST_UNAVAILABLE)
        return "request-unavailable";
    if (val == FU_LOGITECH_HIDPP_ERR_INVALID_PARAM_VALUE)
        return "invalid-param-value";
    if (val == FU_LOGITECH_HIDPP_ERR_WRONG_PIN_CODE)
        return "wrong-pin-code";
    return NULL;
}

/**
 * fu_logitech_hidpp_err2_to_string:
 * @val: value, e.g. %FU_LOGITECH_HIDPP_ERR2_UNKNOWN
 *
 * Converts an enumerated value to a string.
 *
 * Returns: identifier string
 **/
const gchar *
fu_logitech_hidpp_err2_to_string(FuLogitechHidppErr2 val)
{
    if (val == FU_LOGITECH_HIDPP_ERR2_NO_ERROR)
        return "no-error";
    if (val == FU_LOGITECH_HIDPP_ERR2_INVALID_ARGUMENT)
        return "invalid-argument";
    if (val == FU_LOGITECH_HIDPP_ERR2_OUT_OF_RANGE)
        return "out-of-range";
    if (val == FU_LOGITECH_HIDPP_ERR2_HW_ERROR)
        return "hw-error";
    if (val == FU_LOGITECH_HIDPP_ERR2_LOGITECH_INTERNAL)
        return "logitech-internal";
    if (val == FU_LOGITECH_HIDPP_ERR2_INVALID_FEATURE_INDEX)
        return "invalid-feature-index";
    if (val == FU_LOGITECH_HIDPP_ERR2_INVALID_FUNCTION_ID)
        return "invalid-function-id";
    if (val == FU_LOGITECH_HIDPP_ERR2_BUSY)
        return "busy";
    if (val == FU_LOGITECH_HIDPP_ERR2_UNSUPPORTED)
        return "unsupported";
    return NULL;
}

/**
 * fu_logitech_hidpp_status_to_string:
 * @val: value, e.g. %FU_LOGITECH_HIDPP_STATUS_PACKET_SUCCESS
 *
 * Converts an enumerated value to a string.
 *
 * Returns: identifier string
 **/
const gchar *
fu_logitech_hidpp_status_to_string(FuLogitechHidppStatus val)
{
    if (val == FU_LOGITECH_HIDPP_STATUS_INVALID)
        return "invalid";
    if (val == FU_LOGITECH_HIDPP_STATUS_PACKET_SUCCESS)
        return "packet-success";
    if (val == FU_LOGITECH_HIDPP_STATUS_DFU_SUCCESS)
        return "dfu-success";
    if (val == FU_LOGITECH_HIDPP_STATUS_WAIT_FOR_EVENT)
        return "wait-for-event";
    if (val == FU_LOGITECH_HIDPP_STATUS_GENERIC_ERROR04)
        return "generic-error04";
    if (val == FU_LOGITECH_HIDPP_STATUS_DFU_SUCCESS_ENTITY_RESTART_REQUIRED)
        return "dfu-success-entity-restart-required";
    if (val == FU_LOGITECH_HIDPP_STATUS_DFU_SUCCESS_SYSTEM_RESTART_REQUIRED)
        return "dfu-success-system-restart-required";
    if (val == FU_LOGITECH_HIDPP_STATUS_GENERIC_ERROR10)
        return "generic-error10";
    if (val == FU_LOGITECH_HIDPP_STATUS_BAD_VOLTAGE)
        return "bad-voltage";
    if (val == FU_LOGITECH_HIDPP_STATUS_UNKNOWN12)
        return "unknown12";
    if (val == FU_LOGITECH_HIDPP_STATUS_UNSUPPORTED_ENCRYPTION_MODE)
        return "unsupported-encryption-mode";
    if (val == FU_LOGITECH_HIDPP_STATUS_BAD_MAGIC_STRING)
        return "bad-magic-string";
    if (val == FU_LOGITECH_HIDPP_STATUS_ERASE_FAILURE)
        return "erase-failure";
    if (val == FU_LOGITECH_HIDPP_STATUS_DFU_NOT_STARTED)
        return "dfu-not-started";
    if (val == FU_LOGITECH_HIDPP_STATUS_BAD_SEQUENCE_NUMBER)
        return "bad-sequence-number";
    if (val == FU_LOGITECH_HIDPP_STATUS_UNSUPPORTED_COMMAND)
        return "unsupported-command";
    if (val == FU_LOGITECH_HIDPP_STATUS_COMMAND_IN_PROGRESS)
        return "command-in-progress";
    if (val == FU_LOGITECH_HIDPP_STATUS_ADDRESS_OUT_OF_RANGE)
        return "address-out-of-range";
    if (val == FU_LOGITECH_HIDPP_STATUS_UNALIGNED_ADDRESS)
        return "unaligned-address";
    if (val == FU_LOGITECH_HIDPP_STATUS_BAD_SIZE)
        return "bad-size";
    if (val == FU_LOGITECH_HIDPP_STATUS_MISSING_PROGRAM_DATA)
        return "missing-program-data";
    if (val == FU_LOGITECH_HIDPP_STATUS_MISSING_CHECK_DATA)
        return "missing-check-data";
    if (val == FU_LOGITECH_HIDPP_STATUS_PROGRAM_FAILED_TO_WRITE)
        return "program-failed-to-write";
    if (val == FU_LOGITECH_HIDPP_STATUS_PROGRAM_FAILED_TO_VERIFY)
        return "program-failed-to-verify";
    if (val == FU_LOGITECH_HIDPP_STATUS_BAD_FIRMWARE)
        return "bad-firmware";
    if (val == FU_LOGITECH_HIDPP_STATUS_FIRMWARE_CHECK_FAILURE)
        return "firmware-check-failure";
    if (val == FU_LOGITECH_HIDPP_STATUS_BLOCKED_COMMAND)
        return "blocked-command";
    return NULL;
}



/**
 * fu_struct_logitech_hidpp_bootloader_pkt_ref: (skip):
 **/
FuStructLogitechHidppBootloaderPkt *
fu_struct_logitech_hidpp_bootloader_pkt_ref(FuStructLogitechHidppBootloaderPkt *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_logitech_hidpp_bootloader_pkt_unref: (skip):
 **/
void
fu_struct_logitech_hidpp_bootloader_pkt_unref(FuStructLogitechHidppBootloaderPkt *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructLogitechHidppBootloaderPkt refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_logitech_hidpp_bootloader_pkt_new_internal: (skip):
 **/
static FuStructLogitechHidppBootloaderPkt *
fu_struct_logitech_hidpp_bootloader_pkt_new_internal(void)
{
    FuStructLogitechHidppBootloaderPkt *st = g_new0(FuStructLogitechHidppBootloaderPkt, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_logitech_hidpp_bootloader_pkt_get_cmd: (skip):
 **/
FuLogitechHidppBootloaderCmd
fu_struct_logitech_hidpp_bootloader_pkt_get_cmd(const FuStructLogitechHidppBootloaderPkt *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[0];
}
/**
 * fu_struct_logitech_hidpp_bootloader_pkt_get_addr: (skip):
 **/
guint16
fu_struct_logitech_hidpp_bootloader_pkt_get_addr(const FuStructLogitechHidppBootloaderPkt *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 1, G_BIG_ENDIAN);
}
/**
 * fu_struct_logitech_hidpp_bootloader_pkt_get_len: (skip):
 **/
guint8
fu_struct_logitech_hidpp_bootloader_pkt_get_len(const FuStructLogitechHidppBootloaderPkt *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[3];
}
/**
 * fu_struct_logitech_hidpp_bootloader_pkt_get_data: (skip):
 **/
const guint8 *
fu_struct_logitech_hidpp_bootloader_pkt_get_data(const FuStructLogitechHidppBootloaderPkt *st, gsize *bufsz)
{
    g_return_val_if_fail(st != NULL, NULL);
    if (bufsz != NULL)
        *bufsz = 28;
    return st->buf->data + 4;
}

/* setters */
/**
 * fu_struct_logitech_hidpp_bootloader_pkt_set_cmd: (skip):
 **/
void
fu_struct_logitech_hidpp_bootloader_pkt_set_cmd(FuStructLogitechHidppBootloaderPkt *st, FuLogitechHidppBootloaderCmd value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[0] = value;
}
/**
 * fu_struct_logitech_hidpp_bootloader_pkt_set_addr: (skip):
 **/
void
fu_struct_logitech_hidpp_bootloader_pkt_set_addr(FuStructLogitechHidppBootloaderPkt *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 1, value, G_BIG_ENDIAN);
}
/**
 * fu_struct_logitech_hidpp_bootloader_pkt_set_len: (skip):
 **/
void
fu_struct_logitech_hidpp_bootloader_pkt_set_len(FuStructLogitechHidppBootloaderPkt *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[3] = value;
}
/**
 * fu_struct_logitech_hidpp_bootloader_pkt_set_data: (skip):
 **/
gboolean
fu_struct_logitech_hidpp_bootloader_pkt_set_data(FuStructLogitechHidppBootloaderPkt *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, 4, buf, bufsz, 0x0, bufsz, error);
}
/**
 * fu_struct_logitech_hidpp_bootloader_pkt_new: (skip):
 **/
FuStructLogitechHidppBootloaderPkt *
fu_struct_logitech_hidpp_bootloader_pkt_new(void)
{
    FuStructLogitechHidppBootloaderPkt *st = fu_struct_logitech_hidpp_bootloader_pkt_new_internal();
    st->buf = g_byte_array_sized_new(32);
    fu_byte_array_set_size(st->buf, 32, 0x0);
    return st;
}
/**
 * fu_struct_logitech_hidpp_bootloader_pkt_to_string: (skip):
 **/
static gchar *
fu_struct_logitech_hidpp_bootloader_pkt_to_string(const FuStructLogitechHidppBootloaderPkt *st)
{
    g_autoptr(GString) str = g_string_new("FuStructLogitechHidppBootloaderPkt:\n");
    g_return_val_if_fail(st != NULL, NULL);
    {
        const gchar *tmp = fu_logitech_hidpp_bootloader_cmd_to_string(fu_struct_logitech_hidpp_bootloader_pkt_get_cmd(st));
        if (tmp != NULL) {
            g_string_append_printf(str, "  cmd: 0x%x [%s]\n", (guint) fu_struct_logitech_hidpp_bootloader_pkt_get_cmd(st), tmp);
        } else {
            g_string_append_printf(str, "  cmd: 0x%x\n", (guint) fu_struct_logitech_hidpp_bootloader_pkt_get_cmd(st));
        }
    }
    g_string_append_printf(str, "  addr: 0x%x\n",
                           (guint) fu_struct_logitech_hidpp_bootloader_pkt_get_addr(st));
    g_string_append_printf(str, "  len: 0x%x\n",
                           (guint) fu_struct_logitech_hidpp_bootloader_pkt_get_len(st));
    {
        gsize bufsz = 0;
        const guint8 *buf = fu_struct_logitech_hidpp_bootloader_pkt_get_data(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, "  data: 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_logitech_hidpp_bootloader_pkt_validate_internal(FuStructLogitechHidppBootloaderPkt *st, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    return TRUE;
}
static gboolean
fu_struct_logitech_hidpp_bootloader_pkt_parse_internal(FuStructLogitechHidppBootloaderPkt *st, GError **error)
{
    if (g_log_get_debug_enabled()) {
        g_autofree gchar *str = fu_struct_logitech_hidpp_bootloader_pkt_to_string(st);
        g_debug("%s", str);
    }
    if (!fu_struct_logitech_hidpp_bootloader_pkt_validate_internal(st, error))
        return FALSE;
    return TRUE;
}

/**
 * fu_struct_logitech_hidpp_bootloader_pkt_parse: (skip):
 **/
FuStructLogitechHidppBootloaderPkt *
fu_struct_logitech_hidpp_bootloader_pkt_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error)
{
    g_autoptr(FuStructLogitechHidppBootloaderPkt) st = fu_struct_logitech_hidpp_bootloader_pkt_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, 32, error)) {
        g_prefix_error_literal(error, "invalid struct FuStructLogitechHidppBootloaderPkt: ");
        return NULL;
    }
    st->buf = g_byte_array_new();
    g_byte_array_append(st->buf, buf + offset, 32);
    if (!fu_struct_logitech_hidpp_bootloader_pkt_parse_internal(st, error))
        return NULL;
    return g_steal_pointer(&st);
}
/**
 * fu_struct_logitech_hidpp_msg_ref: (skip):
 **/
FuStructLogitechHidppMsg *
fu_struct_logitech_hidpp_msg_ref(FuStructLogitechHidppMsg *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_logitech_hidpp_msg_unref: (skip):
 **/
void
fu_struct_logitech_hidpp_msg_unref(FuStructLogitechHidppMsg *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructLogitechHidppMsg refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_logitech_hidpp_msg_new_internal: (skip):
 **/
static FuStructLogitechHidppMsg *
fu_struct_logitech_hidpp_msg_new_internal(void)
{
    FuStructLogitechHidppMsg *st = g_new0(FuStructLogitechHidppMsg, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_logitech_hidpp_msg_get_report_id: (skip):
 **/
FuLogitechHidppReportId
fu_struct_logitech_hidpp_msg_get_report_id(const FuStructLogitechHidppMsg *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[0];
}
/**
 * fu_struct_logitech_hidpp_msg_get_device_id: (skip):
 **/
FuLogitechHidppDeviceIdx
fu_struct_logitech_hidpp_msg_get_device_id(const FuStructLogitechHidppMsg *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[1];
}
/**
 * fu_struct_logitech_hidpp_msg_get_sub_id: (skip):
 **/
FuLogitechHidppSubid
fu_struct_logitech_hidpp_msg_get_sub_id(const FuStructLogitechHidppMsg *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[2];
}
/**
 * fu_struct_logitech_hidpp_msg_get_function_id: (skip):
 **/
guint8
fu_struct_logitech_hidpp_msg_get_function_id(const FuStructLogitechHidppMsg *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[3];
}
/**
 * fu_struct_logitech_hidpp_msg_get_data: (skip):
 **/
const guint8 *
fu_struct_logitech_hidpp_msg_get_data(const FuStructLogitechHidppMsg *st, gsize *bufsz)
{
    g_return_val_if_fail(st != NULL, NULL);
    if (bufsz != NULL)
        *bufsz = 47;
    return st->buf->data + 4;
}

/* setters */
/**
 * fu_struct_logitech_hidpp_msg_set_report_id: (skip):
 **/
void
fu_struct_logitech_hidpp_msg_set_report_id(FuStructLogitechHidppMsg *st, FuLogitechHidppReportId value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[0] = value;
}
/**
 * fu_struct_logitech_hidpp_msg_set_device_id: (skip):
 **/
void
fu_struct_logitech_hidpp_msg_set_device_id(FuStructLogitechHidppMsg *st, FuLogitechHidppDeviceIdx value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[1] = value;
}
/**
 * fu_struct_logitech_hidpp_msg_set_sub_id: (skip):
 **/
void
fu_struct_logitech_hidpp_msg_set_sub_id(FuStructLogitechHidppMsg *st, FuLogitechHidppSubid value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[2] = value;
}
/**
 * fu_struct_logitech_hidpp_msg_set_function_id: (skip):
 **/
void
fu_struct_logitech_hidpp_msg_set_function_id(FuStructLogitechHidppMsg *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[3] = value;
}
/**
 * fu_struct_logitech_hidpp_msg_set_data: (skip):
 **/
gboolean
fu_struct_logitech_hidpp_msg_set_data(FuStructLogitechHidppMsg *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, 4, buf, bufsz, 0x0, bufsz, error);
}
/**
 * fu_struct_logitech_hidpp_msg_new: (skip):
 **/
FuStructLogitechHidppMsg *
fu_struct_logitech_hidpp_msg_new(void)
{
    FuStructLogitechHidppMsg *st = fu_struct_logitech_hidpp_msg_new_internal();
    st->buf = g_byte_array_sized_new(51);
    fu_byte_array_set_size(st->buf, 51, 0x0);
    return st;
}
/**
 * fu_struct_logitech_hidpp_msg_to_string: (skip):
 **/
gchar *
fu_struct_logitech_hidpp_msg_to_string(const FuStructLogitechHidppMsg *st)
{
    g_autoptr(GString) str = g_string_new("FuStructLogitechHidppMsg:\n");
    g_return_val_if_fail(st != NULL, NULL);
    {
        const gchar *tmp = fu_logitech_hidpp_report_id_to_string(fu_struct_logitech_hidpp_msg_get_report_id(st));
        if (tmp != NULL) {
            g_string_append_printf(str, "  report_id: 0x%x [%s]\n", (guint) fu_struct_logitech_hidpp_msg_get_report_id(st), tmp);
        } else {
            g_string_append_printf(str, "  report_id: 0x%x\n", (guint) fu_struct_logitech_hidpp_msg_get_report_id(st));
        }
    }
    {
        const gchar *tmp = fu_logitech_hidpp_device_idx_to_string(fu_struct_logitech_hidpp_msg_get_device_id(st));
        if (tmp != NULL) {
            g_string_append_printf(str, "  device_id: 0x%x [%s]\n", (guint) fu_struct_logitech_hidpp_msg_get_device_id(st), tmp);
        } else {
            g_string_append_printf(str, "  device_id: 0x%x\n", (guint) fu_struct_logitech_hidpp_msg_get_device_id(st));
        }
    }
    {
        const gchar *tmp = fu_logitech_hidpp_subid_to_string(fu_struct_logitech_hidpp_msg_get_sub_id(st));
        if (tmp != NULL) {
            g_string_append_printf(str, "  sub_id: 0x%x [%s]\n", (guint) fu_struct_logitech_hidpp_msg_get_sub_id(st), tmp);
        } else {
            g_string_append_printf(str, "  sub_id: 0x%x\n", (guint) fu_struct_logitech_hidpp_msg_get_sub_id(st));
        }
    }
    g_string_append_printf(str, "  function_id: 0x%x\n",
                           (guint) fu_struct_logitech_hidpp_msg_get_function_id(st));
    {
        gsize bufsz = 0;
        const guint8 *buf = fu_struct_logitech_hidpp_msg_get_data(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, "  data: 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_logitech_hidpp_msg_validate_internal(FuStructLogitechHidppMsg *st, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    return TRUE;
}
static gboolean
fu_struct_logitech_hidpp_msg_parse_internal(FuStructLogitechHidppMsg *st, GError **error)
{
    if (g_log_get_debug_enabled()) {
        g_autofree gchar *str = fu_struct_logitech_hidpp_msg_to_string(st);
        g_debug("%s", str);
    }
    if (!fu_struct_logitech_hidpp_msg_validate_internal(st, error))
        return FALSE;
    return TRUE;
}

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