use of com.google.protobuf.DescriptorProtos.FileDescriptorProto in project dubbo by alibaba.
the class AbstractGenerator method generateFiles.
@Override
public List<PluginProtos.CodeGeneratorResponse.File> generateFiles(PluginProtos.CodeGeneratorRequest request) throws GeneratorException {
final ProtoTypeMap typeMap = ProtoTypeMap.of(request.getProtoFileList());
List<FileDescriptorProto> protosToGenerate = request.getProtoFileList().stream().filter(protoFile -> request.getFileToGenerateList().contains(protoFile.getName())).collect(Collectors.toList());
List<ServiceContext> services = findServices(protosToGenerate, typeMap);
return generateFiles(services);
}
use of com.google.protobuf.DescriptorProtos.FileDescriptorProto in project atlasdb by palantir.
the class ColumnValueDescription method hydrateFileDescriptorTree.
private static FileDescriptor hydrateFileDescriptorTree(FileDescriptorTreeProto proto) throws DescriptorValidationException, InvalidProtocolBufferException {
FileDescriptor[] dependencies = new FileDescriptor[proto.getDependenciesCount()];
for (int i = 0; i < proto.getDependenciesCount(); i++) {
dependencies[i] = hydrateFileDescriptorTree(proto.getDependencies(i));
}
FileDescriptorProto fileProto = FileDescriptorProto.parseFrom(proto.getProtoFileDescriptor());
return FileDescriptor.buildFrom(fileProto, dependencies);
}
use of com.google.protobuf.DescriptorProtos.FileDescriptorProto in project toolkit by googleapis.
the class ProtocGeneratorMain method parseOptions.
private static ToolOptions parseOptions(CodeGeneratorRequest request) throws Exception {
List<FileDescriptorProto> fileDescriptorProtoList = request.getProtoFileList();
FileDescriptorSet descriptorSet = FileDescriptorSet.newBuilder().addAllFile(fileDescriptorProtoList).build();
// Write out DescriptorSet to temp file.
File descriptorSetFile;
descriptorSetFile = File.createTempFile("api", ".desc");
FileOutputStream fileoutput = new FileOutputStream(descriptorSetFile);
descriptorSet.writeTo(fileoutput);
fileoutput.close();
descriptorSetFile.deleteOnExit();
List<String> parsedArgs = new LinkedList<>();
parsedArgs.add("--descriptor_set");
parsedArgs.add(descriptorSetFile.getAbsolutePath());
List<String> protoPackages = getProtoPackageList(request);
if (protoPackages.size() > 1) {
// can be changed when the use case arises.
throw new IllegalStateException(String.format("Not expecting more than one proto package." + " Found proto packages for generation: %s", protoPackages.toString()));
} else if (protoPackages.size() == 0) {
throw new IllegalStateException("No proto files given to generate.");
}
parsedArgs.add("--package");
parsedArgs.add(protoPackages.get(0));
// Parse plugin params, ignoring unknown params.
String[] requestArgs = request.getParameter().split(",");
for (String arg : requestArgs) {
if (Strings.isNullOrEmpty(arg))
continue;
parsedArgs.add("--" + arg);
}
String[] argsArray = parsedArgs.toArray(new String[] {});
return GeneratorMain.createCodeGeneratorOptionsFromProtoc(argsArray);
}
use of com.google.protobuf.DescriptorProtos.FileDescriptorProto in project BIMserver by opensourceBIM.
the class ProtocolBuffersMetaData method load.
public void load(InputStream inputStream) {
try {
FileDescriptorSet descriptorSet = FileDescriptorSet.parseFrom(inputStream);
List<FileDescriptorProto> fileList = descriptorSet.getFileList();
FileDescriptorProto fileDescriptorProto = fileList.get(0);
FileDescriptor[] dependencyDescriptors = getDependencyDescriptors(fileDescriptorProto);
FileDescriptor fileDescriptor = FileDescriptor.buildFrom(fileDescriptorProto, dependencyDescriptors);
loaded.put(fileDescriptor.getName(), fileDescriptor);
fileDescriptor.getMessageTypes().forEach(descriptor -> this.messageDescriptors.put(descriptor.getName(), new MessageDescriptorContainer(descriptor)));
fileDescriptor.getServices().forEach(serviceDescriptor -> this.serviceDescriptors.put(serviceDescriptor.getName(), new ServiceDescriptorContainer(serviceDescriptor)));
} catch (IOException e) {
LOGGER.error("", e);
} catch (DescriptorValidationException e) {
LOGGER.error("", e);
} finally {
try {
inputStream.close();
} catch (IOException e) {
LOGGER.error("", e);
}
}
}
Aggregations