in source/serializer.c [122:156]
int aws_iot_st_msg_serialize_from_struct(
struct aws_byte_buf *buffer,
struct aws_allocator *allocator,
struct aws_iot_st_msg message) {
if (aws_byte_buf_init(buffer, allocator, AWS_IOT_ST_DEFAULT_ALLO + message.payload.len) != AWS_OP_SUCCESS) {
return AWS_OP_ERR;
}
if (message.type != AWS_IOT_ST_MESSAGE_DEFAULT_TYPE) {
if (s_iot_st_encode_type(message.type, buffer) != AWS_OP_SUCCESS) {
goto cleanup;
}
}
if (message.stream_id != AWS_IOT_ST_MESSAGE_DEFAULT_STREAM_ID) {
if (s_iot_st_encode_stream_id(message.stream_id, buffer) != AWS_OP_SUCCESS) {
goto cleanup;
}
}
if (message.ignorable != AWS_IOT_ST_MESSAGE_DEFAULT_IGNORABLE) {
if (s_iot_st_encode_ignorable(message.ignorable, buffer) != AWS_OP_SUCCESS) {
goto cleanup;
}
}
if (message.payload.len != AWS_IOT_ST_MESSAGE_DEFAULT_PAYLOAD) {
if (s_iot_st_encode_payload(&message.payload, buffer) != AWS_OP_SUCCESS) {
goto cleanup;
}
}
AWS_RETURN_ERROR_IF2(buffer->capacity < AWS_IOT_ST_MAX_MESSAGE_SIZE, AWS_ERROR_INVALID_BUFFER_SIZE);
return AWS_OP_SUCCESS;
cleanup:
aws_byte_buf_clean_up(buffer);
return AWS_OP_ERR;
}