public long readVarInt(int offset) throws NulsException { try { VarInt varint = new VarInt(payload, cursor + offset); cursor += offset + varint.getOriginalSizeInBytes(); return varint.value; } catch (ArrayIndexOutOfBoundsException e) { throw new NulsException(KernelErrorCode.DATA_PARSE_ERROR, e); } }
public static int sizeOfBytes(byte[] val) { if (null == val) { return 1; } return VarInt.sizeOf((val).length) + (val).length; }
public static Integer getIndex(byte[] fromBytes) { byte[] indexBytes = getIndexBytes(fromBytes); if(indexBytes != null) { VarInt varInt = new VarInt(indexBytes, 0); return Math.toIntExact(varInt.value); } return null; }
public static Integer getIndex(byte[] fromBytes) { byte[] indexBytes = getIndexBytes(fromBytes); if(indexBytes != null) { VarInt varInt = new VarInt(indexBytes, 0); return Math.toIntExact(varInt.value); } return null; } }
public static Integer getIndex(byte[] fromBytes) { byte[] indexBytes = getIndexBytes(fromBytes); if(indexBytes != null) { VarInt varInt = new VarInt(indexBytes, 0); return Math.toIntExact(varInt.value); } return null; }
public static byte[] getStateRoot(BlockHeader blockHeader) { if(blockHeader == null || blockHeader.getExtend() == null) { return null; } byte[] stateRoot = blockHeader.getStateRoot(); if(stateRoot != null && stateRoot.length > 0) { return stateRoot; } try { byte[] extend = blockHeader.getExtend(); if(extend.length > BLOCK_EXTENDS_DATA_FIX_LENGTH) { VarInt varInt = new VarInt(extend, BLOCK_EXTENDS_DATA_FIX_LENGTH); int lengthFieldSize = varInt.getOriginalSizeInBytes(); int stateRootlength = (int) varInt.value; stateRoot = new byte[stateRootlength]; System.arraycopy(extend, BLOCK_EXTENDS_DATA_FIX_LENGTH + lengthFieldSize, stateRoot, 0, stateRootlength); blockHeader.setStateRoot(stateRoot); return stateRoot; } } catch (Exception e) { Log.error("parse stateRoot error.", e); } return null; }
public static int sizeOfVarInt(Long val) { return VarInt.sizeOf(val); }
public static int sizeOfVarInt(Integer val) { return VarInt.sizeOf(val); }
public final int getSizeInBytes() { return sizeOf(value); }
@Override public int size() { int size = 0; size += VarInt.sizeOf(txHashList.size()); size += this.getTxHashBytesLength(); return size; }
@Override public int size() { int size = 0; size += requestHash.size(); size += VarInt.sizeOf(txList.size()); size += this.getTxListLength(); return size; }
public byte[] encode() { byte[] bytes; switch (sizeOf(value)) { case 1: return new byte[]{(byte) value}; case 3: return new byte[]{(byte) 253, (byte) (value), (byte) (value >> 8)}; case 5: bytes = new byte[5]; bytes[0] = (byte) 254; SerializeUtils.uint32ToByteArrayLE(value, bytes, 1); return bytes; default: bytes = new byte[9]; bytes[0] = (byte) 255; SerializeUtils.uint64ToByteArrayLE(value, bytes, 1); return bytes; } } }