<commit_before>/*************************************************************************
 * Copyright (c) 2014 eProsima. All rights reserved.
 *
 * This copy of eProsima RTPS is licensed to you under the terms described in the
 * EPROSIMARTPS_LIBRARY_LICENSE file included in this distribution.
 *
 *************************************************************************/

/**
 * DataSubMessage.hpp
 *
 */

using namespace eprosima::dds;

namespace eprosima{
namespace rtps{




bool RTPSMessageCreator::addMessageData(CDRMessage_t* msg,
		GuidPrefix_t& guidprefix,CacheChange_t* change,TopicKind_t topicKind,const EntityId_t& readerId,bool expectsInlineQos,ParameterList_t* inlineQos){


	try{

		RTPSMessageCreator::addHeader(msg,guidprefix);

		RTPSMessageCreator::addSubmessageInfoTS_Now(msg,false);

		RTPSMessageCreator::addSubmessageData(msg,change,topicKind,readerId,expectsInlineQos,inlineQos);

		msg->length = msg->pos;
	}
	catch(int e)
	{
		pError("Data message error"<<e<<endl)

		return false;
	}
	return true;
}



bool RTPSMessageCreator::addSubmessageData(CDRMessage_t* msg,CacheChange_t* change,
		TopicKind_t topicKind,const EntityId_t& readerId,bool expectsInlineQos,ParameterList_t* inlineQos) {

	CDRMessage_t& submsgElem = g_pool_submsg.reserve_Object();
	CDRMessage::initCDRMsg(&submsgElem);
	//Create the two CDR msgs
	//CDRMessage_t submsgElem;
	octet flags = 0x0;
	if(EPROSIMA_ENDIAN == LITTLEEND)
	{
		flags = flags | BIT(0);
		 submsgElem.msg_endian = LITTLEEND;
	}
	else
	{
		 submsgElem.msg_endian = BIGEND;
	}
	//Find out flags
	bool dataFlag = false;
	bool keyFlag = false;
	bool inlineQosFlag = false;
	if(change->kind == ALIVE && change->serializedPayload.length>0 && change->serializedPayload.data!=NULL)
	{
		dataFlag = true;
		keyFlag = false;
	}
	else
	{
		dataFlag = false;
		keyFlag = true;
	}
	 if(topicKind == NO_KEY)
		 keyFlag = false;
	 inlineQosFlag = false;
	if(inlineQos != NULL || expectsInlineQos) //expects inline qos
	{
		if(topicKind == WITH_KEY)
		{
			flags = flags | BIT(1);
			inlineQosFlag = true;
			keyFlag = false;
		}
	}
	if(dataFlag)
		flags = flags | BIT(2);
	if(keyFlag)
		flags = flags | BIT(3);

	octet status = 0;
	if(change->kind == NOT_ALIVE_DISPOSED)
		status = status | BIT(0);
	if(change->kind == NOT_ALIVE_UNREGISTERED)
		status = status | BIT(1);
	if(change->kind == NOT_ALIVE_DISPOSED_UNREGISTERED)
	{
		status = status | BIT(0);
		status = status | BIT(1);
	}

	CDRMessage::initCDRMsg(&submsgElem);
	try{
		//First we create the submsgElements:
		//extra flags. not in this version.<commit_msg>Modified so that the key is always send as inlineQos when deregistering<commit_after>/*************************************************************************
 * Copyright (c) 2014 eProsima. All rights reserved.
 *
 * This copy of eProsima RTPS is licensed to you under the terms described in the
 * EPROSIMARTPS_LIBRARY_LICENSE file included in this distribution.
 *
 *************************************************************************/

/**
 * DataSubMessage.hpp
 *
 */

using namespace eprosima::dds;

namespace eprosima{
namespace rtps{




bool RTPSMessageCreator::addMessageData(CDRMessage_t* msg,
		GuidPrefix_t& guidprefix,CacheChange_t* change,TopicKind_t topicKind,const EntityId_t& readerId,bool expectsInlineQos,ParameterList_t* inlineQos){


	try{

		RTPSMessageCreator::addHeader(msg,guidprefix);

		RTPSMessageCreator::addSubmessageInfoTS_Now(msg,false);

		RTPSMessageCreator::addSubmessageData(msg,change,topicKind,readerId,expectsInlineQos,inlineQos);

		msg->length = msg->pos;
	}
	catch(int e)
	{
		pError("Data message error"<<e<<endl)

		return false;
	}
	return true;
}



bool RTPSMessageCreator::addSubmessageData(CDRMessage_t* msg,CacheChange_t* change,
		TopicKind_t topicKind,const EntityId_t& readerId,bool expectsInlineQos,ParameterList_t* inlineQos) {

	CDRMessage_t& submsgElem = g_pool_submsg.reserve_Object();
	CDRMessage::initCDRMsg(&submsgElem);
	//Create the two CDR msgs
	//CDRMessage_t submsgElem;
	octet flags = 0x0;
	if(EPROSIMA_ENDIAN == LITTLEEND)
	{
		flags = flags | BIT(0);
		 submsgElem.msg_endian = LITTLEEND;
	}
	else
	{
		 submsgElem.msg_endian = BIGEND;
	}
	//Find out flags
	bool dataFlag = false;
	bool keyFlag = false;
	bool inlineQosFlag = false;
	if(change->kind == ALIVE && change->serializedPayload.length>0 && change->serializedPayload.data!=NULL)
	{
		dataFlag = true;
		keyFlag = false;
	}
	else
	{
		dataFlag = false;
		keyFlag = true;
	}
	 if(topicKind == NO_KEY)
		 keyFlag = false;
	 inlineQosFlag = false;
	if(inlineQos != NULL || expectsInlineQos || change->kind != ALIVE) //expects inline qos
	{
		if(topicKind == WITH_KEY)
		{
			flags = flags | BIT(1);
			inlineQosFlag = true;
			keyFlag = false;
		}
	}
	if(dataFlag)
		flags = flags | BIT(2);
	if(keyFlag)
		flags = flags | BIT(3);

	octet status = 0;
	if(change->kind == NOT_ALIVE_DISPOSED)
		status = status | BIT(0);
	if(change->kind == NOT_ALIVE_UNREGISTERED)
		status = status | BIT(1);
	if(change->kind == NOT_ALIVE_DISPOSED_UNREGISTERED)
	{
		status = status | BIT(0);
		status = status | BIT(1);
	}

	CDRMessage::initCDRMsg(&submsgElem);
	try{
		//First we create the submsgElements:
		//extra flags. not in this version.
{'fraction_non_alphanumeric': 0.1651060577106822, 'fraction_numerical': 0.006115039174469711, 'mean_word_length': 4.954493742889647, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2467510', 'n_tokens_mistral': 1976, 'n_tokens_neox': 1825, 'n_words': 382}