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

#include "config.h"

#include <glib.h>

#include "fu-dell-kestrel-rtshub-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_struct_rtshub_hid_cmd_buf_ref: (skip):
 **/
FuStructRtshubHidCmdBuf *
fu_struct_rtshub_hid_cmd_buf_ref(FuStructRtshubHidCmdBuf *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_rtshub_hid_cmd_buf_unref: (skip):
 **/
void
fu_struct_rtshub_hid_cmd_buf_unref(FuStructRtshubHidCmdBuf *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructRtshubHidCmdBuf refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_rtshub_hid_cmd_buf_new_internal: (skip):
 **/
static FuStructRtshubHidCmdBuf *
fu_struct_rtshub_hid_cmd_buf_new_internal(void)
{
    FuStructRtshubHidCmdBuf *st = g_new0(FuStructRtshubHidCmdBuf, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_rtshub_hid_cmd_buf_get_cmd: (skip):
 **/
guint8
fu_struct_rtshub_hid_cmd_buf_get_cmd(const FuStructRtshubHidCmdBuf *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[0];
}
/**
 * fu_struct_rtshub_hid_cmd_buf_get_ext: (skip):
 **/
guint8
fu_struct_rtshub_hid_cmd_buf_get_ext(const FuStructRtshubHidCmdBuf *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[1];
}
/**
 * fu_struct_rtshub_hid_cmd_buf_get_regaddr: (skip):
 **/
guint32
fu_struct_rtshub_hid_cmd_buf_get_regaddr(const FuStructRtshubHidCmdBuf *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint32(st->buf->data + 2, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_rtshub_hid_cmd_buf_get_bufferlen: (skip):
 **/
guint16
fu_struct_rtshub_hid_cmd_buf_get_bufferlen(const FuStructRtshubHidCmdBuf *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 6, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_rtshub_hid_cmd_buf_get_data: (skip):
 **/
const guint8 *
fu_struct_rtshub_hid_cmd_buf_get_data(const FuStructRtshubHidCmdBuf *st, gsize *bufsz)
{
    g_return_val_if_fail(st != NULL, NULL);
    if (bufsz != NULL)
        *bufsz = 128;
    return st->buf->data + 64;
}

/* setters */
/**
 * fu_struct_rtshub_hid_cmd_buf_set_cmd: (skip):
 **/
void
fu_struct_rtshub_hid_cmd_buf_set_cmd(FuStructRtshubHidCmdBuf *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[0] = value;
}
/**
 * fu_struct_rtshub_hid_cmd_buf_set_ext: (skip):
 **/
void
fu_struct_rtshub_hid_cmd_buf_set_ext(FuStructRtshubHidCmdBuf *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[1] = value;
}
/**
 * fu_struct_rtshub_hid_cmd_buf_set_regaddr: (skip):
 **/
void
fu_struct_rtshub_hid_cmd_buf_set_regaddr(FuStructRtshubHidCmdBuf *st, guint32 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint32(st->buf->data + 2, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_rtshub_hid_cmd_buf_set_bufferlen: (skip):
 **/
void
fu_struct_rtshub_hid_cmd_buf_set_bufferlen(FuStructRtshubHidCmdBuf *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 6, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_rtshub_hid_cmd_buf_set_data: (skip):
 **/
gboolean
fu_struct_rtshub_hid_cmd_buf_set_data(FuStructRtshubHidCmdBuf *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->buf->data, st->buf->len, 64, buf, bufsz, 0x0, bufsz, error);
}
/**
 * fu_struct_rtshub_hid_cmd_buf_new: (skip):
 **/
FuStructRtshubHidCmdBuf *
fu_struct_rtshub_hid_cmd_buf_new(void)
{
    FuStructRtshubHidCmdBuf *st = fu_struct_rtshub_hid_cmd_buf_new_internal();
    st->buf = g_byte_array_sized_new(192);
    fu_byte_array_set_size(st->buf, 192, 0x0);
    return st;
}
