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

#include "fu-audio-s5gen2-hid-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 */

/* setters */
/**
 * fu_struct_qc_hid_command_set_report_id: (skip):
 **/
static void
fu_struct_qc_hid_command_set_report_id(GByteArray *st, FuQcReportId value)
{
    g_return_if_fail(st != NULL);
    st->data[0] = value;
}
/**
 * fu_struct_qc_hid_command_set_payload_len: (skip):
 **/
void
fu_struct_qc_hid_command_set_payload_len(GByteArray *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->data[1] = value;
}
/**
 * fu_struct_qc_hid_command_set_payload: (skip):
 **/
gboolean
fu_struct_qc_hid_command_set_payload(GByteArray *st, const guint8 *buf, gsize bufsz, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    g_return_val_if_fail(buf != NULL, FALSE);
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
    return fu_memcpy_safe(st->data, st->len, 2, buf, bufsz, 0x0, bufsz, error);
}
/**
 * fu_struct_qc_hid_command_new: (skip):
 **/
GByteArray *
fu_struct_qc_hid_command_new(void)
{
    GByteArray *st = g_byte_array_sized_new(63);
    fu_byte_array_set_size(st, 63, 0x0);
    fu_struct_qc_hid_command_set_report_id(st, FU_QC_REPORT_ID_COMMAND);
    return st;
}
/* getters */
/**
 * fu_struct_qc_hid_response_get_report_id: (skip):
 **/
static FuQcReportId
fu_struct_qc_hid_response_get_report_id(const GByteArray *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->data[0];
}
/**
 * fu_struct_qc_hid_response_get_payload_len: (skip):
 **/
guint8
fu_struct_qc_hid_response_get_payload_len(const GByteArray *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->data[1];
}
/**
 * fu_struct_qc_hid_response_get_payload: (skip):
 **/
const guint8 *
fu_struct_qc_hid_response_get_payload(const GByteArray *st, gsize *bufsz)
{
    g_return_val_if_fail(st != NULL, NULL);
    if (bufsz != NULL)
        *bufsz = 11;
    return st->data + 2;
}

/* setters */
/**
 * fu_struct_qc_hid_response_to_string: (skip):
 **/
static gchar *
fu_struct_qc_hid_response_to_string(const GByteArray *st)
{
    g_autoptr(GString) str = g_string_new("QcHidResponse:\n");
    g_return_val_if_fail(st != NULL, NULL);
    g_string_append_printf(str, "  payload_len: 0x%x\n",
                           (guint) fu_struct_qc_hid_response_get_payload_len(st));
    {
        gsize bufsz = 0;
        const guint8 *buf = fu_struct_qc_hid_response_get_payload(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, "  payload: 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);
}
/**
 * fu_struct_qc_hid_response_parse: (skip):
 **/
GByteArray *
fu_struct_qc_hid_response_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, 13, error)) {
        g_prefix_error(error, "invalid struct QcHidResponse: ");
        return NULL;
    }
    g_byte_array_append(st, buf + offset, 13);
    if (fu_struct_qc_hid_response_get_report_id(st) != FU_QC_REPORT_ID_RESPONSE) {
        g_set_error_literal(error,
                            G_IO_ERROR,
                            G_IO_ERROR_INVALID_DATA,
                            "constant QcHidResponse.report_id was not valid, expected FU_QC_REPORT_ID_RESPONSE");
        return NULL;
    }
    str = fu_struct_qc_hid_response_to_string(st);
    g_debug("%s", str);
    return g_steal_pointer(&st);
}
/* getters */

/* setters */
/**
 * fu_struct_qc_hid_data_transfer_set_report_id: (skip):
 **/
static void
fu_struct_qc_hid_data_transfer_set_report_id(GByteArray *st, FuQcReportId value)
{
    g_return_if_fail(st != NULL);
    st->data[0] = value;
}
/**
 * fu_struct_qc_hid_data_transfer_set_payload_len: (skip):
 **/
void
fu_struct_qc_hid_data_transfer_set_payload_len(GByteArray *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->data[1] = value;
}
/**
 * fu_struct_qc_hid_data_transfer_set_payload: (skip):
 **/
gboolean
fu_struct_qc_hid_data_transfer_set_payload(GByteArray *st, const guint8 *buf, gsize bufsz, GError **error)
{
    g_return_val_if_fail(st != NULL, FALSE);
    g_return_val_if_fail(buf != NULL, FALSE);
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
    return fu_memcpy_safe(st->data, st->len, 2, buf, bufsz, 0x0, bufsz, error);
}
/**
 * fu_struct_qc_hid_data_transfer_new: (skip):
 **/
GByteArray *
fu_struct_qc_hid_data_transfer_new(void)
{
    GByteArray *st = g_byte_array_sized_new(255);
    fu_byte_array_set_size(st, 255, 0x0);
    fu_struct_qc_hid_data_transfer_set_report_id(st, FU_QC_REPORT_ID_DATA_TRANSFER);
    return st;
}
