Module: KyotoCabinet::Adaptation
- Included in:
- Java::Kyotocabinet::Cursor, Java::Kyotocabinet::DB
- Defined in:
- lib/kyotocabinet.rb
Constant Summary collapse
- BYTE_ARRAY =
[1].to_java(:byte).java_class
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(mod) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/kyotocabinet.rb', line 57 def self.included(mod) super(mod) mod.instance_eval do def with_java_method(mname, args) mh = self.java_method(mname, args) yield mh end def convert_args(mname, args) indices = [] args.each_with_index do |a, i| if a == BYTE_ARRAY indices << i end end mh = self.java_method(mname, args) self.send(:define_method, mname) do |*argv| indices.each { |i| argv[i] = argv[i].to_java_bytes } mh.bind(self).call(*argv) end end def convert_args_ret(mname, args) indices = [] args.each_with_index do |a, i| if a == BYTE_ARRAY indices << i end end mh = self.java_method(mname, args) self.send(:define_method, mname) do |*argv| indices.each { |i| argv[i] = argv[i].to_java_bytes } rv = mh.bind(self).call(*argv) if rv String.from_java_bytes(rv) end end end end end |
Instance Method Details
#conv_string_array(a) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/kyotocabinet.rb', line 45 def conv_string_array(a) ba = Java::byte[a.size, 0].new a.each_with_index do |k, i| ba[i] = k.to_java_bytes end ba end |
#ret_bytes(v) ⇒ Object
97 98 99 100 101 |
# File 'lib/kyotocabinet.rb', line 97 def ret_bytes(v) if v String.from_java_bytes(v) end end |
#to_string_array(ba) ⇒ Object
53 54 55 |
# File 'lib/kyotocabinet.rb', line 53 def to_string_array(ba) ba.collect { |e| String.from_java_bytes(e) } end |