lib/bert/encode.rb in bert-1.1.2-java vs lib/bert/encode.rb in bert-1.1.6

- old
+ new

@@ -8,10 +8,11 @@ self.out = out end def self.encode(data) io = StringIO.new + io.set_encoding('binary') if io.respond_to?(:set_encoding) self.new(io).write_any(data) io.string end def write_any obj @@ -54,11 +55,11 @@ def write_symbol(sym) fail(sym) unless sym.is_a?(Symbol) data = sym.to_s write_1 ATOM - write_2 data.length + write_2 data.bytesize write_string data end def write_fixnum(num) if num >= 0 && num < 256 @@ -76,11 +77,11 @@ write_1 FLOAT write_string format("%15.15e", float).ljust(31, "\000") end def write_bignum(num) - n = (num.to_s(2).size / 8.0).ceil + n = (num.abs.to_s(2).size / 8.0).ceil if n < 256 write_1 SMALL_BIGNUM write_1 n write_bignum_guts(num) else @@ -123,10 +124,10 @@ write_1 NIL end def write_binary(data) write_1 BIN - write_4 data.length + write_4 data.bytesize write_string data end private