Lines Matching +full:header +full:- +full:payload

4  * SPDX-License-Identifier: Apache-2.0
44 * @retval -ENOMEM if there is no place in the buffer to store the value.
48 uint8_t *cur = buf->cur; in pack_uint8()
49 uint8_t *end = buf->end; in pack_uint8()
51 if ((end - cur) < sizeof(uint8_t)) { in pack_uint8()
52 return -ENOMEM; in pack_uint8()
59 buf->cur = (cur + sizeof(uint8_t)); in pack_uint8()
72 * @retval -ENOMEM if there is no place in the buffer to store the value.
76 uint8_t *cur = buf->cur; in pack_uint16()
77 uint8_t *end = buf->end; in pack_uint16()
79 if ((end - cur) < sizeof(uint16_t)) { in pack_uint16()
80 return -ENOMEM; in pack_uint16()
87 buf->cur = (cur + sizeof(uint16_t)); in pack_uint16()
95 * @param[in] str UTF-8 string and its length to be packed.
100 * @retval -ENOMEM if there is no place in the buffer to store the string.
104 if ((buf->end - buf->cur) < GET_UT8STR_BUFFER_SIZE(str)) { in pack_utf8_str()
105 return -ENOMEM; in pack_utf8_str()
109 (uint32_t)GET_UT8STR_BUFFER_SIZE(str), (void *)buf->cur, (void *)buf->end); in pack_utf8_str()
112 (void)pack_uint16(str->size, buf); in pack_utf8_str()
114 memcpy(buf->cur, str->utf8, str->size); in pack_utf8_str()
115 buf->cur += str->size; in pack_utf8_str()
121 * @brief Computes and encodes length for the MQTT fixed header.
138 * @param[in] length Length of variable header and payload in the MQTT message.
150 (buf == NULL) ? 0 : (void *)buf->cur, (buf == NULL) ? 0 : (void *)buf->end); in packet_length_encode()
156 *(buf->cur) = length & MQTT_LENGTH_VALUE_MASK; in packet_length_encode()
163 *(buf->cur) |= MQTT_LENGTH_CONTINUATION_BIT; in packet_length_encode()
165 buf->cur++; in packet_length_encode()
173 * @brief Encodes fixed header for the MQTT message and provides pointer to
174 * start of the header.
179 * @param[in] start Pointer to the start of the variable header.
182 * by the routine to be available to pack the fixed header.
183 * However, since the fixed header length is variable
185 * along with encoded fixed header is supplied as output
191 * @retval -EMSGSIZE if the message is too big for MQTT.
196 uint32_t length = buf->cur - start; in mqtt_encode_fixed_header()
200 return -EMSGSIZE; in mqtt_encode_fixed_header()
208 NET_DBG("Fixed header length = %02x", fixed_header_length); in mqtt_encode_fixed_header()
211 buf->cur = start - fixed_header_length; in mqtt_encode_fixed_header()
219 buf->cur = buf->cur - fixed_header_length; in mqtt_encode_fixed_header()
220 buf->end = buf->cur + length + fixed_header_length; in mqtt_encode_fixed_header()
234 * @retval -ENOMEM if there is no place in the buffer to store the binary
244 * the variable header.
247 * @param[in] message_id Message id to be encoded in the variable header.
261 return -EINVAL; in mqtt_message_id_only_enc()
264 /* Reserve space for fixed header. */ in mqtt_message_id_only_enc()
265 buf->cur += MQTT_FIXED_HEADER_MAX_SIZE; in mqtt_message_id_only_enc()
266 start = buf->cur; in mqtt_message_id_only_enc()
279 uint8_t connect_flags = client->clean_session << 1; in connect_request_encode()
287 if (client->protocol_version == MQTT_VERSION_3_1_1) { in connect_request_encode()
293 /* Reserve space for fixed header. */ in connect_request_encode()
294 buf->cur += MQTT_FIXED_HEADER_MAX_SIZE; in connect_request_encode()
295 start = buf->cur; in connect_request_encode()
297 NET_HEXDUMP_DBG(mqtt_proto_desc->utf8, mqtt_proto_desc->size, in connect_request_encode()
305 NET_DBG("Encoding Protocol Version %02x.", client->protocol_version); in connect_request_encode()
306 err_code = pack_uint8(client->protocol_version, buf); in connect_request_encode()
314 connect_flags_pos = buf->cur; in connect_request_encode()
321 NET_DBG("Encoding Keep Alive Time %04x.", client->keepalive); in connect_request_encode()
322 err_code = pack_uint16(client->keepalive, buf); in connect_request_encode()
327 NET_HEXDUMP_DBG(client->client_id.utf8, client->client_id.size, in connect_request_encode()
329 err_code = pack_utf8_str(&client->client_id, buf); in connect_request_encode()
335 if (client->will_topic != NULL) { in connect_request_encode()
338 connect_flags |= ((client->will_topic->qos & 0x03) << 3); in connect_request_encode()
339 connect_flags |= client->will_retain << 5; in connect_request_encode()
341 NET_HEXDUMP_DBG(client->will_topic->topic.utf8, in connect_request_encode()
342 client->will_topic->topic.size, in connect_request_encode()
344 err_code = pack_utf8_str(&client->will_topic->topic, buf); in connect_request_encode()
349 if (client->will_message != NULL) { in connect_request_encode()
350 NET_HEXDUMP_DBG(client->will_message->utf8, in connect_request_encode()
351 client->will_message->size, in connect_request_encode()
353 err_code = pack_utf8_str(client->will_message, buf); in connect_request_encode()
367 if (client->user_name != NULL) { in connect_request_encode()
370 NET_HEXDUMP_DBG(client->user_name->utf8, in connect_request_encode()
371 client->user_name->size, in connect_request_encode()
373 err_code = pack_utf8_str(client->user_name, buf); in connect_request_encode()
380 if (client->password != NULL) { in connect_request_encode()
383 NET_HEXDUMP_DBG(client->password->utf8, in connect_request_encode()
384 client->password->size, in connect_request_encode()
386 err_code = pack_utf8_str(client->password, buf); in connect_request_encode()
401 MQTT_PKT_TYPE_PUBLISH, param->dup_flag, in publish_encode()
402 param->message.topic.qos, param->retain_flag); in publish_encode()
407 if ((param->message.topic.qos) && (param->message_id == 0U)) { in publish_encode()
408 return -EINVAL; in publish_encode()
411 /* Reserve space for fixed header. */ in publish_encode()
412 buf->cur += MQTT_FIXED_HEADER_MAX_SIZE; in publish_encode()
413 start = buf->cur; in publish_encode()
415 err_code = pack_utf8_str(&param->message.topic.topic, buf); in publish_encode()
420 if (param->message.topic.qos) { in publish_encode()
421 err_code = pack_uint16(param->message_id, buf); in publish_encode()
427 /* Do not copy payload. We move the buffer pointer to ensure that in publish_encode()
428 * message length in fixed header is encoded correctly. in publish_encode()
430 buf->cur += param->message.payload.len; in publish_encode()
437 buf->end -= param->message.payload.len; in publish_encode()
448 return mqtt_message_id_only_enc(message_type, param->message_id, buf); in publish_ack_encode()
457 return mqtt_message_id_only_enc(message_type, param->message_id, buf); in publish_receive_encode()
466 return mqtt_message_id_only_enc(message_type, param->message_id, buf); in publish_release_encode()
475 return mqtt_message_id_only_enc(message_type, param->message_id, buf); in publish_complete_encode()
480 uint8_t *cur = buf->cur; in disconnect_encode()
481 uint8_t *end = buf->end; in disconnect_encode()
483 if ((end - cur) < sizeof(disc_packet)) { in disconnect_encode()
484 return -ENOMEM; in disconnect_encode()
488 buf->end = (cur + sizeof(disc_packet)); in disconnect_encode()
502 if (param->message_id == 0U) { in subscribe_encode()
503 return -EINVAL; in subscribe_encode()
506 /* Reserve space for fixed header. */ in subscribe_encode()
507 buf->cur += MQTT_FIXED_HEADER_MAX_SIZE; in subscribe_encode()
508 start = buf->cur; in subscribe_encode()
510 err_code = pack_uint16(param->message_id, buf); in subscribe_encode()
515 for (i = 0; i < param->list_count; i++) { in subscribe_encode()
516 err_code = pack_utf8_str(&param->list[i].topic, buf); in subscribe_encode()
521 err_code = pack_uint8(param->list[i].qos, buf); in subscribe_encode()
538 /* Reserve space for fixed header. */ in unsubscribe_encode()
539 buf->cur += MQTT_FIXED_HEADER_MAX_SIZE; in unsubscribe_encode()
540 start = buf->cur; in unsubscribe_encode()
542 err_code = pack_uint16(param->message_id, buf); in unsubscribe_encode()
547 for (i = 0; i < param->list_count; i++) { in unsubscribe_encode()
548 err_code = pack_utf8_str(&param->list[i].topic, buf); in unsubscribe_encode()
559 uint8_t *cur = buf->cur; in ping_request_encode()
560 uint8_t *end = buf->end; in ping_request_encode()
562 if ((end - cur) < sizeof(ping_packet)) { in ping_request_encode()
563 return -ENOMEM; in ping_request_encode()
567 buf->end = (cur + sizeof(ping_packet)); in ping_request_encode()