Module: Stargate::Codec
- Defined in:
- lib/stargate/codec.rb,
lib/stargate/codec/json.rb,
lib/stargate/codec/bencode.rb,
lib/stargate/codec/message_pack.rb more...
Defined Under Namespace
Classes: BEncode, JSON, MessagePack
Constant Summary collapse
- Error =
Public: Base codec error.
Class.new(::Stargate::Error)
- UndefinedCodecError =
Public: Raised when given codec is not registered.
Class.new(Error)
- DecodeError =
Public: Raised when codec cannot decode given data string.
Class.new(Error)
- @@codecs =
{}
Class Method Summary collapse
-
.[](content_type) ⇒ Object
Public: Find codec for given content type.
-
.codecs ⇒ Object
Internal: Returns all registered codecs.
-
.find_by_id(id) ⇒ Object
Public: Find codec by given identifier.
-
.register(codec) ⇒ Object
Public: Register new codec.
Class Method Details
permalink .[](content_type) ⇒ Object
Public: Find codec for given content type.
30 31 32 |
# File 'lib/stargate/codec.rb', line 30 def self.[](content_type) codecs[content_type.to_s] or raise UndefinedCodecError, "No codec for type: #{content_type}" end |
permalink .codecs ⇒ Object
Internal: Returns all registered codecs.
15 16 17 |
# File 'lib/stargate/codec.rb', line 15 def self.codecs @@codecs end |
permalink .find_by_id(id) ⇒ Object
Public: Find codec by given identifier.
25 26 27 |
# File 'lib/stargate/codec.rb', line 25 def self.find_by_id(id) codecs.values.find { |codec| codec.id == id.to_sym } or raise UndefinedCodecError, "No such codec: #{id}" end |
permalink .register(codec) ⇒ Object
Public: Register new codec.
20 21 22 |
# File 'lib/stargate/codec.rb', line 20 def self.register(codec) codecs[codec.content_type.to_s] = codec end |