Method: AMF::Pure::AMF3Serializer#write_array

Defined in:
lib/amf/pure/serializer.rb

#write_array(array) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/amf/pure/serializer.rb', line 107

def write_array(array)
  @stream << AMF3_ARRAY_MARKER
  if @object_cache[array] != nil
    write_reference(@object_cache[array])
  else
    # Cache array
    @object_cache.add_obj(array)

    # Build AMF string
    header = array.length << 1 # make room for a low bit of 1
    header = header | 1 # set the low bit to 1
    @stream << pack_integer(header)
    @stream << AMF3_CLOSE_DYNAMIC_ARRAY
    array.each do |elem|
      if elem.respond_to?(:to_amf)
        @stream << elem.to_amf(@opts)
      else
        serialize(elem)
      end
    end
    
    block.call(self) if block_given?
  end
end