@@ -34,6 +34,7 @@ const rclnodejs = require('bindings')('rclnodejs');
3434const DEFAULT_NUMERIC_RANGE_TOLERANCE = 1e-6 ;
3535
3636const PARAMETER_SEPARATOR = '.' ;
37+ const PARAMETER_BYTE = 10 ;
3738
3839/**
3940 * Enum for ParameterType
@@ -125,7 +126,9 @@ class Parameter {
125126 constructor ( name , type , value ) {
126127 this . _name = name ;
127128 this . _type = type ;
128- this . _value = value ;
129+ // Convert to bigint if it's type of `PARAMETER_INTEGER`.
130+ this . _value =
131+ this . _type == ParameterType . PARAMETER_INTEGER ? BigInt ( value ) : value ;
129132 this . _isDirty = true ;
130133
131134 this . validate ( ) ;
@@ -240,10 +243,10 @@ class Parameter {
240243 msg . double_array_value = this . value ;
241244 break ;
242245 case ParameterType . PARAMETER_INTEGER :
243- msg . integer_value = Math . trunc ( this . value ) ;
246+ msg . integer_value = this . value ;
244247 break ;
245248 case ParameterType . PARAMETER_INTEGER_ARRAY :
246- msg . integer_array_value = this . value . map ( ( val ) => Math . trunc ( val ) ) ;
249+ msg . integer_array_value = this . value ;
247250 break ;
248251 case ParameterType . PARAMETER_STRING :
249252 msg . string_value = this . value ;
@@ -537,10 +540,10 @@ class Range {
537540
538541 /**
539542 * Determine if a value is within this range.
540- * A TypeError is thrown when value is not a number.
543+ * A TypeError is thrown when value is not a number or bigint .
541544 * Subclasses should override and call this method for basic type checking.
542545 *
543- * @param {number } value - The number to check.
546+ * @param {number|bigint } value - The number or bigint to check.
544547 * @return {boolean } - True if value satisfies the range; false otherwise.
545548 */
546549 inRange ( value ) {
@@ -550,8 +553,8 @@ class Range {
550553 ( inRange , val ) => inRange && this . inRange ( val ) ,
551554 true
552555 ) ;
553- } else if ( typeof value !== 'number' ) {
554- throw new TypeError ( 'Value must be a number' ) ;
556+ } else if ( typeof value !== 'number' && typeof value !== 'bigint' ) {
557+ throw new TypeError ( 'Value must be a number or bigint ' ) ;
555558 }
556559
557560 return true ;
@@ -652,27 +655,16 @@ class FloatingPointRange extends Range {
652655 * Defines a range for integer values.
653656 * @class
654657 */
655- class IntegerRange extends FloatingPointRange {
658+ class IntegerRange extends Range {
656659 /**
657660 * Create a new instance.
658661 * @constructor
659- * @param {number } fromValue - The lowest inclusive value in range
660- * @param {number } toValue - The highest inclusive value in range
661- * @param {number } step - The internal unit size.
662- * @param {number } tolerance - The plus/minus tolerance for number equivalence.
662+ * @param {bigint } fromValue - The lowest inclusive value in range
663+ * @param {bigint } toValue - The highest inclusive value in range
664+ * @param {bigint } step - The internal unit size.
663665 */
664- constructor (
665- fromValue ,
666- toValue ,
667- step = 1 ,
668- tolerance = DEFAULT_NUMERIC_RANGE_TOLERANCE
669- ) {
670- super (
671- Math . trunc ( fromValue ) ,
672- Math . trunc ( toValue ) ,
673- Math . trunc ( step ) ,
674- tolerance
675- ) ;
666+ constructor ( fromValue , toValue , step = 1n ) {
667+ super ( fromValue , toValue , step ) ;
676668 }
677669
678670 /**
@@ -683,12 +675,23 @@ class IntegerRange extends FloatingPointRange {
683675 */
684676 isValidType ( parameterType ) {
685677 const result =
686- parameterType === ParameterType . PARAMETER_BYTE ||
687- parameterType === ParameterType . PARAMETER_BYTE_ARRAY ||
688678 parameterType === ParameterType . PARAMETER_INTEGER ||
689679 parameterType === ParameterType . PARAMETER_INTEGER_ARRAY ;
690680 return result ;
691681 }
682+
683+ inRange ( value ) {
684+ const min = this . fromValue ;
685+ const max = this . toValue ;
686+ if ( value < min || value > max ) {
687+ return false ;
688+ }
689+
690+ if ( this . step != 0n && ( value - min ) % this . step !== 0n ) {
691+ return false ;
692+ }
693+ return true ;
694+ }
692695}
693696
694697/**
@@ -763,10 +766,13 @@ function validValue(value, type) {
763766 case ParameterType . PARAMETER_STRING :
764767 result = typeof value === 'string' ;
765768 break ;
766- case ParameterType . PARAMETER_INTEGER :
767769 case ParameterType . PARAMETER_DOUBLE :
770+ case PARAMETER_BYTE :
768771 result = typeof value === 'number' ;
769772 break ;
773+ case ParameterType . PARAMETER_INTEGER :
774+ result = typeof value === 'bigint' ;
775+ break ;
770776 case ParameterType . PARAMETER_BOOL_ARRAY :
771777 case ParameterType . PARAMETER_BYTE_ARRAY :
772778 case ParameterType . PARAMETER_INTEGER_ARRAY :
@@ -789,7 +795,7 @@ function _validArray(values, type) {
789795 if ( type === ParameterType . PARAMETER_BOOL_ARRAY ) {
790796 arrayElementType = ParameterType . PARAMETER_BOOL ;
791797 } else if ( type === ParameterType . PARAMETER_BYTE_ARRAY ) {
792- arrayElementType = ParameterType . PARAMETER_INTEGER ;
798+ arrayElementType = PARAMETER_BYTE ;
793799 }
794800 if ( type === ParameterType . PARAMETER_INTEGER_ARRAY ) {
795801 arrayElementType = ParameterType . PARAMETER_INTEGER ;
0 commit comments