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

#include "config.h"

#include <glib.h>

#include "fu-himax-tp-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_himax_tp_fw_status_to_string:
 * @val: value, e.g. %FU_HIMAX_TP_FW_STATUS_MCU_E0
 *
 * Converts an enumerated value to a string.
 *
 * Returns: identifier string
 **/
const gchar *
fu_himax_tp_fw_status_to_string(FuHimaxTpFwStatus val)
{
    if (val == FU_HIMAX_TP_FW_STATUS_NO_ERROR)
        return "no-error";
    if (val == FU_HIMAX_TP_FW_STATUS_MCU_E0)
        return "mcu-e0";
    if (val == FU_HIMAX_TP_FW_STATUS_MCU_E1)
        return "mcu-e1";
    if (val == FU_HIMAX_TP_FW_STATUS_COMMIT)
        return "commit";
    if (val == FU_HIMAX_TP_FW_STATUS_BL)
        return "bl";
    if (val == FU_HIMAX_TP_FW_STATUS_PW)
        return "pw";
    if (val == FU_HIMAX_TP_FW_STATUS_ERASE_FLASH)
        return "erase-flash";
    if (val == FU_HIMAX_TP_FW_STATUS_FLASH_PROGRAMMING)
        return "flash-programming";
    if (val == FU_HIMAX_TP_FW_STATUS_NO_BL)
        return "no-bl";
    if (val == FU_HIMAX_TP_FW_STATUS_NO_MAIN)
        return "no-main";
    return NULL;
}


/**
 * fu_himax_tp_report_id_to_string:
 * @val: value, e.g. %FU_HIMAX_TP_REPORT_ID_REG_RW
 *
 * Converts an enumerated value to a string.
 *
 * Returns: identifier string
 **/
const gchar *
fu_himax_tp_report_id_to_string(FuHimaxTpReportId val)
{
    if (val == FU_HIMAX_TP_REPORT_ID_CFG)
        return "cfg";
    if (val == FU_HIMAX_TP_REPORT_ID_REG_RW)
        return "reg-rw";
    if (val == FU_HIMAX_TP_REPORT_ID_FW_UPDATE)
        return "fw-update";
    if (val == FU_HIMAX_TP_REPORT_ID_FW_UPDATE_HANDSHAKING)
        return "fw-update-handshaking";
    if (val == FU_HIMAX_TP_REPORT_ID_SELF_TEST)
        return "self-test";
    return NULL;
}
/**
 * fu_struct_himax_tp_hid_fw_unit_ref: (skip):
 **/
