Class ByteString
A rope-like immutable data structure containing bytes. The goal of this structure is to reduce copying of arrays when concatenating and slicing sequences of bytes, and also providing a thread safe way of working with bytes.
Inherited Members
Namespace: Akka.IO
Assembly: Akka.dll
Syntax
public sealed class ByteString : IEquatable<ByteString>, IEnumerable<byte>, IEnumerable
Properties
| Edit this page View SourceCount
Gets a total number of bytes stored inside this ByteString.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
int |
Empty
An empty ByteString.
Declaration
public static ByteString Empty { get; }
Property Value
Type | Description |
---|---|
ByteString |
IsCompact
Determines if current ByteString has compact representation. Compact byte strings represent bytes stored inside single, continuous block of memory.
Declaration
public bool IsCompact { get; }
Property Value
Type | Description |
---|---|
bool | TBD |
IsEmpty
Determines if current ByteString is empty.
Declaration
public bool IsEmpty { get; }
Property Value
Type | Description |
---|---|
bool |
this[int]
Gets a byte stored under a provided index
.
Declaration
public byte this[int index] { get; }
Parameters
Type | Name | Description |
---|---|---|
int | index | TBD |
Property Value
Type | Description |
---|---|
byte |
Methods
| Edit this page View SourceCompact()
Compacts current ByteString, potentially copying its content underneat into new byte array.
Declaration
public ByteString Compact()
Returns
Type | Description |
---|---|
ByteString | TBD |
Concat(ByteString)
Appends other
ByteString at the tail
of a current one, creating a new ByteString in result.
Contents of byte strings are NOT copied.
Declaration
public ByteString Concat(ByteString other)
Parameters
Type | Name | Description |
---|---|---|
ByteString | other |
Returns
Type | Description |
---|---|
ByteString | TBD |
CopyFrom(ArraySegment<byte>)
Creates a new ByteString by copying a byte array range from provided buffer.
Declaration
public static ByteString CopyFrom(ArraySegment<byte> buffer)
Parameters
Type | Name | Description |
---|---|---|
ArraySegment<byte> | buffer | Buffer specifying a byte array range to copy. |
Returns
Type | Description |
---|---|
ByteString | A byte string representation of array of bytes. |
CopyFrom(byte[])
Creates a new ByteString by copying a provided byte array.
Declaration
public static ByteString CopyFrom(byte[] array)
Parameters
Type | Name | Description |
---|---|---|
byte[] | array | Array of bytes to copy |
Returns
Type | Description |
---|---|
ByteString | A byte string representation of array of bytes. |
CopyFrom(byte[], int, int)
Creates a new ByteString by copying a byte array.
Declaration
public static ByteString CopyFrom(byte[] array, int offset, int count)
Parameters
Type | Name | Description |
---|---|---|
byte[] | array | Array of bytes to copy |
int | offset | Index in provided |
int | count | Number of bytes to copy. |
Returns
Type | Description |
---|---|
ByteString | TBD |
CopyFrom(IEnumerable<ArraySegment<byte>>)
Creates a new ByteString by copying segments of bytes.
Declaration
public static ByteString CopyFrom(IEnumerable<ArraySegment<byte>> buffers)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<ArraySegment<byte>> | buffers |
Returns
Type | Description |
---|---|
ByteString |
CopyFrom(Memory<byte>)
Creates a new ByteString by copying a Memory<T>.
Declaration
public static ByteString CopyFrom(Memory<byte> memory)
Parameters
Type | Name | Description |
---|---|---|
Memory<byte> | memory | The Memory<T> to copy |
Returns
Type | Description |
---|---|
ByteString | The new ByteString |
CopyFrom(Memory<byte>, int, int)
Creates a new ByteString by copying a Memory<T>.
Declaration
public static ByteString CopyFrom(Memory<byte> memory, int offset, int count)
Parameters
Type | Name | Description |
---|---|---|
Memory<byte> | memory | The Memory<T> to copy |
int | offset | Index in provided |
int | count | Number of bytes to copy. |
Returns
Type | Description |
---|---|
ByteString | The new ByteString |
CopyFrom(Span<byte>)
Creates a new ByteString by copying a Span<T>.
Declaration
public static ByteString CopyFrom(Span<byte> span)
Parameters
Type | Name | Description |
---|---|---|
Span<byte> | span | The Span<T> to copy |
Returns
Type | Description |
---|---|
ByteString | The new ByteString |
CopyFrom(Span<byte>, int, int)
Creates a new ByteString by copying a Span<T>.
Declaration
public static ByteString CopyFrom(Span<byte> span, int offset, int count)
Parameters
Type | Name | Description |
---|---|---|
Span<byte> | span | The Span<T> to copy |
int | offset | Index in provided |
int | count | Number of bytes to copy. |
Returns
Type | Description |
---|---|
ByteString | The new ByteString |
CopyTo(byte[], int, int)
Copies content of a current ByteString into a provided
buffer
starting from index
in that
buffer and copying a count
number of bytes.
Declaration
public int CopyTo(byte[] buffer, int index, int count)
Parameters
Type | Name | Description |
---|---|---|
byte[] | buffer | |
int | index | |
int | count |
Returns
Type | Description |
---|---|
int | TBD |
CopyTo(ref Memory<byte>)
Copies content of a current ByteString into a provided Memory<T>
buffer
Declaration
public int CopyTo(ref Memory<byte> buffer)
Parameters
Type | Name | Description |
---|---|---|
Memory<byte> | buffer |
Returns
Type | Description |
---|---|
int | The number of bytes copied |
CopyTo(ref Memory<byte>, int, int)
Copies content of a current ByteString into a provided Memory<T>
buffer
starting from index
in that
buffer and copying a count
number of bytes.
Declaration
public int CopyTo(ref Memory<byte> buffer, int index, int count)
Parameters
Type | Name | Description |
---|---|---|
Memory<byte> | buffer | |
int | index | |
int | count |
Returns
Type | Description |
---|---|
int | The number of bytes copied |
CopyTo(ref Span<byte>)
Copies content of a current ByteString into a provided Span<T>
buffer
.
Declaration
public int CopyTo(ref Span<byte> buffer)
Parameters
Type | Name | Description |
---|---|---|
Span<byte> | buffer |
Returns
Type | Description |
---|---|
int | The number of bytes copied |
CopyTo(ref Span<byte>, int, int)
Copies content of a current ByteString into a provided Span<T>
buffer
starting from index
in that
buffer and copying a count
number of bytes.
Declaration
public int CopyTo(ref Span<byte> buffer, int index, int count)
Parameters
Type | Name | Description |
---|---|---|
Span<byte> | buffer | |
int | index | |
int | count |
Returns
Type | Description |
---|---|
int | The number of bytes copied |
Equals(ByteString)
Declaration
public bool Equals(ByteString other)
Parameters
Type | Name | Description |
---|---|---|
ByteString | other |
Returns
Type | Description |
---|---|
bool |
Equals(object)
Declaration
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
object | obj |
Returns
Type | Description |
---|---|
bool |
Overrides
| Edit this page View SourceFromBytes(ArraySegment<byte>)
Creates a new ByteString by wrapping raw range over array of bytes. WARNING: this method doesn't copy underlying array, but expects that represented range should not be modified once attached to byte string.
Declaration
public static ByteString FromBytes(ArraySegment<byte> buffer)
Parameters
Type | Name | Description |
---|---|---|
ArraySegment<byte> | buffer | TBD |
Returns
Type | Description |
---|---|
ByteString | TBD |
FromBytes(byte[])
Creates a new ByteString by wrapping raw array of bytes. WARNING: this method doesn't copy underlying array, but expects that it should not be modified once attached to byte string.
Declaration
public static ByteString FromBytes(byte[] array)
Parameters
Type | Name | Description |
---|---|---|
byte[] | array | TBD |
Returns
Type | Description |
---|---|
ByteString | TBD |
FromBytes(byte[], int, int)
Creates a new ByteString by wrapping raw range over array of bytes. WARNING: this method doesn't copy underlying array, but expects that represented range should not be modified once attached to byte string.
Declaration
public static ByteString FromBytes(byte[] array, int offset, int count)
Parameters
Type | Name | Description |
---|---|---|
byte[] | array | TBD |
int | offset | TBD |
int | count | TBD |
Returns
Type | Description |
---|---|
ByteString | TBD |
FromBytes(IEnumerable<ArraySegment<byte>>)
Creates a new ByteString by wrapping raw collection of byte segements. WARNING: this method doesn't copy underlying arrays, but expects that represented range should not be modified once attached to byte string.
Declaration
public static ByteString FromBytes(IEnumerable<ArraySegment<byte>> buffers)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<ArraySegment<byte>> | buffers |
Returns
Type | Description |
---|---|
ByteString |
FromString(string)
Creates a new ByteString which will contain the UTF-8 representation of the given String
Declaration
public static ByteString FromString(string str)
Parameters
Type | Name | Description |
---|---|---|
string | str | TBD |
Returns
Type | Description |
---|---|
ByteString | TBD |
FromString(string, Encoding)
Creates a new ByteString which will contain the representation of the given String in the given charset encoding.
Declaration
public static ByteString FromString(string str, Encoding encoding)
Parameters
Type | Name | Description |
---|---|---|
string | str | TBD |
Encoding | encoding | TBD |
Returns
Type | Description |
---|---|
ByteString | TBD |
GetEnumerator()
Declaration
public IEnumerator<byte> GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator<byte> |
GetHashCode()
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
int |
Overrides
| Edit this page View SourceHasSubstring(ByteString, int)
Checks if a subsequence determined by the other
byte string is can be found in current one, starting from provided
index
.
Declaration
public bool HasSubstring(ByteString other, int index)
Parameters
Type | Name | Description |
---|---|---|
ByteString | other | |
int | index |
Returns
Type | Description |
---|---|
bool |
IndexOf(byte)
Returns an index of the first occurence of provided byte starting from the beginning of the ByteString.
Declaration
public int IndexOf(byte b)
Parameters
Type | Name | Description |
---|---|---|
byte | b |
Returns
Type | Description |
---|---|
int |
IndexOf(byte, int)
Returns an index of the first occurence of provided byte starting from the provided index.
Declaration
public int IndexOf(byte b, int from)
Parameters
Type | Name | Description |
---|---|---|
byte | b | |
int | from |
Returns
Type | Description |
---|---|
int |
Slice(int)
Slices current ByteString, creating a new ByteString which contains a specified range of data from the original. This is non-copying operation.
Declaration
public ByteString Slice(int index)
Parameters
Type | Name | Description |
---|---|---|
int | index | index inside current ByteString, from which slicing should start |
Returns
Type | Description |
---|---|
ByteString |
Slice(int, int)
Slices current ByteString, creating a new ByteString which contains a specified range of data from the original. This is non-copying operation.
Declaration
public ByteString Slice(int index, int count)
Parameters
Type | Name | Description |
---|---|---|
int | index | index inside current ByteString, from which slicing should start |
int | count | Number of bytes to fit into new ByteString. |
Returns
Type | Description |
---|---|
ByteString |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | If index or count result in an invalid ByteString. |
ToArray()
Copies content of a current ByteString into a single byte array.
Declaration
public byte[] ToArray()
Returns
Type | Description |
---|---|
byte[] | TBD |
ToReadOnlySpan()
Returns a ReadOnlySpan
Declaration
public ReadOnlySpan<byte> ToReadOnlySpan()
Returns
Type | Description |
---|---|
ReadOnlySpan<byte> | A ReadOnlySpan |
ToString()
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
string |
Overrides
| Edit this page View SourceToString(Encoding)
Declaration
public string ToString(Encoding encoding)
Parameters
Type | Name | Description |
---|---|---|
Encoding | encoding |
Returns
Type | Description |
---|---|
string |
WriteTo(Stream)
Copies content of the current ByteString to a provided
writeable stream
.
Declaration
public void WriteTo(Stream stream)
Parameters
Type | Name | Description |
---|---|---|
Stream | stream |
WriteToAsync(Stream)
Asynchronously copies content of the current ByteString
to a provided writeable stream
.
Declaration
public Task WriteToAsync(Stream stream)
Parameters
Type | Name | Description |
---|---|---|
Stream | stream |
Returns
Type | Description |
---|---|
Task |
Operators
| Edit this page View Sourceoperator +(ByteString, ByteString)
Declaration
public static ByteString operator +(ByteString x, ByteString y)
Parameters
Type | Name | Description |
---|---|---|
ByteString | x | |
ByteString | y |
Returns
Type | Description |
---|---|
ByteString |
operator ==(ByteString, ByteString)
Declaration
public static bool operator ==(ByteString x, ByteString y)
Parameters
Type | Name | Description |
---|---|---|
ByteString | x | |
ByteString | y |
Returns
Type | Description |
---|---|
bool |
explicit operator byte[](ByteString)
Declaration
public static explicit operator byte[](ByteString byteString)
Parameters
Type | Name | Description |
---|---|---|
ByteString | byteString |
Returns
Type | Description |
---|---|
byte[] |
explicit operator ByteString(byte[])
Declaration
public static explicit operator ByteString(byte[] bytes)
Parameters
Type | Name | Description |
---|---|---|
byte[] | bytes |
Returns
Type | Description |
---|---|
ByteString |
operator !=(ByteString, ByteString)
Declaration
public static bool operator !=(ByteString x, ByteString y)
Parameters
Type | Name | Description |
---|---|---|
ByteString | x | |
ByteString | y |
Returns
Type | Description |
---|---|
bool |