Class: Transit::Marshaler::MessagePack

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/transit/marshaler/cruby/messagepack.rb

Instance Method Summary collapse

Methods included from Base

#build_handlers, #emit_array, #emit_boolean, #emit_double, #emit_encoded, #emit_map, #emit_nil, #emit_string, #emit_tagged_value, #escape, #find_handler, #marshal, #marshal_top, #parse_options

Constructor Details

#initialize(io, opts) ⇒ MessagePack

Returns a new instance of MessagePack.



22
23
24
25
26
27
28
29
# File 'lib/transit/marshaler/cruby/messagepack.rb', line 22

def initialize(io, opts)
  @io = io
  @packer = ::MessagePack::Packer.new(io)
  @max_int = MAX_INT
  @min_int = MIN_INT
  @prefer_strings = false
  parse_options(opts)
end

Instance Method Details

#emit_array_endObject



35
36
37
# File 'lib/transit/marshaler/cruby/messagepack.rb', line 35

def emit_array_end
  # no-op
end

#emit_array_start(size) ⇒ Object



31
32
33
# File 'lib/transit/marshaler/cruby/messagepack.rb', line 31

def emit_array_start(size)
  @packer.write_array_header(size)
end

#emit_int(tag, i, as_map_key, cache) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/transit/marshaler/cruby/messagepack.rb', line 47

def emit_int(tag, i, as_map_key, cache)
  if i > @max_int || i < @min_int
    emit_string(ESC, tag, i, as_map_key, cache)
  else
    emit_value(i, as_map_key)
  end
end

#emit_map_endObject



43
44
45
# File 'lib/transit/marshaler/cruby/messagepack.rb', line 43

def emit_map_end
  # no-op
end

#emit_map_start(size) ⇒ Object



39
40
41
# File 'lib/transit/marshaler/cruby/messagepack.rb', line 39

def emit_map_start(size)
  @packer.write_map_header(size)
end

#emit_value(obj, as_map_key = :ignore) ⇒ Object



55
56
57
# File 'lib/transit/marshaler/cruby/messagepack.rb', line 55

def emit_value(obj, as_map_key=:ignore)
  @packer.write(obj)
end

#flushObject



59
60
61
62
# File 'lib/transit/marshaler/cruby/messagepack.rb', line 59

def flush
  @packer.flush
  @io.flush
end