in amazon_transcribe/eventstream.py [0:0]
def serialize(self, headers: HEADERS_SERIALIZATION_DICT, payload: bytes) -> bytes:
# TODO: Investigate preformance of this once we can make requests
if len(payload) > _MAX_PAYLOAD_LENGTH:
raise PayloadBytesExceedMaxLength(len(payload))
# The encoded headers are variable length and this length
# is required to generate the prelude, generate the headers first
encoded_headers = self.encode_headers(headers)
if len(encoded_headers) > _MAX_HEADERS_LENGTH:
raise HeaderBytesExceedMaxLength(len(encoded_headers))
prelude_bytes = self._encode_prelude(encoded_headers, payload)
# Calculate the prelude_crc and it's byte representation
prelude_crc = self._calculate_checksum(prelude_bytes)
prelude_crc_bytes = pack("!I", prelude_crc)
messages_bytes = prelude_crc_bytes + encoded_headers + payload
# Calculate the checksum continuing from the prelude crc
final_crc = self._calculate_checksum(messages_bytes, crc=prelude_crc)
final_crc_bytes = pack("!I", final_crc)
return prelude_bytes + messages_bytes + final_crc_bytes