From 4a5977ec8eede54635fdc2737c602c14cb54fd97 Mon Sep 17 00:00:00 2001 From: Michael Sippel <micha@fragmental.art> Date: Thu, 20 Feb 2025 05:22:28 +0100 Subject: [PATCH] add morphisms to Msb-ContinuationBit Sequences --- morphisms/length_prefix.morphism-base | 49 +++++++++++++++++++++++---- src/main.rs | 3 +- 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/morphisms/length_prefix.morphism-base b/morphisms/length_prefix.morphism-base index e5ad529..810f4ce 100644 --- a/morphisms/length_prefix.morphism-base +++ b/morphisms/length_prefix.morphism-base @@ -3,22 +3,57 @@ morph_array_as_valterm_to_lenpfx (Terminator:x86.UInt8) --> <Seq~<LengthPrefix x86.UInt64> x86.UInt8> ``` length_prefix_uint8_array_clear(dst); - while( *src != Terminator ) { - length_prefix_uint8_array_push(dst, *src); - src++; - } + while( *src != Terminator ) + length_prefix_uint8_array_push(dst, *src++); return 0; ``` + morph_array_as_lenpfx_to_valterm (Terminator:x86.UInt8) <Seq~<LengthPrefix x86.UInt64> x86.UInt8> --> <Seq~<ValueTerminated Terminator> x86.UInt8> ``` - for( uint64_t i = 0; i < src->len; ++i ) { - *dst ++ = src->items[i]; - } + for( uint64_t i = 0; i < src->len; ++i ) + *dst++ = src->items[i]; + *dst = Terminator; return 0; ``` + +morph_array_as_lenpfx_to_continuation_bit_8 () + <Seq~<LengthPrefix x86.UInt64> x86.UInt8> +--> <Seq~MsbCont x86.UInt8> +``` + for( uint64_t i = 0; i < src->len; ++i ) { + if( src->items[i] & (1<<7) ) { + fprintf(stderr, "error: value to high for MsbContinuation\n"); + return -1; + } + + dst[i] = src->items[i]; + if( i+1 < src->len ) + dst[i] |= (1<<7); + } + + return 0; +``` + +morph_array_as_lenpfx_to_continuation_bit_16 () + <Seq~<LengthPrefix x86.UInt64> x86.UInt16> +--> <Seq~MsbCont x86.UInt16> +``` + for( uint64_t i = 0; i < src->len; ++i ) { + if( src->items[i] & (1<<15) ) { + fprintf(stderr, "error: value to high for MsbContinuation\n"); + return -1; + } + + dst[i] = src->items[i]; + if( i+1 < src->len ) + dst[i] |= (1<<15); + } + + return 0; +``` diff --git a/src/main.rs b/src/main.rs index 8779e31..6240852 100644 --- a/src/main.rs +++ b/src/main.rs @@ -358,7 +358,8 @@ fn parser( fn main() { let mut type_dict = Arc::new(RwLock::new(BimapTypeDict::new())); let mut morphism_base = laddertypes::MorphismBase::<LdmcMorphism>::new(vec![ - type_dict.parse("Seq~<ValueTerminated '\\0'>").expect(""), + //type_dict.parse("Seq~MsbCont").expect(""), + //type_dict.parse("Seq~<ValueTerminated '\\0'>").expect(""), type_dict.parse("Seq~<LengthPrefix x86.UInt64>").expect("") ]);