From 7eb8994289e67f09ff9ea1072e86fe015197dbb6 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Sun, 11 Feb 2024 11:31:57 +0200 Subject: [PATCH] Add KVFile as a root type --- .../Test Data/apisurface.txt | 19 ++++++++++++++++++- ValveKeyValue/ValveKeyValue/KVFile.cs | 10 ++++++++++ ValveKeyValue/ValveKeyValue/KVSerializer.cs | 7 ++++--- 3 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 ValveKeyValue/ValveKeyValue/KVFile.cs diff --git a/ValveKeyValue/ValveKeyValue.Test/Test Data/apisurface.txt b/ValveKeyValue/ValveKeyValue.Test/Test Data/apisurface.txt index df664688..df6a3c9c 100644 --- a/ValveKeyValue/ValveKeyValue.Test/Test Data/apisurface.txt +++ b/ValveKeyValue/ValveKeyValue.Test/Test Data/apisurface.txt @@ -29,6 +29,23 @@ public class ValveKeyValue.KeyValueException public string ToString(); } +public class ValveKeyValue.KVFile +{ + public void Add(ValveKeyValue.KVObject value); + public bool Equals(object obj); + protected void Finalize(); + public System.Collections.Generic.IEnumerable`1[[ValveKeyValue.KVObject]] get_Children(); + public ValveKeyValue.KVValue get_Item(string key); + public string get_Name(); + public ValveKeyValue.KVValue get_Value(); + public System.Collections.Generic.IEnumerator`1[[ValveKeyValue.KVObject]] GetEnumerator(); + public int GetHashCode(); + public Type GetType(); + protected object MemberwiseClone(); + public void set_Item(string key, ValveKeyValue.KVValue value); + public string ToString(); +} + public sealed class ValveKeyValue.KVIgnoreAttribute { public bool Equals(object obj); @@ -95,7 +112,7 @@ public sealed enum ValveKeyValue.KVSerializationFormat public class ValveKeyValue.KVSerializer { public static ValveKeyValue.KVSerializer Create(ValveKeyValue.KVSerializationFormat format); - public ValveKeyValue.KVObject Deserialize(System.IO.Stream stream, ValveKeyValue.KVSerializerOptions options); + public ValveKeyValue.KVFile Deserialize(System.IO.Stream stream, ValveKeyValue.KVSerializerOptions options); public ValveKeyValue.TObject Deserialize(System.IO.Stream stream, ValveKeyValue.KVSerializerOptions options); public bool Equals(object obj); protected void Finalize(); diff --git a/ValveKeyValue/ValveKeyValue/KVFile.cs b/ValveKeyValue/ValveKeyValue/KVFile.cs new file mode 100644 index 00000000..75dd4717 --- /dev/null +++ b/ValveKeyValue/ValveKeyValue/KVFile.cs @@ -0,0 +1,10 @@ +namespace ValveKeyValue +{ + public class KVFile : KVObject + { + public KVFile(string name, KVValue value) : base(name, value) + { + // KV3 will require a header field that contains format/encoding here. + } + } +} diff --git a/ValveKeyValue/ValveKeyValue/KVSerializer.cs b/ValveKeyValue/ValveKeyValue/KVSerializer.cs index fbc8e8d2..aad3234c 100644 --- a/ValveKeyValue/ValveKeyValue/KVSerializer.cs +++ b/ValveKeyValue/ValveKeyValue/KVSerializer.cs @@ -30,8 +30,8 @@ public static KVSerializer Create(KVSerializationFormat format) /// /// The stream to deserialize from. /// Options to use that can influence the deserialization process. - /// A representing the KeyValues structure encoded in the stream. - public KVObject Deserialize(Stream stream, KVSerializerOptions options = null) + /// A representing the KeyValues structure encoded in the stream. + public KVFile Deserialize(Stream stream, KVSerializerOptions options = null) { Require.NotNull(stream, nameof(stream)); var builder = new KVObjectBuilder(); @@ -41,7 +41,8 @@ public KVObject Deserialize(Stream stream, KVSerializerOptions options = null) reader.ReadObject(); } - return builder.GetObject(); + var root = builder.GetObject(); + return new KVFile(root.Name, root.Value); } ///