axl_rle_decode
This commit is contained in:
parent
a4f8b9ca30
commit
ad12631a1a
2 changed files with 59 additions and 2 deletions
28
axl_rle.c
28
axl_rle.c
|
|
@ -40,5 +40,33 @@ u32 axl_rle_encode(const u8* src, u32 src_size, u8* dst, u32 dst_size)
|
|||
|
||||
u32 axl_rle_decode(const u8* src, u32 src_size, u8* dst, u32 dst_size)
|
||||
{
|
||||
const u8* head = src;
|
||||
u32 used_size = 0;
|
||||
|
||||
while(head < src + src_size)
|
||||
{
|
||||
u32 repeat_count;
|
||||
u32 vlq_len = axl_vlq_decode(head, &repeat_count);
|
||||
|
||||
if(vlq_len == 0 || head + vlq_len + 1 >= src + src_size)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
head += vlq_len;
|
||||
const u8 value = *head;
|
||||
head++;
|
||||
|
||||
used_size += repeat_count;
|
||||
|
||||
if(used_size > dst_size)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
axl_memset(dst, value, repeat_count);
|
||||
dst += repeat_count;
|
||||
}
|
||||
|
||||
return used_size;
|
||||
}
|
||||
|
|
|
|||
33
main.c
33
main.c
|
|
@ -2,14 +2,20 @@
|
|||
#include "axl_io.h"
|
||||
#include "axl_memory.h"
|
||||
#include "axl_string.h"
|
||||
#include "axl_vlq.h"
|
||||
#include "axl_rle.h"
|
||||
#include "axl_memory.h"
|
||||
#include <windows.h>
|
||||
|
||||
void *memset(void *s, int c, size_t n)
|
||||
void* memset(void *s, int c, size_t n)
|
||||
{
|
||||
return axl_memset(s, (i8)c, n);
|
||||
}
|
||||
|
||||
void* memcpy(void* dst, const void * src, unsigned long long count)
|
||||
{
|
||||
return axl_memcpy(dst, src, (u32)count);
|
||||
}
|
||||
|
||||
int _start(void)
|
||||
{
|
||||
SetConsoleOutputCP(CP_UTF8);
|
||||
|
|
@ -59,6 +65,29 @@ int _start(void)
|
|||
axl_puts("}");
|
||||
}
|
||||
|
||||
i8 original[] = "00000000022222255555554444444443333339999435999923";
|
||||
i8 encoded[2*sizeof(original)] = {'\0'};
|
||||
i8 decoded[sizeof(original)];
|
||||
|
||||
axl_puts(original);
|
||||
u32 encoded_len = axl_rle_encode((u8*)original, sizeof(original),
|
||||
(u8*)encoded, sizeof(encoded));
|
||||
axl_puts(encoded);
|
||||
axl_rle_decode((u8*)encoded, encoded_len, (u8*)decoded, sizeof(original));
|
||||
axl_puts(decoded);
|
||||
|
||||
i8 orig_size_str[10] = {'\0'};
|
||||
i8 enc_size_str[10] = {'\0'};
|
||||
|
||||
axl_utoa(sizeof(original), orig_size_str, 10);
|
||||
axl_utoa(encoded_len, enc_size_str, 10);
|
||||
|
||||
i8 text_buff[255] = {'\0'};
|
||||
axl_strcat(text_buff, "Original length: ");
|
||||
axl_strcat(text_buff, orig_size_str);
|
||||
axl_strcat(text_buff, "\nEncoded length: ");
|
||||
axl_strcat(text_buff, enc_size_str);
|
||||
axl_puts(text_buff);
|
||||
|
||||
/*u32 new_len = 0;*/
|
||||
/*u8 src[] = "Bonjour le monde!";*/
|
||||
|
|
|
|||
Loading…
Reference in a new issue