This repository has been archived by the owner on Jan 2, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrote the loading mechanism to use JRuby's BasicLibraryService
- Loading branch information
Showing
17 changed files
with
100 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
*.gem | ||
.bundle | ||
pkg/* | ||
/benchmark | ||
/benchmark |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import java.io.IOException; | ||
|
||
import org.jruby.Ruby; | ||
import org.jruby.runtime.load.BasicLibraryService; | ||
|
||
import org.msgpack.jruby.MessagePackLibrary; | ||
|
||
|
||
public class MsgpackJrubyService implements BasicLibraryService { | ||
public boolean basicLoad(final Ruby runtime) throws IOException { | ||
new MessagePackLibrary().load(runtime, false); | ||
return true; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package org.msgpack.jruby; | ||
|
||
|
||
import java.io.IOException; | ||
|
||
import org.jruby.Ruby; | ||
import org.jruby.RubyModule; | ||
import org.jruby.RubyClass; | ||
import org.jruby.RubyString; | ||
import org.jruby.runtime.load.Library; | ||
import org.jruby.runtime.callback.Callback; | ||
import org.jruby.runtime.builtin.IRubyObject; | ||
import org.jruby.runtime.Arity; | ||
import org.jruby.runtime.Block; | ||
|
||
import org.msgpack.MessagePack; | ||
import org.msgpack.packer.BufferPacker; | ||
import org.msgpack.packer.Packer; | ||
|
||
|
||
public class MessagePackLibrary implements Library { | ||
public void load(Ruby runtime, boolean wrap) throws IOException { | ||
MessagePack msgPack = new MessagePack(); | ||
RubyModule msgpackModule = runtime.defineModule("MessagePack"); | ||
msgpackModule.defineModuleFunction("pack", new PackCallback(msgPack)); | ||
msgpackModule.defineModuleFunction("unpack", new UnpackCallback(msgPack)); | ||
} | ||
|
||
private static class PackCallback implements Callback { | ||
private MessagePack msgPack; | ||
|
||
public PackCallback(MessagePack msgPack) { | ||
this.msgPack = msgPack; | ||
} | ||
|
||
public IRubyObject execute(IRubyObject recv, IRubyObject[] args, Block block) { | ||
try { | ||
BufferPacker bufferedPacker = msgPack.createBufferPacker(); | ||
Packer packer = new RubyObjectPacker(msgPack, bufferedPacker).write(args[0]); | ||
return RubyString.newString(recv.getRuntime(), bufferedPacker.toByteArray()); | ||
} catch (IOException ioe) { | ||
// TODO: how to propagate these to the Ruby runtime? | ||
return recv.getRuntime().getNil(); | ||
} | ||
} | ||
|
||
public Arity getArity() { return Arity.ONE_REQUIRED; } | ||
} | ||
|
||
private static class UnpackCallback implements Callback { | ||
private RubyObjectUnpacker unpacker; | ||
|
||
public UnpackCallback(MessagePack msgPack) { | ||
this.unpacker = new RubyObjectUnpacker(msgPack); | ||
} | ||
|
||
public IRubyObject execute(IRubyObject recv, IRubyObject[] args, Block block) { | ||
try { | ||
return unpacker.unpack((RubyString) args[0]); | ||
} catch (IOException ioe) { | ||
// TODO: how to propagate these to the Ruby runtime? | ||
return recv.getRuntime().getNil(); | ||
} | ||
} | ||
|
||
public Arity getArity() { return Arity.ONE_REQUIRED; } | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
# encoding: utf-8 | ||
|
||
require 'java' | ||
|
||
$CLASSPATH << File.expand_path('../ext', __FILE__) | ||
Dir[File.expand_path('../ext/*.jar', __FILE__)].each { |path| $CLASSPATH << path } | ||
$: << File.expand_path('../ext', __FILE__) | ||
|
||
MessagePack = org.msgpack.jruby.MessagePackModule | ||
require 'java' | ||
require 'javassist-3.15.0-GA' | ||
require 'msgpack-0.6.5-SNAPSHOT' | ||
require 'msgpack_jruby' |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.