33 package com.google.protobuf.jruby;
37 import org.jruby.anno.JRubyClass;
38 import org.jruby.anno.JRubyMethod;
39 import org.jruby.runtime.Binding;
40 import org.jruby.runtime.Block;
41 import org.jruby.runtime.ObjectAllocator;
42 import org.jruby.runtime.ThreadContext;
43 import org.jruby.runtime.builtin.IRubyObject;
45 @JRubyClass(
name =
"MessageBuilderContext")
48 RubyModule
protobuf = runtime.getClassFromPath(
"Google::Protobuf");
51 public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
65 this.
cDescriptor = (RubyClass)
context.runtime.getClassFromPath(
"Google::Protobuf::Descriptor");
82 @JRubyMethod(
required = 3, optional = 1)
83 public IRubyObject optional(ThreadContext
context, IRubyObject[]
args) {
85 IRubyObject typeClass = runtime.getNil();
86 if (
args.length > 3) typeClass =
args[3];
88 return context.runtime.getNil();
104 @JRubyMethod(
required = 3, optional = 1)
106 IRubyObject typeClass =
context.runtime.getNil();
107 if (
args.length > 3) typeClass =
args[3];
109 return context.runtime.getNil();
121 @JRubyMethod(
required = 3, optional = 1)
123 IRubyObject typeClass =
context.runtime.getNil();
124 if (
args.length > 3) typeClass =
args[3];
126 return context.runtime.getNil();
141 @JRubyMethod(
required = 4, optional = 1)
143 Ruby runtime =
context.runtime;
145 IRubyObject keyType =
args[1];
146 IRubyObject valueType =
args[2];
148 IRubyObject typeClass =
args.length > 4 ?
args[4] :
context.runtime.getNil();
153 if (keyType.equals(RubySymbol.newSymbol(runtime,
"float")) ||
154 keyType.equals(RubySymbol.newSymbol(runtime,
"double")) ||
155 keyType.equals(RubySymbol.newSymbol(runtime,
"enum")) ||
156 keyType.equals(RubySymbol.newSymbol(runtime,
"message")))
157 throw runtime.newArgumentError(
"Cannot add a map field with a float, double, enum, or message type.");
162 IRubyObject mapentryDescName = RubySymbol.newSymbol(runtime,
name).id2name(
context);
177 valueField.
setLabel(
context, RubySymbol.newSymbol(runtime,
"optional"));
185 this.
builder.pendingList.add(mapentryDesc);
187 msgdefAddField(
context,
"repeated",
name, runtime.newSymbol(
"message"),
number, mapentryDescName);
188 return runtime.getNil();
198 Binding binding =
block.getBinding();
199 binding.setSelf(
ctx);
202 return context.runtime.getNil();
206 IRubyObject
type, IRubyObject
number, IRubyObject typeClass) {