seasonder_readCSSYHeader {SeaSondeR} | R Documentation |
Read CSSY File Header
Description
This function reads the header section of a CSSY file from a binary connection. The CSSY file header contains a set of key blocks formatted according to the SeaSonde CSSY 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 thekeys_so_far
vector is encountered (indicative of repeated keys), which triggers termination.
Usage
seasonder_readCSSYHeader(
connection,
current_specs,
endian = "big",
parent_key = NULL,
keys_so_far = c("CSSY", "HEAD"),
specs_key_size = NULL
)
Arguments
connection |
A binary connection from which to read the CSSY 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("CSSY", "HEAD"). |
specs_key_size |
A specification for reading the key size block, often obtained from YAML specs. |
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_readCSSYFields
.
The function processes the CSSY header recursively:
If
current_specs
contains only field definitions,seasonder_readCSSYFields
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 inkeys_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.
Value
A list containing the parsed CSSY header information. The returned list may be empty if a termination condition is encountered.