FuStructHimaxTpHidFwUnit *
fu_struct_himax_tp_hid_fw_unit_ref(FuStructHimaxTpHidFwUnit *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_himax_tp_hid_fw_unit_unref: (skip):
 **/
void
fu_struct_himax_tp_hid_fw_unit_unref(FuStructHimaxTpHidFwUnit *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructHimaxTpHidFwUnit refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_himax_tp_hid_fw_unit_new_internal: (skip):
 **/
static FuStructHimaxTpHidFwUnit *
fu_struct_himax_tp_hid_fw_unit_new_internal(void)
{
    FuStructHimaxTpHidFwUnit *st = g_new0(FuStructHimaxTpHidFwUnit, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_himax_tp_hid_fw_unit_get_cmd: (skip):
 **/
guint8
fu_struct_himax_tp_hid_fw_unit_get_cmd(const FuStructHimaxTpHidFwUnit *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[0];
}
/**
 * fu_struct_himax_tp_hid_fw_unit_get_bin_start_offset: (skip):
 **/
guint16
fu_struct_himax_tp_hid_fw_unit_get_bin_start_offset(const FuStructHimaxTpHidFwUnit *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 1, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_himax_tp_hid_fw_unit_get_bin_size: (skip):
 **/
guint16
fu_struct_himax_tp_hid_fw_unit_get_bin_size(const FuStructHimaxTpHidFwUnit *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 3, G_LITTLE_ENDIAN);
}

/* setters */
/**
 * fu_struct_himax_tp_hid_fw_unit_to_string: (skip):
 **/
static gchar *
fu_struct_himax_tp_hid_fw_unit_to_string(const FuStructHimaxTpHidFwUnit *st)
{
    g_autoptr(GString) str = g_string_new("FuStructHimaxTpHidFwUnit:\n");
    g_return_val_if_fail(st != NULL, NULL);
    g_string_append_printf(str, "  cmd: 0x%x\n",
                           (guint) fu_struct_himax_tp_hid_fw_unit_get_cmd(st));
    g_string_append_printf(str, "  bin_start_offset: 0x%x\n",
                           (guint) fu_struct_himax_tp_hid_fw_unit_get_bin_start_offset(st));
    g_string_append_printf(str, "  bin_size: 0x%x\n",
                           (guint) fu_struct_himax_tp_hid_fw_unit_get_bin_size(st));
    if (str->len > 0)
        g_string_set_size(str, str->len - 1);
    return g_string_free(g_steal_pointer(&str), FALSE);
}
static gboolean
fu_struct_himax_tp_hid_fw_unit_validate_internal(FuStructHimaxTpHidFwUnit *st, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    return TRUE;
}
/**
 * fu_struct_himax_tp_hid_info_ref: (skip):
 **/
FuStructHimaxTpHidInfo *
fu_struct_himax_tp_hid_info_ref(FuStructHimaxTpHidInfo *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_himax_tp_hid_info_unref: (skip):
 **/
void
fu_struct_himax_tp_hid_info_unref(FuStructHimaxTpHidInfo *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructHimaxTpHidInfo refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_himax_tp_hid_info_new_internal: (skip):
 **/
static FuStructHimaxTpHidInfo *
fu_struct_himax_tp_hid_info_new_internal(void)
{
    FuStructHimaxTpHidInfo *st = g_new0(FuStructHimaxTpHidInfo, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_himax_tp_hid_info_get_main_mapping: (skip):
 **/
FuStructHimaxTpHidFwUnit *
fu_struct_himax_tp_hid_info_get_main_mapping(const FuStructHimaxTpHidInfo *st, guint idx)
{
    g_autoptr(FuStructHimaxTpHidFwUnit) st_tmp = fu_struct_himax_tp_hid_fw_unit_new_internal();
    g_return_val_if_fail(st != NULL, NULL);
    g_return_val_if_fail(idx < 9, NULL);
    st_tmp->buf = g_byte_array_new();
    g_byte_array_append(st_tmp->buf,
                        st->buf->data
                            + FU_STRUCT_HIMAX_TP_HID_INFO_OFFSET_MAIN_MAPPING
                            + (FU_STRUCT_HIMAX_TP_HID_FW_UNIT_SIZE * idx),
                        5);
    return g_steal_pointer(&st_tmp);
}
/**
 * fu_struct_himax_tp_hid_info_get_bl_mapping: (skip):
 **/
FuStructHimaxTpHidFwUnit *
fu_struct_himax_tp_hid_info_get_bl_mapping(const FuStructHimaxTpHidInfo *st)
{
    g_autoptr(FuStructHimaxTpHidFwUnit) st_tmp = fu_struct_himax_tp_hid_fw_unit_new_internal();
    g_return_val_if_fail(st != NULL, NULL);
    st_tmp->buf = g_byte_array_new();
    g_byte_array_append(st_tmp->buf, st->buf->data + FU_STRUCT_HIMAX_TP_HID_INFO_OFFSET_BL_MAPPING, 5);
    return g_steal_pointer(&st_tmp);
}
/**
 * fu_struct_himax_tp_hid_info_get_cid: (skip):
 **/
guint16
fu_struct_himax_tp_hid_info_get_cid(const FuStructHimaxTpHidInfo *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 52, G_BIG_ENDIAN);
}
/**
 * fu_struct_himax_tp_hid_info_get_vid: (skip):
 **/
guint16
fu_struct_himax_tp_hid_info_get_vid(const FuStructHimaxTpHidInfo *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 130, G_BIG_ENDIAN);
}
/**
 * fu_struct_himax_tp_hid_info_get_pid: (skip):
 **/
guint16
fu_struct_himax_tp_hid_info_get_pid(const FuStructHimaxTpHidInfo *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 132, G_BIG_ENDIAN);
}

/* setters */
/**
 * fu_struct_himax_tp_hid_info_to_string: (skip):
 **/
static gchar *
fu_struct_himax_tp_hid_info_to_string(const FuStructHimaxTpHidInfo *st)
{
    g_autoptr(GString) str = g_string_new("FuStructHimaxTpHidInfo:\n");
    g_return_val_if_fail(st != NULL, NULL);
    for (guint i = 0; i < 9; i++) {
        g_autoptr(FuStructHimaxTpHidFwUnit) st_tmp = fu_struct_himax_tp_hid_info_get_main_mapping(st, i);
        g_autofree gchar *tmp = fu_struct_himax_tp_hid_fw_unit_to_string(st_tmp);
        g_string_append_printf(str, "  main_mapping[%u]: %s\n", i, tmp);
    }
    {
        g_autoptr(FuStructHimaxTpHidFwUnit) st_tmp = fu_struct_himax_tp_hid_info_get_bl_mapping(st);
        g_autofree gchar *tmp = fu_struct_himax_tp_hid_fw_unit_to_string(st_tmp);
        g_string_append_printf(str, "  bl_mapping: %s\n", tmp);
    }
    g_string_append_printf(str, "  cid: 0x%x\n",
                           (guint) fu_struct_himax_tp_hid_info_get_cid(st));
    g_string_append_printf(str, "  vid: 0x%x\n",
                           (guint) fu_struct_himax_tp_hid_info_get_vid(st));
    g_string_append_printf(str, "  pid: 0x%x\n",
                           (guint) fu_struct_himax_tp_hid_info_get_pid(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_himax_tp_hid_info_validate_internal(FuStructHimaxTpHidInfo *st, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    {
        GByteArray buf_tmp = {
            .data = (guint8*) st->buf->data + 0x0,
            .len = 45,
        };
        FuStructHimaxTpHidFwUnit st_tmp = { .buf = &buf_tmp };
        if (!fu_struct_himax_tp_hid_fw_unit_validate_internal(&st_tmp, error))
            return FALSE;
    }
    {
        GByteArray buf_tmp = {
            .data = (guint8*) st->buf->data + 0x2D,
            .len = 5,
        };
        FuStructHimaxTpHidFwUnit st_tmp = { .buf = &buf_tmp };
        if (!fu_struct_himax_tp_hid_fw_unit_validate_internal(&st_tmp, error))
            return FALSE;
    }
    return TRUE;
}
static gboolean
fu_struct_himax_tp_hid_info_parse_internal(FuStructHimaxTpHidInfo *st, GError **error)
{
    if (g_log_get_debug_enabled()) {
        g_autofree gchar *str = fu_struct_himax_tp_hid_info_to_string(st);
        g_debug("%s", str);
    }
    if (!fu_struct_himax_tp_hid_info_validate_internal(st, error))
        return FALSE;
    return TRUE;
}

/**
 * fu_struct_himax_tp_hid_info_parse: (skip):
 **/
FuStructHimaxTpHidInfo *
fu_struct_himax_tp_hid_info_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error)
{
    g_autoptr(FuStructHimaxTpHidInfo) st = fu_struct_himax_tp_hid_info_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, 255, error)) {
        g_prefix_error_literal(error, "invalid struct FuStructHimaxTpHidInfo: ");
        return NULL;
    }
    st->buf = g_byte_array_new();
    g_byte_array_append(st->buf, buf + offset, 255);
    if (!fu_struct_himax_tp_hid_info_parse_internal(st, error))
        return NULL;
    return g_steal_pointer(&st);
}
/**
 * fu_struct_himax_tp_ic_id_ref: (skip):
 **/
FuStructHimaxTpIcId *
fu_struct_himax_tp_ic_id_ref(FuStructHimaxTpIcId *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_himax_tp_ic_id_unref: (skip):
 **/
void
fu_struct_himax_tp_ic_id_unref(FuStructHimaxTpIcId *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructHimaxTpIcId refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_himax_tp_ic_id_new_internal: (skip):
 **/
static FuStructHimaxTpIcId *
fu_struct_himax_tp_ic_id_new_internal(void)
{
    FuStructHimaxTpIcId *st = g_new0(FuStructHimaxTpIcId, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_himax_tp_ic_id_get_desc: (skip):
 **/
gchar *
fu_struct_himax_tp_ic_id_get_desc(const FuStructHimaxTpIcId *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    return fu_memstrsafe(st->buf->data, st->buf->len, 0, 12, NULL);
}
/**
 * fu_struct_himax_tp_ic_id_get_vid: (skip):
 **/
guint16
fu_struct_himax_tp_ic_id_get_vid(const FuStructHimaxTpIcId *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 12, G_BIG_ENDIAN);
}
/**
 * fu_struct_himax_tp_ic_id_get_pid: (skip):
 **/
guint16
fu_struct_himax_tp_ic_id_get_pid(const FuStructHimaxTpIcId *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 14, G_BIG_ENDIAN);
}

/* setters */
/**
 * fu_struct_himax_tp_ic_id_to_string: (skip):
 **/
static gchar *
fu_struct_himax_tp_ic_id_to_string(const FuStructHimaxTpIcId *st)
{
    g_autoptr(GString) str = g_string_new("FuStructHimaxTpIcId:\n");
    g_return_val_if_fail(st != NULL, NULL);
    {
        g_autofree gchar *tmp = fu_struct_himax_tp_ic_id_get_desc(st);
        if (tmp != NULL)
            g_string_append_printf(str, "  desc: %s\n", tmp);
    }
    g_string_append_printf(str, "  vid: 0x%x\n",
                           (guint) fu_struct_himax_tp_ic_id_get_vid(st));
    g_string_append_printf(str, "  pid: 0x%x\n",
                           (guint) fu_struct_himax_tp_ic_id_get_pid(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_himax_tp_ic_id_validate_internal(FuStructHimaxTpIcId *st, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    return TRUE;
}
static gboolean
fu_struct_himax_tp_ic_id_parse_internal(FuStructHimaxTpIcId *st, GError **error)
{
    if (g_log_get_debug_enabled()) {
        g_autofree gchar *str = fu_struct_himax_tp_ic_id_to_string(st);
        g_debug("%s", str);
    }
    if (!fu_struct_himax_tp_ic_id_validate_internal(st, error))
        return FALSE;
    return TRUE;
}
/**
 * fu_struct_himax_tp_ic_id_parse_stream: (skip):
 **/
FuStructHimaxTpIcId *
fu_struct_himax_tp_ic_id_parse_stream(GInputStream *stream, gsize offset, GError **error)
{
    g_autoptr(FuStructHimaxTpIcId) st = fu_struct_himax_tp_ic_id_new_internal();
    st->buf = fu_input_stream_read_byte_array(stream, offset, 16, NULL, error);
    if (st->buf == NULL) {
        g_prefix_error(error, "FuStructHimaxTpIcId failed read of 0x%x: ", (guint) 16);
        return NULL;
    }
    if (st->buf->len != 16) {
        g_set_error(error,
                    FWUPD_ERROR,
                    FWUPD_ERROR_INVALID_DATA,
                    "FuStructHimaxTpIcId requested 0x%x and got 0x%x",
                    (guint) 16,
                    (guint) st->buf->len);
        return NULL;
    }
    if (!fu_struct_himax_tp_ic_id_parse_internal(st, error))
        return NULL;
    return g_steal_pointer(&st);
}
/**
 * fu_struct_himax_tp_ic_id_mod_ref: (skip):
 **/
FuStructHimaxTpIcIdMod *
fu_struct_himax_tp_ic_id_mod_ref(FuStructHimaxTpIcIdMod *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_himax_tp_ic_id_mod_unref: (skip):
 **/
void
fu_struct_himax_tp_ic_id_mod_unref(FuStructHimaxTpIcIdMod *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructHimaxTpIcIdMod refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_himax_tp_ic_id_mod_new_internal: (skip):
 **/
static FuStructHimaxTpIcIdMod *
fu_struct_himax_tp_ic_id_mod_new_internal(void)
{
    FuStructHimaxTpIcIdMod *st = g_new0(FuStructHimaxTpIcIdMod, 1);
    st->refcount = 1;
    return st;
}

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

/* setters */
/**
 * fu_struct_himax_tp_ic_id_mod_to_string: (skip):
 **/
static gchar *
fu_struct_himax_tp_ic_id_mod_to_string(const FuStructHimaxTpIcIdMod *st)
{
    g_autoptr(GString) str = g_string_new("FuStructHimaxTpIcIdMod:\n");
    g_return_val_if_fail(st != NULL, NULL);
    {
        g_autofree gchar *tmp = fu_struct_himax_tp_ic_id_mod_get_desc(st);
        if (tmp != NULL)
            g_string_append_printf(str, "  desc: %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_himax_tp_ic_id_mod_validate_internal(FuStructHimaxTpIcIdMod *st, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    return TRUE;
}
static gboolean
fu_struct_himax_tp_ic_id_mod_parse_internal(FuStructHimaxTpIcIdMod *st, GError **error)
{
    if (g_log_get_debug_enabled()) {
        g_autofree gchar *str = fu_struct_himax_tp_ic_id_mod_to_string(st);
        g_debug("%s", str);
    }
    if (!fu_struct_himax_tp_ic_id_mod_validate_internal(st, error))
        return FALSE;
    return TRUE;
}
/**
 * fu_struct_himax_tp_ic_id_mod_parse_stream: (skip):
 **/
FuStructHimaxTpIcIdMod *
fu_struct_himax_tp_ic_id_mod_parse_stream(GInputStream *stream, gsize offset, GError **error)
{
    g_autoptr(FuStructHimaxTpIcIdMod) st = fu_struct_himax_tp_ic_id_mod_new_internal();
    st->buf = fu_input_stream_read_byte_array(stream, offset, 2, NULL, error);
    if (st->buf == NULL) {
        g_prefix_error(error, "FuStructHimaxTpIcIdMod failed read of 0x%x: ", (guint) 2);
        return NULL;
    }
    if (st->buf->len != 2) {
        g_set_error(error,
                    FWUPD_ERROR,
                    FWUPD_ERROR_INVALID_DATA,
                    "FuStructHimaxTpIcIdMod requested 0x%x and got 0x%x",
                    (guint) 2,
                    (guint) st->buf->len);
        return NULL;
    }
    if (!fu_struct_himax_tp_ic_id_mod_parse_internal(st, error))
        return NULL;
    return g_steal_pointer(&st);
}
/**
 * fu_struct_himax_tp_map_code_ref: (skip):
 **/
FuStructHimaxTpMapCode *
fu_struct_himax_tp_map_code_ref(FuStructHimaxTpMapCode *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_himax_tp_map_code_unref: (skip):
 **/
void
fu_struct_himax_tp_map_code_unref(FuStructHimaxTpMapCode *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructHimaxTpMapCode refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_himax_tp_map_code_new_internal: (skip):
 **/
static FuStructHimaxTpMapCode *
fu_struct_himax_tp_map_code_new_internal(void)
{
    FuStructHimaxTpMapCode *st = g_new0(FuStructHimaxTpMapCode, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_himax_tp_map_code_get_mcode: (skip):
 **/
guint32
fu_struct_himax_tp_map_code_get_mcode(const FuStructHimaxTpMapCode *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint32(st->buf->data + 0, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_himax_tp_map_code_get_flash_addr: (skip):
 **/
guint32
fu_struct_himax_tp_map_code_get_flash_addr(const FuStructHimaxTpMapCode *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint32(st->buf->data + 4, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_himax_tp_map_code_get_size: (skip):
 **/
guint32
fu_struct_himax_tp_map_code_get_size(const FuStructHimaxTpMapCode *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint32(st->buf->data + 8, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_himax_tp_map_code_get_cs: (skip):
 **/
guint32
fu_struct_himax_tp_map_code_get_cs(const FuStructHimaxTpMapCode *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint32(st->buf->data + 12, G_LITTLE_ENDIAN);
}

/* setters */
/**
 * fu_struct_himax_tp_map_code_to_string: (skip):
 **/
static gchar *
fu_struct_himax_tp_map_code_to_string(const FuStructHimaxTpMapCode *st)
{
    g_autoptr(GString) str = g_string_new("FuStructHimaxTpMapCode:\n");
    g_return_val_if_fail(st != NULL, NULL);
    g_string_append_printf(str, "  mcode: 0x%x\n",
                           (guint) fu_struct_himax_tp_map_code_get_mcode(st));
    g_string_append_printf(str, "  flash_addr: 0x%x\n",
                           (guint) fu_struct_himax_tp_map_code_get_flash_addr(st));
    g_string_append_printf(str, "  size: 0x%x\n",
                           (guint) fu_struct_himax_tp_map_code_get_size(st));
    g_string_append_printf(str, "  cs: 0x%x\n",
                           (guint) fu_struct_himax_tp_map_code_get_cs(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_himax_tp_map_code_validate_internal(FuStructHimaxTpMapCode *st, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    return TRUE;
}
static gboolean
fu_struct_himax_tp_map_code_parse_internal(FuStructHimaxTpMapCode *st, GError **error)
{
    if (g_log_get_debug_enabled()) {
        g_autofree gchar *str = fu_struct_himax_tp_map_code_to_string(st);
        g_debug("%s", str);
    }
    if (!fu_struct_himax_tp_map_code_validate_internal(st, error))
        return FALSE;
    return TRUE;
}
/**
 * fu_struct_himax_tp_map_code_parse_stream: (skip):
 **/
FuStructHimaxTpMapCode *
fu_struct_himax_tp_map_code_parse_stream(GInputStream *stream, gsize offset, GError **error)
{
    g_autoptr(FuStructHimaxTpMapCode) st = fu_struct_himax_tp_map_code_new_internal();
    st->buf = fu_input_stream_read_byte_array(stream, offset, 16, NULL, error);
    if (st->buf == NULL) {
        g_prefix_error(error, "FuStructHimaxTpMapCode failed read of 0x%x: ", (guint) 16);
        return NULL;
    }
    if (st->buf->len != 16) {
        g_set_error(error,
                    FWUPD_ERROR,
                    FWUPD_ERROR_INVALID_DATA,
                    "FuStructHimaxTpMapCode requested 0x%x and got 0x%x",
                    (guint) 16,
                    (guint) st->buf->len);
        return NULL;
    }
    if (!fu_struct_himax_tp_map_code_parse_internal(st, error))
        return NULL;
    return g_steal_pointer(&st);
}
/**
 * fu_struct_himax_tp_reg_rw_ref: (skip):
 **/
FuStructHimaxTpRegRw *
fu_struct_himax_tp_reg_rw_ref(FuStructHimaxTpRegRw *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_himax_tp_reg_rw_unref: (skip):
 **/
void
fu_struct_himax_tp_reg_rw_unref(FuStructHimaxTpRegRw *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructHimaxTpRegRw refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_himax_tp_reg_rw_new_internal: (skip):
 **/
static FuStructHimaxTpRegRw *
fu_struct_himax_tp_reg_rw_new_internal(void)
{
    FuStructHimaxTpRegRw *st = g_new0(FuStructHimaxTpRegRw, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_himax_tp_reg_rw_get_rw_flag: (skip):
 **/
guint8
fu_struct_himax_tp_reg_rw_get_rw_flag(const FuStructHimaxTpRegRw *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[0];
}
/**
 * fu_struct_himax_tp_reg_rw_get_reg_addr: (skip):
 **/
FuHimaxTpRegisterAddr
fu_struct_himax_tp_reg_rw_get_reg_addr(const FuStructHimaxTpRegRw *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint32(st->buf->data + 1, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_himax_tp_reg_rw_get_reg_value: (skip):
 **/
guint32
fu_struct_himax_tp_reg_rw_get_reg_value(const FuStructHimaxTpRegRw *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint32(st->buf->data + 5, G_LITTLE_ENDIAN);
}

/* setters */
/**
 * fu_struct_himax_tp_reg_rw_set_rw_flag: (skip):
 **/
void
fu_struct_himax_tp_reg_rw_set_rw_flag(FuStructHimaxTpRegRw *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[0] = value;
}
/**
 * fu_struct_himax_tp_reg_rw_set_reg_addr: (skip):
 **/
void
fu_struct_himax_tp_reg_rw_set_reg_addr(FuStructHimaxTpRegRw *st, FuHimaxTpRegisterAddr value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint32(st->buf->data + 1, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_himax_tp_reg_rw_set_reg_value: (skip):
 **/
void
fu_struct_himax_tp_reg_rw_set_reg_value(FuStructHimaxTpRegRw *st, guint32 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint32(st->buf->data + 5, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_himax_tp_reg_rw_new: (skip):
 **/
FuStructHimaxTpRegRw *
fu_struct_himax_tp_reg_rw_new(void)
{
    FuStructHimaxTpRegRw *st = fu_struct_himax_tp_reg_rw_new_internal();
    st->buf = g_byte_array_sized_new(9);
    fu_byte_array_set_size(st->buf, 9, 0x0);
    return st;
}
