Skip to content

Commit

Permalink
Add KVBinaryBlob and KVArrayValue
Browse files Browse the repository at this point in the history
  • Loading branch information
xPaw committed Feb 16, 2024
1 parent f939dcb commit 887000c
Show file tree
Hide file tree
Showing 4 changed files with 402 additions and 0 deletions.
73 changes: 73 additions & 0 deletions ValveKeyValue/ValveKeyValue.Test/Test Data/apisurface.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,79 @@ public class ValveKeyValue.KeyValueException
public string ToString();
}

public class ValveKeyValue.KVArrayValue
{
public void Add(ValveKeyValue.KVValue value);
public void AddRange(System.Collections.Generic.IEnumerable`1[[ValveKeyValue.KVValue]] values);
public void Clear();
public bool Contains(ValveKeyValue.KVValue item);
public void CopyTo(ValveKeyValue.KVValue[] array, int arrayIndex);
public bool Equals(object obj);
protected void Finalize();
public int get_Count();
public bool get_IsReadOnly();
public ValveKeyValue.KVValue get_Item(int key);
public ValveKeyValue.KVValue get_Item(string key);
public ValveKeyValue.KVValueType get_ValueType();
public System.Collections.Generic.IEnumerator`1[[ValveKeyValue.KVValue]] GetEnumerator();
public int GetHashCode();
public Type GetType();
public TypeCode GetTypeCode();
public int IndexOf(ValveKeyValue.KVValue item);
public void Insert(int index, ValveKeyValue.KVValue item);
protected object MemberwiseClone();
public bool Remove(ValveKeyValue.KVValue item);
public void RemoveAt(int index);
public void set_Item(int key, ValveKeyValue.KVValue value);
public bool ToBoolean(IFormatProvider provider);
public byte ToByte(IFormatProvider provider);
public char ToChar(IFormatProvider provider);
public DateTime ToDateTime(IFormatProvider provider);
public decimal ToDecimal(IFormatProvider provider);
public double ToDouble(IFormatProvider provider);
public short ToInt16(IFormatProvider provider);
public int ToInt32(IFormatProvider provider);
public long ToInt64(IFormatProvider provider);
public sbyte ToSByte(IFormatProvider provider);
public float ToSingle(IFormatProvider provider);
public string ToString();
public string ToString(IFormatProvider provider);
public object ToType(Type conversionType, IFormatProvider provider);
public ushort ToUInt16(IFormatProvider provider);
public uint ToUInt32(IFormatProvider provider);
public ulong ToUInt64(IFormatProvider provider);
}

public class ValveKeyValue.KVBinaryBlob
{
public bool Equals(object obj);
protected void Finalize();
public Memory`1[[byte]] get_Bytes();
public ValveKeyValue.KVValue get_Item(string key);
public ValveKeyValue.KVValueType get_ValueType();
public int GetHashCode();
public Type GetType();
public TypeCode GetTypeCode();
protected object MemberwiseClone();
public bool ToBoolean(IFormatProvider provider);
public byte ToByte(IFormatProvider provider);
public char ToChar(IFormatProvider provider);
public DateTime ToDateTime(IFormatProvider provider);
public decimal ToDecimal(IFormatProvider provider);
public double ToDouble(IFormatProvider provider);
public short ToInt16(IFormatProvider provider);
public int ToInt32(IFormatProvider provider);
public long ToInt64(IFormatProvider provider);
public sbyte ToSByte(IFormatProvider provider);
public float ToSingle(IFormatProvider provider);
public string ToString();
public string ToString(IFormatProvider provider);
public object ToType(Type conversionType, IFormatProvider provider);
public ushort ToUInt16(IFormatProvider provider);
public uint ToUInt32(IFormatProvider provider);
public ulong ToUInt64(IFormatProvider provider);
}

public class ValveKeyValue.KVDocument
{
public void Add(ValveKeyValue.KVObject value);
Expand Down
15 changes: 15 additions & 0 deletions ValveKeyValue/ValveKeyValue/HexStringHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Globalization;
using System.Runtime.CompilerServices;

namespace ValveKeyValue
{
Expand All @@ -17,5 +18,19 @@ public static byte[] ParseHexStringAsByteArray(string hexadecimalRepresentation)

return data;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static char HexToCharUpper(int value)
{
value &= 0xF;
value += '0';

if (value > '9')
{
value += ('A' - ('9' + 1));
}

return (char)value;
}
}
}
184 changes: 184 additions & 0 deletions ValveKeyValue/ValveKeyValue/KVArrayValue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
using System.Collections;

namespace ValveKeyValue
{
public class KVArrayValue : KVValue, IEnumerable<KVValue>, ICollection<KVValue>, IList<KVValue>
{
public KVArrayValue()
{
children = new List<KVValue>();
}

readonly List<KVValue> children;

public override KVValueType ValueType => KVValueType.Array;

public int Count => children.Count;

public bool IsReadOnly => false;

public override KVValue this[string key]
{
get { throw new NotSupportedException($"The indexer on a {nameof(KVArrayValue)} can only be used on integer keys, not strings."); }
}

public KVValue this[int key]
{
get
{
return children[key];
}
set
{
children[key] = value;
}
}

public void Add(KVValue value)
{
Require.NotNull(value, nameof(value));
children.Add(value);
}

public void AddRange(IEnumerable<KVValue> values)
{
Require.NotNull(values, nameof(values));
children.AddRange(values);
}

#region IEnumerable<KVValue>

public IEnumerator<KVValue> GetEnumerator() => children.GetEnumerator();

#endregion

#region IConvertible

public override TypeCode GetTypeCode()
{
throw new NotSupportedException();
}

public override bool ToBoolean(IFormatProvider provider)
{
throw new NotSupportedException();
}

public override byte ToByte(IFormatProvider provider)
{
throw new NotSupportedException();
}

public override char ToChar(IFormatProvider provider)
{
throw new NotSupportedException();
}

public override DateTime ToDateTime(IFormatProvider provider)
{
throw new NotSupportedException();
}

public override decimal ToDecimal(IFormatProvider provider)
{
throw new NotSupportedException();
}

public override double ToDouble(IFormatProvider provider)
{
throw new NotSupportedException();
}

public override short ToInt16(IFormatProvider provider)
{
throw new NotSupportedException();
}

public override int ToInt32(IFormatProvider provider)
{
throw new NotSupportedException();
}

public override long ToInt64(IFormatProvider provider)
{
throw new NotSupportedException();
}

public override sbyte ToSByte(IFormatProvider provider)
{
throw new NotSupportedException();
}

public override float ToSingle(IFormatProvider provider)
{
throw new NotSupportedException();
}

public override string ToString(IFormatProvider provider)
=> ToString();

public override object ToType(Type conversionType, IFormatProvider provider)
{
throw new NotSupportedException();
}

public override ushort ToUInt16(IFormatProvider provider)
{
throw new NotSupportedException();
}

public override uint ToUInt32(IFormatProvider provider)
{
throw new NotSupportedException();
}

public override ulong ToUInt64(IFormatProvider provider)
{
throw new NotSupportedException();
}

#endregion

#region IEnumerable

IEnumerator IEnumerable.GetEnumerator() => children.GetEnumerator();

#endregion

public override string ToString() => "[Array]";

public void Clear() => children.Clear();

public bool Contains(KVValue item)
{
Require.NotNull(item, nameof(item));
return children.Contains(item);
}

public void CopyTo(KVValue[] array, int arrayIndex)
{
Require.NotNull(array, nameof(array));
children.CopyTo(array, arrayIndex);
}

public bool Remove(KVValue item)
{
Require.NotNull(item, nameof(item));
return children.Remove(item);
}

public int IndexOf(KVValue item)
{
Require.NotNull(item, nameof(item));
return children.IndexOf(item);
}

public void Insert(int index, KVValue item)
{
Require.NotNull(item, nameof(item));
children.Insert(index, item);
}

public void RemoveAt(int index) => children.RemoveAt(index);
}
}
Loading

0 comments on commit 887000c

Please sign in to comment.