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

#include "config.h"

#include <glib.h>

#include "fu-goodix-moc-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_goodix_moc_cmd_to_string:
 * @val: value, e.g. %FU_GOODIX_MOC_CMD_UPGRADE_DATA
 *
 * Converts an enumerated value to a string.
 *
 * Returns: identifier string
 **/
static const gchar *
fu_goodix_moc_cmd_to_string(FuGoodixMocCmd val)
{
    if (val == FU_GOODIX_MOC_CMD_UPGRADE_INIT)
        return "upgrade-init";
    if (val == FU_GOODIX_MOC_CMD_UPGRADE_DATA)
        return "upgrade-data";
    if (val == FU_GOODIX_MOC_CMD_UPGRADE)
        return "upgrade";
    if (val == FU_GOODIX_MOC_CMD_ACK)
        return "ack";
    if (val == FU_GOODIX_MOC_CMD_RESET)
        return "reset";
    if (val == FU_GOODIX_MOC_CMD_VERSION)
        return "version";
    return NULL;
}

/**
 * fu_goodix_moc_result_to_string:
 * @val: value
 *
 * Converts an enumerated value to a string.
 *
 * Returns: identifier string
 **/
static const gchar *
fu_goodix_moc_result_to_string(FuGoodixMocResult val)
{
    if (val == FU_GOODIX_MOC_RESULT_SUCCESS)
        return "success";
    return NULL;
}

/**
 * fu_goodix_moc_pkg_type_to_string:
 * @val: value, e.g. %FU_GOODIX_MOC_PKG_TYPE_EOP
 *
 * Converts an enumerated value to a string.
 *
 * Returns: identifier string
 **/
static const gchar *
fu_goodix_moc_pkg_type_to_string(FuGoodixMocPkgType val)
{
    if (val == FU_GOODIX_MOC_PKG_TYPE_NORMAL)
        return "normal";
    if (val == FU_GOODIX_MOC_PKG_TYPE_EOP)
        return "eop";
    return NULL;
}
/**
 * fu_struct_goodix_moc_pkg_header_ref: (skip):
 **/
