rmeister opened a new pull request #286:
URL: https://github.com/apache/plc4x/pull/286
Hi,
writing some WORDs with ADS gave me odd results. This is how I've tested my
fix:
```
byte[] convertToByteArrayLE(BigInteger bigIntValue, int targetSize){
byte[] bytes = bigIntValue.toByteArray();
ArrayUtils.reverse(bytes);
return Arrays.copyOf(bytes, targetSize);
}
@Test
void encodeBigInteger(){
assertArrayEquals(new byte[]{1, 0},
convertToByteArrayLE(BigInteger.valueOf(1), 2)); /* one byte input */
assertArrayEquals(new byte[]{-128, 0,},
convertToByteArrayLE(BigInteger.valueOf(128), 2)); /* one byte plus sign byte */
assertArrayEquals(new byte[]{0, 2},
convertToByteArrayLE(BigInteger.valueOf((512)), 2)); /* two bytes, no sign byte
*/
assertArrayEquals(new byte[]{-1, -1},
convertToByteArrayLE(BigInteger.valueOf((65535)), 2)); /* end of 16 bit range */
assertArrayEquals(new byte[]{0, 0},
convertToByteArrayLE(BigInteger.valueOf((65536)), 2)); /* three byte input ->
overflow */
assertArrayEquals(new byte[]{1, 0},
convertToByteArrayLE(BigInteger.valueOf((65537)), 2)); /* three byte input ->
overflow */
assertArrayEquals(new byte[]{1, 0, 1, 0},
convertToByteArrayLE(BigInteger.valueOf((65537)), 4)); /* three bytes, expanded
to four */
}
```
Best regards,
Richard
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]