com.google.protobuf.ByteString#toByteArray ( )源码实例Demo

下面列出了com.google.protobuf.ByteString#toByteArray ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Android   文件: EncryptionUtil.java
public static Connect.GcmData encodeAESGCM(SupportKeyUril.EcdhExts exts, byte[] ecdhKey, byte[] encodes) {
    //ecdhkey extension
    ecdhKey = SupportKeyUril.ecdhKeyExtends(exts, ecdhKey);

    byte[] ab = "ConnectEncrypted".getBytes();
    ByteString iv = ByteString.copyFrom(SupportKeyUril.cdJNISeed());
    byte[] ib = iv.toByteArray();

    GCMModel gc = AllNativeMethod.cdxtalkEncodeAESGCM(encodes, encodes.length,
            ab, ab.length, ecdhKey, ecdhKey.length, ib, ib.length);

    ByteString enc = ByteString.copyFrom(gc.encrypt);
    ByteString mytag = ByteString.copyFrom(gc.tag);

    Connect.GcmData gcmData = Connect.GcmData.newBuilder().setIv(iv).
            setAad(ByteString.copyFrom(ab)).setCiphertext(enc).setTag(mytag).build();
    return gcmData;
}
 
源代码2 项目: gsc-core   文件: TrieService.java
private byte[] getAccountStateRootHash(long blockNumber) {
    long latestNumber = blockNumber;
    byte[] rootHash = null;
    try {
        BlockWrapper blockWrapper = manager.getBlockByNum(latestNumber);
        ByteString value = blockWrapper.getInstance().getBlockHeader().getRawData()
                .getAccountStateRoot();
        rootHash = value == null ? null : value.toByteArray();
        if (Arrays.equals(rootHash, Internal.EMPTY_BYTE_ARRAY)) {
            rootHash = Hash.EMPTY_TRIE_HASH;
        }
    } catch (Exception e) {
        logger.error("Get the {} block error.", latestNumber, e);
    }
    return rootHash;
}
 
源代码3 项目: gsc-core   文件: TransactionWrapper.java
public static byte[] getToAddress(Transaction.Contract contract) {
    ByteString to;
    try {
        Any contractParameter = contract.getParameter();
        switch (contract.getType()) {
            case TransferAssetContract:
                to = contractParameter.unpack(TransferAssetContract.class).getToAddress();
                break;
            case TransferContract:
                to = contractParameter.unpack(TransferContract.class).getToAddress();
                break;
            case ParticipateAssetIssueContract:
                to = contractParameter.unpack(ParticipateAssetIssueContract.class).getToAddress();
                break;
            // todo add other contract

            default:
                return null;
        }
        return to.toByteArray();
    } catch (Exception ex) {
        logger.error(ex.getMessage());
        return null;
    }
}
 
源代码4 项目: redtorch   文件: RpcClientProcessServiceImpl.java
public boolean sendLz4CoreRpc(int targetNodeId, ByteString content, String reqId, RpcId rpcId) {
	ByteString contentByteString = ByteString.EMPTY;
	long beginTime = System.currentTimeMillis();
	try (InputStream in = new ByteArrayInputStream(content.toByteArray()); ByteArrayOutputStream bOut = new ByteArrayOutputStream(); LZ4FrameOutputStream lzOut = new LZ4FrameOutputStream(bOut);) {
		final byte[] buffer = new byte[10240];
		int n = 0;
		while (-1 != (n = in.read(buffer))) {
			lzOut.write(buffer, 0, n);
		}
		lzOut.close();
		in.close();
		contentByteString = ByteString.copyFrom(bOut.toByteArray());
		logger.info("发送RPC记录,目标节点ID:{},请求ID:{},RPC:{},压缩耗时{}ms,原始数据大小{},压缩后数据大小{},压缩率{}", targetNodeId, reqId, rpcId.getValueDescriptor().getName(), System.currentTimeMillis() - beginTime,
				content.size(), contentByteString.size(), contentByteString.size() / (double) content.size());
	} catch (Exception e) {
		logger.error("发送RPC错误,压缩异常,目标节点ID:{},请求ID:{},RPC:{}", targetNodeId, reqId, rpcId.getValueDescriptor().getName(), e);
		return false;
	}

	DataExchangeProtocol.Builder depBuilder = DataExchangeProtocol.newBuilder() //
			.setRpcId(rpcId.getNumber()) //
			.setReqId(reqId) //
			.setContentType(ContentType.COMPRESSED_LZ4) //
			.setSourceNodeId(nodeId) //
			.setTargetNodeId(targetNodeId) //
			.setTimestamp(System.currentTimeMillis()) //
			.setContentBytes(contentByteString);

	if (!webSocketClientHandler.sendData(depBuilder.build().toByteArray())) {
		logger.error("发送RPC错误,目标节点ID:{},请求ID:{},RPC:{}", targetNodeId, reqId,  rpcId.getValueDescriptor().getName());
		return false;
	}
	return true;
}
 
