using System.Buffers.Binary; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using Newtonsoft.Json; namespace BililiveRecorder.Flv.Amf { [DebuggerTypeProxy(typeof(AmfCollectionDebugView))] [DebuggerDisplay("AmfStrictArray, Count = {Count}")] public class ScriptDataStrictArray : IScriptDataValue, IList, ICollection, IEnumerable, IReadOnlyCollection, IReadOnlyList { public ScriptDataType Type => ScriptDataType.StrictArray; [JsonProperty] public List Value { get; set; } = new List(); public void WriteTo(Stream stream) { stream.WriteByte((byte)this.Type); var buffer = new byte[sizeof(uint)]; BinaryPrimitives.WriteUInt32BigEndian(buffer, (uint)this.Value.Count); stream.Write(buffer); foreach (var item in this.Value) item.WriteTo(stream); } public IScriptDataValue this[int index] { get => ((IList)this.Value)[index]; set => ((IList)this.Value)[index] = value; } public int Count => ((IList)this.Value).Count; public bool IsReadOnly => ((IList)this.Value).IsReadOnly; public void Add(IScriptDataValue item) => ((IList)this.Value).Add(item); public void Clear() => ((IList)this.Value).Clear(); public bool Contains(IScriptDataValue item) => ((IList)this.Value).Contains(item); public void CopyTo(IScriptDataValue[] array, int arrayIndex) => ((IList)this.Value).CopyTo(array, arrayIndex); public IEnumerator GetEnumerator() => ((IList)this.Value).GetEnumerator(); public int IndexOf(IScriptDataValue item) => ((IList)this.Value).IndexOf(item); public void Insert(int index, IScriptDataValue item) => ((IList)this.Value).Insert(index, item); public bool Remove(IScriptDataValue item) => ((IList)this.Value).Remove(item); public void RemoveAt(int index) => ((IList)this.Value).RemoveAt(index); IEnumerator IEnumerable.GetEnumerator() => ((IList)this.Value).GetEnumerator(); public static implicit operator List(ScriptDataStrictArray strictArray) => strictArray.Value; public static implicit operator ScriptDataStrictArray(List values) => new ScriptDataStrictArray { Value = values }; } }