Skip to content

Commit

Permalink
Erlectricity::Decoder.read_any_from -> Erlectricity::Decoder.decode
Browse files Browse the repository at this point in the history
  • Loading branch information
mojombo committed Apr 28, 2009
1 parent ac81089 commit d6afa69
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 11 deletions.
1 change: 1 addition & 0 deletions History.txt
Expand Up @@ -8,6 +8,7 @@
instead of STDIN and STDOUT. This prevents inadvertent output
statements from silently corrupting the transfer protocol.
* Erlang atoms 'true' and 'false' are now converted into Ruby booleans
* Erlectricity::Decoder.read_any_from -> Erlectricity::Decoder.decode
* Major Enhancements
* Calling `rake` now runs tests (with and without compiled C extensions)
* Package management is now done by Jeweler
4 changes: 2 additions & 2 deletions Rakefile
Expand Up @@ -25,8 +25,8 @@ task :test do
require 'fileutils'

puts "\nCleaning extension build files and running all specs in native ruby mode..."
FileUtils.rm_f("ext/*.bundle")
FileUtils.rm_f("ext/*.o")
`rm -f ext/*.bundle` && puts("rm -f ext/*.bundle")
`rm -f ext/*.o` && puts("rm -f ext/*.o")
Open3.popen3("ruby test/spec_suite.rb") do |stdin, stdout, stderr|
while !stdout.eof?
print stdout.read(1)
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/bench.rb
Expand Up @@ -10,7 +10,7 @@

Benchmark.bm do|b|
b.report("Decoder") do
100_000.times { Erl::Decoder.read_any_from(bert) }
100_000.times { Erl::Decoder.decode(bert) }
end
end

Expand Down
6 changes: 3 additions & 3 deletions ext/decoder.c
Expand Up @@ -25,7 +25,7 @@ static VALUE mErlectricity;
static VALUE cDecoder;
void Init_decoder();

VALUE method_read_any_from(VALUE klass, VALUE rString);
VALUE method_decode(VALUE klass, VALUE rString);

VALUE read_any_raw(unsigned char **pData);

Expand Down Expand Up @@ -383,7 +383,7 @@ VALUE read_any_raw(unsigned char **pData) {
return Qnil;
}

VALUE method_read_any_from(VALUE klass, VALUE rString) {
VALUE method_decode(VALUE klass, VALUE rString) {
unsigned char *data = (unsigned char *) StringValuePtr(rString);

unsigned char **pData = &data;
Expand All @@ -399,5 +399,5 @@ VALUE method_read_any_from(VALUE klass, VALUE rString) {
void Init_decoder() {
mErlectricity = rb_const_get(rb_cObject, rb_intern("Erlectricity"));
cDecoder = rb_define_class_under(mErlectricity, "Decoder", rb_cObject);
rb_define_singleton_method(cDecoder, "read_any_from", method_read_any_from, 1);
rb_define_singleton_method(cDecoder, "decode", method_decode, 1);
}
2 changes: 1 addition & 1 deletion lib/erlectricity/decoder.rb
Expand Up @@ -3,7 +3,7 @@ class Decoder
attr_accessor :in
include Erlectricity::External::Types

def self.read_any_from(string)
def self.decode(string)
new(StringIO.new(string)).read_any
end

Expand Down
2 changes: 1 addition & 1 deletion lib/erlectricity/port.rb
Expand Up @@ -40,7 +40,7 @@ def read_from_input

packet_length = raw.unpack('N').first
data = input.read(packet_length)
Erlectricity::Decoder.read_any_from(data)
Erlectricity::Decoder.decode(data)
end
end
end
2 changes: 1 addition & 1 deletion test/decode_spec.rb
Expand Up @@ -123,6 +123,6 @@
def get(str)
x = "term_to_binary(#{str.gsub(/"/, '\\\"')})"
bin = run_erl(x)
Erlectricity::Decoder.read_any_from(bin)
Erlectricity::Decoder.decode(bin)
end
end
4 changes: 2 additions & 2 deletions test/encode_spec.rb
Expand Up @@ -67,15 +67,15 @@

specify "An Erlectiricity::NewReference should encode back to its original form" do
ref_bin = run_erl("term_to_binary(make_ref())")
ruby_ref = Erlectricity::Decoder.read_any_from(ref_bin)
ruby_ref = Erlectricity::Decoder.decode(ref_bin)

get{@encoder.write_new_reference(ruby_ref)}.should == ref_bin[1..-1]
write_any(ruby_ref).should == ref_bin
end

specify "An Erlectiricity::Pid should encode back to its original form" do
pid_bin = run_erl("term_to_binary(spawn(fun() -> 3 end))")
ruby_pid = Erlectricity::Decoder.read_any_from(pid_bin)
ruby_pid = Erlectricity::Decoder.decode(pid_bin)

get{@encoder.write_pid(ruby_pid)}.should == pid_bin[1..-1]
write_any(ruby_pid).should == pid_bin
Expand Down

0 comments on commit d6afa69

Please sign in to comment.