Module: THTP::Encoding

Defined in:
lib/thtp/encoding.rb

Overview

Handling of registered MIME types and protocols

Constant Summary collapse

BINARY =
'application/vnd.apache.thrift.binary'.freeze
COMPACT =
'application/vnd.apache.thrift.compact'.freeze
JSON =
'application/vnd.apache.thrift.json'.freeze

Class Method Summary collapse

Class Method Details

.content_type(protocol) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/thtp/encoding.rb', line 21

def self.content_type(protocol)
  # this can't be a case/when because Class !=== Class
  if protocol == Thrift::BinaryProtocol
    BINARY
  elsif protocol == Thrift::CompactProtocol
    COMPACT
  elsif protocol == Thrift::JsonProtocol
    JSON
  end
end

.protocol(content_type) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/thtp/encoding.rb', line 10

def self.protocol(content_type)
  case content_type
  when BINARY
    Thrift::BinaryProtocol
  when COMPACT
    Thrift::CompactProtocol
  when JSON
    Thrift::JsonProtocol
  end
end