/* auto-generated, do not modify */
#include "config.h"

#include "fu-goodixtp-struct.h"
#include "fu-byte-array.h"
#include "fu-mem-private.h"
#include "fu-string.h"

#ifdef G_LOG_DOMAIN
  #undef G_LOG_DOMAIN
#endif
#define G_LOG_DOMAIN "FuStruct"

/* getters */
/**
 * fu_struct_goodix_brlb_hdr_get_firmware_size: (skip):
 **/
guint32
fu_struct_goodix_brlb_hdr_get_firmware_size(const GByteArray *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint32(st->data + 0, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_goodix_brlb_hdr_get_checksum: (skip):
 **/
guint32
fu_struct_goodix_brlb_hdr_get_checksum(const GByteArray *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint32(st->data + 4, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_goodix_brlb_hdr_get_vid: (skip):
 **/
guint16
fu_struct_goodix_brlb_hdr_get_vid(const GByteArray *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->data + 27, G_BIG_ENDIAN);
}
/**
 * fu_struct_goodix_brlb_hdr_get_subsys_num: (skip):
 **/
guint8
fu_struct_goodix_brlb_hdr_get_subsys_num(const GByteArray *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->data[29];
}

/* setters */
/**
 * fu_struct_goodix_brlb_hdr_to_string: (skip):
 **/
static gchar *
fu_struct_goodix_brlb_hdr_to_string(const GByteArray *st)
{
    g_autoptr(GString) str = g_string_new("GoodixBrlbHdr:\n");
    g_return_val_if_fail(st != NULL, NULL);
    g_string_append_printf(str, "  firmware_size: 0x%x\n",
                           (guint) fu_struct_goodix_brlb_hdr_get_firmware_size(st));
    g_string_append_printf(str, "  checksum: 0x%x\n",
                           (guint) fu_struct_goodix_brlb_hdr_get_checksum(st));
    g_string_append_printf(str, "  vid: 0x%x\n",
                           (guint) fu_struct_goodix_brlb_hdr_get_vid(st));
    g_string_append_printf(str, "  subsys_num: 0x%x\n",
                           (guint) fu_struct_goodix_brlb_hdr_get_subsys_num(st));
    if (str->len > 0)
        g_string_set_size(str, str->len - 1);
    return g_string_free(g_steal_pointer(&str), FALSE);
}
/**
 * fu_struct_goodix_brlb_hdr_parse: (skip):
 **/
static GByteArray *
fu_struct_goodix_brlb_hdr_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error)
{
    g_autoptr(GByteArray) st = g_byte_array_new();
    g_autofree gchar *str = NULL;
    g_return_val_if_fail(buf != NULL, NULL);
    g_return_val_if_fail(error == NULL || *error == NULL, NULL);
    if (!fu_memchk_read(bufsz, offset, 42, error)) {
        g_prefix_error(error, "invalid struct GoodixBrlbHdr: ");
        return NULL;
    }
    g_byte_array_append(st, buf + offset, 42);
    str = fu_struct_goodix_brlb_hdr_to_string(st);
    g_debug("%s", str);
    return g_steal_pointer(&st);
}
/**
 * fu_struct_goodix_brlb_hdr_parse_bytes: (skip):
 **/
GByteArray *
fu_struct_goodix_brlb_hdr_parse_bytes(GBytes *blob, gsize offset, GError **error)
{
    gsize bufsz = 0;
    const guint8 *buf = g_bytes_get_data(blob, &bufsz);
    return fu_struct_goodix_brlb_hdr_parse(buf, bufsz, offset, error);
}
/* getters */
/**
 * fu_struct_goodix_brlb_img_get_kind: (skip):
 **/
guint8
fu_struct_goodix_brlb_img_get_kind(const GByteArray *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->data[0];
}
/**
 * fu_struct_goodix_brlb_img_get_size: (skip):
 **/
guint32
fu_struct_goodix_brlb_img_get_size(const GByteArray *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint32(st->data + 1, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_goodix_brlb_img_get_addr: (skip):
 **/
guint32
fu_struct_goodix_brlb_img_get_addr(const GByteArray *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint32(st->data + 5, G_LITTLE_ENDIAN);
}

/* setters */
/**
 * fu_struct_goodix_brlb_img_to_string: (skip):
 **/
static gchar *
fu_struct_goodix_brlb_img_to_string(const GByteArray *st)
{
    g_autoptr(GString) str = g_string_new("GoodixBrlbImg:\n");
    g_return_val_if_fail(st != NULL, NULL);
    g_string_append_printf(str, "  kind: 0x%x\n",
                           (guint) fu_struct_goodix_brlb_img_get_kind(st));
    g_string_append_printf(str, "  size: 0x%x\n",
                           (guint) fu_struct_goodix_brlb_img_get_size(st));
    g_string_append_printf(str, "  addr: 0x%x\n",
                           (guint) fu_struct_goodix_brlb_img_get_addr(st));
    if (str->len > 0)
        g_string_set_size(str, str->len - 1);
    return g_string_free(g_steal_pointer(&str), FALSE);
}
/**
 * fu_struct_goodix_brlb_img_parse: (skip):
 **/
static GByteArray *
fu_struct_goodix_brlb_img_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error)
{
    g_autoptr(GByteArray) st = g_byte_array_new();
    g_autofree gchar *str = NULL;
    g_return_val_if_fail(buf != NULL, NULL);
    g_return_val_if_fail(error == NULL || *error == NULL, NULL);
    if (!fu_memchk_read(bufsz, offset, 10, error)) {
        g_prefix_error(error, "invalid struct GoodixBrlbImg: ");
        return NULL;
    }
    g_byte_array_append(st, buf + offset, 10);
    str = fu_struct_goodix_brlb_img_to_string(st);
    g_debug("%s", str);
    return g_steal_pointer(&st);
}
/**
 * fu_struct_goodix_brlb_img_parse_bytes: (skip):
 **/
GByteArray *
fu_struct_goodix_brlb_img_parse_bytes(GBytes *blob, gsize offset, GError **error)
{
    gsize bufsz = 0;
    const guint8 *buf = g_bytes_get_data(blob, &bufsz);
    return fu_struct_goodix_brlb_img_parse(buf, bufsz, offset, error);
}
/* getters */
/**
 * fu_struct_goodix_gtx8_hdr_get_firmware_size: (skip):
 **/
guint32
fu_struct_goodix_gtx8_hdr_get_firmware_size(const GByteArray *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint32(st->data + 0, G_BIG_ENDIAN);
}
/**
 * fu_struct_goodix_gtx8_hdr_get_checksum: (skip):
 **/
guint16
fu_struct_goodix_gtx8_hdr_get_checksum(const GByteArray *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->data + 4, G_BIG_ENDIAN);
}
/**
 * fu_struct_goodix_gtx8_hdr_get_vid: (skip):
 **/
guint16
fu_struct_goodix_gtx8_hdr_get_vid(const GByteArray *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->data + 25, G_BIG_ENDIAN);
}
/**
 * fu_struct_goodix_gtx8_hdr_get_subsys_num: (skip):
 **/
guint8
fu_struct_goodix_gtx8_hdr_get_subsys_num(const GByteArray *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->data[27];
}

/* setters */
/**
 * fu_struct_goodix_gtx8_hdr_to_string: (skip):
 **/
static gchar *
fu_struct_goodix_gtx8_hdr_to_string(const GByteArray *st)
{
    g_autoptr(GString) str = g_string_new("GoodixGtx8Hdr:\n");
    g_return_val_if_fail(st != NULL, NULL);
    g_string_append_printf(str, "  firmware_size: 0x%x\n",
                           (guint) fu_struct_goodix_gtx8_hdr_get_firmware_size(st));
    g_string_append_printf(str, "  checksum: 0x%x\n",
                           (guint) fu_struct_goodix_gtx8_hdr_get_checksum(st));
    g_string_append_printf(str, "  vid: 0x%x\n",
                           (guint) fu_struct_goodix_gtx8_hdr_get_vid(st));
    g_string_append_printf(str, "  subsys_num: 0x%x\n",
                           (guint) fu_struct_goodix_gtx8_hdr_get_subsys_num(st));
    if (str->len > 0)
        g_string_set_size(str, str->len - 1);
    return g_string_free(g_steal_pointer(&str), FALSE);
}
/**
 * fu_struct_goodix_gtx8_hdr_parse: (skip):
 **/
static GByteArray *
fu_struct_goodix_gtx8_hdr_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error)
{
    g_autoptr(GByteArray) st = g_byte_array_new();
    g_autofree gchar *str = NULL;
    g_return_val_if_fail(buf != NULL, NULL);
    g_return_val_if_fail(error == NULL || *error == NULL, NULL);
    if (!fu_memchk_read(bufsz, offset, 32, error)) {
        g_prefix_error(error, "invalid struct GoodixGtx8Hdr: ");
        return NULL;
    }
    g_byte_array_append(st, buf + offset, 32);
    str = fu_struct_goodix_gtx8_hdr_to_string(st);
    g_debug("%s", str);
    return g_steal_pointer(&st);
}
/**
 * fu_struct_goodix_gtx8_hdr_parse_bytes: (skip):
 **/
