class Neo4j::Core::PackStream::Packer
Object which holds a Ruby object and can pack it into a PackStream
stream
Constants
- INT_HEADERS
Range Minimum | Range Maximum | Representation | Byte |
|============================|================|======|¶ ↑
-9 223 372 036 854 775 808 | -2 147 483 649 | INT_64 | CB | -2 147 483 648 | -32 769 | INT_32 | CA | -32 768 | -129 | INT_16 | C9 | -128 | -17 | INT_8 | C8 | -16 | +127 | TINY_INT | N/A | +128 | +32 767 | INT_16 | C9 | +32 768 | +2 147 483 647 | INT_32 | CA | +2 147 483 648 | +9 223 372 036 854 775 807 | INT_64 | CB |
Public Class Methods
new(object)
click to toggle source
# File lib/neo4j/core/cypher_session/adaptors/bolt/pack_stream.rb 60 def initialize(object) 61 @object = object 62 end
pack_arguments(*objects)
click to toggle source
# File lib/neo4j/core/cypher_session/adaptors/bolt/pack_stream.rb 148 def self.pack_arguments(*objects) 149 objects.map { |o| new(o).packed_stream }.join 150 end
Public Instance Methods
array_stream()
click to toggle source
# File lib/neo4j/core/cypher_session/adaptors/bolt/pack_stream.rb 125 def array_stream 126 marker_string(0x90, 0xD4, @object.size) + @object.map do |e| 127 Packer.new(e).packed_stream 128 end.join 129 end
Also aliased as: set_stream
float_stream()
click to toggle source
# File lib/neo4j/core/cypher_session/adaptors/bolt/pack_stream.rb 106 def float_stream 107 MARKER_HEADERS[:float][64] + [@object].pack('G').force_encoding(Encoding::BINARY) 108 end
hash_stream()
click to toggle source
# File lib/neo4j/core/cypher_session/adaptors/bolt/pack_stream.rb 140 def hash_stream 141 marker_string(0xA0, 0xD8, @object.size) + 142 @object.map do |key, value| 143 Packer.new(key).packed_stream + 144 Packer.new(value).packed_stream 145 end.join 146 end
integer_stream()
click to toggle source
# File lib/neo4j/core/cypher_session/adaptors/bolt/pack_stream.rb 88 def integer_stream 89 case @object 90 when -0x10...0x80 # TINY_INT 91 pack_integer_object_as_string 92 when -0x80...-0x10 # INT_8 93 INT_HEADERS[8] + pack_integer_object_as_string 94 when -0x8000...0x8000 # INT_16 95 INT_HEADERS[16] + pack_integer_object_as_string(2) 96 when -0x80000000...0x80000000 # INT_32 97 INT_HEADERS[32] + pack_integer_object_as_string(4) 98 when -0x8000000000000000...0x8000000000000000 # INT_64 99 INT_HEADERS[64] + pack_integer_object_as_string(8) 100 end 101 end
Also aliased as: fixnum_stream, bignum_stream
packed_stream()
click to toggle source
# File lib/neo4j/core/cypher_session/adaptors/bolt/pack_stream.rb 64 def packed_stream 65 if byte = MARKER_BYTES[@object] 66 pack_array_as_string([byte]) 67 else 68 case @object 69 when Date, Time, DateTime then string_stream 70 when Integer, Float, String, Symbol, Array, Set, Structure, Hash 71 send(@object.class.name.split('::').last.downcase + '_stream') 72 end 73 end 74 end
string_stream()
click to toggle source
Marker | Size | Maximum size
|=============================================|=====================¶ ↑
80..8F | contained within low-order nibble of marker | 15 bytes D0 | 8-bit big-endian unsigned integer | 255 bytes D1 | 16-bit big-endian unsigned integer | 65 535 bytes D2 | 32-bit big-endian unsigned integer | 4 294 967 295 bytes
# File lib/neo4j/core/cypher_session/adaptors/bolt/pack_stream.rb 117 def string_stream 118 s = @object.to_s 119 s = s.dup if s.frozen? 120 marker_string(0x80, 0xD0, @object.to_s.bytesize) + s.force_encoding(Encoding::BINARY) 121 end
Also aliased as: symbol_stream
structure_stream()
click to toggle source
# File lib/neo4j/core/cypher_session/adaptors/bolt/pack_stream.rb 133 def structure_stream 134 fail 'Structure too big' if @object.list.size > 65_535 135 marker_string(0xB0, 0xDC, @object.list.size) + [@object.signature].pack('C') + @object.list.map do |e| 136 Packer.new(e).packed_stream 137 end.join 138 end
Private Instance Methods
marker_string(tiny_base, regular_base, size)
click to toggle source
# File lib/neo4j/core/cypher_session/adaptors/bolt/pack_stream.rb 154 def marker_string(tiny_base, regular_base, size) 155 head_byte = case size 156 when 0...0x10 then tiny_base + size 157 when 0x10...0x100 then regular_base 158 when 0x100...0x10000 then regular_base + 1 159 when 0x10000...0x100000000 then regular_base + 2 160 end 161 162 result = [head_byte].pack('C') 163 result += [size].pack(HEADER_PACK_STRINGS[head_byte - regular_base]).reverse if size >= 0x10 164 result 165 end
pack_array_as_string(a)
click to toggle source
# File lib/neo4j/core/cypher_session/adaptors/bolt/pack_stream.rb 177 def pack_array_as_string(a) 178 a.pack('c*') 179 end
pack_integer_object_as_string(size = 1)
click to toggle source
# File lib/neo4j/core/cypher_session/adaptors/bolt/pack_stream.rb 167 def pack_integer_object_as_string(size = 1) 168 bytes = [] 169 (0...size).to_a.reverse.inject(@object) do |current, i| 170 bytes << (current / (256**i)) 171 current % (256**i) 172 end 173 174 pack_array_as_string(bytes) 175 end