I want to compress a data buffer before sending it over the network for performance reasons. For this I decided to implement Zlib. However, I'm getting a MEM_ERROR return code (-4). I closely followed the implementation from here since it seemed reasonably easy and it matches up nicely with what the Wii U has (compress and compress2 functions).
C server code:
Java client code:
Note that the Wii U implements it in zlib125.rpl.
Any help is greatly appreciated, thank you.
@QuarkTheAwesome
@dimok
@Maschell
@wj44
@NWPlayer123
C server code:
Code:
case 0x09: { /* read_memory_compressed */
int startingAddress = 0x10000000; /* Hardcoded example */
int length = 0x1000;
// Setup raw data buffer
void *rawBuffer = malloc(length);
ASSERT_ALLOCATED(rawBuffer, "Raw buffer")
memcpy(rawBuffer, (const void *) startingAddress, length);
// Setup compressed buffer
int compressedBufferSize = (int) (length + (length * 0.1) + 12) + 1;
void *compressedBuffer = malloc(compressedBufferSize);
ASSERT_ALLOCATED(compressedBuffer, "Compressed buffer")
int destinationBufferSize;
int status = compress2((char *) compressedBuffer, &destinationBufferSize, (const char *) rawBuffer, length, Z_BEST_COMPRESSION);
ret = sendwait(bss, clientfd, &status, 4);
ASSERT_FUNCTION_SUCCEEDED(ret, "sendwait (status)")
if (status == Z_OK) {
// Send the compressed buffer size and content
((int *) buffer)[0] = destinationBufferSize;
memcpy(buffer + 4, compressedBuffer, destinationBufferSize);
ret = sendwait(bss, clientfd, buffer, 4 + destinationBufferSize);
ASSERT_FUNCTION_SUCCEEDED(ret, "sendwait (Compressed data)")
}
free(rawBuffer);
free(compressedBuffer);
break;
}
Code:
public byte[] readCompressedBytes() throws IOException
{
try (CloseableReentrantLock ignored = reentrantLock.acquire())
{
sendCommand(Command.READ_MEMORY_COMPRESSED);
dataSender.flush();
ZLibReturnCode status = ZLibReturnCode.parse(dataReceiver.readInt());
if (status.equals(ZLibReturnCode.OK))
{
int compressedSize = dataReceiver.readInt();
byte[] bytes = new byte[compressedSize];
dataReceiver.readFully(bytes);
return bytes;
}
throw new IllegalStateException("Compression returned with status: " + status);
}
}
Code:
Exception in thread "main" java.lang.IllegalStateException: Compression returned with status: MEM_ERROR
Any help is greatly appreciated, thank you.
@QuarkTheAwesome
@dimok
@Maschell
@wj44
@NWPlayer123
Last edited by BullyWiiPlaza,