FuStructGoodixMocPkgHeader *
fu_struct_goodix_moc_pkg_header_ref(FuStructGoodixMocPkgHeader *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_goodix_moc_pkg_header_unref: (skip):
 **/
void
fu_struct_goodix_moc_pkg_header_unref(FuStructGoodixMocPkgHeader *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructGoodixMocPkgHeader refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_goodix_moc_pkg_header_new_internal: (skip):
 **/
static FuStructGoodixMocPkgHeader *
fu_struct_goodix_moc_pkg_header_new_internal(void)
{
    FuStructGoodixMocPkgHeader *st = g_new0(FuStructGoodixMocPkgHeader, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_goodix_moc_pkg_header_get_cmd0: (skip):
 **/
FuGoodixMocCmd
fu_struct_goodix_moc_pkg_header_get_cmd0(const FuStructGoodixMocPkgHeader *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[0];
}
/**
 * fu_struct_goodix_moc_pkg_header_get_cmd1: (skip):
 **/
guint8
fu_struct_goodix_moc_pkg_header_get_cmd1(const FuStructGoodixMocPkgHeader *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[1];
}
/**
 * fu_struct_goodix_moc_pkg_header_get_pkg_flag: (skip):
 **/
FuGoodixMocPkgType
fu_struct_goodix_moc_pkg_header_get_pkg_flag(const FuStructGoodixMocPkgHeader *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[2];
}
/**
 * fu_struct_goodix_moc_pkg_header_get_seq: (skip):
 **/
guint8
fu_struct_goodix_moc_pkg_header_get_seq(const FuStructGoodixMocPkgHeader *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[3];
}
/**
 * fu_struct_goodix_moc_pkg_header_get_len: (skip):
 **/
guint16
fu_struct_goodix_moc_pkg_header_get_len(const FuStructGoodixMocPkgHeader *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 4, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_goodix_moc_pkg_header_get_crc8: (skip):
 **/
guint8
fu_struct_goodix_moc_pkg_header_get_crc8(const FuStructGoodixMocPkgHeader *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[6];
}
/**
 * fu_struct_goodix_moc_pkg_header_get_rev_crc8: (skip):
 **/
guint8
fu_struct_goodix_moc_pkg_header_get_rev_crc8(const FuStructGoodixMocPkgHeader *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[7];
}

/* setters */
/**
 * fu_struct_goodix_moc_pkg_header_set_cmd0: (skip):
 **/
void
fu_struct_goodix_moc_pkg_header_set_cmd0(FuStructGoodixMocPkgHeader *st, FuGoodixMocCmd value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[0] = value;
}
/**
 * fu_struct_goodix_moc_pkg_header_set_cmd1: (skip):
 **/
void
fu_struct_goodix_moc_pkg_header_set_cmd1(FuStructGoodixMocPkgHeader *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[1] = value;
}
/**
 * fu_struct_goodix_moc_pkg_header_set_pkg_flag: (skip):
 **/
void
fu_struct_goodix_moc_pkg_header_set_pkg_flag(FuStructGoodixMocPkgHeader *st, FuGoodixMocPkgType value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[2] = value;
}
/**
 * fu_struct_goodix_moc_pkg_header_set_seq: (skip):
 **/
void
fu_struct_goodix_moc_pkg_header_set_seq(FuStructGoodixMocPkgHeader *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[3] = value;
}
/**
 * fu_struct_goodix_moc_pkg_header_set_len: (skip):
 **/
void
fu_struct_goodix_moc_pkg_header_set_len(FuStructGoodixMocPkgHeader *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 4, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_goodix_moc_pkg_header_set_crc8: (skip):
 **/
void
fu_struct_goodix_moc_pkg_header_set_crc8(FuStructGoodixMocPkgHeader *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[6] = value;
}
/**
 * fu_struct_goodix_moc_pkg_header_set_rev_crc8: (skip):
 **/
void
fu_struct_goodix_moc_pkg_header_set_rev_crc8(FuStructGoodixMocPkgHeader *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[7] = value;
}
/**
 * fu_struct_goodix_moc_pkg_header_new: (skip):
 **/
FuStructGoodixMocPkgHeader *
fu_struct_goodix_moc_pkg_header_new(void)
{
    FuStructGoodixMocPkgHeader *st = fu_struct_goodix_moc_pkg_header_new_internal();
    st->buf = g_byte_array_sized_new(8);
    fu_byte_array_set_size(st->buf, 8, 0x0);
    return st;
}
/**
 * fu_struct_goodix_moc_pkg_header_to_string: (skip):
 **/
static gchar *
fu_struct_goodix_moc_pkg_header_to_string(const FuStructGoodixMocPkgHeader *st)
{
    g_autoptr(GString) str = g_string_new("FuStructGoodixMocPkgHeader:\n");
    g_return_val_if_fail(st != NULL, NULL);
    {
        const gchar *tmp = fu_goodix_moc_cmd_to_string(fu_struct_goodix_moc_pkg_header_get_cmd0(st));
        if (tmp != NULL) {
            g_string_append_printf(str, "  cmd0: 0x%x [%s]\n", (guint) fu_struct_goodix_moc_pkg_header_get_cmd0(st), tmp);
        } else {
            g_string_append_printf(str, "  cmd0: 0x%x\n", (guint) fu_struct_goodix_moc_pkg_header_get_cmd0(st));
        }
    }
    g_string_append_printf(str, "  cmd1: 0x%x\n",
                           (guint) fu_struct_goodix_moc_pkg_header_get_cmd1(st));
    {
        const gchar *tmp = fu_goodix_moc_pkg_type_to_string(fu_struct_goodix_moc_pkg_header_get_pkg_flag(st));
        if (tmp != NULL) {
            g_string_append_printf(str, "  pkg_flag: 0x%x [%s]\n", (guint) fu_struct_goodix_moc_pkg_header_get_pkg_flag(st), tmp);
        } else {
            g_string_append_printf(str, "  pkg_flag: 0x%x\n", (guint) fu_struct_goodix_moc_pkg_header_get_pkg_flag(st));
        }
    }
    g_string_append_printf(str, "  seq: 0x%x\n",
                           (guint) fu_struct_goodix_moc_pkg_header_get_seq(st));
    g_string_append_printf(str, "  len: 0x%x\n",
                           (guint) fu_struct_goodix_moc_pkg_header_get_len(st));
    g_string_append_printf(str, "  crc8: 0x%x\n",
                           (guint) fu_struct_goodix_moc_pkg_header_get_crc8(st));
    g_string_append_printf(str, "  rev_crc8: 0x%x\n",
                           (guint) fu_struct_goodix_moc_pkg_header_get_rev_crc8(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_goodix_moc_pkg_header_validate_internal(FuStructGoodixMocPkgHeader *st, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    return TRUE;
}
static gboolean
fu_struct_goodix_moc_pkg_header_parse_internal(FuStructGoodixMocPkgHeader *st, GError **error)
{
    if (g_log_get_debug_enabled()) {
        g_autofree gchar *str = fu_struct_goodix_moc_pkg_header_to_string(st);
        g_debug("%s", str);
    }
    if (!fu_struct_goodix_moc_pkg_header_validate_internal(st, error))
        return FALSE;
    return TRUE;
}

/**
 * fu_struct_goodix_moc_pkg_header_parse: (skip):
 **/
FuStructGoodixMocPkgHeader *
fu_struct_goodix_moc_pkg_header_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error)
{
    g_autoptr(FuStructGoodixMocPkgHeader) st = fu_struct_goodix_moc_pkg_header_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 FuStructGoodixMocPkgHeader: ");
        return NULL;
    }
    st->buf = g_byte_array_new();
    g_byte_array_append(st->buf, buf + offset, 8);
    if (!fu_struct_goodix_moc_pkg_header_parse_internal(st, error))
        return NULL;
    return g_steal_pointer(&st);
}
/**
 * fu_struct_goodix_moc_pkg_rsp_ref: (skip):
 **/
FuStructGoodixMocPkgRsp *
fu_struct_goodix_moc_pkg_rsp_ref(FuStructGoodixMocPkgRsp *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_goodix_moc_pkg_rsp_unref: (skip):
 **/
void
fu_struct_goodix_moc_pkg_rsp_unref(FuStructGoodixMocPkgRsp *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructGoodixMocPkgRsp refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_goodix_moc_pkg_rsp_new_internal: (skip):
 **/
static FuStructGoodixMocPkgRsp *
fu_struct_goodix_moc_pkg_rsp_new_internal(void)
{
    FuStructGoodixMocPkgRsp *st = g_new0(FuStructGoodixMocPkgRsp, 1);
    st->refcount = 1;
    return st;
}

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

/* setters */
/**
 * fu_struct_goodix_moc_pkg_rsp_to_string: (skip):
 **/
static gchar *
fu_struct_goodix_moc_pkg_rsp_to_string(const FuStructGoodixMocPkgRsp *st)
{
    g_autoptr(GString) str = g_string_new("FuStructGoodixMocPkgRsp:\n");
    g_return_val_if_fail(st != NULL, NULL);
    {
        const gchar *tmp = fu_goodix_moc_result_to_string(fu_struct_goodix_moc_pkg_rsp_get_result(st));
        if (tmp != NULL) {
            g_string_append_printf(str, "  result: 0x%x [%s]\n", (guint) fu_struct_goodix_moc_pkg_rsp_get_result(st), tmp);
        } else {
            g_string_append_printf(str, "  result: 0x%x\n", (guint) fu_struct_goodix_moc_pkg_rsp_get_result(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_goodix_moc_pkg_rsp_validate_internal(FuStructGoodixMocPkgRsp *st, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    return TRUE;
}
static gboolean
fu_struct_goodix_moc_pkg_rsp_parse_internal(FuStructGoodixMocPkgRsp *st, GError **error)
{
    if (g_log_get_debug_enabled()) {
        g_autofree gchar *str = fu_struct_goodix_moc_pkg_rsp_to_string(st);
        g_debug("%s", str);
    }
    if (!fu_struct_goodix_moc_pkg_rsp_validate_internal(st, error))
        return FALSE;
    return TRUE;
}

/**
 * fu_struct_goodix_moc_pkg_rsp_parse: (skip):
 **/
FuStructGoodixMocPkgRsp *
fu_struct_goodix_moc_pkg_rsp_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error)
{
    g_autoptr(FuStructGoodixMocPkgRsp) st = fu_struct_goodix_moc_pkg_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 FuStructGoodixMocPkgRsp: ");
        return NULL;
    }
    st->buf = g_byte_array_new();
    g_byte_array_append(st->buf, buf + offset, 1);
    if (!fu_struct_goodix_moc_pkg_rsp_parse_internal(st, error))
        return NULL;
    return g_steal_pointer(&st);
}
/**
 * fu_struct_goodix_moc_pkg_ack_rsp_ref: (skip):
 **/
FuStructGoodixMocPkgAckRsp *
fu_struct_goodix_moc_pkg_ack_rsp_ref(FuStructGoodixMocPkgAckRsp *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_goodix_moc_pkg_ack_rsp_unref: (skip):
 **/
void
fu_struct_goodix_moc_pkg_ack_rsp_unref(FuStructGoodixMocPkgAckRsp *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructGoodixMocPkgAckRsp 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_goodix_moc_pkg_version_rsp_ref: (skip):
 **/
FuStructGoodixMocPkgVersionRsp *
fu_struct_goodix_moc_pkg_version_rsp_ref(FuStructGoodixMocPkgVersionRsp *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_goodix_moc_pkg_version_rsp_unref: (skip):
 **/
void
fu_struct_goodix_moc_pkg_version_rsp_unref(FuStructGoodixMocPkgVersionRsp *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructGoodixMocPkgVersionRsp refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_goodix_moc_pkg_version_rsp_new_internal: (skip):
 **/
static FuStructGoodixMocPkgVersionRsp *
fu_struct_goodix_moc_pkg_version_rsp_new_internal(void)
{
    FuStructGoodixMocPkgVersionRsp *st = g_new0(FuStructGoodixMocPkgVersionRsp, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_goodix_moc_pkg_version_rsp_get_result: (skip):
 **/
FuGoodixMocResult
fu_struct_goodix_moc_pkg_version_rsp_get_result(const FuStructGoodixMocPkgVersionRsp *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[0];
}
/**
 * fu_struct_goodix_moc_pkg_version_rsp_get_format: (skip):
 **/
const guint8 *
fu_struct_goodix_moc_pkg_version_rsp_get_format(const FuStructGoodixMocPkgVersionRsp *st, gsize *bufsz)
{
    g_return_val_if_fail(st != NULL, NULL);
    if (bufsz != NULL)
        *bufsz = 2;
    return st->buf->data + 1;
}
/**
 * fu_struct_goodix_moc_pkg_version_rsp_get_fwtype: (skip):
 **/
const guint8 *
fu_struct_goodix_moc_pkg_version_rsp_get_fwtype(const FuStructGoodixMocPkgVersionRsp *st, gsize *bufsz)
{
    g_return_val_if_fail(st != NULL, NULL);
    if (bufsz != NULL)
        *bufsz = 8;
    return st->buf->data + 3;
}
/**
 * fu_struct_goodix_moc_pkg_version_rsp_get_fwversion: (skip):
 **/
gchar *
fu_struct_goodix_moc_pkg_version_rsp_get_fwversion(const FuStructGoodixMocPkgVersionRsp *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    return fu_memstrsafe(st->buf->data, st->buf->len, 11, 8, NULL);
}
/**
 * fu_struct_goodix_moc_pkg_version_rsp_get_customer: (skip):
 **/
const guint8 *
fu_struct_goodix_moc_pkg_version_rsp_get_customer(const FuStructGoodixMocPkgVersionRsp *st, gsize *bufsz)
{
    g_return_val_if_fail(st != NULL, NULL);
    if (bufsz != NULL)
        *bufsz = 8;
    return st->buf->data + 19;
}
/**
 * fu_struct_goodix_moc_pkg_version_rsp_get_mcu: (skip):
 **/
const guint8 *
fu_struct_goodix_moc_pkg_version_rsp_get_mcu(const FuStructGoodixMocPkgVersionRsp *st, gsize *bufsz)
{
    g_return_val_if_fail(st != NULL, NULL);
    if (bufsz != NULL)
        *bufsz = 8;
    return st->buf->data + 27;
}
/**
 * fu_struct_goodix_moc_pkg_version_rsp_get_sensor: (skip):
 **/
const guint8 *
fu_struct_goodix_moc_pkg_version_rsp_get_sensor(const FuStructGoodixMocPkgVersionRsp *st, gsize *bufsz)
{
    g_return_val_if_fail(st != NULL, NULL);
    if (bufsz != NULL)
        *bufsz = 8;
    return st->buf->data + 35;
}
/**
 * fu_struct_goodix_moc_pkg_version_rsp_get_algversion: (skip):
 **/
const guint8 *
fu_struct_goodix_moc_pkg_version_rsp_get_algversion(const FuStructGoodixMocPkgVersionRsp *st, gsize *bufsz)
{
    g_return_val_if_fail(st != NULL, NULL);
    if (bufsz != NULL)
        *bufsz = 8;
    return st->buf->data + 43;
}
/**
 * fu_struct_goodix_moc_pkg_version_rsp_get_interface: (skip):
 **/
const guint8 *
fu_struct_goodix_moc_pkg_version_rsp_get_interface(const FuStructGoodixMocPkgVersionRsp *st, gsize *bufsz)
{
    g_return_val_if_fail(st != NULL, NULL);
    if (bufsz != NULL)
        *bufsz = 8;
    return st->buf->data + 51;
}
/**
 * fu_struct_goodix_moc_pkg_version_rsp_get_protocol: (skip):
 **/
const guint8 *
fu_struct_goodix_moc_pkg_version_rsp_get_protocol(const FuStructGoodixMocPkgVersionRsp *st, gsize *bufsz)
{
    g_return_val_if_fail(st != NULL, NULL);
    if (bufsz != NULL)
        *bufsz = 8;
    return st->buf->data + 59;
}
/**
 * fu_struct_goodix_moc_pkg_version_rsp_get_flash_version: (skip):
 **/
const guint8 *
fu_struct_goodix_moc_pkg_version_rsp_get_flash_version(const FuStructGoodixMocPkgVersionRsp *st, gsize *bufsz)
{
    g_return_val_if_fail(st != NULL, NULL);
    if (bufsz != NULL)
        *bufsz = 8;
    return st->buf->data + 67;
}

/* setters */
/**
 * fu_struct_goodix_moc_pkg_version_rsp_to_string: (skip):
 **/
static gchar *
fu_struct_goodix_moc_pkg_version_rsp_to_string(const FuStructGoodixMocPkgVersionRsp *st)
{
    g_autoptr(GString) str = g_string_new("FuStructGoodixMocPkgVersionRsp:\n");
    g_return_val_if_fail(st != NULL, NULL);
    {
        const gchar *tmp = fu_goodix_moc_result_to_string(fu_struct_goodix_moc_pkg_version_rsp_get_result(st));
        if (tmp != NULL) {
            g_string_append_printf(str, "  result: 0x%x [%s]\n", (guint) fu_struct_goodix_moc_pkg_version_rsp_get_result(st), tmp);
        } else {
            g_string_append_printf(str, "  result: 0x%x\n", (guint) fu_struct_goodix_moc_pkg_version_rsp_get_result(st));
        }
    }
    {
        gsize bufsz = 0;
        const guint8 *buf = fu_struct_goodix_moc_pkg_version_rsp_get_format(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, "  format: 0x%s\n", tmp->str);
    }
    {
        gsize bufsz = 0;
        const guint8 *buf = fu_struct_goodix_moc_pkg_version_rsp_get_fwtype(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, "  fwtype: 0x%s\n", tmp->str);
    }
    {
        g_autofree gchar *tmp = fu_struct_goodix_moc_pkg_version_rsp_get_fwversion(st);
        if (tmp != NULL)
            g_string_append_printf(str, "  fwversion: %s\n", tmp);
    }
    {
        gsize bufsz = 0;
        const guint8 *buf = fu_struct_goodix_moc_pkg_version_rsp_get_customer(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, "  customer: 0x%s\n", tmp->str);
    }
    {
        gsize bufsz = 0;
        const guint8 *buf = fu_struct_goodix_moc_pkg_version_rsp_get_mcu(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, "  mcu: 0x%s\n", tmp->str);
    }
    {
        gsize bufsz = 0;
        const guint8 *buf = fu_struct_goodix_moc_pkg_version_rsp_get_sensor(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, "  sensor: 0x%s\n", tmp->str);
    }
    {
        gsize bufsz = 0;
        const guint8 *buf = fu_struct_goodix_moc_pkg_version_rsp_get_algversion(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, "  algversion: 0x%s\n", tmp->str);
    }
    {
        gsize bufsz = 0;
        const guint8 *buf = fu_struct_goodix_moc_pkg_version_rsp_get_interface(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, "  interface: 0x%s\n", tmp->str);
    }
    {
        gsize bufsz = 0;
        const guint8 *buf = fu_struct_goodix_moc_pkg_version_rsp_get_protocol(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, "  protocol: 0x%s\n", tmp->str);
    }
    {
        gsize bufsz = 0;
        const guint8 *buf = fu_struct_goodix_moc_pkg_version_rsp_get_flash_version(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, "  flash_version: 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_goodix_moc_pkg_version_rsp_validate_internal(FuStructGoodixMocPkgVersionRsp *st, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    return TRUE;
}
static gboolean
fu_struct_goodix_moc_pkg_version_rsp_parse_internal(FuStructGoodixMocPkgVersionRsp *st, GError **error)
{
    if (g_log_get_debug_enabled()) {
        g_autofree gchar *str = fu_struct_goodix_moc_pkg_version_rsp_to_string(st);
        g_debug("%s", str);
    }
    if (!fu_struct_goodix_moc_pkg_version_rsp_validate_internal(st, error))
        return FALSE;
    return TRUE;
}

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