Shared data types

edited July 2010 in Photon Server
This mostly applies to operations. Right now on the server side, there is ResponseParameterAttribute and RequestParameterAttribute. This allows me to create data structures representing the data that I will need to read/write for each operation. However, the client unfortunately can't share these structures because it must duplicate that serialization logic (i.e. the parsing of an operation's Params dictionary). Does Photon provide a way to share operation data structures between client/server? If not, would it be possible to add this in a later version?

When I add/remove/change a variable in this data structure on the server, ideally the change propagates to the client as well. This is beneficial because it would result in unit tests failing on the client (this is a good thing; if data structures change we want to know, so we don't leave the client reading improper data from operation responses).

I'd be interested in hearing opinions on this from the developers. Thanks in advance.

Comments

  • Currently, there is no support for sharing strict definitions of operations between server and clients in Photon.
    The idea is interesting but probably limited to DotNet clients. Also, there are follow up issues with this, as the client would need to adjust to changes somehow or would throw exceptions everywhere.

    A feature like this is not planned by us, at the moment.


    Two classic ways to avoid issues with changes on either side of client / server:
    - Add a version number to client and server. On change of operations you increase the number. Send the version of clients in an operation and make that operation fail if the versions don't match.
    - Operations that fail to deserialize on the server can still return a failure code. Use new OperationResponse(). Client side, check for error codes and make your unit tests fail accordingly.

    A more advanced way would be to generate client code, based on your operation classes. You could use the Attributes to get operation parameters and returns. The invocation id (returned by PhotonPeer.OpCustom()) allows you to map a result to the request you made.
  • BorisBoris ✭✭
    for c# unit tests: you can create a new OperationRequest() with Protocol.GpBinaryByte and a dictionary which is almost 1:1 your hashtable, just that there are shorts instead of byte keys. So you would have to code something to translate it. Then you can actually use PopulateParameters() to test if your structure works
Sign In or Register to comment.