本文整理了Java中net.consensys.cava.bytes.Bytes.toLong()
方法的一些代码示例,展示了Bytes.toLong()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bytes.toLong()
方法的具体详情如下:
包路径:net.consensys.cava.bytes.Bytes
类名称:Bytes
方法名:toLong
[英]The value corresponding to interpreting these bytes as a long.
[中]对应于将这些字节解释为长字节的值。
代码示例来源:origin: net.consensys.cava/cava-bytes
@Override
public long toLong() {
return delegate.toLong();
}
代码示例来源:origin: net.consensys.cava/cava-ssz
private <T> List<T> readList(LongFunction<byte[]> bytesSupplier, Function<byte[], T> converter) {
ensureBytes(4, () -> "SSZ encoded data is not a list");
int originalIndex = this.index;
List<T> elements;
try {
// use a long to simulate reading unsigned
long listSize = consumeBytes(4).toLong();
elements = new ArrayList<>();
while (listSize > 0) {
byte[] bytes = bytesSupplier.apply(listSize);
elements.add(converter.apply(bytes));
listSize -= bytes.length;
if (listSize < 0) {
throw new InvalidSSZTypeException("SSZ encoded list length does not align with lengths of its elements");
}
}
} catch (Exception e) {
this.index = originalIndex;
throw e;
}
return elements;
}
代码示例来源:origin: net.consensys.cava/cava-ssz
@Override
public long readLong(int bitLength) {
checkArgument(bitLength % 8 == 0, "bitLength must be a multiple of 8");
int byteLength = bitLength / 8;
ensureBytes(byteLength, () -> "SSZ encoded data has insufficient length to read a " + bitLength + "-bit integer");
Bytes bytes = content.slice(index, byteLength);
int zeroBytes = content.numberOfLeadingZeroBytes();
if ((byteLength - zeroBytes) > 8) {
throw new InvalidSSZTypeException("decoded integer is too large for an int");
}
index += byteLength;
return bytes.slice(zeroBytes).toLong();
}
代码示例来源:origin: net.consensys.cava/cava-rlp
/**
* Read a long value from the RLP source.
*
* @param lenient If {@code false}, an exception will be thrown if the integer is not minimally encoded.
* @return A long.
* @throws InvalidRLPEncodingException If there is an error decoding the RLP source, or the integer is not minimally
* encoded and `lenient` is {@code false}.
* @throws InvalidRLPTypeException If the next RLP value cannot be represented as a long.
* @throws EndOfRLPException If there are no more RLP values to read.
*/
default long readLong(boolean lenient) {
Bytes bytes = readValue();
if (!lenient && bytes.hasLeadingZeroByte()) {
throw new InvalidRLPEncodingException("Integer value was not minimally encoded");
}
try {
return bytes.toLong();
} catch (IllegalArgumentException e) {
throw new InvalidRLPTypeException("Value is too large to be represented as a long");
}
}
内容来源于网络,如有侵权,请联系作者删除!