Skip to content
Commits on Source (3)
......@@ -7,3 +7,4 @@
2022-06-16T05:53:24.301Z git:fix-enums:or4e3dsw@bytes.nz 0:04:12
2022-06-20T01:32:37.652Z git:main:or4e3dsw@bytes.nz 0:41:19
2022-12-21T02:57:20.725Z git:bits-id:or4e3dsw@bytes.nz 0:02:11
2024-05-14T09:48:32.581Z git:2-fix-uint32:or4e3dsw@bytes.nz 0:15:25
......@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
## [0.6.2] - 2024-05-14
### Fixed
- Fixed handling of 4 byte integers
## [0.6.1] - 2023-03-04
### Fixed
......@@ -56,6 +62,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
Initial version!
[0.6.1]: https://gitlab.com/bytesnz/binary-decoder/compare/v0.6.1...v0.6.2
[0.6.1]: https://gitlab.com/bytesnz/binary-decoder/compare/v0.6.0...v0.6.1
[0.6.0]: https://gitlab.com/bytesnz/binary-decoder/compare/v0.5.0...v0.6.0
[0.5.0]: https://gitlab.com/bytesnz/binary-decoder/compare/v0.4.0...v0.5.0
......
# binary-decoder 0.6.1
# binary-decoder 0.6.2
Decoder for structure binary data
......@@ -219,6 +219,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
## [0.6.2] - 2024-05-14
### Fixed
- Fixed handling of 4 byte integers
## [0.6.1] - 2023-03-04
### Fixed
......@@ -270,6 +276,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
Initial version!
[0.6.1]: https://gitlab.com/bytesnz/binary-decoder/compare/v0.6.1...v0.6.2
[0.6.1]: https://gitlab.com/bytesnz/binary-decoder/compare/v0.6.0...v0.6.1
[0.6.0]: https://gitlab.com/bytesnz/binary-decoder/compare/v0.5.0...v0.6.0
[0.5.0]: https://gitlab.com/bytesnz/binary-decoder/compare/v0.4.0...v0.5.0
......
......@@ -207,6 +207,7 @@ const decodeStructure = (
case 'int16':
case 'int32':
signed = true;
// eslint-disable-line no-fallthrough
case 'byte':
case 'uint8':
case 'uint16':
......@@ -226,6 +227,7 @@ const decodeStructure = (
bytes = 4;
break;
}
// eslint-disable-line no-fallthrough
case 'bytes': {
let negative = false;
......@@ -239,16 +241,13 @@ const decodeStructure = (
throw new Error('Not enough data for structure');
}
if (signed) {
if (message[nextByte] >= 128) {
if (signed || bytes === 4) {
const highestBit =
options.littleEndian || part.littleEndian ? nextByte + (bytes - 1) : nextByte;
if (message[highestBit] >= 128) {
negative = true;
}
} else if (bytes === 4) {
if (message[nextByte] >= 128) {
throw new Error(
'uint32 value (' + toHexString(message, 4, nextByte) + ') too big for JS number'
);
}
}
if (options.littleEndian || part.littleEndian) {
......@@ -261,7 +260,11 @@ const decodeStructure = (
}
}
if (negative) {
if (bytes === 4) {
if (negative && !signed) {
value += Math.pow(2, bytes * 8);
}
} else if (negative) {
value -= Math.pow(2, bytes * 8);
}
......
{
"name": "binary-decoder",
"version": "0.6.1",
"version": "0.6.2",
"description": "Decoder for complex binary data",
"type": "module",
"main": "index.js",
......
......@@ -28,8 +28,8 @@ assert.deepEqual(
int8: -2,
uint16: 65244,
int16: -292,
uint32: 2128394904,
int32: -4314056040
uint32: 4275878552,
int32: -19088744
},
nextByte: 16
},
......
No preview for this file type