Commit 3bfa6609 authored by Brickner_cp's avatar Brickner_cp

Warnings, Code Analysis and Documentation. 132 warnings left.

parent bd000db5
...@@ -25,21 +25,43 @@ namespace PcapDotNet.Base ...@@ -25,21 +25,43 @@ namespace PcapDotNet.Base
return sequence.Concat((IEnumerable<T>)values); return sequence.Concat((IEnumerable<T>)values);
} }
/// <summary>
/// Returns the bitwise xor of all the elements in the sequence.
/// </summary>
/// <param name="sequence">The elements to xor.</param>
/// <returns>The bitwise xor of all the elements in the sequence.</returns>
public static long Xor(this IEnumerable<long> sequence) public static long Xor(this IEnumerable<long> sequence)
{ {
return sequence.Xor(value => value); return sequence.Xor(value => value);
} }
/// <summary>
/// Returns the bitwise xor of all the elements in the sequence.
/// </summary>
/// <param name="sequence">The elements to xor.</param>
/// <returns>The bitwise xor of all the elements in the sequence.</returns>
public static int Xor(this IEnumerable<int> sequence) public static int Xor(this IEnumerable<int> sequence)
{ {
return sequence.Xor(value => value); return sequence.Xor(value => value);
} }
/// <summary>
/// Returns the bitwise xor of all the selected values of the elements in the sequence.
/// </summary>
/// <param name="sequence">The elements to select values to xor.</param>
/// <param name="selector">The selector used to select the values.</param>
/// <returns>The bitwise xor of all the selected values of the elements in the sequence.</returns>
public static long Xor<T>(this IEnumerable<T> sequence, Func<T, long> selector) public static long Xor<T>(this IEnumerable<T> sequence, Func<T, long> selector)
{ {
return sequence.Aggregate((long)0, (xorTotal, current) => xorTotal ^ selector(current)); return sequence.Aggregate((long)0, (xorTotal, current) => xorTotal ^ selector(current));
} }
/// <summary>
/// Returns the bitwise xor of all the selected values of the elements in the sequence.
/// </summary>
/// <param name="sequence">The elements to select values to xor.</param>
/// <param name="selector">The selector used to select the values.</param>
/// <returns>The bitwise xor of all the selected values of the elements in the sequence.</returns>
public static int Xor<T>(this IEnumerable<T> sequence, Func<T, int> selector) public static int Xor<T>(this IEnumerable<T> sequence, Func<T, int> selector)
{ {
return sequence.Aggregate(0, (xorTotal, current) => xorTotal ^ selector(current)); return sequence.Aggregate(0, (xorTotal, current) => xorTotal ^ selector(current));
......
...@@ -15,9 +15,11 @@ ...@@ -15,9 +15,11 @@
<Word>cbt</Word> <Word>cbt</Word>
<Word>ccitt</Word> <Word>ccitt</Word>
<Word>cftp</Word> <!-- maybe Configurable Fault Tolerant Processor --> <Word>cftp</Word> <!-- maybe Configurable Fault Tolerant Processor -->
<Word>codings</Word>
<Word>datagrams</Word> <Word>datagrams</Word>
<Word>datakit</Word> <Word>datakit</Word>
<Word>dcn</Word> <Word>dcn</Word>
<Word>docsis</Word>
<Word>emcon</Word> <Word>emcon</Word>
<Word>endianity</Word> <Word>endianity</Word>
<Word>enqueueing</Word> <Word>enqueueing</Word>
......
...@@ -15,6 +15,16 @@ namespace PcapDotNet.Packets ...@@ -15,6 +15,16 @@ namespace PcapDotNet.Packets
/// </summary> /// </summary>
public static class ByteArrayExtensions public static class ByteArrayExtensions
{ {
/// <summary>
/// Compares all the bytes in the two ranges of the arrays.
/// Returns the first non-zero compare value of the bytes in the ranges or zero if the ranges have the same byte values.
/// </summary>
/// <param name="array">The first array to compare.</param>
/// <param name="offset">The offset of the first byte to compare in the first array.</param>
/// <param name="other">The second array to compare.</param>
/// <param name="otherOffset">The offset of the first byte to compare in the second array.</param>
/// <param name="count">The number of bytes to compare.</param>
/// <returns>The first non-zero compare value of the bytes in the ranges or zero if the ranges have the same byte values.</returns>
public static int Compare(this byte[] array, int offset, byte[] other, int otherOffset, int count) public static int Compare(this byte[] array, int offset, byte[] other, int otherOffset, int count)
{ {
if (array == null) if (array == null)
...@@ -31,6 +41,16 @@ namespace PcapDotNet.Packets ...@@ -31,6 +41,16 @@ namespace PcapDotNet.Packets
return 0; return 0;
} }
/// <summary>
/// Compares all the bytes in the two ranges of the arrays.
/// Returns true iff the ranges have the same byte values.
/// </summary>
/// <param name="array">The first array to compare.</param>
/// <param name="offset">The offset of the first byte to compare in the first array.</param>
/// <param name="other">The second array to compare.</param>
/// <param name="otherOffset">The offset of the first byte to compare in the second array.</param>
/// <param name="count">The number of bytes to compare.</param>
/// <returns>True iff the ranges have the same byte values.</returns>
public static bool SequenceEqual(this byte[] array, int offset, byte[] other, int otherOffset, int count) public static bool SequenceEqual(this byte[] array, int offset, byte[] other, int otherOffset, int count)
{ {
if (array == null) if (array == null)
...@@ -39,6 +59,16 @@ namespace PcapDotNet.Packets ...@@ -39,6 +59,16 @@ namespace PcapDotNet.Packets
return array.Compare(offset, other, otherOffset, count) == 0; return array.Compare(offset, other, otherOffset, count) == 0;
} }
/// <summary>
/// Returns the first offset in the array where the other array's range sequence of bytes can be found or the length of the array if no match exists.
/// </summary>
/// <param name="array">The array to search for the sequence of bytes.</param>
/// <param name="offset">The offset of the first byte in the array that should be compared to the sequence to find.</param>
/// <param name="count">The number of bytes in the array that the sequence can be searched in.</param>
/// <param name="other">The array that contains the sequence of bytes to search.</param>
/// <param name="otherOffset">The offset in the array containing the sequence of the first byte of the sequence.</param>
/// <param name="otherCount">The number of bytes of the sequence.</param>
/// <returns>The first offset in the array where the other array's range sequence of bytes can be found or the length of the array if no match exists.</returns>
public static int Find(this byte[] array, int offset, int count, byte[] other, int otherOffset, int otherCount) public static int Find(this byte[] array, int offset, int count, byte[] other, int otherOffset, int otherCount)
{ {
if (array == null) if (array == null)
...@@ -50,7 +80,7 @@ namespace PcapDotNet.Packets ...@@ -50,7 +80,7 @@ namespace PcapDotNet.Packets
int maxOffset = offset + count - otherCount; int maxOffset = offset + count - otherCount;
while (offset < maxOffset) while (offset < maxOffset)
{ {
if (Compare(array, offset, other, otherOffset, otherCount) == 0) if (array.SequenceEqual(offset, other, otherOffset, otherCount))
return offset; return offset;
++offset; ++offset;
} }
...@@ -58,10 +88,16 @@ namespace PcapDotNet.Packets ...@@ -58,10 +88,16 @@ namespace PcapDotNet.Packets
return array.Length; return array.Length;
} }
/// <summary>
/// Returns the first offset in the array where the other array sequence of bytes can be found or the length of the array if no match exists.
/// </summary>
/// <param name="array">The array to search for the sequence of bytes.</param>
/// <param name="offset">The offset of the first byte in the array that should be compared to the sequence to find.</param>
/// <param name="count">The number of bytes in the array that the sequence can be searched in.</param>
/// <param name="other">The array that contains the sequence of bytes to search.</param>
/// <returns>The first offset in the array where the other array sequence of bytes can be found or the length of the array if no match exists.</returns>
public static int Find(this byte[] array, int offset, int count, byte[] other) public static int Find(this byte[] array, int offset, int count, byte[] other)
{ {
if (array == null)
throw new ArgumentNullException("array");
if (other == null) if (other == null)
throw new ArgumentNullException("other"); throw new ArgumentNullException("other");
...@@ -570,6 +606,14 @@ namespace PcapDotNet.Packets ...@@ -570,6 +606,14 @@ namespace PcapDotNet.Packets
offset += UInt48.SizeOf; offset += UInt48.SizeOf;
} }
/// <summary>
/// Writes a string to a byte array in a specific offset using the given encoding.
/// Increments the offset by the number of bytes written.
/// </summary>
/// <param name="buffer">The buffer to write the string in.</param>
/// <param name="offset">The offset in the buffer to start writing the string in. Incremented by the number of bytes written.</param>
/// <param name="value">The string to write in the buffer.</param>
/// <param name="encoding">The encoding to use to translate the string into a sequence of bytes.</param>
public static void Write(this byte[] buffer, ref int offset, string value, Encoding encoding) public static void Write(this byte[] buffer, ref int offset, string value, Encoding encoding)
{ {
if (encoding == null) if (encoding == null)
...@@ -679,18 +723,31 @@ namespace PcapDotNet.Packets ...@@ -679,18 +723,31 @@ namespace PcapDotNet.Packets
buffer.Write(ref offset, value.MillisecondsSinceMidnightUniversalTime, endianity); buffer.Write(ref offset, value.MillisecondsSinceMidnightUniversalTime, endianity);
} }
// public static void WriteCarriageReturnLineFeed(this byte[] buffer, int offset) // public static void WriteCarriageReturnLinefeed(this byte[] buffer, int offset)
// { // {
// buffer.Write(ref offset, AsciiBytes.CarriageReturn); // buffer.Write(ref offset, AsciiBytes.CarriageReturn);
// buffer.Write(offset, AsciiBytes.LineFeed); // buffer.Write(offset, AsciiBytes.LineFeed);
// } // }
// //
/// <summary>
/// Writes the endline bytes (CRLF) in the buffer in the given offset.
/// Increments the offset by the number of bytes written (2).
/// </summary>
/// <param name="buffer">The buffer to write the CRLF in.</param>
/// <param name="offset">The offset to start writing the CRLF in. Incremented by the number of bytes written (2).</param>
public static void WriteCarriageReturnLinefeed(this byte[] buffer, ref int offset) public static void WriteCarriageReturnLinefeed(this byte[] buffer, ref int offset)
{ {
buffer.Write(ref offset, AsciiBytes.CarriageReturn); buffer.Write(ref offset, AsciiBytes.CarriageReturn);
buffer.Write(ref offset, AsciiBytes.Linefeed); buffer.Write(ref offset, AsciiBytes.Linefeed);
} }
/// <summary>
/// Writes an integer as a decimal string in ASCII encoding to a buffer of bytes in a specific offset.
/// The offset is incremented by the number of bytes (digits) written.
/// </summary>
/// <param name="buffer">The buffer to write the integer in.</param>
/// <param name="offset">The offset in the buffer to start writing the integer. Incremented by the number of bytes (digits) written.</param>
/// <param name="value">The integer value to write in the buffer.</param>
public static void WriteDecimal(this byte[] buffer, ref int offset, uint value) public static void WriteDecimal(this byte[] buffer, ref int offset, uint value)
{ {
buffer.Write(ref offset, value.ToString(CultureInfo.InvariantCulture), Encoding.ASCII); buffer.Write(ref offset, value.ToString(CultureInfo.InvariantCulture), Encoding.ASCII);
......
...@@ -146,11 +146,20 @@ namespace PcapDotNet.Packets ...@@ -146,11 +146,20 @@ namespace PcapDotNet.Packets
return Length.GetHashCode() ^ this.BytesSequenceGetHashCode(); return Length.GetHashCode() ^ this.BytesSequenceGetHashCode();
} }
/// <summary>
/// Converts the datagram to a hexadecimal string representing every bytes as two hexadecimal digits.
/// </summary>
/// <returns>A hexadecimal string representing every bytes as two hexadecimal digits.</returns>
public override string ToString() public override string ToString()
{ {
return Buffer.Range(StartOffset, Length).BytesSequenceToHexadecimalString(); return Buffer.Range(StartOffset, Length).BytesSequenceToHexadecimalString();
} }
/// <summary>
/// Converts the datagram to a string using the given encoding.
/// </summary>
/// <param name="encoding">The encoding to use to convert the bytes sequence in the Datagram to a string.</param>
/// <returns>A string of the bytes in the Datagram converted using the given encoding.</returns>
public string ToString(Encoding encoding) public string ToString(Encoding encoding)
{ {
if (encoding == null) if (encoding == null)
......
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