net.consensys.cava.bytes.Bytes.get()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(6.8k)|赞(0)|评价(0)|浏览(143)

本文整理了Java中net.consensys.cava.bytes.Bytes.get()方法的一些代码示例,展示了Bytes.get()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bytes.get()方法的具体详情如下:
包路径:net.consensys.cava.bytes.Bytes
类名称:Bytes
方法名:get

Bytes.get介绍

[英]Retrieve a byte in this value.
[中]检索此值中的一个字节。

代码示例

代码示例来源:origin: net.consensys.cava/cava-bytes

@Override
public byte get(int i) {
 return delegate.get(i);
}

代码示例来源:origin: net.consensys.cava/cava-bytes

/**
 * Update the provided message digest with the bytes of this value.
 *
 * @param digest The digest to update.
 */
default void update(MessageDigest digest) {
 checkNotNull(digest);
 for (int i = 0; i < size(); i++) {
  digest.update(get(i));
 }
}

代码示例来源:origin: net.consensys.cava/cava-bytes

/**
 * Whether the bytes start with a zero bit value.
 *
 * @return true if the first bit equals zero
 */
default boolean hasLeadingZero() {
 return size() > 0 && (get(0) & 0x80) == 0;
}

代码示例来源:origin: net.consensys.cava/cava-bytes

/**
 * Whether the bytes start with a zero byte value.
 *
 * @return true if the first byte equals zero
 */
default boolean hasLeadingZeroByte() {
 return size() > 0 && get(0) == 0;
}

代码示例来源:origin: net.consensys.cava/cava-bytes

/**
 * @return The number of leading zero bytes of the value.
 */
default int numberOfLeadingZeroBytes() {
 int size = size();
 for (int i = 0; i < size; i++) {
  if (get(i) != 0) {
   return i - 1;
  }
 }
 return size;
}

代码示例来源:origin: net.consensys.cava/cava-bytes

/**
 * @return The number of bits following and including the highest-order ("leftmost") one-bit, or zero if all bits are
 *         zero.
 */
default int bitLength() {
 int size = size();
 for (int i = 0; i < size; i++) {
  byte b = get(i);
  if (b == 0)
   continue;
  return (size * 8) - (i * 8) - (Integer.numberOfLeadingZeros(b & 0xFF) - 3 * 8);
 }
 return 0;
}

代码示例来源:origin: net.consensys.cava/cava-bytes

/**
 * Whether this value has only zero bytes.
 *
 * @return {@code true} if all the bits of this value are zeros.
 */
default boolean isZero() {
 for (int i = size() - 1; i >= 0; --i) {
  if (get(i) != 0)
   return false;
 }
 return true;
}

代码示例来源:origin: net.consensys.cava/cava-bytes

/**
 * Append the bytes of this value to the {@link ByteBuffer}.
 *
 * @param byteBuffer The {@link ByteBuffer} to which to append this value.
 * @throws BufferOverflowException If the writer attempts to write more than the provided buffer can hold.
 * @throws ReadOnlyBufferException If the provided buffer is read-only.
 */
default void appendTo(ByteBuffer byteBuffer) {
 checkNotNull(byteBuffer);
 for (int i = 0; i < size(); i++) {
  byteBuffer.put(get(i));
 }
}

代码示例来源:origin: net.consensys.cava/cava-bytes

/**
 * Extract the bytes of this value into a byte array.
 *
 * @return A byte array with the same content than this value.
 */
default byte[] toArray() {
 int size = size();
 byte[] array = new byte[size];
 for (int i = 0; i < size; i++) {
  array[i] = get(i);
 }
 return array;
}

代码示例来源:origin: net.consensys.cava/cava-bytes

/**
 * @return The number of zero bits preceding the highest-order ("leftmost") one-bit, or {@code size() * 8} if all bits
 *         are zero.
 */
default int numberOfLeadingZeros() {
 int size = size();
 for (int i = 0; i < size; i++) {
  byte b = get(i);
  if (b == 0) {
   continue;
  }
  return (i * 8) + Integer.numberOfLeadingZeros(b & 0xFF) - 3 * 8;
 }
 return size * 8;
}

代码示例来源:origin: net.consensys.cava/cava-bytes

/**
 * Return the number of bytes in common between this set of bytes and another.
 *
 * @param other The bytes to compare to.
 * @return The number of common bytes.
 */
default int commonPrefixLength(Bytes other) {
 checkNotNull(other);
 int ourSize = size();
 int otherSize = other.size();
 int i = 0;
 while (i < ourSize && i < otherSize && get(i) == other.get(i)) {
  i++;
 }
 return i;
}

代码示例来源:origin: net.consensys.cava/cava-bytes

