зеркало из https://github.com/github/bert.git
do less processing on a msgpackable object
* skip 'convert', because the decomposition isn't interesting. * register more types, so that msgpack can deal with all the types that BERT can
This commit is contained in:
Родитель
d733ee9eac
Коммит
2fb106607f
|
@ -19,6 +19,7 @@ module BERT
|
|||
#
|
||||
# Returns the converted Ruby object
|
||||
def self.convert(item)
|
||||
return item if Encode.version == :v3
|
||||
case item
|
||||
when Hash
|
||||
pairs = []
|
||||
|
|
|
@ -3,7 +3,14 @@ require "msgpack"
|
|||
module BERT
|
||||
def self.msgpack
|
||||
factory = MessagePack::Factory.new
|
||||
factory.register_type(0x00, Symbol)
|
||||
factory
|
||||
factory.register_type 0x00, BERT::Tuple, :packer => :to_msgpack
|
||||
factory.register_type 0x01, Symbol
|
||||
factory.register_type 0x02, Regexp,
|
||||
:packer => lambda { |regexp| [regexp.options, regexp.source].pack("Lm") },
|
||||
:unpacker => lambda { |raw| options, source = raw.unpack("Lm"); Regexp.new(source, options) }
|
||||
factory.register_type 0x03, Time,
|
||||
:packer => lambda { |time| [time.to_f].pack("G") },
|
||||
:unpacker => lambda { |raw| Time.at(raw.unpack("G").first) }
|
||||
return factory
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,11 +10,11 @@ class BertTest < Test::Unit::TestCase
|
|||
@ebin_v1 = "<<131,104,9,100,0,4,117,115,101,114,104,3,100,0,4,98,101,114,116,100,0,4,100,105,99,116,108,0,0,0,1,104,2,100,0,4,110,97,109,101,109,0,0,0,3,84,80,87,106,108,0,0,0,2,104,4,100,0,4,98,101,114,116,100,0,5,114,101,103,101,120,109,0,0,0,3,99,97,116,108,0,0,0,1,100,0,8,99,97,115,101,108,101,115,115,106,99,57,46,57,48,48,48,48,48,48,48,48,48,48,48,48,48,48,101,43,48,48,0,0,0,0,0,0,0,0,0,0,106,104,5,100,0,4,98,101,114,116,100,0,4,116,105,109,101,98,0,0,4,230,98,0,14,228,195,97,0,104,2,100,0,4,98,101,114,116,100,0,3,110,105,108,104,2,100,0,4,98,101,114,116,100,0,4,116,114,117,101,104,2,100,0,4,98,101,114,116,100,0,5,102,97,108,115,101,100,0,4,116,114,117,101,100,0,5,102,97,108,115,101>>"
|
||||
@berts = {
|
||||
:v2 => "\x84h\td\x00\x04userh\x03d\x00\x04bertd\x00\x04dictl\x00\x00\x00\x01h\x02d\x00\x04nameq\x00\x00\x00\x03TPWjl\x00\x00\x00\x02h\x04d\x00\x04bertd\x00\x05regexq\x00\x00\x00\x03catl\x00\x00\x00\x01d\x00\bcaselessjc9.900000000000000e+00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00jh\x05d\x00\x04bertd\x00\x04timeb\x00\x00\x04\xE6b\x00\x0E\xE4\xC3a\x00h\x02d\x00\x04bertd\x00\x03nilh\x02d\x00\x04bertd\x00\x04trueh\x02d\x00\x04bertd\x00\x05falsed\x00\x04trued\x00\x05false".b,
|
||||
:v3 => "\x85\x99\xD6\x00user\x93\xD6\x00bert\xD6\x00dict\x91\x92\xD6\x00name\xA3TPW\x92\x94\xD6\x00bert\xC7\x05\x00regex\xA3cat\x91\xD7\x00caseless\xCB@#\xCC\xCC\xCC\xCC\xCC\xCD\x95\xD6\x00bert\xD6\x00time\xCD\x04\xE6\xCE\x00\x0E\xE4\xC3\x00\x92\xD6\x00bert\xC7\x03\x00nil\x92\xD6\x00bert\xD6\x00true\x92\xD6\x00bert\xC7\x05\x00false\xD6\x00true\xC7\x05\x00false".b,
|
||||
:v3 => "\x85\x99\xD6\x01user\x81\xD6\x01name\xA3TPW\x92\xC7\t\x02\x01\x00\x00\x00Y2F0\n\xCB@#\xCC\xCC\xCC\xCC\xCC\xCD\xD7\x03A\xD2\xB3Z\x90\xC0\x00\x00\xC0\xC3\xC2\xD6\x01true\xC7\x05\x01false".b,
|
||||
}
|
||||
@ebins = {
|
||||
:v2 => "<<132,104,9,100,0,4,117,115,101,114,104,3,100,0,4,98,101,114,116,100,0,4,100,105,99,116,108,0,0,0,1,104,2,100,0,4,110,97,109,101,113,0,0,0,3,84,80,87,106,108,0,0,0,2,104,4,100,0,4,98,101,114,116,100,0,5,114,101,103,101,120,113,0,0,0,3,99,97,116,108,0,0,0,1,100,0,8,99,97,115,101,108,101,115,115,106,99,57,46,57,48,48,48,48,48,48,48,48,48,48,48,48,48,48,101,43,48,48,0,0,0,0,0,0,0,0,0,0,106,104,5,100,0,4,98,101,114,116,100,0,4,116,105,109,101,98,0,0,4,230,98,0,14,228,195,97,0,104,2,100,0,4,98,101,114,116,100,0,3,110,105,108,104,2,100,0,4,98,101,114,116,100,0,4,116,114,117,101,104,2,100,0,4,98,101,114,116,100,0,5,102,97,108,115,101,100,0,4,116,114,117,101,100,0,5,102,97,108,115,101>>",
|
||||
:v3 => "<<133,153,164,117,115,101,114,147,164,98,101,114,116,164,100,105,99,116,145,146,164,110,97,109,101,163,84,80,87,146,148,164,98,101,114,116,165,114,101,103,101,120,163,99,97,116,145,168,99,97,115,101,108,101,115,115,203,64,35,204,204,204,204,204,205,149,164,98,101,114,116,164,116,105,109,101,205,4,230,206,0,14,228,195,0,146,164,98,101,114,116,163,110,105,108,146,164,98,101,114,116,164,116,114,117,101,146,164,98,101,114,116,165,102,97,108,115,101,164,116,114,117,101,165,102,97,108,115,101>>",
|
||||
:v3 => "<<133,153,214,1,117,115,101,114,129,214,1,110,97,109,101,163,84,80,87,146,199,9,2,1,0,0,0,89,50,70,48,10,203,64,35,204,204,204,204,204,205,215,3,65,210,179,90,144,192,0,0,192,195,194,214,1,116,114,117,101,199,5,1,102,97,108,115,101>>",
|
||||
}
|
||||
end
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче