Table of Contents

Struct Bytes

Namespace
Utils.Objects
Assembly
Utils.dll

Represents a read-only view over a sequence of bytes.

public readonly struct Bytes : IReadOnlyList<byte>, IReadOnlyCollection<byte>, IEnumerable<byte>, IEnumerable, ICloneable, IEquatable<Bytes>, IEquatable<byte[]>, IComparable<Bytes>, IComparable<byte[]>, IComparable, IComparisonOperators<Bytes, Bytes, bool>, IEqualityOperators<Bytes, Bytes, bool>, IComparisonOperators<Bytes, byte[], bool>, IEqualityOperators<Bytes, byte[], bool>, IAdditionOperators<Bytes, Bytes, Bytes>, IAdditionOperators<Bytes, byte[], Bytes>
Implements
Inherited Members
Extension Methods

Properties

Count

Gets the number of bytes stored in this Bytes instance.

public int Count { get; }

Property Value

int

Empty

Gets an empty Bytes instance with no data.

public static Bytes Empty { get; }

Property Value

Bytes

this[int]

Gets the byte at the specified index.

public byte this[int index] { get; }

Parameters

index int

The zero-based index of the element to get.

Property Value

byte

The byte at the specified index.

Methods

Clone()

Creates a new copy of the current Bytes object.

public object Clone()

Returns

object

A new Bytes containing a copy of the internal array.

CompareTo(byte[]?)

Compares the current Bytes with a byte array.

public int CompareTo(byte[]? other)

Parameters

other byte[]

A byte array to compare.

Returns

int

A signed integer that indicates the relative order of the compared objects. 0 if they are equal, less than 0 if this is less than other, and greater than 0 if this is greater.

CompareTo(object?)

Compares the current instance with another object of the same type.

public int CompareTo(object? obj)

Parameters

obj object

An object to compare, which can be Bytes or byte[].

Returns

int

A value indicating the relative order of the objects.

Exceptions

InvalidOperationException

If obj is not a valid type.

CompareTo(Bytes)

Compares the current Bytes with another Bytes.

public int CompareTo(Bytes other)

Parameters

other Bytes

A Bytes to compare.

Returns

int

A signed integer that indicates the relative order of the compared objects. 0 if they are equal, less than 0 if this is less than other, and greater than 0 if this is greater.

CopyTo(byte[], int, int?)

Copies the contents of this Bytes into the specified array starting at index and using an optional length.

public void CopyTo(byte[] array, int index, int? length = null)

Parameters

array byte[]

The target array.

index int

The destination index in array. If negative, it is offset from the end of array.

length int?

Number of bytes to copy. If null, copies as many as possible.

CopyTo(Stream, int, int?)

Writes the contents of this Bytes to a Stream starting at the specified index and using an optional length.

public void CopyTo(Stream s, int index, int? length = null)

Parameters

s Stream

The stream to write to.

index int

The source index in the Utils.Objects.Bytes._innerBytes array.

length int?

Number of bytes to write. If null, writes as many as possible.

Equals(byte[]?)

Determines whether the specified byte array is equal to the current Bytes.

public bool Equals(byte[]? other)

Parameters

other byte[]

A byte array to compare.

Returns

bool

true if both contain identical byte sequences; otherwise false.

Equals(object?)

Indicates whether this instance and a specified object are equal.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if obj and this instance are the same type and represent the same value; otherwise, false.

Equals(Bytes)

Determines whether the specified Bytes is equal to the current Bytes.

public bool Equals(Bytes other)

Parameters

other Bytes

Another Bytes to compare.

Returns

bool

true if both contain identical byte sequences; otherwise false.

GetEnumerator()

Returns an enumerator that iterates through the byte array.

public IEnumerator<byte> GetEnumerator()

Returns

IEnumerator<byte>

GetHashCode()

Returns the hash code for this instance.

public override int GetHashCode()

Returns

int

A 32-bit signed integer that is the hash code for this instance.

Parse(string)

Creates a Bytes object from a string of hexadecimal numbers separated by spaces or common delimiters.

public static Bytes Parse(string s)

Parameters

s string

A string containing hexadecimal numbers to parse.

Returns

Bytes

A Bytes instance containing the parsed data.

Exceptions

FormatException

Thrown if the string contains invalid hexadecimal values.

ToArray()

Returns a copy of the underlying byte array.

public byte[] ToArray()

Returns

byte[]

A new byte array with the same contents.

ToString()

Returns a string that represents the byte array in hexadecimal format.

public override string ToString()

Returns

string

Operators

operator +(byte[], Bytes)

Concatenates a raw byte array with a Bytes instance.

public static Bytes operator +(byte[] left, Bytes right)

Parameters

left byte[]

The raw array to prepend.

right Bytes

The wrapped byte sequence.

Returns

Bytes

A new Bytes containing the bytes of both operands.

operator +(Bytes, byte[])

Concatenates a Bytes instance with a raw byte array.

public static Bytes operator +(Bytes left, byte[] right)

Parameters

left Bytes

The wrapped byte sequence.

right byte[]

The raw array to append.

Returns

Bytes

A new Bytes containing the bytes of both operands.

operator +(Bytes, Bytes)

Concatenates two Bytes instances into a new sequence.

public static Bytes operator +(Bytes left, Bytes right)

Parameters

left Bytes

The first operand.

right Bytes

The second operand.

Returns

Bytes

A new Bytes containing the bytes of both operands.

operator ==(byte[], Bytes)

Determines whether a raw byte array equals a Bytes instance.

public static bool operator ==(byte[] left, Bytes right)

Parameters

left byte[]

The raw array to compare.

right Bytes

The wrapped byte sequence to compare.

Returns

