ccsds_ndm.ndm_io

Classes

NdmIo()

Format-agnostic read/write facade for CCSDS Navigation Data Messages.

class NdmIo[source]

Format-agnostic read/write facade for CCSDS Navigation Data Messages.

Detects whether the source is KVN or XML by inspecting the first non-whitespace characters, then delegates to NdmKvnIo or NdmXmlIo accordingly.

JSON is not yet defined by the CCSDS standard and will raise NotImplementedError if attempted.

from_bytes(ndm_data_source)[source]

Read an NDM byte string and return the corresponding object tree.

Decodes the bytes as UTF-8 and forwards the result to from_string(), which handles format detection.

Parameters:

ndm_data_source (bytes) – KVN or XML content encoded as a byte string.

Returns:

object – Root xsdata dataclass instance for the detected NDM type (e.g. OpmType, OemType, ApmType, …).

from_path(input_file_path)[source]

Read an NDM file and return the corresponding object tree.

Reads the file as plain text and forwards the content to from_string(), which handles format detection.

Parameters:

input_file_path (Path or str) – Path to the KVN or XML input file.

Returns:

object – Root xsdata dataclass instance for the detected NDM type (e.g. OpmType, OemType, ApmType, …).

from_string(ndm_data_source)[source]

Parse an NDM string and return the corresponding object tree.

Calls _identify_data_format() to determine whether the input is KVN or XML, then dispatches to the appropriate parser:

Parameters:

ndm_data_source (str) – Raw KVN or XML text (Windows or Unix line endings accepted).

Returns:

object – Root xsdata dataclass instance for the detected NDM type (e.g. OpmType, OemType, ApmType, …).

Raises:
  • NotImplementedError – If the input is identified as JSON, which is not yet defined by the CCSDS NDM standard.

  • ValueError – If the format cannot be identified from the input text.

to_file(ndm_obj, data_format, xml_write_file_path, **kwargs)[source]

Serialise an NDM object tree and write it to a file.

Dispatches to the appropriate writer based on data_format:

Parameters:
  • ndm_obj (object) – Root xsdata dataclass instance to serialise.

  • data_format (NDMFileFormats) – Target output format (NDMFileFormats.KVN or NDMFileFormats.XML).

  • xml_write_file_path (Path or str) – Destination file path.

  • **kwargs – Additional keyword arguments forwarded to the underlying writer. For XML output: schema_location, no_namespace_schema_location.

Raises:

NotImplementedError – If data_format is NDMFileFormats.JSON.

to_string(ndm_obj, data_format, **kwargs)[source]

Serialise an NDM object tree to a string.

Dispatches to the appropriate writer based on data_format:

Parameters:
  • ndm_obj (object) – Root xsdata dataclass instance to serialise.

  • data_format (NDMFileFormats) – Target output format (NDMFileFormats.KVN or NDMFileFormats.XML).

  • **kwargs – Additional keyword arguments forwarded to the underlying writer. For XML output: schema_location, no_namespace_schema_location.

Returns:

str – The serialised NDM text in the requested format.

Raises:

NotImplementedError – If data_format is NDMFileFormats.JSON.