Class: ActiveCypher::Bolt::Packstream::Packer

Inherits:
Object
  • Object
show all
Defined in:
lib/active_cypher/bolt/packstream.rb

Overview

Packs Ruby objects into Packstream byte format.

Constant Summary collapse

NULL =

Define constants inside Packer where they are used

0xC0
FALSEY =
0xC2
TRUETHY =
0xC3
FLOAT_64 =
0xC1

Instance Method Summary collapse

Constructor Details

#initialize(io) ⇒ Packer

Returns a new instance of Packer.



52
53
54
# File 'lib/active_cypher/bolt/packstream.rb', line 52

def initialize(io)
  @io = io
end

Instance Method Details

#pack(value) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/active_cypher/bolt/packstream.rb', line 56

def pack(value)
  case value
  when String then pack_string(value)
  when Hash then pack_map(value)
  when Integer then pack_integer(value)
  when Float then pack_float(value)
  when BigDecimal then pack_string(value.to_s('F'))
  when TrueClass then write_marker([TRUETHY].pack('C'))
  when FalseClass then write_marker([FALSEY].pack('C'))
  when NilClass then write_marker([NULL].pack('C'))
  when Array then pack_list(value)
  # TODO: Add other types maybe Postgis stuff when i'm ready for it
  else
    raise ProtocolError, "Cannot pack type: #{value.class}"
  end
end