improve makefile, add morphisms for 8bit sized length-prefix array & add test for posint radix conversion
This commit is contained in:
parent
06227a2731
commit
475d6d43ba
8 changed files with 288 additions and 46 deletions
morphisms
60
morphisms/test.c
Normal file
60
morphisms/test.c
Normal file
|
@ -0,0 +1,60 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <morphisms/length_prefix.h>
|
||||
#include <morphisms/posint.h>
|
||||
|
||||
int main( int argc, char * argv[] ) {
|
||||
char * int1 = malloc(4096);
|
||||
struct LengthPrefixUInt8Array * int2 = malloc(4096);
|
||||
struct LengthPrefixUInt64Array * int3 = malloc(4096);
|
||||
struct LengthPrefixUInt64Array * int4 = malloc(4096);
|
||||
struct LengthPrefixUInt64Array * int5 = malloc(4096);
|
||||
struct LengthPrefixUInt64Array * int6 = malloc(4096);
|
||||
struct LengthPrefixUInt8Array * int7 = malloc(4096);
|
||||
char * int8 = malloc(4096);
|
||||
|
||||
// ℕ ~ <PosInt 10 BigEndian> ~ [~<ValueDelim '\0'> <Digit 10> ~ Char ~ Ascii]
|
||||
scanf("%s", int1);
|
||||
|
||||
// morph to
|
||||
// ℕ ~ <PosInt 10 BigEndian> ~ [~<LengthPrefix x86.UInt64> <Digit 10> ~ Char ~ Ascii]
|
||||
morph_string_as_nullterm_to_length_prefix( int1, int2 );
|
||||
|
||||
// morph to
|
||||
// ℕ ~ <PosInt 10 BigEndian> ~ [~<LengthPrefix x86.UInt64> <Digit 10> ~ ℤ_10 ~ x86.UInt64]
|
||||
int3->len = int2->len;
|
||||
for( uint64_t i = 0; i < int2->len; ++i )
|
||||
morph_digit_as_char_to_uint64( &int2->items[i], &int3->items[i] );
|
||||
|
||||
// morph to
|
||||
// ℕ ~ <PosInt 10 LittleEndian> ~ [~<LengthPrefix x86.UInt64> <Digit 10> ~ ℤ_10 ~ x86.UInt64]
|
||||
morph_posint_endianness( 10, int3, int4 );
|
||||
|
||||
// morph to
|
||||
// ℕ ~ <PosInt 16 LittleEndian> ~ [~<LengthPrefix x86.UInt64> <Digit 16> ~ ℤ_16 ~ x86.UInt64]
|
||||
morph_posint_radix(
|
||||
10,
|
||||
16,
|
||||
int4,
|
||||
int5
|
||||
);
|
||||
|
||||
// morph to
|
||||
// ℕ ~ <PosInt 16 BigEndian> ~ [~<LengthPrefix x86.UInt64> <Digit 16> ~ ℤ_16 ~ x86.UInt64]
|
||||
morph_posint_endianness( 10, int5, int6 );
|
||||
|
||||
// morph to
|
||||
// ℕ ~ <PosInt 16 BigEndian> ~ [~<LengthPrefix x86.UInt64> <Digit 16> ~ Char ~ Ascii]
|
||||
int7->len = int6->len;
|
||||
for( uint64_t i = 0; i < int6->len; ++i )
|
||||
morph_digit_as_uint64_to_char( &int6->items[i], &int7->items[i] );
|
||||
|
||||
// morph to
|
||||
// ℕ ~ <PosInt 16 BigEndian> ~ [~<ValueDelim '\0'> <Digit 16> ~ Char ~ Ascii]
|
||||
morph_string_as_length_prefix_to_nullterm( int7, int8 );
|
||||
|
||||
printf("%s\n", int8);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue