80 lines
1.8 KiB
C#
80 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Collections;
|
|
using System.Runtime.CompilerServices;
|
|
namespace ln.types.odb.values
|
|
{
|
|
public class ODBList : ODBValue
|
|
{
|
|
List<ODBValue> items = new List<ODBValue>();
|
|
|
|
public ODBList()
|
|
:base(0x02)
|
|
{
|
|
}
|
|
public ODBList(byte[] bytes,int offset,int length)
|
|
:this()
|
|
{
|
|
MemoryStream stream = new MemoryStream(bytes, offset, length);
|
|
int nItems = stream.ReadInteger();
|
|
for (int n = 0; n < nItems; n++)
|
|
items.Add(ODBValue.Read(stream));
|
|
}
|
|
|
|
public ODBValue this[int i]
|
|
{
|
|
get => items[i];
|
|
set => items[i] = value;
|
|
}
|
|
|
|
public void Add(ODBValue value)
|
|
{
|
|
items.Add(value);
|
|
}
|
|
public void Remove(ODBValue value)
|
|
{
|
|
items.Remove(value);
|
|
}
|
|
public void RemoveAt(int i)
|
|
{
|
|
items.RemoveAt(i);
|
|
}
|
|
|
|
public int Count => items.Count;
|
|
|
|
public override object Value {
|
|
get
|
|
{
|
|
object[] a = new object[items.Count];
|
|
((IList)items).CopyTo(a, 0);
|
|
return a;
|
|
}
|
|
protected set
|
|
{
|
|
throw new NotSupportedException();
|
|
}
|
|
}
|
|
|
|
public override byte[] ToStorage()
|
|
{
|
|
MemoryStream stream = new MemoryStream();
|
|
BinaryWriter writer = new BinaryWriter(stream);
|
|
|
|
writer.Write(items.Count);
|
|
|
|
foreach (ODBValue value in items)
|
|
value.Store(writer);
|
|
|
|
return stream.ToArray();
|
|
}
|
|
|
|
static ODBList()
|
|
{
|
|
RegisterDeserializer(0x02, (b, o, l) => new ODBList(b,o,l));
|
|
}
|
|
|
|
|
|
}
|
|
}
|