DIFF

class JsonSerializerSource

JsonSerializer Serializer Managed

All members, including inherited

Class for sending RPC over network

// example sending
void Send()
{
	ScriptRPC rpc = new ScriptRPC();

	rpc.Write(645);
	rpc.Write("hello");

	array<float> farray = {1.2, 5.6, 8.1};
	rpc.Write(farray);

	rpc.Send(m_Player, ERPCs.RPC_TEST, true, m_Player.GetIdentity());
}

// example receive
void OnRPC(ParamsReadContext ctx)
{
	int num;
	string text;
	array<float> farray;

	ctx.Read(num);
	ctx.Read(text);
	ctx.Read(farray);
}

Constructors 2

void ~JsonSerializer()

Methods 2

proto bool WriteToString(void variable_out, bool nice, out string result)

Script variable serialization to json string

variable_out
script variable to be serialized to string
nice
if the string should be formated for human readability
result
from the serialization, output or error depending on the return value

Returns: if the serialization was successful

Data data;
string textOut;
bool nice = false;
JsonSerializer js = new JsonSerializer();
bool ok = js.WriteToString(data, false, textOut);
proto bool ReadFromString(void variable_in, string jsonString, out string error)

Json string deserialization to script variable

variable_in
script variable to be deserialized from string
jsonString
the input string
error
from the deserialization. Is used only if the return value of the function is false

Returns: if the deserialization was successful

// Example json
//  {
//    "i": 6,                                 // Int
//    "f": 3.5,                               // Float
//    "v": [1.1,2.2,3.3]                      // Vector3 is static array of size 3
//    "s": "string",                          // String
//    "subData": {                            // Object
//      "staticIArr": [9,8],                  // Static array (of ints)
//      "dynamicSArr": ["string1","string2"]  // Dynamic array (of strings)
//    },                                      //
//    "fSet": [12.3,14.7],                    // Set (of floats)
//    "ifMap": {                              // Map (of int, float), only valid key type is int, enum, string
//      "3": 4.5,							  // Map key has to be as string
//      "4": 5.5
//    }
//  }

Data data = new Data;
string input = // valid json string;
string error;
   bool ok = js.ReadFromString(data, input, error);