GByteArray *
fu_struct_goodix_gtx8_hdr_parse_bytes(GBytes *blob, gsize offset, GError **error)
{
    gsize bufsz = 0;
    const guint8 *buf = g_bytes_get_data(blob, &bufsz);
    return fu_struct_goodix_gtx8_hdr_parse(buf, bufsz, offset, error);
}
/* getters */
/**
 * fu_struct_goodix_gtx8_img_get_kind: (skip):
 **/
guint8
fu_struct_goodix_gtx8_img_get_kind(const GByteArray *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->data[0];
}
/**
 * fu_struct_goodix_gtx8_img_get_size: (skip):
 **/
guint32
fu_struct_goodix_gtx8_img_get_size(const GByteArray *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint32(st->data + 1, G_BIG_ENDIAN);
}
/**
 * fu_struct_goodix_gtx8_img_get_addr: (skip):
 **/
guint16
fu_struct_goodix_gtx8_img_get_addr(const GByteArray *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->data + 5, G_BIG_ENDIAN);
}

/* setters */
/**
 * fu_struct_goodix_gtx8_img_to_string: (skip):
 **/
static gchar *
fu_struct_goodix_gtx8_img_to_string(const GByteArray *st)
{
    g_autoptr(GString) str = g_string_new("GoodixGtx8Img:\n");
    g_return_val_if_fail(st != NULL, NULL);
    g_string_append_printf(str, "  kind: 0x%x\n",
                           (guint) fu_struct_goodix_gtx8_img_get_kind(st));
    g_string_append_printf(str, "  size: 0x%x\n",
                           (guint) fu_struct_goodix_gtx8_img_get_size(st));
    g_string_append_printf(str, "  addr: 0x%x\n",
                           (guint) fu_struct_goodix_gtx8_img_get_addr(st));
    if (str->len > 0)
        g_string_set_size(str, str->len - 1);
    return g_string_free(g_steal_pointer(&str), FALSE);
}
/**
 * fu_struct_goodix_gtx8_img_parse: (skip):
 **/
static GByteArray *
fu_struct_goodix_gtx8_img_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error)
{
    g_autoptr(GByteArray) st = g_byte_array_new();
    g_autofree gchar *str = NULL;
    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(error, "invalid struct GoodixGtx8Img: ");
        return NULL;
    }
    g_byte_array_append(st, buf + offset, 8);
    str = fu_struct_goodix_gtx8_img_to_string(st);
    g_debug("%s", str);
    return g_steal_pointer(&st);
}
/**
 * fu_struct_goodix_gtx8_img_parse_bytes: (skip):
 **/
GByteArray *
fu_struct_goodix_gtx8_img_parse_bytes(GBytes *blob, gsize offset, GError **error)
{
    gsize bufsz = 0;
    const guint8 *buf = g_bytes_get_data(blob, &bufsz);
    return fu_struct_goodix_gtx8_img_parse(buf, bufsz, offset, error);
}
