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

#include "config.h"

#include <glib.h>

#include "fu-lxs-touch-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_lxs_touch_cmd_to_string:
 * @val: value, e.g. %FU_LXS_TOUCH_CMD_FLASH_4KB_UPDATE_MODE
 *
 * Converts an enumerated value to a string.
 *
 * Returns: identifier string
 **/
static const gchar *
fu_lxs_touch_cmd_to_string(FuLxsTouchCmd val)
{
    if (val == FU_LXS_TOUCH_CMD_FLASH_WRITE)
        return "flash-write";
    if (val == FU_LXS_TOUCH_CMD_FLASH_4KB_UPDATE_MODE)
        return "flash-4kb-update-mode";
    if (val == FU_LXS_TOUCH_CMD_FLASH_GET_VERIFY)
        return "flash-get-verify";
    if (val == FU_LXS_TOUCH_CMD_WATCHDOG_RESET)
        return "watchdog-reset";
    return NULL;
}

/**
 * fu_lxs_touch_mode_to_string:
 * @val: value, e.g. %FU_LXS_TOUCH_MODE_DIAG
 *
 * Converts an enumerated value to a string.
 *
 * Returns: identifier string
 **/
static const gchar *
fu_lxs_touch_mode_to_string(FuLxsTouchMode val)
{
    if (val == FU_LXS_TOUCH_MODE_NORMAL)
        return "normal";
    if (val == FU_LXS_TOUCH_MODE_DIAG)
        return "diag";
    if (val == FU_LXS_TOUCH_MODE_DFUP)
        return "dfup";
    return NULL;
}

/**
 * fu_lxs_touch_ready_status_to_string:
 * @val: value, e.g. %FU_LXS_TOUCH_READY_STATUS_NONE
 *
 * Converts an enumerated value to a string.
 *
 * Returns: identifier string
 **/
static const gchar *
fu_lxs_touch_ready_status_to_string(FuLxsTouchReadyStatus val)
{
    if (val == FU_LXS_TOUCH_READY_STATUS_READY)
        return "ready";
    if (val == FU_LXS_TOUCH_READY_STATUS_NONE)
        return "none";
    if (val == FU_LXS_TOUCH_READY_STATUS_LOG)
        return "log";
    if (val == FU_LXS_TOUCH_READY_STATUS_IMAGE)
        return "image";
    return NULL;
}

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

/* getters */

/* setters */
/**
 * fu_struct_lxs_touch_packet_set_report_id: (skip):
 **/
static void
fu_struct_lxs_touch_packet_set_report_id(FuStructLxsTouchPacket *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[0] = value;
}
/**
 * fu_struct_lxs_touch_packet_set_flag: (skip):
 **/
void
fu_struct_lxs_touch_packet_set_flag(FuStructLxsTouchPacket *st, FuLxsTouchFlag value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[1] = value;
}
/**
 * fu_struct_lxs_touch_packet_set_length: (skip):
 **/
void
fu_struct_lxs_touch_packet_set_length(FuStructLxsTouchPacket *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 2, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_lxs_touch_packet_set_command: (skip):
 **/
void
fu_struct_lxs_touch_packet_set_command(FuStructLxsTouchPacket *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 4, value, G_BIG_ENDIAN);
}
/**
 * fu_struct_lxs_touch_packet_new: (skip):
 **/
FuStructLxsTouchPacket *
fu_struct_lxs_touch_packet_new(void)
{
    FuStructLxsTouchPacket *st = fu_struct_lxs_touch_packet_new_internal();
    st->buf = g_byte_array_sized_new(6);
    fu_byte_array_set_size(st->buf, 6, 0x0);
    fu_struct_lxs_touch_packet_set_report_id(st, 0x09);
    return st;
}
/**
 * fu_struct_lxs_touch_interface_ref: (skip):
 **/
