Exemple #1
0
char * NSQueryResult::encode(int seq, int &sz)
{
	char *p = m_buf;

	p = setHeader(p, seq);

	unsigned short found = m_service? 1: 0;
	BINARY_SET_DATA_S_INCR(p, unsigned short, found);
	if (found) {

		const char *n = m_service->name();
		BINARY_SET_STRING_INCR(p, n);
		
		unsigned short k = m_service->kind();
		BINARY_SET_DATA_S_INCR(p, unsigned short, k);

		const char *h = m_service->hostname();
		BINARY_SET_STRING_INCR(p, h);

		int port = m_service->port();
		BINARY_SET_DATA_L_INCR(p, int, port);
	}

	p = setFooter(p);

	sz = p - m_buf;
	setPacketSize(m_buf, sz);
	return m_buf;
}
Exemple #2
0
char *GetAttributesRequest::encode(int seq, int &sz)
{
	int n;
	char *p = m_buf;
	{
		char *h = getHeader(seq, n);
		memcpy(p, h, n);
		p += n;
	}
	unsigned short attrNum = m_attrNames.size();
	BINARY_SET_DATA_S_INCR(p, unsigned short, attrNum);
	
	for (C::iterator i=m_attrNames.begin(); i!=m_attrNames.end(); i++) {
		const char *str = i->c_str();
		BINARY_SET_STRING_INCR(p, str);
	}
	{
		char *f = getFooter(n);
		memcpy(p, f, n);
		p += n;
	}

	sz = p - m_buf;
	setPacketSize(m_buf, sz);
	
	return m_buf;
}
Exemple #3
0
char *AddForceToPartsRequest::encode(int seq, int &sz)
{
	char *p = m_buf;
  
	p = setHeader(p, seq);
	BINARY_SET_STRING_INCR(p, m_name);
	BINARY_SET_STRING_INCR(p, m_parts);

	BINARY_SET_DOUBLE_INCR(p, m_x);
	BINARY_SET_DOUBLE_INCR(p, m_y);
	BINARY_SET_DOUBLE_INCR(p, m_z);
  
	p = setFooter(p);
  
	sz = p - m_buf;
	setPacketSize(m_buf, sz);
	return m_buf;
}
Exemple #4
0
char *GetGravityModeRequest::encode(int seq, int &sz)
{
	char *p = m_buf;
  
	p = setHeader(p, seq);
	BINARY_SET_STRING_INCR(p, m_name);

	p = setFooter(p);
  
	sz = p - m_buf;
	setPacketSize(m_buf, sz);
	return m_buf;
}
Exemple #5
0
char *SetDynamicsModeRequest::encode(int seq, int &sz)
{
	char *p = m_buf;
  
	p = setHeader(p, seq);
	BINARY_SET_STRING_INCR(p, m_name);
	BINARY_SET_BOOL_INCR(p, m_dynamics);

	p = setFooter(p);
  
	sz = p - m_buf;
	setPacketSize(m_buf, sz);
	return m_buf;
}
Exemple #6
0
char *GetAngularVelocityRequest::encode(int seq, int &sz)
{
	char *p = m_buf;
  
	p = setHeader(p, seq);
	{
		BINARY_SET_STRING_INCR(p, m_name);
	}
  
	p = setFooter(p);
  
	sz = p - m_buf;
	setPacketSize(m_buf, sz);
	return m_buf;
}
char *	InvokeOnRecvSound::getDataHeader(int &sz)
{
	char *p = m_dataHeaderBuf;
	BINARY_SET_DOUBLE_INCR(p, m_time);
	BINARY_SET_STRING_INCR(p, m_caller.c_str());
	RawSoundHeader & h = m_sound.getHeader();
	BINARY_SET_DATA_S_INCR(p, short, h.getChannelNum());
	BINARY_SET_DATA_S_INCR(p, unsigned short, h.getSamplingRate());
	BINARY_SET_DATA_S_INCR(p, unsigned short, h.getBitPerSample());
	BINARY_SET_DATA_S_INCR(p, RawSoundEndian, h.getEndian());
	BINARY_SET_DATA_L_INCR(p, unsigned, getDataLen());

	sz = p - m_dataHeaderBuf;
	assert(sz < DATA_HEADER_BUFSIZE);
	return m_dataHeaderBuf;
}
Exemple #8
0
char *MoveCommand::toBinary(int &n)
{
	static char buf[1024];

	char *p = buf;

	BINARY_SET_DATA_S_INCR(p, CommandType, m_type);
	BINARY_SET_STRING_INCR(p, target());
	BINARY_SET_DOUBLE_INCR(p, m_dest.x());
	BINARY_SET_DOUBLE_INCR(p, m_dest.y());
	BINARY_SET_DOUBLE_INCR(p, m_dest.z());
	BINARY_SET_DOUBLE_INCR(p, m_vel);
	
	n = p - buf;
	return buf;
}
Exemple #9
0
char *SetMassRequest::encode(int seq, int &sz)
{
	char *p = m_buf;
  
	p = setHeader(p, seq);
	{
		BINARY_SET_STRING_INCR(p, m_name);
	}
	BINARY_SET_DOUBLE_INCR(p, m_mass);
  
	p = setFooter(p);
  
	sz = p - m_buf;
	setPacketSize(m_buf, sz);
	return m_buf;
}
Exemple #10
0
char *GetLinearVelocityResult::encode(int seq, int &sz)
{
	char *p = m_buf;
  
	p = setHeader(p, seq);
	BINARY_SET_STRING_INCR(p, m_name);
	BINARY_SET_DOUBLE_INCR(p, m_x);
	BINARY_SET_DOUBLE_INCR(p, m_y);
	BINARY_SET_DOUBLE_INCR(p, m_z);

	p = setFooter(p);
  
	sz = p - m_buf;
	setPacketSize(m_buf, sz);
	return m_buf;
}
Exemple #11
0
char *CommDataEncoder::getHeader(int seq, int &n)
{
	static char buf[COMM_DATA_HEADER_MAX_SIZE];
	char *p = buf;
	BINARY_SET_DATA_S_INCR(p, unsigned short, COMM_DATA_PACKET_START_TOKEN);
	BINARY_SET_DATA_S_INCR(p, unsigned short, 0); // packet size
	BINARY_SET_DATA_S_INCR(p, unsigned short, m_type);
	BINARY_SET_DATA_S_INCR(p, unsigned short, packetNum());
	BINARY_SET_DATA_S_INCR(p, unsigned short, seq);
	BINARY_SET_DATA_S_INCR(p, unsigned short, m_forwardFlags);
	BINARY_SET_STRING_INCR(p, m_forwardTo.c_str());
	BINARY_SET_DOUBLE_INCR(p, m_forwardReachRadius);
		
	n = p - buf;
	return buf;
}
Exemple #12
0
char *AddTorqueRequest::encode(int seq, int &sz)
{
	char *p = m_buf;
  
	p = setHeader(p, seq);
	{
		BINARY_SET_STRING_INCR(p, m_name);
	}
	BINARY_SET_DOUBLE_INCR(p, m_x);
	BINARY_SET_DOUBLE_INCR(p, m_y);
	BINARY_SET_DOUBLE_INCR(p, m_z);
	BINARY_SET_BOOL_INCR(p, m_relf);
  
	p = setFooter(p);
  
	sz = p - m_buf;
	setPacketSize(m_buf, sz);
	return m_buf;
}
Exemple #13
0
char *DisplayText::encode(int seq, int &sz)
{
	int n;
	char *p = m_buf;
	{
		char *h = getHeader(seq, n);
		memcpy(p, h, n);
		p += n;
	}
	{
		BINARY_SET_DATA_S_INCR(p, short, m_fs);
		BINARY_SET_DATA_S_INCR(p, short, m_color);
		BINARY_SET_STRING_INCR(p, m_msg.c_str());
	}
	{
		char *f = getFooter(n);
		memcpy(p, f, n);
		p += n;
	}
	sz = p - m_buf;
	setPacketSize(m_buf, sz);
	return m_buf;

}
Exemple #14
0
/**
 * @brief  Binalize of the entity
 * @param  Size of binalized data
 * @return Binalized data
 */
