committed by
Keith Winstein
parent
a4dd2fed89
commit
b0e05776f1
@@ -17,13 +17,15 @@
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <google/protobuf/io/gzip_stream.h>
|
||||
#include <google/protobuf/io/zero_copy_stream_impl.h>
|
||||
|
||||
#include "byteorder.h"
|
||||
#include "transportfragment.h"
|
||||
#include "transportinstruction.pb.h"
|
||||
#include "compressor.h"
|
||||
#include "fatal_assert.h"
|
||||
|
||||
using namespace google::protobuf::io;
|
||||
using namespace Network;
|
||||
using namespace TransportBuffers;
|
||||
|
||||
@@ -115,15 +117,24 @@ Instruction FragmentAssembly::get_assembly( void )
|
||||
{
|
||||
assert( fragments_arrived == fragments_total );
|
||||
|
||||
string encoded;
|
||||
|
||||
ZeroCopyInputStream **streams = new ZeroCopyInputStream *[fragments_total];
|
||||
for ( int i = 0; i < fragments_total; i++ ) {
|
||||
assert( fragments.at( i ).initialized );
|
||||
encoded += fragments.at( i ).contents;
|
||||
streams[i] = new ArrayInputStream( fragments.at( i ).contents.data(),
|
||||
fragments.at( i ).contents.size() );
|
||||
}
|
||||
|
||||
Instruction ret;
|
||||
fatal_assert( ret.ParseFromString( get_compressor().uncompress_str( encoded ) ) );
|
||||
{
|
||||
ConcatenatingInputStream stream( streams, fragments_total );
|
||||
GzipInputStream gzip_stream( &stream, GzipInputStream::ZLIB );
|
||||
fatal_assert( ret.ParseFromZeroCopyStream( &gzip_stream ) );
|
||||
}
|
||||
|
||||
for ( int i = 0; i < fragments_total; i++ ) {
|
||||
delete streams[i];
|
||||
}
|
||||
delete[] streams;
|
||||
|
||||
fragments.clear();
|
||||
fragments_arrived = 0;
|
||||
@@ -158,7 +169,18 @@ vector<Fragment> Fragmenter::make_fragments( const Instruction &inst, int MTU )
|
||||
last_instruction = inst;
|
||||
last_MTU = MTU;
|
||||
|
||||
string payload = get_compressor().compress_str( inst.SerializeAsString() );
|
||||
string payload;
|
||||
{
|
||||
StringOutputStream stream( &payload );
|
||||
GzipOutputStream::Options gzip_options;
|
||||
gzip_options.format = GzipOutputStream::ZLIB;
|
||||
GzipOutputStream gzip_stream( &stream, gzip_options );
|
||||
fatal_assert( inst.SerializeToZeroCopyStream( &gzip_stream ) );
|
||||
if ( !gzip_stream.Close() ) {
|
||||
throw std::string( "zlib error: " ) + gzip_stream.ZlibErrorMessage();
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t fragment_num = 0;
|
||||
vector<Fragment> ret;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user