Skip to content

Commit 8e98808

Browse files
marcomagdybmoffatt
andauthored
Pass payload by value to enable moving arguments (#173)
* Pass payload by value to enable moving arguments * Update the tests to use std::move * empty commit Co-authored-by: Bryan Moffatt <bmoffatt@users.noreply.github.com> Co-authored-by: Bryan Moffatt <bryan@bryanmoffatt.com>
1 parent 08002c5 commit 8e98808

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

examples/dynamodb/main.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,9 @@ aws::lambda_runtime::invocation_response my_handler(
173173
if (cr.error_msg) {
174174
JsonValue response;
175175
response.WithString("body", cr.error_msg).WithInteger("statusCode", 400);
176-
auto const apig_response = response.View().WriteCompact();
176+
auto apig_response = response.View().WriteCompact();
177177
AWS_LOGSTREAM_ERROR(TAG, "Validation failed. " << apig_response);
178-
return aws::lambda_runtime::invocation_response::success(apig_response, "application/json");
178+
return aws::lambda_runtime::invocation_response::success(std::move(apig_response), "application/json");
179179
}
180180

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

193-
auto const apig_response = response.View().WriteCompact();
193+
auto apig_response = response.View().WriteCompact();
194194
AWS_LOGSTREAM_DEBUG(TAG, "api gateway response: " << apig_response);
195195

196-
return aws::lambda_runtime::invocation_response::success(apig_response, "application/json");
196+
return aws::lambda_runtime::invocation_response::success(std::move(apig_response), "application/json");
197197
}
198198

199199
std::function<std::shared_ptr<Aws::Utils::Logging::LogSystemInterface>()> GetConsoleLoggerFactory()

examples/s3/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ static invocation_response my_handler(invocation_request const& req, Aws::S3::S3
5050
return invocation_response::failure(err, "DownloadFailure");
5151
}
5252

53-
return invocation_response::success(base64_encoded_file, "application/base64");
53+
return invocation_response::success(std::move(base64_encoded_file), "application/base64");
5454
}
5555

5656
std::function<std::shared_ptr<Aws::Utils::Logging::LogSystemInterface>()> GetConsoleLoggerFactory()

include/aws/lambda-runtime/runtime.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class invocation_response {
105105
/**
106106
* Create a successful invocation response with the given payload and content-type.
107107
*/
108-
static invocation_response success(std::string const& payload, std::string const& content_type);
108+
static invocation_response success(std::string payload, std::string content_type);
109109

110110
/**
111111
* Create a failure response with the given error message and error type.

src/runtime.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -506,12 +506,12 @@ static std::string json_escape(std::string const& in)
506506
}
507507

508508
AWS_LAMBDA_RUNTIME_API
509-
invocation_response invocation_response::success(std::string const& payload, std::string const& content_type)
509+
invocation_response invocation_response::success(std::string payload, std::string content_type)
510510
{
511511
invocation_response r;
512512
r.m_success = true;
513-
r.m_content_type = content_type;
514-
r.m_payload = payload;
513+
r.m_content_type = std::move(content_type);
514+
r.m_payload = std::move(payload);
515515
return r;
516516
}
517517

tests/resources/lambda_function.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ invocation_response echo_failure(invocation_request const& /*request*/)
2323

2424
invocation_response binary_response(invocation_request const& /*request*/)
2525
{
26-
const std::string png((char*)awslogo_png, AWSLOGO_PNG_LEN);
27-
return invocation_response::success(png, "image/png");
26+
std::string png((char*)awslogo_png, AWSLOGO_PNG_LEN);
27+
return invocation_response::success(std::move(png), "image/png");
2828
}
2929

3030
invocation_response crash_backtrace(invocation_request const& /*request*/)

0 commit comments

Comments
 (0)