源代码5 项目: julongchain   文件: SmartContractProvider.java
/**
* 在世界状态数据库中获取智能合约包
* 依赖couchDB
   */

  public static byte[] extractStateDBArtifactsFromSCPackage(ISmartContractPackage scPack) throws JulongChainException {
      SmartContractPackage.SmartContractDeploymentSpec sds = scPack.getDepSpec();
      ByteString bytes = sds.getCodePackage();
      return bytes.toByteArray();
  }
 
源代码6 项目: jelectrum   文件: Util.java
public static ByteString reverse(ByteString in)
{
  byte b[]=in.toByteArray();
  byte o[]=new byte[b.length];

  for(int i=0; i<b.length; i++)
  {
    o[i]=b[b.length-1-i];
  }
  return ByteString.copyFrom(o);
}
 
public void insertProvider(String name, ByteString buf) {
    if (buf == null || buf.size() == 0) {
        return;
    }

    byte[] b = buf.toByteArray();
    Bitmap icon = BitmapFactory.decodeByteArray(b, 0, b.length);
    mProvider.put(name, icon);
}
 
源代码8 项目: snowblossom   文件: KeyUtil.java
public static PrivateKey decodePrivateKey(ByteString encoded, String algo)
  throws ValidationException
{
  try
  {
    PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(encoded.toByteArray());
    KeyFactory fact = KeyFactory.getInstance(algo, Globals.getCryptoProviderName());
    return fact.generatePrivate(spec);
  }
  catch(java.security.GeneralSecurityException e)
  {
    throw new ValidationException("Error decoding key", e);
  }

}
 
源代码9 项目: Tok-Android   文件: StringUtils.java
public static String byte2Str(ByteString byteString) {
    if (byteString != null) {
        return new String(byteString.toByteArray());
    }
    return "";
}
 
源代码10 项目: android-chromium   文件: Bytes.java
public Bytes(ByteString byteString) {
  this(byteString.toByteArray());
}
 
源代码11 项目: OpenYOLO-Android   文件: ByteStringConverters.java
@Override
public byte[] convert(ByteString value) {
    return value.toByteArray();
}
 
源代码12 项目: netcdf-java   文件: Grib2Index.java
private Grib2SectionGridDefinition readGds(Grib2IndexProto.GribGdsSection proto) {
  ByteString bytes = proto.getGds();
  return new Grib2SectionGridDefinition(bytes.toByteArray());
}
 
源代码13 项目: netcdf-java   文件: Grib1Index.java
private Grib1SectionGridDefinition readGds(Grib1IndexProto.Grib1GdsSection proto) {
  ByteString bytes = proto.getGds();
  return new Grib1SectionGridDefinition(bytes.toByteArray());
}
 
源代码14 项目: client-java   文件: CodecDataInput.java
public CodecDataInput(ByteString data) {
  this(data.toByteArray());
}
 
源代码15 项目: WavesJ   文件: PBTransactions.java
public static com.wavesplatform.wavesj.ByteString toVanillaByteString(final ByteString bs) {
    return new com.wavesplatform.wavesj.ByteString(bs.toByteArray());
}
 
/**
 * The validation parameter bytes that were set when the chaincode was defined.
 * @return A validation parameter.
 */
public byte[] getValidationParameter() {
    final ByteString payloadBytes = chaincodeDefinition.getValidationParameter();
    return payloadBytes == null ? null : payloadBytes.toByteArray();
}
 
源代码17 项目: bisq   文件: ProtoUtil.java
@Nullable
public static byte[] byteArrayOrNullFromProto(ByteString proto) {
    return proto.isEmpty() ? null : proto.toByteArray();
}
 
源代码18 项目: tikv-client-lib-java   文件: Snapshot.java
public byte[] get(byte[] key) {
  ByteString keyString = ByteString.copyFrom(key);
  ByteString value = get(keyString);
  return value.toByteArray();
}
 
