Skip to content

Custom Formats

The easiest way to add a custom format is to let Sonar Catalog read the magic bytes from a sample file:

Terminal window
sonar-catalog add-magic-byte /path/to/sample.myformat \
--format-name my_sonar \
--length 4 \
--description "My proprietary sonar format"

This reads the first 4 bytes from the sample file and registers them as the signature for my_sonar.

FlagDescription
--format-nameName for the format (defaults to file extension)
--lengthNumber of magic bytes to read (default: 4)
--offsetByte offset to start reading from (default: 0)
--descriptionHuman-readable description
--no-extensionDon’t associate the file extension with this format
--forceReplace an existing format with the same name

Some formats have magic bytes at a non-zero offset:

Terminal window
sonar-catalog add-magic-byte /path/to/sample.dat \
--format-name sonar_v2 \
--length 4 \
--offset 8 \
--description "SonarV2 format (magic at offset 8)"

Add extension-to-format mappings in the config file:

{
"metadata": {
"custom_extension_map": {
".myformat": "my_sonar",
".dat": "proprietary_sonar",
".xyz": "bathymetry_export"
}
}
}

You can also add magic byte signatures directly in the config file:

{
"metadata": {
"custom_magic_bytes": [
{
"format": "my_sonar",
"hex_bytes": "cafebabe",
"byte_length": 4,
"offset": 0,
"extension": ".myformat",
"description": "My custom sonar format"
}
]
}
}
FieldDescription
formatFormat name
hex_bytesHex-encoded magic bytes
byte_lengthNumber of bytes
offsetByte offset in file
extensionAssociated file extension
descriptionHuman-readable description

For more complex format detection logic (e.g., checking internal structures beyond magic bytes), write a plugin that implements the detect_format hook. See Writing a Plugin.