GlbParseException を作りました

This commit is contained in:
ousttrue
2022-01-18 20:26:36 +09:00
parent 94f5354f4e
commit 0d0da0bcad
3 changed files with 14 additions and 7 deletions

View File

@@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace UniGLTF
@@ -14,7 +13,7 @@ namespace UniGLTF
public static GlbChunkType ToChunkType(this string src)
{
switch(src)
switch (src)
{
case "BIN":
return GlbChunkType.BIN;
@@ -53,27 +52,27 @@ namespace UniGLTF
//
if (bytes.Length < 12)
{
throw new FormatException("not glb header");
throw new GlbParseException("glb header not found");
}
int pos = 0;
if (Encoding.ASCII.GetString(bytes, 0, 4) != GLB_MAGIC)
{
throw new FormatException("invalid magic");
throw new GlbParseException("invalid magic");
}
pos += 4;
var version = BitConverter.ToUInt32(bytes, pos);
if (version != GLB_VERSION)
{
throw new FormatException($"unknown version: {version}");
throw new GlbParseException($"unknown version: {version}");
}
pos += 4;
var totalLength = BitConverter.ToUInt32(bytes, pos);
if (bytes.Length < totalLength)
{
throw new System.IO.EndOfStreamException($"Not enough size: {bytes.Length} < {totalLength}");
throw new GlbParseException($"not enough size: {bytes.Length} < {totalLength}");
}
pos += 4;

View File

@@ -14,4 +14,12 @@ namespace UniGLTF
public UniGLTFNotSupportedException(string fmt, params object[] args) : this(string.Format(fmt, args)) { }
public UniGLTFNotSupportedException(string msg) : base(msg) { }
}
/// <summary>
/// Exception in parse the glb header
/// </summary>
public class GlbParseException : UniGLTFException
{
public GlbParseException(string msg) : base(msg) { }
}
}

View File

@@ -66,7 +66,7 @@ namespace UniGLTF
// glb header + 1st chunk only
var mod = bytes.Take(12 + 8 + data.Chunks[0].Bytes.Count).ToArray();
Assert.Throws<EndOfStreamException>(() =>
Assert.Throws<GlbParseException>(() =>
{
// 再パース
var data2 = new GlbBinaryParser(mod, Path.GetFileNameWithoutExtension(path)).Parse();