PC Stable Documentation
 
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Loading...
Searching...
No Matches
JsonSerializer Class Reference

Class for sending RPC over network. More...

Private Member Functions

void JsonSerializer ()
 
void ~JsonSerializer ()
 
proto bool WriteToString (void variable_out, bool nice, out string result)
 Script variable serialization to json string.
 
proto bool ReadFromString (void variable_in, string jsonString, out string error)
 Json string deserialization to script variable.
 

Detailed Description

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
{
int num;
string text;
array<float> farray;
ctx.Read(num);
ctx.Read(text);
ctx.Read(farray);
}
ERPCs
Definition ERPCs.c:2
PlayerBase m_Player
Definition TransferValues.c:10
void OnRPC(ParamsReadContext ctx)
Definition TransferValues.c:165
Definition gameplay.c:105
proto native void Send(Object target, int rpc_type, bool guaranteed, PlayerIdentity recipient=NULL)
Initiate remote procedure call. When called on client, RPC is evaluated on server; When called on ser...
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
proto bool Write(void value_out)
proto bool Read(void value_in)
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Definition IsBoxCollidingGeometryProxyClasses.c:28

Constructor & Destructor Documentation

◆ JsonSerializer()

void JsonSerializer ( )
inlineprivate

◆ ~JsonSerializer()

void ~JsonSerializer ( )
inlineprivate

Member Function Documentation

◆ ReadFromString()

proto bool ReadFromString ( void  variable_in,
string  jsonString,
out string  error 
)
private

Json string deserialization to script variable.

Parameters
variable_inscript variable to be deserialized from string
jsonStringthe input string
errorfrom 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);
JsonDataAreaData Data
Definition JsonDataContaminatedArea.c:13

Referenced by GetControlMappingInfo(), and UIScriptedMenu::GetControlMappingInfo().

◆ WriteToString()

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

Script variable serialization to json string.

Parameters
variable_outscript variable to be serialized to string
niceif the string should be formated for human readability
resultfrom the serialization, output or error depending on the return value
Returns
if the serialization was successful
Data data;
string textOut;
bool nice = false;
bool ok = js.WriteToString(data, false, textOut);
Class for sending RPC over network.
Definition gameplay.c:50
void JsonSerializer()
Definition gameplay.c:51
proto bool WriteToString(void variable_out, bool nice, out string result)
Script variable serialization to json string.

The documentation for this class was generated from the following file: