本文整理了Java中org.apache.ratis.thirdparty.com.google.protobuf.ByteString
类的一些代码示例,展示了ByteString
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteString
类的具体详情如下:
包路径:org.apache.ratis.thirdparty.com.google.protobuf.ByteString
类名称:ByteString
暂无
代码示例来源:origin: apache/incubator-ratis
public AssignmentMessage(ByteString bytes) {
this(bytes.toByteArray(), 0);
}
代码示例来源:origin: apache/incubator-ratis
/**
* <code>string value_serde_class = 6;</code>
*/
public java.lang.String getValueSerdeClass() {
java.lang.Object ref = valueSerdeClass_;
if (!(ref instanceof java.lang.String)) {
org.apache.ratis.thirdparty.com.google.protobuf.ByteString bs =
(org.apache.ratis.thirdparty.com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
valueSerdeClass_ = s;
return s;
} else {
return (java.lang.String) ref;
}
}
/**
代码示例来源:origin: apache/incubator-ratis
static ByteString toByteString(byte[] bytes, int offset, int size) {
// return singleton to reduce object allocation
return bytes.length == 0 ?
ByteString.EMPTY : ByteString.copyFrom(bytes, offset, size);
}
代码示例来源:origin: apache/incubator-ratis
private RaftPeerId(ByteString id) {
this.id = Objects.requireNonNull(id, "id == null");
Preconditions.assertTrue(id.size() > 0, "id is empty.");
this.idString = id.toString(StandardCharsets.UTF_8);
}
代码示例来源:origin: apache/incubator-ratis
private static UUID toUuid(ByteString bytes) {
Objects.requireNonNull(bytes, "bytes == null");
checkLength(bytes.size(), "bytes.size()");
final ByteBuffer buf = bytes.asReadOnlyByteBuffer();
return new UUID(buf.getLong(), buf.getLong());
}
代码示例来源:origin: apache/incubator-ratis
public static String bytes2HexShortString(ByteString bytes) {
final int size = bytes.size();
if (size == 0) {
return "<EMPTY>";
} else if (size > 10) {
// return only the first 10 bytes
return bytes2HexString(bytes.substring(0, 10)) + "...(size=" + size + ")";
} else {
return bytes2HexString(bytes);
}
}
代码示例来源:origin: apache/incubator-ratis
static ByteString toByteString(String string) {
return ByteString.copyFromUtf8(string);
}
代码示例来源:origin: apache/incubator-ratis
static int getSerializedSize(LogEntryProto entry) {
return getStateMachineEntry(entry)
.filter(smEnty -> smEnty.getStateMachineData().isEmpty())
.map(StateMachineEntryProto::getLogEntryProtoSerializedSize)
.orElseGet(entry::getSerializedSize);
}
代码示例来源:origin: apache/incubator-ratis
final ByteBuffer expected = ByteString.copyFrom(randomBytes(length, r)).asReadOnlyByteBuffer();
代码示例来源:origin: apache/incubator-ratis
@java.lang.Override
public boolean equals(final java.lang.Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof org.apache.ratis.proto.rmap.RMapProtos.Entry)) {
return super.equals(obj);
}
org.apache.ratis.proto.rmap.RMapProtos.Entry other = (org.apache.ratis.proto.rmap.RMapProtos.Entry) obj;
boolean result = true;
result = result && getKey()
.equals(other.getKey());
result = result && getValue()
.equals(other.getValue());
result = result && unknownFields.equals(other.unknownFields);
return result;
}
代码示例来源:origin: apache/incubator-ratis
public static String bytes2HexString(ByteString bytes) {
Objects.requireNonNull(bytes, "bytes == null");
return bytes2HexString(bytes.asReadOnlyByteBuffer());
}
代码示例来源:origin: apache/incubator-ratis
CompletableFuture<Integer> write(
long index, String relative, boolean close, long offset, ByteString data) {
final int size = data != null? data.size(): 0;
LOG.trace("write {}, offset={}, size={}, close? {} @{}:{}",
relative, offset, size, close, getId(), index);
final boolean createNew = offset == 0L;
final UnderConstruction uc;
if (createNew) {
uc = new UnderConstruction(normalize(relative));
files.putNew(uc);
} else {
try {
uc = files.get(relative).asUnderConstruction();
} catch (FileNotFoundException e) {
return FileStoreCommon.completeExceptionally(
index, "Failed to write to " + relative, e);
}
}
return size == 0 && !close? CompletableFuture.completedFuture(0)
: createNew? uc.submitCreate(this::resolve, data, close, writer, getId(), index)
: uc.submitWrite(offset, data, close, writer, getId(), index);
}
代码示例来源:origin: apache/incubator-ratis
/**
* <code>string value_class = 4;</code>
*/
public org.apache.ratis.thirdparty.com.google.protobuf.ByteString
getValueClassBytes() {
java.lang.Object ref = valueClass_;
if (ref instanceof java.lang.String) {
org.apache.ratis.thirdparty.com.google.protobuf.ByteString b =
org.apache.ratis.thirdparty.com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
valueClass_ = b;
return b;
} else {
return (org.apache.ratis.thirdparty.com.google.protobuf.ByteString) ref;
}
}
代码示例来源:origin: apache/incubator-ratis
public void writeTo(org.apache.ratis.thirdparty.com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
if (!id_.isEmpty()) {
output.writeBytes(1, id_);
}
if (!getAddressBytes().isEmpty()) {
org.apache.ratis.thirdparty.com.google.protobuf.GeneratedMessageV3.writeString(output, 2, address_);
}
unknownFields.writeTo(output);
}
代码示例来源:origin: apache/incubator-ratis
void verify(ByteString read, int offset, int length, ByteBuffer expected) {
Assert.assertEquals(length, read.size());
assertBuffers(offset, length, expected, read.asReadOnlyByteBuffer());
}
代码示例来源:origin: apache/incubator-ratis
@java.lang.Override
public boolean equals(final java.lang.Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof org.apache.ratis.proto.rmap.RMapProtos.PutRequest)) {
return super.equals(obj);
}
org.apache.ratis.proto.rmap.RMapProtos.PutRequest other = (org.apache.ratis.proto.rmap.RMapProtos.PutRequest) obj;
boolean result = true;
result = result && getKey()
.equals(other.getKey());
result = result && getValue()
.equals(other.getValue());
result = result && unknownFields.equals(other.unknownFields);
return result;
}
代码示例来源:origin: apache/incubator-ratis
private int write(long offset, ByteString data, boolean close) throws IOException {
if (offset != writeSize) {
throw new IOException("Offset/size mismatched: offset = " + offset
+ " != writeSize = " + writeSize + ", path=" + getRelativePath());
}
if (out == null) {
throw new IOException("File output is not initialized, path=" + getRelativePath());
}
synchronized (out) {
int n = 0;
if (data != null) {
final ByteBuffer buffer = data.asReadOnlyByteBuffer();
try {
for (; buffer.remaining() > 0; ) {
n += out.write(buffer);
}
} finally {
writeSize += n;
}
}
if (close) {
out.close();
}
return n;
}
}
代码示例来源:origin: apache/incubator-ratis
@Override
public CompletableFuture<Message> applyTransaction(TransactionContext trx) {
final LogEntryProto entry = trx.getLogEntry();
final long index = entry.getIndex();
updateLastAppliedTermIndex(entry.getTerm(), index);
final StateMachineLogEntryProto smLog = entry.getStateMachineLogEntry();
final FileStoreRequestProto request;
try {
request = FileStoreRequestProto.parseFrom(smLog.getLogData());
} catch (InvalidProtocolBufferException e) {
return FileStoreCommon.completeExceptionally(index,
"Failed to parse logData in" + smLog, e);
}
switch(request.getRequestCase()) {
case DELETE:
return delete(index, request.getDelete());
case WRITEHEADER:
return writeCommit(index, request.getWriteHeader(), smLog.getStateMachineEntry().getStateMachineData().size());
case WRITE:
// WRITE should not happen here since
// startTransaction converts WRITE requests to WRITEHEADER requests.
default:
LOG.error(getId() + ": Unexpected request case " + request.getRequestCase());
return FileStoreCommon.completeExceptionally(index,
"Unexpected request case " + request.getRequestCase());
}
}
代码示例来源:origin: hortonworks/ratis
public static List<byte[]> toListByteArray(List<ByteString> list) {
List<byte[]> retVal = new ArrayList<byte[]>(list.size());
for(int i=0; i < list.size(); i++) {
retVal.add(list.get(i).toByteArray());
}
return retVal;
}
代码示例来源:origin: apache/incubator-ratis
static String toString(RaftRpcReplyProto reply) {
return reply.getRequestorId().toStringUtf8() + "->"
+ reply.getReplyId().toStringUtf8() + "," + reply.getSuccess();
}
内容来源于网络,如有侵权,请联系作者删除!