/** * Determines the length of the MQTT subscribe packet that would be produced using the supplied parameters * @param count the number of topic filter strings in topicFilters * @param topicFilters the array of topic filter strings to be used in the publish * @return the length of buffer needed to contain the serialized version of the packet */ int MQTTSerialize_subscribeLength(int count, MQTTString topicFilters[]) { int i; int len = 2; /* packetid */ for (i = 0; i < count; ++i) len += 2 + MQTTstrlen(topicFilters[i]) + 1; /* length + topic + req_qos */ return len; }
/** * Determines the length of the MQTT publish packet that would be produced using the supplied parameters * @param qos the MQTT QoS of the publish (packetid is omitted for QoS 0) * @param topicName the topic name to be used in the publish * @param payloadlen the length of the payload to be sent * @return the length of buffer needed to contain the serialized version of the packet */ int MQTTSerialize_publishLength(int qos, MQTTString topicName, int payloadlen) { int len = 0; len += 2 + MQTTstrlen(topicName) + payloadlen; if (qos > 0) len += 8; /* packetid */ return len; }
/** * Determines the length of the MQTT unsubscribe packet that would be produced using the supplied parameters * @param count the number of topic filter strings in topicFilters * @param topicFilters the array of topic filter strings to be used in the publish * @return the length of buffer needed to contain the serialized version of the packet */ int ICACHE_FLASH_ATTR MQTTSerialize_unsubscribeLength(int count, MQTTString topicFilters[]) { int i; int len = 2; /* packetid */ for (i = 0; i < count; ++i) len += 2 + MQTTstrlen(topicFilters[i]); /* length + topic*/ return len; }
/** * Determines the length of the MQTT connect packet that would be produced using the supplied connect options. * @param options the options to be used to build the connect packet * @return the length of buffer needed to contain the serialized version of the packet */ int MQTTSerialize_connectLength(MQTTPacket_connectData* options) { int len = 0; FUNC_ENTRY; if (options->MQTTVersion == 3) len = 12; /* variable depending on MQTT or MQIsdp */ else if (options->MQTTVersion == 4) len = 10; len += MQTTstrlen(options->clientID)+2; if (options->willFlag) len += MQTTstrlen(options->will.topicName)+2 + MQTTstrlen(options->will.message)+2; if (options->username.cstring || options->username.lenstring.data) len += MQTTstrlen(options->username)+2; if (options->password.cstring || options->password.lenstring.data) len += MQTTstrlen(options->password)+2; FUNC_EXIT_RC(len); return len; }