本文整理了Java中com.google.protobuf.ByteString
类的一些代码示例,展示了ByteString
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteString
类的具体详情如下:
包路径:com.google.protobuf.ByteString
类名称:ByteString
[英]Immutable sequence of bytes. Substring is supported by sharing the reference to the immutable underlying bytes, as with String. Concatenation is likewise supported without copying (long strings) by building a tree of pieces in RopeByteString.
Like String, the contents of a ByteString can never be observed to change, not even in the presence of a data race or incorrect API usage in the client code.
[中]不可变的字节序列。通过共享对不可变底层字节的引用(如字符串)来支持子字符串。通过在RopeByteString中构建一个片段树,在不复制(长字符串)的情况下也同样支持连接。
与字符串一样,ByteString的内容永远不会被观察到发生更改,即使在客户机代码中存在数据竞争或API使用不正确的情况下也是如此。
代码示例来源:origin: bazelbuild/bazel
/**
* <code>optional string default_string = 5;</code>
*/
public java.lang.String getDefaultString() {
java.lang.Object ref = defaultString_;
if (!(ref instanceof java.lang.String)) {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
if (bs.isValidUtf8()) {
defaultString_ = s;
}
return s;
} else {
return (java.lang.String) ref;
}
}
/**
代码示例来源:origin: bazelbuild/bazel
/**
* <code>optional string default_string = 5;</code>
*/
public com.google.protobuf.ByteString
getDefaultStringBytes() {
java.lang.Object ref = defaultString_;
if (ref instanceof java.lang.String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
defaultString_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
代码示例来源:origin: apache/hbase
/**
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0.
*/
@Deprecated
public ByteString toByteString() {
return ByteString.copyFrom(this.bytes, this.offset, this.length);
}
代码示例来源:origin: osmandapp/Osmand
/**
* Tests if this bytestring starts with the specified prefix.
* Similar to {@link String#startsWith(String)}
*
* @param prefix the prefix.
* @return <code>true</code> if the byte sequence represented by the
* argument is a prefix of the byte sequence represented by
* this string; <code>false</code> otherwise.
*/
public boolean startsWith(ByteString prefix) {
return size() >= prefix.size() &&
substring(0, prefix.size()).equals(prefix);
}
代码示例来源:origin: apache/hbase
byte[] getBytesFromResponse(ByteString response) {
ByteBuffer bb = response.asReadOnlyByteBuffer();
bb.rewind();
byte[] bytes;
if (bb.hasArray()) {
bytes = bb.array();
} else {
bytes = response.toByteArray();
}
return bytes;
}
}
代码示例来源:origin: googleapis/google-cloud-java
@java.lang.Override
public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException {
for (int i = 0; i < instances_.size(); i++) {
output.writeMessage(1, instances_.get(i));
}
for (int i = 0; i < failedLocations_.size(); i++) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 2, failedLocations_.getRaw(i));
}
if (!getNextPageTokenBytes().isEmpty()) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 3, nextPageToken_);
}
unknownFields.writeTo(output);
}
代码示例来源:origin: apache/incubator-shardingsphere
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
if (!name_.isEmpty()) {
output.writeBytes(1, name_);
}
if (!password_.isEmpty()) {
output.writeBytes(2, password_);
}
for (int i = 0; i < roles_.size(); i++) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 3, roles_.getRaw(i));
}
unknownFields.writeTo(output);
}
代码示例来源:origin: apache/incubator-shardingsphere
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
if (permType_ != authpb.Auth.Permission.Type.READ.getNumber()) {
output.writeEnum(1, permType_);
}
if (!key_.isEmpty()) {
output.writeBytes(2, key_);
}
if (!rangeEnd_.isEmpty()) {
output.writeBytes(3, rangeEnd_);
}
unknownFields.writeTo(output);
}
代码示例来源:origin: alibaba/canal
@java.lang.Override
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
if (!getDestinationBytes().isEmpty()) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 1, destination_);
}
if (!getClientIdBytes().isEmpty()) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 2, clientId_);
}
if (batchId_ != 0L) {
output.writeInt64(3, batchId_);
}
unknownFields.writeTo(output);
}
代码示例来源:origin: googleapis/google-cloud-java
@java.lang.Override
public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException {
if (!getSubscriptionBytes().isEmpty()) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 1, subscription_);
}
if (ackDeadlineSeconds_ != 0) {
output.writeInt32(3, ackDeadlineSeconds_);
}
for (int i = 0; i < ackIds_.size(); i++) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 4, ackIds_.getRaw(i));
}
unknownFields.writeTo(output);
}
代码示例来源:origin: apache/incubator-shardingsphere
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
if (!name_.isEmpty()) {
output.writeBytes(1, name_);
}
for (int i = 0; i < keyPermission_.size(); i++) {
output.writeMessage(2, keyPermission_.get(i));
}
unknownFields.writeTo(output);
}
代码示例来源:origin: google/error-prone
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
if (!getClassNameBytes().isEmpty()) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 1, className_);
}
for (int i = 0; i < member_.size(); i++) {
output.writeMessage(2, member_.get(i));
}
unknownFields.writeTo(output);
}
代码示例来源:origin: alibaba/canal
@java.lang.Override
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
if (errorCodePresentCase_ == 1) {
output.writeInt32(
1, (int)((java.lang.Integer) errorCodePresent_));
}
if (!getErrorMessageBytes().isEmpty()) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 2, errorMessage_);
}
unknownFields.writeTo(output);
}
代码示例来源:origin: apache/incubator-shardingsphere
@java.lang.Override
public int hashCode() {
if (memoizedHashCode != 0) {
return memoizedHashCode;
}
int hash = 41;
hash = (19 * hash) + getDescriptor().hashCode();
hash = (37 * hash) + PERMTYPE_FIELD_NUMBER;
hash = (53 * hash) + permType_;
hash = (37 * hash) + KEY_FIELD_NUMBER;
hash = (53 * hash) + getKey().hashCode();
hash = (37 * hash) + RANGE_END_FIELD_NUMBER;
hash = (53 * hash) + getRangeEnd().hashCode();
hash = (29 * hash) + unknownFields.hashCode();
memoizedHashCode = hash;
return hash;
}
代码示例来源:origin: alibaba/canal
@java.lang.Override
public int getSerializedSize() {
int size = memoizedSize;
if (size != -1) return size;
size = 0;
if (errorCodePresentCase_ == 1) {
size += com.google.protobuf.CodedOutputStream
.computeInt32Size(
1, (int)((java.lang.Integer) errorCodePresent_));
}
if (!getErrorMessageBytes().isEmpty()) {
size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, errorMessage_);
}
size += unknownFields.getSerializedSize();
memoizedSize = size;
return size;
}
代码示例来源:origin: alibaba/canal
@java.lang.Override
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
if (!getDestinationBytes().isEmpty()) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 1, destination_);
}
if (!getClientIdBytes().isEmpty()) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 2, clientId_);
}
if (!getFilterBytes().isEmpty()) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 7, filter_);
}
unknownFields.writeTo(output);
}
代码示例来源:origin: alibaba/canal
/**
* <code>string filter = 7;</code>
*/
public java.lang.String getFilter() {
java.lang.Object ref = filter_;
if (!(ref instanceof java.lang.String)) {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
filter_ = s;
return s;
} else {
return (java.lang.String) ref;
}
}
/**
代码示例来源:origin: apache/incubator-shardingsphere
@java.lang.Override
public boolean equals(final java.lang.Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof authpb.Auth.Permission)) {
return super.equals(obj);
}
authpb.Auth.Permission other = (authpb.Auth.Permission) obj;
boolean result = true;
result = result && permType_ == other.permType_;
result = result && getKey()
.equals(other.getKey());
result = result && getRangeEnd()
.equals(other.getRangeEnd());
result = result && unknownFields.equals(other.unknownFields);
return result;
}
代码示例来源:origin: weibocom/motan
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
if (location_ != null) {
output.writeMessage(1, getLocation());
}
if (!getMessageBytes().isEmpty()) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 2, message_);
}
}
代码示例来源:origin: Graylog2/graylog2-server
public byte[] getPayload() {
return msgBuilder.getPayload().toByteArray(); // TODO PERFORMANCE array copy
}
内容来源于网络,如有侵权,请联系作者删除!