Пример #1
0
        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);
        }
Пример #2
0
        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
            });
        }