Java Code Examples for com.google.protobuf.Any#pack()

The following examples show how to use com.google.protobuf.Any#pack() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClientRPCStoreTest.java    From seldon-server with Apache License 2.0 6 votes vote down vote up
@Test 
public void testResponseToJSON() throws NoSuchMethodException, SecurityException
{
	mockClientConfigHandler.addListener((ClientConfigUpdateListener) EasyMock.anyObject());
	EasyMock.expectLastCall().once();
	replay(mockClientConfigHandler);
	final String client = "test";
	ClientRpcStore store = new ClientRpcStore(mockClientConfigHandler);
	CustomPredictReply customResponse =  CustomPredictReply.newBuilder().setData("some value").build();
	store.add(client, null, customResponse.getClass(),null,customResponse.getClass().getMethod("newBuilder"));
	Any anyMsg = Any.pack(customResponse);
	ClassificationReplyMeta meta = ClassificationReplyMeta.newBuilder().setPuid("1234").build();
	ClassificationReply request = ClassificationReply.newBuilder().setMeta(meta).setCustom(anyMsg).build();
	JsonNode json = store.getJSONForReply(client, request);
	Assert.assertNotNull(json);
	System.out.println(json);
}
 
Example 2
Source File: UnfreezeBalanceOperatorTest.java    From gsc-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Any getContract(String ownerAddress, Contract.ResourceCode resourceCode) {
  return Any.pack(
      Contract.UnfreezeBalanceContract.newBuilder()
          .setOwnerAddress(ByteString.copyFrom(ByteArray.fromHexString(ownerAddress)))
          .setResource(resourceCode)
          .build());
}
 
Example 3
Source File: WitnessUpdateOperatorTest.java    From gsc-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Any getContract(String address, String url) {
  return Any.pack(
      Contract.WitnessUpdateContract.newBuilder()
          .setOwnerAddress(ByteString.copyFrom(ByteArray.fromHexString(address)))
          .setUpdateUrl(ByteString.copyFrom(ByteArray.fromString(url)))
          .build());
}
 
Example 4
Source File: ProposalDeleteOperatorTest.java    From gsc-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Any getContract(String address, long id) {
  return Any.pack(
      Contract.ProposalDeleteContract.newBuilder()
          .setOwnerAddress(ByteString.copyFrom(ByteArray.fromHexString(address)))
          .setProposalId(id)
          .build());
}
 
Example 5
Source File: UpdateCpuLimitContractOperatorTest.java    From gsc-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Release resources.
 */
private Any getContract(String accountAddress, String contractAddress, long originCpuLimit) {
  return Any.pack(
      Contract.UpdateCpuLimitContract.newBuilder()
          .setOwnerAddress(StringUtil.hexString2ByteString(accountAddress))
          .setContractAddress(StringUtil.hexString2ByteString(contractAddress))
          .setOriginCpuLimit(originCpuLimit).build());
}
 
Example 6
Source File: UnfreezeBalanceOperatorTest.java    From gsc-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Any getDelegatedContractForCpu(String ownerAddress, String receiverAddress) {
  return Any.pack(
      Contract.UnfreezeBalanceContract.newBuilder()
          .setOwnerAddress(ByteString.copyFrom(ByteArray.fromHexString(ownerAddress)))
          .setReceiverAddress(ByteString.copyFrom(ByteArray.fromHexString(receiverAddress)))
          .setResource(org.gsc.protos.Contract.ResourceCode.CPU)
          .build());
}
 
Example 7
Source File: ParticipateAssetIssueOperatorTest.java    From gsc-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Any getContract(long count, String assetName) {
  return Any.pack(
      Contract.ParticipateAssetIssueContract.newBuilder()
          .setOwnerAddress(ByteString.copyFrom(ByteArray.fromHexString(OWNER_ADDRESS)))
          .setToAddress(ByteString.copyFrom(ByteArray.fromHexString(TO_ADDRESS)))
          .setAssetName(ByteString.copyFrom(ByteArray.fromString(assetName)))
          .setAmount(count)
          .build());
}
 
Example 8
Source File: CreateAccountOperatorTest.java    From gsc-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Any getContract(String ownerAddress, String accountAddress) {
  return Any.pack(
      Contract.AccountCreateContract.newBuilder()
          .setAccountAddress(ByteString.copyFrom(ByteArray.fromHexString(accountAddress)))
          .setOwnerAddress(ByteString.copyFrom(ByteArray.fromHexString(ownerAddress)))
          .build());
}
 
Example 9
Source File: UpdateAccountOperatorTest.java    From gsc-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Any getContract(ByteString name, String address) {
    return Any.pack(
            Contract.AccountUpdateContract.newBuilder()
                    .setAccountName(name)
                    .setOwnerAddress(ByteString.copyFrom(ByteArray.fromHexString(address)))
                    .build());
}
 
Example 10
Source File: UnfreezeBalanceOperatorTest.java    From gsc-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Any getDelegatedContractForNet(String ownerAddress, String receiverAddress) {
  return Any.pack(
      Contract.UnfreezeBalanceContract.newBuilder()
          .setOwnerAddress(ByteString.copyFrom(ByteArray.fromHexString(ownerAddress)))
          .setReceiverAddress(ByteString.copyFrom(ByteArray.fromHexString(receiverAddress)))
          .build());
}
 
