• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# ByteArraySegment类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中ByteArraySegment的典型用法代码示例。如果您正苦于以下问题:C# ByteArraySegment类的具体用法?C# ByteArraySegment怎么用?C# ByteArraySegment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ByteArraySegment类属于命名空间,在下文中一共展示了ByteArraySegment类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: TLV

 public TLV(byte[] bytes, int offset)
 {
     ByteArraySegment byteArraySegment = new ByteArraySegment(bytes, offset, 2);
     this.TypeLength = new TLVTypeLength(byteArraySegment);
     this.tlvData = new ByteArraySegment(bytes, offset, this.TypeLength.Length + 2);
     this.tlvData.Length = this.TypeLength.Length + 2;
 }
开发者ID:BGCX261,项目名称:znqq-svn-to-git,代码行数:7,代码来源:TLV.cs


示例2: ProbeRequestFrame

            /// <summary>
            /// Constructor
            /// </summary>
            /// <param name="bas">
            /// A <see cref="ByteArraySegment"/>
            /// </param>
            public ProbeRequestFrame (ByteArraySegment bas)
            {
                header = new ByteArraySegment (bas);

                FrameControl = new FrameControlField (FrameControlBytes);
                Duration = new DurationField (DurationBytes);
                DestinationAddress = GetAddress (0);
                SourceAddress = GetAddress (1);
                BssId = GetAddress (2);
                SequenceControl = new SequenceControlField (SequenceControlBytes);
				
				if(bas.Length > ProbeRequestFields.InformationElement1Position)
				{
                	//create a segment that just refers to the info element section
                	ByteArraySegment infoElementsSegment = new ByteArraySegment (bas.Bytes,
                    	(bas.Offset + ProbeRequestFields.InformationElement1Position),
                    	(bas.Length - ProbeRequestFields.InformationElement1Position));

                	InformationElements = new InformationElementList (infoElementsSegment);
				}
				else
				{
					InformationElements = new InformationElementList ();
				}
                //cant set length until after we have handled the information elements
                //as they vary in length
                header.Length = FrameSize;
            }
开发者ID:vishalishere,项目名称:packetnet,代码行数:34,代码来源:ProbeRequestFrame.cs


示例3: HandleTcpReceived

        internal void HandleTcpReceived(uint sequenceNumber, ByteArraySegment data)
        {
            var dataPosition = SequenceNumberToBytesReceived(sequenceNumber);
            if (dataPosition == BytesReceived)
            {
                OnDataReceived(data);
                BytesReceived += data.Length;
            }
            else
            {
                var dataArray = new byte[data.Length];
                Array.Copy(data.Bytes, data.Offset, dataArray, 0, data.Length);
                if (!_bufferedPackets.ContainsKey(dataPosition) ||
                    _bufferedPackets[dataPosition].Length < dataArray.Length)
                {
                    _bufferedPackets[dataPosition] = dataArray;
                }
            }

            long firstBufferedPosition;
            while (_bufferedPackets.Any() && ((firstBufferedPosition = _bufferedPackets.Keys.First()) <= BytesReceived))
            {
                var dataArray = _bufferedPackets[firstBufferedPosition];
                _bufferedPackets.Remove(firstBufferedPosition);

                var alreadyReceivedBytes = BytesReceived - firstBufferedPosition;
                Debug.Assert(alreadyReceivedBytes >= 0);

                if (alreadyReceivedBytes >= dataArray.Length) continue;
                var count = dataArray.Length - alreadyReceivedBytes;
                OnDataReceived(new ByteArraySegment(dataArray, (int) alreadyReceivedBytes, (int) count));
                BytesReceived += count;
            }
        }
开发者ID:ha-tam,项目名称:TeraDamageMeter,代码行数:34,代码来源:TcpConnection.cs


示例4: Test_Constructor_ConstructWithValues

            public void Test_Constructor_ConstructWithValues ()
            {
                AckFrame frame = new AckFrame (PhysicalAddress.Parse ("111111111111"));
                
                frame.FrameControl.ToDS = false;
                frame.FrameControl.FromDS = true;
                frame.FrameControl.MoreFragments = true;
                
                frame.Duration.Field = 0x1234;
                
                frame.UpdateFrameCheckSequence ();
                UInt32 fcs = frame.FrameCheckSequence;
                
                //serialize the frame into a byte buffer
                var bytes = frame.Bytes;
                var bas = new ByteArraySegment (bytes);

                //create a new frame that should be identical to the original
                AckFrame recreatedFrame = MacFrame.ParsePacket (bas) as AckFrame;
                recreatedFrame.UpdateFrameCheckSequence ();
                
                Assert.AreEqual (FrameControlField.FrameSubTypes.ControlACK, recreatedFrame.FrameControl.SubType);
                Assert.IsFalse (recreatedFrame.FrameControl.ToDS);
                Assert.IsTrue (recreatedFrame.FrameControl.FromDS);
                Assert.IsTrue (recreatedFrame.FrameControl.MoreFragments);
                
                Assert.AreEqual ("111111111111", recreatedFrame.ReceiverAddress.ToString ().ToUpper ());
                
                Assert.AreEqual (fcs, recreatedFrame.FrameCheckSequence);
            }
