当前位置: 首页>>代码示例>>C++>>正文


C++ RemainingLength类代码示例

本文整理汇总了C++中RemainingLength的典型用法代码示例。如果您正苦于以下问题:C++ RemainingLength类的具体用法?C++ RemainingLength怎么用?C++ RemainingLength使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了RemainingLength类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: deserialize

bool MQTTPublish::deserialize(uint8_t* buf){
	uint8_t pos = 2;

	_type = *buf & 0xf0;
	if(_type != MQTT_TYPE_PUBLISH){
		return false;
	}
	RemainingLength remLen;

	_flags = *buf & 0x0f;
	remLen.deserialize(buf + 1);
	_remainLength = remLen.decode();

	buf += 1 + remLen.getSize();
	_topic = string((char*)buf + 2, getUint16(buf));

	buf += _topic.size() + 2;
	if(getQos()){
		_messageId = getUint16(buf);
		buf += 2;
		pos += 2;
	}
	_len = _remainLength - _topic.size() - pos;
	_payload = mqcalloc(_len);
	memcpy(_payload, buf, _len);
	return true;
}
开发者ID:jpfy,项目名称:MQTT-SN,代码行数:27,代码来源:Messages.cpp

示例2: deserialize

bool MQTTMessage::deserialize(uint8_t* buf){
	RemainingLength remLen;

	_type = *buf & 0xf0;
	_flags = *buf & 0x0f;
	remLen.deserialize(buf + 1);
	_remainLength = remLen.decode();

	switch(_type){
		case MQTT_TYPE_PINGRESP:
			return true;
			break;
		case MQTT_TYPE_UNSUBACK:
		case MQTT_TYPE_PUBACK:
			_messageId = getUint16(buf + 2);
			break;
		default:
			return false;
	}
	return true;
}
开发者ID:cxcco,项目名称:MQTT-S-Gateway,代码行数:21,代码来源:Messages.cpp

示例3: serialize

uint16_t MQTTConnect::serialize(uint8_t* buf){
	uint16_t len;
	string protocol;
	if(_protocol == MQTT_PROTOCOL_VER4){
		protocol = MQTT_PROTOCOL_NAME4;
		len = 10;
	}else{
		protocol = MQTT_PROTOCOL_NAME3;
		len = 12;
	}

	len += _clientId.size() + 2;

	if(_connectFlags & 0x0c){  // Will Topic & Message
		len += _willTopic.size() + 2;
		len += _willMessage.size() + 2;
	}
	if(_connectFlags & 0x80){  // User Name
		len += _userName.size() + 2;
	}
	if(_connectFlags & 0x40){  // Password
		len += _password.size() + 2;
	}
	RemainingLength remLen;
	remLen.encode(len);
	_remainLength = len;

	*buf++ = _type | _flags;
	remLen.serialize(buf);
	buf += remLen.getSize();

	utfSerialize(buf, protocol);
	buf += protocol.size() + 2;
	*buf++ = _protocol;
	*buf++ = _connectFlags;
	setUint16(buf++, _keepAliveTime);

	utfSerialize(++buf,_clientId); // copy clienId
	buf += _clientId.size() + 2;

	if(_connectFlags & 0x0c){  // Will Topic & Message
		utfSerialize(buf,_willTopic);
		buf += _willTopic.size() + 2;
		utfSerialize(buf,_willMessage);
		buf += _willMessage.size() + 2;
	}
	if(_connectFlags & 0x80){  // User Name
		utfSerialize(buf,_userName);
		buf += _userName.size() + 2;
	}
	if(_connectFlags & 0x40){  // Password
		utfSerialize(buf,_password);
	}

	return 1 + remLen.getSize() + remLen.decode();

}
开发者ID:jpfy,项目名称:MQTT-SN,代码行数:57,代码来源:Messages.cpp

示例4: serialize

uint16_t MQTTPublish::serialize(uint8_t* buf){
	RemainingLength remLen;
	_remainLength = _topic.size() + 2 + 2 + _len; // topic,MessageID,Payload
	remLen.encode(_remainLength);

	*buf++ = (_type & 0xf0) | (_flags & 0x0f);
	remLen.serialize(buf);
	buf += remLen.getSize();
	utfSerialize(buf, _topic);
	buf += _topic.size() + 2;
	setUint16(buf, _messageId);
	memcpy(buf + 2, _payload, _len);

	return 1 + remLen.getSize() + remLen.decode();
}
开发者ID:cxcco,项目名称:MQTT-S-Gateway,代码行数:15,代码来源:Messages.cpp

示例5: getRemainLengthSize

uint8_t MQTTMessage::getRemainLengthSize(){
	RemainingLength remLen;
	remLen.encode(_remainLength);
	return remLen.getSize();
}
开发者ID:jpfy,项目名称:MQTT-SN,代码行数:5,代码来源:Messages.cpp


注:本文中的RemainingLength类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。