bool

true when both operands contain the same bytes.

operator ==(Bytes, byte[]?)

Determines whether a Bytes instance equals a raw byte array.

public static bool operator ==(Bytes left, byte[]? right)

Parameters

left Bytes

The wrapped byte sequence to compare.

right byte[]

The raw array to compare.

Returns

bool

true when both operands contain the same bytes.

operator ==(Bytes, Bytes)

Determines whether two Bytes instances represent identical sequences.

public static bool operator ==(Bytes left, Bytes right)

Parameters

left Bytes

The first byte sequence to compare.

right Bytes

The second byte sequence to compare.

Returns

bool

true when both operands contain the same bytes.

operator >(byte[], Bytes)

Determines whether a raw byte array is lexicographically greater than a wrapped sequence.

public static bool operator >(byte[] left, Bytes right)

Parameters

left byte[]

The raw array to compare.

right Bytes

The wrapped byte sequence to compare.

Returns

bool

true when left sorts after right.

operator >(Bytes, byte[])

Determines whether a Bytes instance is lexicographically greater than a raw array.

public static bool operator >(Bytes left, byte[] right)

Parameters

left Bytes

The wrapped byte sequence to compare.

right byte[]

The raw array to compare.

Returns

bool

true when left sorts after right.

operator >(Bytes, Bytes)

Determines whether one Bytes instance is lexicographically greater than another.

public static bool operator >(Bytes left, Bytes right)

Parameters

left Bytes

The first byte sequence to compare.

right Bytes

The second byte sequence to compare.

Returns

bool

true when left sorts after right.

operator >=(byte[], Bytes)

Determines whether a raw byte array is lexicographically greater than or equal to a wrapped sequence.

public static bool operator >=(byte[] left, Bytes right)

Parameters

left byte[]

The raw array to compare.

right Bytes

The wrapped byte sequence to compare.

Returns

bool

true when left sorts after or equals right.

operator >=(Bytes, byte[])

Determines whether a Bytes instance is lexicographically greater than or equal to a raw array.

public static bool operator >=(Bytes left, byte[] right)

Parameters

left Bytes

The wrapped byte sequence to compare.

right byte[]

The raw array to compare.

Returns

bool

true when left sorts after or equals right.

operator >=(Bytes, Bytes)

Determines whether one Bytes instance is lexicographically greater than or equal to another.

public static bool operator >=(Bytes left, Bytes right)

Parameters

left Bytes

The first byte sequence to compare.

right Bytes

The second byte sequence to compare.

Returns

bool

true when left sorts after or equals right.

implicit operator Bytes(byte[])

Implicitly converts a byte array to a Bytes instance.

public static implicit operator Bytes(byte[] bytes)

Parameters

bytes byte[]

Returns

Bytes

implicit operator byte[](Bytes)

Implicitly converts a Bytes instance to a byte array.

public static implicit operator byte[](Bytes bytes)

Parameters

bytes Bytes

Returns

byte[]

operator !=(byte[], Bytes)

Determines whether a raw byte array differs from a Bytes instance.

public static bool operator !=(byte[] left, Bytes right)

Parameters

left byte[]

The raw array to compare.

right Bytes

The wrapped byte sequence to compare.

Returns

bool

true when operands differ.

operator !=(Bytes, byte[]?)

Determines whether a Bytes instance differs from a raw byte array.

public static bool operator !=(Bytes left, byte[]? right)

Parameters

left Bytes

The wrapped byte sequence to compare.

right byte[]

The raw array to compare.

Returns

bool

true when operands differ.

operator !=(Bytes, Bytes)

Determines whether two Bytes instances do not represent identical sequences.

public static bool operator !=(Bytes left, Bytes right)

Parameters

left Bytes

The first byte sequence to compare.

right Bytes

The second byte sequence to compare.

Returns

bool

true when operands differ.

operator <(byte[], Bytes)

Determines whether a raw byte array is lexicographically less than a wrapped sequence.

public static bool operator <(byte[] left, Bytes right)

Parameters

left byte[]

The raw array to compare.

right Bytes

The wrapped byte sequence to compare.

Returns

bool

true when left sorts before right.

operator <(Bytes, byte[])

Determines whether a Bytes instance is lexicographically less than a raw array.

public static bool operator <(Bytes left, byte[] right)

Parameters

left Bytes

The wrapped byte sequence to compare.

right byte[]

The raw array to compare.

Returns

bool

true when left sorts before right.

operator <(Bytes, Bytes)

Determines whether one Bytes instance is lexicographically less than another.

public static bool operator <(Bytes left, Bytes right)

Parameters

left Bytes

The first byte sequence to compare.

right Bytes

The second byte sequence to compare.

Returns

bool

true when left sorts before right.

operator <=(byte[], Bytes)

Determines whether a raw byte array is lexicographically less than or equal to a wrapped sequence.

public static bool operator <=(byte[] left, Bytes right)

Parameters

left byte[]

The raw array to compare.

right Bytes

The wrapped byte sequence to compare.

Returns

bool

true when left sorts before or equals right.

operator <=(Bytes, byte[])

Determines whether a Bytes instance is lexicographically less than or equal to a raw array.

public static bool operator <=(Bytes left, byte[] right)

Parameters

left Bytes

The wrapped byte sequence to compare.

right byte[]

The raw array to compare.

Returns

bool

true when left sorts before or equals right.

operator <=(Bytes, Bytes)

Determines whether one Bytes instance is lexicographically less than or equal to another.

public static bool operator <=(Bytes left, Bytes right)

Parameters

left Bytes

The first byte sequence to compare.

right Bytes

The second byte sequence to compare.

Returns

bool

true when left sorts before or equals right.