Created
August 6, 2025 23:55
-
-
Save James2022-rgb/64ab46b8dad77472054c304c282b7e8c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // References: | |
| // https://github.com/gopro/gpmf-parser | |
| // https://community.gopro.com/s/question/0D5Uv000002ABpJKAW/where-can-i-find-descriptions-for-these-gpmf-fourcc-codes?language=ja | |
| #pragma endian big | |
| #include <std/mem.pat> | |
| #include <std/string.pat> | |
| union Fourcc { | |
| char text[4]; | |
| u32 integer; | |
| }; | |
| enum ValueType: u8 { | |
| S8 = 'b', | |
| U8 = 'B', | |
| S32 = 'l', | |
| U32 = 'L', | |
| Ascii = 'c', | |
| F32 = 'f', | |
| Fourcc = 'F', | |
| U64 = 'J', | |
| S16 = 's', | |
| U16 = 'S', | |
| DateTime = 'U', | |
| Nested = 0, | |
| }; | |
| struct Header { | |
| // Fourcc fourcc; | |
| char fourcc[4]; | |
| ValueType type; | |
| u8 size; | |
| be u16 repeat; | |
| }; | |
| struct Kvl { | |
| Header header; | |
| std::print("{}, {}, {}", header.fourcc, header.size, header.repeat); | |
| match (header.type) { | |
| (ValueType::S8): { | |
| s8 values[header.size / 1 * header.repeat]; | |
| padding[std::mem::align_to(4, header.size * header.repeat) - header.size * header.repeat]; | |
| } | |
| (ValueType::U8): { | |
| u8 values[header.size / 1 * header.repeat]; | |
| padding[std::mem::align_to(4, header.size * header.repeat) - header.size * header.repeat]; | |
| } | |
| (ValueType::S32): { | |
| u32 values[header.size / 4 * header.repeat]; | |
| } | |
| (ValueType::U32): { | |
| u32 values[header.size / 4 * header.repeat]; | |
| } | |
| (ValueType::Ascii): { | |
| char value[header.size * header.repeat]; | |
| padding[std::mem::align_to(4, header.size * header.repeat) - header.size * header.repeat]; | |
| } | |
| (ValueType::F32): { | |
| float values[header.size / 4 * header.repeat]; | |
| } | |
| (ValueType::Fourcc): { | |
| Fourcc values[header.size / 4 * header.repeat]; | |
| } | |
| (ValueType::U64): { | |
| u64 values[header.size / 8 * header.repeat]; | |
| } | |
| (ValueType::S16): { | |
| s16 values[header.size / 2 * header.repeat]; | |
| padding[std::mem::align_to(4, header.size * header.repeat) - header.size * header.repeat]; | |
| } | |
| (ValueType::U16): { | |
| u16 values[header.size / 2 * header.repeat]; | |
| padding[std::mem::align_to(4, header.size * header.repeat) - header.size * header.repeat]; | |
| } | |
| (ValueType::DateTime): { | |
| char values[16]; | |
| } | |
| (ValueType::Nested): { | |
| Kvl children[while($ < addressof(this) + 8 + std::mem::align_to(4, header.size * header.repeat))]; | |
| } | |
| (_): { | |
| u8 raw_data[std::mem::align_to(4, header.size * header.repeat)]; | |
| } | |
| } | |
| }; | |
| Kvl kvl[while(std::mem::read_unsigned($, 4) != 0x000000)] @ 0x00; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment