Ejemplo n.º 1
0
        public static Payload Convert <T>(T request, RequestMeta meta)
        {
            var body = new Google.Protobuf.WellKnownTypes.Any
            {
                // convert the request paramter to a json string, as the body
                Value = Google.Protobuf.ByteString.CopyFromUtf8(request.ToJsonString())
            };

            var payload = new Payload
            {
                Body = body
            };

            if (meta != null)
            {
                payload.Metadata = new Metadata
                {
                    ClientIp      = meta.ClientIp,
                    ClientPort    = meta.ClientPort,
                    ClientVersion = meta.ClientVersion,
                    ConnectionId  = meta.ConnectionId,
                    Type          = meta.Type,
                };

                if (meta.Labels != null && meta.Labels.Any())
                {
                    foreach (var item in meta.Labels)
                    {
                        payload.Metadata.Labels.Add(item.Key, item.Value);
                    }
                }
            }

            return(payload);
        }
Ejemplo n.º 2
0
        public override Task <AnyMessageResponse> DoAny(AnyMessage request, ServerCallContext context)
        {
            AnyMessageResponse anyMessageResponse;

            switch (request.TypeUrl)
            {
            case "type.googleapis.com/any.AnyProductRequest":
                var product = request.Unpack <AnyProductRequest>();
                anyMessageResponse = new AnyMessageResponse
                {
                    Message = $"{product.Quantity} x {product.Name}"
                };
                break;

            case "type.googleapis.com/any.AnyUserRequest":
                var user = request.Unpack <AnyUserRequest>();
                anyMessageResponse = new AnyMessageResponse
                {
                    Message = $"{user.Name} - {(user.Enabled ? "Enabled" : "Disabled")}"
                };
                break;

            default:
                throw new InvalidOperationException("Unexpected type URL.");
            }

            return(Task.FromResult(anyMessageResponse));
        }
Ejemplo n.º 3
0
        public static Payload Convert(CommonRequest request, CommonRequestMeta meta)
        {
            var body = new Google.Protobuf.WellKnownTypes.Any
            {
                // convert the request paramter to a json string, as the body
                Value = Google.Protobuf.ByteString.CopyFromUtf8(request.ToJsonString())
            };

            var payload = new Payload
            {
                Body = body
            };

            if (meta != null)
            {
                payload.Metadata = new Metadata
                {
                    Type = meta.Type,
                };

                if (request.Headers != null && request.Headers.Any())
                {
                    foreach (var item in request.Headers)
                    {
                        payload.Metadata.Headers.Add(item.Key, item.Value);
                    }
                }
            }

            return(payload);
        }
        /// <inheritdoc/>
        protected override void OnMessageReceived(IncomingMessage msg)
        {
            Google.Protobuf.WellKnownTypes.Any anyMessage = null;
            try
            {
                anyMessage = Google.Protobuf.WellKnownTypes.Any.Parser.ParseFrom(msg.GetRawBytes());
            }
            catch (Google.Protobuf.InvalidProtocolBufferException)
            {
                // Bad message, nothing we can do about it, so just ignore.
                return;
            }

            if (anyMessage.Is(TrainingEnvironmentInitialized.Descriptor))
            {
                var envInitProto = anyMessage.Unpack <TrainingEnvironmentInitialized>();
                var envInitEvent = envInitProto.ToTrainingEnvironmentInitializedEvent();
                TrainingAnalytics.TrainingEnvironmentInitialized(envInitEvent);
            }
            else if (anyMessage.Is(TrainingBehaviorInitialized.Descriptor))
            {
                var behaviorInitProto     = anyMessage.Unpack <TrainingBehaviorInitialized>();
                var behaviorTrainingEvent = behaviorInitProto.ToTrainingBehaviorInitializedEvent();
                TrainingAnalytics.TrainingBehaviorInitialized(behaviorTrainingEvent);
            }
            // Don't do anything for unknown types, since the user probably can't do anything about it.
        }
