Skip to content

Commit

Permalink
check optional in serialization (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
larshp authored Aug 28, 2023
1 parent c75605d commit c99811f
Show file tree
Hide file tree
Showing 5 changed files with 564 additions and 19 deletions.
5 changes: 4 additions & 1 deletion abaplint.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@
"prefer_pragmas": true,
"no_chained_assignment": true,
"check_subrc": true,
"cyclomatic_complexity": true,
"cyclomatic_complexity": {
"exclude": ["test/generated"],
"max": 20
},
"dangerous_statement": true,
"db_operation_in_loop": true,
"select_add_order_by": true,
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"homepage": "https://github.com/heliconialabs/abap-protobuf#readme",
"devDependencies": {
"@abaplint/cli": "^2.102.30",
"@abaplint/cli": "^2.102.31",
"@abaplint/runtime": "^2.7.83",
"@abaplint/transpiler-cli": "^2.7.83"
}
Expand Down
26 changes: 18 additions & 8 deletions src/generator/zcl_protobuf_generate_clas.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,13 @@ CLASS zcl_protobuf_generate_clas IMPLEMENTATION.
WHEN TYPE zcl_protobuf2_field INTO DATA(lo_field).
lv_name = |is_message-{ zcl_protobuf_generate=>abap_name( lo_field->mv_field_name ) }|.
gv_impl = gv_impl && |" { lo_field->zif_protobuf2_artefact~serialize( ) }\n|.
IF lo_field->mv_label = 'repeated'.
gv_impl = gv_impl && | LOOP AT { lv_name } INTO DATA(lv_{ zcl_protobuf_generate=>abap_name( lo_field->mv_field_name ) }).\n|.
lv_name = |lv_{ zcl_protobuf_generate=>abap_name( lo_field->mv_field_name ) }|.
ENDIF.
CASE lo_field->mv_label.
WHEN 'repeated'.
gv_impl = gv_impl && | LOOP AT { lv_name } INTO DATA(lv_{ zcl_protobuf_generate=>abap_name( lo_field->mv_field_name ) }).\n|.
lv_name = |lv_{ zcl_protobuf_generate=>abap_name( lo_field->mv_field_name ) }|.
WHEN 'optional'.
gv_impl = gv_impl && | IF { lv_name } IS NOT INITIAL.\n|.
ENDCASE.

IF zcl_protobuf_generate=>is_builtin( lo_field->mv_type ) = abap_true.
gv_impl = gv_impl && | lo_stream->encode_field_and_type2(\n|.
Expand Down Expand Up @@ -105,9 +108,12 @@ CLASS zcl_protobuf_generate_clas IMPLEMENTATION.
gv_impl = gv_impl && | lo_stream->encode_delimited( ser_{ zcl_protobuf_generate=>abap_name( lo_field->mv_type ) }( { lv_name } ) ).\n|.
ENDIF.

IF lo_field->mv_label = 'repeated'.
gv_impl = gv_impl && | ENDLOOP.\n|.
ENDIF.
CASE lo_field->mv_label.
WHEN 'repeated'.
gv_impl = gv_impl && | ENDLOOP.\n|.
WHEN 'optional'.
gv_impl = gv_impl && | ENDIF.\n|.
ENDCASE.
ENDCASE.
ENDLOOP.

Expand Down Expand Up @@ -146,7 +152,11 @@ CLASS zcl_protobuf_generate_clas IMPLEMENTATION.
ENDIF.
gv_impl = gv_impl && | |.
IF lo_field->mv_label = 'repeated'.
gv_impl = gv_impl && |INSERT { lv_name } INTO TABLE rs_message-{ zcl_protobuf_generate=>abap_name( lo_field->mv_field_name ) }.\n|.
IF lo_field->mv_type = 'int64'.
gv_impl = gv_impl && |ASSERT 1 = 'todo'.\n|.
ELSE.
gv_impl = gv_impl && |INSERT { lv_name } INTO TABLE rs_message-{ zcl_protobuf_generate=>abap_name( lo_field->mv_field_name ) }.\n|.
ENDIF.
ELSE.
gv_impl = gv_impl && |rs_message-{ zcl_protobuf_generate=>abap_name( lo_field->mv_field_name ) } = { lv_name }.\n|.
ENDIF.
Expand Down
Loading

0 comments on commit c99811f

Please sign in to comment.