Skip to content

Pass payload by value to enable moving arguments #173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions examples/dynamodb/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ aws::lambda_runtime::invocation_response my_handler(
if (cr.error_msg) {
JsonValue response;
response.WithString("body", cr.error_msg).WithInteger("statusCode", 400);
auto const apig_response = response.View().WriteCompact();
auto apig_response = response.View().WriteCompact();
AWS_LOGSTREAM_ERROR(TAG, "Validation failed. " << apig_response);
return aws::lambda_runtime::invocation_response::success(apig_response, "application/json");
return aws::lambda_runtime::invocation_response::success(std::move(apig_response), "application/json");
}

auto result = query(cr, client);
Expand All @@ -190,10 +190,10 @@ aws::lambda_runtime::invocation_response my_handler(
response.WithString("body", "No data found for this product.").WithInteger("statusCode", 400);
}

auto const apig_response = response.View().WriteCompact();
auto apig_response = response.View().WriteCompact();
AWS_LOGSTREAM_DEBUG(TAG, "api gateway response: " << apig_response);

return aws::lambda_runtime::invocation_response::success(apig_response, "application/json");
return aws::lambda_runtime::invocation_response::success(std::move(apig_response), "application/json");
}

std::function<std::shared_ptr<Aws::Utils::Logging::LogSystemInterface>()> GetConsoleLoggerFactory()
Expand Down
2 changes: 1 addition & 1 deletion examples/s3/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static invocation_response my_handler(invocation_request const& req, Aws::S3::S3
return invocation_response::failure(err, "DownloadFailure");
}

return invocation_response::success(base64_encoded_file, "application/base64");
return invocation_response::success(std::move(base64_encoded_file), "application/base64");
}

std::function<std::shared_ptr<Aws::Utils::Logging::LogSystemInterface>()> GetConsoleLoggerFactory()
Expand Down
2 changes: 1 addition & 1 deletion include/aws/lambda-runtime/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class invocation_response {
/**
* Create a successful invocation response with the given payload and content-type.
*/
static invocation_response success(std::string const& payload, std::string const& content_type);
static invocation_response success(std::string payload, std::string content_type);

/**
* Create a failure response with the given error message and error type.
Expand Down
6 changes: 3 additions & 3 deletions src/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,12 +506,12 @@ static std::string json_escape(std::string const& in)
}

AWS_LAMBDA_RUNTIME_API
invocation_response invocation_response::success(std::string const& payload, std::string const& content_type)
invocation_response invocation_response::success(std::string payload, std::string content_type)
{
invocation_response r;
r.m_success = true;
r.m_content_type = content_type;
r.m_payload = payload;
r.m_content_type = std::move(content_type);
r.m_payload = std::move(payload);
return r;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/resources/lambda_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ invocation_response echo_failure(invocation_request const& /*request*/)

invocation_response binary_response(invocation_request const& /*request*/)
{
const std::string png((char*)awslogo_png, AWSLOGO_PNG_LEN);
return invocation_response::success(png, "image/png");
std::string png((char*)awslogo_png, AWSLOGO_PNG_LEN);
return invocation_response::success(std::move(png), "image/png");
}

invocation_response crash_backtrace(invocation_request const& /*request*/)
Expand Down