/* THIS FILE IS GENERATED FROM gtlv_gen.c */
#include <stddef.h>
#include <errno.h>
#include <osmocom/core/utils.h>
#include <osmocom/gtlv/gtlv.h>
#include <osmocom/gtlv/gtlv_dec_enc.h>
#include <osmocom/gtlv/gtlv_gen.h>

#include <myproto_ies_auto.h>

extern int myproto_dec_bar(void *decoded_struct, void *decode_to, const struct osmo_gtlv_load *gtlv);
extern int myproto_enc_bar(struct osmo_gtlv_put *gtlv, const void *decoded_struct, const void *encode_from);
extern int myproto_enc_to_str_bar(char *buf, size_t buflen, const void *encode_from);

static const struct osmo_gtlv_coding ies_in_msg_moo[] = {
	{ { MYPROTO_IEI_BAR, true, MYPROTO_IEI_BAR_ALPHA },
	  .memb_ofs = offsetof(union myproto_ies, moo.bar_alpha),
	  .dec_func = myproto_dec_bar,
	  .enc_func = myproto_enc_bar,
	  .enc_to_str_func = myproto_enc_to_str_bar,
	},
	{ { MYPROTO_IEI_BAR, true, MYPROTO_IEI_BAR_BETA },
	  .memb_ofs = offsetof(union myproto_ies, moo.bar_beta),
	  .dec_func = myproto_dec_bar,
	  .enc_func = myproto_enc_bar,
	  .enc_to_str_func = myproto_enc_to_str_bar,
	  .has_presence_flag = true,
	  .presence_flag_ofs = offsetof(union myproto_ies, moo.bar_beta_present),
	},
	{ { MYPROTO_IEI_BAR, true, MYPROTO_IEI_BAR_GAMMA },
	  .memb_ofs = offsetof(union myproto_ies, moo.bar_gamma),
	  .dec_func = myproto_dec_bar,
	  .enc_func = myproto_enc_bar,
	  .enc_to_str_func = myproto_enc_to_str_bar,
	},
	{}
};

static const struct osmo_gtlv_coding *msg_defs[] = {
	[MYPROTO_MSGT_MOO] = ies_in_msg_moo,
};

const struct osmo_gtlv_coding *myproto_get_msg_coding(enum myproto_msg_type message_type)
{
	if (message_type >= ARRAY_SIZE(msg_defs))
		return NULL;
	return msg_defs[message_type];
}

int myproto_ies_decode(union myproto_ies *dst, struct osmo_gtlv_load *gtlv, bool tlv_ordered,
	enum myproto_msg_type message_type,
	osmo_gtlv_err_cb err_cb, void *err_cb_data, const struct value_string *iei_strs)
{
	return osmo_gtlvs_decode(dst, sizeof(*dst), 0, gtlv, tlv_ordered, myproto_get_msg_coding(message_type),
		err_cb, err_cb_data, iei_strs);
}

int myproto_ies_encode(struct osmo_gtlv_put *gtlv, const union myproto_ies *src,
	enum myproto_msg_type message_type, osmo_gtlv_err_cb err_cb, void *err_cb_data, const struct value_string *iei_strs)
{
	return osmo_gtlvs_encode(gtlv, src, sizeof(*src), 0, myproto_get_msg_coding(message_type),
		err_cb, err_cb_data, iei_strs);
}

int myproto_ies_encode_to_str(char *buf, size_t buflen, const union myproto_ies *src,
	enum myproto_msg_type message_type, const struct value_string *iei_strs)
{
	return osmo_gtlvs_encode_to_str_buf(buf, buflen, src, sizeof(*src), 0, myproto_get_msg_coding(message_type), iei_strs);
}
