How to use deserialize_event method in localstack

Best Python code snippet using localstack_python

race_data_parser.py

Source:race_data_parser.py Github

copy

Full Screen

...26 horse_result.guts_order, horse_result.wiz_order, horse_result.last_spurt_start_distance,27 horse_result.running_style, horse_result.defeat,28 horse_result.finish_time_raw) = struct.unpack_from('<ifffBBfBif', b, offset)29 return horse_result30def deserialize_event(b: bytearray, offset: int) -> race_data_pb2.RaceSimulateEventData:31 event = race_data_pb2.RaceSimulateEventData()32 fmt = '<fbb'33 (event.frame_time, event.type, event.param_count) = struct.unpack_from(fmt, b, offset)34 offset += struct.calcsize(fmt)35 for i in range(event.param_count):36 event.param.append(struct.unpack_from('<i', b, offset)[0])37 offset += 438 return event39def deserialize(b: bytearray) -> race_data_pb2.RaceSimulateData:40 data = race_data_pb2.RaceSimulateData()41 header, offset = deserialize_header(b)42 data.header.CopyFrom(header)43 fmt = '<fiii'44 data.distance_diff_max, data.horse_num, data.horse_frame_size, data.horse_result_size = \45 struct.unpack_from(fmt, b, offset)46 offset += struct.calcsize(fmt)47 data.__padding_size_1 = struct.unpack_from('<i', b, offset)[0]48 offset += 4 + data.__padding_size_149 fmt = '<ii'50 data.frame_count, data.frame_size = struct.unpack_from(fmt, b, offset)51 offset += struct.calcsize(fmt)52 for i in range(data.frame_count):53 data.frame.append(deserialize_frame(b, offset, data.horse_num, data.horse_frame_size))54 offset += data.frame_size55 data.__padding_size_2 = struct.unpack_from('<i', b, offset)[0]56 offset += 4 + data.__padding_size_257 for i in range(data.horse_num):58 data.horse_result.append(deserialize_horse_result(b, offset))59 offset += data.horse_result_size60 data.__padding_size_3 = struct.unpack_from('<i', b, offset)[0]61 offset += 4 + data.__padding_size_362 data.event_count = struct.unpack_from('<i', b, offset)[0]63 offset += 464 for i in range(data.event_count):65 event_wrapper = race_data_pb2.RaceSimulateData.EventDataWrapper()66 event_wrapper.event_size = struct.unpack_from('<h', b, offset)[0]67 offset += 268 event_wrapper.event.CopyFrom(deserialize_event(b, offset))69 offset += event_wrapper.event_size70 data.event.append(event_wrapper)71 return data72def main():73 b = input('Please paste content of field "race_scenario" here: ').strip('"')74 b = gzip.decompress(base64.b64decode(b))75 print(deserialize(b))76if __name__ == '__main__':...

Full Screen

Full Screen

lambda_integration.py

Source:lambda_integration.py Github

copy

Full Screen

...23 raw_event_messages = []24 for record in event['Records']:25 # Deserialize into Python dictionary and extract the26 # "NewImage" (the new version of the full ddb document)27 ddb_new_image = deserialize_event(record)28 if MSG_BODY_RAISE_ERROR_FLAG in ddb_new_image.get('data', {}):29 raise Exception('Test exception (this is intentional)')30 # Place the raw event message document into the Kinesis message format31 kinesis_record = {32 'PartitionKey': 'key123',33 'Data': json.dumps(ddb_new_image)34 }35 if MSG_BODY_MESSAGE_TARGET in ddb_new_image.get('data', {}):36 forwarding_target = ddb_new_image['data'][MSG_BODY_MESSAGE_TARGET]37 target_name = forwarding_target.split(':')[-1]38 if forwarding_target.startswith('kinesis:'):39 ddb_new_image['data'][MSG_BODY_MESSAGE_TARGET] = 's3:/test_chain_result'40 kinesis_record['Data'] = json.dumps(ddb_new_image['data'])41 forward_event_to_target_stream(kinesis_record, target_name)42 elif forwarding_target.startswith('s3:'):43 s3_client = aws_stack.connect_to_service('s3')44 test_data = to_bytes(json.dumps({'test_data': ddb_new_image['data']['test_data']}))45 s3_client.upload_fileobj(BytesIO(test_data), TEST_BUCKET_NAME, target_name)46 else:47 raw_event_messages.append(kinesis_record)48 # Forward messages to Kinesis49 forward_events(raw_event_messages)50def deserialize_event(event):51 # Deserialize into Python dictionary and extract the "NewImage" (the new version of the full ddb document)52 ddb = event.get('dynamodb')53 if ddb:54 ddb_deserializer = TypeDeserializer()55 return ddb_deserializer.deserialize({'M': ddb['NewImage']})56 kinesis = event.get('kinesis')57 if kinesis:58 assert kinesis['sequenceNumber']59 kinesis['data'] = json.loads(to_str(base64.b64decode(kinesis['data'])))60 return kinesis61 return event.get('Sns')62def forward_events(records):63 if not records:64 return...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful