import { isNullOrUndefined } from 'util' ; import { pack } from 'byte-data' ; import { CommandOption } from '../../models' ; param option export const encodeCommandOption = ( option ) : number [ ] => { const payload = [ option . command , option . hasDataPhase ? 1 : 0 , 0 , option . params ? option . params . length / 4 >> 0 : 0 ] ; if ( option . params ) { payload . push ( ... option . params ) ; } const header = [ 1 , 0 , ... pack ( payload . length , { bits : 16 } ) ] ; const placeholders = new Array ( 32 - payload . length ) . fill ( 0 ) ; return [ ... header , ... payload , ... placeholders ] ; } ; export const validateCommandParams = ( params ) : void => { if ( isNullOrUndefined ( params ) ) { return ; } if ( ! Array . isArray ( params ) ) { throw new Error ( 'Command parameters must be an array!' ) ; } if ( params . length > 28 ) { throw new Error ( 'Maximum 7 (28 bytes) command parameters allowed!' ) ; } } ;