char *SimObjBase::toBinary(int &n)
{
	const int RESIZE = 1000;
	static int bufsize = RESIZE;
	static char *buf = new char[bufsize];

	char *p = buf;
	p += sizeof(DataLengthType); // skip datalen

	BINARY_SET_DATA_L_INCR(p, Id, id());
	BINARY_SET_STRING_INCR(p, name());
	BINARY_SET_STRING_INCR(p, classname());
	short attached = isAttached();
	BINARY_SET_DATA_S_INCR(p, short, attached);
	BINARY_SET_DATA_L_INCR(p, Operation, m_ops);

	DataOffsetType	ao_offset = p - buf;
	BINARY_SET_DATA_S_INCR(p, DataOffsetType, 0); // skip attr offset

	DataOffsetType	bo_offset = p - buf;
	BINARY_SET_DATA_S_INCR(p, DataOffsetType, 0); // skip body offset

	// attrs
	{
		DataOffsetType 	attrs_offset = p - buf;
		BINARY_SET_DATA_S(buf + ao_offset, DataOffsetType, attrs_offset);

		BINARY_SET_DATA_S_INCR(p, DataLengthType, 0); // skip attrs size

		DataLengthType attrssize = sizeof(DataLengthType);
		for (AttrM::iterator i=m_attrs.begin(); i!=m_attrs.end(); i++) {
			int head = p - buf;
			Attribute *attr = i->second;
			int nn;
			char *pp = attr->toBinary(nn);
			if (head + nn >= bufsize) {
				int newsize = bufsize + RESIZE;
				char *newbuf = new char[newsize];
				memcpy(newbuf, buf, head);
				delete buf;
				buf = newbuf;
				bufsize = newsize;
				p = buf + head;
			}
			memcpy(p, pp, nn);
			p += nn;
			attrssize += nn;
		}
		BINARY_SET_DATA_S(buf + attrs_offset, DataLengthType, attrssize);
	}


	// set body offset value
	{
		DataOffsetType body_offset = p - buf;
		BINARY_SET_DATA_S(buf + bo_offset, DataOffsetType, body_offset);

		// body

		BINARY_SET_DATA_S_INCR(p, DataLengthType, 0); // skip body size
		DataLengthType bodysize = sizeof(DataLengthType);
		//for (PartsM::iterator i=m_parts.begin(); i!=m_parts.end(); i++) {

		PartsIterator *itr = getPartsIterator();
		Parts *parts = NULL;
		while (itr && (parts = itr->next()) != NULL) {

			if (parts->isBlind()) { continue; }
			
			int head = p - buf;
			//Parts *parts = i->second;

// added by sekikawa (2007/12/4)
#ifdef TAKU_TEST
			parts->calcAbsPos(this);
#endif

			int nn;
			char *pp = parts->toBinary(nn);
			if (head + nn >= bufsize) {
				int newsize = bufsize + RESIZE;
				char *newbuf = new char[newsize];
				memcpy(newbuf, buf, head);
				delete buf;
				buf = newbuf;
				bufsize = newsize;
				p = buf + head;
			}
			memcpy(p, pp, nn);
			p += nn;
			bodysize += nn;
		}
		BINARY_SET_DATA_S(buf + body_offset, DataLengthType, bodysize);
		delete itr;
	}

	n = p-buf;
	// set datalen value
	BINARY_SET_DATA_S(buf, DataLengthType, n);

	return buf;
}