neoxic / php-amf3

PHP AMF3 extension

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

flash amf3 vs php amf3

lingfan opened this issue · comments

json string:
[[10000,1,[]],[10001,2,{"4":19448,"0":1798}],[10001,1,{"20":22800}],[10001,6,{"1":[[2,0],[2,0],[2,0]]}],[10001,8,{"2":["2",1,14,[15,84,15,1055]]}]]

flash (amf3 encode + base64) string:
CQsBCQcBBM4QBAEJAQEJBwEEzhEEAgoLAQM0BIGXeAMwBI4GAQkHAQTOEQQBCgEFMjAEgbIQAQkHAQTOEQQGCgEDMQkHAQkFAQQCBAAJBQEEAgQACQUBBAIEAAEJBwEEzhEECAoBAzIJCQEGCAQBBA4JCQEEDwRUBA8EiB8B

php (amf3 encode + base64) string:
CQsBCQcBBM4QBAEJAQEJBwEEzhEEAgkBAzQEgZd4AzAEjgYBCQcBBM4RBAEJAQUyMASBshABCQcBBM4RBAYJAQMxCQcBCQUBBAIEAAkFAQQCBAAJBQEEAgQAAQkHAQTOEQQICQEDMgkJAQYIBAEEDgkJAQQPBFQEDwSIHwE=

becase of the data not same, so the flash don't parse php amf3encode data.

this is bug?

Umm, it looks like we are missing something important here.

First, I did:

$s = '[[10000,1,[]],[10001,2,{"4":19448,"0":1798}],[10001,1,{"20":22800}],[10001,6,{"1":[[2,0],[2,0],[2,0]]}],[10001,8,{"2":["2",1,14,[15,84,15,1055]]}]]';
$s = json_decode($s);
$s = amf3_encode($s);
print base64_encode($s);

which produces:

CQsBCQcBBM4QBAEJAQEJBwEEzhEEAgoLAQM0BIGXeAMwBI4GAQkHAQTOEQQBCgEFMjAEgbIQAQkHAQTOEQQGCgEDMQkHAQkFAQQCBAAJBQEEAgQACQUBBAIEAAEJBwEEzhEECAoBAzIJCQEGCAQBBA4JCQEEDwRUBA8EiB8B

This is exactly what you mention above as produced by Flash. So, where is the problem?

I also compared the two binary strings you sent. Here they are:

090b0109070104ce10040109010109070104ce110402 0a0b01 0334048197780330048e060109070104ce110401 0a 010532300481b2100109070104ce110406 0a 0103310907010905010402040009050104020400090501040204000109070104ce110408 0a 01033209090106080401040e090901040f0454040f04881f01
090b0109070104ce10040109010109070104ce110402 0901   0334048197780330048e060109070104ce110401 09 010532300481b2100109070104ce110406 09 0103310907010905010402040009050104020400090501040204000109070104ce110408 09 01033209090106080401040e090901040f0454040f04881f01

The difference between the two is that purely associative arrays are encoded as objects (0x0A) in the first stream instead of being arrays (0x09) in the second. Both streams look perfectly correct. So basically, my questions are:

Do you really get the decoding error in Flash? If yes, I'd like to see a piece of Flash code that clearly shows this case.

Did you cook this example? See, the thing is that I suspect that these Objects could come out directly from the usage of PHP's json_decode that represents pure associative arrays as 'stdObject' classes which leads to consequent amf3_encode's behaviour representing those things as AMF3 Objects.

So basically, I need to know what exactly you are trying to do and what exactly you are observing. Because for now, it's some sort of misunderstanding.... Please provide some more information.

o sorry! i don't try it

$s = json_decode($s);
$s = amf3_encode($s);
print base64_encode($s);

Production environment is
$a = amf3_encode(php array)
echo $a;

the as3 get the $a content
don't parse the

{"4":19448,"0":1798}

you need try write
$b = array(1,array("4"=>1111,"0"=>4444));
$b = amf3_encode($b)

as3 parse $b content (the object part don't parse)

php is array
json is object
flash is object

$s = '[[10000,1,[]],[10001,2,{"4":19448,"0":1798}],[10001,1,{"20":22800}],[10001,6,{"1":[[2,0],[2,0],[2,0]]}],[10001,8,{"2":["2",1,14,[15,84,15,1055]]}]]'

$s = json_decode($s, true);

as3 parse result:
0 10000,1,
1 10001,2,1798,,,,19448
2 10001,1,,,,,,,,,,,,,,,,,,,,,22800
3 10001,6,,2,0,2,0,2,0
4 10001,8,,,2,1,14,15,84,15,1055

i know you need

$s = json_decode($s, true);
$s = amf3_encode($s);
print base64_encode($s);

this has bug in "object" vs "php is array"

$s = '[[10000,1,[]],[10001,2,{"4":19448,"0":1798}],[10001,1,{"20":22800}],[10001,6,{"1":[[2,0],[2,0],[2,0]]}],[10001,8,{"2":["2",1,14,[15,84,15,1055]]}]]';

$s = json_decode($s);
$s = amf3_encode($s);
print base64_encode($s);

CQsBCQcBBM4QBAEJAQEJBwEEzhEEAgoLAQM0BIGXeAMwBI4GAQkHAQTOEQQBCgEFMjAEgbIQAQkHAQTOEQQGCgEDMQkHAQkFAQQCBAAJBQEEAgQACQUBBAIEAAEJBwEEzhEECAoBAzIJCQEGCAQBBA4JCQEEDwRUBA8EiB8B

$s = json_decode($s, true);
$s = amf3_encode($s);
print base64_encode($s);

CQsBCQcBBM4QBAEJAQEJBwEEzhEEAgkBAzQEgZd4AzAEjgYBCQcBBM4RBAEJAQUyMASBshABCQcBBM4RBAYJAQMxCQcBCQUBBAIEAAkFAQQCBAAJBQEEAgQAAQkHAQTOEQQICQEDMgkJAQYIBAEEDgkJAQQPBFQEDwSIHwE=

Sorry, it's really hard to understand you, but I think I got what you were trying to say.

You say:

you need try write
$b = array(1,array("4"=>1111,"0"=>4444));
$b = amf3_encode($b)
as3 parse $b content (the object part don't parse)

So, the Flash DOES parse the data, but you can't use it - is that what you are trying to say?

Try the AMF3_FORCE_OBJECT mode, i.e. use:

amf3_encode($data, AMF3_FORCE_OBJECT)

This will always convert pure PHP associative arrays (your case) into anonymous objects on the Flash side.

You probably believe that "Flash doesn't parse" because you can't see the data. It's not quite correct. Unless you get an explicit parse exception in Flash, the decoding was successful.

As to the arrays, please read about the difference between Objects and associative Arrays in Flash to clear things out. It has nothing to do with AMF parsing. Generally speaking, you can still use associative arrays in Flash except for object-style field access (you can't use the Object.name notation to access the members; you should use the object["name"] notation instead). You can still use foreach and all that jazz. The length of a pure associative array is always zero.

thanks very march!

you are right

i use

amf3_encode($data, AMF3_FORCE_OBJECT)

is ok! :)