Interface Bytes48

All Superinterfaces:
Bytes, Comparable<Bytes>
All Known Subinterfaces:
MutableBytes48
All Known Implementing Classes:
DelegatingBytes48

public interface Bytes48 extends Bytes
A Bytes value that is guaranteed to contain exactly 48 bytes.
  • Field Details

    • SIZE

      static final int SIZE
      The number of bytes in this value - i.e. 48
      See Also:
    • ZERO

      static final Bytes48 ZERO
      A Bytes48 containing all zero bytes
  • Method Details

    • wrap

      static Bytes48 wrap(byte[] bytes)
      Wrap the provided byte array, which must be of length 48, as a Bytes48.

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

      Parameters:
      bytes - The bytes to wrap.
      Returns:
      A Bytes48 wrapping value.
      Throws:
      IllegalArgumentException - if value.length != 48.
    • wrap

      static Bytes48 wrap(byte[] bytes, int offset)
      Wrap a slice/sub-part of the provided array as a Bytes48.

      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.

      Parameters:
      bytes - The bytes to wrap.
      offset - The index (inclusive) in value of the first byte exposed by the returned value. In other words, you will have wrap(value, i).get(0) == value[i].
      Returns:
      A Bytes48 that exposes the bytes of value from offset (inclusive) to offset + 48 (exclusive).
      Throws:
      IndexOutOfBoundsException - if offset < 0 || (value.length > 0 && offset >= value.length).
      IllegalArgumentException - if length < 0 || offset + 48 > value.length.
    • wrap

      static Bytes48 wrap(Bytes value)
      Wrap a the provided value, which must be of size 48, as a Bytes48.

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

      Parameters:
      value - The bytes to wrap.
      Returns:
      A Bytes48 that exposes the bytes of value.
      Throws:
      IllegalArgumentException - if value.size() != 48.
    • wrap

      static Bytes48 wrap(Bytes value, int offset)
      Wrap a slice/sub-part of the provided value as a Bytes48.

      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.

      Parameters:
      value - The bytes to wrap.
      offset - The index (inclusive) in value of the first byte exposed by the returned value. In other words, you will have wrap(value, i).get(0) == value.get(i).
      Returns:
      A Bytes48 that exposes the bytes of value from offset (inclusive) to offset + 48 (exclusive).
      Throws:
      IndexOutOfBoundsException - if offset < 0 || (value.size() > 0 && offset >= value.size()).
      IllegalArgumentException - if length < 0 || offset + 48 > value.size().
    • leftPad

      static Bytes48 leftPad(Bytes value)
      Left pad a Bytes value with zero bytes to create a Bytes48.
      Parameters:
      value - The bytes value pad.
      Returns:
      A Bytes48 that exposes the left-padded bytes of value.
      Throws:
      IllegalArgumentException - if value.size() > 48.
    • rightPad

      static Bytes48 rightPad(Bytes value)
      Right pad a Bytes value with zero bytes to create a Bytes48.
      Parameters:
      value - The bytes value pad.
      Returns:
      A Bytes48 that exposes the rightw-padded bytes of value.
      Throws:
      IllegalArgumentException - if value.size() > 48.
    • fromHexStringLenient

      static Bytes48 fromHexStringLenient(CharSequence str)
      Parse a hexadecimal string into a Bytes48.

      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.

      Parameters:
      str - The hexadecimal string to parse, which may or may not start with "0x". That representation may contain less than 48 bytes, in which case the result is left padded with zeros (see fromHexStringStrict(java.lang.CharSequence) if this is not what you want).
      Returns:
      The value corresponding to str.
      Throws:
      IllegalArgumentException - if str does not correspond to a valid hexadecimal representation or contains more than 48 bytes.
    • fromHexString

      static Bytes48 fromHexString(CharSequence str)
      Parse a hexadecimal string into a Bytes48.

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

      Parameters:
      str - The hexadecimal string to parse, which may or may not start with "0x". That representation may contain less than 48 bytes, in which case the result is left padded with zeros (see fromHexStringStrict(java.lang.CharSequence) if this is not what you want).
      Returns:
      The value corresponding to str.
      Throws:
      IllegalArgumentException - if str does not correspond to a valid hexadecimal representation, is of an odd length, or contains more than 48 bytes.
    • random

      static Bytes48 random()
      Generate random bytes.
      Returns:
      A value containing random bytes.
    • random

      static Bytes48 random(Random generator)
      Generate random bytes.
      Parameters:
      generator - The generator for random bytes.
      Returns:
      A value containing random bytes.
    • fromHexStringStrict

      static Bytes48 fromHexStringStrict(CharSequence str)
      Parse a hexadecimal string into a Bytes48.

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

      Parameters:
      str - The hexadecimal string to parse, which may or may not start with "0x".
      Returns:
      The value corresponding to str.
      Throws:
      IllegalArgumentException - if str does not correspond to a valid hexadecimal representation, is of an odd length or does not contain exactly 48 bytes.
    • size

      default int size()
      Description copied from interface: Bytes
      Provides the number of bytes this value represents.
      Specified by:
      size in interface Bytes
      Returns:
      The number of bytes this value represents.
    • and

      default Bytes48 and(Bytes48 other)
      Return a bit-wise AND of these bytes and the supplied bytes.
      Parameters:
      other - The bytes to perform the operation with.
      Returns:
      The result of a bit-wise AND.
    • or

      default Bytes48 or(Bytes48 other)
      Return a bit-wise OR of these bytes and the supplied bytes.
      Parameters:
      other - The bytes to perform the operation with.
      Returns:
      The result of a bit-wise OR.
    • xor

      default Bytes48 xor(Bytes48 other)
      Return a bit-wise XOR of these bytes and the supplied bytes.
      Parameters:
      other - The bytes to perform the operation with.
      Returns:
      The result of a bit-wise XOR.
    • not

      default Bytes48 not()
      Description copied from interface: Bytes
      Return a bit-wise NOT of these bytes.
      Specified by:
      not in interface Bytes
      Returns:
      The result of a bit-wise NOT.
    • shiftRight

      default Bytes48 shiftRight(int distance)
      Description copied from interface: Bytes
      Shift all bits in this value to the right.
      Specified by:
      shiftRight in interface Bytes
      Parameters:
      distance - The number of bits to shift by.
      Returns:
      A value containing the shifted bits.
    • shiftLeft

      default Bytes48 shiftLeft(int distance)
      Description copied from interface: Bytes
      Shift all bits in this value to the left.
      Specified by:
      shiftLeft in interface Bytes
      Parameters:
      distance - The number of bits to shift by.
      Returns:
      A value containing the shifted bits.
    • copy

      Bytes48 copy()
      Description copied from interface: Bytes
      Return a value equivalent to this one but guaranteed to 1) be deeply immutable (i.e. the underlying value will be immutable) and 2) to not retain more bytes than exposed by the value.
      Specified by:
      copy in interface Bytes
      Returns:
      A value, equals to this one, but deeply immutable and that doesn't retain any "unreachable" bytes. For performance reasons, this is allowed to return this value however if it already fit those constraints.
    • mutableCopy

      MutableBytes48 mutableCopy()
      Description copied from interface: Bytes
      Return a new mutable value initialized with the content of this value.
      Specified by:
      mutableCopy in interface Bytes
      Returns:
      A mutable copy of this value. This will copy bytes, modifying the returned value will not modify this value.