开发者ID:vishalishere,项目名称:packetnet,代码行数:30,代码来源:AckFrameTest.cs


示例5: FloodFiller

 public FloodFiller(ByteArraySegment skin, int skinwidth, int skinheight)
 {
     _Skin = skin;
     _Width = skinwidth;
     _Height = skinheight;
     _Fifo = new floodfill_t[FLOODFILL_FIFO_SIZE];
     _FillColor = _Skin.Data[_Skin.StartIndex]; // *skin; // assume this is the pixel to fill
 }
开发者ID:Memorix101,项目名称:SharpQuake,代码行数:8,代码来源:Model.cs


示例6: Test_Constructor_EmptyByteArray

            public void Test_Constructor_EmptyByteArray ()
            {
                ByteArraySegment bas = new ByteArraySegment (new Byte[0]);
                InformationElementList ieList = new InformationElementList (bas);

                Assert.AreEqual (0, ieList.Count);
                Assert.AreEqual (0, ieList.Length);
            }
开发者ID:vishalishere,项目名称:packetnet,代码行数:8,代码来源:InformationElementListTest.cs


示例7: StringTLV

		/// <summary>
		/// Create from a type and string value
		/// </summary>
		/// <param name="tlvType">
		/// A <see cref="TLVTypes"/>
		/// </param>
		/// <param name="StringValue">
		/// A <see cref="System.String"/>
		/// </param>
		public StringTLV(TLVTypes tlvType, string StringValue) {
			var bytes = new byte[TLVTypeLength.TypeLengthLength];
			var offset = 0;
			tlvData = new ByteArraySegment(bytes, offset, bytes.Length);

			Type = tlvType;
			this.StringValue = StringValue;
		}
开发者ID:GodLesZ,项目名称:svn-dump,代码行数:17,代码来源:StringTLV.cs


示例8: IGMPv2Packet

		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="bas">
		/// A <see cref="ByteArraySegment"/>
		/// </param>
		public IGMPv2Packet(ByteArraySegment bas) {
			// set the header field, header field values are retrieved from this byte array
			header = new ByteArraySegment(bas);
			header.Length = UdpFields.HeaderLength;

			// store the payload bytes
			payloadPacketOrData = new PacketOrByteArraySegment();
			payloadPacketOrData.TheByteArraySegment = header.EncapsulatedBytes();
		}
开发者ID:GodLesZ,项目名称:svn-dump,代码行数:15,代码来源:IGMPv2Packet.cs


示例9: Decoder

        public Decoder(int bufsize, long maxmsgsize)
            : base(bufsize)
        {
            m_maxmsgsize = maxmsgsize;
            m_tmpbuf = new ByteArraySegment(new byte[8]);

            //  At the beginning, read one byte and go to one_byte_size_ready state.
            NextStep (m_tmpbuf, 1, OneByteSizeReadyState);
        }
开发者ID:oskarwkarlsson,项目名称:netmq,代码行数:9,代码来源:Decoder.cs


示例10: CtsFrame

            /// <summary>
            /// Constructor
            /// </summary>
            /// <param name="bas">
            /// A <see cref="ByteArraySegment"/>
            /// </param>
            public CtsFrame (ByteArraySegment bas)
            {
                header = new ByteArraySegment (bas);

                FrameControl = new FrameControlField (FrameControlBytes);
                Duration = new DurationField (DurationBytes);
                ReceiverAddress = GetAddress(0);
				
				header.Length = FrameSize;
            }
开发者ID:RSchwoerer,项目名称:Terminals,代码行数:16,代码来源:CtsFrame.cs


示例11: SystemCapabilities

		/// <summary>
		/// Creates a System Capabilities TLV and sets the value
		/// </summary>
		/// <param name="capabilities">
		/// A bitmap containing the available System Capabilities
		/// </param>
		/// <param name="enabled">
		/// A bitmap containing the enabled System Capabilities
		/// </param>
		public SystemCapabilities(ushort capabilities, ushort enabled) {
			var length = TLVTypeLength.TypeLengthLength + SystemCapabilitiesLength + EnabledCapabilitiesLength;
			var bytes = new byte[length];
			var offset = 0;
			tlvData = new ByteArraySegment(bytes, offset, length);

			Type = TLVTypes.SystemCapabilities;
			Capabilities = capabilities;
			Enabled = enabled;
		}
