gpt4 book ai didi

iOS(OC)compression_decode_buffer() 返回空值

转载 作者:行者123 更新时间:2023-11-29 06:02:45 28 4
gpt4 key购买 nike

我有一个工具类。工具类写了lz4解压的方法,但是解压受控,不知道哪里出了问题(libcompression.tbd和#include "compression.h"都有)。下面是代码:

+ (NSData *)getDecompressedData:(NSData *)compressed
{
size_t dst_buffer_size = 168*217;
uint8_t *dst_buffer = (uint8_t *)malloc(dst_buffer_size);
uint8_t *src_buffer = (uint8_t *)malloc(compressed.length);

size_t compressResultLength = compression_decode_buffer(dst_buffer, dst_buffer_size, src_buffer, dst_buffer_size, NULL, COMPRESSION_LZ4);
NSData *decompressed = [[NSData alloc] initWithBytes:dst_buffer length:compressResultLength];
return decompressed;
}

压缩结果长度这个值为0

最佳答案

我错误地选择了这个算法,不应该选择COMPRESSION_LZ4,应该选择COMPRESSION_LZ4_RAW,应用前目标的大小和源数据的大小也错误。我将在下面发送正确的代码:

+ (NSData *)getDecompressedData:(NSData *)compressed{
size_t destSize = 217*168;
uint8_t *destBuf = malloc(sizeof(uint8_t) * destSize);
const uint8_t *src_buffer = (const uint8_t *)[compressed bytes];
size_t src_size = compressed.length;

size_t decompressedSize = compression_decode_buffer(destBuf, destSize, src_buffer, src_size,
NULL, COMPRESSION_LZ4_RAW);
MyLog(@"after decompressed. length = %d",decompressedSize) ;
NSData *data = [NSData dataWithBytesNoCopy:destBuf length:decompressedSize freeWhenDone:YES];
return data;}

关于iOS(OC)compression_decode_buffer() 返回空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51381337/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com