Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue #568: fixed BERTLVAsciiHexPackager getUninterpretLength always returns 0 with AsciiHex interpreter #570

Merged
merged 4 commits into from
Nov 24, 2023

Conversation

T-eli
Copy link
Contributor

@T-eli T-eli commented Nov 23, 2023

The issue was due to The two operands lengthAdjusted and interpreter.getPackedLength(lengthAdjusted) are both Integers.

the result was calculated using Integer arithmetic resulting in a 0,5 that was always rounded down to 0.

0.5 because AsciiHex packed len is double len

solution is to cast one of the operands to a double to use double arithmetic, then cast result to integer.

@ar
Copy link
Member

ar commented Nov 23, 2023

Thank you for the PR and detailed Unit test.

There's no need for the double conversion, @barspi suggest a simpler solution, just

return (length * lengthAdjusted) / interpreter.getPackedLength(lengthAdjusted);

While you are at it, it would be great to also change the following method:

 private int getUninterpretLength(int length, Interpreter interpreter) {
        if (length > 0) {
            int lengthAdjusted = length + length % 2;
            return (length * lengthAdjusted) / interpreter.getPackedLength(lengthAdjusted);
        }
        return 0;
    }

(the one that uses an Interpreter instead of a BinaryInterpreter.

Would you like to send a new PR our of your branch or you prefer us to do it? Please confirm.

@T-eli
Copy link
Contributor Author

T-eli commented Nov 24, 2023

Hello @ar

I've pushed a new commit with the suggested edits , you should be able to see it added to the PR.

@ar ar merged commit c6f02d4 into jpos:master Nov 24, 2023
7 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants