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

#include "config.h"

#include <glib.h>

#include "fu-elantp-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_etp_rptid_to_string:
 * @val: value, e.g. %FU_ETP_RPTID_TP_IAP
 *
 * Converts an enumerated value to a string.
 *
 * Returns: identifier string
 **/
static const gchar *
fu_etp_rptid_to_string(FuEtpRptid val)
{
    if (val == FU_ETP_RPTID_TP_FEATURE)
        return "tp-feature";
    if (val == FU_ETP_RPTID_TP_IAP)
        return "tp-iap";
    if (val == FU_ETP_RPTID_MCU_FEATURE)
        return "mcu-feature";
    if (val == FU_ETP_RPTID_MCU_IAP)
        return "mcu-iap";
    return NULL;
}


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

/* getters */

/* setters */
/**
 * fu_struct_elantp_firmware_ftr_new: (skip):
 **/
FuStructElantpFirmwareFtr *
fu_struct_elantp_firmware_ftr_new(void)
{
    FuStructElantpFirmwareFtr *st = fu_struct_elantp_firmware_ftr_new_internal();
    st->buf = g_byte_array_sized_new(6);
    fu_byte_array_set_size(st->buf, 6, 0x0);
    memcpy(st->buf->data + 0x0, "\xAA\x55\xCC\x33\xFF\xFF", 6); /* nocheck:blocked */
    return st;
}
static gboolean
fu_struct_elantp_firmware_ftr_validate_internal(FuStructElantpFirmwareFtr *st, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    if (memcmp(st->buf->data + 0, "\xAA\x55\xCC\x33\xFF\xFF", 6) != 0) {
        g_set_error_literal(error,
                            FWUPD_ERROR,
                            FWUPD_ERROR_INVALID_DATA,
                            "constant FuStructElantpFirmwareFtr.magic was not valid");
        return FALSE;
    }
    return TRUE;
}
/**
 * fu_struct_elantp_firmware_ftr_validate_stream: (skip):
 **/
gboolean
fu_struct_elantp_firmware_ftr_validate_stream(GInputStream *stream, gsize offset, GError **error)
{
    g_autoptr(FuStructElantpFirmwareFtr) st = fu_struct_elantp_firmware_ftr_new_internal();
    g_return_val_if_fail(G_IS_INPUT_STREAM(stream), FALSE);
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
    st->buf = fu_input_stream_read_byte_array(stream, offset, 6, NULL, error);
    if (st->buf == NULL) {
        g_prefix_error(error, "FuStructElantpFirmwareFtr failed read of 0x%x: ", (guint) 6);
        return FALSE;
    }
    if (st->buf->len != 6) {
        g_set_error(error,
                    FWUPD_ERROR,
                    FWUPD_ERROR_INVALID_DATA,
                    "FuStructElantpFirmwareFtr requested 0x%x and got 0x%x",
                    (guint) 6,
                    (guint) st->buf->len);
        return FALSE;
    }
    return fu_struct_elantp_firmware_ftr_validate_internal(st, error);
}
/**
 * fu_struct_elantp_firmware_hdr_ref: (skip):
 **/
