/* Deserializes the supplied (wire) buffer into connack data - return code  */
int mqtt_deserialize_connack(unsigned char *sessionPresent, unsigned char *connack_rc, unsigned char *buf, int buflen)
/* Deserializes the supplied (wire) buffer into connack data - return code  */
int mqtt_deserialize_connack(unsigned char *sessionPresent, unsigned char *connack_rc, unsigned char *buf, int buflen)
{
	mqtt_header_t header = {0};
	unsigned char* curdata = buf;
	unsigned char* enddata = NULL;
	int rc = 0;
	int mylen;
	mqtt_conn_ack_flags_t flags = {0};
	FUNC_ENTRY;
	header.byte = mqtt_read_char(&curdata);
	if (header.bits.type != MQTTPACKET_CONNACK)
		goto exit;
	curdata += (rc = mqtt_packet_decode_buf(curdata, &mylen));
	enddata = curdata + mylen;
	if (enddata - curdata < 2)
		goto exit;
	flags.all = mqtt_read_char(&curdata);
	*sessionPresent = flags.bits.sessionpresent;
	*connack_rc = mqtt_read_char(&curdata);
	rc = 1;
exit:
	FUNC_EXIT_RC(rc);
	return rc;
}