本文整理汇总了C#中ByteArraySegment类的典型用法代码示例。如果您正苦于以下问题:C# ByteArraySegment类的具体用法?C# ByteArraySegment怎么用?C# ByteArraySegment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ByteArraySegment类属于命名空间,在下文中一共展示了ByteArraySegment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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;
}
示例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;
}
}
示例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);
}
示例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
}
示例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);
}
示例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;
}
示例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();
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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();
}