Encode_iterate_split_ text byte/hex pattern/sequence _hoopsnake

Want to encode some raw text byte/hex pattern/sequences with GH,Python or C#. Goal: 8bit Grayscale images.
kind of run length structure: 4 or 1 byte chunks but you have to extract chunksize inside every chunk.
So does anybody have fast python code to compare every first byte pair of a chunk, read the bytes (4 or one)
and then get the startindex/offset of the next chunk. iterate and maybe draw the decompressed pixels.

tried hoopsnake iterations but too slow for large files. octopus loop not possible.
encode_hoopsnake.gh (23.0 KB)

hex_small example 4x4.txt (19 Bytes)

hex_large_1466x1477.txt (150.1 KB)

Sorry, want to DECODE the text files.