-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
249 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: test | ||
|
||
on: | ||
pull_request: | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
unit: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 5 | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: '20' | ||
- run: npm install | ||
- run: npm test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
output | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"global": { | ||
"files": "/src/**/*.*" | ||
}, | ||
"dependencies": [ | ||
{ | ||
"url": "https://github.com/open-abap/open-abap-core", | ||
"folder": "/deps", | ||
"files": "/src/**/*.*" | ||
} | ||
], | ||
"syntax": { | ||
"version": "v702", | ||
"errorNamespace": "." | ||
}, | ||
"rules": { | ||
"begin_end_names": true, | ||
"check_ddic": true, | ||
"check_include": true, | ||
"check_syntax": true, | ||
"global_class": true, | ||
"implement_methods": true, | ||
"method_implemented_twice": true, | ||
"parser_error": true, | ||
"superclass_final": true, | ||
"unknown_types": true, | ||
"xml_consistency": true | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "crc32c", | ||
"private": true, | ||
"version": "1.0.0", | ||
"description": "CRC32C (Castagnoli)", | ||
"scripts": { | ||
"transpile": "rm -rf output && abap_transpile", | ||
"unit": "npm run transpile && echo RUNNING && node output/index.mjs && echo OK", | ||
"lint": "abaplint", | ||
"test": "npm run lint && npm run unit" | ||
}, | ||
"author": "Lars Hvam Petersen", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@abaplint/cli": "^2.102.42", | ||
"@abaplint/runtime": "^2.7.97", | ||
"@abaplint/transpiler-cli": "^2.7.97" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
CLASS zcl_crc32c DEFINITION PUBLIC. | ||
PUBLIC SECTION. | ||
TYPES ty_crc TYPE x LENGTH 4. | ||
|
||
CLASS-METHODS run | ||
IMPORTING | ||
iv_xstring TYPE xstring | ||
RETURNING | ||
VALUE(rv_crc) TYPE ty_crc. | ||
PRIVATE SECTION. | ||
CLASS-DATA crc32_map TYPE xstring. | ||
ENDCLASS. | ||
|
||
CLASS zcl_crc32c IMPLEMENTATION. | ||
METHOD run. | ||
* https://en.wikipedia.org/wiki/Cyclic_redundancy_check | ||
|
||
CONSTANTS: magic_nr TYPE x LENGTH 4 VALUE '82F63B78', | ||
mffffffff TYPE x LENGTH 4 VALUE 'FFFFFFFF', | ||
m7fffffff TYPE x LENGTH 4 VALUE '7FFFFFFF', | ||
m00ffffff TYPE x LENGTH 4 VALUE '00FFFFFF', | ||
m000000ff TYPE x LENGTH 4 VALUE '000000FF', | ||
m000000 TYPE x LENGTH 3 VALUE '000000'. | ||
|
||
DATA: cindex TYPE x LENGTH 4, | ||
low_bit TYPE x LENGTH 4, | ||
len TYPE i, | ||
nindex TYPE i, | ||
crc TYPE x LENGTH 4 VALUE mffffffff, | ||
x4 TYPE x LENGTH 4, | ||
idx TYPE x LENGTH 4. | ||
|
||
IF xstrlen( crc32_map ) = 0. | ||
DO 256 TIMES. | ||
cindex = sy-index - 1. | ||
DO 8 TIMES. | ||
low_bit = '00000001'. | ||
low_bit = cindex BIT-AND low_bit. " c & 1 | ||
cindex = cindex DIV 2. | ||
cindex = cindex BIT-AND m7fffffff. " c >> 1 (top is zero, but in ABAP signed!) | ||
IF low_bit IS NOT INITIAL. | ||
cindex = cindex BIT-XOR magic_nr. | ||
ENDIF. | ||
ENDDO. | ||
CONCATENATE crc32_map cindex INTO crc32_map IN BYTE MODE. | ||
ENDDO. | ||
ENDIF. | ||
|
||
len = xstrlen( iv_xstring ). | ||
DO len TIMES. | ||
nindex = sy-index - 1. | ||
CONCATENATE m000000 iv_xstring+nindex(1) INTO idx IN BYTE MODE. | ||
idx = ( crc BIT-XOR idx ) BIT-AND m000000ff. | ||
idx = idx * 4. | ||
x4 = crc32_map+idx(4). | ||
crc = crc DIV 256. | ||
crc = crc BIT-AND m00ffffff. " c >> 8 | ||
crc = x4 BIT-XOR crc. | ||
ENDDO. | ||
crc = crc BIT-XOR mffffffff. | ||
|
||
rv_crc = crc. | ||
|
||
ENDMETHOD. | ||
ENDCLASS. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
CLASS ltcl_test DEFINITION FOR TESTING DURATION SHORT RISK LEVEL HARMLESS FINAL. | ||
PRIVATE SECTION. | ||
METHODS test FOR TESTING RAISING cx_static_check. | ||
ENDCLASS. | ||
|
||
|
||
CLASS ltcl_test IMPLEMENTATION. | ||
|
||
METHOD test. | ||
|
||
DATA lv_xstr TYPE xstring. | ||
DATA lv_crc TYPE zcl_crc32c=>ty_crc. | ||
|
||
* https://crccalc.com/?crc=1122334455667788AABBCCDDEEFF&method=crc32&datatype=hex&outtype=0 | ||
lv_xstr = '1122334455667788AABBCCDDEEFF'. | ||
|
||
lv_crc = zcl_crc32c=>run( lv_xstr ). | ||
|
||
cl_abap_unit_assert=>assert_not_initial( lv_crc ). | ||
|
||
cl_abap_unit_assert=>assert_equals( | ||
exp = 'F44CB56B' | ||
act = lv_crc ). | ||
|
||
ENDMETHOD. | ||
|
||
ENDCLASS. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0"> | ||
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0"> | ||
<asx:values> | ||
<VSEOCLASS> | ||
<CLSNAME>ZCL_CRC32C</CLSNAME> | ||
<LANGU>E</LANGU> | ||
<DESCRIPT>ZCL_CRC32C</DESCRIPT> | ||
<STATE>1</STATE> | ||
<CLSCCINCL>X</CLSCCINCL> | ||
<FIXPT>X</FIXPT> | ||
<UNICODE>X</UNICODE> | ||
</VSEOCLASS> | ||
</asx:values> | ||
</asx:abap> | ||
</abapGit> |