public static byte[] Serialize(RPCMethodId id, object obj) { Type type = ArgumentTypes[id]; if (type == null) { return(RPCData.Combine( BitConverter.GetBytes((short)id), BitConverter.GetBytes((int)0))); } var objbyes = Serialize(type, obj); //Debug.Print("Send: " + System.Text.Encoding.UTF8.GetString(objbyes)); return(RPCData.Combine( BitConverter.GetBytes((short)id), BitConverter.GetBytes(objbyes.Length), objbyes)); }
public static async Task <RPCInfo> Deserialize(Stream ns) { var headerbytes = await RPCData.ReadBytes(ns, RPCData.HEADER_SIZE); var id = (RPCMethodId)BitConverter.ToInt16(headerbytes, 0); var csize = BitConverter.ToInt32(headerbytes, 2); //Debug.Print("Header: id=" + id + ", size=" + csize); object arg = null; if (csize > 0) { var data = await RPCData.ReadBytes(ns, csize); //Debug.Print("Received: " + System.Text.Encoding.UTF8.GetString(data)); arg = Deserialize(RPCTypes.ArgumentTypes[id], data); } return(new RPCInfo() { id = id, arg = arg }); }