Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates

# Build results
Expand All @@ -36,6 +37,9 @@
.builds
*.dotCover

# Visual Studio 2015 cache/options directory
.vs/

## TODO: If you have NuGet Package Restore enabled, uncomment this
#packages/

Expand Down
27 changes: 13 additions & 14 deletions Codecs/Binary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static byte TypeToId(Type type, int version)
return ++i;
}

Type IdToType(byte id)
Tuple<Type, Type> IdToType(byte id)
{
var type_list = SupportedAttributes[EncodingVersion];
bool array = false;
Expand All @@ -82,7 +82,7 @@ Type IdToType(byte id)

try
{
return array ? type_list[id].MakeListType() : type_list[id];
return new Tuple<Type, Type>((array ? type_list[id].MakeListType() : type_list[id]), (array ? type_list[id] : null));
}
catch (IndexOutOfRangeException)
{
Expand Down Expand Up @@ -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
{
Expand All @@ -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))
Expand All @@ -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))
Expand All @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion Codecs/KeyValues2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down