FuStructElantpFirmwareHdr *
fu_struct_elantp_firmware_hdr_ref(FuStructElantpFirmwareHdr *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_elantp_firmware_hdr_unref: (skip):
 **/
void
fu_struct_elantp_firmware_hdr_unref(FuStructElantpFirmwareHdr *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructElantpFirmwareHdr refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_elantp_firmware_hdr_new_internal: (skip):
 **/
static FuStructElantpFirmwareHdr *
fu_struct_elantp_firmware_hdr_new_internal(void)
{
    FuStructElantpFirmwareHdr *st = g_new0(FuStructElantpFirmwareHdr, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_elantp_firmware_hdr_get_ic_type: (skip):
 **/
guint16
fu_struct_elantp_firmware_hdr_get_ic_type(const FuStructElantpFirmwareHdr *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 0, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_elantp_firmware_hdr_get_iap_ver: (skip):
 **/
guint16
fu_struct_elantp_firmware_hdr_get_iap_ver(const FuStructElantpFirmwareHdr *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 4, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_elantp_firmware_hdr_get_iap_start: (skip):
 **/
guint16
fu_struct_elantp_firmware_hdr_get_iap_start(const FuStructElantpFirmwareHdr *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 6, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_elantp_firmware_hdr_get_iap_forcetable: (skip):
 **/
guint16
fu_struct_elantp_firmware_hdr_get_iap_forcetable(const FuStructElantpFirmwareHdr *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 10, G_LITTLE_ENDIAN);
}

/* setters */
/**
 * fu_struct_elantp_firmware_hdr_set_ic_type: (skip):
 **/
void
fu_struct_elantp_firmware_hdr_set_ic_type(FuStructElantpFirmwareHdr *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 0, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_elantp_firmware_hdr_set_iap_ver: (skip):
 **/
void
fu_struct_elantp_firmware_hdr_set_iap_ver(FuStructElantpFirmwareHdr *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 4, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_elantp_firmware_hdr_set_iap_start: (skip):
 **/
void
fu_struct_elantp_firmware_hdr_set_iap_start(FuStructElantpFirmwareHdr *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 6, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_elantp_firmware_hdr_set_iap_forcetable: (skip):
 **/
void
fu_struct_elantp_firmware_hdr_set_iap_forcetable(FuStructElantpFirmwareHdr *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 10, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_elantp_firmware_hdr_new: (skip):
 **/
FuStructElantpFirmwareHdr *
fu_struct_elantp_firmware_hdr_new(void)
{
    FuStructElantpFirmwareHdr *st = fu_struct_elantp_firmware_hdr_new_internal();
    st->buf = g_byte_array_sized_new(12);
    fu_byte_array_set_size(st->buf, 12, 0x0);
    return st;
}
/**
 * fu_struct_elantp_firmware_hdr_to_string: (skip):
 **/
static gchar *
fu_struct_elantp_firmware_hdr_to_string(const FuStructElantpFirmwareHdr *st)
{
    g_autoptr(GString) str = g_string_new("FuStructElantpFirmwareHdr:\n");
    g_return_val_if_fail(st != NULL, NULL);
    g_string_append_printf(str, "  ic_type: 0x%x\n",
                           (guint) fu_struct_elantp_firmware_hdr_get_ic_type(st));
    g_string_append_printf(str, "  iap_ver: 0x%x\n",
                           (guint) fu_struct_elantp_firmware_hdr_get_iap_ver(st));
    g_string_append_printf(str, "  iap_start: 0x%x\n",
                           (guint) fu_struct_elantp_firmware_hdr_get_iap_start(st));
    g_string_append_printf(str, "  iap_forcetable: 0x%x\n",
                           (guint) fu_struct_elantp_firmware_hdr_get_iap_forcetable(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_elantp_firmware_hdr_validate_internal(FuStructElantpFirmwareHdr *st, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    return TRUE;
}
static gboolean
fu_struct_elantp_firmware_hdr_parse_internal(FuStructElantpFirmwareHdr *st, GError **error)
{
    if (g_log_get_debug_enabled()) {
        g_autofree gchar *str = fu_struct_elantp_firmware_hdr_to_string(st);
        g_debug("%s", str);
    }
    if (!fu_struct_elantp_firmware_hdr_validate_internal(st, error))
        return FALSE;
    return TRUE;
}
/**
 * fu_struct_elantp_firmware_hdr_parse_stream: (skip):
 **/
FuStructElantpFirmwareHdr *
fu_struct_elantp_firmware_hdr_parse_stream(GInputStream *stream, gsize offset, GError **error)
{
    g_autoptr(FuStructElantpFirmwareHdr) st = fu_struct_elantp_firmware_hdr_new_internal();
    st->buf = fu_input_stream_read_byte_array(stream, offset, 12, NULL, error);
    if (st->buf == NULL) {
        g_prefix_error(error, "FuStructElantpFirmwareHdr failed read of 0x%x: ", (guint) 12);
        return NULL;
    }
    if (st->buf->len != 12) {
        g_set_error(error,
                    FWUPD_ERROR,
                    FWUPD_ERROR_INVALID_DATA,
                    "FuStructElantpFirmwareHdr requested 0x%x and got 0x%x",
                    (guint) 12,
                    (guint) st->buf->len);
        return NULL;
    }
    if (!fu_struct_elantp_firmware_hdr_parse_internal(st, error))
        return NULL;
    return g_steal_pointer(&st);
}
/**
 * fu_struct_elantp_haptic_firmware_hdr_ref: (skip):
 **/
FuStructElantpHapticFirmwareHdr *
fu_struct_elantp_haptic_firmware_hdr_ref(FuStructElantpHapticFirmwareHdr *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_elantp_haptic_firmware_hdr_unref: (skip):
 **/
void
fu_struct_elantp_haptic_firmware_hdr_unref(FuStructElantpHapticFirmwareHdr *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructElantpHapticFirmwareHdr refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_elantp_haptic_firmware_hdr_new_internal: (skip):
 **/
static FuStructElantpHapticFirmwareHdr *
fu_struct_elantp_haptic_firmware_hdr_new_internal(void)
{
    FuStructElantpHapticFirmwareHdr *st = g_new0(FuStructElantpHapticFirmwareHdr, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_elantp_haptic_firmware_hdr_get_magic: (skip):
 **/
static const guint8 *
fu_struct_elantp_haptic_firmware_hdr_get_magic(const FuStructElantpHapticFirmwareHdr *st, gsize *bufsz)
{
    g_return_val_if_fail(st != NULL, NULL);
    if (bufsz != NULL)
        *bufsz = 4;
    return st->buf->data + 0;
}
/**
 * fu_struct_elantp_haptic_firmware_hdr_get_ver_sm: (skip):
 **/
guint8
fu_struct_elantp_haptic_firmware_hdr_get_ver_sm(const FuStructElantpHapticFirmwareHdr *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[4];
}
/**
 * fu_struct_elantp_haptic_firmware_hdr_get_ver_d: (skip):
 **/
guint8
fu_struct_elantp_haptic_firmware_hdr_get_ver_d(const FuStructElantpHapticFirmwareHdr *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[5];
}
/**
 * fu_struct_elantp_haptic_firmware_hdr_get_ver_y: (skip):
 **/
guint8
fu_struct_elantp_haptic_firmware_hdr_get_ver_y(const FuStructElantpHapticFirmwareHdr *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[6];
}

/* setters */
/**
 * fu_struct_elantp_haptic_firmware_hdr_to_string: (skip):
 **/
static gchar *
fu_struct_elantp_haptic_firmware_hdr_to_string(const FuStructElantpHapticFirmwareHdr *st)
{
    g_autoptr(GString) str = g_string_new("FuStructElantpHapticFirmwareHdr:\n");
    g_return_val_if_fail(st != NULL, NULL);
    {
        gsize bufsz = 0;
        const guint8 *buf = fu_struct_elantp_haptic_firmware_hdr_get_magic(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, "  magic: 0x%s\n", tmp->str);
    }
    g_string_append_printf(str, "  ver_sm: 0x%x\n",
                           (guint) fu_struct_elantp_haptic_firmware_hdr_get_ver_sm(st));
    g_string_append_printf(str, "  ver_d: 0x%x\n",
                           (guint) fu_struct_elantp_haptic_firmware_hdr_get_ver_d(st));
    g_string_append_printf(str, "  ver_y: 0x%x\n",
                           (guint) fu_struct_elantp_haptic_firmware_hdr_get_ver_y(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_elantp_haptic_firmware_hdr_validate_internal(FuStructElantpHapticFirmwareHdr *st, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    if (memcmp(st->buf->data + 0, "\xFF\x40\xA2\x5B", 4) != 0) {
        g_set_error_literal(error,
                            FWUPD_ERROR,
                            FWUPD_ERROR_INVALID_DATA,
                            "constant FuStructElantpHapticFirmwareHdr.magic was not valid");
        return FALSE;
    }
    return TRUE;
}
/**
 * fu_struct_elantp_haptic_firmware_hdr_validate_stream: (skip):
 **/
gboolean
fu_struct_elantp_haptic_firmware_hdr_validate_stream(GInputStream *stream, gsize offset, GError **error)
{
    g_autoptr(FuStructElantpHapticFirmwareHdr) st = fu_struct_elantp_haptic_firmware_hdr_new_internal();
    g_return_val_if_fail(G_IS_INPUT_STREAM(stream), FALSE);
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
    st->buf = fu_input_stream_read_byte_array(stream, offset, 7, NULL, error);
    if (st->buf == NULL) {
        g_prefix_error(error, "FuStructElantpHapticFirmwareHdr failed read of 0x%x: ", (guint) 7);
        return FALSE;
    }
    if (st->buf->len != 7) {
        g_set_error(error,
                    FWUPD_ERROR,
                    FWUPD_ERROR_INVALID_DATA,
                    "FuStructElantpHapticFirmwareHdr requested 0x%x and got 0x%x",
                    (guint) 7,
                    (guint) st->buf->len);
        return FALSE;
    }
    return fu_struct_elantp_haptic_firmware_hdr_validate_internal(st, error);
}
static gboolean
fu_struct_elantp_haptic_firmware_hdr_parse_internal(FuStructElantpHapticFirmwareHdr *st, GError **error)
{
    if (g_log_get_debug_enabled()) {
        g_autofree gchar *str = fu_struct_elantp_haptic_firmware_hdr_to_string(st);
        g_debug("%s", str);
    }
    if (!fu_struct_elantp_haptic_firmware_hdr_validate_internal(st, error))
        return FALSE;
    return TRUE;
}
/**
 * fu_struct_elantp_haptic_firmware_hdr_parse_stream: (skip):
 **/
FuStructElantpHapticFirmwareHdr *
fu_struct_elantp_haptic_firmware_hdr_parse_stream(GInputStream *stream, gsize offset, GError **error)
{
    g_autoptr(FuStructElantpHapticFirmwareHdr) st = fu_struct_elantp_haptic_firmware_hdr_new_internal();
    st->buf = fu_input_stream_read_byte_array(stream, offset, 7, NULL, error);
    if (st->buf == NULL) {
        g_prefix_error(error, "FuStructElantpHapticFirmwareHdr failed read of 0x%x: ", (guint) 7);
        return NULL;
    }
    if (st->buf->len != 7) {
        g_set_error(error,
                    FWUPD_ERROR,
                    FWUPD_ERROR_INVALID_DATA,
                    "FuStructElantpHapticFirmwareHdr requested 0x%x and got 0x%x",
                    (guint) 7,
                    (guint) st->buf->len);
        return NULL;
    }
    if (!fu_struct_elantp_haptic_firmware_hdr_parse_internal(st, error))
        return NULL;
    return g_steal_pointer(&st);
}
/**
 * fu_struct_elantp_read_cmd_req_ref: (skip):
 **/
FuStructElantpReadCmdReq *
fu_struct_elantp_read_cmd_req_ref(FuStructElantpReadCmdReq *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_elantp_read_cmd_req_unref: (skip):
 **/
void
fu_struct_elantp_read_cmd_req_unref(FuStructElantpReadCmdReq *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructElantpReadCmdReq refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_elantp_read_cmd_req_new_internal: (skip):
 **/
static FuStructElantpReadCmdReq *
fu_struct_elantp_read_cmd_req_new_internal(void)
{
    FuStructElantpReadCmdReq *st = g_new0(FuStructElantpReadCmdReq, 1);
    st->refcount = 1;
    return st;
}

/* getters */

/* setters */
/**
 * fu_struct_elantp_read_cmd_req_set_report_id: (skip):
 **/
void
fu_struct_elantp_read_cmd_req_set_report_id(FuStructElantpReadCmdReq *st, FuEtpRptid value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[0] = value;
}
/**
 * fu_struct_elantp_read_cmd_req_set_cmd: (skip):
 **/
void
fu_struct_elantp_read_cmd_req_set_cmd(FuStructElantpReadCmdReq *st, FuEtpCmd value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 1, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_elantp_read_cmd_req_set_reg: (skip):
 **/
void
fu_struct_elantp_read_cmd_req_set_reg(FuStructElantpReadCmdReq *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 3, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_elantp_read_cmd_req_new: (skip):
 **/
FuStructElantpReadCmdReq *
fu_struct_elantp_read_cmd_req_new(void)
{
    FuStructElantpReadCmdReq *st = fu_struct_elantp_read_cmd_req_new_internal();
    st->buf = g_byte_array_sized_new(5);
    fu_byte_array_set_size(st->buf, 5, 0x0);
    return st;
}
/**
 * fu_struct_elantp_read_cmd_res_ref: (skip):
 **/
FuStructElantpReadCmdRes *
fu_struct_elantp_read_cmd_res_ref(FuStructElantpReadCmdRes *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_elantp_read_cmd_res_unref: (skip):
 **/
void
fu_struct_elantp_read_cmd_res_unref(FuStructElantpReadCmdRes *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructElantpReadCmdRes refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_elantp_read_cmd_res_new_internal: (skip):
 **/
static FuStructElantpReadCmdRes *
fu_struct_elantp_read_cmd_res_new_internal(void)
{
    FuStructElantpReadCmdRes *st = g_new0(FuStructElantpReadCmdRes, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_elantp_read_cmd_res_get_report_id: (skip):
 **/
FuEtpRptid
fu_struct_elantp_read_cmd_res_get_report_id(const FuStructElantpReadCmdRes *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[0];
}
/**
 * fu_struct_elantp_read_cmd_res_get_value: (skip):
 **/
guint16
fu_struct_elantp_read_cmd_res_get_value(const FuStructElantpReadCmdRes *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 3, G_LITTLE_ENDIAN);
}

/* setters */
/**
 * fu_struct_elantp_read_cmd_res_to_string: (skip):
 **/
static gchar *
fu_struct_elantp_read_cmd_res_to_string(const FuStructElantpReadCmdRes *st)
{
    g_autoptr(GString) str = g_string_new("FuStructElantpReadCmdRes:\n");
    g_return_val_if_fail(st != NULL, NULL);
    {
        const gchar *tmp = fu_etp_rptid_to_string(fu_struct_elantp_read_cmd_res_get_report_id(st));
        if (tmp != NULL) {
            g_string_append_printf(str, "  report_id: 0x%x [%s]\n", (guint) fu_struct_elantp_read_cmd_res_get_report_id(st), tmp);
        } else {
            g_string_append_printf(str, "  report_id: 0x%x\n", (guint) fu_struct_elantp_read_cmd_res_get_report_id(st));
        }
    }
    g_string_append_printf(str, "  value: 0x%x\n",
                           (guint) fu_struct_elantp_read_cmd_res_get_value(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_elantp_read_cmd_res_validate_internal(FuStructElantpReadCmdRes *st, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    return TRUE;
}
static gboolean
fu_struct_elantp_read_cmd_res_parse_internal(FuStructElantpReadCmdRes *st, GError **error)
{
    if (g_log_get_debug_enabled()) {
        g_autofree gchar *str = fu_struct_elantp_read_cmd_res_to_string(st);
        g_debug("%s", str);
    }
    if (!fu_struct_elantp_read_cmd_res_validate_internal(st, error))
        return FALSE;
    return TRUE;
}

/**
 * fu_struct_elantp_read_cmd_res_parse: (skip):
 **/
FuStructElantpReadCmdRes *
fu_struct_elantp_read_cmd_res_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error)
{
    g_autoptr(FuStructElantpReadCmdRes) st = fu_struct_elantp_read_cmd_res_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 FuStructElantpReadCmdRes: ");
        return NULL;
    }
    st->buf = g_byte_array_new();
    g_byte_array_append(st->buf, buf + offset, 5);
    if (!fu_struct_elantp_read_cmd_res_parse_internal(st, error))
        return NULL;
    return g_steal_pointer(&st);
}
/**
 * fu_struct_elantp_write_cmd_req_ref: (skip):
 **/
FuStructElantpWriteCmdReq *
fu_struct_elantp_write_cmd_req_ref(FuStructElantpWriteCmdReq *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_elantp_write_cmd_req_unref: (skip):
 **/
void
fu_struct_elantp_write_cmd_req_unref(FuStructElantpWriteCmdReq *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructElantpWriteCmdReq refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_elantp_write_cmd_req_new_internal: (skip):
 **/
static FuStructElantpWriteCmdReq *
fu_struct_elantp_write_cmd_req_new_internal(void)
{
    FuStructElantpWriteCmdReq *st = g_new0(FuStructElantpWriteCmdReq, 1);
    st->refcount = 1;
    return st;
}

/* getters */

/* setters */
/**
 * fu_struct_elantp_write_cmd_req_set_report_id: (skip):
 **/
void
fu_struct_elantp_write_cmd_req_set_report_id(FuStructElantpWriteCmdReq *st, FuEtpRptid value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[0] = value;
}
/**
 * fu_struct_elantp_write_cmd_req_set_reg: (skip):
 **/
void
fu_struct_elantp_write_cmd_req_set_reg(FuStructElantpWriteCmdReq *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 1, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_elantp_write_cmd_req_set_cmd: (skip):
 **/
void
fu_struct_elantp_write_cmd_req_set_cmd(FuStructElantpWriteCmdReq *st, FuEtpCmd value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 3, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_elantp_write_cmd_req_new: (skip):
 **/
FuStructElantpWriteCmdReq *
fu_struct_elantp_write_cmd_req_new(void)
{
    FuStructElantpWriteCmdReq *st = fu_struct_elantp_write_cmd_req_new_internal();
    st->buf = g_byte_array_sized_new(5);
    fu_byte_array_set_size(st->buf, 5, 0x0);
    return st;
}
