Hashtable in another Hashtable

I tryed to send an Hashtable in another Hashtable to the server in flash.
like:
[code2=as3]var arrInt:Array = [1,2,3];
var arrFloat:Array = [4,5.5,6];
var table2:Dictionary = new Dictionary();
table2[1]=1234;
table2["8"]="8";
var table1:Dictionary = new Dictionary();
table1[1]=1;
table1[2]=123;
table1[3]=13;
table1[4]="abcd";
table1[5]=dicData;
table1[6]=arrInt;
table1[7]=arrFloat;[/code2]
when get the value on server side, the keys and values of table1 are correct.
but the type of keys in table2 is string, not the int.
and the value of the key "8" is "abcd", not "8".
what should i do?

TestRequest.cs[code2=csharp]public class TestRequest : Operation
{
public TestRequest(IRpcProtocol protocol, OperationRequest request)
: base(protocol, request)
{
}

[DataMember(Code = (byte)TestRequestKey.TestByte, IsOptional = true)]
public byte TestByte;
[DataMember(Code = (byte)TestRequestKey.TestInt, IsOptional = true)]
public int TestInt;
[DataMember(Code = (byte)TestRequestKey.TestFloat, IsOptional = true)]
public float TestFloat;
[DataMember(Code = (byte)TestRequestKey.TestString, IsOptional = true)]
public string TestString;
[DataMember(Code = (byte)TestRequestKey.TestHashtable, IsOptional = true)]
public Hashtable TestHashtable;
[DataMember(Code = (byte)TestRequestKey.TestIntArray, IsOptional = true)]
public int[] TestIntArray;
[DataMember(Code = (byte)TestRequestKey.TestFloatArray, IsOptional = true)]
public float[] TestFloatArray;
}[/code2]


The handle function in Peer on the Server side.
[code2=csharp]private OperationResponse OnHandleTest(PeerBase peer, OperationRequest operationRequest, SendParameters sendParameters)
{
TestRequest wRequest = new TestRequest(this.Protocol,operationRequest);
if(!wRequest.IsValid)
{
Log.Debug("OnHandleTest InValid");
return null;
}

string msg = "";
msg += "byte:" + wRequest.TestByte;
msg += ",int:" + wRequest.TestInt;
msg += ",float:" + wRequest.TestFloat;
msg += ",string:" + wRequest.TestString;
msg += ",table:" + wRequest.TestHashtable.Count;
IDictionaryEnumerator wEnum = wRequest.TestHashtable.GetEnumerator();
while(wEnum.MoveNext())
{
msg += String.Format("\r\nkey: type={0},value={1}; value: type={2},value={3}", wEnum.Key.GetType(), wEnum.Key, wEnum.Value.GetType(),wEnum.Value);
}
if(Log.IsDebugEnabled)
Log.DebugFormat(msg);
return null;
}[/code2]

In the flash.
I create a class extends from the PhotonCore.
The code in this class
[code2=as3]public function testSendRequest():void
{
var arrInt:Array = [1,2,3];
var arrFloat:Array = [4,5.5,6];
var dicData:Dictionary = new Dictionary();
dicData[1]=1234;
dicData["8"]="8";
var dic:Dictionary = new Dictionary();
dic[1]=1;
dic[2]=123;
dic[3]=13;
dic[4]="abcd";
dic[5]=dicData;
dic[6]=arrInt;
dic[7]=arrFloat;
SendRequest(0,dic);
}
public function SendRequest(opCode:int, opData:Dictionary = null):void
{
var data : Array = [];
var dic: Dictionary = opData;
var key:*;
var value:*;
for (key in dic)
{
value = dic[key];
data.push(key);
if (value is Dictionary)
{
data.push(DictionaryUtils.serializeDictionaryToObject(value));
}else {
data.push(value);
}
}
if (data.length <= 0)
sendOperation(opCode, null);
else
sendOperation(opCode, data);
return;
}[/code2]

when i call testSendRequest() to send the data to the server.
I get the log on the server side:
ClientPeer - byte:1,int:123,float:13,string:abcd,table:2
key: type=System.String,value=1; value: type=System.Int32,value=1234
key: type=System.String,value=8; value: type=System.String,value=abcd

Comments

  • When I test it by CSharp, the result is correct.

    [code2=csharp]Hashtable table = new Hashtable();
    table.Add("8", "8");
    table.Add(1, 1234);
    int[] arrInt = {1,2,3};
    float[] arrFloat = {4f,5.5f,6f};
    Dictionary<byte, object> wDic = new Dictionary<byte, object>();
    wDic.Add((byte)1, (byte)1);
    wDic.Add((byte)2, 123);
    wDic.Add((byte)3, 123.02f);
    wDic.Add((byte)4, "abc");
    wDic.Add((byte)5, table);
    wDic.Add((byte)6, arrInt);
    wDic.Add((byte)7, arrFloat);
    this._conn.SendRequest((byte)OperationCode.Test, wDic);[/code2]

    On the Server side i get the log:
    ClientPeer - byte:1,int:123,float:123.02,string:abc,table:2
    key: type=System.Int32,value=1; value: type=System.Int32,value=1234
    key: type=System.String,value=8; value: type=System.String,value=8
  • We always have trouble with supporting Flash fully, due to it's limitations with types, so nested Hashtables are most likely affected by this.
    Can you work around this?
    Sadly, I can't promise we can do something about it really soon.
Sign In or Register to comment.