Ejemplo n.º 5
0
        //private void OnGUI()
        //{
        //    if (GUI.Button(new Rect(0, 0, 100, 30), "行走"))
        //    {
        //        string tag = "" + ((1 << 13) ^ (1 << 9) ^ (1 << 5));
        //        hashMap[tag].Transition(Item.STATE_TAG.WALK);
        //    }
        //    if (GUI.Button(new Rect(110, 0, 100, 30), "攻击"))
        //    {
        //        hashMap[tag].Transition(Item.STATE_TAG.ATTACK1);
        //    }
        //    if (GUI.Button(new Rect(220, 0, 100, 30), "攻击2"))
        //    {
        //        hashMap[tag].Transition(Item.STATE_TAG.ATTACK2);
        //    }
        //}

        //// Update is called once per frame
        //void Update()
        //{
        //    //float fix = Time.deltaTime * speed;

        //    foreach (string key in hashMap.Keys)
        //    {
        //        Item item = hashMap[key];
        //        //updateItem(item, fix);
        //        item.Do(Time.deltaTime);
        //    }
        //}

        //private void updateItem(Item item, float dt)
        //{

        //    if (!item.DV.IsZero())
        //    {
        //        var curPos = item.GO.transform.localPosition;
        //        item.GO.GetComponent<CharacterController>().Move(new Vector3(-dt * (float)item.DV.x, 0, -dt * (float)item.DV.z));
        //        transition(2);
        //    }
        //    else
        //        transition(1);
        //}

        //// handleLogicTick 处理逻辑层传过来的演示数据,更新目标状态
        //private void handleLogicTick(EventLogicTickList action)
        //{
        //    foreach (EventLogicTick tick in action)
        //    {

        //        Debug.Log("handle logic tick");
        //        //string tag = "" + tick.tag;
        //        //var item = hashMap[tag];
        //        //if (!item.GO.CompareTag(tag))
        //        //    continue;


        //        //item.DV = tick.v3;
        //        //if (tick.v3.IsZero())
        //        //    continue;

        //        //float radian = Mathf.Atan2(decimal.ToSingle(item.DV.z), decimal.ToSingle(item.DV.x));
        //        //float angle = radian / Mathf.PI * 180;

        //        //item.GO.transform.rotation = Quaternion.Euler(0, -90.0f - angle, 0);
        //    }
        //}

        //NOTE: 处理匹配消息完成
        private void handleNetMatch(Google.Protobuf.WellKnownTypes.Any any)
        {
            WarPb.War_Match match = any.Unpack <WarPb.War_Match>();
            GameObject      prefab;

            switch (match.MapId)
            {
            default:
                prefab = (GameObject)Resources.Load("Prefabs/CompleteLevelArt");
                break;
            }
            GameObject plane = Instantiate(prefab);

            SceneManager.MoveGameObjectToScene(plane, gameObject.scene);

            Net.WsClient.Instance.ID = match.Id;

            //plane.GetComponent<Views.PlaneManager>().DoMatch(match);
            var pm = plane.GetComponent <PlaneManager>();

            pm.DoMatch(match);
            Driver d = gameObject.AddComponent <Driver>();           //NOTE: 添加Driver 组件,处理数据

            d.M = pm.m_Meet;
            EventFollow.Instance.Invoke(pm.Look);
        }
Ejemplo n.º 6
0
 public void Broadcast(Any rumor)
 {
     onRumorReceived?.Invoke(this, new RumorReceivedEventArgs
     {
         Payload = rumor
     });
     pushStateRumorCounterDictionary.Add(rumor, 1);
 }
