Skip to content

Commit

Permalink
uint64
Browse files Browse the repository at this point in the history
  • Loading branch information
larshp committed Aug 30, 2023
1 parent 3fa55e8 commit 63333a0
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 130 deletions.
2 changes: 1 addition & 1 deletion src/generator/zcl_protobuf_generate.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ CLASS zcl_protobuf_generate IMPLEMENTATION.
" 'string' cannot be redefined
rv_abap = rv_abap && | TYPES int32 TYPE i.\n|.
rv_abap = rv_abap && | TYPES uint32 TYPE int8.\n|.
rv_abap = rv_abap && | TYPES uint64 TYPE int8.\n|. " hmm
rv_abap = rv_abap && | TYPES int64 TYPE int8.\n|.
rv_abap = rv_abap && | TYPES uint64 TYPE p LENGTH 11.\n|.
rv_abap = rv_abap && | TYPES bool TYPE abap_bool.\n|.
rv_abap = rv_abap && | TYPES bytes TYPE xstring.\n|.
rv_abap = rv_abap && | TYPES double TYPE f.\n|.
Expand Down
4 changes: 3 additions & 1 deletion src/generator/zcl_protobuf_generate_clas.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,10 @@ CLASS zcl_protobuf_generate_clas IMPLEMENTATION.
lv_name = |lo_stream->decode_delimited( )|.
WHEN 'int32'.
lv_name = |lo_stream->decode_varint( )|.
WHEN 'int64' OR 'uint64' OR 'uint32'.
WHEN 'int64' OR 'uint32'.
lv_name = |lo_stream->decode_varint_int8( )|.
WHEN 'uint64'.
lv_name = |lo_stream->decode_uint64( )|.
ENDCASE.
ELSEIF io_message->is_enum( lo_field->mv_type ) OR go_file->is_enum( lo_field->mv_type ).
lv_name = |lo_stream->decode_varint( )|.
Expand Down
22 changes: 22 additions & 0 deletions src/stream/zcl_protobuf_stream.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ CLASS zcl_protobuf_stream DEFINITION
bit32 TYPE ty_wire_type VALUE 5,
END OF gc_wire_type .

TYPES ty_uint64 TYPE p LENGTH 11.

METHODS constructor
IMPORTING
!iv_hex TYPE xstring OPTIONAL .
Expand All @@ -39,6 +41,9 @@ CLASS zcl_protobuf_stream DEFINITION
METHODS decode_varint_int8
RETURNING
VALUE(rv_int) TYPE int8 .
METHODS decode_uint64
RETURNING
VALUE(rv_int) TYPE ty_uint64 .
METHODS decode_bool
RETURNING
VALUE(rv_bool) TYPE abap_bool .
Expand Down Expand Up @@ -207,6 +212,23 @@ CLASS zcl_protobuf_stream IMPLEMENTATION.

ENDMETHOD.

METHOD decode_uint64.
DATA lv_topbit TYPE i.
DATA lv_lower TYPE ty_uint64.
DATA lv_shift TYPE ty_uint64 VALUE 1.

DO.
lv_topbit = mv_hex(1) DIV 128.
lv_lower = mv_hex(1) MOD 128.
lv_lower = lv_lower * lv_shift.
rv_int = rv_int + lv_lower.
lv_shift = lv_shift * 128.
eat( 1 ).
IF lv_topbit = 0.
EXIT.
ENDIF.
ENDDO.
ENDMETHOD.

METHOD eat.
ASSERT xstrlen( mv_hex ) >= iv_length.
Expand Down
Loading

0 comments on commit 63333a0

Please sign in to comment.