Class: ActiveCypher::Bolt::MessageWriter
- Inherits:
-
Object
- Object
- ActiveCypher::Bolt::MessageWriter
- Defined in:
- lib/active_cypher/bolt/message_writer.rb
Overview
Handles encoding Bolt messages into Packstream format for Bolt v5.0
Constant Summary collapse
- TINY_STRUCT_MARKER_BASE =
Structure Markers
0xB0
- STRUCT_8_MARKER =
0xDC
- STRUCT_16_MARKER =
0xDD
Instance Method Summary collapse
-
#initialize(io) ⇒ MessageWriter
constructor
STRUCT_32_MARKER = 0xDE # Not implementing 32-bit sizes for now.
-
#write(message) ⇒ Object
Encodes and writes a Bolt message to the underlying IO stream.
Constructor Details
#initialize(io) ⇒ MessageWriter
STRUCT_32_MARKER = 0xDE # Not implementing 32-bit sizes for now
13 14 15 16 |
# File 'lib/active_cypher/bolt/message_writer.rb', line 13 def initialize(io) @packer = Packstream::Packer.new(io) @io = io # Keep a reference for direct writing if needed end |
Instance Method Details
#write(message) ⇒ Object
Encodes and writes a Bolt message to the underlying IO stream.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/active_cypher/bolt/message_writer.rb', line 20 def write() # Bolt 4.3 requires different chunking size = .fields.size # Write structure header with size and signature if size < 16 write_marker([TINY_STRUCT_MARKER_BASE | size].pack('C')) else write_marker([STRUCT_8_MARKER, size].pack('CC')) end # Write signature write_marker([.signature].pack('C')) # Pack fields with careful handling of nils .fields.each do |field| if field.nil? @packer.pack(nil) else @packer.pack(field) end end end |