Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

unpack data form binary string

New Here ,
Jan 17, 2010 Jan 17, 2010

Hello,

i need help for unpacking data from a binary string. I realized it with a php code:

list($empty,$size) = unpack( 'V', fread($socket,4) );    $theresult = fread($socket,$size);

But how can i do this in as3 ? I didn´t find a possibilty to encode "unsigned long (always 32 bit, little endian byte order)". Is there a option like unpack in as3 ?

Thanks for help,

Jojo

TOPICS
ActionScript
982
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 17, 2010 Jan 17, 2010

There is the ByteArray class. Exactly how you will get your data into it I'm not sure, but that is what you need.

http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/utils/ByteArray.html

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 18, 2010 Jan 18, 2010

Hi,

thank your for helping me. I tried all reading methods but i get always a four-sided figure which is empty. This shows me that he does not correctly recognize the format or he doesn´t know it. because this i posted the exact php code to get a solution. Maybe i´m wrong with my socket connection but i think i would get no data back form the server if my socket connection is wrong. I will just continue to try.

Edit:

Ok know i get the correct lenght of my data which I expect but how i can show this as string, not the length:

var ba:ByteArray = new ByteArray();

               socket.readBytes(ba);

               var sba:String = ba[0];

sba shows me the correct length but how can i get this as string ? (socket is normal socket connection);

Thanks for your help so far.

best regards,

Jojo

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 18, 2010 Jan 18, 2010

I think you might need readMultiByte() or one of the other "read" methods. I'm never totally clear on how many bytes each of the different ones get. But the code could look something like this:

var ba:ByteArray = new ByteArray();

socket.readBytes(ba);

socket.position=0

var sba:String = ba.readMultiByte(2,"unicode");

Of course you will need to replace "unicode" with whatever scheme the information is encoded with.

I was just involved in another thread (http://forums.adobe.com/message/2525912#2525912) a discussions where Flash seems to not properly understand UTF-16LE, so I'm not sure if that will cause you any problem (or if it is even related to what you are trying to do.

Re: UTF-16 representation in a ByteArray REgards

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 20, 2010 Jan 20, 2010
LATEST

Hello,

big thanks to you, now i get the data correctly. Because of the Bug, i get UTF 32 Bit Little Endian data, that is it´s only a bug with the 16bit LE.

Best regards,

Jojo

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines