All files / src/git/zlib zcl_abapgit_zlib_stream.clas.abap

100% Statements 106/106
100% Branches 4/4
100% Functions 1/1
100% Lines 106/106

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 1071x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1063x 1063x 1063x 1063x 1x 1x 1058x 1058x 1058x 6253x 6253x 6253x 6253x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
CLASS zcl_abapgit_zlib_stream DEFINITION
  PUBLIC
  CREATE PUBLIC .
 
  PUBLIC SECTION.
 
    METHODS constructor
      IMPORTING
        !iv_data TYPE xstring .
    METHODS take_bits
      IMPORTING
        !iv_length     TYPE i
      RETURNING
        VALUE(rv_bits) TYPE string .
    METHODS take_int
      IMPORTING
        !iv_length    TYPE i
      RETURNING
        VALUE(rv_int) TYPE i .
    METHODS remaining
      RETURNING
        VALUE(rv_length) TYPE i .
    "! Take bytes, there's an implicit realignment to start at the beginning of a byte
    "! i.e. if next bit of current byte is not the first bit, then this byte is skipped
    "! and the bytes are taken from the next one.
    "! @parameter iv_length | <p class="shorttext synchronized" lang="en"></p>
    "! @parameter rv_bytes | <p class="shorttext synchronized" lang="en"></p>
    METHODS take_bytes
      IMPORTING
        !iv_length      TYPE i
      RETURNING
        VALUE(rv_bytes) TYPE xstring .
    METHODS clear_bits .
  PROTECTED SECTION.
  PRIVATE SECTION.
 
    DATA mv_bits TYPE string .
    DATA mv_compressed TYPE xstring .
ENDCLASS.
 
 
 
CLASS ZCL_ABAPGIT_ZLIB_STREAM IMPLEMENTATION.
 
 
  METHOD clear_bits.
    CLEAR mv_bits.
  ENDMETHOD.
 
 
  METHOD constructor.
 
    mv_compressed = iv_data.
 
  ENDMETHOD.
 
 
  METHOD remaining.
 
    rv_length = xstrlen( mv_compressed ) + 1.
 
  ENDMETHOD.
 
 
  METHOD take_bits.
 
    DATA: lv_left  TYPE i,
          lv_index TYPE i,
          lv_x     TYPE x LENGTH 1.
 
 
    WHILE strlen( rv_bits ) < iv_length.
      IF mv_bits IS INITIAL.
        lv_x = mv_compressed(1).
        mv_bits = zcl_abapgit_zlib_convert=>hex_to_bits( lv_x ).
        mv_compressed = mv_compressed+1.
      ENDIF.
      lv_left = iv_length - strlen( rv_bits ).
      IF lv_left >= strlen( mv_bits ).
        CONCATENATE mv_bits rv_bits INTO rv_bits.
        CLEAR mv_bits.
      ELSE.
        lv_index = strlen( mv_bits ) - lv_left.
        CONCATENATE mv_bits+lv_index(lv_left) rv_bits INTO rv_bits.
        mv_bits = mv_bits(lv_index).
      ENDIF.
 
    ENDWHILE.
 
  ENDMETHOD.
 
 
  METHOD take_bytes.
 
    rv_bytes = mv_compressed(iv_length).
    mv_compressed = mv_compressed+iv_length.
 
  ENDMETHOD.
 
 
  METHOD take_int.
 
    rv_int = zcl_abapgit_zlib_convert=>bits_to_int( take_bits( iv_length ) ).
 
  ENDMETHOD.
ENDCLASS.