Skip to content

Commit

Permalink
Rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
xPaw committed Feb 16, 2024
1 parent 852a863 commit ba24c07
Show file tree
Hide file tree
Showing 20 changed files with 68 additions and 107 deletions.
46 changes: 46 additions & 0 deletions ValveKeyValue/ValveKeyValue.Test/Test Data/apisurface.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class ValveKeyValue.KVArrayValue
public bool Equals(object obj);
protected void Finalize();
public int get_Count();
public ValveKeyValue.KVFlag get_Flag();
public bool get_IsReadOnly();
public ValveKeyValue.KVValue get_Item(int key);
public ValveKeyValue.KVValue get_Item(string key);
Expand All @@ -52,6 +53,7 @@ public class ValveKeyValue.KVArrayValue
protected object MemberwiseClone();
public bool Remove(ValveKeyValue.KVValue item);
public void RemoveAt(int index);
public void set_Flag(ValveKeyValue.KVFlag value);
public void set_Item(int key, ValveKeyValue.KVValue value);
public bool ToBoolean(IFormatProvider provider);
public byte ToByte(IFormatProvider provider);
Expand All @@ -77,12 +79,14 @@ public class ValveKeyValue.KVBinaryBlob
public bool Equals(object obj);
protected void Finalize();
public Memory`1[[byte]] get_Bytes();
public ValveKeyValue.KVFlag get_Flag();
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 void set_Flag(ValveKeyValue.KVFlag value);
public bool ToBoolean(IFormatProvider provider);
public byte ToByte(IFormatProvider provider);
public char ToChar(IFormatProvider provider);
Expand All @@ -108,6 +112,8 @@ public class ValveKeyValue.KVDocument
public bool Equals(object obj);
protected void Finalize();
public System.Collections.Generic.IEnumerable`1[[ValveKeyValue.KVObject]] get_Children();
public System.Collections.Generic.IEnumerable`1[[ValveKeyValue.KVValue]] get_ChildrenValues();
public ValveKeyValue.KVHeader get_Header();
public ValveKeyValue.KVValue get_Item(string key);
public string get_Name();
public ValveKeyValue.KVValue get_Value();
Expand All @@ -119,6 +125,43 @@ public class ValveKeyValue.KVDocument
public string ToString();
}

public sealed enum ValveKeyValue.KVFlag
{
None = 0;
Resource = 1;
ResourceName = 2;
Panorama = 3;
SoundEvent = 4;
SubClass = 5;

public int CompareTo(object target);
public bool Equals(object obj);
protected void Finalize();
public int GetHashCode();
public Type GetType();
public TypeCode GetTypeCode();
public bool HasFlag(Enum flag);
protected object MemberwiseClone();
public string ToString();
public string ToString(IFormatProvider provider);
public string ToString(string format);
public string ToString(string format, IFormatProvider provider);
}

public class ValveKeyValue.KVHeader
{
public bool Equals(object obj);
protected void Finalize();
public Guid get_Encoding();
public Guid get_Format();
public int GetHashCode();
public Type GetType();
protected object MemberwiseClone();
public void set_Encoding(Guid value);
public void set_Format(Guid value);
public string ToString();
}

public sealed class ValveKeyValue.KVIgnoreAttribute
{
public bool Equals(object obj);
Expand All @@ -138,6 +181,7 @@ public class ValveKeyValue.KVObject
public bool Equals(object obj);
protected void Finalize();
public System.Collections.Generic.IEnumerable`1[[ValveKeyValue.KVObject]] get_Children();
public System.Collections.Generic.IEnumerable`1[[ValveKeyValue.KVValue]] get_ChildrenValues();
public ValveKeyValue.KVValue get_Item(string key);
public string get_Name();
public ValveKeyValue.KVValue get_Value();
Expand Down Expand Up @@ -221,6 +265,7 @@ public class ValveKeyValue.KVValue
{
public bool Equals(object obj);
protected void Finalize();
public ValveKeyValue.KVFlag get_Flag();
public ValveKeyValue.KVValue get_Item(string key);
public ValveKeyValue.KVValueType get_ValueType();
public int GetHashCode();
Expand Down Expand Up @@ -249,6 +294,7 @@ public class ValveKeyValue.KVValue
public static ValveKeyValue.KVValue op_Implicit(long value);
public static ValveKeyValue.KVValue op_Implicit(string value);
public static ValveKeyValue.KVValue op_Implicit(ulong value);
public void set_Flag(ValveKeyValue.KVFlag value);
public bool ToBoolean(IFormatProvider provider);
public byte ToByte(IFormatProvider provider);
public char ToChar(IFormatProvider provider);
Expand Down
6 changes: 2 additions & 4 deletions ValveKeyValue/ValveKeyValue.Test/TextKV3/BasicKV3TestCases.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using NUnit.Framework;

namespace ValveKeyValue.Test.TextKV3
{
class BasicKV3TestCases
Expand Down Expand Up @@ -97,7 +95,7 @@ public void DeserializesArray()

var arrayValue = (KVArrayValue)data["arrayValue"];

Assert.That(arrayValue.Count, Is.EqualTo(2));
Assert.That(arrayValue, Has.Count.EqualTo(2));
Assert.That(arrayValue[0].ToString(), Is.EqualTo("a"));
Assert.That(arrayValue[1].ToString(), Is.EqualTo("b"));

Expand All @@ -111,7 +109,7 @@ public void DeserializesBinaryBlob()
var data = KVSerializer.Create(KVSerializationFormat.KeyValues3Text).Deserialize(stream);

Assert.That(data["array"].ValueType, Is.EqualTo(KVValueType.BinaryBlob));
Assert.That(((KVBinaryBlob)data["array"]).Bytes, Is.EqualTo(new byte[]
Assert.That(((KVBinaryBlob)data["array"]).Bytes.ToArray(), Is.EqualTo(new byte[]
{
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xFF
Expand Down
3 changes: 0 additions & 3 deletions ValveKeyValue/ValveKeyValue.Test/TextKV3/HeadersTestCase.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.IO;
using System.Text;
using NUnit.Framework;

namespace ValveKeyValue.Test.TextKV3
{
Expand Down
4 changes: 0 additions & 4 deletions ValveKeyValue/ValveKeyValue.Test/TextKV3/Kv1ToKv3TestCase.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
using System;
using System.IO;
using NUnit.Framework;

namespace ValveKeyValue.Test.TextKV3
{
class Kv1ToKv3TestCase
Expand Down
3 changes: 0 additions & 3 deletions ValveKeyValue/ValveKeyValue.Test/TextKV3/Kv3ToKv1TestCase.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using System.IO;
using NUnit.Framework;

namespace ValveKeyValue.Test.TextKV3
{
class Kv3ToKv1TestCase
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using NUnit.Framework;

namespace ValveKeyValue.Test.TextKV3
{
class RootTypesTestCase
Expand Down Expand Up @@ -86,7 +84,7 @@ public void DeserializesRootBinaryBlob()
{
Assert.That(data.Name, Is.EqualTo("root"));
Assert.That(data.Value.ValueType, Is.EqualTo(KVValueType.BinaryBlob));
Assert.That(((KVBinaryBlob)data.Value).Bytes, Is.EqualTo(new byte[]
Assert.That(((KVBinaryBlob)data.Value).Bytes.ToArray(), Is.EqualTo(new byte[]
{
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xFF
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using System.IO;
using NUnit.Framework;

namespace ValveKeyValue.Test.TextKV3
{
class SerializationTestCase
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Globalization;
using System.IO;
using ValveKeyValue.Abstraction;

namespace ValveKeyValue.Deserialization.KeyValues3
Expand Down Expand Up @@ -183,7 +181,7 @@ void ReadText(string text)

void ReadBinaryBlob(string text)
{
var bytes = Utils.ParseHexStringAsByteArrayNoReverse(text);
var bytes = HexStringHelper.ParseHexStringAsByteArray(text);
var value = new KVBinaryBlob(bytes)
{
Flag = stateMachine.GetAndResetFlag()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ValveKeyValue.Deserialization.KeyValues3
namespace ValveKeyValue.Deserialization.KeyValues3
{
enum KV3TextReaderState
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Collections.Generic;

namespace ValveKeyValue.Deserialization.KeyValues3
{
class KV3TextReaderStateMachine
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using ValveKeyValue.KeyValues3;
Expand Down
6 changes: 4 additions & 2 deletions ValveKeyValue/ValveKeyValue/KVDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ namespace ValveKeyValue
{
public class KVDocument : KVObject
{
public KVDocument(string name, KVValue value) : base(name, value)
public KVHeader Header { get; }

public KVDocument(KVHeader header, string name, KVValue value) : base(name, value)
{
// KV3 will require a header field that contains format/encoding here.
Header = header;
}
}
}
14 changes: 0 additions & 14 deletions ValveKeyValue/ValveKeyValue/KVFile.cs

This file was deleted.

2 changes: 0 additions & 2 deletions ValveKeyValue/ValveKeyValue/KVFlag.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System;

namespace ValveKeyValue
{
public enum KVFlag
Expand Down
2 changes: 0 additions & 2 deletions ValveKeyValue/ValveKeyValue/KVHeader.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System;

namespace ValveKeyValue
{
public class KVHeader
Expand Down
2 changes: 0 additions & 2 deletions ValveKeyValue/ValveKeyValue/KeyValues3/Encoding.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System;

namespace ValveKeyValue.KeyValues3
{
public class Encoding
Expand Down
2 changes: 0 additions & 2 deletions ValveKeyValue/ValveKeyValue/KeyValues3/Format.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System;

namespace ValveKeyValue.KeyValues3
{
public class Format
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public KV1TextSerializer(Stream stream, KVSerializerOptions options)
readonly KVSerializerOptions options;
readonly TextWriter writer;
int indentation = 0;
Stack<int> arrayCount = new();
readonly Stack<int> arrayCount = new();

public void Dispose()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using ValveKeyValue.Abstraction;

Expand All @@ -23,7 +20,7 @@ public KV3TextSerializer(Stream stream)

readonly TextWriter writer;
int indentation = 0;
Stack<bool> inArray = new();
readonly Stack<bool> inArray = new();

bool IsInArray => inArray.Count > 0 && inArray.Peek();

Expand Down Expand Up @@ -171,8 +168,10 @@ void WriteValue(KVValue value)

void WriteBinaryBlob(KVBinaryBlob value)
{
var bytes = value.Bytes.Span;

// TODO: Verify this against Valve
if (value.Bytes.Length > 32)
if (bytes.Length > 32)
{
writer.WriteLine();
WriteIndentation();
Expand All @@ -184,26 +183,28 @@ void WriteBinaryBlob(KVBinaryBlob value)
indentation++;
WriteIndentation();

var count = 0;
var i = 0;

foreach (var oneByte in value.Bytes)
for (; i < bytes.Length; i++)
{
writer.Write(oneByte.ToString("X2"));
var b = bytes[i];
writer.Write(HexStringHelper.HexToCharUpper(b >> 4));
writer.Write(HexStringHelper.HexToCharUpper(b));

if (++count % 32 == 0)
if (++i % 32 == 0)
{
writer.WriteLine();
WriteIndentation();
}
else if (count != value.Bytes.Length)
else if (i != bytes.Length)
{
writer.Write(' ');
}
}

indentation--;

if (count % 32 != 0)
if (i % 32 != 0)
{
writer.WriteLine();
WriteIndentation();
Expand Down
42 changes: 0 additions & 42 deletions ValveKeyValue/ValveKeyValue/Utils.cs

This file was deleted.

0 comments on commit ba24c07

Please sign in to comment.