Class: RCS::CallListSerializer

Inherits:
Object
  • Object
show all
Includes:
Tracer
Defined in:
lib/rcs-common/serializer.rb

Constant Summary collapse

TYPES =
{0x01 => :name, 0x02 => :type, 0x04 => :note, 0x08 => :number}
INCOMING =
0x00
OUTGOING =
0x01

Constants included from Tracer

Tracer::TRACE_YAML_NAME

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Tracer

#thread_name, #trace, #trace_ensure_log_folders, #trace_init, #trace_named_put, #trace_named_remove, #trace_nested_pop, #trace_nested_push, #trace_setup

Constructor Details

#initializeCallListSerializer

Returns a new instance of CallListSerializer.



94
95
96
97
98
99
# File 'lib/rcs-common/serializer.rb', line 94

def initialize
  @fields = {}
  @start_time = nil
  @end_time = nil
  @properties = []
end

Instance Attribute Details

#end_timeObject (readonly)

Returns the value of attribute end_time.



92
93
94
# File 'lib/rcs-common/serializer.rb', line 92

def end_time
  @end_time
end

#fieldsObject (readonly)

Returns the value of attribute fields.



92
93
94
# File 'lib/rcs-common/serializer.rb', line 92

def fields
  @fields
end

#propertiesObject (readonly)

Returns the value of attribute properties.



92
93
94
# File 'lib/rcs-common/serializer.rb', line 92

def properties
  @properties
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



92
93
94
# File 'lib/rcs-common/serializer.rb', line 92

def start_time
  @start_time
end

Instance Method Details

#unserialize(stream) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/rcs-common/serializer.rb', line 101

def unserialize(stream)

  # HEADER
  header_begin = stream.pos

  tot_size = stream.read(4).unpack('L').shift
  version = stream.read(4).unpack('L').shift

  low, high = stream.read(8).unpack 'V2'
  @start_time = Time.from_filetime high, low
  low, high = stream.read(8).unpack 'V2'
  @end_time = Time.from_filetime high, low

  props = stream.read(4).unpack('L').shift
  if props & OUTGOING == 1
    @properties << :outgoing
  else
    @properties << :incoming
  end

  # BODY
  header_length = stream.pos - header_begin
  content = stream.read(tot_size - header_length)

  until content.empty?
    prefix = content.slice!(0, 4)
    type, size = Serialization.decode_prefix prefix
    @fields[TYPES[type]] = content.slice!(0, size).utf16le_to_utf8
  end

  self
end