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

#include "config.h"

#include <glib.h>

#include "fu-cros-ec-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_cros_ec_update_frame_header_ref: (skip):
 **/
FuStructCrosEcUpdateFrameHeader *
fu_struct_cros_ec_update_frame_header_ref(FuStructCrosEcUpdateFrameHeader *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_cros_ec_update_frame_header_unref: (skip):
 **/
void
fu_struct_cros_ec_update_frame_header_unref(FuStructCrosEcUpdateFrameHeader *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructCrosEcUpdateFrameHeader refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_cros_ec_update_frame_header_new_internal: (skip):
 **/
static FuStructCrosEcUpdateFrameHeader *
fu_struct_cros_ec_update_frame_header_new_internal(void)
{
    FuStructCrosEcUpdateFrameHeader *st = g_new0(FuStructCrosEcUpdateFrameHeader, 1);
    st->refcount = 1;
    return st;
}

/* getters */

/* setters */
/**
 * fu_struct_cros_ec_update_frame_header_set_block_size: (skip):
 **/
void
fu_struct_cros_ec_update_frame_header_set_block_size(FuStructCrosEcUpdateFrameHeader *st, guint32 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint32(st->buf->data + 0, value, G_BIG_ENDIAN);
}
/**
 * fu_struct_cros_ec_update_frame_header_set_cmd_block_digest: (skip):
 **/
void
fu_struct_cros_ec_update_frame_header_set_cmd_block_digest(FuStructCrosEcUpdateFrameHeader *st, guint32 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint32(st->buf->data + 4, value, G_BIG_ENDIAN);
}
/**
 * fu_struct_cros_ec_update_frame_header_set_cmd_block_base: (skip):
 **/
void
fu_struct_cros_ec_update_frame_header_set_cmd_block_base(FuStructCrosEcUpdateFrameHeader *st, guint32 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint32(st->buf->data + 8, value, G_BIG_ENDIAN);
}
/**
 * fu_struct_cros_ec_update_frame_header_new: (skip):
 **/
FuStructCrosEcUpdateFrameHeader *
fu_struct_cros_ec_update_frame_header_new(void)
{
    FuStructCrosEcUpdateFrameHeader *st = fu_struct_cros_ec_update_frame_header_new_internal();
    st->buf = g_byte_array_sized_new(12);
    fu_byte_array_set_size(st->buf, 12, 0x0);
    return st;
}
/**
 * fu_struct_cros_ec_update_done_ref: (skip):
 **/
FuStructCrosEcUpdateDone *
fu_struct_cros_ec_update_done_ref(FuStructCrosEcUpdateDone *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_cros_ec_update_done_unref: (skip):
 **/
void
fu_struct_cros_ec_update_done_unref(FuStructCrosEcUpdateDone *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructCrosEcUpdateDone refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_cros_ec_update_done_new_internal: (skip):
 **/
static FuStructCrosEcUpdateDone *
fu_struct_cros_ec_update_done_new_internal(void)
{
    FuStructCrosEcUpdateDone *st = g_new0(FuStructCrosEcUpdateDone, 1);
    st->refcount = 1;
    return st;
}

/* getters */

/* setters */
/**
 * fu_struct_cros_ec_update_done_set_value: (skip):
 **/
static void
fu_struct_cros_ec_update_done_set_value(FuStructCrosEcUpdateDone *st, guint32 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint32(st->buf->data + 0, value, G_BIG_ENDIAN);
}
/**
 * fu_struct_cros_ec_update_done_new: (skip):
 **/
FuStructCrosEcUpdateDone *
fu_struct_cros_ec_update_done_new(void)
{
    FuStructCrosEcUpdateDone *st = fu_struct_cros_ec_update_done_new_internal();
    st->buf = g_byte_array_sized_new(4);
    fu_byte_array_set_size(st->buf, 4, 0x0);
    fu_struct_cros_ec_update_done_set_value(st, 0xB007AB1E);
    return st;
}
/**
 * fu_struct_cros_ec_signed_header_version_ref: (skip):
 **/
FuStructCrosEcSignedHeaderVersion *
fu_struct_cros_ec_signed_header_version_ref(FuStructCrosEcSignedHeaderVersion *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_cros_ec_signed_header_version_unref: (skip):
 **/
void
fu_struct_cros_ec_signed_header_version_unref(FuStructCrosEcSignedHeaderVersion *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructCrosEcSignedHeaderVersion refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}

/* getters */

/* setters */
/**
 * fu_struct_cros_ec_first_response_pdu_ref: (skip):
 **/
FuStructCrosEcFirstResponsePdu *
fu_struct_cros_ec_first_response_pdu_ref(FuStructCrosEcFirstResponsePdu *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_struct_cros_ec_first_response_pdu_unref: (skip):
 **/
void
fu_struct_cros_ec_first_response_pdu_unref(FuStructCrosEcFirstResponsePdu *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuStructCrosEcFirstResponsePdu refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_struct_cros_ec_first_response_pdu_new_internal: (skip):
 **/
static FuStructCrosEcFirstResponsePdu *
fu_struct_cros_ec_first_response_pdu_new_internal(void)
{
    FuStructCrosEcFirstResponsePdu *st = g_new0(FuStructCrosEcFirstResponsePdu, 1);
    st->refcount = 1;
    return st;
}

/* getters */
/**
 * fu_struct_cros_ec_first_response_pdu_get_return_value: (skip):
 **/
guint32
fu_struct_cros_ec_first_response_pdu_get_return_value(const FuStructCrosEcFirstResponsePdu *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint32(st->buf->data + 0, G_BIG_ENDIAN);
}
/**
 * fu_struct_cros_ec_first_response_pdu_get_header_type: (skip):
 **/
FuStructCrosEcFirstResponsePduHeaderType
fu_struct_cros_ec_first_response_pdu_get_header_type(const FuStructCrosEcFirstResponsePdu *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 4, G_BIG_ENDIAN);
}
/**
 * fu_struct_cros_ec_first_response_pdu_get_protocol_version: (skip):
 **/
guint16
fu_struct_cros_ec_first_response_pdu_get_protocol_version(const FuStructCrosEcFirstResponsePdu *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint16(st->buf->data + 6, G_BIG_ENDIAN);
}
/**
 * fu_struct_cros_ec_first_response_pdu_get_maximum_pdu_size: (skip):
 **/
guint32
fu_struct_cros_ec_first_response_pdu_get_maximum_pdu_size(const FuStructCrosEcFirstResponsePdu *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint32(st->buf->data + 8, G_BIG_ENDIAN);
}
/**
 * fu_struct_cros_ec_first_response_pdu_get_flash_protection: (skip):
 **/
guint32
fu_struct_cros_ec_first_response_pdu_get_flash_protection(const FuStructCrosEcFirstResponsePdu *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint32(st->buf->data + 12, G_BIG_ENDIAN);
}
/**
 * fu_struct_cros_ec_first_response_pdu_get_offset: (skip):
 **/
guint32
fu_struct_cros_ec_first_response_pdu_get_offset(const FuStructCrosEcFirstResponsePdu *st)
{
    g_return_val_if_fail(st != NULL, 0x0);
    return fu_memread_uint32(st->buf->data + 16, G_BIG_ENDIAN);
}
/**
 * fu_struct_cros_ec_first_response_pdu_get_version: (skip):
 **/
gchar *
fu_struct_cros_ec_first_response_pdu_get_version(const FuStructCrosEcFirstResponsePdu *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    return fu_memstrsafe(st->buf->data, st->buf->len, 20, 32, NULL);
}

/* setters */
/**
 * fu_struct_cros_ec_first_response_pdu_set_return_value: (skip):
 **/
void
fu_struct_cros_ec_first_response_pdu_set_return_value(FuStructCrosEcFirstResponsePdu *st, guint32 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint32(st->buf->data + 0, value, G_BIG_ENDIAN);
}
/**
 * fu_struct_cros_ec_first_response_pdu_set_header_type: (skip):
 **/
void
fu_struct_cros_ec_first_response_pdu_set_header_type(FuStructCrosEcFirstResponsePdu *st, FuStructCrosEcFirstResponsePduHeaderType value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 4, value, G_BIG_ENDIAN);
}
/**
 * fu_struct_cros_ec_first_response_pdu_set_protocol_version: (skip):
 **/
void
fu_struct_cros_ec_first_response_pdu_set_protocol_version(FuStructCrosEcFirstResponsePdu *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 6, value, G_BIG_ENDIAN);
}
/**
 * fu_struct_cros_ec_first_response_pdu_set_maximum_pdu_size: (skip):
 **/
void
fu_struct_cros_ec_first_response_pdu_set_maximum_pdu_size(FuStructCrosEcFirstResponsePdu *st, guint32 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint32(st->buf->data + 8, value, G_BIG_ENDIAN);
}
/**
 * fu_struct_cros_ec_first_response_pdu_set_flash_protection: (skip):
 **/
void
fu_struct_cros_ec_first_response_pdu_set_flash_protection(FuStructCrosEcFirstResponsePdu *st, guint32 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint32(st->buf->data + 12, value, G_BIG_ENDIAN);
}
/**
 * fu_struct_cros_ec_first_response_pdu_set_offset: (skip):
 **/
void
fu_struct_cros_ec_first_response_pdu_set_offset(FuStructCrosEcFirstResponsePdu *st, guint32 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint32(st->buf->data + 16, value, G_BIG_ENDIAN);
}
/**
 * fu_struct_cros_ec_first_response_pdu_set_version: (skip):
 **/
gboolean
fu_struct_cros_ec_first_response_pdu_set_version(FuStructCrosEcFirstResponsePdu *st, const gchar *value, GError **error)
{
    gsize len;
    g_return_val_if_fail(st != NULL, FALSE);
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
    if (value == NULL) {
        memset(st->buf->data + 20, 0x0, 32);
        return TRUE;
    }
    len = strlen(value);
    if (len > 32) {
        g_set_error(error,
                    FWUPD_ERROR,
                    FWUPD_ERROR_INVALID_DATA,
                    "string '%s' (0x%x bytes) does not fit in FuStructCrosEcFirstResponsePdu.version (0x%x bytes)",
                    value, (guint) len, (guint) 32);
        return FALSE;
    }
    return fu_memcpy_safe(st->buf->data, st->buf->len, 20, (const guint8 *)value, len, 0x0, len, error);
}
/**
 * fu_struct_cros_ec_first_response_pdu_new: (skip):
 **/
FuStructCrosEcFirstResponsePdu *
fu_struct_cros_ec_first_response_pdu_new(void)
{
    FuStructCrosEcFirstResponsePdu *st = fu_struct_cros_ec_first_response_pdu_new_internal();
    st->buf = g_byte_array_sized_new(60);
    fu_byte_array_set_size(st->buf, 60, 0x0);
    return st;
}
