import { IProtocolConstructor , IStructCodec , IThriftField , ITransportConstructor , ProtocolType , TransportType , TType , } from '../types' ; import { getProtocol , TProtocol } from '../protocols' ; import { getTransport , TTransport } from '../transports' ; export function readThriftObject < StrictType > ( data , ThriftCodec , transportType = 'buffered' , protocolType = 'binary' ) { return new Promise ( ( resolve , reject ) => { const Transport = getTransport ( transportType ) ; const Protocol = getProtocol ( protocolType ) ; const receiver = new Transport ( data ) ; const input = new Protocol ( receiver ) ; const decoded = ThriftCodec . decode ( input ) ; resolve ( [ decoded , receiver . remaining ( ) ] ) ; } ) ; } export function stripStruct ( data , transportType = 'buffered' , protocolType = 'binary' ) { try { const Transport = getTransport ( transportType ) ; const Protocol = getProtocol ( protocolType ) ; const receiver = new Transport ( data ) ; const input = new Protocol ( receiver ) ; input . readStructBegin ( ) ; while ( true ) { const ret = input . readFieldBegin ( ) ; const fieldType = ret . fieldType ; if ( fieldType === TType . STOP ) { break ; } else { input . skip ( fieldType ) ; } input . readFieldEnd ( ) ; } input . readStructEnd ( ) ; return receiver . remaining ( ) ; } catch ( err ) { return data ; } }