Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
larshp committed Jan 2, 2024
1 parent 07582e1 commit f9ab424
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 7 deletions.
49 changes: 42 additions & 7 deletions src/stream/zcl_protobuf_stream.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -402,22 +402,57 @@ CLASS zcl_protobuf_stream IMPLEMENTATION.

METHOD encode_int64.

DATA lv_bits TYPE string.

IF iv_int > 0.
DATA lv_bits TYPE string.
DATA lv_bit TYPE c LENGTH 1.
DATA lv_hex TYPE x LENGTH 1.
DATA lv_index TYPE i.
DATA lv_offset TYPE i.
DATA lv_byteno TYPE i.
DATA lv_int TYPE int8.

IF iv_int >= 0.
ro_ref = encode_varint( iv_int ).
ELSE.
DATA(lv_int) = abs( iv_int + 1 ).
" WRITE / iv_int.
lv_int = -1 * ( iv_int + 1 ).

WHILE lv_int > 0.
DATA(lv_bit) = lv_int MOD 2.
" WRITE / lv_int.
lv_bit = lv_int MOD 2.
CONCATENATE lv_bit lv_bits INTO lv_bits.
lv_int = lv_int DIV 2.
ENDWHILE.

WRITE / lv_bits.
WHILE strlen( lv_bits ) < 64.
CONCATENATE '0' lv_bits INTO lv_bits.
ENDWHILE.

" WRITE / lv_bits.
TRANSLATE lv_bits USING '0110'.
* extra bits to fill the last byte
CONCATENATE '000000' lv_bits INTO lv_bits.
" WRITE / lv_bits.

lv_offset = 70 - 7.
* 10 bytes to encode 64 bits
DO 10 TIMES.
lv_byteno = sy-index.
CLEAR lv_hex.
* add continuation bits, 1 for every 7 bits
IF lv_byteno <> 10.
SET BIT 1 OF lv_hex TO 1.
ENDIF.

DO 7 TIMES.
lv_index = sy-index + 1.
SET BIT lv_index OF lv_hex TO lv_bits+lv_offset(1).
lv_offset = lv_offset + 1.
ENDDO.
" WRITE / lv_hex.
append( lv_hex ).
lv_offset = lv_offset - 14.
ENDDO.

ASSERT 1 = 'todo'.
ENDIF.

ENDMETHOD.
Expand Down
11 changes: 11 additions & 0 deletions src/stream/zcl_protobuf_stream.clas.testclasses.abap
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ CLASS ltcl_test DEFINITION FOR TESTING DURATION SHORT RISK LEVEL HARMLESS FINAL.
METHODS decode_int32_negative_six FOR TESTING RAISING cx_static_check.
METHODS decode_int32_positive_one FOR TESTING RAISING cx_static_check.
METHODS encode_int32_negative_six FOR TESTING RAISING cx_static_check.
METHODS encode_int32_negative_thousand FOR TESTING RAISING cx_static_check.
ENDCLASS.

CLASS ltcl_test IMPLEMENTATION.
Expand Down Expand Up @@ -171,4 +172,14 @@ CLASS ltcl_test IMPLEMENTATION.

ENDMETHOD.

METHOD encode_int32_negative_thousand.

mo_cut->encode_int32( -1000 ).

cl_abap_unit_assert=>assert_equals(
exp = '98F8FFFFFFFFFFFFFF01'
act = mo_cut->get( ) ).

ENDMETHOD.

ENDCLASS.

0 comments on commit f9ab424

Please sign in to comment.