Class: RCS::CalendarSerializer

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

Constant Summary collapse

POOM_V1_0_PROTO =
0x01000000
FLAG_RECUR =
0x00000008
CALENDAR_TYPES =
{ 0x01 => :subject,
0x02 => :categories,
0x04 => :body,
0x08 => :recipients,
0x10 => :location}

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

#initializeCalendarSerializer

Returns a new instance of CalendarSerializer.



149
150
151
152
153
# File 'lib/rcs-common/serializer.rb', line 149

def initialize
  @fields = {}
  @start_date = nil
  @end_date = nil
end

Instance Attribute Details

#end_dateObject (readonly)

Returns the value of attribute end_date.



141
142
143
# File 'lib/rcs-common/serializer.rb', line 141

def end_date
  @end_date
end

#fieldsObject (readonly)

Returns the value of attribute fields.



141
142
143
# File 'lib/rcs-common/serializer.rb', line 141

def fields
  @fields
end

#start_dateObject (readonly)

Returns the value of attribute start_date.



141
142
143
# File 'lib/rcs-common/serializer.rb', line 141

def start_date
  @start_date
end

Instance Method Details

#unserialize(stream) ⇒ Object



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/rcs-common/serializer.rb', line 155

def unserialize(stream)
  header_begin = stream.pos

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

  raise EvidenceDeserializeError.new("Invalid version") unless version == POOM_V1_0_PROTO

  # BODY
  header_length = stream.pos - header_begin
  content = stream.read(tot_size - header_length)
  until content.empty?
    @flags = content.slice!(0, 4).unpack('L').shift

    ft_low = content.slice!(0, 4).unpack('L').shift
    ft_high = content.slice!(0, 4).unpack('L').shift
    @start_date = Time.from_filetime(ft_high, ft_low)

    ft_low = content.slice!(0, 4).unpack('L').shift
    ft_high = content.slice!(0, 4).unpack('L').shift
    @end_date = Time.from_filetime(ft_high, ft_low)

    @sensitivity = content.slice!(0, 4).unpack('L').shift
    @busy = content.slice!(0, 4).unpack('L').shift
    @duration = content.slice!(0, 4).unpack('L').shift
    @status = content.slice!(0, 4).unpack('L').shift

    if @flags == FLAG_RECUR
      return self if content.bytesize < 28 + 16 # struct _TaskRecur

      type, interval, month_of_year, day_of_month, day_of_week_mask, instance, occurrences = *content.slice!(0, 28).unpack("L*")
      ft_low = content.slice!(0, 4).unpack('L').shift
      ft_high = content.slice!(0, 4).unpack('L').shift
      @pattern_start_date = Time.from_filetime(ft_high, ft_low)

      ft_low = content.slice!(0, 4).unpack('L').shift
      ft_high = content.slice!(0, 4).unpack('L').shift
      @pattern_end_date = Time.from_filetime(ft_high, ft_low)
    end

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

  self
end