Commit e18d30c8 authored by Brickner_cp's avatar Brickner_cp

Datagram auto properties

parent f0e4f8f6
...@@ -25,9 +25,9 @@ namespace PcapDotNet.Packets ...@@ -25,9 +25,9 @@ namespace PcapDotNet.Packets
if (buffer == null) if (buffer == null)
throw new ArgumentNullException("buffer"); throw new ArgumentNullException("buffer");
_buffer = buffer; Buffer = buffer;
_startOffset = 0; StartOffset = 0;
_length = buffer.Length; Length = buffer.Length;
} }
/// <summary> /// <summary>
...@@ -38,9 +38,9 @@ namespace PcapDotNet.Packets ...@@ -38,9 +38,9 @@ namespace PcapDotNet.Packets
/// <param name="length">The number of bytes to take.</param> /// <param name="length">The number of bytes to take.</param>
public Datagram(byte[] buffer, int offset, int length) public Datagram(byte[] buffer, int offset, int length)
{ {
_buffer = buffer; Buffer = buffer;
_startOffset = offset; StartOffset = offset;
_length = length; Length = length;
} }
/// <summary> /// <summary>
...@@ -55,10 +55,7 @@ namespace PcapDotNet.Packets ...@@ -55,10 +55,7 @@ namespace PcapDotNet.Packets
/// <summary> /// <summary>
/// The number of bytes in this datagram. /// The number of bytes in this datagram.
/// </summary> /// </summary>
public int Length public int Length { get; private set; }
{
get { return _length; }
}
/// <summary> /// <summary>
/// The value of the byte in the given offset in the datagram. /// The value of the byte in the given offset in the datagram.
...@@ -66,7 +63,7 @@ namespace PcapDotNet.Packets ...@@ -66,7 +63,7 @@ namespace PcapDotNet.Packets
/// <param name="offset">The offset in the datagram to take the byte from.</param> /// <param name="offset">The offset in the datagram to take the byte from.</param>
public byte this[int offset] public byte this[int offset]
{ {
get { return _buffer[StartOffset + offset]; } get { return Buffer[StartOffset + offset]; }
} }
/// <summary> /// <summary>
...@@ -161,25 +158,19 @@ namespace PcapDotNet.Packets ...@@ -161,25 +158,19 @@ namespace PcapDotNet.Packets
internal void Write(byte[] buffer, int offset) internal void Write(byte[] buffer, int offset)
{ {
_buffer.BlockCopy(StartOffset, buffer, offset, Length); Buffer.BlockCopy(StartOffset, buffer, offset, Length);
} }
/// <summary> /// <summary>
/// The original buffer that holds all the data for the datagram. /// The original buffer that holds all the data for the datagram.
/// </summary> /// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")] [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
internal byte[] Buffer internal byte[] Buffer { get; private set; }
{
get { return _buffer; }
}
/// <summary> /// <summary>
/// The offset of the first byte of the datagram in the buffer. /// The offset of the first byte of the datagram in the buffer.
/// </summary> /// </summary>
internal int StartOffset internal int StartOffset { get; private set; }
{
get { return _startOffset; }
}
/// <summary> /// <summary>
/// The default validity check always returns true. /// The default validity check always returns true.
...@@ -324,9 +315,6 @@ namespace PcapDotNet.Packets ...@@ -324,9 +315,6 @@ namespace PcapDotNet.Packets
} }
private static readonly Datagram _empty = new Datagram(new byte[0], 0, 0); private static readonly Datagram _empty = new Datagram(new byte[0], 0, 0);
private readonly byte[] _buffer;
private readonly int _startOffset;
private readonly int _length;
private bool? _isValid; private bool? _isValid;
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment