Class: Rack::Session::SmartCookie::MessagePack
- Inherits:
-
Object
- Object
- Rack::Session::SmartCookie::MessagePack
- Defined in:
- lib/rack/session/smart_cookie.rb
Instance Attribute Summary collapse
-
#factory ⇒ Object
readonly
Returns the value of attribute factory.
Instance Method Summary collapse
- #decode(bin) ⇒ Object
- #encode(data) ⇒ Object
-
#initialize {|@factory| ... } ⇒ MessagePack
constructor
A new instance of MessagePack.
Constructor Details
#initialize {|@factory| ... } ⇒ MessagePack
Returns a new instance of MessagePack.
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rack/session/smart_cookie.rb', line 45 def initialize # Create our own factory so we don't pollute the global namespace # with our custom type. @factory = ::MessagePack::Factory.new # MessagePack gets custom types 0x80..0xFF # we get 0x60...0x80 @factory.register_type(0x60, Symbol) # user gets 0x00...0x60 yield @factory if block_given? end |
Instance Attribute Details
#factory ⇒ Object (readonly)
Returns the value of attribute factory.
43 44 45 |
# File 'lib/rack/session/smart_cookie.rb', line 43 def factory @factory end |
Instance Method Details
#decode(bin) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/rack/session/smart_cookie.rb', line 62 def decode(bin) return unless bin # https://github.com/msgpack/msgpack-ruby/issues/141 factory.unpacker.feed(bin).read rescue end |
#encode(data) ⇒ Object
57 58 59 60 |
# File 'lib/rack/session/smart_cookie.rb', line 57 def encode(data) # https://github.com/msgpack/msgpack-ruby/issues/141 factory.packer.write(data).to_str end |