bloom-lang / bud

Prototype Bud runtime (Bloom Under Development)
http://bloom-lang.net
Other
856 stars 59 forks source link

MsgPack serialization for Symbols #86

Open billmarczak opened 13 years ago

billmarczak commented 13 years ago

check it:

class Test
    include Bud
    state {
        channel :foo, [:@loc, :a]
        scratch :bar, [:a]
    }

    bootstrap {
        foo <~ [["127.0.0.1:54321", :yo]]
        bar <+ [[:yo]]
    }

    declare
    def rules
        stdio <~ bar.map {|f| ["local: yo str"] if f.a == "yo"}
        stdio <~ bar.map {|f| ["local: yo sym"] if f.a == :yo}

        stdio <~ foo.map {|f| ["net: yo str"] if f.a == "yo"}
        stdio <~ foo.map {|f| ["net: yo sym"] if f.a == :yo}
    end
end

t = Test.new(:ip => "127.0.0.1", :port => 54321)
t.run

i'd expect "local: yo sym" and "net: yo sym" to print out. however, what actually prints out is "net: yo str" and "local: yo sym". so not a huge deal, but a minor inconsistency that symbols are converted to strings over the network, but not locally.

neilconway commented 13 years ago

I'm not sure there is an easy way to workaround this:

MessagePack.unpack(MessagePack.pack(:foo)).class
=> String

To fix this particular problem, we could teach MessagePack how to handle Symbols. We could also switch to a different serialization library (e.g., builtin Marshal).

neilconway commented 13 years ago

I looked into this a little bit, and filed a MsgPack bug: http://redmine.msgpack.org/issues/5

I'm not sure there is actually a very clean way to fix this, short of (a) MsgPack bugfix (b) explicitly sending some sort of flag in the serialized data to indicate that a given value is a Symbol.

michaelficarra commented 13 years ago

I've run into this problem now, too. Let me suggest BERT as a MessagePack replacement. It has an available ruby implementation. I believe github uses it for their data serialisation needs.

$ irb
irb(main):001:0> require 'bert'
=> true
irb(main):002:0> BERT.decode(BERT.encode(:symbol)).class
=> Symbol
irb(main):003:0> 
neilconway commented 13 years ago

Yeah, switching to another serialization framework might make sense. I'm not familiar with BERT, but I'll take a look.