author liangqin.fan gmail export function arrayToTyped ( arr ) { return Uint8Array . wrap ( changetype < ArrayBuffer > ( arr . dataStart ) ) ; } export function typedToArray ( u8a , length = - 1 ) { const size = length == - 1 ? u8a . length : length ; const arr = new Array < u8 > ( size ) ; memory . copy ( arr . dataStart , u8a . dataStart , size ) ; return arr ; } export function toU8Array ( ab ) { let size = ab . byteLength ; let arr = new Array < u8 > ( size ) ; memory . copy ( arr . dataStart , changetype < usize > ( ab ) , size ) ; return arr ; } function toHexCharCode ( v ) { if ( v >= 0 && v <= 9 ) return ( v + 0x30 ) as i32 ; else return ( v + 0x61 - 10 ) as i32 ; } export function arryToHexString ( arr ) { let charcodes = new Array < i32 > ( arr . length * 2 ) ; let hsb ; let lsb ; for ( let i = 0 ; i < arr . length ; i ++ ) { hsb = ( ( arr [ i ] & 0xf0 ) >> 4 ) as u8 ; lsb = ( arr [ i ] & 0x0f ) as u8 ; charcodes . push ( toHexCharCode ( hsb ) ) ; charcodes . push ( toHexCharCode ( lsb ) ) ; } return String . fromCharCodes ( charcodes ) ; }