本文整理汇总了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;
}
示例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());
}
示例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();
}
示例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();
}
示例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);
}
示例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);
}
示例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);
}
}
示例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();
}
示例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);
}
示例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;
}
示例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);
}
示例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());
});
}
示例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;
}
示例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());
}
}
示例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);
}