Skip to content

Commit

Permalink
Add options to FieldDescriptors under JRuby.
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonLunn committed Nov 8, 2023
1 parent 1f2c8ba commit 3beac3d
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

package com.google.protobuf.jruby;

import com.google.protobuf.CodedInputStream;
import com.google.protobuf.Descriptors.FieldDescriptor;
import com.google.protobuf.LegacyDescriptorsUtil.LegacyFileDescriptor;
import org.jruby.*;
Expand Down Expand Up @@ -231,6 +232,14 @@ public IRubyObject setValue(ThreadContext context, IRubyObject message, IRubyObj
return context.nil;
}

@JRubyMethod
public IRubyObject options(ThreadContext context) {
RubyDescriptor fieldOptionsDescriptor = (RubyDescriptor) pool.lookup(context, context.runtime.newString("google.protobuf.FieldOptions"));
RubyClass fieldOptionsClass = (RubyClass) fieldOptionsDescriptor.msgclass(context);
RubyMessage msg = (RubyMessage) fieldOptionsClass.newInstance(context, Block.NULL_BLOCK);
return msg.decodeBytes(context, msg, CodedInputStream.newInstance(descriptor.getOptions().toByteString().toByteArray()), /*freeze*/ true);
}

protected void setDescriptor(
ThreadContext context, FieldDescriptor descriptor, RubyDescriptorPool pool) {
if (descriptor.isRequired()
Expand Down

0 comments on commit 3beac3d

Please sign in to comment.