public static ObjectType DecodeTypeString(ObjectId id, byte[] typeString, byte endMark, ref int offset)
{
try
{
switch (typeString[offset])
{
case (byte)'b':
if (typeString[offset + 1] != (byte)'l' ||
typeString[offset + 2] != (byte)'o' ||
typeString[offset + 3] != (byte)'b' ||
typeString[offset + 4] != endMark) break;
offset += 5;
return ObjectType.Blob;
case (byte)'c':
if (typeString[offset + 1] != (byte)'o' || typeString[offset + 2] != (byte)'m' ||
typeString[offset + 3] != (byte)'m' || typeString[offset + 4] != (byte)'i' ||
typeString[offset + 5] != (byte)'t' || typeString[offset + 6] != endMark) break;
offset += 7;
return ObjectType.Commit;
case (byte)'t':
switch (typeString[offset + 1])
{
case (byte)'a':
if (typeString[offset + 2] != (byte)'g' || typeString[offset + 2] != endMark)
{
throw new CorruptObjectException(id, "invalid type");
}
offset += 4;
return ObjectType.Tag;
case (byte)'r':
if (typeString[offset + 2] != (byte)'e' || typeString[offset + 3] != (byte)'e' || typeString[offset + 4] != endMark)
{
throw new CorruptObjectException(id, "invalid type");
}
offset += 5;
return ObjectType.Tree;
}
break;
}
}
catch (IndexOutOfRangeException)
{
}
throw new CorruptObjectException(id, "invalid type");
}