Esempio n. 1
0
        public static Server GetServer(string id)
        {
            var pnt = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Server)));
            var ret = new Server();

            try
            {
                Marshal.StructureToPtr(ret, pnt, false);
                bool success = GetServerInternal(GoString.fromString(id), pnt);
                if (success)
                {
                    ret = (Server)Marshal.PtrToStructure(pnt, typeof(Server));
                    FreeServer(pnt);
                    return(ret);
                }
                throw new Exception("failed to get server! with id " + id);
            } finally
            {
                Marshal.FreeHGlobal(pnt);
            }
        }
Esempio 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);
            }
        }