本文整理汇总了C++中BZ2_bzBuffToBuffDecompress函数的典型用法代码示例。如果您正苦于以下问题:C++ BZ2_bzBuffToBuffDecompress函数的具体用法?C++ BZ2_bzBuffToBuffDecompress怎么用?C++ BZ2_bzBuffToBuffDecompress使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了BZ2_bzBuffToBuffDecompress函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: crm_ipcs_recv
xmlNode *
crm_ipcs_recv(crm_client_t * c, void *data, size_t size, uint32_t * id, uint32_t * flags)
{
xmlNode *xml = NULL;
char *uncompressed = NULL;
char *text = ((char *)data) + sizeof(struct crm_ipc_response_header);
struct crm_ipc_response_header *header = data;
if (id) {
*id = ((struct qb_ipc_response_header *)data)->id;
}
if (flags) {
*flags = header->flags;
}
if (is_set(header->flags, crm_ipc_proxied)) {
/* mark this client as being the endpoint of a proxy connection.
* Proxy connections responses are sent on the event channel to avoid
* blocking the proxy daemon (crmd) */
c->flags |= crm_client_flag_ipc_proxied;
}
if(header->version > PCMK_IPC_VERSION) {
crm_err("Filtering incompatible v%d IPC message, we only support versions <= %d",
header->version, PCMK_IPC_VERSION);
return NULL;
}
if (header->size_compressed) {
int rc = 0;
unsigned int size_u = 1 + header->size_uncompressed;
uncompressed = calloc(1, size_u);
crm_trace("Decompressing message data %d bytes into %d bytes",
header->size_compressed, size_u);
rc = BZ2_bzBuffToBuffDecompress(uncompressed, &size_u, text, header->size_compressed, 1, 0);
text = uncompressed;
if (rc != BZ_OK) {
crm_err("Decompression failed: %s (%d)", bz2_strerror(rc), rc);
free(uncompressed);
return NULL;
}
}
CRM_ASSERT(text[header->size_uncompressed - 1] == 0);
crm_trace("Received %.200s", text);
xml = string2xml(text);
free(uncompressed);
return xml;
}
示例2: bz2_decompress
/*ARGSUSED*/
int
bz2_decompress(void *s_start, void *d_start, size_t s_len, size_t d_len, int n)
{
ASSERT(d_len >= s_len);
if (BZ2_bzBuffToBuffDecompress(d_start, (unsigned int *)&d_len, s_start,
s_len, 0, 0) != Z_OK)
return (-1);
return (0);
}
示例3: Read_compressed_record
static void Read_compressed_record()
{
int bytes_to_read = 0;
int bytes_read = 0;
int error = 0;
int size_of_record = Control_word;
/* Byte-swap size flag so we can use it. */
bytes_to_read = ntohl( size_of_record );
P_debug( "Read_compressed_record: read %d", bytes_to_read );
/* Negative size indicates this is the last record of the volume. */
if( bytes_to_read < 0 )
{
P_debug( "Read_compressed_record: EOV" );
bytes_to_read = -bytes_to_read;
End_of_volume_flag = YES;
}
/* Read in compressed record according to expected size. If fewer
bytes are read than expected, that's a problem. */
bytes_read = Read_stdin( (char *)Read_buf, bytes_to_read );
if( bytes_read != bytes_to_read )
{
P_err( "Read_compressed_record: Bytes read (%d) less than (%d)",
bytes_read, bytes_to_read );
Print_stats( INSUFFICIENT_STDIN_BYTES_READ );
}
/* Decompress the compressed record and put in different buffer. */
Uncompressed_length = sizeof( Uncompressed_buf );
error = BZ2_bzBuffToBuffDecompress( Uncompressed_buf, &Uncompressed_length,
Read_buf, bytes_read,
0, 1 );
if( error )
{
P_err( "Read_compressed_record: Decompress error - %d", error );
Print_stats( DECOMPRESS_ERROR );
}
Uncompressed_bytes += Uncompressed_length;
Compressed_bytes += bytes_read;
Compression_ratio = (float) Uncompressed_bytes / (float) Compressed_bytes;
P_debug( "Radial size - Comp: %d Uncomp: %d Ratio: %f", Compressed_bytes, Uncompressed_bytes, Compression_ratio );
}
示例4: throw
/** \brief uncompress the \ref datum_t and return the uncompressed result
*
* @param datum the data \ref datum_t to uncompress
* @param max_len the maximum length of the result
* @return a \ref datum_t containing the uncompressed data. the \ref datum_t
* is null if the result is larger than \ref max_len.
*/
datum_t compress_bzip_t::uncompress(const datum_t &datum, size_t max_len) throw()
{
unsigned int outlen = max_len;
// allocate the output buffer
char *outbuf = (char *)nipmem_alloca(max_len);
// try to uncompress the data and put them in the output buffer
int err = BZ2_bzBuffToBuffDecompress(outbuf, &outlen, (char *)datum.get_data()
, datum.get_len(), 1, 0);
// if the decompression failed, return a NULL datum_t()
if( err != BZ_OK ) return datum_t();
// copy the decompressed data into a datum_t
return datum_t(outbuf, outlen);
}
示例5: BZ2_bzBuffToBuffDecompress
extern int
bzip2_decode
(const unsigned char *in_start, size_t in_len, unsigned char *out_start, size_t *pout_len, size_t out_max)
{
int small = 1;
int verbosity = 0;
size_t destlen = n;
int x = BZ2_bzBuffToBuffDecompress( (char*)out_start, &destlen, (char*)in_start, in_len,
small, verbosity);
*pout_len = destlen;
return x == BZ_OK;
}
示例6: while
void NetChannel::CopyNormalFragments()
{
fragbuf_t *p, *n;
int totalSize;
if (!m_incomingbufs[FRAG_NORMAL_STREAM]) {
m_System->DPrintf("WARNING! NetChannel::CopyNormalFragments: called with no fragments readied.\n");
return;
}
totalSize = 0;
p = m_incomingbufs[FRAG_NORMAL_STREAM];
while (p)
{
totalSize += p->size;
p = p->next;
}
NetPacket *packet = new NetPacket;
packet->seqnr = m_incoming_sequence;
packet->connectionless = false;
packet->time = m_System->GetTime();
packet->address.FromNetAddress(&m_remote_address);
packet->data.Resize(totalSize);
p = m_incomingbufs[FRAG_NORMAL_STREAM];
while (p)
{
n = p->next;
packet->data.WriteBuf(p->data, p->size);
Mem_Free(p);
p = n;
}
if (*(uint32 *)packet->data.GetData() == MAKEID('B', 'Z', '2', '\0'))
{
char uncompressed[65536];
unsigned int uncompressedSize = 65536;
BZ2_bzBuffToBuffDecompress(uncompressed, &uncompressedSize, (char *)packet->data.GetData() + 4, totalSize - 4, 1, 0);
packet->data.Resize(uncompressedSize);
packet->data.WriteBuf(uncompressed, uncompressedSize);
}
packet->data.Reset();
m_incomingPackets.AddHead(packet);
m_incomingbufs[FRAG_NORMAL_STREAM] = nullptr;
}
示例7: uncompress_using_bzip2
static int uncompress_using_bzip2(void *in, unsigned long in_size,
void *out, unsigned long out_max,
unsigned long *out_size)
{
int ret;
unsigned int inout_size = out_max;
ret = BZ2_bzBuffToBuffDecompress(out, &inout_size, in, in_size,
CONFIG_SYS_MALLOC_LEN < (4096 * 1024), 0);
if (out_size)
*out_size = inout_size;
return (ret != BZ_OK);
}
示例8: convert_xml_child
static void
convert_xml_child(HA_Message * msg, xmlNode * xml)
{
int orig = 0;
int rc = BZ_OK;
unsigned int len = 0;
char *buffer = NULL;
char *compressed = NULL;
const char *name = NULL;
name = (const char *)xml->name;
buffer = dump_xml_unformatted(xml);
orig = strlen(buffer);
if (orig < CRM_BZ2_THRESHOLD) {
ha_msg_add(msg, name, buffer);
goto done;
}
len = (orig * 1.1) + 600; /* recomended size */
compressed = malloc(len);
rc = BZ2_bzBuffToBuffCompress(compressed, &len, buffer, orig, CRM_BZ2_BLOCKS, 0, CRM_BZ2_WORK);
if (rc != BZ_OK) {
crm_err("Compression failed: %d", rc);
free(compressed);
convert_xml_message_struct(msg, xml, name);
goto done;
}
free(buffer);
buffer = compressed;
crm_trace("Compression details: %d -> %d", orig, len);
ha_msg_addbin(msg, name, buffer, len);
done:
free(buffer);
# if 0
{
unsigned int used = orig;
char *uncompressed = NULL;
crm_debug("Trying to decompress %d bytes", len);
uncompressed = calloc(1, orig);
rc = BZ2_bzBuffToBuffDecompress(uncompressed, &used, compressed, len, 1, 0);
CRM_CHECK(rc == BZ_OK,;
);
CRM_CHECK(used == orig,;
);
示例9: BZ2_bzBuffToBuffDecompress
void BZ2Stream::decompress(uint8_t* dest, unsigned int dest_len, uint8_t* source, unsigned int source_len) {
int result = BZ2_bzBuffToBuffDecompress((char*) dest, &dest_len, (char*) source, source_len, 0, verbosity_);
switch (result) {
case BZ_OK: break;
case BZ_CONFIG_ERROR: throw BagException("library has been mis-compiled"); break;
case BZ_PARAM_ERROR: throw BagException("dest is NULL or destLen is NULL or small != 0 && small != 1 or verbosity < 0 or verbosity > 4"); break;
case BZ_MEM_ERROR: throw BagException("insufficient memory is available"); break;
case BZ_OUTBUFF_FULL: throw BagException("size of the compressed data exceeds *destLen"); break;
case BZ_DATA_ERROR: throw BagException("data integrity error was detected in the compressed data"); break;
case BZ_DATA_ERROR_MAGIC: throw BagException("compressed data doesn't begin with the right magic bytes"); break;
case BZ_UNEXPECTED_EOF: throw BagException("compressed data ends unexpectedly"); break;
}
}
示例10: runtime_error
void CIszImageStream::ReadBz2Block(uint32 compressedBlockSize)
{
m_baseStream->Read(m_readBuffer, compressedBlockSize);
//Force BZ2 header
m_readBuffer[0] = 'B';
m_readBuffer[1] = 'Z';
m_readBuffer[2] = 'h';
unsigned int destLength = m_header.blockSize;
if(BZ2_bzBuffToBuffDecompress(
reinterpret_cast<char*>(m_cachedBlock), &destLength,
reinterpret_cast<char*>(m_readBuffer), compressedBlockSize, 0, 0) != BZ_OK)
{
throw std::runtime_error("Error decompressing bz2 block.");
}
}
示例11: ZIP_Decompress
static void ZIP_Decompress( DaoProcess *proc, DaoValue *p[], int N )
{
DString *source = p[0]->xString.value;
DString *res = DaoProcess_PutChars( proc, "" );
unsigned int resLen;
/* TODO: get decompressed size from the compressed data? */
DString_Reserve( res, source->size );
resLen = res->bufSize;
while( resLen == res->bufSize ){
DString_Reserve( res, 2*resLen );
resLen = res->bufSize;
BZ2_bzBuffToBuffDecompress( res->chars, & resLen, source->chars, source->size, 0, 0 );
}
DString_Reset( res, resLen );
}
示例12: bz2decompress
EXPORT BOOL WINAPI bz2decompress(HSPEXINFO *hei)
{
char* dest = (char *)hei->HspFunc_prm_getv();
unsigned int destBufSize = hei->HspFunc_prm_geti();
char* source = (char *)hei->HspFunc_prm_getv();
unsigned int sourceLen = hei->HspFunc_prm_geti();
unsigned int* destLen = &destBufSize;
int ret;
if (*hei->er) return *hei->er;
ret = BZ2_bzBuffToBuffDecompress(dest, destLen, source, sourceLen, 0, 0);
if (ret == BZ_OK) *hei->strsize = *destLen;
return -abs(ret);
return 0;
}
示例13: uncompress_block_bzip2
int uncompress_block_bzip2(u64 compsize, u64 *origsize, u8 *origbuf, u64 origbufsize, u8 *compbuf)
{
unsigned int destsize=origbufsize;
int res;
switch ((res=BZ2_bzBuffToBuffDecompress((char*)origbuf, &destsize, (char*)compbuf, compsize, 0, 0)))
{
case BZ_OK:
*origsize=(u64)destsize;
return FSAERR_SUCCESS;
default:
errprintf("BZ2_bzBuffToBuffDecompress() failed, res=%d\n", res);
return FSAERR_UNKNOWN;
}
return FSAERR_UNKNOWN;
}
示例14: crm_ipc_decompress
static int
crm_ipc_decompress(crm_ipc_t * client)
{
struct crm_ipc_response_header *header = (struct crm_ipc_response_header *)(void*)client->buffer;
if (header->size_compressed) {
int rc = 0;
unsigned int size_u = 1 + header->size_uncompressed;
/* never let buf size fall below our max size required for ipc reads. */
unsigned int new_buf_size = QB_MAX((hdr_offset + size_u), client->max_buf_size);
char *uncompressed = calloc(1, new_buf_size);
crm_trace("Decompressing message data %u bytes into %u bytes",
header->size_compressed, size_u);
rc = BZ2_bzBuffToBuffDecompress(uncompressed + hdr_offset, &size_u,
client->buffer + hdr_offset, header->size_compressed, 1, 0);
if (rc != BZ_OK) {
crm_err("Decompression failed: %s (%d)", bz2_strerror(rc), rc);
free(uncompressed);
return -EILSEQ;
}
/*
* This assert no longer holds true. For an identical msg, some clients may
* require compression, and others may not. If that same msg (event) is sent
* to multiple clients, it could result in some clients receiving a compressed
* msg even though compression was not explicitly required for them.
*
* CRM_ASSERT((header->size_uncompressed + hdr_offset) >= ipc_buffer_max);
*/
CRM_ASSERT(size_u == header->size_uncompressed);
memcpy(uncompressed, client->buffer, hdr_offset); /* Preserve the header */
header = (struct crm_ipc_response_header *)(void*)uncompressed;
free(client->buffer);
client->buf_size = new_buf_size;
client->buffer = uncompressed;
}
CRM_ASSERT(client->buffer[hdr_offset + header->size_uncompressed - 1] == 0);
return pcmk_ok;
}
示例15: bz2_decompress
int bz2_decompress(shared_ptr<FileBuffer> pbz, FileBuffer *p, vector<bz2_blk> * pblk, size_t start, size_t skip)
{
for (int i = start; i < pblk->size(); i += skip)
{
unsigned int len;
if (i) /*skip first dummy one*/
{
(*pblk)[i].error = BZ2_bzBuffToBuffDecompress((char*)p->data() + pblk->at(i).decompress_offset,
&len,
(char*)pbz->data() + pblk->at(i).start,
pblk->at(i).size,
0,
0);
(*pblk)[i].actual_size = len;
}
}
return 0;
}