space_packet_parser.generators

Generators subpackage, containing packet generators for different packet formats.

Submodules

Functions

ccsds_generator(...)

A generator that reads raw packet data from a filelike object or a socket.

fixed_length_generator(→ collections.abc.Iterator[bytes])

A generator that yields fixed-length chunks from binary_data.

Package Contents

space_packet_parser.generators.ccsds_generator(binary_data: BinaryIO | socket.socket | bytes, *, buffer_read_size_bytes: int | None = None, show_progress: bool = False, skip_header_bytes: int = 0, combine_segmented_packets: bool = False, secondary_header_bytes: int = 0) collections.abc.Iterator[CCSDSPacketBytes]

A generator that reads raw packet data from a filelike object or a socket.

Each iteration of the generator yields a CCSDSPacketBytes object that makes up a single CCSDS packet. If combining segmented packets is enabled, the generator will combine segmented packets into a single packet for parsing. This is useful for parsing packets that are split into multiple packets due to size constraints.

Parameters:
  • binary_data (Union[BinaryIO, socket.socket, bytes]) – Binary data source containing CCSDSPackets.

  • buffer_read_size_bytes (int, optional) – Number of bytes to read from e.g. a BufferedReader or socket binary data source on each read attempt. If None, defaults to 4096 bytes from a socket, -1 (full read) from a file.

  • show_progress (bool) – Default False. If True, prints a status bar. Note that for socket sources, the percentage will be zero until the generator ends.

  • skip_header_bytes (int) – Default 0. The parser skips this many bytes at the beginning of every packet. This allows dynamic stripping of additional header data that may be prepended to packets in “raw record” file formats.

  • combine_segmented_packets (bool) – Default False. If True, combines segmented packets into a single packet for parsing. This is useful for parsing packets that are split into multiple packets due to size constraints. The packet data is combined by concatenating the data from each packet together. The combined packet is then parsed as a single packet. Only the first CCSDS header is kept when concatenating continued packets. CCSDS headers (and secondary headers) from continuation packets are discarded.

  • secondary_header_bytes (int) – Default 0. The length of the secondary header in bytes. This is used to skip the secondary header of segmented packets. The byte layout within the returned packet has all data concatenated together as follows: [packet0header, packet0secondaryheader, packet0data, packet1data, packet2data, …].

Yields:

CCSDSPacketBytes – The bytes of a single CCSDS packet.

space_packet_parser.generators.fixed_length_generator(binary_data: BinaryIO | socket.socket | bytes, *, packet_length_bytes: int, buffer_read_size_bytes: int | None = None, show_progress: bool = False) collections.abc.Iterator[bytes]

A generator that yields fixed-length chunks from binary_data.

Parameters:
  • binary_data (Union[BinaryIO, socket.socket, bytes]) – Binary data source.

  • packet_length_bytes (int) – Number of bytes per packet to yield.

  • buffer_read_size_bytes (int, optional) – Number of bytes to read from the source per read.

  • show_progress (bool) – If True, prints a status bar.

Yields:

bytes – Fixed-length packet bytes.