@@ -3790,142 +3790,6 @@ mongoc_cluster_run_opmsg (mongoc_cluster_t *cluster,
3790
3790
}
3791
3791
3792
3792
3793
- /*
3794
- *--------------------------------------------------------------------------
3795
- *
3796
- * _mongoc_rpc_compress --
3797
- *
3798
- * Takes a (little endian) rpc struct and creates a OP_COMPRESSED
3799
- * compressed opcode based on the provided compressor_id.
3800
- * The in-place updated rpc struct remains little endian.
3801
- *
3802
- * Side effects:
3803
- * Overwrites the RPC, and clears and overwrites the cluster buffer
3804
- * with the compressed results.
3805
- *
3806
- *--------------------------------------------------------------------------
3807
- */
3808
-
3809
- char *
3810
- _mongoc_rpc_compress (struct _mongoc_cluster_t * cluster ,
3811
- int32_t compressor_id ,
3812
- mongoc_rpc_t * rpc_le ,
3813
- bson_error_t * error )
3814
- {
3815
- const size_t allocate = BSON_UINT32_FROM_LE (rpc_le -> header .msg_len ) - 16u ;
3816
- BSON_ASSERT (allocate > 0u );
3817
-
3818
- char * const data = bson_malloc0 (allocate );
3819
- const size_t size = _mongoc_cluster_buffer_iovec (
3820
- cluster -> iov .data , cluster -> iov .len , 16 , data );
3821
- size_t output_length =
3822
- mongoc_compressor_max_compressed_length (compressor_id , size );
3823
-
3824
- if (!output_length ) {
3825
- bson_set_error (error ,
3826
- MONGOC_ERROR_COMMAND ,
3827
- MONGOC_ERROR_COMMAND_INVALID_ARG ,
3828
- "Could not determine compression bounds for %s" ,
3829
- mongoc_compressor_id_to_name (compressor_id ));
3830
- bson_free (data );
3831
- return NULL ;
3832
- }
3833
-
3834
- int32_t compression_level = -1 ;
3835
-
3836
- if (compressor_id == MONGOC_COMPRESSOR_ZLIB_ID ) {
3837
- compression_level = mongoc_uri_get_option_as_int32 (
3838
- cluster -> uri , MONGOC_URI_ZLIBCOMPRESSIONLEVEL , -1 );
3839
- }
3840
-
3841
- BSON_ASSERT (size > 0u );
3842
-
3843
- char * const output = (char * ) bson_malloc0 (output_length );
3844
- if (mongoc_compress (compressor_id ,
3845
- compression_level ,
3846
- data ,
3847
- size ,
3848
- output ,
3849
- & output_length )) {
3850
- rpc_le -> header .msg_len = 0 ;
3851
- rpc_le -> compressed .original_opcode =
3852
- BSON_UINT32_FROM_LE (rpc_le -> header .opcode );
3853
- rpc_le -> header .opcode = MONGOC_OPCODE_COMPRESSED ;
3854
- rpc_le -> header .request_id =
3855
- BSON_UINT32_FROM_LE (rpc_le -> header .request_id );
3856
- rpc_le -> header .response_to =
3857
- BSON_UINT32_FROM_LE (rpc_le -> header .response_to );
3858
-
3859
- BSON_ASSERT (bson_in_range_unsigned (int32_t , size ));
3860
- BSON_ASSERT (bson_in_range_unsigned (int32_t , output_length ));
3861
-
3862
- rpc_le -> compressed .uncompressed_size = (int32_t ) size ;
3863
- rpc_le -> compressed .compressor_id = compressor_id ;
3864
- rpc_le -> compressed .compressed_message = (const uint8_t * ) output ;
3865
- rpc_le -> compressed .compressed_message_len = (int32_t ) output_length ;
3866
- bson_free (data );
3867
-
3868
-
3869
- _mongoc_array_destroy (& cluster -> iov );
3870
- _mongoc_array_init (& cluster -> iov , sizeof (mongoc_iovec_t ));
3871
- _mongoc_rpc_gather (rpc_le , & cluster -> iov );
3872
- _mongoc_rpc_swab_to_le (rpc_le );
3873
- return output ;
3874
- } else {
3875
- MONGOC_WARNING ("Could not compress data with %s" ,
3876
- mongoc_compressor_id_to_name (compressor_id ));
3877
- }
3878
- bson_free (data );
3879
- bson_free (output );
3880
- return NULL ;
3881
- }
3882
-
3883
- /*
3884
- *--------------------------------------------------------------------------
3885
- *
3886
- * _mongoc_rpc_decompress --
3887
- *
3888
- * Takes a (little endian) rpc struct assumed to be OP_COMPRESSED
3889
- * and decompresses the opcode into its original opcode.
3890
- * The in-place updated rpc struct remains little endian.
3891
- *
3892
- * Side effects:
3893
- * Overwrites the RPC, along with the provided buf with the
3894
- * compressed results.
3895
- *
3896
- *--------------------------------------------------------------------------
3897
- */
3898
-
3899
- bool
3900
- _mongoc_rpc_decompress (mongoc_rpc_t * rpc_le , uint8_t * buf , size_t buflen )
3901
- {
3902
- size_t uncompressed_size =
3903
- BSON_UINT32_FROM_LE (rpc_le -> compressed .uncompressed_size );
3904
- bool ok ;
3905
- size_t msg_len = BSON_UINT32_TO_LE (buflen );
3906
- const size_t original_uncompressed_size = uncompressed_size ;
3907
-
3908
- BSON_ASSERT (uncompressed_size <= buflen );
3909
- memcpy (buf , (void * ) (& msg_len ), 4 );
3910
- memcpy (buf + 4 , (void * ) (& rpc_le -> header .request_id ), 4 );
3911
- memcpy (buf + 8 , (void * ) (& rpc_le -> header .response_to ), 4 );
3912
- memcpy (buf + 12 , (void * ) (& rpc_le -> compressed .original_opcode ), 4 );
3913
-
3914
- ok = mongoc_uncompress (rpc_le -> compressed .compressor_id ,
3915
- rpc_le -> compressed .compressed_message ,
3916
- rpc_le -> compressed .compressed_message_len ,
3917
- buf + 16 ,
3918
- & uncompressed_size );
3919
-
3920
- BSON_ASSERT (original_uncompressed_size == uncompressed_size );
3921
-
3922
- if (ok ) {
3923
- return _mongoc_rpc_scatter (rpc_le , buf , buflen );
3924
- }
3925
-
3926
- return false;
3927
- }
3928
-
3929
3793
bool
3930
3794
mcd_rpc_message_compress (mcd_rpc_message * rpc ,
3931
3795
int32_t compressor_id ,
@@ -4107,46 +3971,6 @@ mcd_rpc_message_decompress (mcd_rpc_message *rpc, void **data, size_t *data_len)
4107
3971
return mcd_rpc_message_from_data_in_place (rpc , * data , * data_len , NULL );
4108
3972
}
4109
3973
4110
-
4111
- /* If rpc is OP_COMPRESSED, decompress it into buffer.
4112
- *
4113
- * Assumes rpc is still in network little-endian representation (i.e.
4114
- * _mongoc_rpc_swab_to_le has not been called).
4115
- * Returns true if rpc is not OP_COMPRESSED (and is a no-op) or if decompression
4116
- * succeeds.
4117
- * Return false and sets error otherwise.
4118
- */
4119
- bool
4120
- _mongoc_rpc_decompress_if_necessary (mongoc_rpc_t * rpc ,
4121
- mongoc_buffer_t * buffer /* IN/OUT */ ,
4122
- bson_error_t * error /* OUT */ )
4123
- {
4124
- uint8_t * buf = NULL ;
4125
- size_t len ;
4126
-
4127
- if (BSON_UINT32_FROM_LE (rpc -> header .opcode ) != MONGOC_OPCODE_COMPRESSED ) {
4128
- return true;
4129
- }
4130
-
4131
- len = BSON_UINT32_FROM_LE (rpc -> compressed .uncompressed_size ) +
4132
- sizeof (mongoc_rpc_header_t );
4133
-
4134
- buf = bson_malloc0 (len );
4135
- if (!_mongoc_rpc_decompress (rpc , buf , len )) {
4136
- bson_free (buf );
4137
- bson_set_error (error ,
4138
- MONGOC_ERROR_PROTOCOL ,
4139
- MONGOC_ERROR_PROTOCOL_INVALID_REPLY ,
4140
- "Could not decompress server reply" );
4141
- return false;
4142
- }
4143
-
4144
- _mongoc_buffer_destroy (buffer );
4145
- _mongoc_buffer_init (buffer , buf , len , NULL , NULL );
4146
-
4147
- return true;
4148
- }
4149
-
4150
3974
bool
4151
3975
mcd_rpc_message_decompress_if_necessary (mcd_rpc_message * rpc ,
4152
3976
void * * data ,
0 commit comments