481 lines
12 KiB
C#
481 lines
12 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
|
|
namespace Google.Protobuf.Collections
|
|
{
|
|
// Token: 0x02000071 RID: 113
|
|
public sealed class RepeatedField<T> : IList<T>, ICollection<T>, IEnumerable<T>, IEnumerable, IList, ICollection, IDeepCloneable<RepeatedField<T>>, IEquatable<RepeatedField<T>>
|
|
{
|
|
// Token: 0x06000648 RID: 1608 RVA: 0x00015A60 File Offset: 0x00013C60
|
|
public RepeatedField<T> Clone()
|
|
{
|
|
RepeatedField<T> repeatedField = new RepeatedField<T>();
|
|
if (this.array != RepeatedField<T>.EmptyArray)
|
|
{
|
|
repeatedField.array = (T[])this.array.Clone();
|
|
IDeepCloneable<T>[] array = repeatedField.array as IDeepCloneable<T>[];
|
|
if (array != null)
|
|
{
|
|
for (int i = 0; i < this.count; i++)
|
|
{
|
|
repeatedField.array[i] = array[i].Clone();
|
|
}
|
|
}
|
|
}
|
|
repeatedField.count = this.count;
|
|
return repeatedField;
|
|
}
|
|
|
|
// Token: 0x06000649 RID: 1609 RVA: 0x00015AD8 File Offset: 0x00013CD8
|
|
public void AddEntriesFrom(CodedInputStream input, FieldCodec<T> codec)
|
|
{
|
|
uint lastTag = input.LastTag;
|
|
Func<CodedInputStream, T> valueReader = codec.ValueReader;
|
|
if (FieldCodec<T>.IsPackedRepeatedField(lastTag))
|
|
{
|
|
int num = input.ReadLength();
|
|
if (num > 0)
|
|
{
|
|
int num2 = input.PushLimit(num);
|
|
while (!input.ReachedLimit)
|
|
{
|
|
this.Add(valueReader(input));
|
|
}
|
|
input.PopLimit(num2);
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
do
|
|
{
|
|
this.Add(valueReader(input));
|
|
}
|
|
while (input.MaybeConsumeTag(lastTag));
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600064A RID: 1610 RVA: 0x00015B44 File Offset: 0x00013D44
|
|
public int CalculateSize(FieldCodec<T> codec)
|
|
{
|
|
if (this.count == 0)
|
|
{
|
|
return 0;
|
|
}
|
|
uint tag = codec.Tag;
|
|
if (codec.PackedRepeatedField)
|
|
{
|
|
int num = this.CalculatePackedDataSize(codec);
|
|
return CodedOutputStream.ComputeRawVarint32Size(tag) + CodedOutputStream.ComputeLengthSize(num) + num;
|
|
}
|
|
Func<T, int> valueSizeCalculator = codec.ValueSizeCalculator;
|
|
int num2 = this.count * CodedOutputStream.ComputeRawVarint32Size(tag);
|
|
for (int i = 0; i < this.count; i++)
|
|
{
|
|
num2 += valueSizeCalculator(this.array[i]);
|
|
}
|
|
return num2;
|
|
}
|
|
|
|
// Token: 0x0600064B RID: 1611 RVA: 0x00015BC4 File Offset: 0x00013DC4
|
|
private int CalculatePackedDataSize(FieldCodec<T> codec)
|
|
{
|
|
int fixedSize = codec.FixedSize;
|
|
if (fixedSize == 0)
|
|
{
|
|
Func<T, int> valueSizeCalculator = codec.ValueSizeCalculator;
|
|
int num = 0;
|
|
for (int i = 0; i < this.count; i++)
|
|
{
|
|
num += valueSizeCalculator(this.array[i]);
|
|
}
|
|
return num;
|
|
}
|
|
return fixedSize * this.Count;
|
|
}
|
|
|
|
// Token: 0x0600064C RID: 1612 RVA: 0x00015C14 File Offset: 0x00013E14
|
|
public void WriteTo(CodedOutputStream output, FieldCodec<T> codec)
|
|
{
|
|
if (this.count == 0)
|
|
{
|
|
return;
|
|
}
|
|
Action<CodedOutputStream, T> valueWriter = codec.ValueWriter;
|
|
uint tag = codec.Tag;
|
|
if (codec.PackedRepeatedField)
|
|
{
|
|
uint num = (uint)this.CalculatePackedDataSize(codec);
|
|
output.WriteTag(tag);
|
|
output.WriteRawVarint32(num);
|
|
for (int i = 0; i < this.count; i++)
|
|
{
|
|
valueWriter(output, this.array[i]);
|
|
}
|
|
return;
|
|
}
|
|
for (int j = 0; j < this.count; j++)
|
|
{
|
|
output.WriteTag(tag);
|
|
valueWriter(output, this.array[j]);
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600064D RID: 1613 RVA: 0x00015CAC File Offset: 0x00013EAC
|
|
private void EnsureSize(int size)
|
|
{
|
|
if (this.array.Length < size)
|
|
{
|
|
size = Math.Max(size, 8);
|
|
T[] array = new T[Math.Max(this.array.Length * 2, size)];
|
|
Array.Copy(this.array, 0, array, 0, this.array.Length);
|
|
this.array = array;
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600064E RID: 1614 RVA: 0x00015D00 File Offset: 0x00013F00
|
|
public void Add(T item)
|
|
{
|
|
ProtoPreconditions.CheckNotNullUnconstrained<T>(item, "item");
|
|
this.EnsureSize(this.count + 1);
|
|
T[] array = this.array;
|
|
int num = this.count;
|
|
this.count = num + 1;
|
|
array[num] = item;
|
|
}
|
|
|
|
// Token: 0x0600064F RID: 1615 RVA: 0x00015D44 File Offset: 0x00013F44
|
|
public void Clear()
|
|
{
|
|
this.array = RepeatedField<T>.EmptyArray;
|
|
this.count = 0;
|
|
}
|
|
|
|
// Token: 0x06000650 RID: 1616 RVA: 0x00015D58 File Offset: 0x00013F58
|
|
public bool Contains(T item)
|
|
{
|
|
return this.IndexOf(item) != -1;
|
|
}
|
|
|
|
// Token: 0x06000651 RID: 1617 RVA: 0x00015D67 File Offset: 0x00013F67
|
|
public void CopyTo(T[] array, int arrayIndex)
|
|
{
|
|
Array.Copy(this.array, 0, array, arrayIndex, this.count);
|
|
}
|
|
|
|
// Token: 0x06000652 RID: 1618 RVA: 0x00015D80 File Offset: 0x00013F80
|
|
public bool Remove(T item)
|
|
{
|
|
int num = this.IndexOf(item);
|
|
if (num == -1)
|
|
{
|
|
return false;
|
|
}
|
|
Array.Copy(this.array, num + 1, this.array, num, this.count - num - 1);
|
|
this.count--;
|
|
this.array[this.count] = default(T);
|
|
return true;
|
|
}
|
|
|
|
// Token: 0x170001C5 RID: 453
|
|
// (get) Token: 0x06000653 RID: 1619 RVA: 0x00015DE3 File Offset: 0x00013FE3
|
|
public int Count
|
|
{
|
|
get
|
|
{
|
|
return this.count;
|
|
}
|
|
}
|
|
|
|
// Token: 0x170001C6 RID: 454
|
|
// (get) Token: 0x06000654 RID: 1620 RVA: 0x0000761F File Offset: 0x0000581F
|
|
public bool IsReadOnly
|
|
{
|
|
get
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000655 RID: 1621 RVA: 0x00015DEC File Offset: 0x00013FEC
|
|
public void AddRange(IEnumerable<T> values)
|
|
{
|
|
ProtoPreconditions.CheckNotNull<IEnumerable<T>>(values, "values");
|
|
RepeatedField<T> repeatedField = values as RepeatedField<T>;
|
|
if (repeatedField != null)
|
|
{
|
|
this.EnsureSize(this.count + repeatedField.count);
|
|
Array.Copy(repeatedField.array, 0, this.array, this.count, repeatedField.count);
|
|
this.count += repeatedField.count;
|
|
return;
|
|
}
|
|
ICollection collection = values as ICollection;
|
|
if (collection != null)
|
|
{
|
|
int num = collection.Count;
|
|
if (default(T) == null)
|
|
{
|
|
using (IEnumerator enumerator = collection.GetEnumerator())
|
|
{
|
|
while (enumerator.MoveNext())
|
|
{
|
|
if (enumerator.Current == null)
|
|
{
|
|
throw new ArgumentException("Sequence contained null element", "values");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
this.EnsureSize(this.count + num);
|
|
collection.CopyTo(this.array, this.count);
|
|
this.count += num;
|
|
return;
|
|
}
|
|
foreach (T t in values)
|
|
{
|
|
this.Add(t);
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000656 RID: 1622 RVA: 0x00015F38 File Offset: 0x00014138
|
|
public void Add(IEnumerable<T> values)
|
|
{
|
|
this.AddRange(values);
|
|
}
|
|
|
|
// Token: 0x06000657 RID: 1623 RVA: 0x00015F41 File Offset: 0x00014141
|
|
public IEnumerator<T> GetEnumerator()
|
|
{
|
|
int num;
|
|
for (int i = 0; i < this.count; i = num + 1)
|
|
{
|
|
yield return this.array[i];
|
|
num = i;
|
|
}
|
|
yield break;
|
|
}
|
|
|
|
// Token: 0x06000658 RID: 1624 RVA: 0x00015F50 File Offset: 0x00014150
|
|
public override bool Equals(object obj)
|
|
{
|
|
return this.Equals(obj as RepeatedField<T>);
|
|
}
|
|
|
|
// Token: 0x06000659 RID: 1625 RVA: 0x00015F5E File Offset: 0x0001415E
|
|
IEnumerator IEnumerable.GetEnumerator()
|
|
{
|
|
return this.GetEnumerator();
|
|
}
|
|
|
|
// Token: 0x0600065A RID: 1626 RVA: 0x00015F68 File Offset: 0x00014168
|
|
public override int GetHashCode()
|
|
{
|
|
int num = 0;
|
|
for (int i = 0; i < this.count; i++)
|
|
{
|
|
num = num * 31 + this.array[i].GetHashCode();
|
|
}
|
|
return num;
|
|
}
|
|
|
|
// Token: 0x0600065B RID: 1627 RVA: 0x00015FA8 File Offset: 0x000141A8
|
|
public bool Equals(RepeatedField<T> other)
|
|
{
|
|
if (other == null)
|
|
{
|
|
return false;
|
|
}
|
|
if (other == this)
|
|
{
|
|
return true;
|
|
}
|
|
if (other.Count != this.Count)
|
|
{
|
|
return false;
|
|
}
|
|
EqualityComparer<T> @default = EqualityComparer<T>.Default;
|
|
for (int i = 0; i < this.count; i++)
|
|
{
|
|
if (!@default.Equals(this.array[i], other.array[i]))
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
// Token: 0x0600065C RID: 1628 RVA: 0x0001600C File Offset: 0x0001420C
|
|
public int IndexOf(T item)
|
|
{
|
|
ProtoPreconditions.CheckNotNullUnconstrained<T>(item, "item");
|
|
EqualityComparer<T> @default = EqualityComparer<T>.Default;
|
|
for (int i = 0; i < this.count; i++)
|
|
{
|
|
if (@default.Equals(this.array[i], item))
|
|
{
|
|
return i;
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
// Token: 0x0600065D RID: 1629 RVA: 0x00016054 File Offset: 0x00014254
|
|
public void Insert(int index, T item)
|
|
{
|
|
ProtoPreconditions.CheckNotNullUnconstrained<T>(item, "item");
|
|
if (index < 0 || index > this.count)
|
|
{
|
|
throw new ArgumentOutOfRangeException("index");
|
|
}
|
|
this.EnsureSize(this.count + 1);
|
|
Array.Copy(this.array, index, this.array, index + 1, this.count - index);
|
|
this.array[index] = item;
|
|
this.count++;
|
|
}
|
|
|
|
// Token: 0x0600065E RID: 1630 RVA: 0x000160CC File Offset: 0x000142CC
|
|
public void RemoveAt(int index)
|
|
{
|
|
if (index < 0 || index >= this.count)
|
|
{
|
|
throw new ArgumentOutOfRangeException("index");
|
|
}
|
|
Array.Copy(this.array, index + 1, this.array, index, this.count - index - 1);
|
|
this.count--;
|
|
this.array[this.count] = default(T);
|
|
}
|
|
|
|
// Token: 0x0600065F RID: 1631 RVA: 0x00016138 File Offset: 0x00014338
|
|
public override string ToString()
|
|
{
|
|
StringWriter stringWriter = new StringWriter();
|
|
JsonFormatter.Default.WriteList(stringWriter, this);
|
|
return stringWriter.ToString();
|
|
}
|
|
|
|
// Token: 0x170001C7 RID: 455
|
|
public T this[int index]
|
|
{
|
|
get
|
|
{
|
|
if (index < 0 || index >= this.count)
|
|
{
|
|
throw new ArgumentOutOfRangeException("index");
|
|
}
|
|
return this.array[index];
|
|
}
|
|
set
|
|
{
|
|
if (index < 0 || index >= this.count)
|
|
{
|
|
throw new ArgumentOutOfRangeException("index");
|
|
}
|
|
ProtoPreconditions.CheckNotNullUnconstrained<T>(value, "value");
|
|
this.array[index] = value;
|
|
}
|
|
}
|
|
|
|
// Token: 0x170001C8 RID: 456
|
|
// (get) Token: 0x06000662 RID: 1634 RVA: 0x0000761F File Offset: 0x0000581F
|
|
bool IList.IsFixedSize
|
|
{
|
|
get
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000663 RID: 1635 RVA: 0x00015D67 File Offset: 0x00013F67
|
|
void ICollection.CopyTo(Array array, int index)
|
|
{
|
|
Array.Copy(this.array, 0, array, index, this.count);
|
|
}
|
|
|
|
// Token: 0x170001C9 RID: 457
|
|
// (get) Token: 0x06000664 RID: 1636 RVA: 0x0000761F File Offset: 0x0000581F
|
|
bool ICollection.IsSynchronized
|
|
{
|
|
get
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// Token: 0x170001CA RID: 458
|
|
// (get) Token: 0x06000665 RID: 1637 RVA: 0x000142A1 File Offset: 0x000124A1
|
|
object ICollection.SyncRoot
|
|
{
|
|
get
|
|
{
|
|
return this;
|
|
}
|
|
}
|
|
|
|
// Token: 0x170001CB RID: 459
|
|
object IList.this[int index]
|
|
{
|
|
get
|
|
{
|
|
return this[index];
|
|
}
|
|
set
|
|
{
|
|
this[index] = (T)((object)value);
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000668 RID: 1640 RVA: 0x000161D3 File Offset: 0x000143D3
|
|
int IList.Add(object value)
|
|
{
|
|
this.Add((T)((object)value));
|
|
return this.count - 1;
|
|
}
|
|
|
|
// Token: 0x06000669 RID: 1641 RVA: 0x000161E9 File Offset: 0x000143E9
|
|
bool IList.Contains(object value)
|
|
{
|
|
return value is T && this.Contains((T)((object)value));
|
|
}
|
|
|
|
// Token: 0x0600066A RID: 1642 RVA: 0x00016201 File Offset: 0x00014401
|
|
int IList.IndexOf(object value)
|
|
{
|
|
if (!(value is T))
|
|
{
|
|
return -1;
|
|
}
|
|
return this.IndexOf((T)((object)value));
|
|
}
|
|
|
|
// Token: 0x0600066B RID: 1643 RVA: 0x00016219 File Offset: 0x00014419
|
|
void IList.Insert(int index, object value)
|
|
{
|
|
this.Insert(index, (T)((object)value));
|
|
}
|
|
|
|
// Token: 0x0600066C RID: 1644 RVA: 0x00016228 File Offset: 0x00014428
|
|
void IList.Remove(object value)
|
|
{
|
|
if (!(value is T))
|
|
{
|
|
return;
|
|
}
|
|
this.Remove((T)((object)value));
|
|
}
|
|
|
|
// Token: 0x04000269 RID: 617
|
|
private static readonly T[] EmptyArray = new T[0];
|
|
|
|
// Token: 0x0400026A RID: 618
|
|
private const int MinArraySize = 8;
|
|
|
|
// Token: 0x0400026B RID: 619
|
|
private T[] array = RepeatedField<T>.EmptyArray;
|
|
|
|
// Token: 0x0400026C RID: 620
|
|
private int count;
|
|
}
|
|
}
|