Ejemplo n.º 7
0
 async public Task send(Google.Protobuf.WellKnownTypes.Any any)
 {
     using (MemoryStream stream = new MemoryStream())
     {
         Google.Protobuf.CodedOutputStream s = new Google.Protobuf.CodedOutputStream(stream);
         any.WriteTo(s);
         s.Flush();
         ArraySegment <byte> buffer = new ArraySegment <byte>(stream.ToArray());
         await client.SendAsync(buffer, WebSocketMessageType.Binary, true, cancelActionToken);
     }
 }
Ejemplo n.º 8
0
        public static Payload Convert(CommonResponse response)
        {
            var body = new Google.Protobuf.WellKnownTypes.Any
            {
                // convert the request paramter to a json string, as the body
                Value = Google.Protobuf.ByteString.CopyFromUtf8(response.ToJsonString())
            };

            var payload = new Payload
            {
                Body = body
            };

            payload.Metadata = new Metadata
            {
                Type = response.GetRemoteType(),
            };

            return(payload);
        }
        private static bool TryBuild(RpcException baseException, byte[] data, [NotNullWhen(true)] out RpcException?exception)
        {
            var any          = Any.Parser.ParseFrom(data);
            var fullTypeName = Any.GetTypeName(any.TypeUrl);

            if (string.IsNullOrEmpty(fullTypeName))
            {
                fullTypeName = any.TypeUrl;
            }

            var typeDictionary = TypeDictionary();

            if (typeDictionary.TryGetValue(fullTypeName, out var factory))
            {
                exception = factory(baseException, any.Value);
                return(true);
            }

            exception = default;
            return(false);
        }
Ejemplo n.º 10
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello world");

            var tr = new TestReflection();

            tr.DoCheck();
            return;


            TestEnum(); return;

            var m = new SearchRequest();

            m.Query         = "Select * from toto";
            m.PageNumber    = 0;
            m.ResultPerPage = 5;
            m.Data          = ByteString.CopyFrom("Hello world xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", Encoding.ASCII);
            m.Contents.Add(new subfield()
            {
                Id = 1, Content = ByteString.CopyFrom("zzzzzzzzzzzzzzzzzzzz", Encoding.ASCII)
            });
            m.Contents.Add(new subfield()
            {
                Id = 17, Content = ByteString.CopyFrom("zzzdgdfdferg", Encoding.ASCII)
            });

            Console.WriteLine("m={0}", m);

            var m2 = SearchRequest.Parser.ParseFrom(m.ToByteArray());

            Console.WriteLine("m2={0}", m2);

            foreach (var item in m2.Contents)
            {
                item.Content = ByteString.CopyFrom("aaaaaa", Encoding.ASCII);
            }
            Console.WriteLine("m2_bis={0}", m2);
            Console.WriteLine("m_bis={0}", m);

            // Reflection m2 + modif
            //PrintMessage(m2);

            PrintSmart(m);
            Console.WriteLine("m_ter={0}", m);

            var js = new JsonFormatter.Settings(true);
            var jf = new JsonFormatter(js);

            Console.WriteLine("m4={0}", jf.Format(m));

            var t = new Google.Protobuf.WellKnownTypes.Any();

            Console.WriteLine(Properties.Settings.Default.Tester);
            Properties.Settings.Default.Tester = "lionel";
            Properties.Settings.Default.Save();

            Console.WriteLine(Properties.Resources.MyString);

            Console.WriteLine(Properties.Resources.TextFile1);
        }
 public void Broadcast(Any rumor) => serviceImpl.Broadcast(rumor);
Ejemplo n.º 12
0
        public void TestAny()
        {
            var payload = Any.Pack(new PushResponse());

            Assert.Equal("EpidemicBroadcastService.PushResponse", payload.TypeUrl.Split('/').Last());
        }
 public IMessage Unpack(Any any) => AnyUnpackersDic[any.TypeUrl](any);
Ejemplo n.º 14
0
 //监听网络tick消息
 private void handleNetTick(Google.Protobuf.WellKnownTypes.Any any)
 {
     M.DoNetTick(any.Unpack <WarPb.Tick>());
 }