Class: Twilic::Core::Session::MutableSessionState

Inherits:
Object
  • Object
show all
Defined in:
lib/twilic/core/session.rb

Overview

Mutable wrapper for session state used during encode/decode

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = SessionOptions.default) ⇒ MutableSessionState

Returns a new instance of MutableSessionState.



239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'lib/twilic/core/session.rb', line 239

def initialize(options = SessionOptions.default)
  @options = options
  @key_table = MutableInternTable.new
  @string_table = MutableInternTable.new
  @shape_table = MutableShapeTable.new
  @encode_shape_observations = {}
  @base_snapshots = []
  @templates = {}
  @template_columns = {}
  @field_enums = {}
  @dictionaries = {}
  @dictionary_profiles = {}
  @schemas = {}
  @last_schema_id = nil
  @previous_message = nil
  @previous_message_size = nil
  @next_base_id = 0
  @next_template_id = 0
  @next_dictionary_id = 0
end

Instance Attribute Details

#base_snapshotsObject

Returns the value of attribute base_snapshots.



232
233
234
# File 'lib/twilic/core/session.rb', line 232

def base_snapshots
  @base_snapshots
end

#dictionariesObject

Returns the value of attribute dictionaries.



232
233
234
# File 'lib/twilic/core/session.rb', line 232

def dictionaries
  @dictionaries
end

#dictionary_profilesObject

Returns the value of attribute dictionary_profiles.



232
233
234
# File 'lib/twilic/core/session.rb', line 232

def dictionary_profiles
  @dictionary_profiles
end

#encode_shape_observationsObject

Returns the value of attribute encode_shape_observations.



232
233
234
# File 'lib/twilic/core/session.rb', line 232

def encode_shape_observations
  @encode_shape_observations
end

#field_enumsObject

Returns the value of attribute field_enums.



232
233
234
# File 'lib/twilic/core/session.rb', line 232

def field_enums
  @field_enums
end

#key_tableObject

Returns the value of attribute key_table.



232
233
234
# File 'lib/twilic/core/session.rb', line 232

def key_table
  @key_table
end

#last_schema_idObject

Returns the value of attribute last_schema_id.



232
233
234
# File 'lib/twilic/core/session.rb', line 232

def last_schema_id
  @last_schema_id
end

#next_base_idObject

Returns the value of attribute next_base_id.



232
233
234
# File 'lib/twilic/core/session.rb', line 232

def next_base_id
  @next_base_id
end

#next_dictionary_idObject

Returns the value of attribute next_dictionary_id.



232
233
234
# File 'lib/twilic/core/session.rb', line 232

def next_dictionary_id
  @next_dictionary_id
end

#next_template_idObject

Returns the value of attribute next_template_id.



232
233
234
# File 'lib/twilic/core/session.rb', line 232

def next_template_id
  @next_template_id
end

#optionsObject

Returns the value of attribute options.



232
233
234
# File 'lib/twilic/core/session.rb', line 232

def options
  @options
end

#previous_messageObject

Returns the value of attribute previous_message.



232
233
234
# File 'lib/twilic/core/session.rb', line 232

def previous_message
  @previous_message
end

#previous_message_sizeObject

Returns the value of attribute previous_message_size.



232
233
234
# File 'lib/twilic/core/session.rb', line 232

def previous_message_size
  @previous_message_size
end

#schemasObject

Returns the value of attribute schemas.



232
233
234
# File 'lib/twilic/core/session.rb', line 232

def schemas
  @schemas
end

#shape_tableObject

Returns the value of attribute shape_table.



232
233
234
# File 'lib/twilic/core/session.rb', line 232

def shape_table
  @shape_table
end

#string_tableObject

Returns the value of attribute string_table.



232
233
234
# File 'lib/twilic/core/session.rb', line 232

def string_table
  @string_table
end

#template_columnsObject

Returns the value of attribute template_columns.



232
233
234
# File 'lib/twilic/core/session.rb', line 232

def template_columns
  @template_columns
end

#templatesObject

Returns the value of attribute templates.



232
233
234
# File 'lib/twilic/core/session.rb', line 232

def templates
  @templates
end

Instance Method Details

#allocate_base_idObject



272
273
274
275
276
# File 'lib/twilic/core/session.rb', line 272

def allocate_base_id
  id = @next_base_id
  @next_base_id += 1
  id
end

#allocate_dictionary_idObject



284
285
286
287
288
# File 'lib/twilic/core/session.rb', line 284

def allocate_dictionary_id
  id = @next_dictionary_id
  @next_dictionary_id += 1
  id
end

#allocate_template_idObject



278
279
280
281
282
# File 'lib/twilic/core/session.rb', line 278

def allocate_template_id
  id = @next_template_id
  @next_template_id += 1
  id
end

#get_base_snapshot(base_id) ⇒ Object



290
291
292
293
294
295
# File 'lib/twilic/core/session.rb', line 290

def get_base_snapshot(base_id)
  entry = @base_snapshots.find { |e| e.id == base_id }
  return [nil, false] unless entry

  [entry.message.clone_message, true]
end

#register_base_snapshot(base_id, message) ⇒ Object



264
265
266
267
268
269
270
# File 'lib/twilic/core/session.rb', line 264

def register_base_snapshot(base_id, message)
  @base_snapshots.reject! { |e| e.id == base_id }
  @base_snapshots << BaseSnapshotEntry.new(id: base_id, message: message.clone_message)
  while @base_snapshots.length > @options.max_base_snapshots
    @base_snapshots.shift
  end
end

#reset_stateObject



305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
# File 'lib/twilic/core/session.rb', line 305

def reset_state
  reset_tables
  @base_snapshots = []
  @templates = {}
  @template_columns = {}
  @dictionaries = {}
  @dictionary_profiles = {}
  @schemas = {}
  @last_schema_id = nil
  @previous_message = nil
  @previous_message_size = nil
  @next_base_id = 0
  @next_template_id = 0
  @next_dictionary_id = 0
end

#reset_tablesObject



297
298
299
300
301
302
303
# File 'lib/twilic/core/session.rb', line 297

def reset_tables
  @key_table = MutableInternTable.new
  @string_table = MutableInternTable.new
  @shape_table = MutableShapeTable.new
  @encode_shape_observations = {}
  @field_enums = {}
end

#shape_key(keys) ⇒ Object



260
261
262
# File 'lib/twilic/core/session.rb', line 260

def shape_key(keys)
  keys.join("\0")
end