Created
January 24, 2024 15:06
-
-
Save bassmanitram/fc58b50915e3266004a808431e34a050 to your computer and use it in GitHub Desktop.
Lambda HTTP Request Deserialization by Serde Json and SIMD JSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "test-serde-simd-json" | |
version = "0.1.0" | |
edition = "2021" | |
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | |
[dependencies] | |
bytes = "1.5" | |
simd-json = "0.13" | |
lambda_http = { version = "0.9", default-features = false, features = ["apigw_rest"] } | |
serde_json = "1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use lambda_http::request::LambdaRequest; | |
use lambda_http::Request; | |
static EVENT: &str = r#"{ | |
"resource": "/{proxy+}", | |
"path": "/hello/world", | |
"httpMethod": "POST", | |
"headers": { | |
"Accept": "*/*", | |
"Accept-Encoding": "gzip, deflate", | |
"cache-control": "no-cache", | |
"CloudFront-Forwarded-Proto": "https", | |
"CloudFront-Is-Desktop-Viewer": "true", | |
"CloudFront-Is-Mobile-Viewer": "false", | |
"CloudFront-Is-SmartTV-Viewer": "false", | |
"CloudFront-Is-Tablet-Viewer": "false", | |
"CloudFront-Viewer-Country": "US", | |
"Content-Type": "application/json", | |
"headerName": "headerValue", | |
"Host": "gy415nuibc.execute-api.us-east-1.amazonaws.com", | |
"Postman-Token": "9f583ef0-ed83-4a38-aef3-eb9ce3f7a57f", | |
"User-Agent": "PostmanRuntime/2.4.5", | |
"Via": "1.1 d98420743a69852491bbdea73f7680bd.cloudfront.net (CloudFront)", | |
"X-Amz-Cf-Id": "pn-PWIJc6thYnZm5P0NMgOUglL1DYtl0gdeJky8tqsg8iS_sgsKD1A==", | |
"X-Forwarded-For": "54.240.196.186, 54.182.214.83", | |
"X-Forwarded-Port": "443", | |
"X-Forwarded-Proto": "https" | |
}, | |
"multiValueHeaders": { | |
"Accept": [ | |
"*/*" | |
], | |
"Accept-Encoding": [ | |
"gzip, deflate" | |
], | |
"cache-control": [ | |
"no-cache" | |
], | |
"CloudFront-Forwarded-Proto": [ | |
"https" | |
], | |
"CloudFront-Is-Desktop-Viewer": [ | |
"true" | |
], | |
"CloudFront-Is-Mobile-Viewer": [ | |
"false" | |
], | |
"CloudFront-Is-SmartTV-Viewer": [ | |
"false" | |
], | |
"CloudFront-Is-Tablet-Viewer": [ | |
"false" | |
], | |
"CloudFront-Viewer-Country": [ | |
"US" | |
], | |
"Content-Type": [ | |
"application/json" | |
], | |
"headerName": [ | |
"headerValue" | |
], | |
"Host": [ | |
"gy415nuibc.execute-api.us-east-1.amazonaws.com" | |
], | |
"Postman-Token": [ | |
"9f583ef0-ed83-4a38-aef3-eb9ce3f7a57f" | |
], | |
"User-Agent": [ | |
"PostmanRuntime/2.4.5" | |
], | |
"Via": [ | |
"1.1 d98420743a69852491bbdea73f7680bd.cloudfront.net (CloudFront)" | |
], | |
"X-Amz-Cf-Id": [ | |
"pn-PWIJc6thYnZm5P0NMgOUglL1DYtl0gdeJky8tqsg8iS_sgsKD1A==" | |
], | |
"X-Forwarded-For": [ | |
"54.240.196.186, 54.182.214.83" | |
], | |
"X-Forwarded-Port": [ | |
"443" | |
], | |
"X-Forwarded-Proto": [ | |
"https" | |
] | |
}, | |
"queryStringParameters": { | |
"name": "me" | |
}, | |
"multiValueQueryStringParameters": { | |
"name": [ | |
"me" | |
] | |
}, | |
"pathParameters": { | |
"proxy": "hello/world" | |
}, | |
"stageVariables": { | |
"stageVariableName": "stageVariableValue" | |
}, | |
"requestContext": { | |
"accountId": "12345678912", | |
"resourceId": "roq9wj", | |
"path": "/hello/world", | |
"stage": "testStage", | |
"domainName": "gy415nuibc.execute-api.us-east-2.amazonaws.com", | |
"domainPrefix": "y0ne18dixk", | |
"requestId": "deef4878-7910-11e6-8f14-25afc3e9ae33", | |
"protocol": "HTTP/1.1", | |
"identity": { | |
"cognitoIdentityPoolId": "theCognitoIdentityPoolId", | |
"accountId": "theAccountId", | |
"cognitoIdentityId": "theCognitoIdentityId", | |
"caller": "theCaller", | |
"apiKey": "theApiKey", | |
"apiKeyId": "theApiKeyId", | |
"accessKey": "ANEXAMPLEOFACCESSKEY", | |
"sourceIp": "192.168.196.186", | |
"cognitoAuthenticationType": "theCognitoAuthenticationType", | |
"cognitoAuthenticationProvider": "theCognitoAuthenticationProvider", | |
"userArn": "theUserArn", | |
"userAgent": "PostmanRuntime/2.4.5", | |
"user": "theUser" | |
}, | |
"authorizer": { | |
"principalId": "admin", | |
"clientId": 1, | |
"clientName": "Exata" | |
}, | |
"resourcePath": "/{proxy+}", | |
"httpMethod": "POST", | |
"requestTime": "15/May/2020:06:01:09 +0000", | |
"requestTimeEpoch": 1589522469693, | |
"apiId": "gy415nuibc" | |
}, | |
"body": "{\r\n\t\"a\": 1\r\n}" | |
} | |
"#; | |
pub fn main() { | |
let payload1 = EVENT.to_string(); | |
let by_serde: Result<Request, serde_json::Error> = serde_json::from_reader(payload1.as_bytes()).map(LambdaRequest::into); | |
let payload2 = EVENT.to_string(); | |
let by_simd: Result<Request, simd_json::Error> = simd_json::from_reader(payload2.as_bytes()).map(LambdaRequest::into); | |
println!("BY SERDE: {:#?}", by_serde); | |
println!("BY SIMD: {:#?}", by_simd); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment