@@ -233,30 +233,6 @@ function buildClientConfigLogString(prefix: string, config: ClientConfig) : stri
233233 return result ;
234234}
235235
236- function validateUnsignedInteger ( value : number , fieldName : string ) {
237- if ( ! Number . isInteger ( value ) || value < 0 ) {
238- throw new CrtError ( `Field "${ fieldName } " with value "${ value } " is not a valid unsigned integer` ) ;
239- }
240- }
241-
242- function validateOptionalUnsignedInteger ( value : number | undefined , fieldName : string ) {
243- if ( value === undefined ) {
244- return ;
245- }
246-
247- validateUnsignedInteger ( value , fieldName ) ;
248- }
249-
250- function validateOptionalPositiveU32 ( value : number | undefined , fieldName : string ) {
251- if ( value === undefined ) {
252- return ;
253- }
254-
255- if ( ! Number . isInteger ( value ) || value <= 0 || value > ( 256 * 256 * 256 * 256 - 1 ) ) {
256- throw new CrtError ( `Field "${ fieldName } " with value "${ value } " is not a valid positive 32 bit integer` ) ;
257- }
258- }
259-
260236function validateConnectOptions ( options : ConnectOptions , mode : ProtocolMode ) {
261237 if ( options . connectPacketTransformer && ( typeof options . connectPacketTransformer !== "function" ) ) {
262238 throw new CrtError ( "connectPacketTransformer must be a function" ) ;
@@ -278,7 +254,7 @@ function validateConnectOptions(options : ConnectOptions, mode : ProtocolMode) {
278254 validate . validateU16 ( options . receiveMaximum , "receiveMaximum" ) ;
279255 }
280256
281- validateOptionalPositiveU32 ( options . maximumPacketSizeBytes , "maximumPacketSizeBytes" ) ;
257+ validate . validateOptionalPositiveU32 ( options . maximumPacketSizeBytes , "maximumPacketSizeBytes" ) ;
282258 validate . validateOptionalU32 ( options . willDelayIntervalSeconds , "willDelayIntervalSeconds" ) ;
283259
284260 if ( options . will !== undefined ) {
@@ -299,21 +275,21 @@ function validateConfig(config: ClientConfig) {
299275
300276 validateConnectOptions ( config . connectOptions , config . protocolVersion ) ;
301277
302- validateOptionalUnsignedInteger ( config . pingTimeoutMillis , "pingTimeoutMillis" ) ;
278+ validate . validateOptionalUnsignedInteger ( config . pingTimeoutMillis , "pingTimeoutMillis" ) ;
303279
304280 if ( ! config . connectionFactory || ( typeof config . connectionFactory !== "function" ) ) {
305281 throw new CrtError ( "connectionFactory must be a valid function" ) ;
306282 }
307283
308- validateUnsignedInteger ( config . connectTimeoutMillis , "connectTimeoutMillis" ) ;
284+ validate . validateUnsignedInteger ( config . connectTimeoutMillis , "connectTimeoutMillis" ) ;
309285
310286 if ( config . retryJitterMode !== undefined && mqtt5 . RetryJitterType [ config . retryJitterMode ] == undefined ) {
311287 throw new CrtError ( "Invalid value for retryJitterMode" ) ;
312288 }
313289
314- validateOptionalUnsignedInteger ( config . minReconnectDelayMs , "minReconnectDelayMs" ) ;
315- validateOptionalUnsignedInteger ( config . maxReconnectDelayMs , "maxReconnectDelayMs" ) ;
316- validateOptionalUnsignedInteger ( config . resetConnectionFailureCountMillis , "resetConnectionFailureCountMillis" ) ;
290+ validate . validateOptionalUnsignedInteger ( config . minReconnectDelayMs , "minReconnectDelayMs" ) ;
291+ validate . validateOptionalUnsignedInteger ( config . maxReconnectDelayMs , "maxReconnectDelayMs" ) ;
292+ validate . validateOptionalUnsignedInteger ( config . resetConnectionFailureCountMillis , "resetConnectionFailureCountMillis" ) ;
317293
318294 if ( config . resubscribeMode !== undefined && ResubscribeModeType [ config . resubscribeMode ] == undefined ) {
319295 throw new CrtError ( "Invalid value for resubscribeMode" ) ;
0 commit comments