class Neo4j::Core::PackStream::Unpacker

Object which holds a stream of PackStream data and can unpack it

Constants

HEADER_BASE_BYTES
METHOD_MAP

Public Class Methods

new(stream) click to toggle source
    # File lib/neo4j/core/cypher_session/adaptors/bolt/pack_stream.rb
185 def initialize(stream)
186   @stream = stream
187 end

Public Instance Methods

unpack_value!() click to toggle source
    # File lib/neo4j/core/cypher_session/adaptors/bolt/pack_stream.rb
191 def unpack_value!
192   return nil if depleted?
193 
194   marker = shift_byte!
195 
196   if type_and_size = PackStream.marker_type_and_size(marker)
197     type, size = type_and_size
198 
199     shift_value_for_type!(type, size, marker)
200   elsif MARKER_TYPES.key?(marker)
201     MARKER_TYPES[marker]
202   else
203     marker >= 0xF0 ? -0x100 + marker : marker
204   end
205 end

Private Instance Methods

depleted?() click to toggle source
    # File lib/neo4j/core/cypher_session/adaptors/bolt/pack_stream.rb
273 def depleted?
274   @stream.eof?
275 end
shift_byte!() click to toggle source
    # File lib/neo4j/core/cypher_session/adaptors/bolt/pack_stream.rb
260 def shift_byte!
261   shift_bytes!(1).first unless depleted?
262 end
shift_bytes!(length) click to toggle source
    # File lib/neo4j/core/cypher_session/adaptors/bolt/pack_stream.rb
264 def shift_bytes!(length)
265   result = shift_stream!(length)
266   result && result.bytes.to_a
267 end
shift_stream!(length) click to toggle source
    # File lib/neo4j/core/cypher_session/adaptors/bolt/pack_stream.rb
269 def shift_stream!(length)
270   @stream.read(length) if !depleted? || length.zero?
271 end
shift_value_for_type!(type, size, marker) click to toggle source
    # File lib/neo4j/core/cypher_session/adaptors/bolt/pack_stream.rb
220 def shift_value_for_type!(type, size, marker)
221   if %i[text list map struct].include?(type)
222     offset = marker - HEADER_BASE_BYTES[type]
223     size = shift_stream!(2 << (offset - 1)).reverse.unpack(HEADER_PACK_STRINGS[offset])[0]
224   end
225 
226   if %i[tiny_text text bytes].include?(type)
227     shift_stream!(size).force_encoding('UTF-8')
228   else
229     send(METHOD_MAP[type], size)
230   end
231 end
value_for_float!(_size) click to toggle source
    # File lib/neo4j/core/cypher_session/adaptors/bolt/pack_stream.rb
241 def value_for_float!(_size)
242   shift_stream!(8).unpack('G')[0]
243 end
value_for_int!(size) click to toggle source
    # File lib/neo4j/core/cypher_session/adaptors/bolt/pack_stream.rb
233 def value_for_int!(size)
234   r = shift_bytes!(size >> 3).reverse.each_with_index.inject(0) do |sum, (byte, i)|
235     sum + (byte * (256**i))
236   end
237 
238   (r >> (size - 1)) == 1 ? (r - (2**size)) : r
239 end
value_for_list!(size) click to toggle source
    # File lib/neo4j/core/cypher_session/adaptors/bolt/pack_stream.rb
252 def value_for_list!(size)
253   Array.new(size) { unpack_value! }
254 end
value_for_map!(size) click to toggle source
    # File lib/neo4j/core/cypher_session/adaptors/bolt/pack_stream.rb
245 def value_for_map!(size)
246   size.times.each_with_object({}) do |_, r|
247     key = unpack_value!
248     r[key] = unpack_value!
249   end
250 end
value_for_struct!(size) click to toggle source
    # File lib/neo4j/core/cypher_session/adaptors/bolt/pack_stream.rb
256 def value_for_struct!(size)
257   Structure.new(shift_byte!, value_for_list!(size))
258 end