Module: Hyperion::Formats
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Logger
#log_stub, #logger, #with_request_logging
Class Method Details
.get_from(x) ⇒ Object
36
37
38
|
# File 'lib/hyperion/formats.rb', line 36
def self.get_from(x)
x.respond_to?(:format) ? x.format : x
end
|
Instance Method Details
#read(bytes, format) ⇒ Object
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/hyperion/formats.rb', line 25
def read(bytes, format)
return nil if bytes.nil?
return bytes if format.nil?
case Formats.get_from(format)
when :json; read_json(bytes)
when :protobuf; bytes
else; fail "Unsupported format: #{format}"
end
end
|
#write(obj, format) ⇒ Object
15
16
17
18
19
20
21
22
23
|
# File 'lib/hyperion/formats.rb', line 15
def write(obj, format)
return obj if obj.is_a?(String) || obj.nil? || format.nil?
case Formats.get_from(format)
when :json; write_json(obj)
when :protobuf; obj
else; fail "Unsupported format: #{format}"
end
end
|