| 1093 | | /* |
| 1094 | | Append n to binary in big-endian byte format. |
| 1095 | | */ |
| 1096 | | static void _appendAsBytes( UThread* ut, UCell* bcell, |
| 1097 | | int32_t n, int byteCount ) |
| 1098 | | { |
| 1099 | | uint8_t* bp; |
| 1100 | | UBinary* bin = ur_bin( bcell ); |
| 1101 | | |
| 1102 | | ur_arrayReserve( bin, 1, bin->used + byteCount ); |
| 1103 | | bp = bin->ptr.b + bin->used; |
| 1104 | | bin->used += byteCount; |
| 1105 | | |
| | 1093 | static void _intToBytes( int n, uint8_t* bp, int byteCount ) |
| | 1094 | { |
| | 1116 | } |
| | 1117 | |
| | 1118 | |
| | 1119 | /* |
| | 1120 | Append n to binary in big-endian byte format. |
| | 1121 | */ |
| | 1122 | static void _appendAsBytes( UThread* ut, UCell* bcell, |
| | 1123 | int32_t n, int byteCount ) |
| | 1124 | { |
| | 1125 | UBinary* bin = ur_bin( bcell ); |
| | 1126 | |
| | 1127 | ur_arrayReserve( bin, 1, bin->used + byteCount ); |
| | 1128 | _intToBytes( n, bin->ptr.b + bin->used, byteCount ); |
| | 1129 | bin->used += byteCount; |
| | 1130 | |
| 2573 | | UBinary* s1; |
| 2574 | | |
| 2575 | | if( ur_is(tos, UT_STRING) ) |
| 2576 | | { |
| 2577 | | if( ur_encCharSize(tos) != 1 ) |
| | 2576 | UBinary* s1 = ur_bin(a1); |
| | 2577 | |
| | 2578 | switch( ur_type(tos) ) |
| | 2579 | { |
| | 2580 | case UT_CHAR: |
| | 2581 | case UT_INT: |
| | 2582 | { |
| | 2583 | uint8_t bytes[ 4 ]; |
| | 2584 | |
| | 2585 | if( part < 1 ) |
| | 2586 | part = 1; |
| | 2587 | else if( part > 4 ) |
| | 2588 | goto type_err; |
| | 2589 | |
| | 2590 | _intToBytes( ur_int(tos), bytes, part ); |
| | 2591 | a1->series.it = _changeBytes( s1, a1->series.it, |
| | 2592 | (char*) bytes, part, 0 ); |
| | 2593 | } |
| | 2594 | break; |
| | 2595 | |
| | 2596 | case UT_STRING: |
| | 2597 | if( ur_encCharSize(tos) != 1 ) |
| | 2598 | goto type_err; |
| | 2599 | // Fall through... |
| | 2600 | |
| | 2601 | case UT_BINARY: |
| | 2602 | { |
| | 2603 | UBinary* s2 = ur_bin(tos); |
| | 2604 | a1->series.it = _changeBytes( s1, a1->series.it, |
| | 2605 | s2->ptr.c + tos->series.it, |
| | 2606 | ur_sliceEnd(tos, s2) - tos->series.it, |
| | 2607 | part ); |
| | 2608 | } |
| | 2609 | break; |
| | 2610 | |
| | 2611 | default: |
| 2580 | | else if( ! ur_is(tos, UT_BINARY) ) |
| 2581 | | { |
| 2582 | | goto type_err; |
| 2583 | | } |
| 2584 | | |
| 2585 | | s1 = ur_bin(a1); |
| 2586 | | assert( a1->series.it <= s1->used ); |
| 2587 | | |
| 2588 | | if( ur_is(tos, UT_CHAR) ) |
| 2589 | | { |
| 2590 | | if( a1->series.it == s1->used ) |
| 2591 | | { |
| 2592 | | ur_arrayReserve( s1, sizeof(char), 1 ); |
| 2593 | | ++s1->used; |
| 2594 | | } |
| 2595 | | s1->ptr.b[ a1->series.it ] = ur_char(tos); |
| 2596 | | a1->series.it += 1; |
| 2597 | | } |
| 2598 | | else |
| 2599 | | { |
| 2600 | | a1->series.it = _changeBytes( s1, a1->series.it, |
| 2601 | | ur_bin(tos), tos->series.it, |
| 2602 | | part ); |
| 2603 | | } |
| | 2614 | |