當前位置: 首頁>>代碼示例>>Java>>正文


Java ByteString類代碼示例

本文整理匯總了Java中com.google.protobuf.ByteString的典型用法代碼示例。如果您正苦於以下問題:Java ByteString類的具體用法?Java ByteString怎麽用?Java ByteString使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ByteString類屬於com.google.protobuf包,在下文中一共展示了ByteString類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createPaymentRequest

import com.google.protobuf.ByteString; //導入依賴的package包/類
/**
 * Create a payment request. You may want to sign the request using {@link #signPaymentRequest}. Use
 * {@link org.bitcoin.protocols.payments.Protos.PaymentRequest.Builder#build} to get the actual payment request.
 * 
 * @param params network parameters
 * @param outputs list of outputs to request coins to
 * @param memo arbitrary, user readable memo, or null if none
 * @param paymentUrl URL to send payment message to, or null if none
 * @param merchantData arbitrary merchant data, or null if none
 * @return created payment request, in its builder form
 */
public static Protos.PaymentRequest.Builder createPaymentRequest(NetworkParameters params,
        List<Protos.Output> outputs, @Nullable String memo, @Nullable String paymentUrl,
        @Nullable byte[] merchantData) {
    final Protos.PaymentDetails.Builder paymentDetails = Protos.PaymentDetails.newBuilder();
    paymentDetails.setNetwork(params.getPaymentProtocolId());
    for (Protos.Output output : outputs)
        paymentDetails.addOutputs(output);
    if (memo != null)
        paymentDetails.setMemo(memo);
    if (paymentUrl != null)
        paymentDetails.setPaymentUrl(paymentUrl);
    if (merchantData != null)
        paymentDetails.setMerchantData(ByteString.copyFrom(merchantData));
    paymentDetails.setTime(Utils.currentTimeSeconds());

    final Protos.PaymentRequest.Builder paymentRequest = Protos.PaymentRequest.newBuilder();
    paymentRequest.setSerializedPaymentDetails(paymentDetails.build().toByteString());
    return paymentRequest;
}
 
開發者ID:guodroid,項目名稱:okwallet,代碼行數:31,代碼來源:PaymentProtocol.java

示例2: testClientRefusesNonCanonicalKey

import com.google.protobuf.ByteString; //導入依賴的package包/類
@Test
public void testClientRefusesNonCanonicalKey() throws Exception {
    ChannelTestUtils.RecordingPair pair = ChannelTestUtils.makeRecorders(serverWallet, mockBroadcaster);
    PaymentChannelServer server = pair.server;
    PaymentChannelClient client = new PaymentChannelClient(wallet, myKey, COIN, Sha256Hash.ZERO_HASH, null, clientChannelProperties, pair.clientRecorder);
    client.connectionOpen();
    server.connectionOpen();
    server.receiveMessage(pair.clientRecorder.checkNextMsg(MessageType.CLIENT_VERSION));
    client.receiveMessage(pair.serverRecorder.checkNextMsg(MessageType.SERVER_VERSION));
    Protos.TwoWayChannelMessage.Builder initiateMsg = Protos.TwoWayChannelMessage.newBuilder(pair.serverRecorder.checkNextMsg(MessageType.INITIATE));
    ByteString brokenKey = initiateMsg.getInitiate().getMultisigKey();
    brokenKey = ByteString.copyFrom(Arrays.copyOf(brokenKey.toByteArray(), brokenKey.size() + 1));
    initiateMsg.getInitiateBuilder().setMultisigKey(brokenKey);
    client.receiveMessage(initiateMsg.build());
    pair.clientRecorder.checkNextMsg(MessageType.ERROR);
    assertEquals(CloseReason.REMOTE_SENT_INVALID_MESSAGE, pair.clientRecorder.q.take());
}
 
開發者ID:creativechain,項目名稱:creacoinj,代碼行數:18,代碼來源:ChannelConnectionTest.java

示例3: convert

