public async Task ProcOneMessage() { var headerbytes = await RPCData.ReadBytes(stream, RPCData.HEADER_SIZE); var id = (RPCMethodId)BitConverter.ToInt16(headerbytes, 0); var csize = BitConverter.ToInt32(headerbytes, 2); object arg = null; if (csize > 0) { var data = RPCData.SplitChunks(await RPCData.ReadBytes(stream, csize)); Type type = null; if (id == RPCMethodId.OnAddResult) { type = typeof(string); } else if (id == RPCMethodId.OnOperationResult) { type = typeof(OperationResult); } if (type != null) { arg = new DataContractSerializer(type).ReadObject(data[0]); } } OnRequestReceived(id, arg); }
public static object Deserialize(Type type, byte[] bytes) { var data = RPCData.SplitChunks(bytes); var arg = new DataContractSerializer(type).ReadObject(data[0]); // 画像だけ特別処理 var setter = ImageSetter(arg); if (setter != null) { List <BitmapFrame> images = new List <BitmapFrame>(); for (int i = 1; i < data.Count; ++i) { if (data[i].Length == 0) { images.Add(null); } else { images.Add(BitmapFrame.Create(data[i])); } } setter(images); } return(arg); }