开发者ID:GodLesZ,项目名称:svn-dump,代码行数:19,代码来源:SystemCapabilities.cs


示例12: Test_Constructor_BufferTooShort

 public void Test_Constructor_BufferTooShort ()
 {
     //This IE will have and length of 5 but only three bytes of data
     Byte[] value = new Byte[] { 0x0, 0x5, 0x1, 0x2, 0x3 };
     ByteArraySegment bas = new ByteArraySegment (value);
     
     InformationElement infoElement = new InformationElement (bas);
     
     Assert.AreEqual (3, infoElement.ValueLength);
     Assert.AreEqual (3, infoElement.Value.Length);
 }
开发者ID:vishalishere,项目名称:packetnet,代码行数:11,代码来源:InformationElementTest.cs


示例13: NullDataFrame

            /// <summary>
            /// Initializes a new instance of the <see cref="PacketDotNet.Ieee80211.NullDataFrame"/> class.
            /// </summary>
            /// <param name='bas'>
            /// A <see cref="ByteArraySegment"/>
            /// </param>
            public NullDataFrame (ByteArraySegment bas)
            {
                header = new ByteArraySegment (bas);

                FrameControl = new FrameControlField (FrameControlBytes);
                Duration = new DurationField (DurationBytes);
                SequenceControl = new SequenceControlField (SequenceControlBytes);
                ReadAddresses ();
                
                header.Length = FrameSize;
            }
开发者ID:RSchwoerer,项目名称:Terminals,代码行数:17,代码来源:NullDataFrame.cs


示例14: Test_Constructor_BufferLongerThanElement

 public void Test_Constructor_BufferLongerThanElement ()
 {
     //This IE will have and length of 2 but there are three bytes of data available,
     //the last one should be ignored
     Byte[] value = new Byte[] { 0x0, 0x2, 0x1, 0x2, 0x3 };
     ByteArraySegment bas = new ByteArraySegment (value);
     
     InformationElement infoElement = new InformationElement (bas);
     
     Assert.AreEqual (2, infoElement.ValueLength);
     Assert.AreEqual (2, infoElement.Value.Length);
 }
开发者ID:vishalishere,项目名称:packetnet,代码行数:12,代码来源:InformationElementTest.cs


示例15: V1Decoder

        /// <summary>
        /// Create a new V1Decoder with the given buffer-size, maximum-message-size and Endian-ness.
        /// </summary>
        /// <param name="bufsize">the buffer-size to give the contained buffer</param>
        /// <param name="maxMessageSize">the maximum message size. -1 indicates no limit.</param>
        /// <param name="endian">the Endianness to specify for it - either Big or Little</param>
        public V1Decoder(int bufsize, long maxMessageSize, Endianness endian)
            : base(bufsize, endian)
        {
            m_maxMessageSize = maxMessageSize;
            m_tmpbuf = new ByteArraySegment(new byte[8]);

            //  At the beginning, read one byte and go to one_byte_size_ready state.
            NextStep(m_tmpbuf, 1, OneByteSizeReadyState);

            m_inProgress = new Msg();
            m_inProgress.InitEmpty();
        }
开发者ID:bbqchickenrobot,项目名称:netmq,代码行数:18,代码来源:V1Decoder.cs


示例16: device_OnPacketArrival

        public void device_OnPacketArrival(object sender, CaptureEventArgs eCap)
        {
            try
            {
                ByteArraySegment raw = new ByteArraySegment(eCap.Packet.Data);
                EthernetPacket ethernetPacket = new EthernetPacket(raw);
                IpPacket ipPacket = (IpPacket)ethernetPacket.PayloadPacket;
                TcpPacket tcp = (TcpPacket)ipPacket.PayloadPacket;

                if (ipPacket != null && tcp != null)
                {
                    string destIp = ipPacket.DestinationAddress.ToString();

                    if (destIp == captureIp)
                    {
                        //Client -> Server
                        MainWindow.pp.AppendClientData(tcp.PayloadData);

                        // ReSharper disable CSharpWarnings::CS0642
                        while (MainWindow.pp.ProcessClientData()) ;
                        // ReSharper restore CSharpWarnings::CS0642

                    }
                    else
                    {
                        //Do a check for a new game Connection. Each handshake starts with a dword 1 packet from the server.
                        byte[] test = { 0x01, 0x00, 0x00, 0x00 };
                        if (StructuralComparisons.StructuralEqualityComparer.Equals(test, tcp.PayloadData))
                        {
                            //New Connection detected.
                            //We should reset State and Security Info
                            MainWindow.pp.Init();
                            MainWindow.pp.State = 0;
                            MainWindow.ClearPackets();
                        }

                        //Sever -> Client
                        MainWindow.pp.AppendServerData(tcp.PayloadData);
                        // ReSharper disable CSharpWarnings::CS0642
                        while (MainWindow.pp.ProcessServerData()) ;
                        // ReSharper restore CSharpWarnings::CS0642
                    }

                }
            }
            catch (Exception ex)
            {

                MainWindow.SetText("device_OnPacketArrival failure. \n Message:" + ex);
            }
        }
