/** Lists the GRPC services - filtered by service name (contains) or method name (contains) */
public static void listServices(
Output output,
FileDescriptorSet fileDescriptorSet,
String protoDiscoveryRoot,
Optional<String> serviceFilter,
Optional<String> methodFilter,
Optional<Boolean> withMessage) {
ServiceResolver serviceResolver = ServiceResolver.fromFileDescriptorSet(fileDescriptorSet);
// Add white-space before the rendered output
output.newLine();
for (ServiceDescriptor descriptor : serviceResolver.listServices()) {
boolean matchingDescriptor =
!serviceFilter.isPresent()
|| descriptor.getFullName().toLowerCase().contains(serviceFilter.get().toLowerCase());
if (matchingDescriptor) {
listMethods(output, protoDiscoveryRoot, descriptor, methodFilter, withMessage);
}
}
}
java类com.google.protobuf.Descriptors.ServiceDescriptor的实例源码
ServiceList.java 文件源码
项目:polyglot
阅读 35
收藏 0
点赞 0
评论 0
GpbMessageContext.java 文件源码
项目:Okra-Ax
阅读 28
收藏 0
点赞 0
评论 0
public void registerGpbMsgDesc(FileDescriptor fileDescriptor) {
if (fileDescriptor == null) return;
// service
for (ServiceDescriptor service : fileDescriptor.getServices()) {
for (MethodDescriptor method : service.getMethods()) {
if (gpbMsgDescMap.containsKey(method.getName())) {
LOG.error("[Gpb] the method [" + method.getName() + "] already registered.");
}
registerGpbMessage(method.getInputType());
methodInputTypeMap.put(method.getName(), method.getInputType().getName());
}
}
// message
for (Descriptor descriptor : fileDescriptor.getMessageTypes()) {
registerGpbMessage(descriptor);
}
}
ProtoReflectionService.java 文件源码
项目:grpc-java
阅读 32
收藏 0
点赞 0
评论 0
private void processService(ServiceDescriptor service, FileDescriptor fd) {
String serviceName = service.getFullName();
checkState(
!fileDescriptorsBySymbol.containsKey(serviceName),
"Service already defined: %s",
serviceName);
fileDescriptorsBySymbol.put(serviceName, fd);
for (MethodDescriptor method : service.getMethods()) {
String methodName = method.getFullName();
checkState(
!fileDescriptorsBySymbol.containsKey(methodName),
"Method already defined: %s",
methodName);
fileDescriptorsBySymbol.put(methodName, fd);
}
}
DescriptorsTest.java 文件源码
项目:sstore-soft
阅读 30
收藏 0
点赞 0
评论 0
public void testServiceDescriptor() throws Exception {
ServiceDescriptor service = TestService.getDescriptor();
assertEquals("TestService", service.getName());
assertEquals("protobuf_unittest.TestService", service.getFullName());
assertEquals(UnittestProto.getDescriptor(), service.getFile());
assertEquals(2, service.getMethods().size());
MethodDescriptor fooMethod = service.getMethods().get(0);
assertEquals("Foo", fooMethod.getName());
assertEquals(UnittestProto.FooRequest.getDescriptor(),
fooMethod.getInputType());
assertEquals(UnittestProto.FooResponse.getDescriptor(),
fooMethod.getOutputType());
assertEquals(fooMethod, service.findMethodByName("Foo"));
MethodDescriptor barMethod = service.getMethods().get(1);
assertEquals("Bar", barMethod.getName());
assertEquals(UnittestProto.BarRequest.getDescriptor(),
barMethod.getInputType());
assertEquals(UnittestProto.BarResponse.getDescriptor(),
barMethod.getOutputType());
assertEquals(barMethod, service.findMethodByName("Bar"));
assertNull(service.findMethodByName("NoSuchMethod"));
for (int i = 0; i < service.getMethods().size(); i++) {
assertEquals(i, service.getMethods().get(i).getIndex());
}
}
DescriptorsTest.java 文件源码
项目:s-store
阅读 33
收藏 0
点赞 0
评论 0
public void testServiceDescriptor() throws Exception {
ServiceDescriptor service = TestService.getDescriptor();
assertEquals("TestService", service.getName());
assertEquals("protobuf_unittest.TestService", service.getFullName());
assertEquals(UnittestProto.getDescriptor(), service.getFile());
assertEquals(2, service.getMethods().size());
MethodDescriptor fooMethod = service.getMethods().get(0);
assertEquals("Foo", fooMethod.getName());
assertEquals(UnittestProto.FooRequest.getDescriptor(),
fooMethod.getInputType());
assertEquals(UnittestProto.FooResponse.getDescriptor(),
fooMethod.getOutputType());
assertEquals(fooMethod, service.findMethodByName("Foo"));
MethodDescriptor barMethod = service.getMethods().get(1);
assertEquals("Bar", barMethod.getName());
assertEquals(UnittestProto.BarRequest.getDescriptor(),
barMethod.getInputType());
assertEquals(UnittestProto.BarResponse.getDescriptor(),
barMethod.getOutputType());
assertEquals(barMethod, service.findMethodByName("Bar"));
assertNull(service.findMethodByName("NoSuchMethod"));
for (int i = 0; i < service.getMethods().size(); i++) {
assertEquals(i, service.getMethods().get(i).getIndex());
}
}
NrpcServiceRegistry.java 文件源码
项目:JavaNRPC
阅读 28
收藏 0
点赞 0
评论 0
/**
* Get matching method.
*/
public MethodDescriptor getMethod(String methodName, ServiceDescriptor descriptor) throws MethodNotFoundException {
MethodDescriptor method = descriptor.findMethodByName(methodName);
if (method == null) {
throw new MethodNotFoundException(
String.format("Could not find method %s in service %s", methodName, descriptor.getFullName())
);
}
return method;
}
ServiceResolver.java 文件源码
项目:polyglot
阅读 24
收藏 0
点赞 0
评论 0
/** Lists all of the services found in the file descriptors */
public Iterable<ServiceDescriptor> listServices() {
ArrayList<ServiceDescriptor> serviceDescriptors = new ArrayList<ServiceDescriptor>();
for (FileDescriptor fileDescriptor: fileDescriptors) {
serviceDescriptors.addAll(fileDescriptor.getServices());
}
return serviceDescriptors;
}
ServiceResolver.java 文件源码
项目:polyglot
阅读 25
收藏 0
点赞 0
评论 0
private MethodDescriptor resolveServiceMethod(
String serviceName, String methodName, String packageName) {
ServiceDescriptor service = findService(serviceName, packageName);
MethodDescriptor method = service.findMethodByName(methodName);
if (method == null) {
throw new IllegalArgumentException(
"Unable to find method " + methodName + " in service " + serviceName);
}
return method;
}
ServiceResolver.java 文件源码
项目:polyglot
阅读 34
收藏 0
点赞 0
评论 0
private ServiceDescriptor findService(String serviceName, String packageName) {
// TODO(dino): Consider creating an index.
for (FileDescriptor fileDescriptor : fileDescriptors) {
if (!fileDescriptor.getPackage().equals(packageName)) {
// Package does not match this file, ignore.
continue;
}
ServiceDescriptor serviceDescriptor = fileDescriptor.findServiceByName(serviceName);
if (serviceDescriptor != null) {
return serviceDescriptor;
}
}
throw new IllegalArgumentException("Unable to find service with name: " + serviceName);
}
ServiceList.java 文件源码
项目:polyglot
阅读 28
收藏 0
点赞 0
评论 0
/** Lists the methods on the service (the methodFilter will be applied if non-empty) */
private static void listMethods(
Output output,
String protoDiscoveryRoot,
ServiceDescriptor descriptor,
Optional<String> methodFilter,
Optional<Boolean> withMessage) {
boolean printedService = false;
// Due to the way the protos are discovered, the leaf directly of the protoDiscoveryRoot
// is the same as the root directory as the proto file
File protoDiscoveryDir = new File(protoDiscoveryRoot).getParentFile();
for (MethodDescriptor method : descriptor.getMethods()) {
if (!methodFilter.isPresent() || method.getName().contains(methodFilter.get())) {
// Only print the service name once - and only if a method is going to be printed
if (!printedService) {
File pFile = new File(protoDiscoveryDir, descriptor.getFile().getName());
output.writeLine(descriptor.getFullName() + " -> " + pFile.getAbsolutePath());
printedService = true;
}
output.writeLine(" " + descriptor.getFullName() + "/" + method.getName());
// If requested, add the message definition
if (withMessage.isPresent() && withMessage.get()) {
output.writeLine(renderDescriptor(method.getInputType(), " "));
output.newLine();
}
}
}
if (printedService) {
output.newLine();
}
}
RpcForwarder.java 文件源码
项目:protobuf-socket-rpc
阅读 29
收藏 0
点赞 0
评论 0
/**
* Get matching method.
*/
private MethodDescriptor getMethod(SocketRpcProtos.Request rpcRequest,
ServiceDescriptor descriptor) throws RpcException {
MethodDescriptor method = descriptor.findMethodByName(
rpcRequest.getMethodName());
if (method == null) {
throw new RpcException(
ErrorReason.METHOD_NOT_FOUND,
String.format("Could not find method %s in service %s",
rpcRequest.getMethodName(), descriptor.getFullName()),
null);
}
return method;
}
DescriptorsTest.java 文件源码
项目:vsminecraft
阅读 33
收藏 0
点赞 0
评论 0
public void testServiceDescriptor() throws Exception {
ServiceDescriptor service = TestService.getDescriptor();
assertEquals("TestService", service.getName());
assertEquals("protobuf_unittest.TestService", service.getFullName());
assertEquals(UnittestProto.getDescriptor(), service.getFile());
MethodDescriptor fooMethod = service.getMethods().get(0);
assertEquals("Foo", fooMethod.getName());
assertEquals(UnittestProto.FooRequest.getDescriptor(),
fooMethod.getInputType());
assertEquals(UnittestProto.FooResponse.getDescriptor(),
fooMethod.getOutputType());
assertEquals(fooMethod, service.findMethodByName("Foo"));
MethodDescriptor barMethod = service.getMethods().get(1);
assertEquals("Bar", barMethod.getName());
assertEquals(UnittestProto.BarRequest.getDescriptor(),
barMethod.getInputType());
assertEquals(UnittestProto.BarResponse.getDescriptor(),
barMethod.getOutputType());
assertEquals(barMethod, service.findMethodByName("Bar"));
assertNull(service.findMethodByName("NoSuchMethod"));
for (int i = 0; i < service.getMethods().size(); i++) {
assertEquals(i, service.getMethods().get(i).getIndex());
}
}
CoprocessorRpcUtils.java 文件源码
项目:hbase
阅读 33
收藏 0
点赞 0
评论 0
/**
* Returns the name to use for coprocessor service calls. For core HBase services
* (in the hbase.pb protobuf package), this returns the unqualified name in order to provide
* backward compatibility across the package name change. For all other services,
* the fully-qualified service name is used.
*/
public static String getServiceName(Descriptors.ServiceDescriptor service) {
if (service.getFullName().startsWith(hbaseServicePackage)) {
return service.getName();
}
return service.getFullName();
}
CoprocessorRpcUtils.java 文件源码
项目:hbase
阅读 27
收藏 0
点赞 0
评论 0
public static MethodDescriptor getMethodDescriptor(final String methodName,
final ServiceDescriptor serviceDesc)
throws UnknownProtocolException {
Descriptors.MethodDescriptor methodDesc = serviceDesc.findMethodByName(methodName);
if (methodDesc == null) {
throw new UnknownProtocolException("Unknown method " + methodName + " called on service " +
serviceDesc.getFullName());
}
return methodDesc;
}
FileDescriptors.java 文件源码
项目:protobuf-el
阅读 31
收藏 0
点赞 0
评论 0
private void makeCanonicalService(final ServiceDescriptorProto.Builder service,
final ServiceDescriptor serviceDescriptor) {
for (final MethodDescriptorProto.Builder method : service.getMethodBuilderList()) {
final MethodDescriptor methodDescriptor =
serviceDescriptor.findMethodByName(method.getName());
method.setInputType(ensureLeadingDot(methodDescriptor.getInputType().getFullName()));
method.setOutputType(ensureLeadingDot(methodDescriptor.getOutputType().getFullName()));
}
}
FileDescriptorEx.java 文件源码
项目:protobuf-el
阅读 31
收藏 0
点赞 0
评论 0
private void makeCanonicalService(final ServiceDescriptorProto.Builder service,
final ServiceDescriptor serviceDescriptor) {
for (final MethodDescriptorProto.Builder method : service.getMethodBuilderList()) {
final MethodDescriptor methodDescriptor =
serviceDescriptor.findMethodByName(method.getName());
method.setInputType(ensureLeadingDot(methodDescriptor.getInputType().getFullName()));
method.setOutputType(ensureLeadingDot(methodDescriptor.getOutputType().getFullName()));
}
}
DescriptorsTest.java 文件源码
项目:bazel
阅读 37
收藏 0
点赞 0
评论 0
public void testServiceDescriptor() throws Exception {
ServiceDescriptor service = TestService.getDescriptor();
assertEquals("TestService", service.getName());
assertEquals("protobuf_unittest.TestService", service.getFullName());
assertEquals(UnittestProto.getDescriptor(), service.getFile());
assertEquals(2, service.getMethods().size());
MethodDescriptor fooMethod = service.getMethods().get(0);
assertEquals("Foo", fooMethod.getName());
assertEquals(UnittestProto.FooRequest.getDescriptor(),
fooMethod.getInputType());
assertEquals(UnittestProto.FooResponse.getDescriptor(),
fooMethod.getOutputType());
assertEquals(fooMethod, service.findMethodByName("Foo"));
MethodDescriptor barMethod = service.getMethods().get(1);
assertEquals("Bar", barMethod.getName());
assertEquals(UnittestProto.BarRequest.getDescriptor(),
barMethod.getInputType());
assertEquals(UnittestProto.BarResponse.getDescriptor(),
barMethod.getOutputType());
assertEquals(barMethod, service.findMethodByName("Bar"));
assertNull(service.findMethodByName("NoSuchMethod"));
for (int i = 0; i < service.getMethods().size(); i++) {
assertEquals(i, service.getMethods().get(i).getIndex());
}
}
DescriptorsTest.java 文件源码
项目:bazel
阅读 33
收藏 0
点赞 0
评论 0
public void testServiceDescriptor() throws Exception {
ServiceDescriptor service = TestService.getDescriptor();
assertEquals("TestService", service.getName());
assertEquals("protobuf_unittest.TestService", service.getFullName());
assertEquals(UnittestProto.getDescriptor(), service.getFile());
MethodDescriptor fooMethod = service.getMethods().get(0);
assertEquals("Foo", fooMethod.getName());
assertEquals(UnittestProto.FooRequest.getDescriptor(),
fooMethod.getInputType());
assertEquals(UnittestProto.FooResponse.getDescriptor(),
fooMethod.getOutputType());
assertEquals(fooMethod, service.findMethodByName("Foo"));
MethodDescriptor barMethod = service.getMethods().get(1);
assertEquals("Bar", barMethod.getName());
assertEquals(UnittestProto.BarRequest.getDescriptor(),
barMethod.getInputType());
assertEquals(UnittestProto.BarResponse.getDescriptor(),
barMethod.getOutputType());
assertEquals(barMethod, service.findMethodByName("Bar"));
assertNull(service.findMethodByName("NoSuchMethod"));
for (int i = 0; i < service.getMethods().size(); i++) {
assertEquals(i, service.getMethods().get(i).getIndex());
}
}
ProtoReflectionService.java 文件源码
项目:grpc-java
阅读 41
收藏 0
点赞 0
评论 0
/**
* Checks for updates to the server's mutable services and updates the index if any changes are
* detected. A change is any addition or removal in the set of file descriptors attached to the
* mutable services or a change in the service names.
*
* @return The (potentially updated) index.
*/
private ServerReflectionIndex updateIndexIfNecessary() {
synchronized (lock) {
if (serverReflectionIndex == null) {
serverReflectionIndex =
new ServerReflectionIndex(server.getImmutableServices(), server.getMutableServices());
return serverReflectionIndex;
}
Set<FileDescriptor> serverFileDescriptors = new HashSet<FileDescriptor>();
Set<String> serverServiceNames = new HashSet<String>();
List<ServerServiceDefinition> serverMutableServices = server.getMutableServices();
for (ServerServiceDefinition mutableService : serverMutableServices) {
io.grpc.ServiceDescriptor serviceDescriptor = mutableService.getServiceDescriptor();
if (serviceDescriptor.getSchemaDescriptor() instanceof ProtoFileDescriptorSupplier) {
String serviceName = serviceDescriptor.getName();
FileDescriptor fileDescriptor =
((ProtoFileDescriptorSupplier) serviceDescriptor.getSchemaDescriptor())
.getFileDescriptor();
serverFileDescriptors.add(fileDescriptor);
serverServiceNames.add(serviceName);
}
}
// Replace the index if the underlying mutable services have changed. Check both the file
// descriptors and the service names, because one file descriptor can define multiple
// services.
FileDescriptorIndex mutableServicesIndex = serverReflectionIndex.getMutableServicesIndex();
if (!mutableServicesIndex.getServiceFileDescriptors().equals(serverFileDescriptors)
|| !mutableServicesIndex.getServiceNames().equals(serverServiceNames)) {
serverReflectionIndex =
new ServerReflectionIndex(server.getImmutableServices(), serverMutableServices);
}
return serverReflectionIndex;
}
}
ProtoReflectionService.java 文件源码
项目:grpc-java
阅读 36
收藏 0
点赞 0
评论 0
FileDescriptorIndex(List<ServerServiceDefinition> services) {
Queue<FileDescriptor> fileDescriptorsToProcess = new ArrayDeque<FileDescriptor>();
Set<String> seenFiles = new HashSet<String>();
for (ServerServiceDefinition service : services) {
io.grpc.ServiceDescriptor serviceDescriptor = service.getServiceDescriptor();
if (serviceDescriptor.getSchemaDescriptor() instanceof ProtoFileDescriptorSupplier) {
FileDescriptor fileDescriptor =
((ProtoFileDescriptorSupplier) serviceDescriptor.getSchemaDescriptor())
.getFileDescriptor();
String serviceName = serviceDescriptor.getName();
checkState(
!serviceNames.contains(serviceName), "Service already defined: %s", serviceName);
serviceFileDescriptors.add(fileDescriptor);
serviceNames.add(serviceName);
if (!seenFiles.contains(fileDescriptor.getName())) {
seenFiles.add(fileDescriptor.getName());
fileDescriptorsToProcess.add(fileDescriptor);
}
}
}
while (!fileDescriptorsToProcess.isEmpty()) {
FileDescriptor currentFd = fileDescriptorsToProcess.remove();
processFileDescriptor(currentFd);
for (FileDescriptor dependencyFd : currentFd.getDependencies()) {
if (!seenFiles.contains(dependencyFd.getName())) {
seenFiles.add(dependencyFd.getName());
fileDescriptorsToProcess.add(dependencyFd);
}
}
}
}
ProtoReflectionService.java 文件源码
项目:grpc-java
阅读 38
收藏 0
点赞 0
评论 0
private void processFileDescriptor(FileDescriptor fd) {
String fdName = fd.getName();
checkState(!fileDescriptorsByName.containsKey(fdName), "File name already used: %s", fdName);
fileDescriptorsByName.put(fdName, fd);
for (ServiceDescriptor service : fd.getServices()) {
processService(service, fd);
}
for (Descriptor type : fd.getMessageTypes()) {
processType(type, fd);
}
for (FieldDescriptor extension : fd.getExtensions()) {
processExtension(extension, fd);
}
}
ProtobufRpcClient.java 文件源码
项目:cloudata
阅读 32
收藏 0
点赞 0
评论 0
public static <RequestT extends Message, ResponseT extends Message> RpcMethod<RequestT, ResponseT> create(
ServiceDescriptor descriptor, String methodName, RequestT requestDefaultInstance,
ResponseT responseDefaultInstance) {
MethodDescriptor method = descriptor.findMethodByName(methodName);
Preconditions.checkArgument(method != null);
Preconditions.checkArgument(requestDefaultInstance.getDescriptorForType() == method.getInputType());
Preconditions.checkArgument(responseDefaultInstance.getDescriptorForType() == method.getOutputType());
return new RpcMethod<RequestT, ResponseT>(method, responseDefaultInstance);
}
ProtoGenerator.java 文件源码
项目:fuchsia
阅读 31
收藏 0
点赞 0
评论 0
public void generateProtoFromDescriptor(FileDescriptor descriptor,
Appendable out, Descriptor wrapperMessage) throws IOException {
String package1 = descriptor.getPackage();
if (package1 != null) {
out.append("package " + package1 + ";\n");
}
FileOptions options = descriptor.getOptions();
String javaPackage = options.getJavaPackage();
if (javaPackage != null) {
out.append("option java_package = \"" + javaPackage + "\";\n");
}
String javaOuterClassname = options.getJavaOuterClassname();
if (javaOuterClassname != null) {
out.append("option java_outer_classname = \"" + javaOuterClassname
+ "\";\n");
}
for (ServiceDescriptor serviceDescriptor : descriptor.getServices()) {
generateProtoFromDescriptor(serviceDescriptor, out);
}
for (Descriptor messageDescriptor : descriptor.getMessageTypes()) {
if (wrapperMessage != null && messageDescriptor.equals(wrapperMessage)) {
out.append("// This is the message you can send to this service (wrapper message):\n");
}
generateProtoFromDescriptor(messageDescriptor, out, "",
new LinkedHashMap<Descriptor, Boolean>());
}
for (EnumDescriptor enumDescriptor : descriptor.getEnumTypes()) {
generateProtoFromDescriptor(enumDescriptor, out, "");
}
}
ProtoGenerator.java 文件源码
项目:fuchsia
阅读 28
收藏 0
点赞 0
评论 0
private void generateProtoFromDescriptor(ServiceDescriptor descriptor,
Appendable out) throws IOException {
out.append("service " + descriptor.getName() + " {\n");
for (MethodDescriptor methodDescriptor : descriptor.getMethods()) {
generateProtoFromDescriptor(methodDescriptor, out);
}
out.append("}\n");
}
DescriptorsTest.java 文件源码
项目:sstore-soft
阅读 36
收藏 0
点赞 0
评论 0
public void testFileDescriptor() throws Exception {
FileDescriptor file = UnittestProto.getDescriptor();
assertEquals("google/protobuf/unittest.proto", file.getName());
assertEquals("protobuf_unittest", file.getPackage());
assertEquals("UnittestProto", file.getOptions().getJavaOuterClassname());
assertEquals("google/protobuf/unittest.proto",
file.toProto().getName());
assertEquals(Arrays.asList(UnittestImport.getDescriptor()),
file.getDependencies());
Descriptor messageType = TestAllTypes.getDescriptor();
assertEquals(messageType, file.getMessageTypes().get(0));
assertEquals(messageType, file.findMessageTypeByName("TestAllTypes"));
assertNull(file.findMessageTypeByName("NoSuchType"));
assertNull(file.findMessageTypeByName("protobuf_unittest.TestAllTypes"));
for (int i = 0; i < file.getMessageTypes().size(); i++) {
assertEquals(i, file.getMessageTypes().get(i).getIndex());
}
EnumDescriptor enumType = ForeignEnum.getDescriptor();
assertEquals(enumType, file.getEnumTypes().get(0));
assertEquals(enumType, file.findEnumTypeByName("ForeignEnum"));
assertNull(file.findEnumTypeByName("NoSuchType"));
assertNull(file.findEnumTypeByName("protobuf_unittest.ForeignEnum"));
assertEquals(Arrays.asList(ImportEnum.getDescriptor()),
UnittestImport.getDescriptor().getEnumTypes());
for (int i = 0; i < file.getEnumTypes().size(); i++) {
assertEquals(i, file.getEnumTypes().get(i).getIndex());
}
ServiceDescriptor service = TestService.getDescriptor();
assertEquals(service, file.getServices().get(0));
assertEquals(service, file.findServiceByName("TestService"));
assertNull(file.findServiceByName("NoSuchType"));
assertNull(file.findServiceByName("protobuf_unittest.TestService"));
assertEquals(Collections.emptyList(),
UnittestImport.getDescriptor().getServices());
for (int i = 0; i < file.getServices().size(); i++) {
assertEquals(i, file.getServices().get(i).getIndex());
}
FieldDescriptor extension =
UnittestProto.optionalInt32Extension.getDescriptor();
assertEquals(extension, file.getExtensions().get(0));
assertEquals(extension,
file.findExtensionByName("optional_int32_extension"));
assertNull(file.findExtensionByName("no_such_ext"));
assertNull(file.findExtensionByName(
"protobuf_unittest.optional_int32_extension"));
assertEquals(Collections.emptyList(),
UnittestImport.getDescriptor().getExtensions());
for (int i = 0; i < file.getExtensions().size(); i++) {
assertEquals(i, file.getExtensions().get(i).getIndex());
}
}
DescriptorsTest.java 文件源码
项目:sstore-soft
阅读 28
收藏 0
点赞 0
评论 0
public void testCustomOptions() throws Exception {
Descriptor descriptor =
UnittestCustomOptions.TestMessageWithCustomOptions.getDescriptor();
assertTrue(
descriptor.getOptions().hasExtension(UnittestCustomOptions.messageOpt1));
assertEquals(Integer.valueOf(-56),
descriptor.getOptions().getExtension(UnittestCustomOptions.messageOpt1));
FieldDescriptor field = descriptor.findFieldByName("field1");
assertNotNull(field);
assertTrue(
field.getOptions().hasExtension(UnittestCustomOptions.fieldOpt1));
assertEquals(Long.valueOf(8765432109L),
field.getOptions().getExtension(UnittestCustomOptions.fieldOpt1));
EnumDescriptor enumType =
UnittestCustomOptions.TestMessageWithCustomOptions.AnEnum.getDescriptor();
assertTrue(
enumType.getOptions().hasExtension(UnittestCustomOptions.enumOpt1));
assertEquals(Integer.valueOf(-789),
enumType.getOptions().getExtension(UnittestCustomOptions.enumOpt1));
ServiceDescriptor service =
UnittestCustomOptions.TestServiceWithCustomOptions.getDescriptor();
assertTrue(
service.getOptions().hasExtension(UnittestCustomOptions.serviceOpt1));
assertEquals(Long.valueOf(-9876543210L),
service.getOptions().getExtension(UnittestCustomOptions.serviceOpt1));
MethodDescriptor method = service.findMethodByName("Foo");
assertNotNull(method);
assertTrue(
method.getOptions().hasExtension(UnittestCustomOptions.methodOpt1));
assertEquals(UnittestCustomOptions.MethodOpt1.METHODOPT1_VAL2,
method.getOptions().getExtension(UnittestCustomOptions.methodOpt1));
}
DescriptorsTest.java 文件源码
项目:s-store
阅读 36
收藏 0
点赞 0
评论 0
public void testFileDescriptor() throws Exception {
FileDescriptor file = UnittestProto.getDescriptor();
assertEquals("google/protobuf/unittest.proto", file.getName());
assertEquals("protobuf_unittest", file.getPackage());
assertEquals("UnittestProto", file.getOptions().getJavaOuterClassname());
assertEquals("google/protobuf/unittest.proto",
file.toProto().getName());
assertEquals(Arrays.asList(UnittestImport.getDescriptor()),
file.getDependencies());
Descriptor messageType = TestAllTypes.getDescriptor();
assertEquals(messageType, file.getMessageTypes().get(0));
assertEquals(messageType, file.findMessageTypeByName("TestAllTypes"));
assertNull(file.findMessageTypeByName("NoSuchType"));
assertNull(file.findMessageTypeByName("protobuf_unittest.TestAllTypes"));
for (int i = 0; i < file.getMessageTypes().size(); i++) {
assertEquals(i, file.getMessageTypes().get(i).getIndex());
}
EnumDescriptor enumType = ForeignEnum.getDescriptor();
assertEquals(enumType, file.getEnumTypes().get(0));
assertEquals(enumType, file.findEnumTypeByName("ForeignEnum"));
assertNull(file.findEnumTypeByName("NoSuchType"));
assertNull(file.findEnumTypeByName("protobuf_unittest.ForeignEnum"));
assertEquals(Arrays.asList(ImportEnum.getDescriptor()),
UnittestImport.getDescriptor().getEnumTypes());
for (int i = 0; i < file.getEnumTypes().size(); i++) {
assertEquals(i, file.getEnumTypes().get(i).getIndex());
}
ServiceDescriptor service = TestService.getDescriptor();
assertEquals(service, file.getServices().get(0));
assertEquals(service, file.findServiceByName("TestService"));
assertNull(file.findServiceByName("NoSuchType"));
assertNull(file.findServiceByName("protobuf_unittest.TestService"));
assertEquals(Collections.emptyList(),
UnittestImport.getDescriptor().getServices());
for (int i = 0; i < file.getServices().size(); i++) {
assertEquals(i, file.getServices().get(i).getIndex());
}
FieldDescriptor extension =
UnittestProto.optionalInt32Extension.getDescriptor();
assertEquals(extension, file.getExtensions().get(0));
assertEquals(extension,
file.findExtensionByName("optional_int32_extension"));
assertNull(file.findExtensionByName("no_such_ext"));
assertNull(file.findExtensionByName(
"protobuf_unittest.optional_int32_extension"));
assertEquals(Collections.emptyList(),
UnittestImport.getDescriptor().getExtensions());
for (int i = 0; i < file.getExtensions().size(); i++) {
assertEquals(i, file.getExtensions().get(i).getIndex());
}
}
DescriptorsTest.java 文件源码
项目:s-store
阅读 31
收藏 0
点赞 0
评论 0
public void testCustomOptions() throws Exception {
Descriptor descriptor =
UnittestCustomOptions.TestMessageWithCustomOptions.getDescriptor();
assertTrue(
descriptor.getOptions().hasExtension(UnittestCustomOptions.messageOpt1));
assertEquals(Integer.valueOf(-56),
descriptor.getOptions().getExtension(UnittestCustomOptions.messageOpt1));
FieldDescriptor field = descriptor.findFieldByName("field1");
assertNotNull(field);
assertTrue(
field.getOptions().hasExtension(UnittestCustomOptions.fieldOpt1));
assertEquals(Long.valueOf(8765432109L),
field.getOptions().getExtension(UnittestCustomOptions.fieldOpt1));
EnumDescriptor enumType =
UnittestCustomOptions.TestMessageWithCustomOptions.AnEnum.getDescriptor();
assertTrue(
enumType.getOptions().hasExtension(UnittestCustomOptions.enumOpt1));
assertEquals(Integer.valueOf(-789),
enumType.getOptions().getExtension(UnittestCustomOptions.enumOpt1));
ServiceDescriptor service =
UnittestCustomOptions.TestServiceWithCustomOptions.getDescriptor();
assertTrue(
service.getOptions().hasExtension(UnittestCustomOptions.serviceOpt1));
assertEquals(Long.valueOf(-9876543210L),
service.getOptions().getExtension(UnittestCustomOptions.serviceOpt1));
MethodDescriptor method = service.findMethodByName("Foo");
assertNotNull(method);
assertTrue(
method.getOptions().hasExtension(UnittestCustomOptions.methodOpt1));
assertEquals(UnittestCustomOptions.MethodOpt1.METHODOPT1_VAL2,
method.getOptions().getExtension(UnittestCustomOptions.methodOpt1));
}
DescriptorsTest.java 文件源码
项目:vsminecraft
阅读 44
收藏 0
点赞 0
评论 0
public void testFileDescriptor() throws Exception {
FileDescriptor file = UnittestProto.getDescriptor();
assertEquals("google/protobuf/unittest.proto", file.getName());
assertEquals("protobuf_unittest", file.getPackage());
assertEquals("UnittestProto", file.getOptions().getJavaOuterClassname());
assertEquals("google/protobuf/unittest.proto",
file.toProto().getName());
assertEquals(Arrays.asList(UnittestImport.getDescriptor()),
file.getDependencies());
Descriptor messageType = TestAllTypes.getDescriptor();
assertEquals(messageType, file.getMessageTypes().get(0));
assertEquals(messageType, file.findMessageTypeByName("TestAllTypes"));
assertNull(file.findMessageTypeByName("NoSuchType"));
assertNull(file.findMessageTypeByName("protobuf_unittest.TestAllTypes"));
for (int i = 0; i < file.getMessageTypes().size(); i++) {
assertEquals(i, file.getMessageTypes().get(i).getIndex());
}
EnumDescriptor enumType = ForeignEnum.getDescriptor();
assertEquals(enumType, file.getEnumTypes().get(0));
assertEquals(enumType, file.findEnumTypeByName("ForeignEnum"));
assertNull(file.findEnumTypeByName("NoSuchType"));
assertNull(file.findEnumTypeByName("protobuf_unittest.ForeignEnum"));
assertEquals(Arrays.asList(ImportEnum.getDescriptor()),
UnittestImport.getDescriptor().getEnumTypes());
for (int i = 0; i < file.getEnumTypes().size(); i++) {
assertEquals(i, file.getEnumTypes().get(i).getIndex());
}
ServiceDescriptor service = TestService.getDescriptor();
assertEquals(service, file.getServices().get(0));
assertEquals(service, file.findServiceByName("TestService"));
assertNull(file.findServiceByName("NoSuchType"));
assertNull(file.findServiceByName("protobuf_unittest.TestService"));
assertEquals(Collections.emptyList(),
UnittestImport.getDescriptor().getServices());
for (int i = 0; i < file.getServices().size(); i++) {
assertEquals(i, file.getServices().get(i).getIndex());
}
FieldDescriptor extension =
UnittestProto.optionalInt32Extension.getDescriptor();
assertEquals(extension, file.getExtensions().get(0));
assertEquals(extension,
file.findExtensionByName("optional_int32_extension"));
assertNull(file.findExtensionByName("no_such_ext"));
assertNull(file.findExtensionByName(
"protobuf_unittest.optional_int32_extension"));
assertEquals(Collections.emptyList(),
UnittestImport.getDescriptor().getExtensions());
for (int i = 0; i < file.getExtensions().size(); i++) {
assertEquals(i, file.getExtensions().get(i).getIndex());
}
}
DescriptorsTest.java 文件源码
项目:vsminecraft
阅读 30
收藏 0
点赞 0
评论 0
public void testCustomOptions() throws Exception {
// Get the descriptor indirectly from a dependent proto class. This is to
// ensure that when a proto class is loaded, custom options defined in its
// dependencies are also properly initialized.
Descriptor descriptor =
TestCustomOptions.TestMessageWithCustomOptionsContainer.getDescriptor()
.findFieldByName("field").getMessageType();
assertTrue(
descriptor.getOptions().hasExtension(UnittestCustomOptions.messageOpt1));
assertEquals(Integer.valueOf(-56),
descriptor.getOptions().getExtension(UnittestCustomOptions.messageOpt1));
FieldDescriptor field = descriptor.findFieldByName("field1");
assertNotNull(field);
assertTrue(
field.getOptions().hasExtension(UnittestCustomOptions.fieldOpt1));
assertEquals(Long.valueOf(8765432109L),
field.getOptions().getExtension(UnittestCustomOptions.fieldOpt1));
EnumDescriptor enumType =
UnittestCustomOptions.TestMessageWithCustomOptions.AnEnum.getDescriptor();
assertTrue(
enumType.getOptions().hasExtension(UnittestCustomOptions.enumOpt1));
assertEquals(Integer.valueOf(-789),
enumType.getOptions().getExtension(UnittestCustomOptions.enumOpt1));
ServiceDescriptor service =
UnittestCustomOptions.TestServiceWithCustomOptions.getDescriptor();
assertTrue(
service.getOptions().hasExtension(UnittestCustomOptions.serviceOpt1));
assertEquals(Long.valueOf(-9876543210L),
service.getOptions().getExtension(UnittestCustomOptions.serviceOpt1));
MethodDescriptor method = service.findMethodByName("Foo");
assertNotNull(method);
assertTrue(
method.getOptions().hasExtension(UnittestCustomOptions.methodOpt1));
assertEquals(UnittestCustomOptions.MethodOpt1.METHODOPT1_VAL2,
method.getOptions().getExtension(UnittestCustomOptions.methodOpt1));
}