Example 11
Source File: TransferAssetOperatorTest.java    From gsc-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Any getContract(long sendCoin, String owner, String to) {
  String assertName = ASSET_NAME;
  if (dbManager.getDynamicPropertiesStore().getAllowSameTokenName() == 1) {
    long tokenIdNum = dbManager.getDynamicPropertiesStore().getTokenIdNum();
    assertName = String.valueOf(tokenIdNum);
  }
  return Any.pack(
      Contract.TransferAssetContract.newBuilder()
          .setAssetName(ByteString.copyFrom(ByteArray.fromString(assertName)))
          .setOwnerAddress(ByteString.copyFrom(ByteArray.fromHexString(owner)))
          .setToAddress(ByteString.copyFrom(ByteArray.fromHexString(to)))
          .setAmount(sendCoin)
          .build());
}
 
Example 12
Source File: TransferAssetOperatorTest.java    From gsc-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Any getContract(long sendCoin, String assetName) {
  return Any.pack(
      Contract.TransferAssetContract.newBuilder()
          .setAssetName(ByteString.copyFrom(ByteArray.fromString(assetName)))
          .setOwnerAddress(ByteString.copyFrom(ByteArray.fromHexString(OWNER_ADDRESS)))
          .setToAddress(ByteString.copyFrom(ByteArray.fromHexString(TO_ADDRESS)))
          .setAmount(sendCoin)
          .build());
}
 
Example 13
Source File: ProposalDeleteOperatorTest.java    From gsc-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Any getContract(String address, HashMap<Long, Long> paras) {
  return Any.pack(
      Contract.ProposalCreateContract.newBuilder()
          .setOwnerAddress(ByteString.copyFrom(ByteArray.fromHexString(address)))
          .putAllParameters(paras)
          .build());
}
 
Example 14
Source File: TransferAssetOperatorTest.java    From gsc-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Any getContract(long sendCoin) {
  String assertName = ASSET_NAME;
  if (dbManager.getDynamicPropertiesStore().getAllowSameTokenName() == 1) {
    long tokenIdNum = dbManager.getDynamicPropertiesStore().getTokenIdNum();
    assertName = String.valueOf(tokenIdNum);
  }

  return Any.pack(
      Contract.TransferAssetContract.newBuilder()
          .setAssetName(ByteString.copyFrom(ByteArray.fromString(assertName)))
          .setOwnerAddress(ByteString.copyFrom(ByteArray.fromHexString(OWNER_ADDRESS)))
          .setToAddress(ByteString.copyFrom(ByteArray.fromHexString(TO_ADDRESS)))
          .setAmount(sendCoin)
          .build());
}
 
Example 15
Source File: ExchangeWithdrawOperatorTest.java    From gsc-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Any getContract(String address, long exchangeId, String tokenId, long quant) {
  return Any.pack(
      Contract.ExchangeWithdrawContract.newBuilder()
          .setOwnerAddress(ByteString.copyFrom(ByteArray.fromHexString(address)))
          .setExchangeId(exchangeId)
          .setTokenId(ByteString.copyFrom(tokenId.getBytes()))
          .setQuant(quant)
          .build());
}
 
Example 16
Source File: UpdateAccountOperatorTest.java    From gsc-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Any getContract(String name, String address) {
    return Any.pack(
            Contract.AccountUpdateContract.newBuilder()
                    .setAccountName(ByteString.copyFromUtf8(name))
                    .setOwnerAddress(ByteString.copyFrom(ByteArray.fromHexString(address)))
                    .build());
}
 
Example 17
Source File: ProposalCreateOperatorTest.java    From gsc-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Any getContract(String address, HashMap<Long, Long> paras) {
  return Any.pack(
      Contract.ProposalCreateContract.newBuilder()
          .setOwnerAddress(ByteString.copyFrom(ByteArray.fromHexString(address)))
          .putAllParameters(paras)
          .build());
}
 
Example 18
Source File: AnyTest.java    From jprotobuf with Apache License 2.0 5 votes vote down vote up
@Test
public void testAnyOriginEncodeJprotobufDeocde() throws IOException {
    String s1 = "hello world";
    String s2 = "hello xiemalin";
    
    // origin protobuf
    StringMessage message = StringMessage.newBuilder().setList(s1).build();
    Any any = Any.pack(message);
    AnyObject anyObject = AnyObject.newBuilder().addDetails(any).setMessage(s2).build();
    byte[] byteArray = anyObject.toByteArray();
    
    // jprotobuf 
    StringTypePOJOClass pojo = new StringTypePOJOClass();
    pojo.setStr(s1);

    com.baidu.bjf.remoting.protobuf.Any any2 =
            com.baidu.bjf.remoting.protobuf.Any.pack(pojo, "pkg.StringMessage");
    AnyPOJO anyPojo = new AnyPOJO();
    List<com.baidu.bjf.remoting.protobuf.Any> details = new ArrayList<com.baidu.bjf.remoting.protobuf.Any>();
    details.add(any2);
    anyPojo.setDetails(details);
    anyPojo.setMessage(s2);
    
    Codec<AnyPOJO> codec = ProtobufProxy.create(AnyPOJO.class);
    byte[] byteArray2 = codec.encode(anyPojo);
    
    Assert.assertArrayEquals(byteArray, byteArray2);
}
 
Example 19
Source File: UnfreezeBalanceOperatorTest.java    From gsc-core with GNU Lesser General Public License v3.0 4 votes vote down vote up
private Any getContractForNet(String ownerAddress) {
  return Any.pack(
      Contract.UnfreezeBalanceContract.newBuilder()
          .setOwnerAddress(ByteString.copyFrom(ByteArray.fromHexString(ownerAddress)))
          .build());
}
 
Example 20
Source File: UnfreezeAssetOperatorTest.java    From gsc-core with GNU Lesser General Public License v3.0 4 votes vote down vote up
private Any getContract(String ownerAddress) {
  return Any.pack(
      Contract.UnfreezeAssetContract.newBuilder()
          .setOwnerAddress(StringUtil.hexString2ByteString(ownerAddress))
          .build());
}