本文整理汇总了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;
}
示例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;
}
示例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();
}
示例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();
}
示例5: getRemainLengthSize
uint8_t MQTTMessage::getRemainLengthSize(){
RemainingLength remLen;
remLen.encode(_remainLength);
return remLen.getSize();
}