void WriteVector(AmfObject vector) { if (vector.IsSparse) { throw new InvalidOperationException("Vectors must be dense."); } if (TryWriteRef(vector)) { return; } WriteU29(vector.DenseCount, true); _writer.Write(vector.IsFixedVector); if (vector.Type == AmfTypes.VectorGeneric) { WriteString(vector.GenericElementType); } foreach (var value in vector.GetDensePart()) { switch (vector.Type) { case AmfTypes.VectorInt: WriteI32((int)value); break; case AmfTypes.VectorUInt: WriteU32((uint)value); break; case AmfTypes.VectorDouble: WriteDouble((double)value); break; case AmfTypes.VectorGeneric: WriteValue(value); break; default: throw new NotImplementedException(); } } }
void WriteArray(AmfObject array) { if (TryWriteRef(array)) { return; } WriteU29(array.DenseCount, true); // Associative part (key-value pairs) foreach (var pair in array.GetSparseAndAssociativePairs()) { WriteString(pair.Key.ToString()); WriteValue(pair.Value); } WriteString(""); // Dense part (consecutive indices >=0 and <count) foreach (var value in array.GetDensePart()) { WriteValue(value); } }