Struct KeyBytes
Wraps a byte array and provides equality comparison and hash code calculation. Designed to be used as a key in dictionaries.
Namespace: Libplanet.Store.Trie
Assembly: Libplanet.dll
Syntax
public readonly struct KeyBytes : IEquatable<KeyBytes>, IEquatable<ImmutableArray<byte>>, IEquatable<byte[]>
Constructors
| Improve this Doc View SourceKeyBytes(in ImmutableArray<Byte>)
Creates a new KeyBytes instance from the given byte array.
Declaration
public KeyBytes(in ImmutableArray<byte> bytes)
Parameters
Type | Name | Description |
---|---|---|
ImmutableArray<Byte> | bytes | An immutable byte array to wrap. |
KeyBytes(Byte[])
Creates a new KeyBytes instance from the given byte array.
Declaration
public KeyBytes(params byte[] bytes)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | bytes | A mutable byte array to wrap. |
KeyBytes(String, Encoding)
Creates a new KeyBytes instance from the given string
.
Declaration
public KeyBytes(string string, Encoding encoding)
Parameters
Type | Name | Description |
---|---|---|
String | string | A key string. This is encoded to bytes. |
Encoding | encoding | The text encoding used for the key string. |
Properties
| Improve this Doc View SourceByteArray
The immutable array of bytes.
Declaration
public readonly ImmutableArray<byte> ByteArray { get; }
Property Value
Type | Description |
---|---|
ImmutableArray<Byte> |
Hex
The hexadecimal string representation of the byte array.
Declaration
public readonly string Hex { get; }
Property Value
Type | Description |
---|---|
String |
Length
The length of the byte array.
Declaration
public readonly int Length { get; }
Property Value
Type | Description |
---|---|
Int32 |
Methods
| Improve this Doc View SourceEquals(ImmutableArray<Byte>)
Declaration
public readonly bool Equals(ImmutableArray<byte> other)
Parameters
Type | Name | Description |
---|---|---|
ImmutableArray<Byte> | other |
Returns
Type | Description |
---|---|
Boolean |
Equals(KeyBytes)
Declaration
public readonly bool Equals(KeyBytes other)
Parameters
Type | Name | Description |
---|---|---|
KeyBytes | other |
Returns
Type | Description |
---|---|
Boolean |
Equals(Byte[])
Declaration
public readonly bool Equals(byte[] other)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | other |
Returns
Type | Description |
---|---|
Boolean |
Equals(Nullable<Object>)
Declaration
public override readonly bool Equals(object? obj)
Parameters
Type | Name | Description |
---|---|---|
Nullable<Object> | obj |
Returns
Type | Description |
---|---|
Boolean |
FromHex(String)
Parses the given hexadecimal string as bytes and returns a new KeyBytes instance.
Declaration
public static KeyBytes FromHex(string hex)
Parameters
Type | Name | Description |
---|---|---|
String | hex | A hexadecimal string which encodes bytes. |
Returns
Type | Description |
---|---|
KeyBytes | A new KeyBytes instance. |
GetHashCode()
Declaration
public override readonly int GetHashCode()
Returns
Type | Description |
---|---|
Int32 |
ToByteArray()
Converts to a mutable byte array.
Declaration
public readonly byte[] ToByteArray()
Returns
Type | Description |
---|---|
Byte[] | A new copy of mutable byte array. |
ToString()
Declaration
public override readonly string ToString()
Returns
Type | Description |
---|---|
String |
Operators
| Improve this Doc View SourceEquality(KeyBytes, KeyBytes)
Compares two KeyBytes values.
Declaration
public static bool operator ==(KeyBytes left, KeyBytes right)
Parameters
Type | Name | Description |
---|---|---|
KeyBytes | left | An operand. |
KeyBytes | right | Another operand. |
Returns
Type | Description |
---|---|
Boolean | true if two values equal; otherwise false. |
Inequality(KeyBytes, KeyBytes)
Compares two KeyBytes values.
Declaration
public static bool operator !=(KeyBytes left, KeyBytes right)
Parameters
Type | Name | Description |
---|---|---|
KeyBytes | left | An operand. |
KeyBytes | right | Another operand. |
Returns
Type | Description |
---|---|
Boolean | false if two values equal; otherwise true. |