Class: Neo4j::Driver::PackStream::Unpacker
- Inherits:
-
Object
- Object
- Neo4j::Driver::PackStream::Unpacker
- Includes:
- Markers
- Defined in:
- lib/neo4j/driver/packstream/unpacker.rb
Overview
PackStream Unpacker - deserializes PackStream binary format to Ruby objects
Constant Summary
Constants included from Markers
Markers::BOOLEAN_FALSE, Markers::BOOLEAN_TRUE, Markers::BYTES_16, Markers::BYTES_32, Markers::BYTES_8, Markers::FLOAT_64, Markers::INT_16, Markers::INT_32, Markers::INT_64, Markers::INT_8, Markers::LIST_16, Markers::LIST_32, Markers::LIST_8, Markers::MAP_16, Markers::MAP_32, Markers::MAP_8, Markers::NULL, Markers::STRING_16, Markers::STRING_32, Markers::STRING_8, Markers::STRUCT_16, Markers::STRUCT_8, Markers::TINY_LIST, Markers::TINY_MAP, Markers::TINY_STRING, Markers::TINY_STRUCT, Markers::UUID
Instance Method Summary collapse
-
#initialize(io, protocol) ⇒ Unpacker
constructor
A new instance of Unpacker.
-
#raise_unknown_marker(marker) ⇒ Object
A ProtocolException (not a bare RuntimeError) so the failure reaches the user as a DriverError.
- #register_hydration_handler(signature, handler = nil, &block) ⇒ Object
- #unpack ⇒ Object
-
#unpack_uuid_value ⇒ Object
PackStream V2 UUID (Bolt 6.1+): 16 raw bytes (big-endian) after the marker, rendered to the canonical hyphenated form for Types::UUID.
Constructor Details
#initialize(io, protocol) ⇒ Unpacker
Returns a new instance of Unpacker.
10 11 12 13 14 |
# File 'lib/neo4j/driver/packstream/unpacker.rb', line 10 def initialize(io, protocol) @io = io @hydration_handlers = {} @protocol = protocol end |
Instance Method Details
#raise_unknown_marker(marker) ⇒ Object
A ProtocolException (not a bare RuntimeError) so the failure reaches the user as a DriverError. The wording carries "PackStream" and the zero-padded marker byte — e.g. a UUID (0xE0) received before Bolt 6.1, which Protocol::Base#unpack_uuid routes here. testkit's UUID-over-6.0 assertion greps the lowercased message for "unknown packstream" and "e0", both of which this satisfies.
42 43 44 45 |
# File 'lib/neo4j/driver/packstream/unpacker.rb', line 42 def raise_unknown_marker(marker) raise Exceptions::ProtocolException, format('Unknown PackStream type marker: 0x%02x', marker) end |
#register_hydration_handler(signature, handler = nil, &block) ⇒ Object
16 17 18 |
# File 'lib/neo4j/driver/packstream/unpacker.rb', line 16 def register_hydration_handler(signature, handler = nil, &block) @hydration_handlers[signature] = handler || block end |
#unpack ⇒ Object
20 21 22 23 |
# File 'lib/neo4j/driver/packstream/unpacker.rb', line 20 def unpack marker_byte = read_bytes(1).unpack1('C') unpack_value(marker_byte) end |
#unpack_uuid_value ⇒ Object
PackStream V2 UUID (Bolt 6.1+): 16 raw bytes (big-endian) after the marker, rendered to the canonical hyphenated form for Types::UUID. Called by Protocol::V61#unpack_uuid — earlier protocols reject the marker instead, so this is only reached once 6.1 is negotiated.
29 30 31 32 33 34 |
# File 'lib/neo4j/driver/packstream/unpacker.rb', line 29 def unpack_uuid_value hex = read_bytes(16).unpack1('H*') Types::UUID.from_string( "#{hex[0, 8]}-#{hex[8, 4]}-#{hex[12, 4]}-#{hex[16, 4]}-#{hex[20, 12]}" ) end |