Exemple #1
0
        public void DefaultsValuesAreNotUsedIfValuesSpecified()
        {
            var spanState = new SpanState(1, 0, 2, SpanFlags.None);
            var started   = TimeUtils.UtcNow;

            // Make sure we choose something different thant the default values
            const string serviceName = SerializerUtils.DefaultServiceName + "_notDefault";
            var          hostPort    = SerializerUtils.DefaultEndPoint.Port + 1;

            const string name = "myRPCmethod";

            var span = new Span(spanState, started)
            {
                Endpoint = new IPEndPoint(IPAddress.Loopback, hostPort), ServiceName = serviceName, Name = name
            };

            AddClientSendReceiveAnnotations(span);

            var thriftSpan = ThriftSpanSerializer.ConvertToThrift(span);

            AssertSpanHasRequiredFields(thriftSpan);

            Assert.NotNull(thriftSpan);
            Assert.AreEqual(2, thriftSpan.Annotations.Count);

            thriftSpan.Annotations.ForEach(annotation =>
            {
                Assert.AreEqual(serviceName, annotation.Host.Service_name);
                Assert.AreEqual(SerializerUtils.IpToInt(IPAddress.Loopback), annotation.Host.Ipv4);
                Assert.AreEqual(hostPort, annotation.Host.Port);
            });

            Assert.AreEqual(name, thriftSpan.Name);
        }
Exemple #2
0
    public void Deserialize(int msgType, byte[] data)
    {
        //int mType = SerializerUtils.ReadInt(data);
        Debug.Log("D: " + BitConverter.ToString(data) + " : " + data.Length);
        bool arg0 = SerializerUtils.ReadBool(ref data);
        bool arg1 = SerializerUtils.ReadBool(ref data);
        bool arg2 = SerializerUtils.ReadBool(ref data);

        //what do we do with this data now?
        //send if off *somewhere* to be applied?
        //should that happen here?

        //need to wrap this data *somehow* to make it nice to send around.  Otherwise we hardcode
        //process functions into Deserialize functions and I don't know if we want to do that?

        //Process(arg0, arg1, arg0);
        //NetworkManager.instance.ProcessDeserializedData[msgType](arg0, arg1, arg0);
        //NetworkManager.instance.ProcessDeserializedData[msgType] = ProcessConnectAccept;
        //public void ProcessConnectAccept(bool, bool, bool)?

        //Register("ConnectAccept", S, D, P);
        //when we receive a "ConnectAccept, we D(), which will interally call P() to our callback with the proper type args
        //when we send we go QueueSend(MessageType, bool, bool, bool) and interally it will S() our args?
        //our Q needs a per-message priority filter (not type) so that we can eventually send everything out on our simulation frame.
        //can we send more than one packet per simulation frame? What if we get into a downward spiral?
        //eventually things should slow down, right?
        Debug.Log(string.Format("{0}, {1}, {2}", arg0, arg1, arg2));
    }
Exemple #3
0
        public static void Deserialize(ulong sender, int msgCode, ByteStream stream)
        {
            //Debug.Log(BitTools.BitDisplay.BytesToString(stream.Data));

            //Debug.Log("MessageCode.EntityUpdate.Deserialize");
            //read the entity header
            int prefabId   = SerializerUtils.ReadInt(stream, 0, Core.net.maxPrefabs);
            int networkId  = SerializerUtils.ReadInt(stream, 0, Core.net.maxNetworkIds);
            int owner      = SerializerUtils.ReadInt(stream, 0, Core.net.maxPlayers);
            int controller = SerializerUtils.ReadInt(stream, 0, Core.net.maxPlayers);

            //pass it down to the Behaviour to process further
            Core.net.GetPrefabNetworkGameObject(prefabId).Deserialize(stream, prefabId, networkId, owner, controller);
            //what happens if we get here and we CAN"T find the entity? It's already been destroyed locally?
            //we won't know the state, and we won't know how much data to read.
            //and we can't just throw away the packet.. because it might have important data AFTER this message
            //so we need a way to know the message size even if the entity doesn't exisit.

            //we could send the message size but that's another 8 bits at least.. and that would kind of be a waste.
            //hmmmmm
            //cause use the prefabs template peek because it could have a different size (delta compressed)
            //HMMMMM

            //can we use a static deserialize (on the prefab template)
            //that will read anything conditional? I guess

            //Debug.Log("Deserialize: " + prefabId + " : " + networkId + " : " + owner + " : " + controller);

            //process is called the next level down (prefab's behaviour's deserialize)
            //Core.net.MessageProcessors[msgCode](sender, prefabId, networkId, owner, controller);
        }