/**
 * Append this value as a sequence of hexadecimal characters.
 *
 * @param appendable The appendable
 * @param <T> The appendable type.
 * @return The appendable.
 * @throws IOException If an IO error occurs.
 */
default <T extends Appendable> T appendHexTo(T appendable) throws IOException {
 int size = size();
 for (int i = 0; i < size; i++) {
  byte b = get(i);
  appendable.append(AbstractBytes.HEX_CODE[b >> 4 & 15]);
  appendable.append(AbstractBytes.HEX_CODE[b & 15]);
 }
 return appendable;
}

代码示例来源:origin: net.consensys.cava/cava-bytes

@Override
public byte get(int i) {
 checkElementIndex(i, size);
 for (Bytes value : values) {
  int vSize = value.size();
  if (i < vSize) {
   return value.get(i);
  }
  i -= vSize;
 }
 throw new IllegalStateException("element sizes do not match total size");
}

代码示例来源:origin: net.consensys.cava/cava-bytes

/**
 * Append the bytes of this value to the provided Vert.x {@link Buffer}.
 *
 * <p>
 * Note that since a Vert.x {@link Buffer} will grow as necessary, this method never fails.
 *
 * @param buffer The {@link Buffer} to which to append this value.
 */
default void appendTo(Buffer buffer) {
 checkNotNull(buffer);
 for (int i = 0; i < size(); i++) {
  buffer.appendByte(get(i));
 }
}

代码示例来源:origin: net.consensys.cava/cava-rlp

@Override
public boolean nextIsList() {
 int remaining = content.size() - index;
 if (remaining == 0) {
  throw new EndOfRLPException();
 }
 int prefix = (((int) content.get(index)) & 0xFF);
 return prefix > 0xbf;
}

代码示例来源:origin: net.consensys.cava/cava-rlp

@Override
public boolean nextIsEmpty() {
 int remaining = content.size() - index;
 if (remaining == 0) {
  throw new EndOfRLPException();
 }
 int prefix = (((int) content.get(index)) & 0xFF);
 return prefix == 0x80;
}

代码示例来源:origin: net.consensys.cava/cava-bytes

/**
 * Return a slice of representing the same value but without any leading zero bytes.
 *
 * @return {@code value} if its left-most byte is non zero, or a slice that exclude any leading zero bytes.
 */
default Bytes trimLeadingZeros() {
 int size = size();
 for (int i = 0; i < size; i++) {
  if (get(i) != 0) {
   return slice(i);
  }
 }
 return Bytes.EMPTY;
}

代码示例来源:origin: net.consensys.cava/cava-bytes

/**
 * Calculate a bit-wise NOT of these bytes.
 *
 * <p>
 * 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.
 *
 * @param result The mutable output vector for the result.
 * @param <T> The {@link MutableBytes} value type.
 * @return The {@code result} output vector.
 */
default <T extends MutableBytes> T not(T result) {
 checkNotNull(result);
 int rSize = result.size();
 int offsetSelf = rSize - size();
 for (int i = 0; i < rSize; i++) {
  byte b1 = (i < offsetSelf) ? 0x00 : get(i - offsetSelf);
  result.set(i, (byte) ~b1);
 }
 return result;
}

代码示例来源:origin: net.consensys.cava/cava-rlp

/**
 * Read a byte from the RLP source.
 *
 * @param lenient If {@code false}, an exception will be thrown if the byte is not minimally encoded.
 * @return The byte for the next value.
 * @throws InvalidRLPEncodingException If there is an error decoding the RLP source.
 * @throws EndOfRLPException If there are no more RLP values to read.
 */
default byte readByte(boolean lenient) {
 Bytes bytes = readValue(lenient);
 if (bytes.size() != 1) {
  throw new InvalidRLPTypeException("Value is not a single byte");
 }
 return bytes.get(0);
}

代码示例来源:origin: net.consensys.cava/cava-rlpx

static Bytes decryptMessage(Bytes msgBytes, SecretKey ourKey) {
 Bytes commonMac = msgBytes.slice(0, 2);
 int size = (commonMac.get(1) & 0xFF) + ((commonMac.get(0) & 0xFF) << 8);
 PublicKey ephemeralPublicKey = PublicKey.fromBytes(msgBytes.slice(3, 64));
 Bytes iv = msgBytes.slice(67, 16);
 Bytes encrypted = msgBytes.slice(83, size - 81);
 EthereumIESEncryptionEngine decryptor = forDecryption(ourKey, ephemeralPublicKey, iv, commonMac);
 byte[] result;
 try {
  result = decryptor.processBlock(encrypted.toArrayUnsafe(), 0, encrypted.size());
 } catch (InvalidCipherTextException e) {
  throw new InvalidMACException(e);
 }
 return Bytes.wrap(result);
}

相关文章

微信公众号

最新文章

更多