源代码19 项目: tron-wallet-android   文件: TransactionUtils.java
public static byte[] getOwner(Transaction.Contract contract) {
  ByteString owner;
  try {
    switch (contract.getType()) {
      case AccountCreateContract:
        owner = unpackContract(contract, org.tron.protos.Contract.AccountCreateContract.class).getOwnerAddress();
        break;
      case TransferContract:
        owner = unpackContract(contract, org.tron.protos.Contract.TransferContract.class).getOwnerAddress();
        break;
      case TransferAssetContract:
        owner = unpackContract(contract, org.tron.protos.Contract.TransferAssetContract.class).getOwnerAddress();
        break;
      case VoteAssetContract:
        owner = unpackContract(contract, org.tron.protos.Contract.VoteAssetContract.class).getOwnerAddress();
        break;
      case VoteWitnessContract:
        owner = unpackContract(contract, org.tron.protos.Contract.VoteWitnessContract.class).getOwnerAddress();
        break;
      case WitnessCreateContract:
        owner = unpackContract(contract, org.tron.protos.Contract.WitnessCreateContract.class).getOwnerAddress();
        break;
      case AssetIssueContract:
        owner = unpackContract(contract, org.tron.protos.Contract.AssetIssueContract.class).getOwnerAddress();
        break;
      case WitnessUpdateContract:
        owner = unpackContract(contract, org.tron.protos.Contract.WitnessUpdateContract.class).getOwnerAddress();
        break;
      case ParticipateAssetIssueContract:
        owner = unpackContract(contract, org.tron.protos.Contract.ParticipateAssetIssueContract.class).getOwnerAddress();
        break;
      case AccountUpdateContract:
        owner = unpackContract(contract, org.tron.protos.Contract.AccountUpdateContract.class).getOwnerAddress();
        break;
      case FreezeBalanceContract:
        owner = unpackContract(contract, org.tron.protos.Contract.FreezeBalanceContract.class).getOwnerAddress();
        break;
      case UnfreezeBalanceContract:
        owner = unpackContract(contract, org.tron.protos.Contract.UnfreezeBalanceContract.class).getOwnerAddress();
        break;
      case UnfreezeAssetContract:
        owner = unpackContract(contract, org.tron.protos.Contract.UnfreezeAssetContract.class).getOwnerAddress();
        break;
      case WithdrawBalanceContract:
        owner = unpackContract(contract, org.tron.protos.Contract.WithdrawBalanceContract.class).getOwnerAddress();
        break;
      case UpdateAssetContract:
        owner = unpackContract(contract, org.tron.protos.Contract.UpdateAssetContract.class).getOwnerAddress();
        break; // -----
      case ProposalCreateContract:
        owner = unpackContract(contract, org.tron.protos.Contract.ProposalCreateContract.class).getOwnerAddress();
        break;
      case ProposalApproveContract:
        owner = unpackContract(contract, org.tron.protos.Contract.ProposalApproveContract.class).getOwnerAddress();
        break;
      case ProposalDeleteContract:
        owner = unpackContract(contract, org.tron.protos.Contract.ProposalDeleteContract.class).getOwnerAddress();
        break;
      case SetAccountIdContract:
        owner = unpackContract(contract, org.tron.protos.Contract.SetAccountIdContract.class).getOwnerAddress();
        break;
      //case CustomContract:
        //owner = unpackContract(contract, org.tron.protos.Contract.CustomContract.class).getOwnerAddress();
        //break;
      case CreateSmartContract:
        owner = unpackContract(contract, org.tron.protos.Contract.CreateSmartContract.class).getOwnerAddress();
        break;
      case TriggerSmartContract:
        owner = unpackContract(contract, org.tron.protos.Contract.TriggerSmartContract.class).getOwnerAddress();
        break;
      //case GetContract:
        //owner = unpackContract(contract, org.tron.protos.Contract.GetContract.class).getOwnerAddress();
        //break;
      case UpdateSettingContract:
        owner = unpackContract(contract, org.tron.protos.Contract.UpdateSettingContract.class).getOwnerAddress();
        break;
      case ExchangeCreateContract:
        owner = unpackContract(contract, org.tron.protos.Contract.ExchangeCreateContract.class).getOwnerAddress();
        break;
      case ExchangeInjectContract:
        owner = unpackContract(contract, org.tron.protos.Contract.ExchangeInjectContract.class).getOwnerAddress();
        break;
      case ExchangeWithdrawContract:
        owner = unpackContract(contract, org.tron.protos.Contract.ExchangeWithdrawContract.class).getOwnerAddress();
        break;
      case ExchangeTransactionContract:
        owner = unpackContract(contract, org.tron.protos.Contract.ExchangeTransactionContract.class).getOwnerAddress();
        break;
      default:
        return null;
    }
    return owner.toByteArray();
  } catch (Exception ex) {
    ex.printStackTrace();
    return null;
  }
}
 
源代码20 项目: reef   文件: GRPCUtils.java
/**
 * Converts ByteString to byte array.
 * @param bs ByteString
 * @return byte array or null if not present
 */
public static byte[] toByteArray(final ByteString bs) {
  return bs == null || bs.isEmpty() ? null : bs.toByteArray();
}