import { defaultLogger } from '../logger' ; import { IProtocolConstructor , IThriftMessage , ITransportConstructor , LogFunction , } from '../types' ; import { BinaryProtocol , TProtocol } from '../protocols' ; import { BufferedTransport , TTransport } from '../transports' ; export function readThriftMetadata ( buffer , Transport , Protocol , logger ) { try { const transportWithData = new Transport ( buffer ) ; const input = new Protocol ( transportWithData ) ; return input . readMessageBegin ( ) ; } catch ( err ) { logger ( [ 'warn' , 'readThriftMetadata' ] , `Unable to read Thrift message. ${ err . message }` ) ; throw err ; } } export function readThriftMethod ( buffer , Transport = BufferedTransport , Protocol = BinaryProtocol , logger = defaultLogger ) { try { const { fieldName } = readThriftMetadata ( buffer , Transport , Protocol , logger ) ; return fieldName ; } catch ( err ) { logger ( [ 'warn' , 'readThrfitMethod' ] , `Unable to read Thrift method name. ${ err . message }` ) ; return '' ; } } export function readRequestId ( buffer , Transport , Protocol , logger = defaultLogger ) { try { const { requestId } = readThriftMetadata ( buffer , Transport , Protocol , logger ) ; return requestId ; } catch ( err ) { logger ( [ 'warn' , 'readRequestId' ] , `Unable to read Thrift requestId. ${ err . message }` ) ; return 0 ; } }