RubyFileDescriptor.java
Go to the documentation of this file.
1 /*
2  * Protocol Buffers - Google's data interchange format
3  * Copyright 2014 Google Inc. All rights reserved.
4  * https://developers.google.com/protocol-buffers/
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above
13  * copyright notice, this list of conditions and the following disclaimer
14  * in the documentation and/or other materials provided with the
15  * distribution.
16  * * Neither the name of Google Inc. nor the names of its
17  * contributors may be used to endorse or promote products derived from
18  * this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 package com.google.protobuf.jruby;
34 
39 import org.jruby.*;
40 import org.jruby.anno.JRubyClass;
41 import org.jruby.anno.JRubyMethod;
42 import org.jruby.runtime.Block;
43 import org.jruby.runtime.ObjectAllocator;
44 import org.jruby.runtime.ThreadContext;
45 import org.jruby.runtime.builtin.IRubyObject;
46 
47 @JRubyClass(name = "FileDescriptor")
48 public class RubyFileDescriptor extends RubyObject {
49  public static void createRubyFileDescriptor(Ruby runtime) {
50  RubyModule mProtobuf = runtime.getClassFromPath("Google::Protobuf");
51  cFileDescriptor = mProtobuf.defineClassUnder("FileDescriptor", runtime.getObject(), new ObjectAllocator() {
52  @Override
53  public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
54  return new RubyFileDescriptor(runtime, klazz);
55  }
56  });
57  cFileDescriptor.defineAnnotatedMethods(RubyFileDescriptor.class);
58  }
59 
61  RubyFileDescriptor rfd = (RubyFileDescriptor) cFileDescriptor.newInstance(context, Block.NULL_BLOCK);
62  rfd.fileDescriptor = descriptor.getFile();
63  return rfd;
64  }
65 
66  public RubyFileDescriptor(Ruby runtime, RubyClass klazz) {
67  super(runtime, klazz);
68  }
69 
70  /*
71  * call-seq:
72  * FileDescriptor.name => name
73  *
74  * Returns the name of the file.
75  */
76  @JRubyMethod(name = "name")
77  public IRubyObject getName(ThreadContext context) {
78  String name = fileDescriptor.getName();
79  return name == null ? context.nil : context.runtime.newString(name);
80  }
81 
82  /*
83  * call-seq:
84  * FileDescriptor.syntax => syntax
85  *
86  * Returns this file descriptors syntax.
87  *
88  * Valid syntax versions are:
89  * :proto2 or :proto3.
90  */
91  @JRubyMethod(name = "syntax")
92  public IRubyObject getSyntax(ThreadContext context) {
93  switch (fileDescriptor.getSyntax()) {
94  case PROTO2:
95  return context.runtime.newSymbol("proto2");
96  case PROTO3:
97  return context.runtime.newSymbol("proto3");
98  default:
99  return context.nil;
100  }
101  }
102 
103  private static RubyClass cFileDescriptor;
104 
106 }
com.google.protobuf.Descriptors
Definition: bloaty/third_party/protobuf/java/core/src/main/java/com/google/protobuf/Descriptors.java:80
com.google.protobuf.jruby.RubyFileDescriptor.fileDescriptor
FileDescriptor fileDescriptor
Definition: RubyFileDescriptor.java:105
com.google.protobuf.jruby.RubyFileDescriptor
Definition: RubyFileDescriptor.java:48
setup.name
name
Definition: setup.py:542
com.google.protobuf
Definition: bloaty/third_party/protobuf/benchmarks/java/src/main/java/com/google/protobuf/ProtoCaliperBenchmark.java:2
com.google.protobuf.jruby.RubyFileDescriptor.cFileDescriptor
static RubyClass cFileDescriptor
Definition: RubyFileDescriptor.java:103
com.google.protobuf.Descriptors.GenericDescriptor
Definition: bloaty/third_party/protobuf/java/core/src/main/java/com/google/protobuf/Descriptors.java:2123
com.google.protobuf.Descriptors.FileDescriptor.Syntax
Definition: bloaty/third_party/protobuf/java/core/src/main/java/com/google/protobuf/Descriptors.java:156
cFileDescriptor
VALUE cFileDescriptor
com.google.protobuf.Descriptors.Descriptor
Definition: bloaty/third_party/protobuf/java/core/src/main/java/com/google/protobuf/Descriptors.java:629
com.google.protobuf.jruby.RubyFileDescriptor.getRubyFileDescriptor
static RubyFileDescriptor getRubyFileDescriptor(ThreadContext context, GenericDescriptor descriptor)
Definition: RubyFileDescriptor.java:60
com.google
com
com.google.protobuf.jruby.RubyFileDescriptor.createRubyFileDescriptor
static void createRubyFileDescriptor(Ruby runtime)
Definition: RubyFileDescriptor.java:49
context
grpc::ClientContext context
Definition: istio_echo_server_lib.cc:61
com.google.protobuf.jruby.RubyFileDescriptor.RubyFileDescriptor
RubyFileDescriptor(Ruby runtime, RubyClass klazz)
Definition: RubyFileDescriptor.java:66
com.google.protobuf.Descriptors.FileDescriptor
Definition: bloaty/third_party/protobuf/java/core/src/main/java/com/google/protobuf/Descriptors.java:87
descriptor
static const char descriptor[1336]
Definition: certs.upbdefs.c:16


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:01:14