@@ -246,30 +246,6 @@ function buildClientConfigLogString(prefix: string, config: ClientConfig) : stri
246246 return result ;
247247}
248248
249- function validateUnsignedInteger ( value : number , fieldName : string ) {
250- if ( ! Number . isInteger ( value ) || value < 0 ) {
251- throw new CrtError ( `Field "${ fieldName } " with value "${ value } " is not a valid unsigned integer` ) ;
252- }
253- }
254-
255- function validateOptionalUnsignedInteger ( value : number | undefined , fieldName : string ) {
256- if ( value === undefined ) {
257- return ;
258- }
259-
260- validateUnsignedInteger ( value , fieldName ) ;
261- }
262-
263- function validateOptionalPositiveU32 ( value : number | undefined , fieldName : string ) {
264- if ( value === undefined ) {
265- return ;
266- }
267-
268- if ( ! Number . isInteger ( value ) || value <= 0 || value > ( 256 * 256 * 256 * 256 - 1 ) ) {
269- throw new CrtError ( `Field "${ fieldName } " with value "${ value } " is not a valid positive 32 bit integer` ) ;
270- }
271- }
272-
273249function validateConnectOptions ( options : ConnectOptions , mode : ProtocolMode ) {
274250 if ( options . connectPacketTransformer && ( typeof options . connectPacketTransformer !== "function" ) ) {
275251 throw new CrtError ( "connectPacketTransformer must be a function" ) ;
@@ -291,7 +267,7 @@ function validateConnectOptions(options : ConnectOptions, mode : ProtocolMode) {
291267 validate . validateU16 ( options . receiveMaximum , "receiveMaximum" ) ;
292268 }
293269
294- validateOptionalPositiveU32 ( options . maximumPacketSizeBytes , "maximumPacketSizeBytes" ) ;
270+ validate . validateOptionalPositiveU32 ( options . maximumPacketSizeBytes , "maximumPacketSizeBytes" ) ;
295271 validate . validateOptionalU32 ( options . willDelayIntervalSeconds , "willDelayIntervalSeconds" ) ;
296272
297273 if ( options . will !== undefined ) {
@@ -312,21 +288,21 @@ function validateConfig(config: ClientConfig) {
312288
313289 validateConnectOptions ( config . connectOptions , config . protocolVersion ) ;
314290
315- validateOptionalUnsignedInteger ( config . pingTimeoutMillis , "pingTimeoutMillis" ) ;
291+ validate . validateOptionalUnsignedInteger ( config . pingTimeoutMillis , "pingTimeoutMillis" ) ;
316292
317293 if ( ! config . connectionFactory || ( typeof config . connectionFactory !== "function" ) ) {
318294 throw new CrtError ( "connectionFactory must be a valid function" ) ;
319295 }
320296
321- validateUnsignedInteger ( config . connectTimeoutMillis , "connectTimeoutMillis" ) ;
297+ validate . validateUnsignedInteger ( config . connectTimeoutMillis , "connectTimeoutMillis" ) ;
322298
323299 if ( config . retryJitterMode !== undefined && mqtt5 . RetryJitterType [ config . retryJitterMode ] == undefined ) {
324300 throw new CrtError ( "Invalid value for retryJitterMode" ) ;
325301 }
326302
327- validateOptionalUnsignedInteger ( config . minReconnectDelayMs , "minReconnectDelayMs" ) ;
328- validateOptionalUnsignedInteger ( config . maxReconnectDelayMs , "maxReconnectDelayMs" ) ;
329- validateOptionalUnsignedInteger ( config . resetConnectionFailureCountMillis , "resetConnectionFailureCountMillis" ) ;
303+ validate . validateOptionalUnsignedInteger ( config . minReconnectDelayMs , "minReconnectDelayMs" ) ;
304+ validate . validateOptionalUnsignedInteger ( config . maxReconnectDelayMs , "maxReconnectDelayMs" ) ;
305+ validate . validateOptionalUnsignedInteger ( config . resetConnectionFailureCountMillis , "resetConnectionFailureCountMillis" ) ;
330306
331307 if ( config . resubscribeMode !== undefined && ResubscribeModeType [ config . resubscribeMode ] == undefined ) {
332308 throw new CrtError ( "Invalid value for resubscribeMode" ) ;
0 commit comments