Class: Twilic::Core::Session::MutableSessionState
- Inherits:
-
Object
- Object
- Twilic::Core::Session::MutableSessionState
- Defined in:
- lib/twilic/core/session.rb
Overview
Mutable wrapper for session state used during encode/decode
Instance Attribute Summary collapse
-
#base_snapshots ⇒ Object
Returns the value of attribute base_snapshots.
-
#dictionaries ⇒ Object
Returns the value of attribute dictionaries.
-
#dictionary_profiles ⇒ Object
Returns the value of attribute dictionary_profiles.
-
#encode_shape_observations ⇒ Object
Returns the value of attribute encode_shape_observations.
-
#field_enums ⇒ Object
Returns the value of attribute field_enums.
-
#key_table ⇒ Object
Returns the value of attribute key_table.
-
#last_schema_id ⇒ Object
Returns the value of attribute last_schema_id.
-
#next_base_id ⇒ Object
Returns the value of attribute next_base_id.
-
#next_dictionary_id ⇒ Object
Returns the value of attribute next_dictionary_id.
-
#next_template_id ⇒ Object
Returns the value of attribute next_template_id.
-
#options ⇒ Object
Returns the value of attribute options.
-
#previous_message ⇒ Object
Returns the value of attribute previous_message.
-
#previous_message_size ⇒ Object
Returns the value of attribute previous_message_size.
-
#schemas ⇒ Object
Returns the value of attribute schemas.
-
#shape_table ⇒ Object
Returns the value of attribute shape_table.
-
#string_table ⇒ Object
Returns the value of attribute string_table.
-
#template_columns ⇒ Object
Returns the value of attribute template_columns.
-
#templates ⇒ Object
Returns the value of attribute templates.
Instance Method Summary collapse
- #allocate_base_id ⇒ Object
- #allocate_dictionary_id ⇒ Object
- #allocate_template_id ⇒ Object
- #get_base_snapshot(base_id) ⇒ Object
-
#initialize(options = SessionOptions.default) ⇒ MutableSessionState
constructor
A new instance of MutableSessionState.
- #register_base_snapshot(base_id, message) ⇒ Object
- #reset_state ⇒ Object
- #reset_tables ⇒ Object
- #shape_key(keys) ⇒ Object
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( = SessionOptions.default) @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_snapshots ⇒ Object
Returns the value of attribute base_snapshots.
232 233 234 |
# File 'lib/twilic/core/session.rb', line 232 def base_snapshots @base_snapshots end |
#dictionaries ⇒ Object
Returns the value of attribute dictionaries.
232 233 234 |
# File 'lib/twilic/core/session.rb', line 232 def dictionaries @dictionaries end |
#dictionary_profiles ⇒ Object
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_observations ⇒ Object
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_enums ⇒ Object
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_table ⇒ Object
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_id ⇒ Object
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_id ⇒ Object
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_id ⇒ Object
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_id ⇒ Object
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 |
#options ⇒ Object
Returns the value of attribute options.
232 233 234 |
# File 'lib/twilic/core/session.rb', line 232 def @options end |
#previous_message ⇒ Object
Returns the value of attribute previous_message.
232 233 234 |
# File 'lib/twilic/core/session.rb', line 232 def @previous_message end |
#previous_message_size ⇒ Object
Returns the value of attribute previous_message_size.
232 233 234 |
# File 'lib/twilic/core/session.rb', line 232 def @previous_message_size end |
#schemas ⇒ Object
Returns the value of attribute schemas.
232 233 234 |
# File 'lib/twilic/core/session.rb', line 232 def schemas @schemas end |
#shape_table ⇒ Object
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_table ⇒ Object
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_columns ⇒ Object
Returns the value of attribute template_columns.
232 233 234 |
# File 'lib/twilic/core/session.rb', line 232 def template_columns @template_columns end |
#templates ⇒ Object
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_id ⇒ Object
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_id ⇒ Object
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_id ⇒ Object
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.., 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, ) @base_snapshots.reject! { |e| e.id == base_id } @base_snapshots << BaseSnapshotEntry.new(id: base_id, message: .) while @base_snapshots.length > @options.max_base_snapshots @base_snapshots.shift end end |
#reset_state ⇒ Object
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_tables ⇒ Object
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 |