bert
bert copied to clipboard
ArgumentError with BERT::Decode.new
Running into a bit of a perplexing problem with version 1.1.2:
>> BERT::Decode.new(StringIO.new("\203h\002d\000\005replyl\000\000\000\001a\001j"))
ArgumentError: wrong number of arguments (1 for 0)
from (irb):2:in `initialize'
from (irb):2:in `new'
I don't immediately see how that error's even possible given the code for BERT::Decode#initialize
. Maybe there's a redefinition of the new
class method going on elsewhere - didn't look.
The following works as expected:
>> BERT::Decode.decode("\203h\002d\000\005replyl\000\000\000\001a\001j")
=> t[:reply, [1]]
However, I'd prefer to be able to use BERT::Decode.new
directly with an IO
object, to avoid the StringIO
creation overhead inside BERT::Decode.decode
; important for decoding larger messages that can be read block by block, on demand, instead of copied around in full in memory a couple of times over.
Looks the same as #4.
Ah, that explains why the Ruby source code for BERT::Decode.new
had no clues to this problem. I had forgotten there's a C extension as well. Clear as day, now.
An easy workaround is to explicitly load up the Ruby version of the decoder:
>> require 'bert'
>> BERT::Decode.new(StringIO.new("\203h\002d\000\005replyl\000\000\000\001a\001j"))
ArgumentError: wrong number of arguments (1 for 0)
from (irb):2:in `initialize'
from (irb):2:in `new'
>> require 'bert/decode'
>> BERT::Decode.new(StringIO.new("\203h\002d\000\005replyl\000\000\000\001a\001j"))
=> #<BERT::Decode:0x1023a1968 @peeked="", @in=#<StringIO:0x1023a1990>