make MsbCont morphism generic over item type
This commit is contained in:
parent
4b824cbb7c
commit
1869176bb7
2 changed files with 16 additions and 24 deletions
morphisms
|
@ -27,37 +27,20 @@ morph_array_as_lenpfx_to_valterm (Terminator:native.UInt8)
|
|||
return 0;
|
||||
```
|
||||
|
||||
morph_array_as_lenpfx_to_continuation_bit_8 ()
|
||||
<Seq~<LengthPrefix native.UInt64> native.UInt8>
|
||||
--> <Seq~MsbCont native.UInt8>
|
||||
morph_array_as_lenpfx_to_continuation_bit (T:Type)
|
||||
<Seq~<LengthPrefix native.UInt64> T>
|
||||
--> <Seq~MsbCont T>
|
||||
```
|
||||
for( uint64_t i = 0; i < src->len; ++i ) {
|
||||
if( src->items[i] & (1<<7) ) {
|
||||
const size_t n_bits = 8*sizeof(T);
|
||||
if( src->items[i] & (1<<(n_bits-1)) ) {
|
||||
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 native.UInt64> native.UInt16>
|
||||
--> <Seq~MsbCont native.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);
|
||||
dst[i] |= (1<<(n_bits-1));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue