Exemplo n.º 1
0
        private static T GetProtoMessageFromResponse <T>(RPCRes rpcRes)
        {
            byte[] resData  = rpcRes.getResData();
            var    response = new Protos.Response();

            response.MergeFrom(new CodedInputStream(resData));
            var res = (IMessage)Activator.CreateInstance(typeof(T));

            res.MergeFrom(new CodedInputStream(response.Data.ToByteArray()));
            Logger.Debug("getProtoMsgFromResponse: got this res {0}", res);

            return((T)res);
        }
Exemplo n.º 2
0
        public static T RPC <T>(string serverId, Route route, IMessage msg)
        {
            byte[] data = ProtoMessageToByteArray(msg);
            var    ret  = new RPCRes();
            IntPtr pnt  = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(RPCRes)));

            try
            {
                Marshal.StructureToPtr(ret, pnt, false);
                bool success = SendRPC(GoString.fromString(serverId), route, GoSlice.fromSlice <byte>(data), pnt);
                if (success)
                {
                    ret = (RPCRes)Marshal.PtrToStructure(pnt, typeof(RPCRes));
                    T protoRet = GetProtoMessageFromResponse <T>(ret);
                    FreeRPCRes(pnt);
                    return(protoRet);
                }
                throw new Exception("RPC call failed!");
            } finally
            {
                Marshal.FreeHGlobal(pnt);
            }
        }