ios - Convert stream bytes to string -
i using google protocol buffers send data c++ server ios app. use function on ios side convert stream bytes string:
-(nsstring*)convertstreambytestostring:(nsmutabledata*)data { int len = [data length]; char raw[len]; [data getbytes:raw length:len]; nsstring *protocstruct =[[nsstring alloc] initwithbytes:raw length:len encoding:nsutf8stringencoding]; return protocstruct; }
my problem doesn't work. can see send , receive bytes, when converting of them lost. example 83 bytes, when printing string 20 characters. rest ? there problem don't know converting method ?
nsstring class handling unicode strings. cannot store arbitrary bytes in c string. (and cannot transmit binary data in place of character string , expect survive transport)
you need convert binary data string in way results in valid text string. example via base64 encoding.
there lots of ios projects can encode/decode base64, google it.
here's article it: http://www.cocoawithlove.com/2009/06/base64-encoding-options-on-mac-and.html?m=1
Comments
Post a Comment