1
0
mirror of https://github.com/FreeRTOS/coreMQTT synced 2025-05-12 13:24:58 +08:00
coreMQTT/latest/mqtt_serializeconnect_function.html

165 lines
14 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.6"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>coreMQTT: MQTT_SerializeConnect</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(document).ready(function() { init_search(); });
/* @license-end */
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="style.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr id="projectrow">
<td id="projectalign">
<div id="projectname">coreMQTT<span id="projectnumber">&#160;v2.3.1</span>
</div>
<div id="projectbrief">MQTT 3.1.1 Client Library</div>
</td>
<td> <div id="MSearchBox" class="MSearchBoxInactive">
<span class="left">
<span id="MSearchSelect" onmouseover="return searchBox.OnSearchSelectShow()" onmouseout="return searchBox.OnSearchSelectHide()">&#160;</span>
<input type="text" id="MSearchField" value="" placeholder="Search" accesskey="S"
onfocus="searchBox.OnSearchFieldFocus(true)"
onblur="searchBox.OnSearchFieldFocus(false)"
onkeyup="searchBox.OnSearchFieldChange(event)"/>
</span><span class="right">
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.svg" alt=""/></a>
</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.6 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search/",'.html');
/* @license-end */
</script>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(document).ready(function(){initNavTree('mqtt_serializeconnect_function.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>
<div><div class="header">
<div class="headertitle"><div class="title">MQTT_SerializeConnect </div></div>
</div><!--header-->
<div class="contents">
<div class="textblock"><div class="fragment"><div class="line"><a class="code hl_enumeration" href="group__mqtt__enum__types.html#gaba7ec045874a1c3432f99173367f735c">MQTTStatus_t</a> <a class="code hl_function" href="core__mqtt__serializer_8h.html#aa2e2300d6c43e61f8f2cf83f7149835c">MQTT_SerializeConnect</a>( <span class="keyword">const</span> <a class="code hl_struct" href="struct_m_q_t_t_connect_info__t.html">MQTTConnectInfo_t</a> * pConnectInfo,</div>
<div class="line"> <span class="keyword">const</span> <a class="code hl_struct" href="struct_m_q_t_t_publish_info__t.html">MQTTPublishInfo_t</a> * pWillInfo,</div>
<div class="line"> <span class="keywordtype">size_t</span> remainingLength,</div>
<div class="line"> <span class="keyword">const</span> <a class="code hl_struct" href="struct_m_q_t_t_fixed_buffer__t.html">MQTTFixedBuffer_t</a> * pFixedBuffer );</div>
<div class="ttc" id="acore__mqtt__serializer_8h_html_aa2e2300d6c43e61f8f2cf83f7149835c"><div class="ttname"><a href="core__mqtt__serializer_8h.html#aa2e2300d6c43e61f8f2cf83f7149835c">MQTT_SerializeConnect</a></div><div class="ttdeci">MQTTStatus_t MQTT_SerializeConnect(const MQTTConnectInfo_t *pConnectInfo, const MQTTPublishInfo_t *pWillInfo, size_t remainingLength, const MQTTFixedBuffer_t *pFixedBuffer)</div><div class="ttdoc">Serialize an MQTT CONNECT packet in the given fixed buffer pFixedBuffer.</div><div class="ttdef"><b>Definition:</b> core_mqtt_serializer.c:1790</div></div>
<div class="ttc" id="agroup__mqtt__enum__types_html_gaba7ec045874a1c3432f99173367f735c"><div class="ttname"><a href="group__mqtt__enum__types.html#gaba7ec045874a1c3432f99173367f735c">MQTTStatus_t</a></div><div class="ttdeci">MQTTStatus_t</div><div class="ttdoc">Return codes from MQTT functions.</div><div class="ttdef"><b>Definition:</b> core_mqtt_serializer.h:87</div></div>
<div class="ttc" id="astruct_m_q_t_t_connect_info__t_html"><div class="ttname"><a href="struct_m_q_t_t_connect_info__t.html">MQTTConnectInfo_t</a></div><div class="ttdoc">MQTT CONNECT packet parameters.</div><div class="ttdef"><b>Definition:</b> core_mqtt_serializer.h:133</div></div>
<div class="ttc" id="astruct_m_q_t_t_fixed_buffer__t_html"><div class="ttname"><a href="struct_m_q_t_t_fixed_buffer__t.html">MQTTFixedBuffer_t</a></div><div class="ttdoc">Buffer passed to MQTT library.</div><div class="ttdef"><b>Definition:</b> core_mqtt_serializer.h:123</div></div>
<div class="ttc" id="astruct_m_q_t_t_publish_info__t_html"><div class="ttname"><a href="struct_m_q_t_t_publish_info__t.html">MQTTPublishInfo_t</a></div><div class="ttdoc">MQTT PUBLISH packet parameters.</div><div class="ttdef"><b>Definition:</b> core_mqtt_serializer.h:202</div></div>
</div><!-- fragment --><p>Serialize an MQTT CONNECT packet in the given fixed buffer <code>pFixedBuffer</code>. </p>
<p><a class="el" href="core__mqtt__serializer_8h.html#a4e57ccef527a25b572dc66eeb2e217c5" title="Get the size and Remaining Length of an MQTT CONNECT packet.">MQTT_GetConnectPacketSize</a> should be called with <code>pConnectInfo</code> and <code>pWillInfo</code> before invoking this function to get the size of the required <a class="el" href="struct_m_q_t_t_fixed_buffer__t.html" title="Buffer passed to MQTT library.">MQTTFixedBuffer_t</a> and <code>remainingLength</code>. The <code>remainingLength</code> must be the same as returned by <a class="el" href="core__mqtt__serializer_8h.html#a4e57ccef527a25b572dc66eeb2e217c5" title="Get the size and Remaining Length of an MQTT CONNECT packet.">MQTT_GetConnectPacketSize</a>. The <a class="el" href="struct_m_q_t_t_fixed_buffer__t.html" title="Buffer passed to MQTT library.">MQTTFixedBuffer_t</a> must be at least as large as the size returned by <a class="el" href="core__mqtt__serializer_8h.html#a4e57ccef527a25b572dc66eeb2e217c5" title="Get the size and Remaining Length of an MQTT CONNECT packet.">MQTT_GetConnectPacketSize</a>.</p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramdir">[in]</td><td class="paramname">pConnectInfo</td><td>MQTT CONNECT packet parameters. </td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">pWillInfo</td><td>Last Will and Testament. Pass NULL if not used. </td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">remainingLength</td><td>Remaining Length provided by <a class="el" href="core__mqtt__serializer_8h.html#a4e57ccef527a25b572dc66eeb2e217c5" title="Get the size and Remaining Length of an MQTT CONNECT packet.">MQTT_GetConnectPacketSize</a>. </td></tr>
<tr><td class="paramdir">[out]</td><td class="paramname">pFixedBuffer</td><td>Buffer for packet serialization.</td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd><a class="el" href="group__mqtt__enum__types.html#ggaba7ec045874a1c3432f99173367f735cab1be4db832a0468f024243bca151a8df">MQTTNoMemory</a> if pFixedBuffer is too small to hold the MQTT packet; <a class="el" href="group__mqtt__enum__types.html#ggaba7ec045874a1c3432f99173367f735caa39030c93b0263b2699502a074f003b5">MQTTBadParameter</a> if invalid parameters are passed; <a class="el" href="group__mqtt__enum__types.html#ggaba7ec045874a1c3432f99173367f735ca484e062cb4f3fccc1858dd25cfeee056">MQTTSuccess</a> otherwise.</dd></dl>
<p><b>Example</b> </p><div class="fragment"><div class="line"><span class="comment">// Variables used in this example.</span></div>
<div class="line"><a class="code hl_enumeration" href="group__mqtt__enum__types.html#gaba7ec045874a1c3432f99173367f735c">MQTTStatus_t</a> status;</div>
<div class="line"><a class="code hl_struct" href="struct_m_q_t_t_connect_info__t.html">MQTTConnectInfo_t</a> connectInfo = { 0 };</div>
<div class="line"><a class="code hl_struct" href="struct_m_q_t_t_publish_info__t.html">MQTTPublishInfo_t</a> willInfo = { 0 };</div>
<div class="line"><a class="code hl_struct" href="struct_m_q_t_t_fixed_buffer__t.html">MQTTFixedBuffer_t</a> fixedBuffer;</div>
<div class="line">uint8_t buffer[ BUFFER_SIZE ];</div>
<div class="line"><span class="keywordtype">size_t</span> remainingLength = 0, packetSize = 0;</div>
<div class="line"> </div>
<div class="line">fixedBuffer.<a class="code hl_variable" href="struct_m_q_t_t_fixed_buffer__t.html#acea147448e044870fb36b7fa2347dbd6">pBuffer</a> = buffer;</div>
<div class="line">fixedBuffer.<a class="code hl_variable" href="struct_m_q_t_t_fixed_buffer__t.html#a0b0b6a93cc62751ebeb03095d5431636">size</a> = BUFFER_SIZE;</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Assume connectInfo and willInfo are initialized. Get the size requirement for</span></div>
<div class="line"><span class="comment">// the connect packet.</span></div>
<div class="line">status = <a class="code hl_function" href="core__mqtt__serializer_8h.html#a4e57ccef527a25b572dc66eeb2e217c5">MQTT_GetConnectPacketSize</a>(</div>
<div class="line"> &amp;connectInfo, &amp;willInfo, &amp;remainingLength, &amp;packetSize</div>
<div class="line">);</div>
<div class="line">assert( status == <a class="code hl_enumvalue" href="group__mqtt__enum__types.html#ggaba7ec045874a1c3432f99173367f735ca484e062cb4f3fccc1858dd25cfeee056">MQTTSuccess</a> );</div>
<div class="line">assert( packetSize &lt;= BUFFER_SIZE );</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Serialize the connect packet into the fixed buffer.</span></div>
<div class="line">status = <a class="code hl_function" href="core__mqtt__serializer_8h.html#aa2e2300d6c43e61f8f2cf83f7149835c">MQTT_SerializeConnect</a>( &amp;connectInfo, &amp;willInfo, remainingLength, &amp;fixedBuffer );</div>
<div class="line"> </div>
<div class="line"><span class="keywordflow">if</span>( status == <a class="code hl_enumvalue" href="group__mqtt__enum__types.html#ggaba7ec045874a1c3432f99173367f735ca484e062cb4f3fccc1858dd25cfeee056">MQTTSuccess</a> )</div>
<div class="line">{</div>
<div class="line"> <span class="comment">// The connect packet can now be sent to the broker.</span></div>
<div class="line">}</div>
<div class="ttc" id="acore__mqtt__serializer_8h_html_a4e57ccef527a25b572dc66eeb2e217c5"><div class="ttname"><a href="core__mqtt__serializer_8h.html#a4e57ccef527a25b572dc66eeb2e217c5">MQTT_GetConnectPacketSize</a></div><div class="ttdeci">MQTTStatus_t MQTT_GetConnectPacketSize(const MQTTConnectInfo_t *pConnectInfo, const MQTTPublishInfo_t *pWillInfo, size_t *pRemainingLength, size_t *pPacketSize)</div><div class="ttdoc">Get the size and Remaining Length of an MQTT CONNECT packet.</div><div class="ttdef"><b>Definition:</b> core_mqtt_serializer.c:1690</div></div>
<div class="ttc" id="agroup__mqtt__enum__types_html_ggaba7ec045874a1c3432f99173367f735ca484e062cb4f3fccc1858dd25cfeee056"><div class="ttname"><a href="group__mqtt__enum__types.html#ggaba7ec045874a1c3432f99173367f735ca484e062cb4f3fccc1858dd25cfeee056">MQTTSuccess</a></div><div class="ttdeci">@ MQTTSuccess</div><div class="ttdef"><b>Definition:</b> core_mqtt_serializer.h:88</div></div>
<div class="ttc" id="astruct_m_q_t_t_fixed_buffer__t_html_a0b0b6a93cc62751ebeb03095d5431636"><div class="ttname"><a href="struct_m_q_t_t_fixed_buffer__t.html#a0b0b6a93cc62751ebeb03095d5431636">MQTTFixedBuffer_t::size</a></div><div class="ttdeci">size_t size</div><div class="ttdoc">Size of buffer.</div><div class="ttdef"><b>Definition:</b> core_mqtt_serializer.h:125</div></div>
<div class="ttc" id="astruct_m_q_t_t_fixed_buffer__t_html_acea147448e044870fb36b7fa2347dbd6"><div class="ttname"><a href="struct_m_q_t_t_fixed_buffer__t.html#acea147448e044870fb36b7fa2347dbd6">MQTTFixedBuffer_t::pBuffer</a></div><div class="ttdeci">uint8_t * pBuffer</div><div class="ttdoc">Pointer to buffer.</div><div class="ttdef"><b>Definition:</b> core_mqtt_serializer.h:124</div></div>
</div><!-- fragment --> </div></div><!-- contents -->
</div><!-- PageDoc -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.6 </li>
</ul>
</div>
</body>
</html>