import { IProtocolConstructor , IStructCodec , ITransportConstructor , ProtocolType , TransportType , } from '../types' ; import { BinaryProtocol , getProtocol , TProtocol } from '../protocols' ; import { BufferedTransport , getTransport , TTransport } from '../transports' ; export function encode < LooseType > ( thriftObject , ThriftCodec , Transport = BufferedTransport , Protocol = BinaryProtocol ) { return new Promise ( ( resolve , reject ) => { const transport = new Transport ( ) ; const protocol = new Protocol ( transport ) ; ThriftCodec . encode ( thriftObject , protocol ) ; const data = protocol . flush ( ) ; resolve ( data ) ; } ) ; } export function appendThriftObject < LooseType > ( value , data , ThriftCodec , transportType = 'buffered' , protocolType = 'binary' ) { const Transport = getTransport ( transportType ) ; const Protocol = getProtocol ( protocolType ) ; return encode < LooseType > ( value , ThriftCodec , Transport , Protocol ) . then ( ( encoded ) => { return Buffer . concat ( [ encoded , data ] ) ; } ) ; }