本文整理匯總了Java中com.google.protobuf.ByteString.toStringUtf8方法的典型用法代碼示例。如果您正苦於以下問題:Java ByteString.toStringUtf8方法的具體用法?Java ByteString.toStringUtf8怎麽用?Java ByteString.toStringUtf8使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.protobuf.ByteString
的用法示例。
在下文中一共展示了ByteString.toStringUtf8方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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());
});
}
示例2: 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);
Long userId = Long.valueOf(tokenArg.toStringUtf8());
RoomGroup.getRoomManger().onOnline(ctx, userId);
return userId;
});
}
示例3: collectFileData
import com.google.protobuf.ByteString; //導入方法依賴的package包/類
@Override
protected List<String> collectFileData() {
String sourePackageName = super.getSourcePackageName();
String className = super.getClassName();
String packageName = sourePackageName.toLowerCase();
List<String> packageData = Lists.newArrayList();
packageData.add("package " + packageName + ";");
packageData.add("");
List<String> importData = Lists.newArrayList();
importData.add("import com.quancheng.saluki.serializer.ProtobufAttribute;");
importData.add("import com.quancheng.saluki.serializer.ProtobufEntity;");
List<String> classAnnotationData = Lists.newArrayList();
classAnnotationData.add("");
classAnnotationData.add("@ProtobufEntity(" + sourePackageName + "." + className + ".class)");
boolean validator = false;
List<String> fileData = Lists.newArrayList();
fileData.add("public class " + className + "{");
for (int i = 0; i < messageFields.size(); i++) {
FieldDescriptorProto messageField = messageFields.get(i);
String javaType = findJavaType(packageName, sourceMessageDesc, messageField);
if (messageField.getLabel() == Label.LABEL_REPEATED && javaType != null) {
if (!javaType.contains("java.util.Map")) {
javaType = "java.util.ArrayList<" + javaType + ">";
}
}
fileData.add("");
String fieldName = messageField.getName();
UnknownFieldSet unknownFields = messageField.getOptions().getUnknownFields();
if (unknownFields != null) {
for (Map.Entry<Integer, UnknownFieldSet.Field> integerFieldEntry : unknownFields.asMap()
.entrySet()) {
for (ByteString byteString : integerFieldEntry.getValue().getLengthDelimitedList()) {
validator = true;
String validateMsg = byteString.toStringUtf8();
fileData.add(" " + validateMsg);
}
}
}
fileData.add(" @ProtobufAttribute");
fileData.add(" private " + javaType + " " + fieldName + ";");
fileData.add("");
fileData.add(" public " + javaType + " get" + captureName(fieldName) + "() {");
fileData.add(" return this." + fieldName + ";");
fileData.add(" }");
fileData.add("");
fileData.add(" public void set" + captureName(fieldName) + "(" + javaType + " " + fieldName
+ ") {");
fileData.add(" this." + fieldName + "=" + fieldName + ";");
fileData.add(" }");
fileData.add("");
}
fileData.add("}");
if (validator) {
importData.add("import com.quancheng.saluki.core.grpc.annotation.ArgValidator;");
classAnnotationData.add("@ArgValidator");
}
packageData.addAll(importData);
packageData.addAll(classAnnotationData);
packageData.addAll(fileData);
return packageData;
}