示例#1
0
        public BasicModel DecodeModel()
        {
            long id = CommunicationMessageInterpreter.ReadInt64(ModelData, 0);
            int  x  = CommunicationMessageInterpreter.ReadInt32(ModelData, sizeof(ulong));
            int  y  = CommunicationMessageInterpreter.ReadInt32(ModelData, sizeof(uint) + sizeof(ulong));
            int  w  = CommunicationMessageInterpreter.ReadInt32(ModelData, 2 * sizeof(uint) + sizeof(ulong));
            int  h  = CommunicationMessageInterpreter.ReadInt32(ModelData, 3 * sizeof(uint) + sizeof(ulong));

            return(new BasicModel {
                id = id, x = x, y = y, w = w, h = h
            });
        }
        private void State_MessageDecoded(object sender, CommunicationMessageEventArgs e)
        {
            string payload = Encoding.UTF8.GetString(e.Payload);

            switch (e.Type)
            {
            case 1:
                Tuple <int, long> authData = CommunicationMessageInterpreter.GetAuthentificationData(e.Payload);
                Type = authData.Item1;
                Id   = authData.Item2;
                OnAuthentificated();
                break;

            default:
                OnDataAvailable(e);
                break;
            }
            Console.WriteLine($"{e.Type} Payload: {payload}");
        }