serializerclass-general Mailing List for SerializerClass
Brought to you by:
sephiroth_tmm
You can subscribe to this list here.
2004 |
Jan
|
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2005 |
Jan
(3) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Jamie P <ja...@e-...> - 2005-01-14 12:03:01
|
Hi, I think I found the correct way to calculate string length for serialising and deserialising, both the code in the CVS and the code I previously sent you don't work properly. In the PHP manual it says Unicode is converted to UTF-8 as follows : bytes bits representation 1 7 0bbbbbbb 2 11 110bbbbb 10bbbbbb 3 16 1110bbbb 10bbbbbb 10bbbbbb 4 21 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb It seems that Flash only supports Unicode characters up to 16 bits so we will have to ignore 4 byte UTF-8. We should probably throw an error if someone tries to send 4 byte but someone else can work on that one. Here is the code that I have developed and tested with relevant test cases. private function getCStringLength ():Number { var colon:Number = this.buffer.indexOf (":", 3); // index of second colon var ss:Number = colon+2; // index of start of string var len:Number = parseInt (this.buffer.substr (2, colon - 2)); var i:Number; var j:Number = len; //char length of string to be calculated var c:Number; var cstr = this.buffer; for (i = ss; i < (ss + j); i++) { c=cstr.charCodeAt(i); if (c<128) { //do nothing }else if (c<2048) { j = j-1; } else { j = j-2; } } return j; }; // getCStringLength and used to serialize data : private function calcLength(struct:String) { var c; var result=0; var l = struct.length; for (var i=0; i < l; i++) { c = (struct.charCodeAt(i)); if(c<128) { result += 1; } else if (c<2048) { result += 2; } else { result += 3; } } return result; } This seems to be able to serialize and unserialise all unicode characters supported by Flash properly and construct / reconstruct arrays and strings which can be unserialised and serialised by php . Check out the zip file for my test case here : http://jamiep.org/mbcs/test.zip and see it in action here : http://jamiep.org/mbcs/serialtest.html ALso you may be interested in the way I found to send data to the server : override XML.toString(). It seems if you make XML.toString() return a string and then use XML.sendAndLoad() or XML.send() that exactly the string you return is sent. If you use the XML constructor then XML converts & to & but not if you override XML.toString(). Old news maybe? Jamie |
From: Jamie P <ja...@e-...> - 2005-01-14 08:58:51
|
Here is the fixed serialise class file in full, with some more minor changes. |
From: Jamie P <ja...@e-...> - 2005-01-14 08:47:44
|
Hi all, While reworking PHPobject I came across a bug in Alessandro's serializer class multibyte support. I have tried to fix the deserialize function which wasn't handling MB strings properly. Here are the main changes (- marks the old code + the new): + private function getCStringLength ():Number { + var colon:Number = this.buffer.indexOf (":", 3); // index of second colon + var ss:Number = colon+2; // index of start of string + var len:Number = parseInt (this.buffer.substr (2, colon - 2)); var i:Number; - var j:Number = len; + var j:Number = len; //char length of string to be calculated + var c:Number; var cstr = this.buffer; - for (i = 0; i < j; i++) + for (i = ss; i < (ss + j); i++) { - if (cstr.charCodeAt (i + 5) > 128) - { - j = j - 2; + c=cstr.charCodeAt(i); + + if (c<128) { + //do nothing + }else if (c<1024) { + j = j-1; + } else if (c<32768) { + j = j-2; + } else if (c<2097152) { + j = j-3; } } return j; - }; // getCStringLenght + }; // getCStringLength I am now hoping to get PHPobject working with UTF-8 without all the escaping and urlencoding that is being used now, which I think is largely or probably completely unnecessary. I see that there is already a fix for this issue in the CVS! But my fix is different to yours. My fix does the reverse of your serialize function. Which is right I wonder?? I'm not sure how utf-8 is encoded in Flash. According to the Flash docs then char code can only go to 65535. Jamie |
From: søren j. <dem...@ho...> - 2004-02-22 12:18:38
|
Hi all! I've recently discovered the SerializerClass, and have begun experimenting with it ;) Though all seems to work fine i'm having trouble unserializing data from flash in php, that contains special characters like: "æ ø å" My PHP looks the following: <? error_reporting(E_ALL); /* echo "<br>showing post<br>"; var_dump($_POST); echo "<br>showing get<br>"; var_dump($_GET); $a = $_POST['xmldata']; echo "<br>showing name=\"xmldata\"<br>"; $b = $a['xmldata']; echo $a['xmldata']; $c = $b['Shippinginfo']; var_dump($b['Shippinginfo']); $d = $c['Name']; echo get_object_vars($c); $xml = unserialize(urldecode(stripslashes($_REQUEST['xmldata']))); var_dump($xml); print_r($_REQUEST['xmldata']); */ class xmldata { } $xml = unserialize(urldecode(stripslashes($_REQUEST['xmldata']))); var_dump($xml); ?> Any suggestions to what i'm doing wrong? Secondly is this the way to go, if i want to transport large amounts of data in the area of 300-400 Kb's of data? Or is it better to use the AMF format? Regards Søren Jepsen _________________________________________________________________ Få alle de nye og sjove ikoner med MSN Messenger http://messenger.msn.dk |