Class: Twilic::Core::Model::Message

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#arrayObject (readonly)

Returns the value of attribute array

Returns:

  • (Object)

    the current value of array



244
245
246
# File 'lib/twilic/core/model.rb', line 244

def array
  @array
end

#base_snapshotObject (readonly)

Returns the value of attribute base_snapshot

Returns:

  • (Object)

    the current value of base_snapshot



244
245
246
# File 'lib/twilic/core/model.rb', line 244

def base_snapshot
  @base_snapshot
end

#column_batchObject (readonly)

Returns the value of attribute column_batch

Returns:

  • (Object)

    the current value of column_batch



244
245
246
# File 'lib/twilic/core/model.rb', line 244

def column_batch
  @column_batch
end

#controlObject (readonly)

Returns the value of attribute control

Returns:

  • (Object)

    the current value of control



244
245
246
# File 'lib/twilic/core/model.rb', line 244

def control
  @control
end

#control_streamObject (readonly)

Returns the value of attribute control_stream

Returns:

  • (Object)

    the current value of control_stream



244
245
246
# File 'lib/twilic/core/model.rb', line 244

def control_stream
  @control_stream
end

#extObject (readonly)

Returns the value of attribute ext

Returns:

  • (Object)

    the current value of ext



244
245
246
# File 'lib/twilic/core/model.rb', line 244

def ext
  @ext
end

#kindObject (readonly)

Returns the value of attribute kind

Returns:

  • (Object)

    the current value of kind



244
245
246
# File 'lib/twilic/core/model.rb', line 244

def kind
  @kind
end

#mapObject (readonly)

Returns the value of attribute map

Returns:

  • (Object)

    the current value of map



244
245
246
# File 'lib/twilic/core/model.rb', line 244

def map
  @map
end

#row_batchObject (readonly)

Returns the value of attribute row_batch

Returns:

  • (Object)

    the current value of row_batch



244
245
246
# File 'lib/twilic/core/model.rb', line 244

def row_batch
  @row_batch
end

#scalarObject (readonly)

Returns the value of attribute scalar

Returns:

  • (Object)

    the current value of scalar



244
245
246
# File 'lib/twilic/core/model.rb', line 244

def scalar
  @scalar
end

#schema_objectObject (readonly)

Returns the value of attribute schema_object

Returns:

  • (Object)

    the current value of schema_object



244
245
246
# File 'lib/twilic/core/model.rb', line 244

def schema_object
  @schema_object
end

#shaped_objectObject (readonly)

Returns the value of attribute shaped_object

Returns:

  • (Object)

    the current value of shaped_object



244
245
246
# File 'lib/twilic/core/model.rb', line 244

def shaped_object
  @shaped_object
end

#state_patchObject (readonly)

Returns the value of attribute state_patch

Returns:

  • (Object)

    the current value of state_patch



244
245
246
# File 'lib/twilic/core/model.rb', line 244

def state_patch
  @state_patch
end

#template_batchObject (readonly)

Returns the value of attribute template_batch

Returns:

  • (Object)

    the current value of template_batch



244
245
246
# File 'lib/twilic/core/model.rb', line 244

def template_batch
  @template_batch
end

#typed_vectorObject (readonly)

Returns the value of attribute typed_vector

Returns:

  • (Object)

    the current value of typed_vector



244
245
246
# File 'lib/twilic/core/model.rb', line 244

def typed_vector
  @typed_vector
end

Instance Method Details

#clone_messageObject



249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
# File 'lib/twilic/core/model.rb', line 249

def clone_message
  case kind
  when MessageKind::SCALAR
    v = scalar.clone_value
    Model.message(kind: kind, scalar: v)
  when MessageKind::ARRAY
    Model.message(kind: kind, array: array.map(&:clone_value))
  when MessageKind::MAP
    Model.message(kind: kind, map: map.map { |e| MessageMapEntry.new(e.key, e.value.clone_value) })
  when MessageKind::SHAPED_OBJECT
    s = shaped_object
    vals = s.values.map(&:clone_value)
    pres = s.has_presence ? s.presence.dup : nil
    Model.message(kind: kind, shaped_object: ShapedObjectMessage.new(
      shape_id: s.shape_id, presence: pres, has_presence: s.has_presence, values: vals
    ))
  when MessageKind::SCHEMA_OBJECT
    s = schema_object
    fields = s.fields.map(&:clone_value)
    pres = s.has_presence ? s.presence.dup : nil
    sid = s.schema_id
    Model.message(kind: kind, schema_object: SchemaObjectMessage.new(
      schema_id: sid, presence: pres, has_presence: s.has_presence, fields: fields
    ))
  when MessageKind::TYPED_VECTOR
    Model.message(kind: kind, typed_vector: Model.clone_typed_vector(typed_vector))
  when MessageKind::ROW_BATCH
    rows = row_batch.rows.map { |r| r.map(&:clone_value) }
    Model.message(kind: kind, row_batch: RowBatchMessage.new(rows: rows))
  when MessageKind::COLUMN_BATCH
    cols = column_batch.columns.map { |c| Model.clone_column(c) }
    Model.message(kind: kind, column_batch: ColumnBatchMessage.new(
      count: column_batch.count, columns: cols
    ))
  when MessageKind::CONTROL
    Model.message(kind: kind, control: Model.clone_control(control))
  when MessageKind::EXT
    Model.message(kind: kind, ext: ExtMessage.new(
      ext_type: ext.ext_type, payload: ext.payload.b.dup
    ))
  when MessageKind::STATE_PATCH
    sp = state_patch
    ops = sp.operations.map do |op|
      val = op.value ? op.value.clone_value : nil
      PatchOperation.new(field_id: op.field_id, opcode: op.opcode, value: val)
    end
    lits = sp.literals.map(&:clone_value)
    Model.message(kind: kind, state_patch: StatePatchMessage.new(
      base_ref: sp.base_ref, operations: ops, literals: lits
    ))
  when MessageKind::TEMPLATE_BATCH
    tb = template_batch
    cols = tb.columns.map { |c| Model.clone_column(c) }
    Model.message(kind: kind, template_batch: TemplateBatchMessage.new(
      template_id: tb.template_id, count: tb.count,
      changed_column_mask: tb.changed_column_mask.dup, columns: cols
    ))
  when MessageKind::CONTROL_STREAM
    cs = control_stream
    Model.message(kind: kind, control_stream: ControlStreamMessage.new(
      codec: cs.codec, payload: cs.payload.b.dup
    ))
  when MessageKind::BASE_SNAPSHOT
    bs = base_snapshot
    Model.message(kind: kind, base_snapshot: BaseSnapshotMessage.new(
      base_id: bs.base_id, schema_or_shape_ref: bs.schema_or_shape_ref,
      payload: bs.payload.clone_message
    ))
  else
    Model.message(kind: MessageKind::SCALAR)
  end
end