Class ByteUtil
Utility methods to deal with System.Byte arrays.
Inherited Members
Namespace: Libplanet.Common
Assembly: Libplanet.Common.dll
Syntax
public static class ByteUtil
Methods
| Improve this Doc View SourceCalculateHashCode(Byte[])
Calculates a deterministic hash code from a given
bytes
. It is mostly used to implement
GetHashCode() method.
Declaration
[Pure]
public static int CalculateHashCode(byte[] bytes)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | bytes | A System.Byte array, which completely determines (or encodes) an object, to calculate a hash code. |
Returns
Type | Description |
---|---|
Int32 | A hash code determined from the given
|
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Thrown when the given
|
Hex(Byte[])
Renders a hexadecimal string in lowercase from a System.Byte array.
Declaration
[Pure]
public static string Hex(byte[] bytes)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | bytes | A System.Byte array to renders the corresponding hexadecimal string. |
Returns
Type | Description |
---|---|
String | A hexadecimal string which encodes the given
|
See Also
| Improve this Doc View SourceHex(in ImmutableArray<Byte>)
Renders a hexadecimal string in lowercase from a System.Byte array.
Declaration
[Pure]
public static string Hex(in ImmutableArray<byte> bytes)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Immutable.ImmutableArray<System.Byte> | bytes | A System.Byte array to renders the corresponding hexadecimal string. |
Returns
Type | Description |
---|---|
String | A hexadecimal string which encodes the given
|
See Also
| Improve this Doc View SourceParseHex(String)
Converts a hexadecimal string to a mutable System.Byte array.
Declaration
[Pure]
public static byte[] ParseHex(string hex)
Parameters
Type | Name | Description |
---|---|---|
String | hex | A String which encodes System.Bytes in hexadecimal. Its length must be zero or an even number. It must not be null. |
Returns
Type | Description |
---|---|
System.Byte[] | A System.Byte array that the given
|
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | Thrown when the length
of the given |
FormatException | Thrown when the given
|
See Also
| Improve this Doc View SourceParseHexToImmutable(String)
Converts a hexadecimal string to an immutable System.Byte array.
Declaration
[Pure]
public static ImmutableArray<byte> ParseHexToImmutable(string hex)
Parameters
Type | Name | Description |
---|---|---|
String | hex | A String which encodes System.Bytes in hexadecimal. Its length must be zero or an even number. It must not be null. |
Returns
Type | Description |
---|---|
System.Collections.Immutable.ImmutableArray<System.Byte> | A System.Byte array that the given |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Thrown when the given |
ArgumentOutOfRangeException | Thrown when the length of the given
|
FormatException | Thrown when the given |
See Also
| Improve this Doc View SourceSatisfies(IReadOnlyList<Byte>, Int64)
Tests if a hash digest is less than the target computed for the given
difficulty
).
Declaration
[Pure]
public static bool Satisfies(IReadOnlyList<byte> hashDigest, long difficulty)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyList<System.Byte> | hashDigest | A hash digest to test. |
System.Int64 | difficulty | The difficulty to compute target number. |
Returns
Type | Description |
---|---|
System.Boolean | true only if a digest is less than the target computed for
the given |
TimingSafelyCompare(IReadOnlyList<Byte>, IReadOnlyList<Byte>)
Timing safe comparison of two byte arrays.
Declaration
[Pure]
public static bool TimingSafelyCompare(IReadOnlyList<byte> left, IReadOnlyList<byte> right)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyList<System.Byte> | left | A byte array. |
IReadOnlyList<System.Byte> | right | Another byte array. |
Returns
Type | Description |
---|---|
System.Boolean | true iff two byte arrays have the exactly same contents. |
Remarks
In case of two byte arrays do not have the same length, it tries to keep the timing dependent on the length of the shorter one.