MySQL 8.0.30
Source Code Documentation
my_compress.cc File Reference
#include "my_compress.h"
#include <string.h>
#include <sys/types.h>
#include <zlib.h>
#include <zstd.h>
#include <algorithm>
#include <cstddef>
#include <mysql_com.h>
#include "my_compiler.h"
#include "my_dbug.h"
#include "my_inttypes.h"
#include "my_sys.h"
#include "mysql/service_mysql_alloc.h"
#include "mysys/mysys_priv.h"

Functions

void mysql_compress_context_init (mysql_compress_context *cmp_ctx, enum enum_compression_algorithm algorithm, unsigned int compression_level)
 Initialize a compress context object to be associated with a NET object. More...
 
void mysql_compress_context_deinit (mysql_compress_context *mysql_compress_ctx)
 Deinitialize the compression context allocated. More...
 
ucharzstd_compress_alloc (mysql_zstd_compress_context *comp_ctx, const uchar *packet, size_t *len, size_t *complen)
 Allocate zstd compression contexts if necessary and compress using zstd the buffer. More...
 
static bool zstd_uncompress (mysql_zstd_compress_context *comp_ctx, uchar *packet, size_t len, size_t *complen)
 Uncompress a zstd compressed data. More...
 
static ucharzlib_compress_alloc (mysql_zlib_compress_context *comp_ctx, const uchar *packet, size_t *len, size_t *complen)
 Allocate zlib compression contexts if necessary and compress using zlib the buffer. More...
 
static bool zlib_uncompress (uchar *packet, size_t len, size_t *complen)
 Uncompress a zlib compressed data. More...
 
bool my_compress (mysql_compress_context *comp_ctx, uchar *packet, size_t *len, size_t *complen)
 This replaces the packet with a compressed packet. More...
 
ucharmy_compress_alloc (mysql_compress_context *comp_ctx, const uchar *packet, size_t *len, size_t *complen)
 
bool my_uncompress (mysql_compress_context *comp_ctx, uchar *packet, size_t len, size_t *complen)
 Uncompress packet. More...
 
unsigned int mysql_default_compression_level (enum enum_compression_algorithm algorithm)
 Get default compression level corresponding to a given compression method. More...
 

Function Documentation

◆ mysql_compress_context_deinit()

void mysql_compress_context_deinit ( mysql_compress_context mysql_compress_ctx)

Deinitialize the compression context allocated.

Parameters
mysql_compress_ctxPointer to Compression context.

◆ mysql_compress_context_init()

void mysql_compress_context_init ( mysql_compress_context cmp_ctx,
enum enum_compression_algorithm  algorithm,
unsigned int  compression_level 
)

Initialize a compress context object to be associated with a NET object.

Parameters
cmp_ctxPointer to compression context.
algorithmCompression algorithm.
compression_levelCompression level corresponding to the compression algorithm.

◆ mysql_default_compression_level()

unsigned int mysql_default_compression_level ( enum enum_compression_algorithm  algorithm)

Get default compression level corresponding to a given compression method.

Parameters
algorithmCompression Method. Possible values are zlib or zstd.
Returns
an unsigned int representing default compression level. 6 is the default compression level for zlib and 3 is the default compression level for zstd.

◆ zlib_compress_alloc()

static uchar * zlib_compress_alloc ( mysql_zlib_compress_context comp_ctx,
const uchar packet,
size_t *  len,
size_t *  complen 
)
static

Allocate zlib compression contexts if necessary and compress using zlib the buffer.

Parameters
comp_ctxCompression context info relating to zlib.
packetData to compress. This is is replaced with the compressed data.
lenLength of data to compress at 'packet'
[out]complen0 if packet was not compressed
Returns
nullptr if error (len is not changed) else pointer to buffer. size of compressed packet).

◆ zlib_uncompress()

static bool zlib_uncompress ( uchar packet,
size_t  len,
size_t *  complen 
)
static

Uncompress a zlib compressed data.

Parameters
packetPacket which zstd compressed data.
lenLength of zstd compressed packet.
[out]complenLength of uncompressed packet.
Returns
true on error else false.

◆ zstd_compress_alloc()

uchar * zstd_compress_alloc ( mysql_zstd_compress_context comp_ctx,
const uchar packet,
size_t *  len,
size_t *  complen 
)

Allocate zstd compression contexts if necessary and compress using zstd the buffer.

Parameters
comp_ctxCompression context info relating to zstd.
packetData to compress. This is is replaced with the compressed data.
lenLength of data to compress at 'packet'
complenout: 0 if packet was not compressed
Returns
nullptr if error (len is not changed) else pointer to buffer. size of compressed packet).

◆ zstd_uncompress()

static bool zstd_uncompress ( mysql_zstd_compress_context comp_ctx,
uchar packet,
size_t  len,
size_t *  complen 
)
static

Uncompress a zstd compressed data.

Parameters
comp_ctxPointer to compression context.
packetPacket with zstd compressed data.
lenLength of zstd compressed packet.
[out]complenLength of uncompressed packet.
Returns
true on error else false.