Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / third_party / om-file-format-sys / c / include / om_file.h
om_file.h76 lines · 2.0 KiBRaw
| 1 | // |
| 2 | // om_file.h |
| 3 | // OpenMeteoApi |
| 4 | // |
| 5 | // Created by Patrick Zippenfenig on 24.11.2024. |
| 6 | // |
| 7 | |
| 8 | |
| 9 | #ifndef OM_FILE_H |
| 10 | #define OM_FILE_H |
| 11 | |
| 12 | #include "om_common.h" |
| 13 | |
| 14 | typedef enum { |
| 15 | OM_HEADER_INVALID = 0, |
| 16 | OM_HEADER_LEGACY = 1, |
| 17 | OM_HEADER_READ_TRAILER = 2, |
| 18 | } OmHeaderType_t; |
| 19 | |
| 20 | /// Legacy files only contain one 2D array with attributes in the header |
| 21 | /// File content: Header, look-up-table, compressed data |
| 22 | typedef struct { |
| 23 | uint8_t magic_number1; |
| 24 | uint8_t magic_number2; |
| 25 | uint8_t version; |
| 26 | uint8_t compression_type; // OmCompression_t |
| 27 | float scale_factor; |
| 28 | uint64_t dim0; |
| 29 | uint64_t dim1; |
| 30 | uint64_t chunk0; |
| 31 | uint64_t chunk1; |
| 32 | // followed by lookup table and then data |
| 33 | } OmHeaderV1_t; |
| 34 | |
| 35 | /// Newer version only contain magic number "OM" and the version 3 |
| 36 | typedef struct { |
| 37 | uint8_t magic_number1; |
| 38 | uint8_t magic_number2; |
| 39 | uint8_t version; |
| 40 | } OmHeaderV3_t; |
| 41 | |
| 42 | /// Trailer only present in version 3 files |
| 43 | typedef struct { |
| 44 | uint8_t magic_number1; |
| 45 | uint8_t magic_number2; |
| 46 | uint8_t version; |
| 47 | uint8_t reserved; |
| 48 | uint32_t reserved2; // can later be used for a 32 bit hash. E.g. xxhash |
| 49 | uint64_t root_offset; |
| 50 | uint64_t root_size; |
| 51 | } OmTrailer_t; |
| 52 | |
| 53 | |
| 54 | |
| 55 | /// Return the size in byte of the header that should be read. Always 40 byte to support legacy 2D files. |
| 56 | size_t om_header_size(); |
| 57 | |
| 58 | /// Size in bytes of the trailer that contains the root variable offset in newer files |
| 59 | size_t om_trailer_size(); |
| 60 | |
| 61 | /// The size of a OM header for newer files. Always 3 bytes. |
| 62 | size_t om_header_write_size(); |
| 63 | |
| 64 | /// Check if the header is a OM file header and return if its a legacy version or a new version file |
| 65 | OmHeaderType_t om_header_type(const void* src); |
| 66 | |
| 67 | /// Read the trailer of an OM file to get the root variable. Size is set to 0 if this is not an OM file. |
| 68 | bool om_trailer_read(const void* src, uint64_t* offset, uint64_t* size); |
| 69 | |
| 70 | /// Write an header for newer OM files |
| 71 | void om_header_write(void* dest); |
| 72 | |
| 73 | /// Write an trailer for newer OM files including the root variable |
| 74 | void om_trailer_write(void* dest, uint64_t offset, uint64_t size); |
| 75 | |
| 76 | #endif // OM_FILE_H |