diff --git a/.gitignore b/.gitignore index a7586c0..880b725 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ # User-specific files *.suo *.user +*.userosscache *.sln.docstates # Build results @@ -36,6 +37,9 @@ .builds *.dotCover +# Visual Studio 2015 cache/options directory +.vs/ + ## TODO: If you have NuGet Package Restore enabled, uncomment this #packages/ diff --git a/Codecs/Binary.cs b/Codecs/Binary.cs index 699c33d..b85ffb4 100644 --- a/Codecs/Binary.cs +++ b/Codecs/Binary.cs @@ -59,7 +59,7 @@ static byte TypeToId(Type type, int version) return ++i; } - Type IdToType(byte id) + Tuple IdToType(byte id) { var type_list = SupportedAttributes[EncodingVersion]; bool array = false; @@ -82,7 +82,7 @@ Type IdToType(byte id) try { - return array ? type_list[id].MakeListType() : type_list[id]; + return new Tuple((array ? type_list[id].MakeListType() : type_list[id]), (array ? type_list[id] : null)); } catch (IndexOutOfRangeException) { @@ -350,7 +350,7 @@ public Datamodel Decode(int encoding_version, string format, int format_version, if (defer_mode == DeferredMode.Automatic) { CodecUtilities.AddDeferredAttribute(elem, name, Reader.BaseStream.Position); - SkipAttribte(); + SkipAttribute(); } else { @@ -371,14 +371,14 @@ public object DeferredDecodeAttribute(Datamodel dm, long offset) object DecodeAttribute(Datamodel dm) { - var type = IdToType(Reader.ReadByte()); + var types = IdToType(Reader.ReadByte()); - if (!Datamodel.IsDatamodelArrayType(type)) - return ReadValue(dm, type, EncodingVersion < 4); + if (types.Item2 == null) + return ReadValue(dm, types.Item1, EncodingVersion < 4); else { var count = Reader.ReadInt32(); - var inner_type = Datamodel.GetArrayInnerType(type); + var inner_type = types.Item2; var array = CodecUtilities.MakeList(inner_type, count); foreach (var x in Enumerable.Range(0, count)) @@ -388,17 +388,16 @@ object DecodeAttribute(Datamodel dm) } } - void SkipAttribte() + void SkipAttribute() { - var type = IdToType(Reader.ReadByte()); + var types = IdToType(Reader.ReadByte()); int count = 1; - bool array = false; - if (Datamodel.IsDatamodelArrayType(type)) + Type type = types.Item1; + if (types.Item2 != null) { - array = true; count = Reader.ReadInt32(); - type = Datamodel.GetArrayInnerType(type); + type = types.Item2; } if (type == typeof(Element)) @@ -424,7 +423,7 @@ void SkipAttribte() } else if (type == typeof(string)) { - if (!StringDict.Dummy && !array && EncodingVersion >= 4) + if (!StringDict.Dummy && types.Item2 == null && EncodingVersion >= 4) length = StringDict.IndiceSize; else { diff --git a/Codecs/KeyValues2.cs b/Codecs/KeyValues2.cs index 6647bec..b0caef6 100644 --- a/Codecs/KeyValues2.cs +++ b/Codecs/KeyValues2.cs @@ -283,7 +283,7 @@ void WriteAttribute(string name, Type type, object value, bool in_array) void WriteElement(Element element) { if (TypeNames.ContainsValue(element.ClassName)) - throw new CodecException(String.Format("Element {} uses reserved type name \"{1}\".", element.ID, element.ClassName)); + throw new CodecException(String.Format("Element {0} uses reserved type name \"{1}\".", element.ID, element.ClassName)); Writer.WriteTokens(element.ClassName); Writer.WriteLine("{"); Writer.Indent++;