开发者ID:GiGatR00n,项目名称:Tera_PacketViewer,代码行数:51,代码来源:Capture.cs


示例17: DataDataFrame

            /// <summary>
            /// Initializes a new instance of the <see cref="PacketDotNet.Ieee80211.DataDataFrame"/> class.
            /// </summary>
            /// <param name='bas'>
            /// Bas.
            /// </param>
            public DataDataFrame (ByteArraySegment bas)
            {
                header = new ByteArraySegment (bas);

                FrameControl = new FrameControlField (FrameControlBytes);
                Duration = new DurationField (DurationBytes);
                SequenceControl = new SequenceControlField (SequenceControlBytes);
                ReadAddresses (); //must do this after reading FrameControl

                header.Length = FrameSize; 
                var availablePayloadLength = GetAvailablePayloadLength();
				if(availablePayloadLength > 0)
				{
					payloadPacketOrData.TheByteArraySegment = header.EncapsulatedBytes (availablePayloadLength);
				}
            }
开发者ID:RSchwoerer,项目名称:Terminals,代码行数:22,代码来源:DataDataFrame.cs


示例18: Init

        public void Init( PgmAddress pgmAddress)
        {
            m_pgmAddress = pgmAddress;

            m_pgmSocket = new PgmSocket(m_options, PgmSocketType.Publisher, (PgmAddress)m_addr.Resolved);
            m_pgmSocket.Init();

            m_socket = m_pgmSocket.Handle;

            var localEndpoint = new IPEndPoint(IPAddress.Any, 0);

            m_socket.Bind(localEndpoint);

            m_pgmSocket.InitOptions();

            m_outBufferSize = Config.PgmMaxTPDU;
            m_outBuffer = new ByteArraySegment(new byte[m_outBufferSize]);
        }
开发者ID:awb99,项目名称:netmq,代码行数:18,代码来源:PgmSender.cs


示例19: IntLittleEndian

        public void IntLittleEndian()
        {
            ByteArraySegment byteArraySegment = new ByteArraySegment(new byte[4]);

            byteArraySegment.PutInteger(Endianness.Little, 1, 0);

            Assert.AreEqual(1, byteArraySegment[0]);
            Assert.AreEqual(0, byteArraySegment[3]);

            long num = byteArraySegment.GetInteger(Endianness.Little, 0);

            Assert.AreEqual(1, num);

            byteArraySegment.PutInteger(Endianness.Little, 16777216, 0);

            Assert.AreEqual(1, byteArraySegment[3]);
            Assert.AreEqual(0, byteArraySegment[0]);

            num = byteArraySegment.GetInteger(Endianness.Little, 0);

            Assert.AreEqual(16777216, num);
        }
开发者ID:bbqchickenrobot,项目名称:netmq,代码行数:22,代码来源:ByteArraySegmentTests.cs


示例20: LongLittleEndian

        public void LongLittleEndian()
        {
            ByteArraySegment byteArraySegment = new ByteArraySegment(new byte[8]);

            byteArraySegment.PutLong(Endianness.Little, 1, 0);

            Assert.AreEqual(byteArraySegment[0], 1);
            Assert.AreEqual(0, byteArraySegment[7]);

            long num = byteArraySegment.GetLong(Endianness.Little, 0);

            Assert.AreEqual(1, num);

            byteArraySegment.PutLong(Endianness.Little, 72057594037927936, 0);

            Assert.AreEqual(1, byteArraySegment[7]);
            Assert.AreEqual(0, byteArraySegment[0]);

            num = byteArraySegment.GetLong(Endianness.Little, 0);

            Assert.AreEqual(72057594037927936, num);
        }
开发者ID:bbqchickenrobot,项目名称:netmq,代码行数:22,代码来源:ByteArraySegmentTests.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# ByteBuffer类代码示例发布时间:2022-05-24
下一篇:
C# ByteArrayPart类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap