Skip to contents

This function reads the header section of a CSSW file from a binary connection. The CSSW file header contains a set of key blocks formatted according to the SeaSonde CSSW specification. The header section is processed recursively and terminates when one of the following conditions is met:

  • A key with name "BODY" is encountered. In this case, the connection is rewound by 8 bytes to allow subsequent processing of the body.

  • A key that is not defined in current_specs but is already present in the keys_so_far vector is encountered (indicative of repeated keys), which triggers termination.

Usage

seasonder_readCSSWHeader(
  connection,
  current_specs,
  endian = "big",
  parent_key = NULL,
  keys_so_far = c("CSSW", "HEAD"),
  specs_key_size = NULL
)

Arguments

connection

A binary connection from which to read the CSSW file header.

current_specs

A list representing the specification for the header; may contain nested subkeys.

endian

A character string indicating the byte order for reading numeric values ("big" or "little").

parent_key

(Optional) A list with information from the parent key block, used when processing nested keys.

keys_so_far

A character vector of keys already processed, used to avoid recursive loops. Defaults to c("CSSW", "HEAD").

specs_key_size

A specification for reading the key size block, often obtained from YAML specs.

Value

A list containing the parsed CSSW header information. The returned list may be empty if a termination condition is encountered.

Details

When no subkeys are specified in current_specs (i.e. current_specs comprises only simple field definitions), the function delegates the processing to seasonder_readCSSWFields.

The function processes the CSSW header recursively:

  • If current_specs contains only field definitions, seasonder_readCSSWFields is called.

  • When a key named "BODY" is encountered, it signifies the beginning of the body section; the function rewinds the connection 8 bytes and stops processing further keys.

  • If a key is encountered that is not defined in current_specs but is already present in keys_so_far, the function also rewinds the connection 8 bytes and terminates header reading.

  • Otherwise, the function updates keys_so_far, handles special cases (e.g., key "cs4h"), and calls itself recursively to process nested keys.