本文整理汇总了Java中com.google.protobuf.DescriptorProtos类的典型用法代码示例。如果您正苦于以下问题:Java DescriptorProtos类的具体用法?Java DescriptorProtos怎么用?Java DescriptorProtos使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DescriptorProtos类属于com.google.protobuf包,在下文中一共展示了DescriptorProtos类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: extractServiceContext
import com.google.protobuf.DescriptorProtos; //导入依赖的package包/类
private Context extractServiceContext(
ProtoTypeMap protoTypeMap,
DescriptorProtos.ServiceDescriptorProto serviceProto) {
Context ctx = new Context();
ctx.fileName = serviceProto.getName() + CLASS_SUFFIX + ".java";
ctx.className = serviceProto.getName() + CLASS_SUFFIX;
ctx.serviceName = serviceProto.getName();
ctx.deprecated = serviceProto.getOptions() != null && serviceProto.getOptions().getDeprecated();
// Identify methods to generate a CompletableFuture-based client for.
// Only unary methods are supported.
serviceProto.getMethodList().stream()
.filter(method -> !method.getClientStreaming() && !method.getServerStreaming())
.forEach(method -> {
ContextMethod ctxMethod = new ContextMethod();
ctxMethod.methodName = lowerCaseFirst(method.getName());
ctxMethod.inputType = protoTypeMap.toJavaTypeName(method.getInputType());
ctxMethod.outputType = protoTypeMap.toJavaTypeName(method.getOutputType());
ctxMethod.deprecated = method.getOptions() != null && method.getOptions().getDeprecated();
ctx.methods.add(ctxMethod);
});
return ctx;
}
示例2: ProtoLocation
import com.google.protobuf.DescriptorProtos; //导入依赖的package包/类
public ProtoLocation(
DescriptorProtos.SourceCodeInfo.Location location, final ProtoElement element) {
// Spit out "?:?" for line:column if there's no "span" set in the location. This can happen
// when (for example) a proto transform tool synthesizes a field that doesn't appear in the
// source *.proto files.
if (location.getSpanCount() > 0) {
this.displayString =
String.format(
"%s:%d:%d",
element.getFile().getLocation().getDisplayString(),
location.getSpan(0) + 1,
location.getSpan(1) + 1);
} else {
this.displayString =
String.format("%s:?:?", element.getFile().getLocation().getDisplayString());
}
this.element = element;
}
示例3: add
import com.google.protobuf.DescriptorProtos; //导入依赖的package包/类
private void add(List<FieldDescriptorProto> extensions) {
for (int i = 0; i < extensions.size(); i++) {
pathSegments.push(i);
FieldDescriptorProto extensionProto = extensions.get(i);
String extendee = resolve(extensionProto.getExtendee());
Multimap<String, Extension> messageExtensions = builder.get(extendee);
if (messageExtensions == null) {
messageExtensions = ArrayListMultimap.create();
builder.put(extendee, messageExtensions);
}
String path = DOT_JOINER.join(pathSegments.descendingIterator());
DescriptorProtos.SourceCodeInfo.Location location = locationMap.get(path).get(0);
// Since paths are only unique within a file, we need a synthetic path to make them unique,
// given that paths are used to uniquely identify elements in a ProtoFile, and we're
// stuffing elements from another file into it.
path = currentFile.getName() + ":" + path;
Location fileLocation = new SimpleLocation(String.format(
"%s:%d:%d", currentFile.getName(), location.getSpan(0) + 1, location.getSpan(1) + 1));
Extension extension = new Extension(extensionProto, location, path, fileLocation);
messageExtensions.put(getExtensionFieldName(extensionProto.getName()), extension);
pathSegments.pop();
}
}
示例4: getFileDescProtoForMsgType
import com.google.protobuf.DescriptorProtos; //导入依赖的package包/类
private static DescriptorProtos.FileDescriptorProto getFileDescProtoForMsgType(
String packageName,
String messageType,
DescriptorProtos.FileDescriptorSet set
) {
DescriptorProtos.FileDescriptorProto file = null;
for (DescriptorProtos.FileDescriptorProto fileDescriptorProto : set.getFileList()) {
if (!packageMatch(fileDescriptorProto, packageName)) {
continue;
}
file = containsMessageType(fileDescriptorProto, messageType);
if (file != null) {
break;
}
}
return file;
}
示例5: doTest
import com.google.protobuf.DescriptorProtos; //导入依赖的package包/类
/**
* Write a protobuf to a buffer 'numProtos' times, and then
* read them back, making sure all data comes through correctly.
*/
private void doTest(int numProtos) throws IOException {
Configuration conf = new Configuration();
DataOutputBuffer out = new DataOutputBuffer();
// Write numProtos protobufs to the buffer
Message[] sent = new Message[numProtos];
for (int i = 0; i < numProtos; i++) {
// Construct a test protocol buffer using one of the
// protos that ships with the protobuf library
Message testProto = DescriptorProtos.EnumValueDescriptorProto.newBuilder()
.setName("test" + i).setNumber(i).build();
ObjectWritable.writeObject(out, testProto,
DescriptorProtos.EnumValueDescriptorProto.class, conf);
sent[i] = testProto;
}
// Read back the data
DataInputBuffer in = new DataInputBuffer();
in.reset(out.getData(), out.getLength());
for (int i = 0; i < numProtos; i++) {
Message received = (Message)ObjectWritable.readObject(in, conf);
assertEquals(sent[i], received);
}
}
示例6: of
import com.google.protobuf.DescriptorProtos; //导入依赖的package包/类
/**
* Returns an instance of {@link ProtoTypeMap} based on the given FileDescriptorProto instances.
*
* @param fileDescriptorProtos the full collection of files descriptors from the code generator request
*/
public static ProtoTypeMap of(@Nonnull Collection<DescriptorProtos.FileDescriptorProto> fileDescriptorProtos) {
Preconditions.checkNotNull(fileDescriptorProtos, "fileDescriptorProtos");
Preconditions.checkArgument(!fileDescriptorProtos.isEmpty(), "fileDescriptorProtos.isEmpty()");
final ImmutableMap.Builder<String, String> types = ImmutableMap.builder();
for (final DescriptorProtos.FileDescriptorProto fileDescriptor : fileDescriptorProtos) {
final DescriptorProtos.FileOptions fileOptions = fileDescriptor.getOptions();
final String protoPackage = fileDescriptor.hasPackage() ? "." + fileDescriptor.getPackage() : "";
final String javaPackage = Strings.emptyToNull(
fileOptions.hasJavaPackage() ?
fileOptions.getJavaPackage() :
fileDescriptor.getPackage());
final String enclosingClassName =
fileOptions.getJavaMultipleFiles() ?
null :
getJavaOuterClassname(fileDescriptor, fileOptions);
fileDescriptor.getEnumTypeList().forEach(
e -> types.put(
protoPackage + "." + e.getName(),
toJavaTypeName(e.getName(), enclosingClassName, javaPackage)));
fileDescriptor.getMessageTypeList().forEach(
m -> types.put(
protoPackage + "." + m.getName(),
toJavaTypeName(m.getName(), enclosingClassName, javaPackage)));
}
return new ProtoTypeMap(types.build());
}
示例7: getJavaOuterClassname
import com.google.protobuf.DescriptorProtos; //导入依赖的package包/类
private static String getJavaOuterClassname(
DescriptorProtos.FileDescriptorProto fileDescriptor,
DescriptorProtos.FileOptions fileOptions) {
if (fileOptions.hasJavaOuterClassname()) {
return fileOptions.getJavaOuterClassname();
}
// If the outer class name is not explicitly defined, then we take the proto filename, strip its extension,
// and convert it from snake case to camel case.
String filename = fileDescriptor.getName().substring(0, fileDescriptor.getName().length() - ".proto".length());
filename = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, filename);
return appendOuterClassSuffix(filename, fileDescriptor);
}
示例8: appendOuterClassSuffix
import com.google.protobuf.DescriptorProtos; //导入依赖的package包/类
/**
* In the event of a name conflict between the outer and inner type names, protoc adds an OuterClass suffix to the
* outer type's name.
*/
private static String appendOuterClassSuffix(final String enclosingClassName, DescriptorProtos.FileDescriptorProto fd) {
if (fd.getEnumTypeList().stream().anyMatch(enumProto -> enumProto.getName().equals(enclosingClassName)) ||
fd.getMessageTypeList().stream().anyMatch(messageProto -> messageProto.getName().equals(enclosingClassName))) {
return enclosingClassName + "OuterClass";
} else {
return enclosingClassName;
}
}
示例9: extractContext
import com.google.protobuf.DescriptorProtos; //导入依赖的package包/类
private Stream<Context> extractContext(ProtoTypeMap protoTypeMap, DescriptorProtos.FileDescriptorProto proto) {
return proto.getServiceList().stream()
.map(s -> extractServiceContext(protoTypeMap, s))
.map(ctx -> {
ctx.packageName = extractPackageName(proto); return ctx;
})
.map(ctx -> {
ctx.protoName = proto.getName(); return ctx;
});
}
示例10: extractPackageName
import com.google.protobuf.DescriptorProtos; //导入依赖的package包/类
private String extractPackageName(DescriptorProtos.FileDescriptorProto proto) {
DescriptorProtos.FileOptions options = proto.getOptions();
if (options != null) {
String javaPackage = options.getJavaPackage();
if (!Strings.isNullOrEmpty(javaPackage)) {
return javaPackage;
}
}
return Strings.nullToEmpty(proto.getPackage());
}
示例11: Extension
import com.google.protobuf.DescriptorProtos; //导入依赖的package包/类
private Extension(FieldDescriptorProto proto, DescriptorProtos.SourceCodeInfo.Location location,
String path, Location fileLocation) {
this.proto = proto;
this.location = location;
this.path = path;
this.fileLocation = fileLocation;
}
示例12: buildLocationMap
import com.google.protobuf.DescriptorProtos; //导入依赖的package包/类
private static ImmutableListMultimap<String, DescriptorProtos.SourceCodeInfo.Location>
buildLocationMap(FileDescriptorProto file) {
return Multimaps.<String, DescriptorProtos.SourceCodeInfo.Location>index(
file.getSourceCodeInfo().getLocationList(),
new Function<DescriptorProtos.SourceCodeInfo.Location, String>() {
@Override
public String apply(DescriptorProtos.SourceCodeInfo.Location location) {
return DOT_JOINER.join(location.getPathList());
}
});
}
示例13: getDocumentation
import com.google.protobuf.DescriptorProtos; //导入依赖的package包/类
private String getDocumentation(String path) {
String comment = "";
DescriptorProtos.SourceCodeInfo.Location location = getSourceCodeLocation(path);
if (location != null) {
if (!Strings.isNullOrEmpty(location.getLeadingComments())) {
comment = location.getLeadingComments();
}
if (!Strings.isNullOrEmpty(location.getTrailingComments())){
comment += location.getTrailingComments();
}
}
return comment;
}
示例14: getSourceCodeLocation
import com.google.protobuf.DescriptorProtos; //导入依赖的package包/类
private DescriptorProtos.SourceCodeInfo.Location getSourceCodeLocation(String path) {
if (locationMap.containsKey(path)) {
// We get the first location.
return locationMap.get(path).get(0);
} else {
return null;
}
}
示例15: getAllFileDescriptors
import com.google.protobuf.DescriptorProtos; //导入依赖的package包/类
/**
* Loads a Protobuf file descriptor set into an ubermap of file descriptors.
*
* @param set FileDescriptorSet
* @param dependenciesMap FileDescriptor dependency map
* @param fileDescriptorMap The populated map of FileDescriptors
* @throws StageException
*/
public static void getAllFileDescriptors(
DescriptorProtos.FileDescriptorSet set,
Map<String, Set<Descriptors.FileDescriptor>> dependenciesMap,
Map<String, Descriptors.FileDescriptor> fileDescriptorMap
) throws StageException {
List<DescriptorProtos.FileDescriptorProto> fileList = set.getFileList();
try {
for (DescriptorProtos.FileDescriptorProto fdp : fileList) {
if (!fileDescriptorMap.containsKey(fdp.getName())) {
Set<Descriptors.FileDescriptor> dependencies = dependenciesMap.get(fdp.getName());
if (dependencies == null) {
dependencies = new LinkedHashSet<>();
dependenciesMap.put(fdp.getName(), dependencies);
dependencies.addAll(getDependencies(dependenciesMap, fileDescriptorMap, fdp, set));
}
Descriptors.FileDescriptor fileDescriptor = Descriptors.FileDescriptor.buildFrom(
fdp,
dependencies.toArray(new Descriptors.FileDescriptor[dependencies.size()])
);
fileDescriptorMap.put(fdp.getName(), fileDescriptor);
}
}
} catch (Descriptors.DescriptorValidationException e) {
throw new StageException(Errors.PROTOBUF_07, e.getDescription(), e);
}
}