33 package com.google.protobuf.jruby;
36 import org.jruby.anno.JRubyClass;
37 import org.jruby.anno.JRubyMethod;
38 import org.jruby.runtime.*;
39 import org.jruby.runtime.builtin.IRubyObject;
41 @JRubyClass(
name =
"Builder")
44 RubyModule
protobuf = runtime.getClassFromPath(
"Google::Protobuf");
45 RubyClass
cBuilder =
protobuf.defineClassUnder(
"Builder", runtime.getObject(),
new ObjectAllocator() {
47 public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
55 super(runtime, metaClass);
56 this.
cDescriptor = (RubyClass) runtime.getClassFromPath(
"Google::Protobuf::Descriptor");
57 this.
cEnumDescriptor = (RubyClass) runtime.getClassFromPath(
"Google::Protobuf::EnumDescriptor");
58 this.
cMessageBuilderContext = (RubyClass) runtime.getClassFromPath(
"Google::Protobuf::MessageBuilderContext");
59 this.
cEnumBuilderContext = (RubyClass) runtime.getClassFromPath(
"Google::Protobuf::EnumBuilderContext");
73 this.pendingList = runtime.newArray();
88 @JRubyMethod(
name =
"add_message")
93 if (
block.isGiven()) {
97 Binding binding =
block.getBinding();
102 this.pendingList.add(
msgdef);
103 return context.runtime.getNil();
116 @JRubyMethod(
name =
"add_enum")
122 if (
block.isGiven()) {
126 Binding binding =
block.getBinding();
127 binding.setSelf(
ctx);
132 this.pendingList.add(enumDef);
133 return context.runtime.getNil();
150 @JRubyMethod(
name =
"finalize_to_pool")
151 public IRubyObject finalizeToPool(ThreadContext
context, IRubyObject rbPool) {
153 for (
int i = 0;
i < this.pendingList.size();
i++) {
154 IRubyObject defRb = this.pendingList.entry(
i);
161 this.pendingList =
context.runtime.newArray();
162 return context.runtime.getNil();