use of com.google.protobuf.DescriptorProtos.FileDescriptorSet in project tesla by linking12.
the class ProtobufUtil method findDirectyprotobuf.
private static Pair<Descriptor, Descriptor> findDirectyprotobuf(final FilterRpcDO rpcDo) {
byte[] protoContent = rpcDo.getProtoContext();
FileDescriptorSet descriptorSet = null;
if (protoContent != null && protoContent.length > 0) {
try {
descriptorSet = FileDescriptorSet.parseFrom(protoContent);
ServiceResolver serviceResolver = ServiceResolver.fromFileDescriptorSet(descriptorSet);
ProtoMethodName protoMethodName = ProtoMethodName.parseFullGrpcMethodName(rpcDo.getServiceName() + "/" + rpcDo.getMethodName());
MethodDescriptor protoMethodDesc = serviceResolver.resolveServiceMethod(protoMethodName);
return new ImmutablePair<Descriptor, Descriptor>(protoMethodDesc.getInputType(), protoMethodDesc.getOutputType());
} catch (InvalidProtocolBufferException e) {
LOG.error(e.getMessage(), e);
throw new RpcBizException("protobuf service definition is invalid,the descriptorSet is: " + descriptorSet, e);
}
}
return null;
}
use of com.google.protobuf.DescriptorProtos.FileDescriptorSet 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.FileDescriptorSet 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