Esempio n. 1
0
        public static GoString fromString(string str)
        {
            byte[]   bytes  = Encoding.ASCII.GetBytes(str);
            GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned);

            try
            {
                IntPtr   ptr  = handle.AddrOfPinnedObject();
                GoString gstr = new GoString(ptr, str.Length);
                return(gstr);
            } finally
            {
                if (handle.IsAllocated)
                {
                    handle.Free();
                }
            }
        }
Esempio n. 2
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. 3
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);
            }
        }
Esempio n. 4
0
 static extern bool SendRPC(GoString svId, Route route, GoSlice message, IntPtr ret);
Esempio n. 5
0
 static extern bool GetServerInternal(GoString id, IntPtr ret);
Esempio n. 6
0
 public static extern bool ConfigureJaeger(double probability, GoString serviceName);