public RubyBuilder(Ruby runtime, RubyClass metaClass) { super(runtime, metaClass); this.cDescriptor = (RubyClass) runtime.getClassFromPath("Google::Protobuf::Descriptor"); this.cEnumDescriptor = (RubyClass) runtime.getClassFromPath("Google::Protobuf::EnumDescriptor"); this.cMessageBuilderContext = (RubyClass) runtime.getClassFromPath("Google::Protobuf::MessageBuilderContext"); this.cEnumBuilderContext = (RubyClass) runtime.getClassFromPath("Google::Protobuf::EnumBuilderContext"); }
@JRubyMethod public IRubyObject initialize(ThreadContext context, IRubyObject descriptor, IRubyObject rubyBuilder) { this.cFieldDescriptor = (RubyClass) context.runtime.getClassFromPath("Google::Protobuf::FieldDescriptor"); this.cDescriptor = (RubyClass) context.runtime.getClassFromPath("Google::Protobuf::Descriptor"); this.cOneofDescriptor = (RubyClass) context.runtime.getClassFromPath("Google::Protobuf::OneofDescriptor"); this.cOneofBuilderContext = (RubyClass) context.runtime.getClassFromPath("Google::Protobuf::Internal::OneofBuilderContext"); this.descriptor = (RubyDescriptor) descriptor; this.builder = (RubyBuilder) rubyBuilder; return this; }
@JRubyMethod public IRubyObject initialize(ThreadContext context, IRubyObject oneofdef) { this.descriptor = (RubyOneofDescriptor) oneofdef; this.cFieldDescriptor = (RubyClass) context.runtime.getClassFromPath("Google::Protobuf::FieldDescriptor"); return this; }
@JRubyMethod public IRubyObject initialize(ThreadContext context) { this.symtab = new HashMap<IRubyObject, IRubyObject>(); this.cBuilder = (RubyClass) context.runtime.getClassFromPath("Google::Protobuf::Builder"); this.builder = DescriptorProtos.FileDescriptorProto.newBuilder(); return this; }
public static void createRubyMessageBuilderContext(Ruby runtime) { RubyModule protobuf = runtime.getClassFromPath("Google::Protobuf"); RubyClass cMessageBuilderContext = protobuf.defineClassUnder("MessageBuilderContext", runtime.getObject(), new ObjectAllocator() { @Override public IRubyObject allocate(Ruby runtime, RubyClass klazz) { return new RubyMessageBuilderContext(runtime, klazz); } }); cMessageBuilderContext.defineAnnotatedMethods(RubyMessageBuilderContext.class); }
public static void createRubyBuilder(Ruby runtime) { RubyModule protobuf = runtime.getClassFromPath("Google::Protobuf"); RubyClass cBuilder = protobuf.defineClassUnder("Builder", runtime.getObject(), new ObjectAllocator() { @Override public IRubyObject allocate(Ruby runtime, RubyClass klazz) { return new RubyBuilder(runtime, klazz); } }); cBuilder.defineAnnotatedMethods(RubyBuilder.class); }
public static void createRubyFileDescriptor(Ruby runtime) { RubyModule mProtobuf = runtime.getClassFromPath("Google::Protobuf"); RubyClass cFieldDescriptor = mProtobuf.defineClassUnder("FieldDescriptor", runtime.getObject(), new ObjectAllocator() { @Override public IRubyObject allocate(Ruby runtime, RubyClass klazz) { return new RubyFieldDescriptor(runtime, klazz); } }); cFieldDescriptor.defineAnnotatedMethods(RubyFieldDescriptor.class); }
public static void createRubyEnumBuilderContext(Ruby runtime) { RubyModule protobuf = runtime.getClassFromPath("Google::Protobuf"); RubyClass cMessageBuilderContext = protobuf.defineClassUnder("EnumBuilderContext", runtime.getObject(), new ObjectAllocator() { @Override public IRubyObject allocate(Ruby runtime, RubyClass klazz) { return new RubyEnumBuilderContext(runtime, klazz); } }); cMessageBuilderContext.defineAnnotatedMethods(RubyEnumBuilderContext.class); }
@JRubyMethod(optional = 1) public IRubyObject initialize(final ThreadContext context, IRubyObject[] args) { final Ruby runtime = context.runtime; this.cRepeatedField = (RubyClass) runtime.getClassFromPath("Google::Protobuf::RepeatedField"); this.cMap = (RubyClass) runtime.getClassFromPath("Google::Protobuf::Map"); this.builder = DynamicMessage.newBuilder(this.descriptor); this.repeatedFields = new HashMap<Descriptors.FieldDescriptor, RubyRepeatedField>();
public static void createRubyOneofBuilderContext(Ruby runtime) { RubyModule protobuf = runtime.getClassFromPath("Google::Protobuf"); RubyModule internal = protobuf.defineModuleUnder("Internal"); RubyClass cRubyOneofBuidlerContext = internal.defineClassUnder("OneofBuilderContext", runtime.getObject(), new ObjectAllocator() { @Override public IRubyObject allocate(Ruby ruby, RubyClass rubyClass) { return new RubyOneofBuilderContext(ruby, rubyClass); } }); cRubyOneofBuidlerContext.defineAnnotatedMethods(RubyOneofBuilderContext.class); }
public static void createRubyOneofDescriptor(Ruby runtime) { RubyModule protobuf = runtime.getClassFromPath("Google::Protobuf"); RubyClass cRubyOneofDescriptor = protobuf.defineClassUnder("OneofDescriptor", runtime.getObject(), new ObjectAllocator() { @Override public IRubyObject allocate(Ruby ruby, RubyClass rubyClass) { return new RubyOneofDescriptor(ruby, rubyClass); } }); cRubyOneofDescriptor.defineAnnotatedMethods(RubyOneofDescriptor.class); cRubyOneofDescriptor.includeModule(runtime.getEnumerable()); }
public static void createRubyDescriptorPool(Ruby runtime) { RubyModule protobuf = runtime.getClassFromPath("Google::Protobuf"); RubyClass cDescriptorPool = protobuf.defineClassUnder("DescriptorPool", runtime.getObject(), new ObjectAllocator() { @Override public IRubyObject allocate(Ruby runtime, RubyClass klazz) { return new RubyDescriptorPool(runtime, klazz); } }); cDescriptorPool.defineAnnotatedMethods(RubyDescriptorPool.class); descriptorPool = (RubyDescriptorPool) cDescriptorPool.newInstance(runtime.getCurrentContext(), Block.NULL_BLOCK); }
public static void createRubyRepeatedField(Ruby runtime) { RubyModule mProtobuf = runtime.getClassFromPath("Google::Protobuf"); RubyClass cRepeatedField = mProtobuf.defineClassUnder("RepeatedField", runtime.getObject(), new ObjectAllocator() { @Override public IRubyObject allocate(Ruby runtime, RubyClass klazz) { return new RubyRepeatedField(runtime, klazz); } }); cRepeatedField.defineAnnotatedMethods(RubyRepeatedField.class); cRepeatedField.includeModule(runtime.getEnumerable()); }
public static void createRubyMap(Ruby runtime) { RubyModule protobuf = runtime.getClassFromPath("Google::Protobuf"); RubyClass cMap = protobuf.defineClassUnder("Map", runtime.getObject(), new ObjectAllocator() { @Override public IRubyObject allocate(Ruby ruby, RubyClass rubyClass) { return new RubyMap(ruby, rubyClass); } }); cMap.includeModule(runtime.getEnumerable()); cMap.defineAnnotatedMethods(RubyMap.class); }
public static void createRubyDescriptor(Ruby runtime) { RubyModule protobuf = runtime.getClassFromPath("Google::Protobuf"); RubyClass cDescriptor = protobuf.defineClassUnder("Descriptor", runtime.getObject(), new ObjectAllocator() { @Override public IRubyObject allocate(Ruby runtime, RubyClass klazz) { return new RubyDescriptor(runtime, klazz); } }); cDescriptor.includeModule(runtime.getEnumerable()); cDescriptor.defineAnnotatedMethods(RubyDescriptor.class); }
public static void createRubyEnumDescriptor(Ruby runtime) { RubyModule mProtobuf = runtime.getClassFromPath("Google::Protobuf"); RubyClass cEnumDescriptor = mProtobuf.defineClassUnder("EnumDescriptor", runtime.getObject(), new ObjectAllocator() { @Override public IRubyObject allocate(Ruby runtime, RubyClass klazz) { return new RubyEnumDescriptor(runtime, klazz); } }); cEnumDescriptor.includeModule(runtime.getEnumerable()); cEnumDescriptor.defineAnnotatedMethods(RubyEnumDescriptor.class); }
@JRubyMethod(name = "decode_json", meta = true) public static IRubyObject decodeJson(ThreadContext context, IRubyObject recv, IRubyObject json) { Ruby runtime = context.runtime; RubyMessage ret = (RubyMessage) ((RubyClass) recv).newInstance(context, Block.NULL_BLOCK); RubyModule jsonModule = runtime.getClassFromPath("JSON"); RubyHash opts = RubyHash.newHash(runtime); opts.fastASet(runtime.newSymbol("symbolize_names"), runtime.getTrue()); IRubyObject[] args = new IRubyObject[] { Helpers.invoke(context, jsonModule, "parse", json, opts) }; ret.initialize(context, args); return ret; }
private RubyModule buildClassFromDescriptor(ThreadContext context) { Ruby runtime = context.runtime; ObjectAllocator allocator = new ObjectAllocator() { @Override public IRubyObject allocate(Ruby runtime, RubyClass klazz) { return new RubyMessage(runtime, klazz, descriptor); } }; // rb_define_class_id RubyClass klass = RubyClass.newClass(runtime, runtime.getObject()); klass.setAllocator(allocator); klass.makeMetaClass(runtime.getObject().getMetaClass()); klass.inherit(runtime.getObject()); RubyModule messageExts = runtime.getClassFromPath("Google::Protobuf::MessageExts"); klass.include(new IRubyObject[] {messageExts}); klass.instance_variable_set(runtime.newString(Utils.DESCRIPTOR_INSTANCE_VAR), this); klass.defineAnnotatedMethods(RubyMessage.class); return klass; }
public void run() { if (latch.compareAndSet(false, true)) { if (currentThread.alive_p().isTrue()) { RubyClass anonException = (RubyClass)runtime.getClassFromPath("Timeout::AnonymousException"); IRubyObject anonExceptionObj = anonException.newInstance(runtime.getCurrentContext(), runtime.newString("execution expired"), Block.NULL_BLOCK); anonExceptionObj.getInternalVariables().setInternalVariable("__identifier__", id); currentThread.internalRaise(new IRubyObject[] {anonExceptionObj}); } } } };
@JRubyMethod(visibility = PRIVATE) public static IRubyObject path2class(ThreadContext context, IRubyObject self, IRubyObject path) { try { return context.runtime.getClassFromPath(path.asJavaString()); } catch (RaiseException re) { if (re.getException().getMetaClass() == context.runtime.getNameError()) { throw context.runtime.newArgumentError("undefined class/module " + path); } throw re; } } }