in source/serializer.c [164:222]
int aws_iot_st_msg_deserialize_from_cursor(
struct aws_iot_st_msg *message,
struct aws_byte_cursor *cursor,
struct aws_allocator *allocator) {
AWS_RETURN_ERROR_IF2(cursor->len < AWS_IOT_ST_MAX_MESSAGE_SIZE, AWS_ERROR_INVALID_BUFFER_SIZE);
uint8_t wire_type;
uint8_t field_number;
int length;
int payload_check = 0;
while ((aws_byte_cursor_is_valid(cursor)) && (cursor->len > 0)) {
// wire_type is only the first 3 bits, Zeroing out the first 5
// 0x07 == 00000111
wire_type = *cursor->ptr & 0x07;
field_number = (*cursor->ptr) >> 3;
aws_byte_cursor_advance(cursor, 1);
if (field_number == AWS_IOT_ST_STREAM_ID_FIELD_NUMBER && wire_type == AWS_IOT_ST_VARINT_WIRE) {
uint32_t res = 0;
if (s_iot_st_decode_varint_uint32_t(cursor, &res) != AWS_OP_SUCCESS) {
return AWS_OP_ERR;
}
message->stream_id = res;
} else if (field_number == AWS_IOT_ST_IGNORABLE_FIELD_NUMBER && wire_type == AWS_IOT_ST_VARINT_WIRE) {
uint32_t res = 0;
if (s_iot_st_decode_varint_uint32_t(cursor, &res) != AWS_OP_SUCCESS) {
return AWS_OP_ERR;
}
message->ignorable = res;
} else if (field_number == AWS_IOT_ST_TYPE_FIELD_NUMBER && wire_type == AWS_IOT_ST_VARINT_WIRE) {
uint32_t res = 0;
if (s_iot_st_decode_varint_uint32_t(cursor, &res) != AWS_OP_SUCCESS) {
return AWS_OP_ERR;
}
message->type = res;
} else if (field_number == AWS_IOT_ST_PAYLOAD_FIELD_NUMBER && wire_type == AWS_IOT_ST_VARINT_LENGTHDELIM_WIRE) {
uint32_t res = 0;
if (s_iot_st_decode_varint_uint32_t(cursor, &res) != AWS_OP_SUCCESS) {
return AWS_OP_ERR;
}
length = res;
if (aws_byte_buf_init(&message->payload, allocator, length) != AWS_OP_SUCCESS) {
return AWS_OP_ERR;
}
if (s_aws_st_decode_lengthdelim(cursor, &message->payload, length) != AWS_OP_SUCCESS) {
goto cleanup;
}
aws_byte_cursor_advance(cursor, length);
payload_check = 1;
}
}
if (payload_check == 0) {
AWS_ZERO_STRUCT(message->payload);
}
return AWS_OP_SUCCESS;
cleanup:
aws_byte_buf_clean_up(&message->payload);
return AWS_OP_ERR;
}