当前位置: 首页>>代码示例>>Java>>正文


Java ByteUtil.byteArrayToInt方法代码示例

本文整理汇总了Java中org.ethereum.util.ByteUtil.byteArrayToInt方法的典型用法代码示例。如果您正苦于以下问题:Java ByteUtil.byteArrayToInt方法的具体用法?Java ByteUtil.byteArrayToInt怎么用?Java ByteUtil.byteArrayToInt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.ethereum.util.ByteUtil的用法示例。


在下文中一共展示了ByteUtil.byteArrayToInt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parse

import org.ethereum.util.ByteUtil; //导入方法依赖的package包/类
private void parse() {
    RLPList paramsList = (RLPList) RLP.decode2(encoded).get(0);

    peers = new LinkedHashSet<>();
    for (int i = 1; i < paramsList.size(); ++i) {
        RLPList peerParams = (RLPList) paramsList.get(i);
        byte[] ipBytes = peerParams.get(0).getRLPData();
        byte[] portBytes = peerParams.get(1).getRLPData();
        byte[] peerIdRaw = peerParams.get(2).getRLPData();

        try {
            int peerPort = ByteUtil.byteArrayToInt(portBytes);
            InetAddress address = InetAddress.getByAddress(ipBytes);

            String peerId = peerIdRaw == null ? "" : Hex.toHexString(peerIdRaw);
            Peer peer = new Peer(address, peerPort, peerId);
            peers.add(peer);
        } catch (UnknownHostException e) {
            throw new RuntimeException("Malformed ip", e);
        }
    }
    this.parsed = true;
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:24,代码来源:PeersMessage.java

示例2: parse

import org.ethereum.util.ByteUtil; //导入方法依赖的package包/类
@Override
public void parse(byte[] data) {

    RLPList dataList = (RLPList) RLP.decode2OneItem(data, 0);

    RLPList fromList = (RLPList) dataList.get(1);
    byte[] ipF = fromList.get(0).getRLPData();
    this.fromHost = bytesToIp(ipF);
    this.fromPort = ByteUtil.byteArrayToInt(fromList.get(1).getRLPData());

    RLPList toList = (RLPList) dataList.get(2);
    byte[] ipT = toList.get(0).getRLPData();
    this.toHost = bytesToIp(ipT);
    this.toPort = ByteUtil.byteArrayToInt(toList.get(1).getRLPData());

    RLPItem expires = (RLPItem) dataList.get(3);
    this.expires = ByteUtil.byteArrayToLong(expires.getRLPData());

    this.version = ByteUtil.byteArrayToInt(dataList.get(0).getRLPData());
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:21,代码来源:PingMessage.java

示例3: parse

import org.ethereum.util.ByteUtil; //导入方法依赖的package包/类
@Override
public final void parse(byte[] data) {
    RLPList dataList = (RLPList) RLP.decode2OneItem(data, 0);
    RLPList fromList = (RLPList) dataList.get(1);
    RLPItem chk = (RLPItem) dataList.get(2);

    byte[] ipB = fromList.get(0).getRLPData();

    this.host = new String(ipB, Charset.forName("UTF-8"));
    this.port = ByteUtil.byteArrayToInt(fromList.get(1).getRLPData());
    this.messageId = new String(chk.getRLPData(), Charset.forName("UTF-8"));
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:13,代码来源:PingPeerMessage.java

示例4: parse

import org.ethereum.util.ByteUtil; //导入方法依赖的package包/类
@Override
public final void parse(byte[] data) {
    RLPList dataList = (RLPList) RLP.decode2OneItem(data, 0);
    RLPList fromList = (RLPList) dataList.get(1);

    byte[] ipB = fromList.get(0).getRLPData();
    this.host = new String(ipB, Charset.forName("UTF-8"));
    this.port = ByteUtil.byteArrayToInt(fromList.get(1).getRLPData());

    RLPItem chk = (RLPItem) dataList.get(2);

    this.messageId = new String(chk.getRLPData(), Charset.forName("UTF-8"));
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:14,代码来源:PongPeerMessage.java

示例5: parse

import org.ethereum.util.ByteUtil; //导入方法依赖的package包/类
protected void parse() {
    RLPList paramsList = (RLPList) RLP.decode2(encoded).get(0);

    this.protocolVersion = paramsList.get(0).getRLPData()[0];
    byte[] networkIdBytes = paramsList.get(1).getRLPData();
    this.networkId = networkIdBytes == null ? 0 : ByteUtil.byteArrayToInt(networkIdBytes);

    byte[] diff = paramsList.get(2).getRLPData();
    this.totalDifficulty = (diff == null) ? ZERO_BYTE_ARRAY : diff;
    this.bestHash = paramsList.get(3).getRLPData();
    this.genesisHash = paramsList.get(4).getRLPData();

    parsed = true;
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:15,代码来源:StatusMessage.java

示例6: decode

import org.ethereum.util.ByteUtil; //导入方法依赖的package包/类
static AuthInitiateMessageV4 decode(byte[] wire) {
    AuthInitiateMessageV4 message = new AuthInitiateMessageV4();

    RLPList params = (RLPList) RLP.decode2OneItem(wire, 0);

    byte[] signatureBytes = params.get(0).getRLPData();
    int offset = 0;
    byte[] r = new byte[32];
    byte[] s = new byte[32];
    System.arraycopy(signatureBytes, offset, r, 0, 32);
    offset += 32;
    System.arraycopy(signatureBytes, offset, s, 0, 32);
    offset += 32;
    int v = signatureBytes[offset] + 27;
    message.signature = ECKey.ECDSASignature.fromComponents(r, s, (byte)v);

    byte[] publicKeyBytes = params.get(1).getRLPData();
    byte[] bytes = new byte[65];
    System.arraycopy(publicKeyBytes, 0, bytes, 1, 64);
    bytes[0] = 0x04; // uncompressed
    message.publicKey = ECKey.CURVE.getCurve().decodePoint(bytes);

    message.nonce = params.get(2).getRLPData();

    byte[] versionBytes = params.get(3).getRLPData();
    message.version = ByteUtil.byteArrayToInt(versionBytes);

    return message;
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:30,代码来源:AuthInitiateMessageV4.java

示例7: parse

import org.ethereum.util.ByteUtil; //导入方法依赖的package包/类
private void parse() {
    RLPList paramsList = (RLPList) RLP.decode2(encoded).get(0);

    byte[] p2pVersionBytes = paramsList.get(0).getRLPData();
    this.p2pVersion = p2pVersionBytes != null ? p2pVersionBytes[0] : 0;

    byte[] clientIdBytes = paramsList.get(1).getRLPData();
    this.clientId = new String(clientIdBytes != null ? clientIdBytes : EMPTY_BYTE_ARRAY);

    RLPList capabilityList = (RLPList) paramsList.get(2);
    this.capabilities = new ArrayList<>();
    for (Object aCapabilityList : capabilityList) {

        RLPElement capId = ((RLPList) aCapabilityList).get(0);
        RLPElement capVersion = ((RLPList) aCapabilityList).get(1);

        String name = new String(capId.getRLPData());
        byte version = capVersion.getRLPData() == null ? 0 : capVersion.getRLPData()[0];

        Capability cap = new Capability(name, version);
        this.capabilities.add(cap);
    }

    byte[] peerPortBytes = paramsList.get(3).getRLPData();
    this.listenPort = ByteUtil.byteArrayToInt(peerPortBytes);

    byte[] peerIdBytes = paramsList.get(4).getRLPData();
    this.peerId = Hex.toHexString(peerIdBytes);
    this.parsed = true;
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:31,代码来源:HelloMessage.java

示例8: deserialize

import org.ethereum.util.ByteUtil; //导入方法依赖的package包/类
public static ProgramPrecompile deserialize(byte[] stream) {
    RLPList l = (RLPList) RLP.decode2(stream).get(0);
    int ver = ByteUtil.byteArrayToInt(l.get(0).getRLPData());
    if (ver != version) return null;
    ProgramPrecompile ret = new ProgramPrecompile();
    for (int i = 1; i < l.size(); i++) {
        ret.jumpdest.add(ByteUtil.byteArrayToInt(l.get(i).getRLPData()));
    }
    return ret;
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:11,代码来源:ProgramPrecompile.java

示例9: size

import org.ethereum.util.ByteUtil; //导入方法依赖的package包/类
@Override
public synchronized int size() {
    if (size < 0) {
        byte[] sizeBB = src.getSource().get(SIZE_KEY);
        size = sizeBB == null ? 0 : ByteUtil.byteArrayToInt(sizeBB);
    }
    return size;
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:9,代码来源:DataSourceArray.java

示例10: parse

import org.ethereum.util.ByteUtil; //导入方法依赖的package包/类
static PeerAddress parse(RLPList l) {
    PeerAddress ret = new PeerAddress();
    ret.ip = l.get(0).getRLPData();
    ret.port = ByteUtil.byteArrayToInt(l.get(1).getRLPData());
    ret.id = l.get(2).getRLPData();
    return ret;
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:8,代码来源:PeerAddress.java

示例11: parse

import org.ethereum.util.ByteUtil; //导入方法依赖的package包/类
protected synchronized void parse() {
    if (parsed) return;
    RLPList paramsList = (RLPList) RLP.decode2(encoded).get(0);

    this.protocolVersion = paramsList.get(0).getRLPData()[0];
    byte[] networkIdBytes = paramsList.get(1).getRLPData();
    this.networkId = networkIdBytes == null ? 0 : ByteUtil.byteArrayToInt(networkIdBytes);

    byte[] diff = paramsList.get(2).getRLPData();
    this.totalDifficulty = (diff == null) ? ByteUtil.ZERO_BYTE_ARRAY : diff;
    this.bestHash = paramsList.get(3).getRLPData();
    this.genesisHash = paramsList.get(4).getRLPData();

    parsed = true;
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:16,代码来源:StatusMessage.java

示例12: decode

import org.ethereum.util.ByteUtil; //导入方法依赖的package包/类
static AuthResponseMessageV4 decode(byte[] wire) {

        AuthResponseMessageV4 message = new AuthResponseMessageV4();

        RLPList params = (RLPList) RLP.decode2OneItem(wire, 0);

        byte[] pubKeyBytes = params.get(0).getRLPData();

        byte[] bytes = new byte[65];
        System.arraycopy(pubKeyBytes, 0, bytes, 1, 64);
        bytes[0] = 0x04; // uncompressed
        message.ephemeralPublicKey = ECKey.CURVE.getCurve().decodePoint(bytes);

        message.nonce = params.get(1).getRLPData();

        byte[] versionBytes = params.get(2).getRLPData();
        message.version = ByteUtil.byteArrayToInt(versionBytes);

        return message;
    }
 
开发者ID:rsksmart,项目名称:rskj,代码行数:21,代码来源:AuthResponseMessageV4.java

示例13: decodeCount

import org.ethereum.util.ByteUtil; //导入方法依赖的package包/类
/**
 * Extracts counter from the backing Source counter + value byte array
 */
protected int decodeCount(byte[] srcVal) {
    return srcVal == null ? 0 : ByteUtil.byteArrayToInt((byte[]) RLP.decode(srcVal, 0).getDecoded());
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:7,代码来源:CountingBytesSource.java

示例14: rlpDecodeInt

import org.ethereum.util.ByteUtil; //导入方法依赖的package包/类
public static int rlpDecodeInt(RLPElement elem) {
    byte[] b = elem.getRLPData();
    if (b == null) return 0;
    return ByteUtil.byteArrayToInt(b);
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:6,代码来源:Util.java

示例15: hashCode

import org.ethereum.util.ByteUtil; //导入方法依赖的package包/类
@Override
public int hashCode() {
    return ByteUtil.byteArrayToInt(getSender()) + ByteUtil.byteArrayToInt(transaction.getNonce());
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:5,代码来源:PendingTransaction.java


注:本文中的org.ethereum.util.ByteUtil.byteArrayToInt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。