tuweni / org.apache.tuweni.bytes / Bytes32

Bytes32

interface Bytes32 : Bytes (source)

A Bytes value that is guaranteed to contain exactly 32 bytes.

Properties

SIZE

static val SIZE: Int

The number of bytes in this value - i.e. 32

ZERO

static val ZERO: Bytes32

A Bytes32 containing all zero bytes

Inherited Properties

EMPTY

static val EMPTY: Bytes

The empty value (with 0 bytes).

Functions

and

open fun and(other: Bytes32): Bytes32

Return a bit-wise AND of these bytes and the supplied bytes.

copy

abstract fun copy(): Bytes32

fromHexString

open static fun fromHexString(str: CharSequence): Bytes32

Parse a hexadecimal string into a Bytes32.

This method is strict in that str must of an even length.

fromHexStringLenient

open static fun fromHexStringLenient(str: CharSequence): Bytes32

Parse a hexadecimal string into a Bytes32.

This method is lenient in that str may of an odd length, in which case it will behave exactly as if it had an additional 0 in front.

fromHexStringStrict

open static fun fromHexStringStrict(str: CharSequence): Bytes32

Parse a hexadecimal string into a Bytes32.

This method is extra strict in that str must of an even length and the provided representation must have exactly 32 bytes.

leftPad

open static fun leftPad(value: Bytes): Bytes32

Left pad a Bytes value with zero bytes to create a Bytes32.

mutableCopy

abstract fun mutableCopy(): MutableBytes32

not

open fun not(): Bytes32

or

open fun or(other: Bytes32): Bytes32

Return a bit-wise OR of these bytes and the supplied bytes.

random

open static fun random(): Bytes32
open static fun random(generator: Random): Bytes32

Generate random bytes.

rightPad

open static fun rightPad(value: Bytes): Bytes32

Right pad a Bytes value with zero bytes to create a Bytes32.

shiftLeft

open fun shiftLeft(distance: Int): Bytes32

shiftRight

open fun shiftRight(distance: Int): Bytes32

size

open fun size(): Int

wrap

open static fun wrap(bytes: ByteArray): Bytes32

Wrap the provided byte array, which must be of length 32, as a Bytes32.

Note that value is not copied, only wrapped, and thus any future update to value will be reflected in the returned value.

open static fun wrap(bytes: ByteArray, offset: Int): Bytes32

Wrap a slice/sub-part of the provided array as a Bytes32.

Note that value is not copied, only wrapped, and thus any future update to value within the wrapped parts will be reflected in the returned value.

open static fun wrap(value: Bytes): Bytes32

Wrap a the provided value, which must be of size 32, as a Bytes32.

Note that value is not copied, only wrapped, and thus any future update to value will be reflected in the returned value.

open static fun wrap(value: Bytes, offset: Int): Bytes32

Wrap a slice/sub-part of the provided value as a Bytes32.

Note that value is not copied, only wrapped, and thus any future update to value within the wrapped parts will be reflected in the returned value.

xor

open fun xor(other: Bytes32): Bytes32

Return a bit-wise XOR of these bytes and the supplied bytes.

Inherited Functions

and

open fun and(other: Bytes): Bytes

Return a bit-wise AND of these bytes and the supplied bytes. If this value and the supplied value are different lengths, then the shorter will be zero-padded to the left.

open fun <T : MutableBytes> and(other: Bytes, result: T): T

Calculate a bit-wise AND of these bytes and the supplied bytes.

If this value or the supplied value are shorter in length than the output vector, then they will be zero-padded to the left. Likewise, if either this value or the supplied valid is longer in length than the output vector, then they will be truncated to the left.

appendHexTo

open fun <T : Appendable> appendHexTo(appendable: T): T

Append this value as a sequence of hexadecimal characters.

appendTo

open fun appendTo(byteBuffer: ByteBuffer): Unit

Append the bytes of this value to the ByteBuffer.

open fun appendTo(buffer: Buffer): Unit

Append the bytes of this value to the provided Vert.x Buffer.

Note that since a Vert.x Buffer will grow as necessary, this method never fails.

bitLength

open fun bitLength(): Int

commonPrefix

open fun commonPrefix(other: Bytes): Bytes

Return a slice over the common prefix between this set of bytes and another.

commonPrefixLength

open fun commonPrefixLength(other: Bytes): Int

Return the number of bytes in common between this set of bytes and another.

copyTo

open fun copyTo(destination: MutableBytes): Unit

Copy the bytes of this value to the provided mutable one, which must have the same size.

open fun copyTo(destination: MutableBytes, destinationOffset: Int): Unit

Copy the bytes of this value to the provided mutable one from a particular offset.

This is a (potentially slightly more efficient) shortcut for copyTo(destination.mutableSlice(destinationOffset, this.size())).

get

abstract fun get(i: Int): Byte

Retrieve a byte in this value.

getInt

open fun getInt(i: Int): Int
open fun getInt(i: Int, order: ByteOrder): Int

