Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
IPCMessage.cs
Go to the documentation of this file.
1using System;
3using System.Linq;
4using System.Text;
5
7
8public class IPCMessage
9{
11
12 private string _jsonData;
13
14 public void Build<T>(IPCMessageType cmd, T t)
15 {
16 _jsonData = WeGameHelper.Serialize(t);
17 _cmd = cmd;
18 }
19
20 public void BuildFrom(byte[] data)
21 {
22 byte[] value = data.Take(4).ToArray();
23 byte[] bytes = data.Skip(4).ToArray();
25 _jsonData = Encoding.UTF8.GetString(bytes);
26 }
27
28 public void Parse<T>(out T value)
29 {
30 WeGameHelper.UnSerialize<T>(_jsonData, out value);
31 }
32
33 public byte[] GetBytes()
34 {
36 byte[] bytes = BitConverter.GetBytes((int)_cmd);
37 list.AddRange(bytes);
38 list.AddRange(Encoding.UTF8.GetBytes(_jsonData));
39 return list.ToArray();
40 }
41
43 {
44 return _cmd;
45 }
46}
static byte[] GetBytes(bool value)
static int ToInt32(byte[] value, int startIndex)
static Encoding UTF8
Definition Encoding.cs:526
void Build< T >(IPCMessageType cmd, T t)
Definition IPCMessage.cs:14