@@ -2,9 +2,10 @@ const {parseSignature} = require('./signature');
22const { getBigIntCompat } = require ( './library-options' ) ;
33const JSBI = require ( 'jsbi' ) ;
44const Long = require ( 'long' ) ;
5+ const LE = require ( './constants' ) . endianness . le ;
56
67// Buffer + position + global start position ( used in alignment )
7- function DBusBuffer ( buffer , startPos , options ) {
8+ function DBusBuffer ( buffer , startPos , endian , options ) {
89 if ( typeof options !== 'object' ) {
910 options = { ayBuffer : true } ;
1011 } else if ( options . ayBuffer === undefined ) {
@@ -13,6 +14,7 @@ function DBusBuffer(buffer, startPos, options) {
1314 }
1415 this . options = options ;
1516 this . buffer = buffer ;
17+ this . endian = endian ;
1618 ( this . startPos = startPos ? startPos : 0 ) , ( this . pos = 0 ) ;
1719}
1820
@@ -29,35 +31,55 @@ DBusBuffer.prototype.readInt8 = function() {
2931
3032DBusBuffer . prototype . readSInt16 = function ( ) {
3133 this . align ( 1 ) ;
32- var res = this . buffer . readInt16LE ( this . pos ) ;
34+
35+ var res = ( this . endian === LE ?
36+ this . buffer . readInt16LE ( this . pos ) :
37+ this . buffer . readInt16BE ( this . pos ) ) ;
38+
3339 this . pos += 2 ;
3440 return res ;
3541} ;
3642
3743DBusBuffer . prototype . readInt16 = function ( ) {
3844 this . align ( 1 ) ;
39- var res = this . buffer . readUInt16LE ( this . pos ) ;
45+
46+ var res = ( this . endian === LE ?
47+ this . buffer . readUInt16LE ( this . pos ) :
48+ this . buffer . readUInt16BE ( this . pos ) ) ;
49+
4050 this . pos += 2 ;
4151 return res ;
4252} ;
4353
4454DBusBuffer . prototype . readSInt32 = function ( ) {
4555 this . align ( 2 ) ;
46- var res = this . buffer . readInt32LE ( this . pos ) ;
56+
57+ var res = ( this . endian === LE ?
58+ this . buffer . readInt32LE ( this . pos ) :
59+ this . buffer . readInt32BE ( this . pos ) ) ;
60+
4761 this . pos += 4 ;
4862 return res ;
4963} ;
5064
5165DBusBuffer . prototype . readInt32 = function ( ) {
5266 this . align ( 2 ) ;
53- var res = this . buffer . readUInt32LE ( this . pos ) ;
67+
68+ var res = ( this . endian === LE ?
69+ this . buffer . readUInt32LE ( this . pos ) :
70+ this . buffer . readUInt32BE ( this . pos ) ) ;
71+
5472 this . pos += 4 ;
5573 return res ;
5674} ;
5775
5876DBusBuffer . prototype . readDouble = function ( ) {
5977 this . align ( 3 ) ;
60- var res = this . buffer . readDoubleLE ( this . pos ) ;
78+
79+ var res = ( this . endian === LE ?
80+ this . buffer . readDoubleLE ( this . pos ) :
81+ this . buffer . readDoubleBE ( this . pos ) ) ;
82+
6183 this . pos += 8 ;
6284 return res ;
6385} ;
0 commit comments