Context:
I have a successful implementation of CloudScript server round-trip involving serialization/deserialization of a complex nested serializable C# object (named PlayerDataModel or pdm).
Problem:
I feel it is not optimized because I find myself in need of many inefficient steps.
My Implementation:
1. Serialize the pdm from its object form into a string then send to Cloudscript via ExecuteCloudScript
PlayFabClientAPI.ExecuteCloudScript( new ExecuteCloudScriptRequest() { FunctionName = "SavePlayerDataModel", FunctionParameter = new { pdm = JsonUtility.ToJson(pdm) }, }, ...
2. CloudScript deserializes the pdm string to put it back into a javascript object form in order to be able to work with it.
handlers.SavePlayerDataModel = function(args, context) { let pdm = JSON.parse(args.pdm); ... // work with pdm, reading/writing from/to its fields.
3. Convert the pdm javascript object back into a string to be able to store it in the the Player Data (Title)
let data = { }; data.PlayerDataModel = JSON.stringify(pdm); server.UpdateUserData({ "PlayFabId": currentPlayerId, "Data": data });
4. Return the javascript object "pdm" to the client because it will have been modified by the server and the client needs to update to its latest state.
return { "pdm": pdm };
5. The client deserializes the coming json stream to transform it back into a C# object
resultCallback: result => { JsonObject jsonResult = (JsonObject) result.FunctionResult; PlayerDataModel pdmFromServer = JsonUtility.FromJson<PlayerDataModel>(jsonResult["pdm"].ToString()); ...
My Concern/Question:
I feel like there's probably lots of inefficiencies in this flow.
Could you please suggest a better way of achieving this?
Thanks and regards