Compare commits

..

No commits in common. "c341e973b1ac02618e95c890234bdccab1e67493" and "7ac2113e60fb9dae285d1276ee9499cae14d3965" have entirely different histories.

6 changed files with 0 additions and 135 deletions

1
axl.h
View file

@ -5,6 +5,5 @@
#include "axl_memory.h"
#include "axl_string.h"
#include "axl_io.h"
#include "axl_vlq.h"
#endif

View file

@ -15,21 +15,4 @@ typedef unsigned long long u64;
#define false 0
#define NULL ((void*)0)
// Minimum and maximum values for integer types
#define I8_MIN (-128)
#define I8_MAX 127
#define U8_MAX 255
#define I16_MIN (-32768)
#define I16_MAX 32767
#define U16_MAX 65535
#define I32_MIN (-2147483647 - 1)
#define I32_MAX 2147483647
#define U32_MAX 4294967295U
#define I64_MIN (-9223372036854775807LL - 1LL)
#define I64_MAX 9223372036854775807LL
#define U64_MAX 18446744073709551615ULL
#endif // !AXL_TYPES_H

View file

@ -1,57 +0,0 @@
#include "axl_vlq.h"
u32 axl_vlq_encode(u32 num, u8* out)
{
u8 buf[5];
int pos = 0;
if(num == 0)
{
out[0] = 0;
return 1;
}
while(num > 0)
{
buf[pos] = num & 0x7F;
num >>= 7;
pos++;
}
for(int j = pos - 1; j > 0; j--)
{
buf[j] |= 0x80;
}
for(int j = pos - 1; j >= 0; j--)
{
*out++ = buf[j];
}
return pos;
}
u32 axl_vlq_decode(const u8* in, u32* num)
{
*num = 0;
u32 pos = 0;
while(pos < AXL_VLQ_MAX_LEN)
{
u8 b = in[pos++];
*num = (*num << 7) | (b & 0x7F);
if(!(b & 0x80))
{
return pos;
}
if(*num > (U32_MAX >> 7))
{
return 0;
}
}
return 0;
}

View file

@ -1,11 +0,0 @@
#ifndef AXL_VLQ_H
#define AXL_VLQ_H
#include "axl_types.h"
#define AXL_VLQ_MAX_LEN 5
u32 axl_vlq_encode(u32 num, u8* out);
u32 axl_vlq_decode(const u8* in, u32* num);
#endif // !AXL_VLQ_H

View file

@ -1,30 +0,0 @@
#include "axl_koan.h"
#include "axl_memory.h"
#include "axl_types.h"
#include "axl_vlq.h"
KOAN(vlq_basic_encode_decode)
{
u32 expected[] = {0, 126, 129, 256, 65535, 70000, 9999999, U32_MAX};
u32 expected_len[] = {1, 1, 2, 2, 3, 3, 4, 5 };
u8 encoded[AXL_VLQ_MAX_LEN];
for(u32 i = 0; i < sizeof(expected) / sizeof(expected[0]); i++)
{
u32 encoded_len = axl_vlq_encode(expected[i], encoded);
u32 decoded = 0;
u32 decoded_len = axl_vlq_decode(encoded, &decoded);
ASSERT_UINT_EQ(expected_len[i], encoded_len);
ASSERT_UINT_EQ(expected_len[i], decoded_len);
ASSERT_UINT_EQ(expected[i], decoded);
}
}
int main(void)
{
axl_init();
return koan_run_all();
}

19
main.c
View file

@ -1,5 +1,4 @@
#include "axl.h"
#include "axl_vlq.h"
#include <windows.h>
int _start(void)
@ -30,23 +29,5 @@ int _start(void)
(void)fds;
(void)f;
u32 new_len = 0;
u8 src[] = "Bonjour le monde!";
u32 src_len = axl_strlen((i8*)src);
for(u32 i = 0; i < src_len; i += 4)
{
u8 buff[AXL_VLQ_MAX_LEN + 1];
u32 encoded_l = axl_vlq_encode(*((u32*)(src + i)), buff);
new_len += encoded_l;
buff[encoded_l] = '\0';
axl_puts((i8*)buff);
}
(void)new_len;
return 0;
}