Class: Neo4j::Core::CypherSession::Adaptors::Bolt::Message
- Inherits:
-
Object
- Object
- Neo4j::Core::CypherSession::Adaptors::Bolt::Message
- Defined in:
- lib/neo4j/core/cypher_session/adaptors/bolt.rb
Overview
Represents messages sent to or received from the server
Constant Summary collapse
- TYPE_CODES =
{ # client message types init: 0x01, # 0000 0001 // INIT <user_agent> ack_failure: 0x0E, # 0000 1110 // ACK_FAILURE reset: 0x0F, # 0000 1111 // RESET run: 0x10, # 0001 0000 // RUN <statement> <parameters> discard_all: 0x2F, # 0010 1111 // DISCARD * pull_all: 0x3F, # 0011 1111 // PULL * # server message types success: 0x70, # 0111 0000 // SUCCESS <metadata> record: 0x71, # 0111 0001 // RECORD <value> ignored: 0x7E, # 0111 1110 // IGNORED <metadata> failure: 0x7F # 0111 1111 // FAILURE <metadata> }.freeze
- CODE_TYPES =
TYPE_CODES.invert
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(type_or_code, *args) ⇒ Message
constructor
A new instance of Message.
- #packed_stream ⇒ Object
- #struct ⇒ Object
- #to_s ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(type_or_code, *args) ⇒ Message
Returns a new instance of Message.
251 252 253 254 255 256 257 |
# File 'lib/neo4j/core/cypher_session/adaptors/bolt.rb', line 251 def initialize(type_or_code, *args) @type_code = Message.type_code_for(type_or_code) fail "Invalid message type: #{@type_code.inspect}" if !@type_code @type = CODE_TYPES[@type_code] @args = args end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
285 286 287 |
# File 'lib/neo4j/core/cypher_session/adaptors/bolt.rb', line 285 def args @args end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
285 286 287 |
# File 'lib/neo4j/core/cypher_session/adaptors/bolt.rb', line 285 def type @type end |
Class Method Details
.interpret_field_value(value) ⇒ Object
291 292 293 294 295 296 297 298 299 300 301 |
# File 'lib/neo4j/core/cypher_session/adaptors/bolt.rb', line 291 def self.interpret_field_value(value) if value.is_a?(Array) && (1..3).cover?(value[0]) case value[0] when 1 {type: :node, identity: value[1], labels: value[2], properties: value[3]} end else value end end |
.type_code_for(type_or_code) ⇒ Object
287 288 289 |
# File 'lib/neo4j/core/cypher_session/adaptors/bolt.rb', line 287 def self.type_code_for(type_or_code) type_or_code.is_a?(Integer) ? type_or_code : TYPE_CODES[type_or_code] end |
Instance Method Details
#packed_stream ⇒ Object
267 268 269 |
# File 'lib/neo4j/core/cypher_session/adaptors/bolt.rb', line 267 def packed_stream PackStream::Packer.new(struct).packed_stream end |
#struct ⇒ Object
259 260 261 |
# File 'lib/neo4j/core/cypher_session/adaptors/bolt.rb', line 259 def struct PackStream::Structure.new(@type_code, @args) end |
#to_s ⇒ Object
263 264 265 |
# File 'lib/neo4j/core/cypher_session/adaptors/bolt.rb', line 263 def to_s "#{ANSI::GREEN}#{@type.to_s.upcase}#{ANSI::CLEAR} #{@args.inspect if !@args.empty?}" end |
#value ⇒ Object
271 272 273 274 275 276 277 278 279 280 281 282 283 |
# File 'lib/neo4j/core/cypher_session/adaptors/bolt.rb', line 271 def value return if @type != :record @args.map do |arg| # Assuming result is Record field_names = arg[1] field_values = arg[2].map do |field_value| Message.interpret_field_value(field_value) end Hash[field_names.zip(field_values)] end end |