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

#include "config.h"

#include <glib.h>

#include "fu-wch-ch347-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_wch_ch347_req_ref: (skip):
 **/
FuStructWchCh347Req *
fu_struct_wch_ch347_req_ref(FuStructWchCh347Req *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_wch_ch347_req_unref: (skip):
 **/
void
fu_struct_wch_ch347_req_unref(FuStructWchCh347Req *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructWchCh347Req refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_wch_ch347_req_new_internal: (skip):
 **/
static FuStructWchCh347Req *
fu_struct_wch_ch347_req_new_internal(void)
{
    FuStructWchCh347Req *st = g_new0(FuStructWchCh347Req, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_wch_ch347_req_get_cmd: (skip):
 **/
FuWchCh347CmdSpi
fu_struct_wch_ch347_req_get_cmd(const FuStructWchCh347Req *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return st->buf->data[0];
}
/**
 * fu_struct_wch_ch347_req_get_payloadsz: (skip):
 **/
guint16
fu_struct_wch_ch347_req_get_payloadsz(const FuStructWchCh347Req *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 1, G_LITTLE_ENDIAN);
}

/* setters */
/**
 * fu_struct_wch_ch347_req_set_cmd: (skip):
 **/
void
fu_struct_wch_ch347_req_set_cmd(FuStructWchCh347Req *st, FuWchCh347CmdSpi value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[0] = value;
}
/**
 * fu_struct_wch_ch347_req_set_payloadsz: (skip):
 **/
void
fu_struct_wch_ch347_req_set_payloadsz(FuStructWchCh347Req *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 1, value, G_LITTLE_ENDIAN);
}
/**
 * fu_struct_wch_ch347_req_new: (skip):
 **/
FuStructWchCh347Req *
fu_struct_wch_ch347_req_new(void)
{
    FuStructWchCh347Req *st = fu_struct_wch_ch347_req_new_internal();
    st->buf = g_byte_array_sized_new(3);
    fu_byte_array_set_size(st->buf, 3, 0x0);
    return st;
}