FuStructLxsTouchInterface *
fu_struct_lxs_touch_interface_ref(FuStructLxsTouchInterface *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_lxs_touch_interface_unref: (skip):
 **/
void
fu_struct_lxs_touch_interface_unref(FuStructLxsTouchInterface *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructLxsTouchInterface refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_lxs_touch_interface_new_internal: (skip):
 **/
static FuStructLxsTouchInterface *
fu_struct_lxs_touch_interface_new_internal(void)
{
    FuStructLxsTouchInterface *st = g_new0(FuStructLxsTouchInterface, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_lxs_touch_interface_get_protocol_name: (skip):
 **/
gchar *
fu_struct_lxs_touch_interface_get_protocol_name(const FuStructLxsTouchInterface *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    return fu_memstrsafe(st->buf->data, st->buf->len, 0, 8, NULL);
}

/* setters */
/**
 * fu_struct_lxs_touch_interface_to_string: (skip):
 **/
static gchar *
fu_struct_lxs_touch_interface_to_string(const FuStructLxsTouchInterface *st)
{
    g_autoptr(GString) str = g_string_new("FuStructLxsTouchInterface:\n");
    g_return_val_if_fail(st != NULL, NULL);
    {
        g_autofree gchar *tmp = fu_struct_lxs_touch_interface_get_protocol_name(st);
        if (tmp != NULL)
            g_string_append_printf(str, "  protocol_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_lxs_touch_interface_validate_internal(FuStructLxsTouchInterface *st, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    return TRUE;
}
static gboolean
fu_struct_lxs_touch_interface_parse_internal(FuStructLxsTouchInterface *st, GError **error)
{
    if (g_log_get_debug_enabled()) {
        g_autofree gchar *str = fu_struct_lxs_touch_interface_to_string(st);
        g_debug("%s", str);
    }
    if (!fu_struct_lxs_touch_interface_validate_internal(st, error))
        return FALSE;
    return TRUE;
}

/**
 * fu_struct_lxs_touch_interface_parse: (skip):
 **/
FuStructLxsTouchInterface *
fu_struct_lxs_touch_interface_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error)
{
    g_autoptr(FuStructLxsTouchInterface) st = fu_struct_lxs_touch_interface_new_internal();
    g_return_val_if_fail(buf != NULL, NULL);
    g_return_val_if_fail(error == NULL || *error == NULL, NULL);
    if (!fu_memchk_read(bufsz, offset, 8, error)) {
        g_prefix_error_literal(error, "invalid struct FuStructLxsTouchInterface: ");
        return NULL;
    }
    st->buf = g_byte_array_new();
    g_byte_array_append(st->buf, buf + offset, 8);
    if (!fu_struct_lxs_touch_interface_parse_internal(st, error))
        return NULL;
    return g_steal_pointer(&st);
}
/**
 * fu_struct_lxs_touch_panel_ref: (skip):
 **/
FuStructLxsTouchPanel *
fu_struct_lxs_touch_panel_ref(FuStructLxsTouchPanel *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_lxs_touch_panel_unref: (skip):
 **/
void
fu_struct_lxs_touch_panel_unref(FuStructLxsTouchPanel *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructLxsTouchPanel refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_lxs_touch_panel_new_internal: (skip):
 **/
static FuStructLxsTouchPanel *
fu_struct_lxs_touch_panel_new_internal(void)
{
    FuStructLxsTouchPanel *st = g_new0(FuStructLxsTouchPanel, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_lxs_touch_panel_get_x_resolution: (skip):
 **/
guint16
fu_struct_lxs_touch_panel_get_x_resolution(const FuStructLxsTouchPanel *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 0, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_lxs_touch_panel_get_y_resolution: (skip):
 **/
guint16
fu_struct_lxs_touch_panel_get_y_resolution(const FuStructLxsTouchPanel *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 2, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_lxs_touch_panel_get_x_node: (skip):
 **/
guint8
fu_struct_lxs_touch_panel_get_x_node(const FuStructLxsTouchPanel *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[4];
}
/**
 * fu_struct_lxs_touch_panel_get_y_node: (skip):
 **/
guint8
fu_struct_lxs_touch_panel_get_y_node(const FuStructLxsTouchPanel *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[5];
}

/* setters */
/**
 * fu_struct_lxs_touch_panel_to_string: (skip):
 **/
static gchar *
fu_struct_lxs_touch_panel_to_string(const FuStructLxsTouchPanel *st)
{
    g_autoptr(GString) str = g_string_new("FuStructLxsTouchPanel:\n");
    g_return_val_if_fail(st != NULL, NULL);
    g_string_append_printf(str, "  x_resolution: 0x%x\n",
                           (guint) fu_struct_lxs_touch_panel_get_x_resolution(st));
    g_string_append_printf(str, "  y_resolution: 0x%x\n",
                           (guint) fu_struct_lxs_touch_panel_get_y_resolution(st));
    g_string_append_printf(str, "  x_node: 0x%x\n",
                           (guint) fu_struct_lxs_touch_panel_get_x_node(st));
    g_string_append_printf(str, "  y_node: 0x%x\n",
                           (guint) fu_struct_lxs_touch_panel_get_y_node(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_lxs_touch_panel_validate_internal(FuStructLxsTouchPanel *st, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    return TRUE;
}
static gboolean
fu_struct_lxs_touch_panel_parse_internal(FuStructLxsTouchPanel *st, GError **error)
{
    if (g_log_get_debug_enabled()) {
        g_autofree gchar *str = fu_struct_lxs_touch_panel_to_string(st);
        g_debug("%s", str);
    }
    if (!fu_struct_lxs_touch_panel_validate_internal(st, error))
        return FALSE;
    return TRUE;
}

/**
 * fu_struct_lxs_touch_panel_parse: (skip):
 **/
FuStructLxsTouchPanel *
fu_struct_lxs_touch_panel_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error)
{
    g_autoptr(FuStructLxsTouchPanel) st = fu_struct_lxs_touch_panel_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 FuStructLxsTouchPanel: ");
        return NULL;
    }
    st->buf = g_byte_array_new();
    g_byte_array_append(st->buf, buf + offset, 6);
    if (!fu_struct_lxs_touch_panel_parse_internal(st, error))
        return NULL;
    return g_steal_pointer(&st);
}
/**
 * fu_struct_lxs_touch_version_ref: (skip):
 **/
FuStructLxsTouchVersion *
fu_struct_lxs_touch_version_ref(FuStructLxsTouchVersion *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_lxs_touch_version_unref: (skip):
 **/
void
fu_struct_lxs_touch_version_unref(FuStructLxsTouchVersion *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructLxsTouchVersion refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_lxs_touch_version_new_internal: (skip):
 **/
static FuStructLxsTouchVersion *
fu_struct_lxs_touch_version_new_internal(void)
{
    FuStructLxsTouchVersion *st = g_new0(FuStructLxsTouchVersion, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_lxs_touch_version_get_boot_ver: (skip):
 **/
guint16
fu_struct_lxs_touch_version_get_boot_ver(const FuStructLxsTouchVersion *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 0, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_lxs_touch_version_get_core_ver: (skip):
 **/
guint16
fu_struct_lxs_touch_version_get_core_ver(const FuStructLxsTouchVersion *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 2, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_lxs_touch_version_get_app_ver: (skip):
 **/
guint16
fu_struct_lxs_touch_version_get_app_ver(const FuStructLxsTouchVersion *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 4, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_lxs_touch_version_get_param_ver: (skip):
 **/
guint16
fu_struct_lxs_touch_version_get_param_ver(const FuStructLxsTouchVersion *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 6, G_LITTLE_ENDIAN);
}

/* setters */
/**
 * fu_struct_lxs_touch_version_to_string: (skip):
 **/
static gchar *
fu_struct_lxs_touch_version_to_string(const FuStructLxsTouchVersion *st)
{
    g_autoptr(GString) str = g_string_new("FuStructLxsTouchVersion:\n");
    g_return_val_if_fail(st != NULL, NULL);
    g_string_append_printf(str, "  boot_ver: 0x%x\n",
                           (guint) fu_struct_lxs_touch_version_get_boot_ver(st));
    g_string_append_printf(str, "  core_ver: 0x%x\n",
                           (guint) fu_struct_lxs_touch_version_get_core_ver(st));
    g_string_append_printf(str, "  app_ver: 0x%x\n",
                           (guint) fu_struct_lxs_touch_version_get_app_ver(st));
    g_string_append_printf(str, "  param_ver: 0x%x\n",
                           (guint) fu_struct_lxs_touch_version_get_param_ver(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_lxs_touch_version_validate_internal(FuStructLxsTouchVersion *st, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    return TRUE;
}
static gboolean
fu_struct_lxs_touch_version_parse_internal(FuStructLxsTouchVersion *st, GError **error)
{
    if (g_log_get_debug_enabled()) {
        g_autofree gchar *str = fu_struct_lxs_touch_version_to_string(st);
        g_debug("%s", str);
    }
    if (!fu_struct_lxs_touch_version_validate_internal(st, error))
        return FALSE;
    return TRUE;
}

/**
 * fu_struct_lxs_touch_version_parse: (skip):
 **/
FuStructLxsTouchVersion *
fu_struct_lxs_touch_version_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error)
{
    g_autoptr(FuStructLxsTouchVersion) st = fu_struct_lxs_touch_version_new_internal();
    g_return_val_if_fail(buf != NULL, NULL);
    g_return_val_if_fail(error == NULL || *error == NULL, NULL);
    if (!fu_memchk_read(bufsz, offset, 8, error)) {
        g_prefix_error_literal(error, "invalid struct FuStructLxsTouchVersion: ");
        return NULL;
    }
    st->buf = g_byte_array_new();
    g_byte_array_append(st->buf, buf + offset, 8);
    if (!fu_struct_lxs_touch_version_parse_internal(st, error))
        return NULL;
    return g_steal_pointer(&st);
}
/**
 * fu_struct_lxs_touch_crc_ref: (skip):
 **/
FuStructLxsTouchCrc *
fu_struct_lxs_touch_crc_ref(FuStructLxsTouchCrc *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_lxs_touch_crc_unref: (skip):
 **/
void
fu_struct_lxs_touch_crc_unref(FuStructLxsTouchCrc *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructLxsTouchCrc 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_lxs_touch_setter_ref: (skip):
 **/
FuStructLxsTouchSetter *
fu_struct_lxs_touch_setter_ref(FuStructLxsTouchSetter *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_lxs_touch_setter_unref: (skip):
 **/
void
fu_struct_lxs_touch_setter_unref(FuStructLxsTouchSetter *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructLxsTouchSetter refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_lxs_touch_setter_new_internal: (skip):
 **/
static FuStructLxsTouchSetter *
fu_struct_lxs_touch_setter_new_internal(void)
{
    FuStructLxsTouchSetter *st = g_new0(FuStructLxsTouchSetter, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_lxs_touch_setter_get_mode: (skip):
 **/
FuLxsTouchMode
fu_struct_lxs_touch_setter_get_mode(const FuStructLxsTouchSetter *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[0];
}
/**
 * fu_struct_lxs_touch_setter_get_event_trigger_type: (skip):
 **/
guint8
fu_struct_lxs_touch_setter_get_event_trigger_type(const FuStructLxsTouchSetter *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[1];
}

/* setters */
/**
 * fu_struct_lxs_touch_setter_set_mode: (skip):
 **/
void
fu_struct_lxs_touch_setter_set_mode(FuStructLxsTouchSetter *st, FuLxsTouchMode value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[0] = value;
}
/**
 * fu_struct_lxs_touch_setter_set_event_trigger_type: (skip):
 **/
void
fu_struct_lxs_touch_setter_set_event_trigger_type(FuStructLxsTouchSetter *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[1] = value;
}
/**
 * fu_struct_lxs_touch_setter_new: (skip):
 **/
FuStructLxsTouchSetter *
fu_struct_lxs_touch_setter_new(void)
{
    FuStructLxsTouchSetter *st = fu_struct_lxs_touch_setter_new_internal();
    st->buf = g_byte_array_sized_new(2);
    fu_byte_array_set_size(st->buf, 2, 0x0);
    return st;
}
/**
 * fu_struct_lxs_touch_setter_to_string: (skip):
 **/
static gchar *
fu_struct_lxs_touch_setter_to_string(const FuStructLxsTouchSetter *st)
{
    g_autoptr(GString) str = g_string_new("FuStructLxsTouchSetter:\n");
    g_return_val_if_fail(st != NULL, NULL);
    {
        const gchar *tmp = fu_lxs_touch_mode_to_string(fu_struct_lxs_touch_setter_get_mode(st));
        if (tmp != NULL) {
            g_string_append_printf(str, "  mode: 0x%x [%s]\n", (guint) fu_struct_lxs_touch_setter_get_mode(st), tmp);
        } else {
            g_string_append_printf(str, "  mode: 0x%x\n", (guint) fu_struct_lxs_touch_setter_get_mode(st));
        }
    }
    g_string_append_printf(str, "  event_trigger_type: 0x%x\n",
                           (guint) fu_struct_lxs_touch_setter_get_event_trigger_type(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_lxs_touch_setter_validate_internal(FuStructLxsTouchSetter *st, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    return TRUE;
}
static gboolean
fu_struct_lxs_touch_setter_parse_internal(FuStructLxsTouchSetter *st, GError **error)
{
    if (g_log_get_debug_enabled()) {
        g_autofree gchar *str = fu_struct_lxs_touch_setter_to_string(st);
        g_debug("%s", str);
    }
    if (!fu_struct_lxs_touch_setter_validate_internal(st, error))
        return FALSE;
    return TRUE;
}

/**
 * fu_struct_lxs_touch_setter_parse: (skip):
 **/
FuStructLxsTouchSetter *
fu_struct_lxs_touch_setter_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error)
{
    g_autoptr(FuStructLxsTouchSetter) st = fu_struct_lxs_touch_setter_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, 2, error)) {
        g_prefix_error_literal(error, "invalid struct FuStructLxsTouchSetter: ");
        return NULL;
    }
    st->buf = g_byte_array_new();
    g_byte_array_append(st->buf, buf + offset, 2);
    if (!fu_struct_lxs_touch_setter_parse_internal(st, error))
        return NULL;
    return g_steal_pointer(&st);
}
/**
 * fu_struct_lxs_touch_getter_ref: (skip):
 **/
FuStructLxsTouchGetter *
fu_struct_lxs_touch_getter_ref(FuStructLxsTouchGetter *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_lxs_touch_getter_unref: (skip):
 **/
void
fu_struct_lxs_touch_getter_unref(FuStructLxsTouchGetter *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructLxsTouchGetter refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_lxs_touch_getter_new_internal: (skip):
 **/
static FuStructLxsTouchGetter *
fu_struct_lxs_touch_getter_new_internal(void)
{
    FuStructLxsTouchGetter *st = g_new0(FuStructLxsTouchGetter, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_lxs_touch_getter_get_ready_status: (skip):
 **/
FuLxsTouchReadyStatus
fu_struct_lxs_touch_getter_get_ready_status(const FuStructLxsTouchGetter *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[0];
}
/**
 * fu_struct_lxs_touch_getter_get_event_ready: (skip):
 **/
guint8
fu_struct_lxs_touch_getter_get_event_ready(const FuStructLxsTouchGetter *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[1];
}

/* setters */
/**
 * fu_struct_lxs_touch_getter_to_string: (skip):
 **/
static gchar *
fu_struct_lxs_touch_getter_to_string(const FuStructLxsTouchGetter *st)
{
    g_autoptr(GString) str = g_string_new("FuStructLxsTouchGetter:\n");
    g_return_val_if_fail(st != NULL, NULL);
    {
        const gchar *tmp = fu_lxs_touch_ready_status_to_string(fu_struct_lxs_touch_getter_get_ready_status(st));
        if (tmp != NULL) {
            g_string_append_printf(str, "  ready_status: 0x%x [%s]\n", (guint) fu_struct_lxs_touch_getter_get_ready_status(st), tmp);
        } else {
            g_string_append_printf(str, "  ready_status: 0x%x\n", (guint) fu_struct_lxs_touch_getter_get_ready_status(st));
        }
    }
    g_string_append_printf(str, "  event_ready: 0x%x\n",
                           (guint) fu_struct_lxs_touch_getter_get_event_ready(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_lxs_touch_getter_validate_internal(FuStructLxsTouchGetter *st, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    return TRUE;
}
static gboolean
fu_struct_lxs_touch_getter_parse_internal(FuStructLxsTouchGetter *st, GError **error)
{
    if (g_log_get_debug_enabled()) {
        g_autofree gchar *str = fu_struct_lxs_touch_getter_to_string(st);
        g_debug("%s", str);
    }
    if (!fu_struct_lxs_touch_getter_validate_internal(st, error))
        return FALSE;
    return TRUE;
}

/**
 * fu_struct_lxs_touch_getter_parse: (skip):
 **/
FuStructLxsTouchGetter *
fu_struct_lxs_touch_getter_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error)
{
    g_autoptr(FuStructLxsTouchGetter) st = fu_struct_lxs_touch_getter_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, 2, error)) {
        g_prefix_error_literal(error, "invalid struct FuStructLxsTouchGetter: ");
        return NULL;
    }
    st->buf = g_byte_array_new();
    g_byte_array_append(st->buf, buf + offset, 2);
    if (!fu_struct_lxs_touch_getter_parse_internal(st, error))
        return NULL;
    return g_steal_pointer(&st);
}
/**
 * fu_struct_lxs_touch_flash_iap_cmd_ref: (skip):
 **/
FuStructLxsTouchFlashIapCmd *
fu_struct_lxs_touch_flash_iap_cmd_ref(FuStructLxsTouchFlashIapCmd *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_lxs_touch_flash_iap_cmd_unref: (skip):
 **/
void
fu_struct_lxs_touch_flash_iap_cmd_unref(FuStructLxsTouchFlashIapCmd *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructLxsTouchFlashIapCmd refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_lxs_touch_flash_iap_cmd_new_internal: (skip):
 **/
static FuStructLxsTouchFlashIapCmd *
fu_struct_lxs_touch_flash_iap_cmd_new_internal(void)
{
    FuStructLxsTouchFlashIapCmd *st = g_new0(FuStructLxsTouchFlashIapCmd, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_lxs_touch_flash_iap_cmd_get_addr: (skip):
 **/
guint32
fu_struct_lxs_touch_flash_iap_cmd_get_addr(const FuStructLxsTouchFlashIapCmd *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint32(st->buf->data + 0, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_lxs_touch_flash_iap_cmd_get_size: (skip):
 **/
guint16
fu_struct_lxs_touch_flash_iap_cmd_get_size(const FuStructLxsTouchFlashIapCmd *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 4, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_lxs_touch_flash_iap_cmd_get_status: (skip):
 **/
guint8
fu_struct_lxs_touch_flash_iap_cmd_get_status(const FuStructLxsTouchFlashIapCmd *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[6];
}
/**
 * fu_struct_lxs_touch_flash_iap_cmd_get_cmd: (skip):
 **/
FuLxsTouchCmd
fu_struct_lxs_touch_flash_iap_cmd_get_cmd(const FuStructLxsTouchFlashIapCmd *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[7];
}

/* setters */
/**
 * fu_struct_lxs_touch_flash_iap_cmd_set_addr: (skip):
 **/
void
fu_struct_lxs_touch_flash_iap_cmd_set_addr(FuStructLxsTouchFlashIapCmd *st, guint32 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint32(st->buf->data + 0, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_lxs_touch_flash_iap_cmd_set_size: (skip):
 **/
void
fu_struct_lxs_touch_flash_iap_cmd_set_size(FuStructLxsTouchFlashIapCmd *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 4, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_lxs_touch_flash_iap_cmd_set_status: (skip):
 **/
void
fu_struct_lxs_touch_flash_iap_cmd_set_status(FuStructLxsTouchFlashIapCmd *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[6] = value;
}
/**
 * fu_struct_lxs_touch_flash_iap_cmd_set_cmd: (skip):
 **/
void
fu_struct_lxs_touch_flash_iap_cmd_set_cmd(FuStructLxsTouchFlashIapCmd *st, FuLxsTouchCmd value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[7] = value;
}
/**
 * fu_struct_lxs_touch_flash_iap_cmd_new: (skip):
 **/
FuStructLxsTouchFlashIapCmd *
fu_struct_lxs_touch_flash_iap_cmd_new(void)
{
    FuStructLxsTouchFlashIapCmd *st = fu_struct_lxs_touch_flash_iap_cmd_new_internal();
    st->buf = g_byte_array_sized_new(8);
    fu_byte_array_set_size(st->buf, 8, 0x0);
    return st;
}
/**
 * fu_struct_lxs_touch_flash_iap_cmd_to_string: (skip):
 **/
static gchar *
fu_struct_lxs_touch_flash_iap_cmd_to_string(const FuStructLxsTouchFlashIapCmd *st)
{
    g_autoptr(GString) str = g_string_new("FuStructLxsTouchFlashIapCmd:\n");
    g_return_val_if_fail(st != NULL, NULL);
    g_string_append_printf(str, "  addr: 0x%x\n",
                           (guint) fu_struct_lxs_touch_flash_iap_cmd_get_addr(st));
    g_string_append_printf(str, "  size: 0x%x\n",
                           (guint) fu_struct_lxs_touch_flash_iap_cmd_get_size(st));
    g_string_append_printf(str, "  status: 0x%x\n",
                           (guint) fu_struct_lxs_touch_flash_iap_cmd_get_status(st));
    {
        const gchar *tmp = fu_lxs_touch_cmd_to_string(fu_struct_lxs_touch_flash_iap_cmd_get_cmd(st));
        if (tmp != NULL) {
            g_string_append_printf(str, "  cmd: 0x%x [%s]\n", (guint) fu_struct_lxs_touch_flash_iap_cmd_get_cmd(st), tmp);
        } else {
            g_string_append_printf(str, "  cmd: 0x%x\n", (guint) fu_struct_lxs_touch_flash_iap_cmd_get_cmd(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_lxs_touch_flash_iap_cmd_validate_internal(FuStructLxsTouchFlashIapCmd *st, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    return TRUE;
}
static gboolean
fu_struct_lxs_touch_flash_iap_cmd_parse_internal(FuStructLxsTouchFlashIapCmd *st, GError **error)
{
    if (g_log_get_debug_enabled()) {
        g_autofree gchar *str = fu_struct_lxs_touch_flash_iap_cmd_to_string(st);
        g_debug("%s", str);
    }
    if (!fu_struct_lxs_touch_flash_iap_cmd_validate_internal(st, error))
        return FALSE;
    return TRUE;
}

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