Exemple #4
0
    //bolt 3 float properties compressed the same (18 bits each = 54 bits)
    //20 packets per second, means 1080 bits or 135 bytes per second or 0.135 bytes per second

    public override void Serialize(UdpStream stream)
    {
        SerializerUtils.WriteFloat(stream, this.transform.position.x, -100f, 100f, 0.0001f);
        SerializerUtils.WriteFloat(stream, this.transform.position.y, -100f, 100f, 0.0001f);
        SerializerUtils.WriteFloat(stream, this.transform.position.z, -100f, 100f, 0.0001f);
        SerializerUtils.WriteQuaterinion(stream, this.transform.rotation, 0.001f);
    }
Exemple #5
0
        public string SendToJson()
        {
            try
            {
                var dic = new Dictionary <string, object>();
                dic.Add("date", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                dic.Add("netid", id.getInt());

                foreach (var item in _data)
                {
                    dic.Add(item.Key, item.Value);
                }
                var rtnstr = SerializerUtils.ScriptSerialize <Dictionary <string, object> >(dic);

                //if (_netid != NetID.XinTiao && _netid != NetID.GongGao && _netid != NetID.OnLine)
                //{
                //    Logger.Log(rtnstr);
                //}
                return(rtnstr);
            }
            catch (Exception e)
            {
                return(string.Empty);
            }
        }
Exemple #6
0
    public override void Deserialize(UdpStream stream, int prefabId, int networkId, int owner, int controller)
    {
        //deserialize any state data.

        float      x        = SerializerUtils.ReadFloat(stream, -100f, 100f, 0.0001f);
        float      y        = SerializerUtils.ReadFloat(stream, -100f, 100f, 0.0001f);
        float      z        = SerializerUtils.ReadFloat(stream, -100f, 100f, 0.0001f);
        int        iValue   = SerializerUtils.ReadInt(stream, -100, 100);
        float      fValue   = SerializerUtils.ReadFloat(stream, -100f, 100f, 0.001f);
        Quaternion rotation = SerializerUtils.ReadQuaternion(stream, 0.001f);

        //we have to do this after the deseralize, otherwise the data will be corrupted
        //we can't do this here because this call to priority would be on the prefab, not the instance because
        //this is on the receiver. and we usually want to use this.transform.position in the priority check
        //and it would always be 0,0,0!

        //at this point, we don't know if this entity is even instantiated in the world
        //we don't do that check until inside of ProcessEntityMessage, but in some cases we don't
        //want to process it because then it will get instantiated when we don't want it to (eg, in a different scene)
        //so we need to make some compromises with how the priority system will work for entities
        //eg, we can only use prefab values as we don't have an entity instance to work with
        //but we can push in any extra data if we really need to, we just need to modify it
        //we could pass in args, too..
        //ProcessDeserialize();
        //how can we simplify this?
        //Process(prefabId, networkId, owner, controller, entityProps....)
        //can we assume xyz are the first three entity props?
        //will an entity ALWAYS have a position?

        ProcessDeserialize(prefabId, networkId, owner, controller, x, y, z, iValue, fValue, rotation);
    }
Exemple #7
0
        public void Save(Action <Exception> callback)
        {
            if (this._threadZipping)
            {
                ClientLogger.Error("zipping is not finished");
                if (callback != null)
                {
                    callback(new InvalidOperationException("zipping is not finished"));
                }
                return;
            }
            List <ReplayMessage> savedMsgs = this._savedMsgs;

            this._savedMsgs       = new List <ReplayMessage>(10);
            this._threadException = null;
            this._finishCallback  = callback;
            this._threadZipping   = true;
            new Thread(delegate(object x)
            {
                List <ReplayMessage> data = x as List <ReplayMessage>;
                try
                {
                    SerializerUtils.ReplaySerialize(this._path, data);
                }
                catch (Exception threadException)
                {
                    this._threadException = threadException;
                }
                this._threadZipping = false;
            }).Start(savedMsgs);
            new Task(this.Monitor(), true);
        }
Exemple #8
0
    //callback from SteamClient. Read the data and decide how to process it.
    public void ReceiveP2PData(ulong steamID, byte[] bytes, int length, int channel)
    {
        readStream = new UdpKit.UdpStream(bytes, length);
        //Debug.Log("rec message");
        //string s = stream.ReadString();
        while (readStream.CanRead() && readStream.CanRead(SerializerUtils.RequiredBitsInt(0, maxMessageTypes)))
        {
            int msgCode = (int)SerializerUtils.ReadInt(readStream, 0, maxMessageTypes);
            //Debug.Log("[REC] MessageCode: " + msgCode);
            if (msgCode == GetMessageCode("Empty"))
            {
                AddToBandwidthInBuffer(-8);
                break; //no more data, the rest of this packet is junk
            }
            //can we ignore all state data here if we're not in the same zone?
            //we don't know what kind of entity it's from..so...
            //maybe all zoneless data should just go through events?
            //or we can check the prefab to find out if it's zoneless?

            if (MessageDeserializers[msgCode] != null)
            {
                MessageDeserializers[msgCode](steamID, msgCode, readStream);
                //entity messages deserialize is called internally (MessageCodes.SpawnPrefab.Deserialize  calles entity.Deserialize)
            }
            else
            {
                MessageProcessors[msgCode](steamID); //process is usually called within the deserializer, but since we have no deserializer (because we have no data, just a msgCode), call it here.
            }
        }
    }
        public void ReadDatabase(JsonReader reader, IFakeDatabase database)
        {
            // Parse JSON
            var databaseJSON = JObject.Load(reader);              // Load JSON Database object
            var databaseType = GetTypeFromProperty(databaseJSON); // Database Type

            // Create Database
            database = SerializerUtils.TryToBuildObject <IFakeDatabase>(databaseType, null);

            if (database == null)
            {
                throw new Exception("Database is null, after setting.");
            }

            // Set Database Name
            database.Name = databaseJSON[FakeDbConstants.PropertyName].Value <string>();

            // For Each Table in file
            foreach (var tableJSON in databaseJSON.Property(FakeDbConstants.LabelTable).Value.AsJEnumerable())
            {
                // Build Table
                var tableName = tableJSON[FakeDbConstants.PropertyName].Value <string>();
                var tableType = Type.GetType(tableJSON[FakeDbConstants.PropertyClass].Value <string>()); // Table Type
                var table     = SerializerUtils.TryToBuildObject <IFakeTable>(tableType, new object[] { database, tableName });

                // Force change the Table Name
                table.Name = tableName;

                // For each Column in Table
                foreach (var columnJSON in tableJSON[FakeDbConstants.LabelColumn])
                {
                    // Build Column
                    var columnName = columnJSON[FakeDbConstants.PropertyName].Value <string>();
                    var columnType = Type.GetType(columnJSON[FakeDbConstants.PropertyClass].Value <string>()); // Column Type

                    var columnRecordType = Type.GetType(columnJSON[FakeDbConstants.PropertyColumnRecordType].Value <string>());

                    var column = SerializerUtils.TryToBuildObject <IFakeColumn>(columnType, new object[] { table, columnName, columnRecordType });

                    // Force change Column Name
                    column.Name = columnName;

                    // All Record for this Column
                    foreach (var recordJSON in columnJSON[FakeDbConstants.LabelRecord])
                    {
                        var index = recordJSON[FakeDbConstants.PropertyIndex].Value <int>();
                        var value = recordJSON[FakeDbConstants.PropertyValue].Value <string>();

                        // Add Record to Column
                        column.Add(new KeyValuePair <int, object>(index, value));
                    }

                    // Add Column to Table
                    table.AddColumn(column);
                }

                // Add Table to Database
                database.Add(table);
            }
        }
Exemple #10
0
        public static T GetModelBypath <T>(string rootpath, string modelId, string package)
        {
            FileOperation fileOperation = new FileOperation();

            fileOperation.Encoding = LibEncoding.UTF8;
            if (typeof(T) == typeof(LibDataSource))
            {
                fileOperation.FilePath = string.Format(@"{0}\Models\{1}\{2}\{3}.xml", rootpath, SysConstManage.DataSourceNm, package, modelId);
            }
            else if (typeof(T) == typeof(LibFormPage))
            {
                fileOperation.FilePath = string.Format(@"{0}\Models\{1}\{2}\{3}.xml", rootpath, SysConstManage.FormSourceNm, package, modelId);
            }
            else if (typeof(T) == typeof(LibPermissionSource))
            {
                fileOperation.FilePath = string.Format(@"{0}\Models\{1}\{2}\{3}.xml", rootpath, SysConstManage.PermissionSourceNm, package, modelId);
            }
            else if (typeof(T) == typeof(LibReportsSource))
            {
                fileOperation.FilePath = string.Format(@"{0}\Models\{1}\{2}\{3}.xml", rootpath, SysConstManage.ReportSourceNm, package, modelId);
            }
            else if (typeof(T) == typeof(LibTransSource))
            {
                fileOperation.FilePath = string.Format(@"{0}\Models\{1}\{2}\{3}.xml", rootpath, SysConstManage.TransSourceNm, package, modelId);
            }
            string xmlstr = fileOperation.ReadFile();

            if (!string.IsNullOrEmpty(xmlstr))
            {
                return(SerializerUtils.XMLDeSerialize <T>(xmlstr));
            }
            return(default(T));
        }
    //ConnectionResponse Serailize/Deserialize/Process methods
    //this message has two properties.
    //arg[0] is a bool that says if our connect request was accepted (which is kind of redundant because we wouldn't get a response if it was rejected anyways)
    //arg[1] is an int telling us what connectionIndex the host is assigned assigned.
    //arg[2] is an int telling us what connectionIndex the host assigned us.
    private static byte[] SConnectResponse(int msgCode, params object[] args)
    {
        byte[] data = new byte[0];

        //we need to know what data were are sending with each msg, but to keep it modular we need to cast to types here
        bool arg0 = (bool)args[0];
        int  arg1 = (int)args[1];
        int  arg2 = (int)args[2];

        //we need to write data in this method, and read it in the Deserialize method in the SAME ORDER.
        //if we do not, the data can't be read properly.
        //eg if we had multiple properties to seralize
        //WriteBool()
        //WriteString()
        //WriteInt()

        //then in deserialize
        //ReadBool()
        //ReadString()
        //ReadInt()
        data = data.Append(SerializerUtils.WriteBool(arg0));
        data = data.Append(SerializerUtils.WriteInt(arg1));
        data = data.Append(SerializerUtils.WriteInt(arg2));
        return(data);
    }
Exemple #12
0
        public static T GetModelBymodelId <T>(string rootpath, string modelId)
        {
            FileOperation fileOperation = new FileOperation();

            fileOperation.Encoding = LibEncoding.UTF8;
            rootpath = string.Format(@"{0}\Models", rootpath);
            if (typeof(T).Equals(typeof(LibDataSource)))
            {
                fileOperation.FilePath = string.Format(@"{0}\{1}", rootpath, SysConstManage.DataSourceNm);
            }
            else if (typeof(T).Equals(typeof(LibFormPage)))
            {
                fileOperation.FilePath = string.Format(@"{0}\{1}", rootpath, SysConstManage.FormSourceNm);
            }
            else if (typeof(T).Equals(typeof(LibPermissionSource)))
            {
                fileOperation.FilePath = string.Format(@"{0}\{1}", rootpath, SysConstManage.PermissionSourceNm);
            }
            else if (typeof(T).Equals(typeof(LibReportsSource)))
            {
                fileOperation.FilePath = string.Format(@"{0}\{1}", rootpath, SysConstManage.ReportSourceNm);
            }
            else if (typeof(T).Equals(typeof(LibTransSource)))
            {
                fileOperation.FilePath = string.Format(@"{0}\{1}", rootpath, SysConstManage.TransSourceNm);
            }
            string dsxml = fileOperation.SearchAndRead(string.Format("{0}.xml", modelId));

            if (string.IsNullOrEmpty(dsxml))
            {
                return(default(T));
            }
            return(SerializerUtils.XMLDeSerialize <T>(dsxml));
        }
Exemple #13
0
        private void ReceiveMessage(NetMQSocket socket, NetMQMessage message)
        {
            if (message[message.FrameCount - 2].MessageSize != 0)
            {
                RaiseError("ProtocolError", "Invalid event: Second to last argument must be an empty buffer!");
                return;
            }
            List <byte[]> envelope = message.Take(message.FrameCount - 2).Select(n => n.ToByteArray()).ToList();

            Event evt;

            try
            {
                evt = SerializerUtils.Deserialize(envelope, message.Last.ToByteArray());
            }
            catch (Exception ex)
            {
                RaiseError("ProtocolError", $"Invalid event: {ex.Message}", ex.StackTrace);
                return;
            }

            if (Channels.TryGetValue(evt.Header.ResponseTo, out Channel ch))
            {
                ch.ProcessAsync(evt);
            }
            else
            {
                EventReceived?.BeginInvoke(this, new EventReceivedArgs {
                    Event = evt
                }, null, null);
            }
        }
Exemple #14
0
        public Task SendPushToUser(
            string frontendId,
            string serverKind,
            string route,
            string uid,
            object pushMsg)
        {
            return(Task.Run(() =>
            {
                var context = new CallbackContext <bool>
                {
                    t = new TaskCompletionSource <bool>(),
                    serializer = _serializer,
                };
                var handle = GCHandle.Alloc(context, GCHandleType.Normal);
                var push = new Push
                {
                    Route = route,
                    Uid = uid,
                    Data = ByteString.CopyFrom(SerializerUtils.SerializeOrRaw(pushMsg, _serializer))
                };

                unsafe
                {
                    var data = push.ToByteArray();
                    fixed(byte *p = data)
                    {
                        IntPtr pushBuffer = PitayaCluster.pitaya_buffer_new((IntPtr)p, data.Length);
                        PitayaCluster.pitaya_send_push_to_user(_pitaya, frontendId, serverKind, pushBuffer, pushCallback, GCHandle.ToIntPtr(handle));
                    }
                }

                return context.t.Task;
            }));
        }
Exemple #15
0
        public void DefaultsValuesAreUsedIfNothingSpecified()
        {
            var spanState = new SpanState(1, 0, 2, SpanFlags.None);
            var span      = new Span(spanState, TimeUtils.UtcNow);

            AddClientSendReceiveAnnotations(span);

            var thriftSpan = ThriftSpanSerializer.ConvertToThrift(span);

            AssertSpanHasRequiredFields(thriftSpan);

            const string defaultName        = SerializerUtils.DefaultRpcMethodName;
            const string defaultServiceName = SerializerUtils.DefaultServiceName;
            var          defaultIpv4        = SerializerUtils.IpToInt(SerializerUtils.DefaultEndPoint.Address);
            var          defaultPort        = SerializerUtils.DefaultEndPoint.Port;

            Assert.AreEqual(2, thriftSpan.Annotations.Count);
            thriftSpan.Annotations.ForEach(ann =>
            {
                Assert.AreEqual(defaultServiceName, ann.Host.Service_name);
                Assert.AreEqual(defaultIpv4, ann.Host.Ipv4);
                Assert.AreEqual(defaultPort, ann.Host.Port);
            });

            Assert.AreEqual(defaultName, thriftSpan.Name);
            Assert.IsNull(thriftSpan.Duration);
        }
Exemple #16
0
        public void InitBaseConfigDataXML()
        {
            string xMLFolder = this.getXMLFolder();

            string[] files = FileUtils.GetFiles(xMLFolder, SearchOption.AllDirectories);
            string   text  = ".xml";

            if (files != null)
            {
                this.data = new Dictionary <string, Dictionary <string, object> >();
                for (int i = 0; i < files.Length; i++)
                {
                    if (text == string.Empty || files[i].Contains(text))
                    {
                        FileInfo fileInfo = new FileInfo(files[i]);
                        string   text2    = fileInfo.Name.Split(new char[]
                        {
                            '.'
                        })[0];
                        Dictionary <string, object> value = SerializerUtils.loadXML2(files[i], this.getClzType(text2));
                        this.data.Add(text2, value);
                    }
                }
            }
            this.parse();
            this.IsBaseDataInit = true;
        }
Exemple #17
0
        /// <summary>
        /// Loads the manga list from the local cache
        /// </summary>
        public async Task LoadMangaListFromCacheAsync( )
        {
            var fi = GetMangaListInfo( );

            try
            {
                if (fi.Exists && fi.Length > 0)
                {
                    var mangas = await SerializerUtils
                                 .DeserializeFromFileAsync <Manga[]> (fi.FullName);

                    if (mangas != null)
                    {
                        foreach (var manga in mangas)
                        {
                            manga.Connector = this;
                        }

                        this.MangaList = mangas;
                    }
                }
            }
            catch (Exception)
            {
                // For some reason the config didn't load
                this.MangaList = new Manga[0];
                return;
            }
        }
    //callback from SteamClient. Read the data and decide how to process it.
    public void ReceiveP2PData(ulong steamID, byte[] bytes, int length, int channel)
    {
        readStream = new UdpKit.UdpStream(bytes, length);
        //Debug.Log("rec message");
        //string s = stream.ReadString();
        while (readStream.CanRead() && readStream.CanRead(8))
        {
            int msgCode = (int)SerializerUtils.ReadInt(readStream, 0, 255);
            //Debug.Log("[REC] MessageCode: " + msgCode);
            if (msgCode == GetMessageCode("Empty"))
            {
                break; //no more data, the rest of this packet is junk
            }

            if (MessageDeserializers[msgCode] != null)
            {
                MessageDeserializers[msgCode](steamID, msgCode, readStream);
                //entity messages deserialize is called internally (MessageCodes.SpawnPrefab.Deserialize  calles entity.Deserialize)
            }
            else
            {
                MessageProcessors[msgCode](steamID); //process is usually called within the deserializer, but since we have no deserializer (because we have no data, just a msgCode), call it here.
            }
        }
    }
        public void ToEscaped()
        {
            string testString  = "\"testString\"";
            string testString2 = "\"!@#$%^&*()\a\b\0\f\n\r\t\v";

            Assert.AreEqual(SerializerUtils.ToEscaped(testString), "\\\"testString\\\"");
            Assert.AreEqual(SerializerUtils.ToEscaped(testString2), "\\\"!@#$%^&*()\\a\\b\\0\\f\\n\\r\\t\\v");
        }
    //test int S/D/P methods
    private static byte[] STestInt(int msgCode, params object[] args)
    {
        byte[] data = new byte[0];
        int    arg0 = (int)args[0];

        data = data.Append(SerializerUtils.WriteInt(arg0));
        return(data);
    }
    private static void DConnectResponse(ulong sender, int msgCode, byte[] data)
    {
        bool arg0 = SerializerUtils.ReadBool(ref data);
        int  arg1 = SerializerUtils.ReadInt(ref data);
        int  arg2 = SerializerUtils.ReadInt(ref data);

        NetworkManager.instance.Process(sender, msgCode, arg0, arg1, arg2);
    }
Exemple #22
0
        public static int Peek(params object[] args)
        {
            int s = 0;

            s += MessageCode.Internal.PeekEntityHeader();
            s += SerializerUtils.RequiredBitsBool();
            return(s);
        }
Exemple #23
0
        public static int Peek(params object[] args)
        {
            int s = 0;

            s += SerializerUtils.RequiredBitsInt(0, 255);
            s += SerializerUtils.RequiredBitsInt(0, 255);
            return(s);
        }
Exemple #24
0
        //
        public static void Serialize(ulong receiver, ByteStream stream, params object[] args)
        {
            int arg0 = (int)args[0]; //the connectionIndex of the player who sent you this message (the host)
            int arg1 = (int)args[1]; //the connectionIndex of you assigned by the host

            SerializerUtils.WriteInt(stream, arg0, 0, 255);
            SerializerUtils.WriteInt(stream, arg1, 0, 255);
        }
        public static unsafe Task <T> Rpc <T>(string serverId, Route route, object msg)
        {
            return(_rpcTaskFactory.StartNew(() =>
            {
                MemoryBuffer *memBufPtr = null;
                var retError = new Error();
                var ok = false;
                Stopwatch sw = null;
                try
                {
                    var data = SerializerUtils.SerializeOrRaw(msg, _serializer);
                    sw = Stopwatch.StartNew();
                    fixed(byte *p = data)
                    {
                        ok = RPCInternal(serverId, route.ToString(), (IntPtr)p, data.Length, &memBufPtr, ref retError);
                    }

                    sw.Stop();

                    if (!ok) // error
                    {
                        if (retError.code == "PIT-504")
                        {
                            throw new PitayaTimeoutException($"Timeout on RPC call: ({retError.code}: {retError.msg})");
                        }
                        if (retError.code == "PIT-404")
                        {
                            throw new PitayaRouteNotFoundException($"Route not found on RPC call: ({retError.code}: {retError.msg})");
                        }
                        throw new PitayaException($"RPC call failed: ({retError.code}: {retError.msg})");
                    }

                    var protoRet = GetProtoMessageFromMemoryBuffer <T>(*memBufPtr);
                    return protoRet;
                }
                finally
                {
                    if (sw != null)
                    {
                        if (ok)
                        {
                            MetricsReporters.ReportTimer(Metrics.Constants.Status.success.ToString(), route.ToString(),
                                                         "rpc", "", sw);
                        }
                        else
                        {
                            MetricsReporters.ReportTimer(Metrics.Constants.Status.fail.ToString(), route.ToString(),
                                                         "rpc", $"{retError.code}", sw);
                        }
                    }

                    if (memBufPtr != null)
                    {
                        FreeMemoryBufferInternal(memBufPtr);
                    }
                }
            }));
        }
Exemple #26
0
    public override void Deserialize(UdpStream stream, int prefabId, int networkId, int owner, int controller)
    {
        //deserialize any state data.
        float x = SerializerUtils.ReadFloat(stream, -10f, 10f, 0.0001f);
        float y = SerializerUtils.ReadFloat(stream, -10f, 10f, 0.0001f);
        float z = SerializerUtils.ReadFloat(stream, -10f, 10f, 0.0001f);

        Core.net.ProcessEntityMessage(prefabId, networkId, owner, controller, x, y, z);
    }
Exemple #27
0
        private void App_OnExit(object sender, ExitEventArgs e)
        {
            ConfigHelper helper = new ConfigHelper
            {
                DownloadGroups = MainWindowVM.DownloadGroups
            };

            SerializerUtils.SaveConfig(helper);
        }
Exemple #28
0
        public static void Deserialize(ulong sender, int msgCode, ByteStream stream)
        {
            int arg0 = SerializerUtils.ReadInt(stream, 0, 255);
            int arg1 = SerializerUtils.ReadInt(stream, 0, 255);

            //no need for a null check, can't have a deserializer without a processor.
            //I mean, you can, but it wouldn't do anything with the data you just received
            Core.net.MessageProcessors[msgCode](sender, arg0, arg1);
        }
Exemple #29
0
        public void ThriftConversionBinaryAnnotationWithEndPointButNoServiceNameIsCorrect()
        {
            string serviceName      = null;
            var    ipEndPoint       = new IPEndPoint(1, 2);
            var    expectedEndpoint = new Endpoint {
                Service_name = _someHost.Service_name, Ipv4 = SerializerUtils.IpToInt(ipEndPoint.Address), Port = (short)ipEndPoint.Port
            };

            AssertBinaryAnnotationConversion(serviceName, ipEndPoint, expectedEndpoint);
        }
Exemple #30
0
        public void ThriftConversionBinaryAnnotationWithEndPointIsCorrect()
        {
            var serviceName      = "database";
            var ipEndPoint       = new IPEndPoint(1, 2);
            var expectedEndpoint = new Endpoint {
                Service_name = serviceName, Ipv4 = SerializerUtils.IpToInt(ipEndPoint.Address), Port = (short)ipEndPoint.Port
            };

            AssertBinaryAnnotationConversion(serviceName, ipEndPoint, expectedEndpoint);
        }