Show / Hide Table of Contents

Class ByteUtil

Utility methods to deal with arrays.

Inheritance
System.Object
ByteUtil
Namespace: Libplanet.Common
Assembly: Libplanet.Common.dll
Syntax
public static class ByteUtil : object

Methods

| Improve this Doc View Source

CalculateHashCode(Byte[])

Calculates a deterministic hash code from a given bytes. It is mostly used to implement method.

Declaration
public static int CalculateHashCode(byte[] bytes)
Parameters
Type Name Description
System.Byte[] bytes

A array, which completely determines (or encodes) an object, to calculate a hash code.

Returns
Type Description
System.Int32

A hash code determined from the given bytes. For equivalent bytes, the same hash code is returned. It must not be null.

| Improve this Doc View Source

Hex(in ImmutableArray<Byte>)

Renders a hexadecimal string in lowercase from a array.

Declaration
public static string Hex(in ImmutableArray<byte> bytes)
Parameters
Type Name Description
ImmutableArray<System.Byte> bytes

A array to renders the corresponding hexadecimal string.

Returns
Type Description
System.String

A hexadecimal string which encodes the given bytes.

See Also
Hex(Byte[])
ParseHexToImmutable(String)
| Improve this Doc View Source

Hex(Byte[])

Renders a hexadecimal string in lowercase from a array.

Declaration
public static string Hex(byte[] bytes)
Parameters
Type Name Description
System.Byte[] bytes

A array to renders the corresponding hexadecimal string.

Returns
Type Description
System.String

A hexadecimal string which encodes the given bytes.

See Also
Hex(in ImmutableArray<Byte>)
ParseHex(String)
| Improve this Doc View Source

ParseHex(String)

Converts a hexadecimal string to a mutable array.

Declaration
public static byte[] ParseHex(string hex)
Parameters
Type Name Description
System.String hex

A which encodes s in hexadecimal. Its length must be zero or an even number. It must not be null.

Returns
Type Description
System.Byte[]

A array that the given hex string represented in hexadecimal. It lengthens the half of the given hex string.

See Also
ParseHexToImmutable(String)
Hex(Byte[])
| Improve this Doc View Source

ParseHexToImmutable(String)

Converts a hexadecimal string to an immutable array.

Declaration
public static ImmutableArray<byte> ParseHexToImmutable(string hex)
Parameters
Type Name Description
System.String hex

A which encodes s in hexadecimal. Its length must be zero or an even number. It must not be null.

Returns
Type Description
ImmutableArray<System.Byte>

A array that the given hex string represented in hexadecimal.

See Also
ParseHex(String)
Hex(in ImmutableArray<Byte>)
| Improve this Doc View Source

Satisfies(IReadOnlyList<Byte>, Int64)

Tests if a hash digest is less than the target computed for the given difficulty).

Declaration
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 difficulty). If difficulty is 0 it always returns true.

| Improve this Doc View Source

TimingSafelyCompare(IReadOnlyList<Byte>, IReadOnlyList<Byte>)

Timing safe comparison of two byte arrays.

Declaration
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.

  • Improve this Doc
  • View Source
In This Article
Back to top Copyright © 2018–2023 Planetarium