import { EventEmitter } from 'events' ; import { IHessianType } from './types' ; export const msg = new EventEmitter ( ) ; export const noop = ( ) => { } ; const toString = Object . prototype . toString ; export const isBoolean = ( param ) : param is boolean => toString . call ( param ) === '[object Boolean]' ; export const isString = ( param ) : param is string => toString . call ( param ) === '[object String]' ; export const isNumber = ( param ) : param is number => toString . call ( param ) === '[object Number]' ; export const isMap = ( param ) : param is Map < any , any > => param instanceof Map ; export const isFn = ( param ) : param is Function => toString . call ( param ) === '[object Function]' ; export const isObj = ( param ) : param is Object => toString . call ( param ) === '[object Object]' ; export const isRegExp = ( arg ) : arg is RegExp => toString . call ( arg ) === '[object RegExp]' ; export const isArray = ( arg ) : arg is Array < string > => toString . call ( arg ) === '[object Array]' ; param param export function checkHessianParam ( param ) { return ( typeof param === 'object' && typeof param [ '$class' ] !== 'undefined' && typeof param [ '$' ] !== 'undefined' ) ; } param res export function checkRetValHessian ( res ) { if ( typeof res === 'undefined' || isBoolean ( res ) || isNumber ( res ) || isString ( res ) || isMap ( res ) ) { return true ; } const hessian = res . __fields2java ? res . __fields2java ( ) : res ; return checkHessianParam ( hessian ) ; } /**
 * Dubbo Version
 */ export class Version { private static version2Int = new Map < string , number > ( ) ; static LEGACY_DUBBO_PROTOCOL_VERSION = 10000 ; static LOWEST_VERSION_FOR_RESPONSE_ATTACHMENT = 2000200 ; static HIGHEST_PROTOCOL_VERSION = 2009900 ; static isSupportResponseAttachment ( version ) { if ( ! version ) { return false ; } const v = Version . getIntVersion ( version ) ; return ( v >= Version . LOWEST_VERSION_FOR_RESPONSE_ATTACHMENT && v <= Version . HIGHEST_PROTOCOL_VERSION ) ; } static getIntVersion ( version ) { let v = Version . version2Int . get ( version ) ; if ( ! v ) { try { v = Version . parseInt ( version ) ; if ( version . split ( '.' ) . length == 3 ) { v = v * 100 ; } } catch ( err ) { console . error ( 'Please make sure your version value has the right format: ' + '\n 1. only contains digital number: 2.0.0; \n 2. with string suffix: 2.6.7-stable. ' + '\nIf you are using Dubbo before v2.6.2, the version value is the same with the jar version.' ) ; v = this . LEGACY_DUBBO_PROTOCOL_VERSION ; } this . version2Int . set ( version , v ) ; } return v ; } static parseInt ( version ) { let v = 0 ; const vArr = version . split ( '.' ) ; const len = vArr . length ; for ( let i = 0 ; i < len ; i ++ ) { const subversion = Version . getPrefixDigits ( vArr [ i ] ) ; if ( subversion ) { v += parseInt ( subversion ) * Math . pow ( 10 , ( len - i - 1 ) * 2 ) ; } } return v ; } static getPrefixDigits ( v ) { const match = v . match ( /^([0-9]*).*/ ) ; return match ? match [ 1 ] : '' ; } }