Java Code Examples for com.google.protobuf.ByteString#toStringUtf8()
The following examples show how to use
com.google.protobuf.ByteString#toStringUtf8() .
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: SmartContractSupportServiceTest.java From julongchain with Apache License 2.0 | 6 votes |
@Test public void testGetState() throws InterruptedException { SmartContractMessage.Builder builder = SmartContractMessage.newBuilder(); builder.setPayload(ByteString.copyFromUtf8("a")); builder.setTxid("txid"); builder.setGroupId("myGroup"); builder.setSmartContractEvent(SmartContractEventPackage.SmartContractEvent.newBuilder().setSmartContractId("mycc").build()); builder.setType(SmartContractMessage.Type.GET_STATE); SmartContractMessage sendMessage = builder.build(); sendObserver.onNext(sendMessage); SmartContractMessage receiveMessage = queue.take(); ByteString payload = receiveMessage.getPayload(); String value = payload.toStringUtf8(); log.info(value); Assert.assertEquals(value, "10"); }
Example 2
Source File: SmartContractShimTest.java From julongchain with Apache License 2.0 | 6 votes |
@Test public void testGetState() throws InterruptedException { SmartContractShim.SmartContractMessage.Builder builder = SmartContractShim.SmartContractMessage.newBuilder(); builder.setPayload(ByteString.copyFromUtf8("a")); builder.setTxid("txid"); builder.setGroupId("myGroup"); builder.setSmartContractEvent(SmartContractEventPackage.SmartContractEvent.newBuilder().setSmartContractId("mycc").build()); builder.setType(SmartContractShim.SmartContractMessage.Type.GET_STATE); SmartContractShim.SmartContractMessage sendMessage = builder.build(); sendObserver.onNext(sendMessage); SmartContractShim.SmartContractMessage receiveMessage = queue.take(); ByteString payload = receiveMessage.getPayload(); String value = payload.toStringUtf8(); log.info(value); Assert.assertEquals(value, "10"); }
Example 3
Source File: ProtoApk.java From bazel with Apache License 2.0 | 6 votes |
private ByteString findNamespacePrefix(ByteString uri) { for (Map<ByteString, ByteString> uriToPrefix : namespaceStack) { if (uriToPrefix.containsKey(uri)) { return uriToPrefix.get(uri); } } throw new IllegalStateException( "Unable to find prefix for " + uri.toStringUtf8() + " in [ " + namespaceStack.stream() .map(Map::keySet) .flatMap(Set::stream) .map(ByteString::toString) .collect(joining(", ")) + " ]"); }
Example 4
Source File: ProtoLanguageFileWriter.java From metastore with Apache License 2.0 | 5 votes |
private Object convertFieldValue(Descriptors.FieldDescriptor fieldDescriptor, Object value) { switch (fieldDescriptor.getType()) { case MESSAGE: try { DynamicMessage dynamicMessage = DynamicMessage.parseFrom(fieldDescriptor.getMessageType(), (ByteString) value); return dynamicMessage; } catch (IOException e) { throw new RuntimeException(e); } case BOOL: return value.equals(1L); case ENUM: case STRING: ByteString byteString = (ByteString) value; return byteString.toStringUtf8(); case INT32: case INT64: return unsignedToString((Long) value); case DOUBLE: return Double.longBitsToDouble((Long) value); case FLOAT: return Float.intBitsToFloat((Integer) value); } throw new RuntimeException( "conversion of unknownfield for type " + fieldDescriptor.getType().toString() + " not implemented"); }
Example 5
Source File: EtcdWatchUpdate.java From etcd-java with Apache License 2.0 | 5 votes |
private static String kvToString(KeyValue kv) { if (kv == null) { return null; } ByteString key = kv.getKey(); return key != null ? key.toStringUtf8() : "null"; }
Example 6
Source File: ESSCTest.java From julongchain with Apache License 2.0 | 5 votes |
@Test public void transformProtobuf() { try { ProposalResponsePackage.Response successResponse = ProposalResponsePackage.Response.newBuilder(). setStatus(200).setMessage("OK").setPayload(ByteString.copyFromUtf8("payload")).build(); ByteString byteString = successResponse.toByteString(); ProposalResponsePackage.Response transformedResponse = ProposalResponsePackage.Response.parseFrom(byteString); assertThat(transformedResponse.getStatus(),is(200)); ProposalResponsePackage.Response successResponse2 = ProposalResponsePackage.Response.newBuilder(). setStatus(200).setMessage("OK").setPayload(ByteString.copyFromUtf8("payload")).build(); ByteString byteString2 = successResponse.toByteString(); String string2=byteString2.toStringUtf8(); ByteString transformByteString=ByteString.copyFromUtf8(string2); ProposalResponsePackage.Response transformedResponse2 = ProposalResponsePackage.Response.parseFrom(transformByteString); assertThat(transformedResponse2.getStatus(),not(200)); ProposalResponsePackage.Response successResponse3= ProposalResponsePackage.Response.newBuilder(). setStatus(200).setMessage("OK").setPayload(ByteString.copyFromUtf8("payload")).build(); ByteString byteString3 = successResponse.toByteString(); byte[] byteArray3 = byteString3.toByteArray(); ProposalResponsePackage.Response transformedResponse3 = ProposalResponsePackage.Response.parseFrom(byteArray3); assertThat(transformedResponse3.getStatus(),is(200)); } catch (InvalidProtocolBufferException e) { e.printStackTrace(); } }
Example 7
Source File: TextSource.java From DataflowTemplates with Apache License 2.0 | 5 votes |
/** * Decodes the current element updating the buffer to only contain the unconsumed bytes. * * <p>This invalidates the currently stored {@code startOfDelimiterInBuffer} and {@code * endOfDelimiterInBuffer}. */ private void decodeCurrentElement() throws IOException { ByteString dataToDecode = buffer.substring(0, startOfDelimiterInBuffer); // If present, the UTF8 Byte Order Mark (BOM) will be removed. if (startOfRecord == 0 && dataToDecode.startsWith(UTF8_BOM)) { dataToDecode = dataToDecode.substring(UTF8_BOM.size()); } currentValue = dataToDecode.toStringUtf8(); elementIsPresent = true; buffer = buffer.substring(endOfDelimiterInBuffer); }
Example 8
Source File: BigtableIOTest.java From beam with Apache License 2.0 | 5 votes |
public FakeBigtableReader(BigtableSource source) { this.source = source; if (source.getRowFilter() == null) { filter = Predicates.alwaysTrue(); } else { ByteString keyRegex = source.getRowFilter().getRowKeyRegexFilter(); checkArgument(!keyRegex.isEmpty(), "Only RowKeyRegexFilter is supported"); filter = new KeyMatchesRegex(keyRegex.toStringUtf8()); } service.verifyTableExists(source.getTableId().get()); }
Example 9
Source File: TextBasedReader.java From dlp-dataflow-deidentification with Apache License 2.0 | 4 votes |
private void decodeCurrentElement() throws IOException { ByteString dataToDecode = buffer.substring(0, startOfDelimiterInBuffer); currentValue = dataToDecode.toStringUtf8(); elementIsPresent = true; buffer = buffer.substring(endOfDelimiterInBuffer); }
Example 10
Source File: ContractGrcToken029.java From gsc-core with GNU Lesser General Public License v3.0 | 4 votes |
/** * constructor. */ @Test(enabled = true, description = "Trigger transferTokenwithSameName") public void deploy02TransferTokenContract() { Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(dev001Address, blockingStubFull); info = PublicMethed.queryAccount(dev001Address, blockingStubFull); Long beforeBalance = info.getBalance(); Long beforeCpuUsed = resourceInfo.getCpuUsed(); Long beforeNetUsed = resourceInfo.getNetUsed(); Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); Long beforeAssetIssueDevAddress = PublicMethed .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); Long beforeAssetIssueUserAddress = PublicMethed .getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); Long beforeAssetIssueContractAddress = PublicMethed .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); Long beforeBalanceContractAddress = PublicMethed.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); Long beforeUserBalance = PublicMethed.queryAccount(user001Address, blockingStubFull) .getBalance(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeCpuUsed:" + beforeCpuUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); logger.info("beforeAssetIssueCount:" + beforeAssetIssueContractAddress); logger.info("beforeAssetIssueDevAddress:" + beforeAssetIssueDevAddress); logger.info("beforeAssetIssueUserAddress:" + beforeAssetIssueUserAddress); logger.info("beforeBalanceContractAddress:" + beforeBalanceContractAddress); logger.info("beforeUserBalance:" + beforeUserBalance); // user trigger A to transfer token to B ByteString assetAccountDev = PublicMethed .queryAccount(dev001Address, blockingStubFull).getAssetIssuedID(); ByteString fakeTokenId = ByteString .copyFromUtf8(Long.toString(Long.valueOf(assetAccountDev.toStringUtf8()) + 100)); String param = "\"" + fakeTokenId.toStringUtf8() + "\",\"1\""; final String triggerTxid = PublicMethed.triggerContract(transferTokenContractAddress, "transferTokenWithSameName(grcToken,uint256)", param, false, 0, 1000000000L, "0", 0, dev001Address, dev001Key, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); Account infoafter = PublicMethed.queryAccount(dev001Address, blockingStubFull); AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(dev001Address, blockingStubFull); Long afterBalance = infoafter.getBalance(); Long afterCpuUsed = resourceInfoafter.getCpuUsed(); Long afterAssetIssueDevAddress = PublicMethed .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); Long afterNetUsed = resourceInfoafter.getNetUsed(); Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); Long afterAssetIssueContractAddress = PublicMethed .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); Long afterAssetIssueUserAddress = PublicMethed .getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); Long afterBalanceContractAddress = PublicMethed.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); Long afterUserBalance = PublicMethed.queryAccount(user001Address, blockingStubFull) .getBalance(); logger.info("afterBalance:" + afterBalance); logger.info("afterCpuUsed:" + afterCpuUsed); logger.info("afterNetUsed:" + afterNetUsed); logger.info("afterFreeNetUsed:" + afterFreeNetUsed); logger.info("afterAssetIssueCount:" + afterAssetIssueDevAddress); logger.info("afterAssetIssueDevAddress:" + afterAssetIssueContractAddress); logger.info("afterAssetIssueUserAddress:" + afterAssetIssueUserAddress); logger.info("afterBalanceContractAddress:" + afterBalanceContractAddress); logger.info("afterUserBalance:" + afterUserBalance); Optional<TransactionInfo> infoById = PublicMethed .getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); Assert.assertTrue(afterAssetIssueUserAddress == beforeAssetIssueUserAddress); Assert.assertEquals(afterBalanceContractAddress, beforeBalanceContractAddress); Assert.assertEquals(afterUserBalance, beforeUserBalance); Assert.assertTrue(afterAssetIssueContractAddress == beforeAssetIssueContractAddress); PublicMethed.unFreezeBalance(dev001Address, dev001Key, 1, null, blockingStubFull); PublicMethed.unFreezeBalance(user001Address, user001Key, 1, null, blockingStubFull); }
Example 11
Source File: ContractGrcToken035.java From gsc-core with GNU Lesser General Public License v3.0 | 4 votes |
@Test(enabled = true, description = "Trigger after transfertoken execute assert contract") public void deploy02TransferTokenContract() { Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(dev001Address, blockingStubFull); info = PublicMethed.queryAccount(dev001Address, blockingStubFull); Long beforeBalance = info.getBalance(); Long beforeCpuUsed = resourceInfo.getCpuUsed(); Long beforeNetUsed = resourceInfo.getNetUsed(); Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); Long beforeAssetIssueDevAddress = PublicMethed .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); Long beforeAssetIssueUserAddress = PublicMethed .getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); Long beforeAssetIssueContractAddress = PublicMethed .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeCpuUsed:" + beforeCpuUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); logger.info("beforeAssetIssueCount:" + beforeAssetIssueContractAddress); logger.info("beforeAssetIssueDevAddress:" + beforeAssetIssueDevAddress); logger.info("beforeAssetIssueUserAddress:" + beforeAssetIssueUserAddress); // user trigger A to transfer token to B ByteString assetAccountDev = PublicMethed .queryAccount(dev001Address, blockingStubFull).getAssetIssuedID(); ByteString fakeTokenId = ByteString .copyFromUtf8(Long.toString(Long.valueOf(assetAccountDev.toStringUtf8()) + 100)); String param = "\"" + Base58.encode58Check(user001Address) + "\",1,\"" + fakeTokenId .toStringUtf8() + "\""; final String triggerTxid = PublicMethed.triggerContract(transferTokenContractAddress, "failTransferTokenError(address,uint256,grcToken)", param, false, 0, 1000000000L, "0", 0, dev001Address, dev001Key, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); Account infoafter = PublicMethed.queryAccount(dev001Address, blockingStubFull); AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(dev001Address, blockingStubFull); Long afterBalance = infoafter.getBalance(); Long afterCpuUsed = resourceInfoafter.getCpuUsed(); Long afterAssetIssueDevAddress = PublicMethed .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); Long afterNetUsed = resourceInfoafter.getNetUsed(); Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); Long afterAssetIssueContractAddress = PublicMethed .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); Long afterAssetIssueUserAddress = PublicMethed .getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); logger.info("afterBalance:" + afterBalance); logger.info("afterCpuUsed:" + afterCpuUsed); logger.info("afterNetUsed:" + afterNetUsed); logger.info("afterFreeNetUsed:" + afterFreeNetUsed); logger.info("afterAssetIssueCount:" + afterAssetIssueDevAddress); logger.info("afterAssetIssueDevAddress:" + afterAssetIssueContractAddress); logger.info("afterAssetIssueUserAddress:" + afterAssetIssueUserAddress); Optional<TransactionInfo> infoById = PublicMethed .getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 1); Assert.assertEquals(beforeBalance, afterBalance); Assert.assertEquals(beforeAssetIssueDevAddress, afterAssetIssueDevAddress); Assert.assertEquals(beforeAssetIssueUserAddress, afterAssetIssueUserAddress); Assert.assertEquals(beforeAssetIssueContractAddress, afterAssetIssueContractAddress); PublicMethed.unFreezeBalance(dev001Address, dev001Key, 1, dev001Address, blockingStubFull); PublicMethed.unFreezeBalance(user001Address, user001Key, 1, user001Address, blockingStubFull); }
Example 12
Source File: ContractGrcToken034.java From gsc-core with GNU Lesser General Public License v3.0 | 4 votes |
@Test(enabled = true, description = "Trigger after transfertoken execute require contract") public void deploy02TransferTokenContract() { Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(dev001Address, blockingStubFull); info = PublicMethed.queryAccount(dev001Address, blockingStubFull); Long beforeBalance = info.getBalance(); Long beforeCpuUsed = resourceInfo.getCpuUsed(); Long beforeNetUsed = resourceInfo.getNetUsed(); Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); Long beforeAssetIssueDevAddress = PublicMethed .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); Long beforeAssetIssueUserAddress = PublicMethed .getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); Long beforeAssetIssueContractAddress = PublicMethed .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeCpuUsed:" + beforeCpuUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); logger.info("beforeAssetIssueCount:" + beforeAssetIssueContractAddress); logger.info("beforeAssetIssueDevAddress:" + beforeAssetIssueDevAddress); logger.info("beforeAssetIssueUserAddress:" + beforeAssetIssueUserAddress); // user trigger A to transfer token to B ByteString assetAccountDev = PublicMethed .queryAccount(dev001Address, blockingStubFull).getAssetIssuedID(); ByteString fakeTokenId = ByteString .copyFromUtf8(Long.toString(Long.valueOf(assetAccountDev.toStringUtf8()) + 100)); String param = "\"" + Base58.encode58Check(user001Address) + "\",1,\"" + fakeTokenId .toStringUtf8() + "\""; final String triggerTxid = PublicMethed.triggerContract(transferTokenContractAddress, "failTransferTokenRevert(address,uint256,grcToken)", param, false, 0, 1000000000L, "0", 0, dev001Address, dev001Key, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); Account infoafter = PublicMethed.queryAccount(dev001Address, blockingStubFull); AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(dev001Address, blockingStubFull); Long afterBalance = infoafter.getBalance(); Long afterCpuUsed = resourceInfoafter.getCpuUsed(); Long afterAssetIssueDevAddress = PublicMethed .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); Long afterNetUsed = resourceInfoafter.getNetUsed(); Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); Long afterAssetIssueContractAddress = PublicMethed .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); Long afterAssetIssueUserAddress = PublicMethed .getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); logger.info("afterBalance:" + afterBalance); logger.info("afterCpuUsed:" + afterCpuUsed); logger.info("afterNetUsed:" + afterNetUsed); logger.info("afterFreeNetUsed:" + afterFreeNetUsed); logger.info("afterAssetIssueCount:" + afterAssetIssueDevAddress); logger.info("afterAssetIssueDevAddress:" + afterAssetIssueContractAddress); logger.info("afterAssetIssueUserAddress:" + afterAssetIssueUserAddress); Optional<TransactionInfo> infoById = PublicMethed .getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 1); Assert.assertEquals(beforeBalance, afterBalance); Assert.assertEquals(beforeAssetIssueDevAddress, afterAssetIssueDevAddress); Assert.assertEquals(beforeAssetIssueUserAddress, afterAssetIssueUserAddress); Assert.assertEquals(beforeAssetIssueContractAddress, afterAssetIssueContractAddress); PublicMethed.unFreezeBalance(dev001Address, dev001Key, 1, dev001Address, blockingStubFull); PublicMethed.unFreezeBalance(user001Address, user001Key, 1, user001Address, blockingStubFull); }