Retrieve the 4 bytes starting at the provided index in this value as an integer.

getLong

open fun getLong(i: Int): Long
open fun getLong(i: Int, order: ByteOrder): Long

Retrieves the 8 bytes starting at the provided index in this value as a long.

hasLeadingZero

open fun hasLeadingZero(): Boolean

Whether the bytes start with a zero bit value.

hasLeadingZeroByte

open fun hasLeadingZeroByte(): Boolean

Whether the bytes start with a zero byte value.

isEmpty

open fun isEmpty(): Boolean

Whether this value contains no bytes.

isZero

open fun isZero(): Boolean

Whether this value has only zero bytes.

not

open fun <T : MutableBytes> not(result: T): T

Calculate a bit-wise NOT of these bytes.

If this value is shorter in length than the output vector, then it will be zero-padded to the left. Likewise, if this value is longer in length than the output vector, then it will be truncated to the left.

numberOfLeadingZeroBytes

open fun numberOfLeadingZeroBytes(): Int

numberOfLeadingZeros

open fun numberOfLeadingZeros(): Int

numberOfTrailingZeroBytes

open fun numberOfTrailingZeroBytes(): Int

or

open fun or(other: Bytes): Bytes

Return a bit-wise OR of these bytes and the supplied bytes.

If this value and the supplied value are different lengths, then the shorter will be zero-padded to the left.

open fun <T : MutableBytes> or(other: Bytes, result: T): T

Calculate a bit-wise OR of these bytes and the supplied bytes.

If this value or the supplied value are shorter in length than the output vector, then they will be zero-padded to the left. Likewise, if either this value or the supplied valid is longer in length than the output vector, then they will be truncated to the left.

reverse

open fun reverse(): Bytes

Computes the reverse array of bytes of the current bytes.

shiftLeft

open fun <T : MutableBytes> shiftLeft(distance: Int, result: T): T

Shift all bits in this value to the left.

If this value is shorter in length than the output vector, then it will be zero-padded to the left. Likewise, if this value is longer in length than the output vector, then it will be truncated to the left.

shiftRight

open fun <T : MutableBytes> shiftRight(distance: Int, result: T): T

Shift all bits in this value to the right.

If this value is shorter in length than the output vector, then it will be zero-padded to the left. Likewise, if this value is longer in length than the output vector, then it will be truncated to the left (after shifting).

slice

open fun slice(i: Int): Bytes
abstract fun slice(i: Int, length: Int): Bytes

Create a new value representing (a view of) a slice of the bytes of this value.

Please note that the resulting slice is only a view and as such maintains a link to the underlying full value. So holding a reference to the returned slice may hold more memory than the slide represents. Use #copy on the returned slice if that is not what you want.

toArray

open fun toArray(): ByteArray

Extract the bytes of this value into a byte array.

toArrayUnsafe

open fun toArrayUnsafe(): ByteArray

Get the bytes represented by this value as byte array.

Contrarily to #toArray(), this may avoid allocating a new array and directly return the backing array of this value if said value is array backed and doing so is possible. As such, modifications to the returned array may or may not impact this value. As such, this method should be used with care and hence the "unsafe" moniker.

toBase64String

open fun toBase64String(): String

toBigInteger

open fun toBigInteger(): BigInteger
open fun toBigInteger(order: ByteOrder): BigInteger

The BigInteger corresponding to interpreting these bytes as a two's-complement signed integer.

toHexString

open fun toHexString(): String

toInt

open fun toInt(): Int
open fun toInt(order: ByteOrder): Int

The value corresponding to interpreting these bytes as an integer.

toLong

open fun toLong(): Long
open fun toLong(order: ByteOrder): Long

The value corresponding to interpreting these bytes as a long.

toShortHexString

open fun toShortHexString(): String

toUnsignedBigInteger

open fun toUnsignedBigInteger(): BigInteger
open fun toUnsignedBigInteger(order: ByteOrder): BigInteger

The BigInteger corresponding to interpreting these bytes as an unsigned integer.

trimLeadingZeros

open fun trimLeadingZeros(): Bytes

Return a slice of representing the same value but without any leading zero bytes.

update

open fun update(digest: MessageDigest): Unit

Update the provided message digest with the bytes of this value.

xor

open fun xor(other: Bytes): Bytes

Return a bit-wise XOR of these bytes and the supplied bytes.

If this value and the supplied value are different lengths, then the shorter will be zero-padded to the left.

open fun <T : MutableBytes> xor(other: Bytes, result: T): T

Calculate a bit-wise XOR of these bytes and the supplied bytes.

If this value or the supplied value are shorter in length than the output vector, then they will be zero-padded to the left. Likewise, if either this value or the supplied valid is longer in length than the output vector, then they will be truncated to the left.

Inheritors

MutableBytes32

interface MutableBytes32 : MutableBytes, Bytes32

A mutable Bytes32, that is a mutable Bytes value of exactly 32 bytes.