Support for Unsigned value types

Options
zeppelinisgod
edited July 2012 in Photon Server
Hello,

I'm kinda bothered by the fact Photon doesn't support Unsigned value types, is there a particular reason for that? Because, I ended up writing my own serialization method for common unsigned values. This creates a minor problem since I serialize the unsigned value to a byte array, this means, photon will add an extra 5 bytes since its an array so it needs to have its length stored. This adds an extra 5 bytes to all unsigned values I send.

UInt32 = 5 + 4 * 1 = 9
UInt64 = 5 + 8 * 1 = 13

Is there any way to avoid it(No, I DEFINITELY HAVE to use Unsigned over signed) or is there any possibility that unsigned value types will be supported in the next version?

Thank you!

Comments

  • It was stated if it's requested often enough, they might implement signed/unsigned value types. :D ( so yeah- bump! )

    re: serializing yourself
    Hmm does sound wasteful. Maybe instead could you parse the unsigned value after getting it from Photon, like this?

    // int to uint
    uint res = (uint) i + int.MaxValue + 1;
    // uint to int
    int res = (int) i - int.MaxValue - 1;

    (warning I dont know if that's always correct, but seems to work for me!)
  • Kaiserludi
    Options
    1. Its 3 extra bytes, not 4, as Photon sends array-lengths as short, not as int, to save bandwidth.

    2. You could just cast your unsigned values to signed before sending and cast them back afterwards. Your clients know, which values tghey have to interpret as unsigned, so this will work and you do not have any extra bytes costs for that.

    The main reason for Photon not supporting unsigned values is, that Photon is a multi platform engine. It does not only support C# clients, but also C, C++, objective C, Java, Flash and Java Script ones. All these clients can play in the same games: inter platform compatibility is a feature, thats used by a lot Photon using games. Therefor we only support types, that can be supported on all clients (with the exception of Flash, as the type support in Action Script it that limited, that it doesn't make sense to limit other clients that far). As Java does not have support for unsigned types in the language at all, we do not support them in Photon, as any game, using them, would need changes on all other client platforms, as soon, as it would be ported to Java (which is not an uncommon scenario for non-unity clients, for example for games, that use objective C on iOS, but Java on Android). Of course we could add unsigned types support nontheless with a big warning on it "use at your own risk. Parents will be held liable for damage done by their children.", but as you could just cast them yourself, when you absolutely need them, there is really no need.
  • thnx both of you. Its nice to know photon doesn't send 5 bytes for array size. I actually ended up rewriting everything back to signed.