import com.google.protobuf.ByteString; //導入依賴的package包/類
public static SnapshottableDirectoryStatusProto convert(
    SnapshottableDirectoryStatus status) {
  if (status == null) {
    return null;
  }
  int snapshotNumber = status.getSnapshotNumber();
  int snapshotQuota = status.getSnapshotQuota();
  byte[] parentFullPath = status.getParentFullPath();
  ByteString parentFullPathBytes = ByteString.copyFrom(
      parentFullPath == null ? DFSUtil.EMPTY_BYTES : parentFullPath);
  HdfsFileStatusProto fs = convert(status.getDirStatus());
  SnapshottableDirectoryStatusProto.Builder builder = 
      SnapshottableDirectoryStatusProto
      .newBuilder().setSnapshotNumber(snapshotNumber)
      .setSnapshotQuota(snapshotQuota).setParentFullpath(parentFullPathBytes)
      .setDirStatus(fs);
  return builder.build();
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:19,代碼來源:PBHelper.java

示例4: ackUpdate

import com.google.protobuf.ByteString; //導入依賴的package包/類
@NotNull
public static Call ackUpdate(
        @NotNull final FrameworkID frameworkId,
        @NotNull final ByteString uuid,
        @NotNull final AgentID agentId,
        @NotNull final TaskID taskId
) {
    return Call.newBuilder()
            .setFrameworkId(frameworkId)
            .setType(Call.Type.ACKNOWLEDGE)
            .setAcknowledge(
                    Call.Acknowledge.newBuilder()
                            .setUuid(uuid)
                            .setAgentId(agentId)
                            .setTaskId(taskId)
                            .build()
            )
            .build();
}
 
開發者ID:HujiangTechnology,項目名稱:Juice,代碼行數:20,代碼來源:SchedulerCalls.java

示例5: customBytesRequest

import com.google.protobuf.ByteString; //導入依賴的package包/類
@Test
public void customBytesRequest() throws InvalidProtocolBufferException
{
	String customData = "{\"c\":1.0}";
	SeldonMessage.Builder b = SeldonMessage.newBuilder();
	b.setBinData(ByteString.copyFrom(customData.getBytes()));
	SeldonMessage request = b.build();
	
	String json = ProtoBufUtils.toJson(request);
	
	System.out.println(json);
	
	SeldonMessage.Builder b2 = SeldonMessage.newBuilder();
	ProtoBufUtils.updateMessageBuilderFromJson(b2, json);
	
	SeldonMessage request2 = b2.build();
	String custom = request2.getBinData().toString(StandardCharsets.UTF_8);
	System.out.println(custom);
	
	String json2 = ProtoBufUtils.toJson(request2);
	
	System.out.println(json2);
	
	Assert.assertEquals(json, json2);
}
 
開發者ID:SeldonIO,項目名稱:seldon-core,代碼行數:26,代碼來源:TestPredictionProto.java

示例6: transactionMap

import com.google.protobuf.ByteString; //導入依賴的package包/類
/**
 * Tell all remote partitions to start the map phase for this txn
 * @param ts
 */
public void transactionMap(LocalTransaction ts, RpcCallback<TransactionMapResponse> callback) {
    ByteString paramBytes = null;
    try {
        ByteBuffer b = ByteBuffer.wrap(FastSerializer.serialize(ts.getProcedureParameters()));
        paramBytes = ByteString.copyFrom(b.array()); 
    } catch (Exception ex) {
        throw new RuntimeException("Unexpected error when serializing StoredProcedureInvocation", ex);
    }
    
    TransactionMapRequest request = TransactionMapRequest.newBuilder()
                                                 .setTransactionId(ts.getTransactionId())
                                                 .setClientHandle(ts.getClientHandle())
                                                 .setBasePartition(ts.getBasePartition())
                                                 .setProcedureId(ts.getProcedure().getId())
                                                 .setParams(paramBytes)
                                                 .build();
    
    PartitionSet partitions = ts.getPredictTouchedPartitions();
    if (debug.val){
        LOG.debug(String.format("Notifying partitions %s that %s is in Map Phase", partitions, ts));
        if (trace.val) LOG.trace("<HStoreCoordinator.TransactionMap> is executing to sendMessages to all partitions");
    }
    this.transactionMap_handler.sendMessages(ts, request, callback, partitions);
}
 
開發者ID:s-store,項目名稱:sstore-soft,代碼行數:29,代碼來源:HStoreCoordinator.java

示例7: PduAttachData

import com.google.protobuf.ByteString; //導入依賴的package包/類
public PduAttachData(ByteString bytes) {
    
    buffer.writeBytes(bytes.toByteArray());
    
    this.type = buffer.readInt();
    this.handle = buffer.readLong();
    this.serviceType = buffer.readInt();
    this.pduLength = buffer.readInt();
    ByteBuf buf = buffer.readBytes(this.pduLength);
    
    if (buf.hasArray()) {
        this.pdu = ByteString.copyFrom(buf.array());
    } else {
        byte[] content = new byte[buf.capacity()];
        buf.readBytes(content);
        this.pdu = ByteString.copyFrom(content);
    }
}
 
開發者ID:ccfish86,項目名稱:sctalk,代碼行數:19,代碼來源:PduAttachData.java

示例8: setup

import com.google.protobuf.ByteString; //導入依賴的package包/類
@Before
public void setup() {
    MockitoAnnotations.initMocks(this);

    data = new HashMap<>();
    data.put("key1", "value1");
    data.put("key2", "value2");
    data.put("key3", "value3");

    byteString = ByteString.copyFrom(SerializationUtils.serialize((Serializable) data));
    chunk1 = getNextChunk(byteString, 0, 10);
    chunk2 = getNextChunk(byteString, 10, 10);
    chunk3 = getNextChunk(byteString, 20, byteString.size());

    fbos = spy(new FileBackedOutputStream(100000000, "target"));
    FileBackedOutputStreamFactory mockFactory = mock(FileBackedOutputStreamFactory.class);
    doReturn(fbos).when(mockFactory).newInstance();
    doReturn(mockFactory).when(mockContext).getFileBackedOutputStreamFactory();
}
 
開發者ID:hashsdn,項目名稱:hashsdn-controller,代碼行數:20,代碼來源:SnapshotTrackerTest.java

示例9: write

import com.google.protobuf.ByteString; //導入依賴的package包/類
@Override
public void write(byte[] buf, int off, int len) throws IOException {
  if (LOG.isDebugEnabled()) {
    LOG.debug("wrapping token of length:" + len);
  }
  buf = saslClient.wrap(buf, off, len);
  RpcSaslProto saslMessage = RpcSaslProto.newBuilder()
      .setState(SaslState.WRAP)
      .setToken(ByteString.copyFrom(buf, 0, buf.length))
      .build();
  RpcRequestMessageWrapper request =
      new RpcRequestMessageWrapper(saslHeader, saslMessage);
  DataOutputStream dob = new DataOutputStream(out);
  dob.writeInt(request.getLength());
  request.write(dob);
 }
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:17,代碼來源:SaslRpcClient.java

示例10: createGroupContext

import com.google.protobuf.ByteString; //導入依賴的package包/類
private static GroupContext.Builder createGroupContext(SignalServiceGroup group) {
  GroupContext.Builder builder = GroupContext.newBuilder();
  builder.setId(ByteString.copyFrom(group.getGroupId()));

  if (group.getAvatar().isPresent() && group.getAvatar().get().isPointer()) {
    builder.setAvatar(AttachmentPointer.newBuilder()
                                       .setId(group.getAvatar().get().asPointer().getId())
                                       .setKey(ByteString.copyFrom(group.getAvatar().get().asPointer().getKey()))
                                       .setContentType(group.getAvatar().get().getContentType()));
  }

  if (group.getName().isPresent()) {
    builder.setName(group.getName().get());
  }

  if (group.getMembers().isPresent()) {
    builder.addAllMembers(group.getMembers().get());
  }

  return builder;
}
 
開發者ID:CableIM,項目名稱:Cable-Android,代碼行數:22,代碼來源:GroupMessageProcessor.java

示例11: writeProtos

import com.google.protobuf.ByteString; //導入依賴的package包/類
@Override
void writeProtos(OutputStream out) throws IOException {
  ProtosFactory.Put.Builder putBuilder = ProtosFactory.Put.newBuilder();
  ProtosFactory.FlumeEvent.Builder eventBuilder =
      ProtosFactory.FlumeEvent.newBuilder();
  Map<String, String> headers = event.getHeaders();
  ProtosFactory.FlumeEventHeader.Builder headerBuilder =
      ProtosFactory.FlumeEventHeader.newBuilder();
  if (headers != null) {
    for (String key : headers.keySet()) {
      String value = headers.get(key);
      headerBuilder.clear();
      eventBuilder.addHeaders(headerBuilder.setKey(key)
          .setValue(value).build());
    }
  }
  eventBuilder.setBody(ByteString.copyFrom(event.getBody()));
  ProtosFactory.FlumeEvent protoEvent = eventBuilder.build();
  putBuilder.setEvent(protoEvent);
  putBuilder.setChecksum(calculateChecksum(event.getBody()));
  putBuilder.build().writeDelimitedTo(out);
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:23,代碼來源:Put.java

示例12: onLogin

import com.google.protobuf.ByteString; //導入依賴的package包/類
@Override
public CompletableFuture<Long> onLogin(ChannelHandlerContext ctx, SocketASK ask) {
    // 整個消息就是 token
    ByteString tokenArg = ask.getBody().getArgs(0);
    if (tokenArg == null) {
        logger.info("Token arg must be input.");
        return null;
    }
    String token = tokenArg.toStringUtf8();
    if (Strings.isNullOrEmpty(token)) {
        logger.info("Token arg must be input.");
        return null;
    }
    return CompletableFuture.supplyAsync(() -> {
        String parseToken = new String(BaseEncoding.base64Url().decode(token));
        List<String> tokenChars = Splitter.on('|').splitToList(parseToken);
        return Long.valueOf(tokenArg.toStringUtf8());
    });
}
 
開發者ID:freedompy,項目名稱:commelina,代碼行數:20,代碼來源:NioSocketEventHandlerForAkka.java

示例13: buildSaslNegotiateResponse

import com.google.protobuf.ByteString; //導入依賴的package包/類
private RpcSaslProto buildSaslNegotiateResponse()
    throws IOException, InterruptedException {
  RpcSaslProto negotiateMessage = negotiateResponse;
  // accelerate token negotiation by sending initial challenge
  // in the negotiation response
  if (enabledAuthMethods.contains(AuthMethod.TOKEN)) {
    saslServer = createSaslServer(AuthMethod.TOKEN);
    byte[] challenge = saslServer.evaluateResponse(new byte[0]);
    RpcSaslProto.Builder negotiateBuilder =
        RpcSaslProto.newBuilder(negotiateResponse);
    negotiateBuilder.getAuthsBuilder(0)  // TOKEN is always first
        .setChallenge(ByteString.copyFrom(challenge));
    negotiateMessage = negotiateBuilder.build();
  }
  sentNegotiate = true;
  return negotiateMessage;
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:18,代碼來源:Server.java

示例14: rawPut

import com.google.protobuf.ByteString; //導入依賴的package包/類
/** */
public void rawPut(
    com.pingcap.tikv.kvproto.Kvrpcpb.RawPutRequest request,
    io.grpc.stub.StreamObserver<com.pingcap.tikv.kvproto.Kvrpcpb.RawPutResponse>
        responseObserver) {
  try {
    verifyContext(request.getContext());
    ByteString key = request.getKey();

    Kvrpcpb.RawPutResponse.Builder builder = Kvrpcpb.RawPutResponse.newBuilder();
    Integer errorCode = errorMap.get(key);
    Errorpb.Error.Builder errBuilder = Errorpb.Error.newBuilder();
    if (errorCode != null) {
      setErrorInfo(errorCode, errBuilder);
      builder.setRegionError(errBuilder.build());
      //builder.setError("");
    }
    responseObserver.onNext(builder.build());
    responseObserver.onCompleted();
  } catch (Exception e) {
    responseObserver.onError(Status.INTERNAL.asRuntimeException());
  }
}
 
開發者ID:pingcap,項目名稱:tikv-client-lib-java,代碼行數:24,代碼來源:KVMockServer.java

示例15: onSuccess

import com.google.protobuf.ByteString; //導入依賴的package包/類
@Override
public void onSuccess(Transaction result) {
    // Send the successfully accepted transaction back to the client.
    final Protos.TwoWayChannelMessage.Builder msg = Protos.TwoWayChannelMessage.newBuilder();
    msg.setType(Protos.TwoWayChannelMessage.MessageType.CLOSE);
    if (result != null) {
        // Result can be null on various error paths, like if we never actually opened
        // properly and so on.
        msg.getSettlementBuilder().setTx(ByteString.copyFrom(result.unsafeBitcoinSerialize()));
        log.info("Sending CLOSE back with broadcast settlement tx.");
    } else {
        log.info("Sending CLOSE back without broadcast settlement tx.");
    }
    conn.sendToClient(msg.build());
    conn.destroyConnection(clientRequestedClose);
}
 
開發者ID:creativechain,項目名稱:creacoinj,代碼行數:17,代碼來源:PaymentChannelServer.java


注:本文中的com.google.protobuf.ByteString類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。