c# - Extract the byte array of Zip files sent from C # in Objective-c side -
it passes c # byte array of zip files via plugin in objective-c, want thaw in objective-c side, suffering not go well. byte data has been converted nsdata type using zlib following url reference tried thaw but, inflate (& stream, z_no_flush); of after review of our return value, have been returned z_data_error data can not decompressed zlib determined have been input not know cause, please tell me if there people knowledge
■ url
https://gist.github.com/hacha/9207616
http://www.zlib.net/zlib_how.html
sourcecode(c#)
using unityengine; using system.collections; using system.runtime.interopservices; public class callplugin : monobehaviour { [dllimport("__internal")] private static extern void uncompressbygzip(byte[] zipbytearray,int ziplen); public void callmain(byte[] unzipstream,int unziplength){ uncompressbygzip (unzipstream,unziplength); debug.log ("test csharp"); } }
sourcecode(objective-c)
#import <foundation/foundation.h> #include <zlib.h> extern "c"{ void uncompressbygzip(const char** ptrsrc, const int srclength); } void uncompressbygzip(const char** ptrsrc, const int srclength) { nsdata *source = [nsdata datawithbytes:(const void *)ptrsrc length:(sizeof(unsigned char) * srclength)]; nsstring* str = [nsstring stringwithformat:@"%d",srclength]; nslog(@"src = %@",str); if (source.length == 0) return; nslog(@"11111"); z_stream stream; stream.zalloc = z_null; stream.zfree = z_null; stream.opaque = z_null; stream.avail_in = (uint)source.length; stream.next_in = (bytef *)source.bytes; stream.total_out = 0; stream.avail_out = 0; nslog(@"22222"); if (inflateinit2(&stream, 31) != z_ok) return; nslog(@"33333"); nsmutabledata *filesystemdata = [nsmutabledata datawithcapacity:0]; while (stream.avail_out == 0) { nslog(@"12345"); bytef buffer[16384]; stream.next_out = buffer; stream.avail_out = sizeof(buffer); nsstring* avail_outbef = [nsstring stringwithformat:@"%d",(nsinteger)stream.avail_out]; nslog(@"avail_outbef = %@",avail_outbef); // inflate(&stream, z_finish); int ret; inflate(&stream,z_no_flush); size_t length = sizeof(buffer) - stream.avail_out; avail_outbef = [nsstring stringwithformat:@"%d",(nsinteger)stream.avail_out]; nslog(@"avail_outaft = %@",avail_outbef); nsstring* strlength = [nsstring stringwithformat:@"%d",(nsinteger)length]; nslog(@"length = %@",strlength); if (length > 0) [filesystemdata appendbytes:buffer length:length]; } inflateend(&stream); nslog(@"44444"); }
your uncompressbygzip
function taking const char**
argument data buffer. i'm not familiar marshalling behavior c# code, looks suspicious since you're passing through byte []
. guess want direct const char *
instead of indirected pointer. call -[nsdata datawithbytes:length:]
expects actual buffer, not pointer one.
Comments
Post a Comment