File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -116,7 +116,7 @@ function convertFloatToBigEndian(value, size) {
116116 * the given size. The value is returned in hex format and prefixed with '0x'.
117117 */
118118function convertIntToBigEndian ( value , size ) {
119- const arrayBuffer = size <= 4 ? new ArrayBuffer ( size ) : new ArrayBuffer ( 8 )
119+ const arrayBuffer = new ArrayBuffer ( Math . pow ( 2 , Math . ceil ( Math . log2 ( size ) ) ) )
120120 const dataView = new DataView ( arrayBuffer )
121121 let i = 0
122122 if ( size == 1 ) {
Original file line number Diff line number Diff line change @@ -234,6 +234,32 @@ test(
234234 testUtil . timeout . short ( )
235235)
236236
237+ test (
238+ 'Generated Macro little endian for attribute of size 3 bytes' ,
239+ ( ) => {
240+ let options = { hash : { endian : 'little' } }
241+ return zclHelper
242+ . as_generated_default_macro ( '0x003840' , 3 , options )
243+ . then ( ( res ) => {
244+ return expect ( res ) . toBe ( '0x40, 0x38, 0x00, ' )
245+ } )
246+ } ,
247+ testUtil . timeout . short ( )
248+ )
249+
250+ test (
251+ 'Generated Macro big endian for attribute of size 3 bytes' ,
252+ ( ) => {
253+ let options = { hash : { endian : 'big' } }
254+ return zclHelper
255+ . as_generated_default_macro ( '0x003840' , 3 , options )
256+ . then ( ( res ) => {
257+ return expect ( res ) . toBe ( ' 0x00, 0x38, 0x40,' )
258+ } )
259+ } ,
260+ testUtil . timeout . short ( )
261+ )
262+
237263test (
238264 'Generated Macro little endian' ,
239265 ( ) => {
You can’t perform that action at this time.
0 commit comments