当前位置: 首页>>代码示例>>C#>>正文


C# CircularBuffer.Skip方法代码示例

本文整理汇总了C#中CircularBuffer.Skip方法的典型用法代码示例。如果您正苦于以下问题:C# CircularBuffer.Skip方法的具体用法?C# CircularBuffer.Skip怎么用?C# CircularBuffer.Skip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CircularBuffer的用法示例。


在下文中一共展示了CircularBuffer.Skip方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Add_MoreThanCapacity_ProperlyCircles

            public void Add_MoreThanCapacity_ProperlyCircles()
            {
                var buffer = new CircularBuffer<int>(3);
                buffer.Add(1);
                buffer.Add(2);
                buffer.Add(3);
                buffer.Add(4);

                Assert.AreEqual(2, buffer.Skip(0).First());
                Assert.AreEqual(3, buffer.Skip(1).First());
                Assert.AreEqual(4, buffer.Skip(2).First());
            }
开发者ID:EliSchleifer,项目名称:mstum.utils,代码行数:12,代码来源:CircularBufferTests.cs

示例2: Deserialize

        public Packet Deserialize(CircularBuffer<byte> buffer)
        {
            try
            {
                var bytes = new byte[buffer.Size];
                buffer.Peek(bytes, 0, buffer.Size);

                var json = Encoding.UTF8.GetString(bytes);

                var stringReader = new StringReader(json);
                var reader = new JsonTextReader(stringReader);

                // 주의
                var field =
                    stringReader.GetType().GetField(
                        "_pos",
                        System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);

                var depth = 0;
                var id = 0;
                var idField = true;
                var hasObject = false;

                try
                {
                    while (reader.Read())
                    {
                        switch (reader.TokenType)
                        {
                            case JsonToken.StartObject:
                                depth++;
                                hasObject = true;
                                break;
                            case JsonToken.EndObject:
                                depth--;

                                if (depth == 0)
                                    break;
                                break;

                            case JsonToken.PropertyName:
                                if (depth == 1 &&
                                    (String)reader.Value == "id")
                                    idField = true;
                                break;
                            case JsonToken.Integer:
                                if (idField)
                                {
                                    id = Convert.ToInt32(reader.Value);
                                    idField = false;
                                }
                                break;
                        }
                    }
                }
                catch (JsonReaderException e)
                {
                    // ignore
                }


                if (hasObject == false)
                    return null;
                if (depth != 0)
                    return null;

                var count = (int)field.GetValue(stringReader);
                buffer.Skip(count);

                var slicedJson = json.Substring(0, count);

                var packet =
                    (Packet)JsonConvert.DeserializeObject(
                        slicedJson, Packet.GetTypeById(id));

                packet.packetId = id;

                return packet;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            return null;
        }
开发者ID:pjc0247,项目名称:Merona.JsonProtocol.cs,代码行数:85,代码来源:JsonMarshaler.cs

示例3: Deserialize

        protected override Packet Deserialize(CircularBuffer<byte> buffer)
        {
            var parsed = parser.Execute(new ArraySegment<byte>(buffer.ToArray()));
            buffer.Skip(parsed);

            if (processed.Count > 0)
            {
                var data = processed.Dequeue();
                
                var id = Int32.Parse(data["packetId"]);
                
                var type = Packet.GetTypeById(id);

                if (type == null)
                    return null;

                var packet = Activator.CreateInstance(type);

                if (packet == null)
                    Console.WriteLine("packet is null");

                foreach(var field in data)
                {
                    var dest = type.GetField(field.Key);
                    var value = Convert.ChangeType(field.Value, dest.FieldType);
                    
                    dest.SetValue(packet, value);
                }

                Console.WriteLine(packet.GetType());

                return (Packet)packet;
            }
            else
                return null;
        }
开发者ID:pjc0247,项目名称:Merona.Http.cs,代码行数:36,代码来源:Program.cs

示例4: Add_WithinCapacity_ProperlyAdds

            public void Add_WithinCapacity_ProperlyAdds()
            {
                var buffer = new CircularBuffer<int>(3);
                buffer.Add(1);
                buffer.Add(2);

                Assert.AreEqual(1, buffer.Skip(0).First());
                Assert.AreEqual(2, buffer.Skip(1).First());
            }
开发者ID:EliSchleifer,项目名称:mstum.utils,代码行数:9,代码来源:CircularBufferTests.cs

示例5: Add_MoreThanCapacityTwice_ProperlyCircles

            public void Add_MoreThanCapacityTwice_ProperlyCircles()
            {
                var buffer = new CircularBuffer<int>(3);
                buffer.Add(1);
                buffer.Add(2);
                buffer.Add(3);
                buffer.Add(4);
                buffer.Add(5);
                buffer.Add(6);
                buffer.Add(7);
                buffer.Add(8);

                Assert.AreEqual(6, buffer.Skip(0).First());
                Assert.AreEqual(7, buffer.Skip(1).First());
                Assert.AreEqual(8, buffer.Skip(2).First());
            }
开发者ID:EliSchleifer,项目名称:mstum.utils,代码行数:16,代码来源:CircularBufferTests.cs


注:本文中的CircularBuffer.Skip方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。