async def _get_packet_from_stream(self, stream, existing_data, got_first_packet=True, psml_structure=None): """A coroutine which returns a single packet if it can be read from the given StreamReader. :return a tuple of (packet, remaining_data). The packet will be None if there was not enough XML data to create a packet. remaining_data is the leftover data which was not enough to create a packet from. :raises EOFError if EOF was reached. """ # yield each packet in existing_data if self.use_json: packet, existing_data = self._extract_packet_json_from_data(existing_data, got_first_packet=got_first_packet) else: packet, existing_data = self._extract_tag_from_data(existing_data) if packet: if self.use_json: packet = packet_from_json_packet(packet) else: packet = packet_from_xml_packet(packet, psml_structure=psml_structure) return packet, existing_data new_data = await stream.read(self.DEFAULT_BATCH_SIZE) existing_data += new_data if not new_data: # Reached EOF raise EOFError() return None, existing_data
async def _get_packet_from_stream(self, stream, existing_data, got_first_packet=True, psml_structure=None): """A coroutine which returns a single packet if it can be read from the given StreamReader. :return a tuple of (packet, remaining_data). The packet will be None if there was not enough XML data to create a packet. remaining_data is the leftover data which was not enough to create a packet from. :raises EOFError if EOF was reached. """ # yield each packet in existing_data if self.use_json: packet, existing_data = self._extract_packet_json_from_data(existing_data, got_first_packet=got_first_packet) else: packet, existing_data = self._extract_tag_from_data(existing_data) if packet: if self.use_json: packet = packet_from_json_packet(packet, deduplicate_fields=self._json_has_duplicate_keys) else: packet = packet_from_xml_packet(packet, psml_structure=psml_structure) return packet, existing_data new_data = await stream.read(self.DEFAULT_BATCH_SIZE) existing_data += new_data if not new_data: # Reached EOF self._eof_reached = True raise EOFError() return None, existing_data
def parsed_packet(data_directory): return tshark_json.packet_from_json_packet( data_directory.joinpath("packet.json").read_bytes())