Class: Stargate::Codec::BEncode

Inherits:
Object
  • Object
show all
Defined in:
lib/stargate/codec/bencode.rb

Overview

Internal: BEncode (BitTorrent encoding) powered codec.

Class Method Summary collapse

Class Method Details

.content_typeObject


11
12
13
# File 'lib/stargate/codec/bencode.rb', line 11

def self.content_type
  'application/bencode'
end

.decode(str) ⇒ Object


19
20
21
22
23
# File 'lib/stargate/codec/bencode.rb', line 19

def self.decode(str)
  ::BEncode::Parser.new(str).parse!
rescue ::BEncode::DecodeError => err
  raise DecodeError, "Arguments cannot be decoded: bencode parser error"
end

.encode(obj) ⇒ Object


15
16
17
# File 'lib/stargate/codec/bencode.rb', line 15

def self.encode(obj)
  obj.bencode
end

.idObject


7
8
9
# File 'lib/stargate/codec/bencode.rb', line 7

def self.id
  :bencode
end