Class ReadOnlySpanUtilities
- Namespace
- Plugin.ByteArrays
- Assembly
- Plugin.ByteArrays.dll
Utility functions for analyzing and working with ReadOnlySpan<byte> data.
public static class ReadOnlySpanUtilities
- Inheritance
-
ReadOnlySpanUtilities
- Inherited Members
Methods
AllBytesEqual(ReadOnlySpan<byte>)
Checks if all bytes in the ReadOnlySpan<byte> have the same value.
public static bool AllBytesEqual(this ReadOnlySpan<byte> span)
Parameters
spanReadOnlySpan<byte>The ReadOnlySpan<byte> to check.
Returns
- bool
True if all bytes are identical or span is empty; otherwise, false.
AnalyzeDistribution(ReadOnlySpan<byte>)
Analyzes the distribution of byte values in the ReadOnlySpan<byte>. Returns a dictionary mapping each byte value to its frequency count.
public static Dictionary<byte, int> AnalyzeDistribution(this ReadOnlySpan<byte> span)
Parameters
spanReadOnlySpan<byte>The ReadOnlySpan<byte> to analyze.
Returns
- Dictionary<byte, int>
A dictionary with byte values as keys and their frequencies as values.
CalculateEntropy(ReadOnlySpan<byte>)
Calculates the Shannon entropy of the ReadOnlySpan<byte>. Entropy is a measure of randomness/unpredictability in the data. Returns a value between 0.0 (perfectly ordered) and 8.0 (maximum entropy for bytes).
public static double CalculateEntropy(this ReadOnlySpan<byte> span)
Parameters
spanReadOnlySpan<byte>The ReadOnlySpan<byte> to analyze.
Returns
- double
The calculated entropy value.
CountOccurrences(ReadOnlySpan<byte>, byte)
Counts the occurrences of a specific byte value in the ReadOnlySpan<byte>.
public static int CountOccurrences(this ReadOnlySpan<byte> span, byte value)
Parameters
spanReadOnlySpan<byte>The ReadOnlySpan<byte> to search.
valuebyteThe byte value to count.
Returns
- int
The number of occurrences of the specified byte value.
FindAllIndices(ReadOnlySpan<byte>, byte)
Finds all indices where a specific byte value occurs in the ReadOnlySpan<byte>.
public static int[] FindAllIndices(this ReadOnlySpan<byte> span, byte value)
Parameters
spanReadOnlySpan<byte>The ReadOnlySpan<byte> to search.
valuebyteThe byte value to find.
Returns
- int[]
An array of indices where the byte value was found.
IsAllZeros(ReadOnlySpan<byte>)
Checks if the ReadOnlySpan<byte> contains only zero bytes.
public static bool IsAllZeros(this ReadOnlySpan<byte> span)
Parameters
spanReadOnlySpan<byte>The ReadOnlySpan<byte> to check.
Returns
- bool
True if all bytes are zero or span is empty; otherwise, false.
Reverse(ReadOnlySpan<byte>)
Reverses the bytes in a copy of the ReadOnlySpan<byte>. Note: This creates a new array since ReadOnlySpan is immutable.
public static byte[] Reverse(this ReadOnlySpan<byte> span)
Parameters
spanReadOnlySpan<byte>The ReadOnlySpan<byte> to reverse.
Returns
- byte[]
A new byte array with reversed byte order.
Xor(ReadOnlySpan<byte>, ReadOnlySpan<byte>)
Performs an XOR operation between two ReadOnlySpan<byte> instances. If spans have different lengths, operates on the shorter length.
public static byte[] Xor(this ReadOnlySpan<byte> span1, ReadOnlySpan<byte> span2)
Parameters
span1ReadOnlySpan<byte>First ReadOnlySpan<byte>.
span2ReadOnlySpan<byte>Second ReadOnlySpan<byte>.
Returns
- byte[]
A new byte array containing the XOR result.