Class: SQLite::Recordsets
- Inherits:
-
Object
- Object
- SQLite::Recordsets
- Defined in:
- lib/sqlite.rb
Overview
Used to serialize/deserialize Recordsets over AMQP message payloads
Instance Attribute Summary collapse
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#recordsets ⇒ Object
Returns the value of attribute recordsets.
Instance Method Summary collapse
- #<<(element) ⇒ Object
-
#fromMsgPack(binary) ⇒ Object
Deserilize MessagePack payload.
-
#initialize(binary = nil) ⇒ Recordsets
constructor
A new instance of Recordsets.
-
#toMsgPack ⇒ Object
Serilize MessagePack payload.
Constructor Details
#initialize(binary = nil) ⇒ Recordsets
Returns a new instance of Recordsets.
215 216 217 218 219 220 221 222 |
# File 'lib/sqlite.rb', line 215 def initialize(binary = nil) @headers = {} @recordsets = [] if not binary.nil? from_mpack binary end end |
Instance Attribute Details
#headers ⇒ Object
Returns the value of attribute headers.
212 213 214 |
# File 'lib/sqlite.rb', line 212 def headers @headers end |
#recordsets ⇒ Object
Returns the value of attribute recordsets.
212 213 214 |
# File 'lib/sqlite.rb', line 212 def recordsets @recordsets end |
Instance Method Details
#<<(element) ⇒ Object
224 225 226 227 228 229 230 |
# File 'lib/sqlite.rb', line 224 def <<(element) if element.class != Recordset raise "Invalide element type. Must be Recordset" end @recordsets << element end |
#fromMsgPack(binary) ⇒ Object
Deserilize MessagePack payload
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/sqlite.rb', line 246 def fromMsgPack(binary) @recordsets = [] data = MessagePack.unpack(binary) if data[0].class != Hash or data[1].class != Array raise "Invalid messagepack format" end @headers = data[0] # Convert raw recordset format into Ruby Recordset classes data[1].each do |rs| recordset = Recordset.new() recordset.load(rs) @recordsets << recordset end end |
#toMsgPack ⇒ Object
Serilize MessagePack payload
234 235 236 237 238 239 240 241 242 |
# File 'lib/sqlite.rb', line 234 def toMsgPack() # Convert Ruby Recordset instances to raw array format (JSON-like) recordsets = [] @recordsets.each do |recordset| recordsets << [recordset.columns, recordset.types, recordset.rows] end return MessagePack.pack([@headers, recordsets]) end |