Sha256: 77e8ce08564a3307c3f6994a961a5f33888cbd9f584a4133e23e48183f8c271e
Contents?: true
Size: 884 Bytes
Versions: 16
Compression:
Stored size: 884 Bytes
Contents
require 'oj' class Mercury class WireSerializer # TODO: DRY with hyperion once we know more def write(struct_or_hash) write_json(struct_or_hash) end def read(bytes) read_json(bytes) end private def write_json(obj) if obj.is_a?(String) obj else Oj.dump(hashify(obj), oj_options) end end def read_json(bytes) begin Oj.compat_load(bytes, oj_options) rescue Oj::ParseError => e bytes end end def oj_options { mode: :compat, time_format: :xmlschema, # xmlschema == iso8601 use_to_json: false, second_precision: 3 } end def hashify(x) case x when Hash x when Struct x.to_h else raise "Could not convert to hash: #{x.inspect}" end end end end
Version data entries
16 entries across 16 versions & 1 rubygems