LoadBalancingApi can not serialize an array?

zhuchun
zhuchun
edited December 2018 in Photon Server
Hi, in order to combine packet as much as possible, I want to wrap my data into Dictionary[] and then send it to the server. But Unity Editor throws IndexOurOfRangeExceptions while trying to serialize it. Is that a bug or custom data has to be sent as a Hashtable?

Snapshot:
image

-----
CustomData:

var inputs= new List <Dictionary <byte,object>>(); foreach (var input in e.inputBuffer.Cached) { inputs.Add(input.ToDictionary()); } var customDataToBeSent = inputs.ToArray();
-----

Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    Hi @zhuchun,

    You can't serialize an array of dictionaries.
    Read "Serialization in Photon".
  • Hi.

    To clarify for future readers, who use other clients:
    Actually sending Arrays of Dictionaries is supported on the server and in some clients (I know for sure that it is supported in the C++ and objective C clients - @vadim should be able to tell about the others), just not in the C# client.
  • Thank you.

    In that Serialization in Photon page it said

    array (array of type T, T[])
    T-type can be any of the types listed in this table except byte.
    So I thought Dictionary is OK :p Does it mean collection array is not supported in the C# LoadBalacingApi?
    Is there any supported way to send data in batch?
  • >Does it mean collection array is not supported in the C# LoadBalacingApi?
    Yes, exactly. Current version for some reason does not support this feature

    >Is there any supported way to send data in batch?
    please ask in a corresponding forum section. I would suggest using a dictionary or hashtable

    best,
    ilya
  • zhuchun
    zhuchun
    edited December 2018
    Thank you @chvetsov It's feasible to use hashtable instead of array for now
  • Kaiserludi
    Kaiserludi admin
    edited December 2018
    Hi @zhuchun.

    I am not too familiar with the C# Client myself, so I am not 100% sure that this will work, but what you could also try is casting your array of Dictionaries into an array of Objects. Object arrays are treated differently by Photons serialization code than normal arrays. For the former the type info is written not once per array, but once per element, as each element could be of a different type. Due to this difference there is a good chance that sending Object arrays with Dictionary elements works in the current C# clients.